1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function test() {
waitForExplicitFinish();
ok(PopupNotifications, "PopupNotifications object exists");
ok(PopupNotifications.panel, "PopupNotifications panel exists");
setup();
goNext();
}
var tests = [
// Test optional params
{ id: "Test#1",
run: function () {
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.secondaryActions = undefined;
this.notification = showNotification(this.notifyObj);
},
onShown: function (popup) {
checkPopup(popup, this.notifyObj);
dismissNotification(popup);
},
onHidden: function (popup) {
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
this.notification.remove();
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
}
},
// Test that icons appear
{ id: "Test#2",
run: function () {
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.id = "geolocation";
this.notifyObj.anchorID = "geo-notification-icon";
this.notification = showNotification(this.notifyObj);
},
onShown: function (popup) {
checkPopup(popup, this.notifyObj);
isnot(document.getElementById("geo-notification-icon").boxObject.width, 0,
"geo anchor should be visible");
dismissNotification(popup);
},
onHidden: function (popup) {
let icon = document.getElementById("geo-notification-icon");
isnot(icon.boxObject.width, 0,
"geo anchor should be visible after dismissal");
this.notification.remove();
is(icon.boxObject.width, 0,
"geo anchor should not be visible after removal");
}
},
// Test that persistence allows the notification to persist across reloads
{ id: "Test#3",
run: function* () {
this.oldSelectedTab = gBrowser.selectedTab;
gBrowser.selectedTab = gBrowser.addTab("about:blank");
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.com/");
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.addOptions({
persistence: 2
});
this.notification = showNotification(this.notifyObj);
},
onShown: function* (popup) {
this.complete = false;
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.org/");
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.com/")
// Next load will remove the notification
this.complete = true;
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.org/");
},
onHidden: function (popup) {
ok(this.complete, "Should only have hidden the notification after 3 page loads");
ok(this.notifyObj.removedCallbackTriggered, "removal callback triggered");
gBrowser.removeTab(gBrowser.selectedTab);
gBrowser.selectedTab = this.oldSelectedTab;
}
},
// Test that a timeout allows the notification to persist across reloads
{ id: "Test#4",
run: function* () {
this.oldSelectedTab = gBrowser.selectedTab;
gBrowser.selectedTab = gBrowser.addTab("about:blank");
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.com/");
this.notifyObj = new BasicNotification(this.id);
// Set a timeout of 10 minutes that should never be hit
this.notifyObj.addOptions({
timeout: Date.now() + 600000
});
this.notification = showNotification(this.notifyObj);
},
onShown: function* (popup) {
this.complete = false;
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.org/");
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.com/");
// Next load will hide the notification
this.notification.options.timeout = Date.now() - 1;
this.complete = true;
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.org/");
},
onHidden: function (popup) {
ok(this.complete, "Should only have hidden the notification after the timeout was passed");
this.notification.remove();
gBrowser.removeTab(gBrowser.selectedTab);
gBrowser.selectedTab = this.oldSelectedTab;
}
},
// Test that setting persistWhileVisible allows a visible notification to
// persist across location changes
{ id: "Test#5",
run: function* () {
this.oldSelectedTab = gBrowser.selectedTab;
gBrowser.selectedTab = gBrowser.addTab("about:blank");
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.com/");
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.addOptions({
persistWhileVisible: true
});
this.notification = showNotification(this.notifyObj);
},
onShown: function* (popup) {
this.complete = false;
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.org/");
yield promiseTabLoadEvent(gBrowser.selectedTab, "http://example.com/");
// Notification should persist across location changes
this.complete = true;
dismissNotification(popup);
},
onHidden: function (popup) {
ok(this.complete, "Should only have hidden the notification after it was dismissed");
this.notification.remove();
gBrowser.removeTab(gBrowser.selectedTab);
gBrowser.selectedTab = this.oldSelectedTab;
}
},
// Test that nested icon nodes correctly activate popups
{ id: "Test#6",
run: function() {
// Add a temporary box as the anchor with a button
this.box = document.createElement("box");
PopupNotifications.iconBox.appendChild(this.box);
let button = document.createElement("button");
button.setAttribute("label", "Please click me!");
this.box.appendChild(button);
// The notification should open up on the box
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.anchorID = this.box.id = "nested-box";
this.notifyObj.addOptions({dismissed: true});
this.notification = showNotification(this.notifyObj);
// This test places a normal button in the notification area, which has
// standard GTK styling and dimensions. Due to the clip-path, this button
// gets clipped off, which makes it necessary to synthesize the mouse click
// a little bit downward. To be safe, I adjusted the x-offset with the same
// amount.
EventUtils.synthesizeMouse(button, 4, 4, {});
},
onShown: function(popup) {
checkPopup(popup, this.notifyObj);
dismissNotification(popup);
},
onHidden: function(popup) {
this.notification.remove();
this.box.parentNode.removeChild(this.box);
}
},
// Test that popupnotifications without popups have anchor icons shown
{ id: "Test#7",
run: function* () {
let notifyObj = new BasicNotification(this.id);
notifyObj.anchorID = "geo-notification-icon";
notifyObj.addOptions({neverShow: true});
let promiseTopic = promiseTopicObserved("PopupNotifications-updateNotShowing");
showNotification(notifyObj);
yield promiseTopic;
isnot(document.getElementById("geo-notification-icon").boxObject.width, 0,
"geo anchor should be visible");
goNext();
}
},
// Test notification "Not Now" menu item
{ id: "Test#8",
run: function () {
this.notifyObj = new BasicNotification(this.id);
this.notification = showNotification(this.notifyObj);
},
onShown: function (popup) {
checkPopup(popup, this.notifyObj);
triggerSecondaryCommand(popup, 1);
},
onHidden: function (popup) {
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
this.notification.remove();
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
}
},
// Test notification close button
{ id: "Test#9",
run: function () {
this.notifyObj = new BasicNotification(this.id);
this.notification = showNotification(this.notifyObj);
},
onShown: function (popup) {
checkPopup(popup, this.notifyObj);
let notification = popup.childNodes[0];
EventUtils.synthesizeMouseAtCenter(notification.closebutton, {});
},
onHidden: function (popup) {
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
this.notification.remove();
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
}
},
// Test notification when chrome is hidden
{ id: "Test#10",
run: function () {
window.locationbar.visible = false;
this.notifyObj = new BasicNotification(this.id);
this.notification = showNotification(this.notifyObj);
},
onShown: function (popup) {
checkPopup(popup, this.notifyObj);
is(popup.anchorNode.className, "tabbrowser-tab", "notification anchored to tab");
dismissNotification(popup);
},
onHidden: function (popup) {
ok(this.notifyObj.dismissalCallbackTriggered, "dismissal callback triggered");
this.notification.remove();
ok(this.notifyObj.removedCallbackTriggered, "removed callback triggered");
window.locationbar.visible = true;
}
},
// Test that dismissed popupnotifications can be opened on about:blank
// (where the rest of the identity block is disabled)
{ id: "Test#11",
run: function() {
this.oldSelectedTab = gBrowser.selectedTab;
gBrowser.selectedTab = gBrowser.addTab("about:blank");
this.notifyObj = new BasicNotification(this.id);
this.notifyObj.anchorID = "geo-notification-icon";
this.notifyObj.addOptions({dismissed: true});
this.notification = showNotification(this.notifyObj);
EventUtils.synthesizeMouse(document.getElementById("geo-notification-icon"), 0, 0, {});
},
onShown: function(popup) {
checkPopup(popup, this.notifyObj);
dismissNotification(popup);
},
onHidden: function(popup) {
this.notification.remove();
gBrowser.removeTab(gBrowser.selectedTab);
gBrowser.selectedTab = this.oldSelectedTab;
}
}
];
|