1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/passwordmgr/test/notification_common.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,99 @@ 1.4 +/* 1.5 + * Initialization: for each test, remove any prior notifications. 1.6 + */ 1.7 +function cleanUpPopupNotifications() { 1.8 + var container = getPopupNotifications(window.top); 1.9 + var notes = container._currentNotifications; 1.10 + info(true, "Removing " + notes.length + " popup notifications."); 1.11 + for (var i = notes.length-1; i >= 0; i--) { 1.12 + notes[i].remove(); 1.13 + } 1.14 +} 1.15 +cleanUpPopupNotifications(); 1.16 + 1.17 +/* 1.18 + * getPopupNotifications 1.19 + * 1.20 + * Fetches the popup notification for the specified window. 1.21 + */ 1.22 +function getPopupNotifications(aWindow) { 1.23 + var Ci = SpecialPowers.Ci; 1.24 + var Cc = SpecialPowers.Cc; 1.25 + ok(Ci != null, "Access Ci"); 1.26 + ok(Cc != null, "Access Cc"); 1.27 + 1.28 + var chromeWin = SpecialPowers.wrap(aWindow) 1.29 + .QueryInterface(Ci.nsIInterfaceRequestor) 1.30 + .getInterface(Ci.nsIWebNavigation) 1.31 + .QueryInterface(Ci.nsIDocShell) 1.32 + .chromeEventHandler.ownerDocument.defaultView; 1.33 + 1.34 + var popupNotifications = chromeWin.PopupNotifications; 1.35 + return popupNotifications; 1.36 +} 1.37 + 1.38 + 1.39 +/* 1.40 + * getPopup 1.41 + * 1.42 + */ 1.43 +function getPopup(aPopupNote, aKind) { 1.44 + ok(true, "Looking for " + aKind + " popup notification"); 1.45 + return aPopupNote.getNotification(aKind); 1.46 +} 1.47 + 1.48 + 1.49 +/* 1.50 + * clickPopupButton 1.51 + * 1.52 + * Clicks the specified popup notification button. 1.53 + */ 1.54 +function clickPopupButton(aPopup, aButtonIndex) { 1.55 + ok(true, "Looking for action at index " + aButtonIndex); 1.56 + 1.57 + var notifications = SpecialPowers.wrap(aPopup.owner).panel.childNodes; 1.58 + ok(notifications.length > 0, "at least one notification displayed"); 1.59 + ok(true, notifications.length + " notifications"); 1.60 + var notification = notifications[0]; 1.61 + 1.62 + if (aButtonIndex == 0) { 1.63 + ok(true, "Triggering main action"); 1.64 + notification.button.doCommand(); 1.65 + } else if (aButtonIndex <= aPopup.secondaryActions.length) { 1.66 + var index = aButtonIndex - 1; 1.67 + ok(true, "Triggering secondary action " + index); 1.68 + notification.childNodes[index].doCommand(); 1.69 + } 1.70 +} 1.71 + 1.72 +const kRememberButton = 0; 1.73 +const kNeverButton = 1; 1.74 + 1.75 +const kChangeButton = 0; 1.76 +const kDontChangeButton = 1; 1.77 + 1.78 +function dumpNotifications() { 1.79 + try { 1.80 + // PopupNotifications 1.81 + var container = getPopupNotifications(window.top); 1.82 + ok(true, "is popup panel open? " + container.isPanelOpen); 1.83 + var notes = container._currentNotifications; 1.84 + ok(true, "Found " + notes.length + " popup notifications."); 1.85 + for (var i = 0; i < notes.length; i++) { 1.86 + ok(true, "#" + i + ": " + notes[i].id); 1.87 + } 1.88 + 1.89 + // Notification bars 1.90 + var chromeWin = SpecialPowers.wrap(window.top) 1.91 + .QueryInterface(Ci.nsIInterfaceRequestor) 1.92 + .getInterface(Ci.nsIWebNavigation) 1.93 + .QueryInterface(Ci.nsIDocShell) 1.94 + .chromeEventHandler.ownerDocument.defaultView; 1.95 + var nb = chromeWin.getNotificationBox(window.top); 1.96 + var notes = nb.allNotifications; 1.97 + ok(true, "Found " + notes.length + " notification bars."); 1.98 + for (var i = 0; i < notes.length; i++) { 1.99 + ok(true, "#" + i + ": " + notes[i].getAttribute("value")); 1.100 + } 1.101 + } catch(e) { todo(false, "WOAH! " + e); } 1.102 +}