|
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(); |
|
13 |
|
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"); |
|
24 |
|
25 var chromeWin = SpecialPowers.wrap(aWindow) |
|
26 .QueryInterface(Ci.nsIInterfaceRequestor) |
|
27 .getInterface(Ci.nsIWebNavigation) |
|
28 .QueryInterface(Ci.nsIDocShell) |
|
29 .chromeEventHandler.ownerDocument.defaultView; |
|
30 |
|
31 var popupNotifications = chromeWin.PopupNotifications; |
|
32 return popupNotifications; |
|
33 } |
|
34 |
|
35 |
|
36 /* |
|
37 * getPopup |
|
38 * |
|
39 */ |
|
40 function getPopup(aPopupNote, aKind) { |
|
41 ok(true, "Looking for " + aKind + " popup notification"); |
|
42 return aPopupNote.getNotification(aKind); |
|
43 } |
|
44 |
|
45 |
|
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); |
|
53 |
|
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]; |
|
58 |
|
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 } |
|
68 |
|
69 const kRememberButton = 0; |
|
70 const kNeverButton = 1; |
|
71 |
|
72 const kChangeButton = 0; |
|
73 const kDontChangeButton = 1; |
|
74 |
|
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 } |
|
85 |
|
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 } |