|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 const TESTROOT = "http://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; |
|
6 const TESTROOT2 = "http://example.org/browser/toolkit/mozapps/extensions/test/xpinstall/"; |
|
7 const SECUREROOT = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/"; |
|
8 const XPINSTALL_URL = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul"; |
|
9 const PREF_INSTALL_REQUIREBUILTINCERTS = "extensions.install.requireBuiltInCerts"; |
|
10 |
|
11 var rootDir = getRootDirectory(gTestPath); |
|
12 var path = rootDir.split('/'); |
|
13 var chromeName = path[0] + '//' + path[2]; |
|
14 var croot = chromeName + "/content/browser/toolkit/mozapps/extensions/test/xpinstall/"; |
|
15 var jar = getJar(croot); |
|
16 if (jar) { |
|
17 var tmpdir = extractJarToTmp(jar); |
|
18 croot = 'file://' + tmpdir.path + '/'; |
|
19 } |
|
20 const CHROMEROOT = croot; |
|
21 |
|
22 var gApp = document.getElementById("bundle_brand").getString("brandShortName"); |
|
23 var gVersion = Services.appinfo.version; |
|
24 var check_notification; |
|
25 |
|
26 function wait_for_notification(aCallback) { |
|
27 info("Waiting for notification"); |
|
28 check_notification = function() { |
|
29 PopupNotifications.panel.removeEventListener("popupshown", check_notification, false); |
|
30 info("Saw notification"); |
|
31 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); |
|
32 aCallback(PopupNotifications.panel); |
|
33 }; |
|
34 PopupNotifications.panel.addEventListener("popupshown", check_notification, false); |
|
35 } |
|
36 |
|
37 function wait_for_notification_close(aCallback) { |
|
38 info("Waiting for notification to close"); |
|
39 PopupNotifications.panel.addEventListener("popuphidden", function() { |
|
40 PopupNotifications.panel.removeEventListener("popuphidden", arguments.callee, false); |
|
41 aCallback(); |
|
42 }, false); |
|
43 } |
|
44 |
|
45 function wait_for_install_dialog(aCallback) { |
|
46 info("Waiting for install dialog"); |
|
47 Services.wm.addListener({ |
|
48 onOpenWindow: function(aXULWindow) { |
|
49 info("Install dialog opened, waiting for focus"); |
|
50 Services.wm.removeListener(this); |
|
51 |
|
52 var domwindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor) |
|
53 .getInterface(Ci.nsIDOMWindow); |
|
54 waitForFocus(function() { |
|
55 info("Saw install dialog"); |
|
56 is(domwindow.document.location.href, XPINSTALL_URL, "Should have seen the right window open"); |
|
57 |
|
58 // Override the countdown timer on the accept button |
|
59 var button = domwindow.document.documentElement.getButton("accept"); |
|
60 button.disabled = false; |
|
61 |
|
62 aCallback(domwindow); |
|
63 }, domwindow); |
|
64 }, |
|
65 |
|
66 onCloseWindow: function(aXULWindow) { |
|
67 }, |
|
68 |
|
69 onWindowTitleChange: function(aXULWindow, aNewTitle) { |
|
70 } |
|
71 }); |
|
72 } |
|
73 |
|
74 function wait_for_single_notification(aCallback) { |
|
75 function inner_waiter() { |
|
76 info("Waiting for single notification"); |
|
77 // Notification should never close while we wait |
|
78 ok(PopupNotifications.isPanelOpen, "Notification should still be open"); |
|
79 if (PopupNotifications.panel.childNodes.length == 2) { |
|
80 executeSoon(inner_waiter); |
|
81 return; |
|
82 } |
|
83 |
|
84 aCallback(); |
|
85 } |
|
86 |
|
87 executeSoon(inner_waiter); |
|
88 } |
|
89 |
|
90 function setup_redirect(aSettings) { |
|
91 var url = "https://example.com/browser/toolkit/mozapps/extensions/test/xpinstall/redirect.sjs?mode=setup"; |
|
92 for (var name in aSettings) { |
|
93 url += "&" + name + "=" + aSettings[name]; |
|
94 } |
|
95 |
|
96 var req = new XMLHttpRequest(); |
|
97 req.open("GET", url, false); |
|
98 req.send(null); |
|
99 } |
|
100 |
|
101 var TESTS = [ |
|
102 function test_disabled_install() { |
|
103 Services.prefs.setBoolPref("xpinstall.enabled", false); |
|
104 |
|
105 // Wait for the disabled notification |
|
106 wait_for_notification(function(aPanel) { |
|
107 let notification = aPanel.childNodes[0]; |
|
108 is(notification.id, "xpinstall-disabled-notification", "Should have seen installs disabled"); |
|
109 is(notification.button.label, "Enable", "Should have seen the right button"); |
|
110 is(notification.getAttribute("label"), |
|
111 "Software installation is currently disabled. Click Enable and try again."); |
|
112 |
|
113 wait_for_notification_close(function() { |
|
114 try { |
|
115 ok(Services.prefs.getBoolPref("xpinstall.enabled"), "Installation should be enabled"); |
|
116 } |
|
117 catch (e) { |
|
118 ok(false, "xpinstall.enabled should be set"); |
|
119 } |
|
120 |
|
121 gBrowser.removeTab(gBrowser.selectedTab); |
|
122 |
|
123 AddonManager.getAllInstalls(function(aInstalls) { |
|
124 is(aInstalls.length, 1, "Should have been one install created"); |
|
125 aInstalls[0].cancel(); |
|
126 |
|
127 runNextTest(); |
|
128 }); |
|
129 }); |
|
130 |
|
131 // Click on Enable |
|
132 EventUtils.synthesizeMouseAtCenter(notification.button, {}); |
|
133 }); |
|
134 |
|
135 var triggers = encodeURIComponent(JSON.stringify({ |
|
136 "XPI": "unsigned.xpi" |
|
137 })); |
|
138 gBrowser.selectedTab = gBrowser.addTab(); |
|
139 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
140 }, |
|
141 |
|
142 function test_blocked_install() { |
|
143 // Wait for the blocked notification |
|
144 wait_for_notification(function(aPanel) { |
|
145 let notification = aPanel.childNodes[0]; |
|
146 is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); |
|
147 is(notification.button.label, "Allow", "Should have seen the right button"); |
|
148 is(notification.getAttribute("label"), |
|
149 gApp + " prevented this site (example.com) from asking you to install " + |
|
150 "software on your computer.", |
|
151 "Should have seen the right message"); |
|
152 |
|
153 // Wait for the install confirmation dialog |
|
154 wait_for_install_dialog(function(aWindow) { |
|
155 // Wait for the complete notification |
|
156 wait_for_notification(function(aPanel) { |
|
157 let notification = aPanel.childNodes[0]; |
|
158 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
159 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
160 is(notification.getAttribute("label"), |
|
161 "XPI Test will be installed after you restart " + gApp + ".", |
|
162 "Should have seen the right message"); |
|
163 |
|
164 AddonManager.getAllInstalls(function(aInstalls) { |
|
165 is(aInstalls.length, 1, "Should be one pending install"); |
|
166 aInstalls[0].cancel(); |
|
167 |
|
168 wait_for_notification_close(runNextTest); |
|
169 gBrowser.removeTab(gBrowser.selectedTab); |
|
170 }); |
|
171 }); |
|
172 |
|
173 aWindow.document.documentElement.acceptDialog(); |
|
174 }); |
|
175 |
|
176 // Click on Allow |
|
177 EventUtils.synthesizeMouse(notification.button, 20, 10, {}); |
|
178 |
|
179 // Notification should have changed to progress notification |
|
180 ok(PopupNotifications.isPanelOpen, "Notification should still be open"); |
|
181 notification = aPanel.childNodes[0]; |
|
182 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
183 |
|
184 }); |
|
185 |
|
186 var triggers = encodeURIComponent(JSON.stringify({ |
|
187 "XPI": "unsigned.xpi" |
|
188 })); |
|
189 gBrowser.selectedTab = gBrowser.addTab(); |
|
190 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
191 }, |
|
192 |
|
193 function test_whitelisted_install() { |
|
194 // Wait for the progress notification |
|
195 wait_for_notification(function(aPanel) { |
|
196 let notification = aPanel.childNodes[0]; |
|
197 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
198 |
|
199 // Wait for the install confirmation dialog |
|
200 wait_for_install_dialog(function(aWindow) { |
|
201 // Wait for the complete notification |
|
202 wait_for_notification(function(aPanel) { |
|
203 let notification = aPanel.childNodes[0]; |
|
204 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
205 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
206 is(notification.getAttribute("label"), |
|
207 "XPI Test will be installed after you restart " + gApp + ".", |
|
208 "Should have seen the right message"); |
|
209 |
|
210 AddonManager.getAllInstalls(function(aInstalls) { |
|
211 is(aInstalls.length, 1, "Should be one pending install"); |
|
212 aInstalls[0].cancel(); |
|
213 |
|
214 Services.perms.remove("example.com", "install"); |
|
215 wait_for_notification_close(runNextTest); |
|
216 gBrowser.removeTab(gBrowser.selectedTab); |
|
217 }); |
|
218 }); |
|
219 |
|
220 aWindow.document.documentElement.acceptDialog(); |
|
221 }); |
|
222 }); |
|
223 |
|
224 var pm = Services.perms; |
|
225 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
226 |
|
227 var triggers = encodeURIComponent(JSON.stringify({ |
|
228 "XPI": "unsigned.xpi" |
|
229 })); |
|
230 gBrowser.selectedTab = gBrowser.addTab(); |
|
231 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
232 }, |
|
233 |
|
234 function test_failed_download() { |
|
235 // Wait for the progress notification |
|
236 wait_for_notification(function(aPanel) { |
|
237 let notification = aPanel.childNodes[0]; |
|
238 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
239 |
|
240 // Wait for the failed notification |
|
241 wait_for_notification(function(aPanel) { |
|
242 let notification = aPanel.childNodes[0]; |
|
243 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); |
|
244 is(notification.getAttribute("label"), |
|
245 "The add-on could not be downloaded because of a connection failure " + |
|
246 "on example.com.", |
|
247 "Should have seen the right message"); |
|
248 |
|
249 Services.perms.remove("example.com", "install"); |
|
250 wait_for_notification_close(runNextTest); |
|
251 gBrowser.removeTab(gBrowser.selectedTab); |
|
252 }); |
|
253 }); |
|
254 |
|
255 var pm = Services.perms; |
|
256 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
257 |
|
258 var triggers = encodeURIComponent(JSON.stringify({ |
|
259 "XPI": "missing.xpi" |
|
260 })); |
|
261 gBrowser.selectedTab = gBrowser.addTab(); |
|
262 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
263 }, |
|
264 |
|
265 function test_corrupt_file() { |
|
266 // Wait for the progress notification |
|
267 wait_for_notification(function(aPanel) { |
|
268 let notification = aPanel.childNodes[0]; |
|
269 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
270 |
|
271 // Wait for the failed notification |
|
272 wait_for_notification(function(aPanel) { |
|
273 let notification = aPanel.childNodes[0]; |
|
274 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); |
|
275 is(notification.getAttribute("label"), |
|
276 "The add-on downloaded from example.com could not be installed " + |
|
277 "because it appears to be corrupt.", |
|
278 "Should have seen the right message"); |
|
279 |
|
280 Services.perms.remove("example.com", "install"); |
|
281 wait_for_notification_close(runNextTest); |
|
282 gBrowser.removeTab(gBrowser.selectedTab); |
|
283 }); |
|
284 }); |
|
285 |
|
286 var pm = Services.perms; |
|
287 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
288 |
|
289 var triggers = encodeURIComponent(JSON.stringify({ |
|
290 "XPI": "corrupt.xpi" |
|
291 })); |
|
292 gBrowser.selectedTab = gBrowser.addTab(); |
|
293 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
294 }, |
|
295 |
|
296 function test_incompatible() { |
|
297 // Wait for the progress notification |
|
298 wait_for_notification(function(aPanel) { |
|
299 let notification = aPanel.childNodes[0]; |
|
300 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
301 |
|
302 // Wait for the failed notification |
|
303 wait_for_notification(function(aPanel) { |
|
304 let notification = aPanel.childNodes[0]; |
|
305 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); |
|
306 is(notification.getAttribute("label"), |
|
307 "XPI Test could not be installed because it is not compatible with " + |
|
308 gApp + " " + gVersion + ".", |
|
309 "Should have seen the right message"); |
|
310 |
|
311 Services.perms.remove("example.com", "install"); |
|
312 wait_for_notification_close(runNextTest); |
|
313 gBrowser.removeTab(gBrowser.selectedTab); |
|
314 }); |
|
315 }); |
|
316 |
|
317 var pm = Services.perms; |
|
318 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
319 |
|
320 var triggers = encodeURIComponent(JSON.stringify({ |
|
321 "XPI": "incompatible.xpi" |
|
322 })); |
|
323 gBrowser.selectedTab = gBrowser.addTab(); |
|
324 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
325 }, |
|
326 |
|
327 function test_restartless() { |
|
328 // Wait for the progress notification |
|
329 wait_for_notification(function(aPanel) { |
|
330 let notification = aPanel.childNodes[0]; |
|
331 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
332 |
|
333 // Wait for the install confirmation dialog |
|
334 wait_for_install_dialog(function(aWindow) { |
|
335 // Wait for the complete notification |
|
336 wait_for_notification(function(aPanel) { |
|
337 let notification = aPanel.childNodes[0]; |
|
338 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
339 is(notification.getAttribute("label"), |
|
340 "XPI Test has been installed successfully.", |
|
341 "Should have seen the right message"); |
|
342 |
|
343 AddonManager.getAllInstalls(function(aInstalls) { |
|
344 is(aInstalls.length, 0, "Should be no pending installs"); |
|
345 |
|
346 AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) { |
|
347 aAddon.uninstall(); |
|
348 |
|
349 Services.perms.remove("example.com", "install"); |
|
350 wait_for_notification_close(runNextTest); |
|
351 gBrowser.removeTab(gBrowser.selectedTab); |
|
352 }); |
|
353 }); |
|
354 }); |
|
355 |
|
356 aWindow.document.documentElement.acceptDialog(); |
|
357 }); |
|
358 }); |
|
359 |
|
360 var pm = Services.perms; |
|
361 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
362 |
|
363 var triggers = encodeURIComponent(JSON.stringify({ |
|
364 "XPI": "restartless.xpi" |
|
365 })); |
|
366 gBrowser.selectedTab = gBrowser.addTab(); |
|
367 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
368 }, |
|
369 |
|
370 function test_multiple() { |
|
371 // Wait for the progress notification |
|
372 wait_for_notification(function(aPanel) { |
|
373 let notification = aPanel.childNodes[0]; |
|
374 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
375 |
|
376 // Wait for the install confirmation dialog |
|
377 wait_for_install_dialog(function(aWindow) { |
|
378 // Wait for the complete notification |
|
379 wait_for_notification(function(aPanel) { |
|
380 let notification = aPanel.childNodes[0]; |
|
381 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
382 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
383 is(notification.getAttribute("label"), |
|
384 "2 add-ons will be installed after you restart " + gApp + ".", |
|
385 "Should have seen the right message"); |
|
386 |
|
387 AddonManager.getAllInstalls(function(aInstalls) { |
|
388 is(aInstalls.length, 1, "Should be one pending install"); |
|
389 aInstalls[0].cancel(); |
|
390 |
|
391 AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) { |
|
392 aAddon.uninstall(); |
|
393 |
|
394 Services.perms.remove("example.com", "install"); |
|
395 wait_for_notification_close(runNextTest); |
|
396 gBrowser.removeTab(gBrowser.selectedTab); |
|
397 }); |
|
398 }); |
|
399 }); |
|
400 |
|
401 aWindow.document.documentElement.acceptDialog(); |
|
402 }); |
|
403 }); |
|
404 |
|
405 var pm = Services.perms; |
|
406 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
407 |
|
408 var triggers = encodeURIComponent(JSON.stringify({ |
|
409 "Unsigned XPI": "unsigned.xpi", |
|
410 "Restartless XPI": "restartless.xpi" |
|
411 })); |
|
412 gBrowser.selectedTab = gBrowser.addTab(); |
|
413 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
414 }, |
|
415 |
|
416 function test_url() { |
|
417 // Wait for the progress notification |
|
418 wait_for_notification(function(aPanel) { |
|
419 let notification = aPanel.childNodes[0]; |
|
420 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
421 |
|
422 // Wait for the install confirmation dialog |
|
423 wait_for_install_dialog(function(aWindow) { |
|
424 // Wait for the complete notification |
|
425 wait_for_notification(function(aPanel) { |
|
426 let notification = aPanel.childNodes[0]; |
|
427 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
428 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
429 is(notification.getAttribute("label"), |
|
430 "XPI Test will be installed after you restart " + gApp + ".", |
|
431 "Should have seen the right message"); |
|
432 |
|
433 AddonManager.getAllInstalls(function(aInstalls) { |
|
434 is(aInstalls.length, 1, "Should be one pending install"); |
|
435 aInstalls[0].cancel(); |
|
436 |
|
437 wait_for_notification_close(runNextTest); |
|
438 gBrowser.removeTab(gBrowser.selectedTab); |
|
439 }); |
|
440 }); |
|
441 |
|
442 aWindow.document.documentElement.acceptDialog(); |
|
443 }); |
|
444 }); |
|
445 |
|
446 gBrowser.selectedTab = gBrowser.addTab(); |
|
447 gBrowser.loadURI(TESTROOT + "unsigned.xpi"); |
|
448 }, |
|
449 |
|
450 function test_localfile() { |
|
451 // Wait for the install to fail |
|
452 Services.obs.addObserver(function() { |
|
453 Services.obs.removeObserver(arguments.callee, "addon-install-failed"); |
|
454 |
|
455 // Wait for the browser code to add the failure notification |
|
456 wait_for_single_notification(function() { |
|
457 let notification = PopupNotifications.panel.childNodes[0]; |
|
458 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); |
|
459 is(notification.getAttribute("label"), |
|
460 "This add-on could not be installed because it appears to be corrupt.", |
|
461 "Should have seen the right message"); |
|
462 |
|
463 wait_for_notification_close(runNextTest); |
|
464 gBrowser.removeTab(gBrowser.selectedTab); |
|
465 }); |
|
466 }, "addon-install-failed", false); |
|
467 |
|
468 var cr = Components.classes["@mozilla.org/chrome/chrome-registry;1"] |
|
469 .getService(Components.interfaces.nsIChromeRegistry); |
|
470 try { |
|
471 var path = cr.convertChromeURL(makeURI(CHROMEROOT + "corrupt.xpi")).spec; |
|
472 } catch (ex) { |
|
473 var path = CHROMEROOT + "corrupt.xpi"; |
|
474 } |
|
475 gBrowser.selectedTab = gBrowser.addTab(); |
|
476 gBrowser.loadURI(path); |
|
477 }, |
|
478 |
|
479 function test_wronghost() { |
|
480 gBrowser.selectedTab = gBrowser.addTab(); |
|
481 gBrowser.addEventListener("load", function() { |
|
482 if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html") |
|
483 return; |
|
484 |
|
485 gBrowser.removeEventListener("load", arguments.callee, true); |
|
486 |
|
487 // Wait for the progress notification |
|
488 wait_for_notification(function(aPanel) { |
|
489 let notification = aPanel.childNodes[0]; |
|
490 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
491 // Wait for the complete notification |
|
492 wait_for_notification(function(aPanel) { |
|
493 let notification = aPanel.childNodes[0]; |
|
494 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); |
|
495 is(notification.getAttribute("label"), |
|
496 "The add-on downloaded from example.com could not be installed " + |
|
497 "because it appears to be corrupt.", |
|
498 "Should have seen the right message"); |
|
499 |
|
500 wait_for_notification_close(runNextTest); |
|
501 gBrowser.removeTab(gBrowser.selectedTab); |
|
502 }); |
|
503 }); |
|
504 |
|
505 gBrowser.loadURI(TESTROOT + "corrupt.xpi"); |
|
506 }, true); |
|
507 gBrowser.loadURI(TESTROOT2 + "enabled.html"); |
|
508 }, |
|
509 |
|
510 function test_reload() { |
|
511 // Wait for the progress notification |
|
512 wait_for_notification(function(aPanel) { |
|
513 let notification = aPanel.childNodes[0]; |
|
514 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
515 |
|
516 // Wait for the install confirmation dialog |
|
517 wait_for_install_dialog(function(aWindow) { |
|
518 // Wait for the complete notification |
|
519 wait_for_notification(function(aPanel) { |
|
520 let notification = aPanel.childNodes[0]; |
|
521 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
522 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
523 is(notification.getAttribute("label"), |
|
524 "XPI Test will be installed after you restart " + gApp + ".", |
|
525 "Should have seen the right message"); |
|
526 |
|
527 function test_fail() { |
|
528 ok(false, "Reloading should not have hidden the notification"); |
|
529 } |
|
530 |
|
531 PopupNotifications.panel.addEventListener("popuphiding", test_fail, false); |
|
532 |
|
533 gBrowser.addEventListener("load", function() { |
|
534 if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html") |
|
535 return; |
|
536 |
|
537 gBrowser.removeEventListener("load", arguments.callee, true); |
|
538 |
|
539 PopupNotifications.panel.removeEventListener("popuphiding", test_fail, false); |
|
540 |
|
541 AddonManager.getAllInstalls(function(aInstalls) { |
|
542 is(aInstalls.length, 1, "Should be one pending install"); |
|
543 aInstalls[0].cancel(); |
|
544 |
|
545 Services.perms.remove("example.com", "install"); |
|
546 wait_for_notification_close(runNextTest); |
|
547 gBrowser.removeTab(gBrowser.selectedTab); |
|
548 }); |
|
549 }, true); |
|
550 gBrowser.loadURI(TESTROOT2 + "enabled.html"); |
|
551 }); |
|
552 |
|
553 aWindow.document.documentElement.acceptDialog(); |
|
554 }); |
|
555 }); |
|
556 |
|
557 var pm = Services.perms; |
|
558 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
559 |
|
560 var triggers = encodeURIComponent(JSON.stringify({ |
|
561 "Unsigned XPI": "unsigned.xpi" |
|
562 })); |
|
563 gBrowser.selectedTab = gBrowser.addTab(); |
|
564 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
565 }, |
|
566 |
|
567 function test_theme() { |
|
568 // Wait for the progress notification |
|
569 wait_for_notification(function(aPanel) { |
|
570 let notification = aPanel.childNodes[0]; |
|
571 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
572 |
|
573 // Wait for the install confirmation dialog |
|
574 wait_for_install_dialog(function(aWindow) { |
|
575 // Wait for the complete notification |
|
576 wait_for_notification(function(aPanel) { |
|
577 let notification = aPanel.childNodes[0]; |
|
578 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
579 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
580 is(notification.getAttribute("label"), |
|
581 "Theme Test will be installed after you restart " + gApp + ".", |
|
582 "Should have seen the right message"); |
|
583 |
|
584 AddonManager.getAddonByID("{972ce4c6-7e08-4474-a285-3208198ce6fd}", function(aAddon) { |
|
585 ok(aAddon.userDisabled, "Should be switching away from the default theme."); |
|
586 // Undo the pending theme switch |
|
587 aAddon.userDisabled = false; |
|
588 |
|
589 AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) { |
|
590 isnot(aAddon, null, "Test theme will have been installed"); |
|
591 aAddon.uninstall(); |
|
592 |
|
593 Services.perms.remove("example.com", "install"); |
|
594 wait_for_notification_close(runNextTest); |
|
595 gBrowser.removeTab(gBrowser.selectedTab); |
|
596 }); |
|
597 }); |
|
598 }); |
|
599 |
|
600 aWindow.document.documentElement.acceptDialog(); |
|
601 }); |
|
602 }); |
|
603 |
|
604 var pm = Services.perms; |
|
605 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
606 |
|
607 var triggers = encodeURIComponent(JSON.stringify({ |
|
608 "Theme XPI": "theme.xpi" |
|
609 })); |
|
610 gBrowser.selectedTab = gBrowser.addTab(); |
|
611 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
612 }, |
|
613 |
|
614 function test_renotify_blocked() { |
|
615 // Wait for the blocked notification |
|
616 wait_for_notification(function(aPanel) { |
|
617 let notification = aPanel.childNodes[0]; |
|
618 is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); |
|
619 |
|
620 wait_for_notification_close(function () { |
|
621 info("Timeouts after this probably mean bug 589954 regressed"); |
|
622 executeSoon(function () { |
|
623 wait_for_notification(function(aPanel) { |
|
624 let notification = aPanel.childNodes[0]; |
|
625 is(notification.id, "addon-install-blocked-notification", |
|
626 "Should have seen the install blocked - 2nd time"); |
|
627 |
|
628 AddonManager.getAllInstalls(function(aInstalls) { |
|
629 is(aInstalls.length, 2, "Should be two pending installs"); |
|
630 aInstalls[0].cancel(); |
|
631 aInstalls[1].cancel(); |
|
632 |
|
633 info("Closing browser tab"); |
|
634 wait_for_notification_close(runNextTest); |
|
635 gBrowser.removeTab(gBrowser.selectedTab); |
|
636 }); |
|
637 }); |
|
638 |
|
639 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
640 }); |
|
641 }); |
|
642 |
|
643 // hide the panel (this simulates the user dismissing it) |
|
644 aPanel.hidePopup(); |
|
645 }); |
|
646 |
|
647 var triggers = encodeURIComponent(JSON.stringify({ |
|
648 "XPI": "unsigned.xpi" |
|
649 })); |
|
650 gBrowser.selectedTab = gBrowser.addTab(); |
|
651 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
652 }, |
|
653 |
|
654 function test_renotify_installed() { |
|
655 // Wait for the progress notification |
|
656 wait_for_notification(function(aPanel) { |
|
657 let notification = aPanel.childNodes[0]; |
|
658 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
659 |
|
660 // Wait for the install confirmation dialog |
|
661 wait_for_install_dialog(function(aWindow) { |
|
662 // Wait for the complete notification |
|
663 wait_for_notification(function(aPanel) { |
|
664 let notification = aPanel.childNodes[0]; |
|
665 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
666 |
|
667 // Dismiss the notification |
|
668 wait_for_notification_close(function () { |
|
669 // Install another |
|
670 executeSoon(function () { |
|
671 // Wait for the progress notification |
|
672 wait_for_notification(function(aPanel) { |
|
673 let notification = aPanel.childNodes[0]; |
|
674 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
675 |
|
676 // Wait for the install confirmation dialog |
|
677 wait_for_install_dialog(function(aWindow) { |
|
678 info("Timeouts after this probably mean bug 589954 regressed"); |
|
679 |
|
680 // Wait for the complete notification |
|
681 wait_for_notification(function(aPanel) { |
|
682 let notification = aPanel.childNodes[0]; |
|
683 is(notification.id, "addon-install-complete-notification", "Should have seen the second install complete"); |
|
684 |
|
685 AddonManager.getAllInstalls(function(aInstalls) { |
|
686 is(aInstalls.length, 1, "Should be one pending installs"); |
|
687 aInstalls[0].cancel(); |
|
688 |
|
689 Services.perms.remove("example.com", "install"); |
|
690 wait_for_notification_close(runNextTest); |
|
691 gBrowser.removeTab(gBrowser.selectedTab); |
|
692 }); |
|
693 }); |
|
694 |
|
695 aWindow.document.documentElement.acceptDialog(); |
|
696 }); |
|
697 }); |
|
698 |
|
699 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
700 }); |
|
701 }); |
|
702 |
|
703 // hide the panel (this simulates the user dismissing it) |
|
704 aPanel.hidePopup(); |
|
705 }); |
|
706 |
|
707 aWindow.document.documentElement.acceptDialog(); |
|
708 }); |
|
709 }); |
|
710 |
|
711 var pm = Services.perms; |
|
712 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
713 |
|
714 var triggers = encodeURIComponent(JSON.stringify({ |
|
715 "XPI": "unsigned.xpi" |
|
716 })); |
|
717 gBrowser.selectedTab = gBrowser.addTab(); |
|
718 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
719 }, |
|
720 |
|
721 function test_cancel_restart() { |
|
722 // Wait for the progress notification |
|
723 wait_for_notification(function(aPanel) { |
|
724 let notification = aPanel.childNodes[0]; |
|
725 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
726 |
|
727 // Close the notification |
|
728 let anchor = document.getElementById("addons-notification-icon"); |
|
729 anchor.click(); |
|
730 // Reopen the notification |
|
731 anchor.click(); |
|
732 |
|
733 ok(PopupNotifications.isPanelOpen, "Notification should still be open"); |
|
734 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); |
|
735 isnot(notification, aPanel.childNodes[0], "Should have reconstructed the notification UI"); |
|
736 notification = aPanel.childNodes[0]; |
|
737 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
738 let button = document.getAnonymousElementByAttribute(notification, "anonid", "cancel"); |
|
739 |
|
740 // Cancel the download |
|
741 EventUtils.synthesizeMouse(button, 2, 2, {}); |
|
742 |
|
743 // Notification should have changed to cancelled |
|
744 notification = aPanel.childNodes[0]; |
|
745 is(notification.id, "addon-install-cancelled-notification", "Should have seen the cancelled notification"); |
|
746 |
|
747 // Wait for the install confirmation dialog |
|
748 wait_for_install_dialog(function(aWindow) { |
|
749 // Wait for the complete notification |
|
750 wait_for_notification(function(aPanel) { |
|
751 let notification = aPanel.childNodes[0]; |
|
752 is(notification.id, "addon-install-complete-notification", "Should have seen the install complete"); |
|
753 is(notification.button.label, "Restart Now", "Should have seen the right button"); |
|
754 is(notification.getAttribute("label"), |
|
755 "XPI Test will be installed after you restart " + gApp + ".", |
|
756 "Should have seen the right message"); |
|
757 |
|
758 AddonManager.getAllInstalls(function(aInstalls) { |
|
759 is(aInstalls.length, 1, "Should be one pending install"); |
|
760 aInstalls[0].cancel(); |
|
761 |
|
762 Services.perms.remove("example.com", "install"); |
|
763 wait_for_notification_close(runNextTest); |
|
764 gBrowser.removeTab(gBrowser.selectedTab); |
|
765 }); |
|
766 }); |
|
767 |
|
768 aWindow.document.documentElement.acceptDialog(); |
|
769 }); |
|
770 |
|
771 // Restart the download |
|
772 EventUtils.synthesizeMouse(notification.button, 20, 10, {}); |
|
773 |
|
774 // Should be back to a progress notification |
|
775 ok(PopupNotifications.isPanelOpen, "Notification should still be open"); |
|
776 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); |
|
777 notification = aPanel.childNodes[0]; |
|
778 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
779 }); |
|
780 |
|
781 var pm = Services.perms; |
|
782 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION); |
|
783 |
|
784 var triggers = encodeURIComponent(JSON.stringify({ |
|
785 "XPI": "unsigned.xpi" |
|
786 })); |
|
787 gBrowser.selectedTab = gBrowser.addTab(); |
|
788 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers); |
|
789 }, |
|
790 |
|
791 function test_failed_security() { |
|
792 Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false); |
|
793 |
|
794 setup_redirect({ |
|
795 "Location": TESTROOT + "unsigned.xpi" |
|
796 }); |
|
797 |
|
798 // Wait for the blocked notification |
|
799 wait_for_notification(function(aPanel) { |
|
800 let notification = aPanel.childNodes[0]; |
|
801 is(notification.id, "addon-install-blocked-notification", "Should have seen the install blocked"); |
|
802 |
|
803 // Click on Allow |
|
804 EventUtils.synthesizeMouse(notification.button, 20, 10, {}); |
|
805 |
|
806 // Notification should have changed to progress notification |
|
807 ok(PopupNotifications.isPanelOpen, "Notification should still be open"); |
|
808 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); |
|
809 notification = aPanel.childNodes[0]; |
|
810 is(notification.id, "addon-progress-notification", "Should have seen the progress notification"); |
|
811 |
|
812 // Wait for it to fail |
|
813 Services.obs.addObserver(function() { |
|
814 Services.obs.removeObserver(arguments.callee, "addon-install-failed"); |
|
815 |
|
816 // Allow the browser code to add the failure notification and then wait |
|
817 // for the progress notification to dismiss itself |
|
818 wait_for_single_notification(function() { |
|
819 is(PopupNotifications.panel.childNodes.length, 1, "Should be only one notification"); |
|
820 notification = aPanel.childNodes[0]; |
|
821 is(notification.id, "addon-install-failed-notification", "Should have seen the install fail"); |
|
822 |
|
823 Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, true); |
|
824 wait_for_notification_close(runNextTest); |
|
825 gBrowser.removeTab(gBrowser.selectedTab); |
|
826 }); |
|
827 }, "addon-install-failed", false); |
|
828 }); |
|
829 |
|
830 var triggers = encodeURIComponent(JSON.stringify({ |
|
831 "XPI": "redirect.sjs?mode=redirect" |
|
832 })); |
|
833 gBrowser.selectedTab = gBrowser.addTab(); |
|
834 gBrowser.loadURI(SECUREROOT + "installtrigger.html?" + triggers); |
|
835 } |
|
836 ]; |
|
837 |
|
838 var gTestStart = null; |
|
839 |
|
840 function runNextTest() { |
|
841 if (gTestStart) |
|
842 info("Test part took " + (Date.now() - gTestStart) + "ms"); |
|
843 |
|
844 ok(!PopupNotifications.isPanelOpen, "Notification should be closed"); |
|
845 |
|
846 AddonManager.getAllInstalls(function(aInstalls) { |
|
847 is(aInstalls.length, 0, "Should be no active installs"); |
|
848 |
|
849 if (TESTS.length == 0) { |
|
850 finish(); |
|
851 return; |
|
852 } |
|
853 |
|
854 info("Running " + TESTS[0].name); |
|
855 gTestStart = Date.now(); |
|
856 TESTS.shift()(); |
|
857 }); |
|
858 }; |
|
859 |
|
860 var XPInstallObserver = { |
|
861 observe: function (aSubject, aTopic, aData) { |
|
862 var installInfo = aSubject.QueryInterface(Components.interfaces.amIWebInstallInfo); |
|
863 info("Observed " + aTopic + " for " + installInfo.installs.length + " installs"); |
|
864 installInfo.installs.forEach(function(aInstall) { |
|
865 info("Install of " + aInstall.sourceURI.spec + " was in state " + aInstall.state); |
|
866 }); |
|
867 } |
|
868 }; |
|
869 |
|
870 function test() { |
|
871 requestLongerTimeout(4); |
|
872 waitForExplicitFinish(); |
|
873 |
|
874 Services.prefs.setBoolPref("extensions.logging.enabled", true); |
|
875 Services.prefs.setBoolPref("extensions.strictCompatibility", true); |
|
876 |
|
877 Services.obs.addObserver(XPInstallObserver, "addon-install-started", false); |
|
878 Services.obs.addObserver(XPInstallObserver, "addon-install-blocked", false); |
|
879 Services.obs.addObserver(XPInstallObserver, "addon-install-failed", false); |
|
880 Services.obs.addObserver(XPInstallObserver, "addon-install-complete", false); |
|
881 |
|
882 PopupNotifications.transitionsEnabled = false; |
|
883 |
|
884 registerCleanupFunction(function() { |
|
885 // Make sure no more test parts run in case we were timed out |
|
886 TESTS = []; |
|
887 PopupNotifications.panel.removeEventListener("popupshown", check_notification, false); |
|
888 PopupNotifications.transitionsEnabled = true; |
|
889 |
|
890 AddonManager.getAllInstalls(function(aInstalls) { |
|
891 aInstalls.forEach(function(aInstall) { |
|
892 aInstall.cancel(); |
|
893 }); |
|
894 }); |
|
895 |
|
896 Services.prefs.clearUserPref("extensions.logging.enabled"); |
|
897 Services.prefs.clearUserPref("extensions.strictCompatibility"); |
|
898 |
|
899 Services.obs.removeObserver(XPInstallObserver, "addon-install-started"); |
|
900 Services.obs.removeObserver(XPInstallObserver, "addon-install-blocked"); |
|
901 Services.obs.removeObserver(XPInstallObserver, "addon-install-failed"); |
|
902 Services.obs.removeObserver(XPInstallObserver, "addon-install-complete"); |
|
903 }); |
|
904 |
|
905 runNextTest(); |
|
906 } |