michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: "use strict"; michael@0: michael@0: let tab; michael@0: let notification; michael@0: let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html"; michael@0: michael@0: function test () { michael@0: waitForExplicitFinish(); michael@0: michael@0: let pm = Services.perms; michael@0: registerCleanupFunction(function() { michael@0: pm.remove(notificationURL, "desktop-notification"); michael@0: gBrowser.removeTab(tab); michael@0: window.restore(); michael@0: }); michael@0: michael@0: pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION); michael@0: michael@0: tab = gBrowser.addTab(notificationURL); michael@0: tab.linkedBrowser.addEventListener("load", onLoad, true); michael@0: } michael@0: michael@0: function onLoad() { michael@0: isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab"); michael@0: tab.linkedBrowser.removeEventListener("load", onLoad, true); michael@0: let win = tab.linkedBrowser.contentWindow.wrappedJSObject; michael@0: notification = win.showNotification(); michael@0: notification.addEventListener("show", onAlertShowing); michael@0: } michael@0: michael@0: function onAlertShowing() { michael@0: info("Notification alert showing"); michael@0: notification.removeEventListener("show", onAlertShowing); michael@0: michael@0: let alertWindow = findChromeWindowByURI("chrome://global/content/alerts/alert.xul"); michael@0: if (!alertWindow) { michael@0: todo(false, "Notifications don't use XUL windows on all platforms."); michael@0: notification.close(); michael@0: finish(); michael@0: return; michael@0: } michael@0: gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect); michael@0: EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow); michael@0: info("Clicked on notification"); michael@0: alertWindow.close(); michael@0: } michael@0: michael@0: function onTabSelect() { michael@0: gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect); michael@0: is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL, michael@0: "Notification tab should be selected."); michael@0: michael@0: finish(); michael@0: }