LEFT | RIGHT |
(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-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 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 ]); | 364 ]); |
365 this.runScheduledTasks(1).then(() => | 365 this.runScheduledTasks(1).then(() => |
366 { | 366 { |
367 test.deepEqual(showNotifications(), [withoutURLFilter], "URL-specific notifi
cations are skipped"); | 367 test.deepEqual(showNotifications(), [withoutURLFilter], "URL-specific notifi
cations are skipped"); |
368 test.deepEqual(showNotifications("http://foo.com"), [withURLFilterFoo], "URL
-specific notification is retrieved"); | 368 test.deepEqual(showNotifications("http://foo.com"), [withURLFilterFoo], "URL
-specific notification is retrieved"); |
369 test.deepEqual(showNotifications("http://foo.com"), [], "URL-specific notifi
cation is not retrieved"); | 369 test.deepEqual(showNotifications("http://foo.com"), [], "URL-specific notifi
cation is not retrieved"); |
370 test.deepEqual(showNotifications("http://www.example.com"), [subdomainURLFil
ter], "URL-specific notification matches subdomain"); | 370 test.deepEqual(showNotifications("http://www.example.com"), [subdomainURLFil
ter], "URL-specific notification matches subdomain"); |
371 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 371 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
372 }; | 372 }; |
373 | 373 |
| 374 exports.testInterval = function(test) |
| 375 { |
| 376 let relentless = { |
| 377 id: 3, |
| 378 type: "relentless", |
| 379 interval: 100 |
| 380 }; |
| 381 |
| 382 registerHandler.call(this, [relentless]); |
| 383 this.runScheduledTasks(1).then(() => |
| 384 { |
| 385 test.deepEqual(showNotifications(), [relentless], "Relentless notifications
are shown initially"); |
| 386 }).then(() => |
| 387 { |
| 388 test.deepEqual(showNotifications(), [], "Relentless notifications are not sh
own before the interval"); |
| 389 }).then(() => |
| 390 { |
| 391 // Date always returns a fixed time (see setupTimerAndXMLHttp) so we |
| 392 // manipulate the shown data manually. |
| 393 Prefs.notificationdata.shown[relentless.id] -= relentless.interval; |
| 394 test.deepEqual(showNotifications(), [relentless], "Relentless notifications
are shown after the interval"); |
| 395 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 396 }; |
| 397 |
| 398 exports.testRelentlessNotification = function(test) |
| 399 { |
| 400 let relentless = { |
| 401 id: 3, |
| 402 type: "relentless", |
| 403 interval: 100, |
| 404 urlFilters: ["foo.com$document", "bar.foo$document"] |
| 405 }; |
| 406 |
| 407 registerHandler.call(this, [relentless]); |
| 408 this.runScheduledTasks(1).then(() => |
| 409 { |
| 410 test.deepEqual(showNotifications(), [], "Relentless notification is not show
n without URL"); |
| 411 test.deepEqual(showNotifications("http://bar.com"), [], "Relentless notifica
tion is not shown for a non-matching URL"); |
| 412 test.deepEqual(showNotifications("http://foo.com"), [relentless], "Relentles
s notification is shown for a matching URL"); |
| 413 }).then(() => |
| 414 { |
| 415 test.deepEqual(showNotifications("http://foo.com"), [], "Relentless notifica
tions are not shown before the interval"); |
| 416 }).then(() => |
| 417 { |
| 418 // Date always returns a fixed time (see setupTimerAndXMLHttp) so we |
| 419 // manipulate the shown data manually. |
| 420 Prefs.notificationdata.shown[relentless.id] -= relentless.interval; |
| 421 test.deepEqual(showNotifications(), [], "Relentless notifications are not sh
own after the interval without URL"); |
| 422 test.deepEqual(showNotifications("http://bar.com"), [], "Relentless notifica
tions are not shown after the interval for a non-matching URL"); |
| 423 test.deepEqual(showNotifications("http://bar.foo.com"), [relentless], "Relen
tless notifications are shown after the interval for a matching URL"); |
| 424 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
| 425 }; |
| 426 |
374 exports.testGlobalOptOut = function(test) | 427 exports.testGlobalOptOut = function(test) |
375 { | 428 { |
376 Notification.toggleIgnoreCategory("*", true); | 429 Notification.toggleIgnoreCategory("*", true); |
377 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Force enabl
e global opt-out"); | 430 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Force enabl
e global opt-out"); |
378 Notification.toggleIgnoreCategory("*", true); | 431 Notification.toggleIgnoreCategory("*", true); |
379 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Force enabl
e global opt-out (again)"); | 432 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Force enabl
e global opt-out (again)"); |
380 Notification.toggleIgnoreCategory("*", false); | 433 Notification.toggleIgnoreCategory("*", false); |
381 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Force disab
le global opt-out"); | 434 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Force disab
le global opt-out"); |
382 Notification.toggleIgnoreCategory("*", false); | 435 Notification.toggleIgnoreCategory("*", false); |
383 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Force disab
le global opt-out (again)"); | 436 test.ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Force disab
le global opt-out (again)"); |
(...skipping 11 matching lines...) Expand all Loading... |
395 test.ok(Prefs.notifications_showui, "Opt-out UI will be shown after enabling g
lobal opt-out even if it got disabled again"); | 448 test.ok(Prefs.notifications_showui, "Opt-out UI will be shown after enabling g
lobal opt-out even if it got disabled again"); |
396 | 449 |
397 let information = { | 450 let information = { |
398 id: 1, | 451 id: 1, |
399 type: "information" | 452 type: "information" |
400 }; | 453 }; |
401 let critical = { | 454 let critical = { |
402 id: 2, | 455 id: 2, |
403 type: "critical" | 456 type: "critical" |
404 }; | 457 }; |
| 458 let relentless = { |
| 459 id: 3, |
| 460 type: "relentless" |
| 461 }; |
405 | 462 |
406 Notification.toggleIgnoreCategory("*", true); | 463 Notification.toggleIgnoreCategory("*", true); |
407 registerHandler.call(this, [information]); | 464 registerHandler.call(this, [information]); |
408 this.runScheduledTasks(1).then(() => | 465 this.runScheduledTasks(1).then(() => |
409 { | 466 { |
410 test.deepEqual(showNotifications(), [], "Information notifications are ignor
ed after enabling global opt-out"); | 467 test.deepEqual(showNotifications(), [], "Information notifications are ignor
ed after enabling global opt-out"); |
411 Notification.toggleIgnoreCategory("*", false); | 468 Notification.toggleIgnoreCategory("*", false); |
412 test.deepEqual(showNotifications(), [information], "Information notification
s are shown after disabling global opt-out"); | 469 test.deepEqual(showNotifications(), [information], "Information notification
s are shown after disabling global opt-out"); |
413 | 470 |
414 Notification.toggleIgnoreCategory("*", true); | 471 Notification.toggleIgnoreCategory("*", true); |
415 Prefs.notificationdata = {}; | 472 Prefs.notificationdata = {}; |
416 registerHandler.call(this, [critical]); | 473 registerHandler.call(this, [critical]); |
417 return this.runScheduledTasks(1); | 474 return this.runScheduledTasks(1); |
418 }).then(() => | 475 }).then(() => |
419 { | 476 { |
420 test.deepEqual(showNotifications(), [critical], "Critical notifications are
not ignored"); | 477 test.deepEqual(showNotifications(), [critical], "Critical notifications are
not ignored"); |
| 478 |
| 479 Prefs.notificationdata = {}; |
| 480 registerHandler.call(this, [relentless]); |
| 481 return this.runScheduledTasks(1); |
| 482 }).then(() => |
| 483 { |
| 484 test.deepEqual(showNotifications(), [relentless], "Relentless notifications
are not ignored"); |
421 }).catch(unexpectedError.bind(test)).then(() => test.done()); | 485 }).catch(unexpectedError.bind(test)).then(() => test.done()); |
422 }; | 486 }; |
423 | 487 |
424 exports.testMessageWithoutLocalization = function(test) | 488 exports.testMessageWithoutLocalization = function(test) |
425 { | 489 { |
426 let notification = {message: "non-localized"}; | 490 let notification = {message: "non-localized"}; |
427 let texts = Notification.getLocalizedTexts(notification, "en-US"); | 491 let texts = Notification.getLocalizedTexts(notification, "en-US"); |
428 test.equal(texts.message, "non-localized"); | 492 test.equal(texts.message, "non-localized"); |
429 test.done(); | 493 test.done(); |
430 }; | 494 }; |
(...skipping 18 matching lines...) Expand all Loading... |
449 test.done(); | 513 test.done(); |
450 }; | 514 }; |
451 | 515 |
452 exports.testMissingTranslation = function(test) | 516 exports.testMissingTranslation = function(test) |
453 { | 517 { |
454 let notification = {message: {"en-US": "en-US"}}; | 518 let notification = {message: {"en-US": "en-US"}}; |
455 let texts = Notification.getLocalizedTexts(notification, "fr"); | 519 let texts = Notification.getLocalizedTexts(notification, "fr"); |
456 test.equal(texts.message, "en-US"); | 520 test.equal(texts.message, "en-US"); |
457 test.done(); | 521 test.done(); |
458 }; | 522 }; |
LEFT | RIGHT |