Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: test/notification.js

Issue 29501607: Issue 5459 - Add support to show a notification based on the number of ads blocked (Closed)
Left Patch Set: Created July 31, 2017, 3:05 p.m.
Right Patch Set: Show notification for blockedTotal* only if Prefs.show_statsinpopup Created Aug. 24, 2017, 4:35 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « lib/notification.js ('k') | test/stub-modules/prefs.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 message: {"en-US": "Information"} 132 message: {"en-US": "Information"}
133 }; 133 };
134 134
135 registerHandler.call(this, [information]); 135 registerHandler.call(this, [information]);
136 this.runScheduledTasks(1).then(() => 136 this.runScheduledTasks(1).then(() =>
137 { 137 {
138 test.deepEqual(showNotifications(), [information], "The notification is show n"); 138 test.deepEqual(showNotifications(), [information], "The notification is show n");
139 test.deepEqual(showNotifications(), [], "Notification is treated as type inf ormation"); 139 test.deepEqual(showNotifications(), [], "Notification is treated as type inf ormation");
140 }).catch(unexpectedError.bind(test)).then(() => test.done()); 140 }).catch(unexpectedError.bind(test)).then(() => test.done());
141 }; 141 };
142
143 function testTargetSelectionFunc(propName, value, result)
144 {
145 return function(test)
146 {
147 let targetInfo = {};
148 targetInfo[propName] = value;
149
150 let information = {
151 id: 1,
152 type: "information",
153 message: {"en-US": "Information"},
154 targets: [targetInfo]
155 };
156
157 registerHandler.call(this, [information]);
158 this.runScheduledTasks(1).then(() =>
159 {
160 let expected = (result ? [information] : []);
161 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets));
162 test.deepEqual(showNotifications(), [], "No notification on second call");
163 }).catch(unexpectedError.bind(test)).then(() => test.done());
164 };
165 }
142 166
143 exports.testTargetSelection = {}; 167 exports.testTargetSelection = {};
144 168
145 for (let [propName, value, result] of [ 169 for (let [propName, value, result] of [
146 ["extension", "adblockpluschrome", true], 170 ["extension", "adblockpluschrome", true],
147 ["extension", "adblockplus", false], 171 ["extension", "adblockplus", false],
148 ["extension", "adblockpluschrome2", false], 172 ["extension", "adblockpluschrome2", false],
149 ["extensionMinVersion", "1.4", true], 173 ["extensionMinVersion", "1.4", true],
150 ["extensionMinVersion", "1.4.1", true], 174 ["extensionMinVersion", "1.4.1", true],
151 ["extensionMinVersion", "1.5", false], 175 ["extensionMinVersion", "1.5", false],
(...skipping 15 matching lines...) Expand all
167 ["platform", "chromium", true], 191 ["platform", "chromium", true],
168 ["platform", "gecko", false], 192 ["platform", "gecko", false],
169 ["platformMinVersion", "12.0", true], 193 ["platformMinVersion", "12.0", true],
170 ["platformMinVersion", "12", true], 194 ["platformMinVersion", "12", true],
171 ["platformMinVersion", "11", true], 195 ["platformMinVersion", "11", true],
172 ["platformMinVersion", "13", false], 196 ["platformMinVersion", "13", false],
173 ["platformMinVersion", "12.1", false], 197 ["platformMinVersion", "12.1", false],
174 ["platformMaxVersion", "12.0", true], 198 ["platformMaxVersion", "12.0", true],
175 ["platformMaxVersion", "12", true], 199 ["platformMaxVersion", "12", true],
176 ["platformMaxVersion", "13", true], 200 ["platformMaxVersion", "13", true],
177 ["platformMaxVersion", "11", false] 201 ["platformMaxVersion", "11", false],
202 ["blockedTotalMin", "11", false],
203 ["blockedTotalMin", "10", true],
204 ["blockedTotalMax", "10", true],
205 ["blockedTotalMax", "1", false],
206 ["locales", ["en-US"], true],
207 ["locales", ["en-US", "de-DE"], true],
208 ["locales", ["de-DE"], false],
209 ["locales", ["en-GB", "de-DE"], false]
178 ]) 210 ])
179 { 211 {
180 exports.testTargetSelection[`${propName}=${value}`] = function(test) 212 exports.testTargetSelection[`${propName}=${value}`] = testTargetSelectionFunc( propName, value, result);
181 { 213 }
182 let targetInfo = {}; 214
183 targetInfo[propName] = value; 215 exports.testTargetSelectionNoShowStats = {
184 216
185 let information = { 217 setUp(callback)
186 id: 1, 218 {
187 type: "information", 219 this.show_statsinpopup_orig = Prefs.show_statsinpopup;
188 message: {"en-US": "Information"}, 220 Prefs.show_statsinpopup = false;
189 targets: [targetInfo] 221 callback();
190 }; 222 },
191 223 tearDown(callback)
192 registerHandler.call(this, [information]); 224 {
193 this.runScheduledTasks(1).then(() => 225 Prefs.show_statsinpopup = this.show_statsinpopup_orig;
194 { 226 callback();
195 let expected = (result ? [information] : []); 227 }
196 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets)); 228 };
197 test.deepEqual(showNotifications(), [], "No notification on second call"); 229 for (let [propName, value, result] of [
198 }).catch(unexpectedError.bind(test)).then(() => test.done()); 230 ["blockedTotalMin", "10", false],
199 }; 231 ["blockedTotalMax", "10", false]
232 ])
233 {
234 exports.testTargetSelectionNoShowStats[`${propName}=${value}`] = testTargetSel ectionFunc(propName, value, result);
200 } 235 }
201 236
202 exports.testMultipleTargets = {}; 237 exports.testMultipleTargets = {};
203 238
204 for (let [[propName1, value1, result1], [propName2, value2, result2]] of pairs([ 239 for (let [[propName1, value1, result1], [propName2, value2, result2]] of pairs([
205 ["extension", "adblockpluschrome", true], 240 ["extension", "adblockpluschrome", true],
206 ["extension", "adblockplus", false], 241 ["extension", "adblockplus", false],
207 ["extensionMinVersion", "1.4", true], 242 ["extensionMinVersion", "1.4", true],
208 ["extensionMinVersion", "1.5", false], 243 ["extensionMinVersion", "1.5", false],
209 ["application", "chrome", true], 244 ["application", "chrome", true],
210 ["application", "firefox", false], 245 ["application", "firefox", false],
211 ["applicationMinVersion", "27", true], 246 ["applicationMinVersion", "27", true],
212 ["applicationMinVersion", "28", false], 247 ["applicationMinVersion", "28", false],
213 ["platform", "chromium", true], 248 ["platform", "chromium", true],
214 ["platform", "gecko", false], 249 ["platform", "gecko", false],
215 ["platformMinVersion", "12", true], 250 ["platformMinVersion", "12", true],
216 ["platformMinVersion", "13", false] 251 ["platformMinVersion", "13", false],
252 ["unkown", "unknown", false]
217 ])) 253 ]))
218 { 254 {
219 exports.testMultipleTargets[`${propName1}=${value1},${propName2}=${value2}`] = function(test) 255 exports.testMultipleTargets[`${propName1}=${value1},${propName2}=${value2}`] = function(test)
220 { 256 {
221 let targetInfo1 = {}; 257 let targetInfo1 = {};
222 targetInfo1[propName1] = value1; 258 targetInfo1[propName1] = value1;
223 let targetInfo2 = {}; 259 let targetInfo2 = {};
224 targetInfo2[propName2] = value2; 260 targetInfo2[propName2] = value2;
225 261
226 let information = { 262 let information = {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 test.done(); 551 test.done();
516 }; 552 };
517 553
518 exports.testMissingTranslation = function(test) 554 exports.testMissingTranslation = function(test)
519 { 555 {
520 let notification = {message: {"en-US": "en-US"}}; 556 let notification = {message: {"en-US": "en-US"}};
521 let texts = Notification.getLocalizedTexts(notification, "fr"); 557 let texts = Notification.getLocalizedTexts(notification, "fr");
522 test.equal(texts.message, "en-US"); 558 test.equal(texts.message, "en-US");
523 test.done(); 559 test.done();
524 }; 560 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld