toolkit/components/passwordmgr/test/notification_common.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 /*
     2  * Initialization: for each test, remove any prior notifications.
     3  */
     4 function cleanUpPopupNotifications() {
     5     var container = getPopupNotifications(window.top);
     6     var notes = container._currentNotifications;
     7     info(true, "Removing " + notes.length + " popup notifications.");
     8     for (var i = notes.length-1; i >= 0; i--) {
     9 	notes[i].remove();
    10     }
    11 }
    12 cleanUpPopupNotifications();
    14 /*
    15  * getPopupNotifications
    16  *
    17  * Fetches the popup notification for the specified window.
    18  */
    19 function getPopupNotifications(aWindow) {
    20     var Ci = SpecialPowers.Ci;
    21     var Cc = SpecialPowers.Cc;
    22     ok(Ci != null, "Access Ci");
    23     ok(Cc != null, "Access Cc");
    25     var chromeWin = SpecialPowers.wrap(aWindow)
    26                                  .QueryInterface(Ci.nsIInterfaceRequestor)
    27                                  .getInterface(Ci.nsIWebNavigation)
    28                                  .QueryInterface(Ci.nsIDocShell)
    29                                  .chromeEventHandler.ownerDocument.defaultView;
    31     var popupNotifications = chromeWin.PopupNotifications;
    32     return popupNotifications;
    33 }
    36 /*
    37  * getPopup
    38  *
    39  */
    40 function getPopup(aPopupNote, aKind) {
    41     ok(true, "Looking for " + aKind + " popup notification");
    42     return aPopupNote.getNotification(aKind);
    43 }
    46 /*
    47  * clickPopupButton
    48  *
    49  * Clicks the specified popup notification button.
    50  */
    51 function clickPopupButton(aPopup, aButtonIndex) {
    52     ok(true, "Looking for action at index " + aButtonIndex);
    54     var notifications = SpecialPowers.wrap(aPopup.owner).panel.childNodes;
    55     ok(notifications.length > 0, "at least one notification displayed");
    56     ok(true, notifications.length + " notifications");
    57     var notification = notifications[0];
    59     if (aButtonIndex == 0) {
    60         ok(true, "Triggering main action");
    61         notification.button.doCommand();
    62     } else if (aButtonIndex <= aPopup.secondaryActions.length) {
    63         var index = aButtonIndex - 1;
    64         ok(true, "Triggering secondary action " + index);
    65         notification.childNodes[index].doCommand();
    66     }
    67 }
    69 const kRememberButton = 0;
    70 const kNeverButton = 1;
    72 const kChangeButton = 0;
    73 const kDontChangeButton = 1;
    75 function dumpNotifications() {
    76   try {
    77     // PopupNotifications
    78     var container = getPopupNotifications(window.top);
    79     ok(true, "is popup panel open? " + container.isPanelOpen);
    80     var notes = container._currentNotifications;
    81     ok(true, "Found " + notes.length + " popup notifications.");
    82     for (var i = 0; i < notes.length; i++) {
    83         ok(true, "#" + i + ": " + notes[i].id);
    84     }
    86     // Notification bars
    87     var chromeWin = SpecialPowers.wrap(window.top)
    88                            .QueryInterface(Ci.nsIInterfaceRequestor)
    89                            .getInterface(Ci.nsIWebNavigation)
    90                            .QueryInterface(Ci.nsIDocShell)
    91                            .chromeEventHandler.ownerDocument.defaultView;
    92     var nb = chromeWin.getNotificationBox(window.top);
    93     var notes = nb.allNotifications;
    94     ok(true, "Found " + notes.length + " notification bars.");
    95     for (var i = 0; i < notes.length; i++) {
    96         ok(true, "#" + i + ": " + notes[i].getAttribute("value"));
    97     }
    98   } catch(e) { todo(false, "WOAH! " + e); }
    99 }

mercurial