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

Unified Diff: chrome/content/tests/notification.js

Issue 5499340072157184: Issue 2420 - Update notification tests (Closed)
Patch Set: Created June 8, 2015, 11:37 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/content/tests/notification.js
===================================================================
--- a/chrome/content/tests/notification.js
+++ b/chrome/content/tests/notification.js
@@ -6,6 +6,23 @@
let originalInfo;
let info = require("info");
+ function showNotifications(url)
+ {
+ let shownNotifications = [];
+ function showListener(notification)
+ {
+ shownNotifications.push(notification);
+ }
+ Notification.addShowListener(showListener);
+ Notification.showNext(url);
+ Notification.removeShowListener(showListener);
+ shownNotifications.forEach(function(notification)
+ {
+ 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.
+ });
+ return shownNotifications;
+ }
+
module("Notification handling",
{
setup: function()
@@ -40,6 +57,8 @@
this._origRandom = DownloaderGlobal.Math.random;
DownloaderGlobal.Math.random = () => randomResult;
randomResult = 0.5;
+
+ Notification.removeAllShowListeners();
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.
},
teardown: function()
@@ -89,7 +108,7 @@
test("No data", function()
{
- equal(Notification.getNextToShow(), null, "null should be returned if there is no data");
+ deepEqual(showNotifications(), [], "No notifications should be returned if there is no data");
});
test("Single notification", function()
@@ -103,8 +122,8 @@
registerHandler([information]);
testRunner.runScheduledTasks(1);
- deepEqual(Notification.getNextToShow(), information, "The notification is shown");
- equal(Notification.getNextToShow(), null, "Informational notifications aren't shown more than once");
+ deepEqual(showNotifications(), [information], "The notification is shown");
+ deepEqual(showNotifications(), [], "Informational notifications aren't shown more than once");
});
test("Information and critical", function()
@@ -123,8 +142,8 @@
registerHandler([information, critical]);
testRunner.runScheduledTasks(1);
- deepEqual(Notification.getNextToShow(), critical, "The critical notification is given priority");
- deepEqual(Notification.getNextToShow(), critical, "Critical notifications can be shown multiple times");
+ deepEqual(showNotifications(), [critical], "The critical notification is given priority");
+ deepEqual(showNotifications(), [critical], "Critical notifications can be shown multiple times");
});
test("No type", function()
@@ -137,8 +156,8 @@
registerHandler([information]);
testRunner.runScheduledTasks(1);
- deepEqual(Notification.getNextToShow(), information, "The notification is shown");
- equal(Notification.getNextToShow(), null, "Notification is treated as type information");
+ deepEqual(showNotifications(), [information], "The notification is shown");
+ deepEqual(showNotifications(), [], "Notification is treated as type information");
});
test("Target selection", function()
@@ -194,9 +213,9 @@
registerHandler([information]);
testRunner.runScheduledTasks(1);
- let expected = (result ? information : null);
- deepEqual(Notification.getNextToShow(), expected, "Selected notification for " + JSON.stringify(information.targets));
- deepEqual(Notification.getNextToShow(), null, "No notification on second call");
+ let expected = (result ? [information] : []);
+ deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets));
+ deepEqual(showNotifications(), [], "No notification on second call");
}
function pairs(array)
@@ -223,9 +242,9 @@
registerHandler([information]);
testRunner.runScheduledTasks(1);
- let expected = (result1 || result2 ? information : null)
- deepEqual(Notification.getNextToShow(), expected, "Selected notification for " + JSON.stringify(information.targets));
- deepEqual(Notification.getNextToShow(), null, "No notification on second call");
+ let expected = (result1 || result2 ? [information] : [])
+ deepEqual(showNotifications(), expected, "Selected notification for " + JSON.stringify(information.targets));
+ deepEqual(showNotifications(), [], "No notification on second call");
information = fixConstructors({
id: 1,
@@ -244,8 +263,8 @@
registerHandler([information, critical]);
testRunner.runScheduledTasks(1);
- expected = (result2 ? critical : (result1 ? information : null));
- deepEqual(Notification.getNextToShow(), expected, "Selected notification for information with " + JSON.stringify(information.targets) + " and critical with " + JSON.stringify(critical.targets));
+ expected = (result2 ? [critical] : (result1 ? [information] : []));
+ deepEqual(showNotifications(), expected, "Selected notification for information with " + JSON.stringify(information.targets) + " and critical with " + JSON.stringify(critical.targets));
}
});
@@ -371,10 +390,10 @@
]);
testRunner.runScheduledTasks(1);
- deepEqual(Notification.getNextToShow(), withoutURLFilter, "URL-specific notifications are skipped");
- deepEqual(Notification.getNextToShow("http://foo.com"), withURLFilterFoo, "URL-specific notification is retrieved");
- deepEqual(Notification.getNextToShow("http://foo.com"), null, "URL-specific notification is not retrieved");
- deepEqual(Notification.getNextToShow("http://www.example.com"), subdomainURLFilter, "URL-specific notification matches subdomain");
+ deepEqual(showNotifications(), [withoutURLFilter], "URL-specific notifications are skipped");
+ deepEqual(showNotifications("http://foo.com"), [withURLFilterFoo], "URL-specific notification is retrieved");
+ deepEqual(showNotifications("http://foo.com"), [], "URL-specific notification is not retrieved");
+ deepEqual(showNotifications("http://www.example.com"), [subdomainURLFilter], "URL-specific notification matches subdomain");
});
test("Global opt-out", function()
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld