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

Side by Side Diff: chrome/content/tests/notification.js

Issue 5654617534758912: Issue 2237 - Added unit tests for notification opt-out (Closed)
Patch Set: Created April 13, 2015, 3:55 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 Prefs.notifications_showui = false;
383
384 Notification.toggleIgnoreCategory("*", true);
385
386 ok(Prefs.notifications_showui, "Opt-out UI will be shown after opt-out");
387
388 let information = fixConstructors({
389 id: 1,
390 type: "information"
391 });
392 let critical = fixConstructors({
393 id: 2,
394 type: "critical"
395 });
396
397 registerHandler([information]);
398 testRunner.runScheduledTasks(1);
399
400 deepEqual(Notification.getNextToShow(), null, "Information notifications are ignored");
401
402 Prefs.notificationdata = {};
403 registerHandler([critical]);
404 testRunner.runScheduledTasks(1);
405
406 deepEqual(Notification.getNextToShow(), critical, "Critical notifications ar e not ignored");
Wladimir Palant 2015/05/26 11:23:19 This test is incomplete. Following scenarios need
Thomas Greiner 2015/05/28 13:24:18 Done, thanks for the additions. Note that the exi
407 });
408
379 module("Notification localization"); 409 module("Notification localization");
380 410
381 test("Message without localization", function() 411 test("Message without localization", function()
382 { 412 {
383 let notification = {message: "non-localized"}; 413 let notification = {message: "non-localized"};
384 let texts = Notification.getLocalizedTexts(notification, "en-US"); 414 let texts = Notification.getLocalizedTexts(notification, "en-US");
385 equal(texts.message, "non-localized"); 415 equal(texts.message, "non-localized");
386 }); 416 });
387 417
388 test("Language only", function() 418 test("Language only", function()
(...skipping 14 matching lines...) Expand all
403 equal(texts.message, "fr"); 433 equal(texts.message, "fr");
404 }); 434 });
405 435
406 test("Missing translation", function() 436 test("Missing translation", function()
407 { 437 {
408 let notification = {message: {"en-US": "en-US"}}; 438 let notification = {message: {"en-US": "en-US"}};
409 let texts = Notification.getLocalizedTexts(notification, "fr"); 439 let texts = Notification.getLocalizedTexts(notification, "fr");
410 equal(texts.message, "en-US"); 440 equal(texts.message, "en-US");
411 }); 441 });
412 })(); 442 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld