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