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

Delta Between Two Patch Sets: test/notification.js

Issue 30032558: Noissue - Fix tests on NodeJS < 10 (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore/
Left Patch Set: Created March 27, 2019, 6:58 p.m.
Right Patch Set: Remove URL from eslint globals Created March 28, 2019, 11:48 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « test/.eslintrc.json ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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-present eyeo GmbH 3 * Copyright (C) 2006-present 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 21 createSandbox, setupTimerAndFetch, setupRandomResult, unexpectedError
22 } = require("./_common"); 22 } = require("./_common");
23 23
24 let Prefs = null; 24 let Prefs = null;
25 let Utils = null; 25 let Utils = null;
26 let Notification = null; 26 let Notification = null;
27 27
28 // Only starting NodeJS 10 that URL is in the global space. 28 // Only starting NodeJS 10 that URL is in the global space.
29 const {URL} = require("url"); 29 const {URL} = require("url");
30 30
31 exports.setUp = function(callback) 31 exports.setUp = function(callback)
32 { 32 {
33 // Inject our Array and JSON to make sure that instanceof checks on arrays 33 // Inject our Array and JSON to make sure that instanceof checks on arrays
34 // within the sandbox succeed even with data passed in from outside. 34 // within the sandbox succeed even with data passed in from outside.
35 let globals = Object.assign({Array, JSON}, 35 let globals = Object.assign({Array, JSON},
36 setupTimerAndXMLHttp.call(this), setupRandomResult.call(this)); 36 setupTimerAndFetch.call(this), setupRandomResult.call(this));
37 37
38 let sandboxedRequire = createSandbox({globals}); 38 let sandboxedRequire = createSandbox({globals});
39 ( 39 (
40 {Prefs} = sandboxedRequire("./stub-modules/prefs"), 40 {Prefs} = sandboxedRequire("./stub-modules/prefs"),
41 {Utils} = sandboxedRequire("./stub-modules/utils"), 41 {Utils} = sandboxedRequire("./stub-modules/utils"),
42 {Notification} = sandboxedRequire("../lib/notification") 42 {Notification} = sandboxedRequire("../lib/notification")
43 ); 43 );
44 44
45 callback(); 45 callback();
46 }; 46 };
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 428
429 registerHandler.call(this, [relentless]); 429 registerHandler.call(this, [relentless]);
430 this.runScheduledTasks(1).then(() => 430 this.runScheduledTasks(1).then(() =>
431 { 431 {
432 test.deepEqual(showNotifications(), [relentless], "Relentless notifications are shown initially"); 432 test.deepEqual(showNotifications(), [relentless], "Relentless notifications are shown initially");
433 }).then(() => 433 }).then(() =>
434 { 434 {
435 test.deepEqual(showNotifications(), [], "Relentless notifications are not sh own before the interval"); 435 test.deepEqual(showNotifications(), [], "Relentless notifications are not sh own before the interval");
436 }).then(() => 436 }).then(() =>
437 { 437 {
438 // Date always returns a fixed time (see setupTimerAndXMLHttp) so we 438 // Date always returns a fixed time (see setupTimerAndFetch) so we
439 // manipulate the shown data manually. 439 // manipulate the shown data manually.
440 Prefs.notificationdata.shown[relentless.id] -= relentless.interval; 440 Prefs.notificationdata.shown[relentless.id] -= relentless.interval;
441 test.deepEqual(showNotifications(), [relentless], "Relentless notifications are shown after the interval"); 441 test.deepEqual(showNotifications(), [relentless], "Relentless notifications are shown after the interval");
442 }).catch(unexpectedError.bind(test)).then(() => test.done()); 442 }).catch(unexpectedError.bind(test)).then(() => test.done());
443 }; 443 };
444 444
445 exports.testRelentlessNotification = function(test) 445 exports.testRelentlessNotification = function(test)
446 { 446 {
447 let relentless = { 447 let relentless = {
448 id: 3, 448 id: 3,
449 type: "relentless", 449 type: "relentless",
450 interval: 100, 450 interval: 100,
451 urlFilters: ["foo.com$document", "bar.foo$document"] 451 urlFilters: ["foo.com$document", "bar.foo$document"]
452 }; 452 };
453 453
454 registerHandler.call(this, [relentless]); 454 registerHandler.call(this, [relentless]);
455 this.runScheduledTasks(1).then(() => 455 this.runScheduledTasks(1).then(() =>
456 { 456 {
457 test.deepEqual(showNotifications(), [], "Relentless notification is not show n without URL"); 457 test.deepEqual(showNotifications(), [], "Relentless notification is not show n without URL");
458 test.deepEqual(showNotifications("http://bar.com"), [], "Relentless notifica tion is not shown for a non-matching URL"); 458 test.deepEqual(showNotifications("http://bar.com"), [], "Relentless notifica tion is not shown for a non-matching URL");
459 test.deepEqual(showNotifications("http://foo.com"), [relentless], "Relentles s notification is shown for a matching URL"); 459 test.deepEqual(showNotifications("http://foo.com"), [relentless], "Relentles s notification is shown for a matching URL");
460 }).then(() => 460 }).then(() =>
461 { 461 {
462 test.deepEqual(showNotifications("http://foo.com"), [], "Relentless notifica tions are not shown before the interval"); 462 test.deepEqual(showNotifications("http://foo.com"), [], "Relentless notifica tions are not shown before the interval");
463 }).then(() => 463 }).then(() =>
464 { 464 {
465 // Date always returns a fixed time (see setupTimerAndXMLHttp) so we 465 // Date always returns a fixed time (see setupTimerAndFetch) so we
466 // manipulate the shown data manually. 466 // manipulate the shown data manually.
467 Prefs.notificationdata.shown[relentless.id] -= relentless.interval; 467 Prefs.notificationdata.shown[relentless.id] -= relentless.interval;
468 test.deepEqual(showNotifications(), [], "Relentless notifications are not sh own after the interval without URL"); 468 test.deepEqual(showNotifications(), [], "Relentless notifications are not sh own after the interval without URL");
469 test.deepEqual(showNotifications("http://bar.com"), [], "Relentless notifica tions are not shown after the interval for a non-matching URL"); 469 test.deepEqual(showNotifications("http://bar.com"), [], "Relentless notifica tions are not shown after the interval for a non-matching URL");
470 test.deepEqual(showNotifications("http://bar.foo.com"), [relentless], "Relen tless notifications are shown after the interval for a matching URL"); 470 test.deepEqual(showNotifications("http://bar.foo.com"), [relentless], "Relen tless notifications are shown after the interval for a matching URL");
471 }).catch(unexpectedError.bind(test)).then(() => test.done()); 471 }).catch(unexpectedError.bind(test)).then(() => test.done());
472 }; 472 };
473 473
474 exports.testGlobalOptOut = function(test) 474 exports.testGlobalOptOut = function(test)
475 { 475 {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 }; 565 };
566 566
567 exports.testMissingTranslation = function(test) 567 exports.testMissingTranslation = function(test)
568 { 568 {
569 let notification = {message: {"en-US": "en-US"}}; 569 let notification = {message: {"en-US": "en-US"}};
570 Utils.appLocale = "fr"; 570 Utils.appLocale = "fr";
571 let texts = Notification.getLocalizedTexts(notification); 571 let texts = Notification.getLocalizedTexts(notification);
572 test.equal(texts.message, "en-US"); 572 test.equal(texts.message, "en-US");
573 test.done(); 573 test.done();
574 }; 574 };
LEFTRIGHT

Powered by Google App Engine
This is Rietveld