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

Delta Between Two Patch Sets: chrome/content/tests/notification.js

Issue 5499340072157184: Issue 2420 - Update notification tests (Closed)
Left Patch Set: Created June 8, 2015, 11:37 a.m.
Right Patch Set: Rebased, addressed comments Created June 8, 2015, 7:35 p.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 | « no previous file | 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 (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 function showNotifications(url) 9 function showNotifications(url)
10 { 10 {
11 let shownNotifications = []; 11 let shownNotifications = [];
12 function showListener(notification) 12 function showListener(notification)
13 { 13 {
14 shownNotifications.push(notification); 14 shownNotifications.push(notification);
15 Notification.markAsShown(notification.id);
15 } 16 }
16 Notification.addShowListener(showListener); 17 Notification.addShowListener(showListener);
17 Notification.showNext(url); 18 Notification.showNext(url);
18 Notification.removeShowListener(showListener); 19 Notification.removeShowListener(showListener);
19 shownNotifications.forEach(function(notification)
20 {
21 Notification.markAsShown(notification.id);
Wladimir Palant 2015/06/08 11:45:21 Shouldn't this be called in showListener above?
Felix Dahlke 2015/06/08 19:36:53 Done.
22 });
23 return shownNotifications; 20 return shownNotifications;
24 } 21 }
25 22
26 module("Notification handling", 23 module("Notification handling",
27 { 24 {
28 setup: function() 25 setup: function()
29 { 26 {
30 testRunner = this; 27 testRunner = this;
31 28
32 preparePrefs.call(this); 29 preparePrefs.call(this);
(...skipping 18 matching lines...) Expand all
51 Prefs.notificationurl = "http://example.com/notification.json"; 48 Prefs.notificationurl = "http://example.com/notification.json";
52 Prefs.notificationdata = {}; 49 Prefs.notificationdata = {};
53 Prefs.notifications_ignoredcategories = []; 50 Prefs.notifications_ignoredcategories = [];
54 51
55 // Replace Math.random() function 52 // Replace Math.random() function
56 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader") ); 53 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader") );
57 this._origRandom = DownloaderGlobal.Math.random; 54 this._origRandom = DownloaderGlobal.Math.random;
58 DownloaderGlobal.Math.random = () => randomResult; 55 DownloaderGlobal.Math.random = () => randomResult;
59 randomResult = 0.5; 56 randomResult = 0.5;
60 57
61 Notification.removeAllShowListeners(); 58 let NotificationGlobal = getModuleGlobal("notification");
Wladimir Palant 2015/06/08 11:45:21 Better save the old listeners and restore them in
Felix Dahlke 2015/06/08 19:36:53 Done.
59 this._origShowListeners = NotificationGlobal.showListeners;
60 NotificationGlobal.showListeners = [];
62 }, 61 },
63 62
64 teardown: function() 63 teardown: function()
65 { 64 {
66 restorePrefs.call(this); 65 restorePrefs.call(this);
67 restoreVirtualTime.call(this); 66 restoreVirtualTime.call(this);
68 restoreVirtualXMLHttp.call(this); 67 restoreVirtualXMLHttp.call(this);
69 68
70 for (let key in originalInfo) 69 for (let key in originalInfo)
71 info[key] = originalInfo[key]; 70 info[key] = originalInfo[key];
72 71
73 if (this._origRandom) 72 if (this._origRandom)
74 { 73 {
75 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader ")); 74 let DownloaderGlobal = Cu.getGlobalForObject(getModuleGlobal("downloader "));
76 DownloaderGlobal.Math.random = this._origRandom; 75 DownloaderGlobal.Math.random = this._origRandom;
77 delete this._origRandom; 76 delete this._origRandom;
77 }
78
79 if (this._origShowListeners)
80 {
81 let NotificationGlobal = getModuleGlobal("notification");
82 NotificationGlobal.showListeners = this._origShowListeners;
83 delete this._origShowListeners;
78 } 84 }
79 85
80 Notification.init(); 86 Notification.init();
81 } 87 }
82 }); 88 });
83 89
84 function registerHandler(notifications, checkCallback) 90 function registerHandler(notifications, checkCallback)
85 { 91 {
86 testRunner.registerHandler("/notification.json", function(metadata) 92 testRunner.registerHandler("/notification.json", function(metadata)
87 { 93 {
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 }); 431 });
426 let critical = fixConstructors({ 432 let critical = fixConstructors({
427 id: 2, 433 id: 2,
428 type: "critical" 434 type: "critical"
429 }); 435 });
430 436
431 Notification.toggleIgnoreCategory("*", true); 437 Notification.toggleIgnoreCategory("*", true);
432 registerHandler([information]); 438 registerHandler([information]);
433 testRunner.runScheduledTasks(1); 439 testRunner.runScheduledTasks(1);
434 440
435 deepEqual(Notification.getNextToShow(), null, "Information notifications are ignored after enabling global opt-out"); 441 deepEqual(showNotifications(), [], "Information notifications are ignored af ter enabling global opt-out");
Felix Dahlke 2015/06/08 19:36:53 This and the following changes are the result of r
436 Notification.toggleIgnoreCategory("*", false); 442 Notification.toggleIgnoreCategory("*", false);
437 deepEqual(Notification.getNextToShow(), information, "Information notificati ons are shown after disabling global opt-out"); 443 deepEqual(showNotifications(), [information], "Information notifications are shown after disabling global opt-out");
438 444
439 Notification.toggleIgnoreCategory("*", true); 445 Notification.toggleIgnoreCategory("*", true);
440 Prefs.notificationdata = {}; 446 Prefs.notificationdata = {};
441 registerHandler([critical]); 447 registerHandler([critical]);
442 testRunner.runScheduledTasks(1); 448 testRunner.runScheduledTasks(1);
443 449
444 deepEqual(Notification.getNextToShow(), critical, "Critical notifications ar e not ignored"); 450 deepEqual(showNotifications(), [critical], "Critical notifications are not i gnored");
445 }); 451 });
446 452
447 module("Notification localization"); 453 module("Notification localization");
448 454
449 test("Message without localization", function() 455 test("Message without localization", function()
450 { 456 {
451 let notification = {message: "non-localized"}; 457 let notification = {message: "non-localized"};
452 let texts = Notification.getLocalizedTexts(notification, "en-US"); 458 let texts = Notification.getLocalizedTexts(notification, "en-US");
453 equal(texts.message, "non-localized"); 459 equal(texts.message, "non-localized");
454 }); 460 });
(...skipping 16 matching lines...) Expand all
471 equal(texts.message, "fr"); 477 equal(texts.message, "fr");
472 }); 478 });
473 479
474 test("Missing translation", function() 480 test("Missing translation", function()
475 { 481 {
476 let notification = {message: {"en-US": "en-US"}}; 482 let notification = {message: {"en-US": "en-US"}};
477 let texts = Notification.getLocalizedTexts(notification, "fr"); 483 let texts = Notification.getLocalizedTexts(notification, "fr");
478 equal(texts.message, "en-US"); 484 equal(texts.message, "en-US");
479 }); 485 });
480 })(); 486 })();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld