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.

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

mercurial