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: Created Feb. 20, 2017, 10:02 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
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 Notification.addShowListener(showListener); 53 Notification.addShowListener(showListener);
54 Notification.showNext(url); 54 Notification.showNext(url);
55 Notification.removeShowListener(showListener); 55 Notification.removeShowListener(showListener);
56 return shownNotifications; 56 return shownNotifications;
57 } 57 }
58 58
59 function* pairs(array) 59 function* pairs(array)
60 { 60 {
61 for (let element1 of array) 61 for (let element1 of array)
62 {
62 for (let element2 of array) 63 for (let element2 of array)
64 {
63 if (element1 != element2) 65 if (element1 != element2)
64 yield [element1, element2]; 66 yield [element1, element2];
67 }
68 }
65 } 69 }
66 70
67 function registerHandler(notifications, checkCallback) 71 function registerHandler(notifications, checkCallback)
68 { 72 {
69 this.registerHandler("/notification.json", metadata => 73 this.registerHandler("/notification.json", metadata =>
70 { 74 {
71 if (checkCallback) 75 if (checkCallback)
72 checkCallback(metadata); 76 checkCallback(metadata);
73 77
74 let notification = { 78 let notification = {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ["platform", "chromium", true], 169 ["platform", "chromium", true],
166 ["platform", "gecko", false], 170 ["platform", "gecko", false],
167 ["platformMinVersion", "12.0", true], 171 ["platformMinVersion", "12.0", true],
168 ["platformMinVersion", "12", true], 172 ["platformMinVersion", "12", true],
169 ["platformMinVersion", "11", true], 173 ["platformMinVersion", "11", true],
170 ["platformMinVersion", "13", false], 174 ["platformMinVersion", "13", false],
171 ["platformMinVersion", "12.1", false], 175 ["platformMinVersion", "12.1", false],
172 ["platformMaxVersion", "12.0", true], 176 ["platformMaxVersion", "12.0", true],
173 ["platformMaxVersion", "12", true], 177 ["platformMaxVersion", "12", true],
174 ["platformMaxVersion", "13", true], 178 ["platformMaxVersion", "13", true],
175 ["platformMaxVersion", "11", false], 179 ["platformMaxVersion", "11", false]
176 ]) 180 ])
177 { 181 {
178 exports.testTargetSelection[`${propName}=${value}`] = function(test) 182 exports.testTargetSelection[`${propName}=${value}`] = function(test)
179 { 183 {
180 let targetInfo = {}; 184 let targetInfo = {};
181 targetInfo[propName] = value; 185 targetInfo[propName] = value;
182 186
183 let information = { 187 let information = {
184 id: 1, 188 id: 1,
185 type: "information", 189 type: "information",
(...skipping 18 matching lines...) Expand all
204 ["extension", "adblockplus", false], 208 ["extension", "adblockplus", false],
205 ["extensionMinVersion", "1.4", true], 209 ["extensionMinVersion", "1.4", true],
206 ["extensionMinVersion", "1.5", false], 210 ["extensionMinVersion", "1.5", false],
207 ["application", "chrome", true], 211 ["application", "chrome", true],
208 ["application", "firefox", false], 212 ["application", "firefox", false],
209 ["applicationMinVersion", "27", true], 213 ["applicationMinVersion", "27", true],
210 ["applicationMinVersion", "28", false], 214 ["applicationMinVersion", "28", false],
211 ["platform", "chromium", true], 215 ["platform", "chromium", true],
212 ["platform", "gecko", false], 216 ["platform", "gecko", false],
213 ["platformMinVersion", "12", true], 217 ["platformMinVersion", "12", true],
214 ["platformMinVersion", "13", false], 218 ["platformMinVersion", "13", false]
215 ])) 219 ]))
216 { 220 {
217 exports.testMultipleTargets[`${propName1}=${value1},${propName2}=${value2}`] = function(test) 221 exports.testMultipleTargets[`${propName1}=${value1},${propName2}=${value2}`] = function(test)
218 { 222 {
219 let targetInfo1 = {}; 223 let targetInfo1 = {};
220 targetInfo1[propName1] = value1; 224 targetInfo1[propName1] = value1;
221 let targetInfo2 = {}; 225 let targetInfo2 = {};
222 targetInfo2[propName2] = value2; 226 targetInfo2[propName2] = value2;
223 227
224 let information = { 228 let information = {
225 id: 1, 229 id: 1,
226 type: "information", 230 type: "information",
227 message: {"en-US": "Information"}, 231 message: {"en-US": "Information"},
228 targets: [targetInfo1, targetInfo2] 232 targets: [targetInfo1, targetInfo2]
229 }; 233 };
230 234
231 registerHandler.call(this, [information]); 235 registerHandler.call(this, [information]);
232 this.runScheduledTasks(1).then(() => 236 this.runScheduledTasks(1).then(() =>
233 { 237 {
234 let expected = (result1 || result2 ? [information] : []) 238 let expected = (result1 || result2 ? [information] : []);
235 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets)); 239 test.deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets));
236 }).catch(unexpectedError.bind(test)).then(() => test.done()); 240 }).catch(unexpectedError.bind(test)).then(() => test.done());
237 } 241 };
238 } 242 }
239 243
240 exports.testParametersSent = function(test) 244 exports.testParametersSent = function(test)
241 { 245 {
242 Prefs.notificationdata = { 246 Prefs.notificationdata = {
243 data: { 247 data: {
244 version: "3" 248 version: "3"
245 }, 249 }
246 }; 250 };
247 251
248 let parameters = null; 252 let parameters = null;
249 registerHandler.call(this, [], function(metadata) 253 registerHandler.call(this, [], metadata =>
250 { 254 {
251 parameters = decodeURI(metadata.queryString); 255 parameters = decodeURI(metadata.queryString);
252 }); 256 });
253 this.runScheduledTasks(1).then(() => 257 this.runScheduledTasks(1).then(() =>
254 { 258 {
255 test.equal(parameters, 259 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", 260 "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"); 261 "The correct parameters are sent to the server");
258 }).catch(unexpectedError.bind(test)).then(() => test.done()); 262 }).catch(unexpectedError.bind(test)).then(() => test.done());
259 }; 263 };
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 test.ok(!("severity" in notification), "Severity property was removed"); 332 test.ok(!("severity" in notification), "Severity property was removed");
329 test.ok("type" in notification, "Type property was added"); 333 test.ok("type" in notification, "Type property was added");
330 test.equal(notification.type, severityNotification.severity, "Type property has correct value"); 334 test.equal(notification.type, severityNotification.severity, "Type property has correct value");
331 test.done(); 335 test.done();
332 } 336 }
333 Prefs.addListener(listener); 337 Prefs.addListener(listener);
334 338
335 let responseText = JSON.stringify({ 339 let responseText = JSON.stringify({
336 notifications: [severityNotification] 340 notifications: [severityNotification]
337 }); 341 });
338 Notification._onDownloadSuccess({}, responseText, function() {}, function() {} ); 342 Notification._onDownloadSuccess({}, responseText, () => {}, () => {});
339 }; 343 };
340 344
341 exports.testURLSpecificNotification = function(test) 345 exports.testURLSpecificNotification = function(test)
342 { 346 {
343 let withURLFilterFoo = { 347 let withURLFilterFoo = {
344 id: 1, 348 id: 1,
345 urlFilters: ["foo.com$document"] 349 urlFilters: ["foo.com$document"]
346 }; 350 };
347 let withoutURLFilter = { 351 let withoutURLFilter = {
348 id: 2 352 id: 2
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 let notification = {message: {fr: "fr"}}; 502 let notification = {message: {fr: "fr"}};
499 let texts = Notification.getLocalizedTexts(notification, "fr"); 503 let texts = Notification.getLocalizedTexts(notification, "fr");
500 test.equal(texts.message, "fr"); 504 test.equal(texts.message, "fr");
501 texts = Notification.getLocalizedTexts(notification, "fr-CA"); 505 texts = Notification.getLocalizedTexts(notification, "fr-CA");
502 test.equal(texts.message, "fr"); 506 test.equal(texts.message, "fr");
503 test.done(); 507 test.done();
504 }; 508 };
505 509
506 exports.testLanguageAndCountry = function(test) 510 exports.testLanguageAndCountry = function(test)
507 { 511 {
508 let notification = {message: {fr: "fr", "fr-CA": "fr-CA"}}; 512 let notification = {message: {"fr": "fr", "fr-CA": "fr-CA"}};
509 let texts = Notification.getLocalizedTexts(notification, "fr-CA"); 513 let texts = Notification.getLocalizedTexts(notification, "fr-CA");
510 test.equal(texts.message, "fr-CA"); 514 test.equal(texts.message, "fr-CA");
511 texts = Notification.getLocalizedTexts(notification, "fr"); 515 texts = Notification.getLocalizedTexts(notification, "fr");
512 test.equal(texts.message, "fr"); 516 test.equal(texts.message, "fr");
513 test.done(); 517 test.done();
514 }; 518 };
515 519
516 exports.testMissingTranslation = function(test) 520 exports.testMissingTranslation = function(test)
517 { 521 {
518 let notification = {message: {"en-US": "en-US"}}; 522 let notification = {message: {"en-US": "en-US"}};
519 let texts = Notification.getLocalizedTexts(notification, "fr"); 523 let texts = Notification.getLocalizedTexts(notification, "fr");
520 test.equal(texts.message, "en-US"); 524 test.equal(texts.message, "en-US");
521 test.done(); 525 test.done();
522 }; 526 };
OLDNEW
« lib/filterStorage.js ('K') | « test/matcher.js ('k') | test/regexpFilters_matching.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld