|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 "use strict"; |
|
6 |
|
7 let tab; |
|
8 let notification; |
|
9 let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html"; |
|
10 |
|
11 function test () { |
|
12 waitForExplicitFinish(); |
|
13 |
|
14 let pm = Services.perms; |
|
15 registerCleanupFunction(function() { |
|
16 pm.remove(notificationURL, "desktop-notification"); |
|
17 gBrowser.removeTab(tab); |
|
18 window.restore(); |
|
19 }); |
|
20 |
|
21 pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION); |
|
22 |
|
23 tab = gBrowser.addTab(notificationURL); |
|
24 tab.linkedBrowser.addEventListener("load", onLoad, true); |
|
25 } |
|
26 |
|
27 function onLoad() { |
|
28 isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab"); |
|
29 tab.linkedBrowser.removeEventListener("load", onLoad, true); |
|
30 let win = tab.linkedBrowser.contentWindow.wrappedJSObject; |
|
31 notification = win.showNotification(); |
|
32 notification.addEventListener("show", onAlertShowing); |
|
33 } |
|
34 |
|
35 function onAlertShowing() { |
|
36 info("Notification alert showing"); |
|
37 notification.removeEventListener("show", onAlertShowing); |
|
38 |
|
39 let alertWindow = findChromeWindowByURI("chrome://global/content/alerts/alert.xul"); |
|
40 if (!alertWindow) { |
|
41 todo(false, "Notifications don't use XUL windows on all platforms."); |
|
42 notification.close(); |
|
43 finish(); |
|
44 return; |
|
45 } |
|
46 gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect); |
|
47 EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow); |
|
48 info("Clicked on notification"); |
|
49 alertWindow.close(); |
|
50 } |
|
51 |
|
52 function onTabSelect() { |
|
53 gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect); |
|
54 is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL, |
|
55 "Notification tab should be selected."); |
|
56 |
|
57 finish(); |
|
58 } |