michael@0: /* michael@0: * Initialization: for each test, remove any prior notifications. michael@0: */ michael@0: function cleanUpPopupNotifications() { michael@0: var container = getPopupNotifications(window.top); michael@0: var notes = container._currentNotifications; michael@0: info(true, "Removing " + notes.length + " popup notifications."); michael@0: for (var i = notes.length-1; i >= 0; i--) { michael@0: notes[i].remove(); michael@0: } michael@0: } michael@0: cleanUpPopupNotifications(); michael@0: michael@0: /* michael@0: * getPopupNotifications michael@0: * michael@0: * Fetches the popup notification for the specified window. michael@0: */ michael@0: function getPopupNotifications(aWindow) { michael@0: var Ci = SpecialPowers.Ci; michael@0: var Cc = SpecialPowers.Cc; michael@0: ok(Ci != null, "Access Ci"); michael@0: ok(Cc != null, "Access Cc"); michael@0: michael@0: var chromeWin = SpecialPowers.wrap(aWindow) michael@0: .QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsIDocShell) michael@0: .chromeEventHandler.ownerDocument.defaultView; michael@0: michael@0: var popupNotifications = chromeWin.PopupNotifications; michael@0: return popupNotifications; michael@0: } michael@0: michael@0: michael@0: /* michael@0: * getPopup michael@0: * michael@0: */ michael@0: function getPopup(aPopupNote, aKind) { michael@0: ok(true, "Looking for " + aKind + " popup notification"); michael@0: return aPopupNote.getNotification(aKind); michael@0: } michael@0: michael@0: michael@0: /* michael@0: * clickPopupButton michael@0: * michael@0: * Clicks the specified popup notification button. michael@0: */ michael@0: function clickPopupButton(aPopup, aButtonIndex) { michael@0: ok(true, "Looking for action at index " + aButtonIndex); michael@0: michael@0: var notifications = SpecialPowers.wrap(aPopup.owner).panel.childNodes; michael@0: ok(notifications.length > 0, "at least one notification displayed"); michael@0: ok(true, notifications.length + " notifications"); michael@0: var notification = notifications[0]; michael@0: michael@0: if (aButtonIndex == 0) { michael@0: ok(true, "Triggering main action"); michael@0: notification.button.doCommand(); michael@0: } else if (aButtonIndex <= aPopup.secondaryActions.length) { michael@0: var index = aButtonIndex - 1; michael@0: ok(true, "Triggering secondary action " + index); michael@0: notification.childNodes[index].doCommand(); michael@0: } michael@0: } michael@0: michael@0: const kRememberButton = 0; michael@0: const kNeverButton = 1; michael@0: michael@0: const kChangeButton = 0; michael@0: const kDontChangeButton = 1; michael@0: michael@0: function dumpNotifications() { michael@0: try { michael@0: // PopupNotifications michael@0: var container = getPopupNotifications(window.top); michael@0: ok(true, "is popup panel open? " + container.isPanelOpen); michael@0: var notes = container._currentNotifications; michael@0: ok(true, "Found " + notes.length + " popup notifications."); michael@0: for (var i = 0; i < notes.length; i++) { michael@0: ok(true, "#" + i + ": " + notes[i].id); michael@0: } michael@0: michael@0: // Notification bars michael@0: var chromeWin = SpecialPowers.wrap(window.top) michael@0: .QueryInterface(Ci.nsIInterfaceRequestor) michael@0: .getInterface(Ci.nsIWebNavigation) michael@0: .QueryInterface(Ci.nsIDocShell) michael@0: .chromeEventHandler.ownerDocument.defaultView; michael@0: var nb = chromeWin.getNotificationBox(window.top); michael@0: var notes = nb.allNotifications; michael@0: ok(true, "Found " + notes.length + " notification bars."); michael@0: for (var i = 0; i < notes.length; i++) { michael@0: ok(true, "#" + i + ": " + notes[i].getAttribute("value")); michael@0: } michael@0: } catch(e) { todo(false, "WOAH! " + e); } michael@0: }