summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html')
-rw-r--r--dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html110
1 files changed, 110 insertions, 0 deletions
diff --git a/dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html b/dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html
new file mode 100644
index 000000000..37bcb16c0
--- /dev/null
+++ b/dom/tests/mochitest/notification/desktop-notification/test_notification_tag.html
@@ -0,0 +1,110 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=782211
+-->
+<head>
+ <title>Bug 782211</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=782211">Bug 782211</a>
+<p id="display"></p>
+<iframe name="sameDomain"></iframe>
+<iframe name="anotherSameDomain"></iframe>
+<iframe name="crossDomain"></iframe>
+<div id="content" style="display: none">
+</div>
+<pre id="test">
+</pre>
+<script type="text/javascript">
+ const MOCK_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{dbe37e64-d9a3-402c-8d8a-0826c619f7ad}");
+ const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
+
+ var mockAlertsService = {
+ showAlert: function(alert, alertListener) {
+ notificationsCreated.push(alert.name);
+ if (notificationsCreated.length == 3) {
+ checkNotifications();
+ }
+ },
+
+ showAlertNotification: function(imageUrl, title, text, textClickable,
+ cookie, alertListener, name, dir,
+ lang, data) {
+ this.showAlert({ name: name });
+ },
+
+ QueryInterface: function(aIID) {
+ if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) ||
+ SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService)) {
+ return this;
+ }
+ throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
+ },
+
+ createInstance: function(aOuter, aIID) {
+ if (aOuter != null) {
+ throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION;
+ }
+ return this.QueryInterface(aIID);
+ }
+ };
+ mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService);
+
+ var notificationsCreated = [];
+ function checkNotifications() {
+ // notifications created by the test1 origin
+ var test1notifications = [];
+ // notifications created by the test2 origin
+ var test2notifications = [];
+ for (var i = 0; i < notificationsCreated.length; i++) {
+ var notificationName = notificationsCreated[i];
+ if (notificationName.indexOf("test1") !== -1) {
+ test1notifications.push(notificationsCreated[i]);
+ } else if (notificationName.indexOf("test2") !== -1) {
+ test2notifications.push(notificationsCreated[i]);
+ }
+ }
+
+ is(test1notifications.length, 2, "2 notifications should be created by test1.example.org:80 origin.");
+ is(test1notifications[0], test1notifications[1], "notification names should be identical.");
+ is(test2notifications.length, 1, "1 notification should be created by test2.example.org:80 origin.");
+
+ // Register original alerts service.
+ SpecialPowers.wrap(SpecialPowers.Components).
+ manager.QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar).
+ unregisterFactory(MOCK_CID, mockAlertsService);
+
+ SimpleTest.finish();
+ }
+
+ if (window.Notification) {
+ SimpleTest.waitForExplicitFinish();
+
+ function showNotifications() {
+ SpecialPowers.wrap(SpecialPowers.Components).
+ manager.QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar).
+ registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
+
+ // Load two frames with the same origin that create notification with the same tag.
+ // Both pages should generate notifications with the same name, and thus the second
+ // notification should replace the first.
+ frames["sameDomain"].location.href = "http://test1.example.org:80/tests/dom/tests/mochitest/notification/create_notification.html";
+ frames["anotherSameDomain"].location.href = "http://test1.example.org:80/tests/dom/tests/mochitest/notification/create_notification.html";
+
+ // Load a frame with a different origin that creates a notification with the same tag.
+ // The notification name should be different and thus no notifications should be replaced.
+ frames["crossDomain"].location.href = "http://test2.example.org:80/tests/dom/tests/mochitest/notification/create_notification.html";
+ }
+
+ SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true],
+ ["notification.prompt.testing.allow", true]]},
+ showNotifications);
+ } else {
+ ok(true, "Notifications are not enabled on the platform.");
+ }
+</script>
+</body>
+</html>