1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/general/browser_notification_tab_switching.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + * http://creativecommons.org/publicdomain/zero/1.0/ 1.6 + */ 1.7 + 1.8 +"use strict"; 1.9 + 1.10 +let tab; 1.11 +let notification; 1.12 +let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html"; 1.13 + 1.14 +function test () { 1.15 + waitForExplicitFinish(); 1.16 + 1.17 + let pm = Services.perms; 1.18 + registerCleanupFunction(function() { 1.19 + pm.remove(notificationURL, "desktop-notification"); 1.20 + gBrowser.removeTab(tab); 1.21 + window.restore(); 1.22 + }); 1.23 + 1.24 + pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION); 1.25 + 1.26 + tab = gBrowser.addTab(notificationURL); 1.27 + tab.linkedBrowser.addEventListener("load", onLoad, true); 1.28 +} 1.29 + 1.30 +function onLoad() { 1.31 + isnot(gBrowser.selectedTab, tab, "Notification page loaded as a background tab"); 1.32 + tab.linkedBrowser.removeEventListener("load", onLoad, true); 1.33 + let win = tab.linkedBrowser.contentWindow.wrappedJSObject; 1.34 + notification = win.showNotification(); 1.35 + notification.addEventListener("show", onAlertShowing); 1.36 +} 1.37 + 1.38 +function onAlertShowing() { 1.39 + info("Notification alert showing"); 1.40 + notification.removeEventListener("show", onAlertShowing); 1.41 + 1.42 + let alertWindow = findChromeWindowByURI("chrome://global/content/alerts/alert.xul"); 1.43 + if (!alertWindow) { 1.44 + todo(false, "Notifications don't use XUL windows on all platforms."); 1.45 + notification.close(); 1.46 + finish(); 1.47 + return; 1.48 + } 1.49 + gBrowser.tabContainer.addEventListener("TabSelect", onTabSelect); 1.50 + EventUtils.synthesizeMouseAtCenter(alertWindow.document.getElementById("alertTitleLabel"), {}, alertWindow); 1.51 + info("Clicked on notification"); 1.52 + alertWindow.close(); 1.53 +} 1.54 + 1.55 +function onTabSelect() { 1.56 + gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect); 1.57 + is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL, 1.58 + "Notification tab should be selected."); 1.59 + 1.60 + finish(); 1.61 +}