OLD | NEW |
1 (function() | 1 (function() |
2 { | 2 { |
3 let testRunner = null; | 3 let testRunner = null; |
4 let randomResult = 0.5; | 4 let randomResult = 0.5; |
5 | 5 |
6 let originalInfo; | 6 let originalInfo; |
7 let info = require("info"); | 7 let info = require("info"); |
8 | 8 |
9 module("Notification handling", | 9 module("Notification handling", |
10 { | 10 { |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 info.addonName = "adblockpluschrome"; | 27 info.addonName = "adblockpluschrome"; |
28 info.addonVersion = "1.4.1"; | 28 info.addonVersion = "1.4.1"; |
29 info.application = "chrome"; | 29 info.application = "chrome"; |
30 info.applicationVersion = "27.0"; | 30 info.applicationVersion = "27.0"; |
31 info.platform = "chromium"; | 31 info.platform = "chromium"; |
32 info.platformVersion = "12.0"; | 32 info.platformVersion = "12.0"; |
33 | 33 |
34 Prefs.notificationurl = "http://example.com/notification.json"; | 34 Prefs.notificationurl = "http://example.com/notification.json"; |
35 Prefs.notificationdata = {}; | 35 Prefs.notificationdata = {}; |
| 36 Prefs.notifications_ignoredcategories = []; |
36 | 37 |
37 // Replace Math.random() function | 38 // Replace Math.random() function |
38 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader")
); | 39 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader")
); |
39 this._origRandom = DownloaderGlobal.Math.random; | 40 this._origRandom = DownloaderGlobal.Math.random; |
40 DownloaderGlobal.Math.random = () => randomResult; | 41 DownloaderGlobal.Math.random = () => randomResult; |
41 randomResult = 0.5; | 42 randomResult = 0.5; |
42 }, | 43 }, |
43 | 44 |
44 teardown: function() | 45 teardown: function() |
45 { | 46 { |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 subdomainURLFilter | 370 subdomainURLFilter |
370 ]); | 371 ]); |
371 testRunner.runScheduledTasks(1); | 372 testRunner.runScheduledTasks(1); |
372 | 373 |
373 deepEqual(Notification.getNextToShow(), withoutURLFilter, "URL-specific noti
fications are skipped"); | 374 deepEqual(Notification.getNextToShow(), withoutURLFilter, "URL-specific noti
fications are skipped"); |
374 deepEqual(Notification.getNextToShow("http://foo.com"), withURLFilterFoo, "U
RL-specific notification is retrieved"); | 375 deepEqual(Notification.getNextToShow("http://foo.com"), withURLFilterFoo, "U
RL-specific notification is retrieved"); |
375 deepEqual(Notification.getNextToShow("http://foo.com"), null, "URL-specific
notification is not retrieved"); | 376 deepEqual(Notification.getNextToShow("http://foo.com"), null, "URL-specific
notification is not retrieved"); |
376 deepEqual(Notification.getNextToShow("http://www.example.com"), subdomainURL
Filter, "URL-specific notification matches subdomain"); | 377 deepEqual(Notification.getNextToShow("http://www.example.com"), subdomainURL
Filter, "URL-specific notification matches subdomain"); |
377 }); | 378 }); |
378 | 379 |
| 380 test("Global opt-out", function() |
| 381 { |
| 382 Notification.toggleIgnoreCategory("*", true); |
| 383 ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Force enable g
lobal opt-out"); |
| 384 Notification.toggleIgnoreCategory("*", true); |
| 385 ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Force enable g
lobal opt-out (again)"); |
| 386 Notification.toggleIgnoreCategory("*", false); |
| 387 ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Force disable
global opt-out"); |
| 388 Notification.toggleIgnoreCategory("*", false); |
| 389 ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Force disable
global opt-out (again)"); |
| 390 Notification.toggleIgnoreCategory("*"); |
| 391 ok(Prefs.notifications_ignoredcategories.indexOf("*") != -1, "Toggle enable
global opt-out"); |
| 392 Notification.toggleIgnoreCategory("*"); |
| 393 ok(Prefs.notifications_ignoredcategories.indexOf("*") == -1, "Toggle disable
global opt-out"); |
| 394 |
| 395 Prefs.notifications_showui = false; |
| 396 Notification.toggleIgnoreCategory("*", false); |
| 397 ok(!Prefs.notifications_showui, "Opt-out UI will not be shown if global opt-
out hasn't been enabled yet"); |
| 398 Notification.toggleIgnoreCategory("*", true); |
| 399 ok(Prefs.notifications_showui, "Opt-out UI will be shown after enabling glob
al opt-out"); |
| 400 Notification.toggleIgnoreCategory("*", false); |
| 401 ok(Prefs.notifications_showui, "Opt-out UI will be shown after enabling glob
al opt-out even if it got disabled again"); |
| 402 |
| 403 let information = fixConstructors({ |
| 404 id: 1, |
| 405 type: "information" |
| 406 }); |
| 407 let critical = fixConstructors({ |
| 408 id: 2, |
| 409 type: "critical" |
| 410 }); |
| 411 |
| 412 Notification.toggleIgnoreCategory("*", true); |
| 413 registerHandler([information]); |
| 414 testRunner.runScheduledTasks(1); |
| 415 |
| 416 deepEqual(Notification.getNextToShow(), null, "Information notifications are
ignored after enabling global opt-out"); |
| 417 Notification.toggleIgnoreCategory("*", false); |
| 418 deepEqual(Notification.getNextToShow(), information, "Information notificati
ons are shown after disabling global opt-out"); |
| 419 |
| 420 Notification.toggleIgnoreCategory("*", true); |
| 421 Prefs.notificationdata = {}; |
| 422 registerHandler([critical]); |
| 423 testRunner.runScheduledTasks(1); |
| 424 |
| 425 deepEqual(Notification.getNextToShow(), critical, "Critical notifications ar
e not ignored"); |
| 426 }); |
| 427 |
379 module("Notification localization"); | 428 module("Notification localization"); |
380 | 429 |
381 test("Message without localization", function() | 430 test("Message without localization", function() |
382 { | 431 { |
383 let notification = {message: "non-localized"}; | 432 let notification = {message: "non-localized"}; |
384 let texts = Notification.getLocalizedTexts(notification, "en-US"); | 433 let texts = Notification.getLocalizedTexts(notification, "en-US"); |
385 equal(texts.message, "non-localized"); | 434 equal(texts.message, "non-localized"); |
386 }); | 435 }); |
387 | 436 |
388 test("Language only", function() | 437 test("Language only", function() |
(...skipping 14 matching lines...) Expand all Loading... |
403 equal(texts.message, "fr"); | 452 equal(texts.message, "fr"); |
404 }); | 453 }); |
405 | 454 |
406 test("Missing translation", function() | 455 test("Missing translation", function() |
407 { | 456 { |
408 let notification = {message: {"en-US": "en-US"}}; | 457 let notification = {message: {"en-US": "en-US"}}; |
409 let texts = Notification.getLocalizedTexts(notification, "fr"); | 458 let texts = Notification.getLocalizedTexts(notification, "fr"); |
410 equal(texts.message, "en-US"); | 459 equal(texts.message, "en-US"); |
411 }); | 460 }); |
412 })(); | 461 })(); |
OLD | NEW |