browser/base/content/test/general/browser_notification_tab_switching.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* Any copyright is dedicated to the Public Domain.
     2  * http://creativecommons.org/publicdomain/zero/1.0/
     3  */
     5 "use strict";
     7 let tab;
     8 let notification;
     9 let notificationURL = "http://example.org/browser/browser/base/content/test/general/file_dom_notifications.html";
    11 function test () {
    12   waitForExplicitFinish();
    14   let pm = Services.perms;
    15   registerCleanupFunction(function() {
    16     pm.remove(notificationURL, "desktop-notification");
    17     gBrowser.removeTab(tab);
    18     window.restore();
    19   });
    21   pm.add(makeURI(notificationURL), "desktop-notification", pm.ALLOW_ACTION);
    23   tab = gBrowser.addTab(notificationURL);
    24   tab.linkedBrowser.addEventListener("load", onLoad, true);
    25 }
    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 }
    35 function onAlertShowing() {
    36   info("Notification alert showing");
    37   notification.removeEventListener("show", onAlertShowing);
    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 }
    52 function onTabSelect() {
    53   gBrowser.tabContainer.removeEventListener("TabSelect", onTabSelect);
    54   is(gBrowser.selectedTab.linkedBrowser.contentWindow.location.href, notificationURL,
    55      "Notification tab should be selected.");
    57   finish();
    58 }

mercurial