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

Side by Side Diff: test/notification.js

Issue 29375915: Issue 4878 - Start using ESLint for adblockpluscore (Closed)
Patch Set: Addressed Sebastian's initial feedback Created Feb. 21, 2017, 6:12 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
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-2016 Eyeo GmbH 3 * Copyright (C) 2006-2016 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
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 "use strict"; 18 "use strict";
19 19
20 let { 20 let {
21 createSandbox, setupTimerAndXMLHttp, setupRandomResult, unexpectedError, Cr 21 createSandbox, setupTimerAndXMLHttp, setupRandomResult, unexpectedError, Cr
22 } = require("./_common"); 22 } = require("./_common");
23 23
24 let info = null;
25 let Prefs = null; 24 let Prefs = null;
26 let Notification = null; 25 let Notification = null;
27 26
28 exports.setUp = function(callback) 27 exports.setUp = function(callback)
29 { 28 {
30 // Inject our Array and JSON to make sure that instanceof checks on arrays 29 // Inject our Array and JSON to make sure that instanceof checks on arrays
31 // within the sandbox succeed even with data passed in from outside. 30 // within the sandbox succeed even with data passed in from outside.
32 let globals = Object.assign({Array, JSON}, 31 let globals = Object.assign({Array, JSON},
33 setupTimerAndXMLHttp.call(this), setupRandomResult.call(this)); 32 setupTimerAndXMLHttp.call(this), setupRandomResult.call(this));
34 33
35 let sandboxedRequire = createSandbox({globals}); 34 let sandboxedRequire = createSandbox({globals});
36 ( 35 (
37 info = sandboxedRequire("./stub-modules/info"),
38 {Prefs} = sandboxedRequire("./stub-modules/prefs"), 36 {Prefs} = sandboxedRequire("./stub-modules/prefs"),
39 {Notification} = sandboxedRequire("../lib/notification") 37 {Notification} = sandboxedRequire("../lib/notification")
40 ); 38 );
41 39
42 callback(); 40 callback();
43 }; 41 };
44 42
45 function showNotifications(url) 43 function showNotifications(url)
46 { 44 {
47 let shownNotifications = []; 45 let shownNotifications = [];
48 function showListener(notification) 46 function showListener(notification)
49 { 47 {
50 shownNotifications.push(notification); 48 shownNotifications.push(notification);
51 Notification.markAsShown(notification.id); 49 Notification.markAsShown(notification.id);
52 } 50 }
53 Notification.addShowListener(showListener); 51 Notification.addShowListener(showListener);
54 Notification.showNext(url); 52 Notification.showNext(url);
55 Notification.removeShowListener(showListener); 53 Notification.removeShowListener(showListener);
56 return shownNotifications; 54 return shownNotifications;
57 } 55 }
58 56
59 function* pairs(array) 57 function* pairs(array)
60 { 58 {
61 for (let element1 of array) 59 for (let element1 of array)
60 {
62 for (let element2 of array) 61 for (let element2 of array)
62 {
63 if (element1 != element2) 63 if (element1 != element2)
64 yield [element1, element2]; 64 yield [element1, element2];
65 }
66 }
65 } 67 }
66 68
67 function registerHandler(notifications, checkCallback) 69 function registerHandler(notifications, checkCallback)
68 { 70 {
69 this.registerHandler("/notification.json", metadata => 71 this.registerHandler("/notification.json", metadata =>
70 { 72 {
71 if (checkCallback) 73 if (checkCallback)
72 checkCallback(metadata); 74 checkCallback(metadata);
73 75
74 let notification = { 76 let notification = {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ["platform", "chromium", true], 167 ["platform", "chromium", true],
166 ["platform", "gecko", false], 168 ["platform", "gecko", false],
167 ["platformMinVersion", "12.0", true], 169 ["platformMinVersion", "12.0", true],
168 ["platformMinVersion", "12", true], 170 ["platformMinVersion", "12", true],
169 ["platformMinVersion", "11", true], 171 ["platformMinVersion", "11", true],
170 ["platformMinVersion", "13", false], 172 ["platformMinVersion", "13", false],
171 ["platformMinVersion", "12.1", false], 173 ["platformMinVersion", "12.1", false],
172 ["platformMaxVersion", "12.0", true], 174 ["platformMaxVersion", "12.0", true],
173 ["platformMaxVersion", "12", true], 175 ["platformMaxVersion", "12", true],
174 ["platformMaxVersion", "13", true], 176 ["platformMaxVersion", "13", true],
175 ["platformMaxVersion", "11", false], 177 ["platformMaxVersion", "11", false]
176 ]) 178 ])
177 { 179 {
178 exports.testTargetSelection[`${propName}=${value}`] = function(test) 180 exports.testTargetSelection[`${propName}=${value}`] = function(test)
179 { 181 {
180 let targetInfo = {}; 182 let targetInfo = {};
181 targetInfo[propName] = value; 183 targetInfo[propName] = value;
182 184
183 let information = { 185 let information = {
184 id: 1, 186 id: 1,
185 type: "information", 187 type: "information",
(...skipping 18 matching lines...) Expand all
204 ["extension", "adblockplus", false], 206 ["extension", "adblockplus", false],
205 ["extensionMinVersion", "1.4", true], 207 ["extensionMinVersion", "1.4", true],
206 ["extensionMinVersion", "1.5", false], 208 ["extensionMinVersion", "1.5", false],
207 ["application", "chrome", true], 209 ["application", "chrome", true],
208 ["application", "firefox", false], 210 ["application", "firefox", false],
209 ["applicationMinVersion", "27", true], 211 ["applicationMinVersion", "27", true],
210 ["applicationMinVersion", "28", false], 212 ["applicationMinVersion", "28", false],
211 ["platform", "chromium", true], 213 ["platform", "chromium", true],
212 ["platform", "gecko", false], 214 ["platform", "gecko", false],
213 ["platformMinVersion", "12", true], 215 ["platformMinVersion", "12", true],
214 ["platformMinVersion", "13", false], 216 ["platformMinVersion", "13", false]
215 ])) 217 ]))
216 { 218 {
217 exports.testMultipleTargets[`${propName1}=${value1},${propName2}=${value2}`] = function(test) 219 exports.testMultipleTargets[`${propName1}=${value1},${propName2}=${value2}`] = function(test)
218 { 220 {
219 let targetInfo1 = {}; 221 let targetInfo1 = {};
220 targetInfo1[propName1] = value1; 222 targetInfo1[propName1] = value1;
221 let targetInfo2 = {}; 223 let targetInfo2 = {};
222 targetInfo2[propName2] = value2; 224 targetInfo2[propName2] = value2;
223 225
224 let information = { 226 let information = {
225 id: 1, 227 id: 1,
226 type: "information", 228 type: "information",
227 message: {"en-US": "Information"}, 229 message: {"en-US": "Information"},
228 targets: [targetInfo1, targetInfo2] 230 targets: [targetInfo1, targetInfo2]
229 }; 231 };
230 232
231 registerHandler.call(this, [information]); 233 registerHandler.call(this, [information]);
232 this.runScheduledTasks(1).then(() => 234 this.runScheduledTasks(1).then(() =>
233 { 235 {
234 let expected = (result1 || result2 ? [information] : []) 236 let expected = (result1 || result2 ? [information] : []);
235 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets)); 237 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets));
236 }).catch(unexpectedError.bind(test)).then(() => test.done()); 238 }).catch(unexpectedError.bind(test)).then(() => test.done());
237 } 239 };
238 } 240 }
239 241
240 exports.testParametersSent = function(test) 242 exports.testParametersSent = function(test)
241 { 243 {
242 Prefs.notificationdata = { 244 Prefs.notificationdata = {
243 data: { 245 data: {
244 version: "3" 246 version: "3"
245 }, 247 }
246 }; 248 };
247 249
248 let parameters = null; 250 let parameters = null;
249 registerHandler.call(this, [], function(metadata) 251 registerHandler.call(this, [], metadata =>
250 { 252 {
251 parameters = decodeURI(metadata.queryString); 253 parameters = decodeURI(metadata.queryString);
252 }); 254 });
253 this.runScheduledTasks(1).then(() => 255 this.runScheduledTasks(1).then(() =>
254 { 256 {
255 test.equal(parameters, 257 test.equal(parameters,
256 "addonName=adblockpluschrome&addonVersion=1.4.1&application=chrome&app licationVersion=27.0&platform=chromium&platformVersion=12.0&lastVersion=3&downlo adCount=0", 258 "addonName=adblockpluschrome&addonVersion=1.4.1&application=chrome&app licationVersion=27.0&platform=chromium&platformVersion=12.0&lastVersion=3&downlo adCount=0",
257 "The correct parameters are sent to the server"); 259 "The correct parameters are sent to the server");
258 }).catch(unexpectedError.bind(test)).then(() => test.done()); 260 }).catch(unexpectedError.bind(test)).then(() => test.done());
259 }; 261 };
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 test.ok(!("severity" in notification), "Severity property was removed"); 330 test.ok(!("severity" in notification), "Severity property was removed");
329 test.ok("type" in notification, "Type property was added"); 331 test.ok("type" in notification, "Type property was added");
330 test.equal(notification.type, severityNotification.severity, "Type property has correct value"); 332 test.equal(notification.type, severityNotification.severity, "Type property has correct value");
331 test.done(); 333 test.done();
332 } 334 }
333 Prefs.addListener(listener); 335 Prefs.addListener(listener);
334 336
335 let responseText = JSON.stringify({ 337 let responseText = JSON.stringify({
336 notifications: [severityNotification] 338 notifications: [severityNotification]
337 }); 339 });
338 Notification._onDownloadSuccess({}, responseText, function() {}, function() {} ); 340 Notification._onDownloadSuccess({}, responseText, () => {}, () => {});
339 }; 341 };
340 342
341 exports.testURLSpecificNotification = function(test) 343 exports.testURLSpecificNotification = function(test)
342 { 344 {
343 let withURLFilterFoo = { 345 let withURLFilterFoo = {
344 id: 1, 346 id: 1,
345 urlFilters: ["foo.com$document"] 347 urlFilters: ["foo.com$document"]
346 }; 348 };
347 let withoutURLFilter = { 349 let withoutURLFilter = {
348 id: 2 350 id: 2
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 let notification = {message: {fr: "fr"}}; 500 let notification = {message: {fr: "fr"}};
499 let texts = Notification.getLocalizedTexts(notification, "fr"); 501 let texts = Notification.getLocalizedTexts(notification, "fr");
500 test.equal(texts.message, "fr"); 502 test.equal(texts.message, "fr");
501 texts = Notification.getLocalizedTexts(notification, "fr-CA"); 503 texts = Notification.getLocalizedTexts(notification, "fr-CA");
502 test.equal(texts.message, "fr"); 504 test.equal(texts.message, "fr");
503 test.done(); 505 test.done();
504 }; 506 };
505 507
506 exports.testLanguageAndCountry = function(test) 508 exports.testLanguageAndCountry = function(test)
507 { 509 {
508 let notification = {message: {fr: "fr", "fr-CA": "fr-CA"}}; 510 let notification = {message: {"fr": "fr", "fr-CA": "fr-CA"}};
509 let texts = Notification.getLocalizedTexts(notification, "fr-CA"); 511 let texts = Notification.getLocalizedTexts(notification, "fr-CA");
510 test.equal(texts.message, "fr-CA"); 512 test.equal(texts.message, "fr-CA");
511 texts = Notification.getLocalizedTexts(notification, "fr"); 513 texts = Notification.getLocalizedTexts(notification, "fr");
512 test.equal(texts.message, "fr"); 514 test.equal(texts.message, "fr");
513 test.done(); 515 test.done();
514 }; 516 };
515 517
516 exports.testMissingTranslation = function(test) 518 exports.testMissingTranslation = function(test)
517 { 519 {
518 let notification = {message: {"en-US": "en-US"}}; 520 let notification = {message: {"en-US": "en-US"}};
519 let texts = Notification.getLocalizedTexts(notification, "fr"); 521 let texts = Notification.getLocalizedTexts(notification, "fr");
520 test.equal(texts.message, "en-US"); 522 test.equal(texts.message, "en-US");
521 test.done(); 523 test.done();
522 }; 524 };
OLDNEW
« test/_common.js ('K') | « test/matcher.js ('k') | test/regexpFilters_matching.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld