Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
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";
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;
22 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
23 var gVersion = Services.appinfo.version;
24 var check_notification;
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 }
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 }
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);
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");
58 // Override the countdown timer on the accept button
59 var button = domwindow.document.documentElement.getButton("accept");
60 button.disabled = false;
62 aCallback(domwindow);
63 }, domwindow);
64 },
66 onCloseWindow: function(aXULWindow) {
67 },
69 onWindowTitleChange: function(aXULWindow, aNewTitle) {
70 }
71 });
72 }
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 }
84 aCallback();
85 }
87 executeSoon(inner_waiter);
88 }
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 }
96 var req = new XMLHttpRequest();
97 req.open("GET", url, false);
98 req.send(null);
99 }
101 var TESTS = [
102 function test_disabled_install() {
103 Services.prefs.setBoolPref("xpinstall.enabled", false);
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.");
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 }
121 gBrowser.removeTab(gBrowser.selectedTab);
123 AddonManager.getAllInstalls(function(aInstalls) {
124 is(aInstalls.length, 1, "Should have been one install created");
125 aInstalls[0].cancel();
127 runNextTest();
128 });
129 });
131 // Click on Enable
132 EventUtils.synthesizeMouseAtCenter(notification.button, {});
133 });
135 var triggers = encodeURIComponent(JSON.stringify({
136 "XPI": "unsigned.xpi"
137 }));
138 gBrowser.selectedTab = gBrowser.addTab();
139 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
140 },
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");
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");
164 AddonManager.getAllInstalls(function(aInstalls) {
165 is(aInstalls.length, 1, "Should be one pending install");
166 aInstalls[0].cancel();
168 wait_for_notification_close(runNextTest);
169 gBrowser.removeTab(gBrowser.selectedTab);
170 });
171 });
173 aWindow.document.documentElement.acceptDialog();
174 });
176 // Click on Allow
177 EventUtils.synthesizeMouse(notification.button, 20, 10, {});
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");
184 });
186 var triggers = encodeURIComponent(JSON.stringify({
187 "XPI": "unsigned.xpi"
188 }));
189 gBrowser.selectedTab = gBrowser.addTab();
190 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
191 },
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");
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");
210 AddonManager.getAllInstalls(function(aInstalls) {
211 is(aInstalls.length, 1, "Should be one pending install");
212 aInstalls[0].cancel();
214 Services.perms.remove("example.com", "install");
215 wait_for_notification_close(runNextTest);
216 gBrowser.removeTab(gBrowser.selectedTab);
217 });
218 });
220 aWindow.document.documentElement.acceptDialog();
221 });
222 });
224 var pm = Services.perms;
225 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
227 var triggers = encodeURIComponent(JSON.stringify({
228 "XPI": "unsigned.xpi"
229 }));
230 gBrowser.selectedTab = gBrowser.addTab();
231 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
232 },
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");
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");
249 Services.perms.remove("example.com", "install");
250 wait_for_notification_close(runNextTest);
251 gBrowser.removeTab(gBrowser.selectedTab);
252 });
253 });
255 var pm = Services.perms;
256 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
258 var triggers = encodeURIComponent(JSON.stringify({
259 "XPI": "missing.xpi"
260 }));
261 gBrowser.selectedTab = gBrowser.addTab();
262 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
263 },
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");
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");
280 Services.perms.remove("example.com", "install");
281 wait_for_notification_close(runNextTest);
282 gBrowser.removeTab(gBrowser.selectedTab);
283 });
284 });
286 var pm = Services.perms;
287 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
289 var triggers = encodeURIComponent(JSON.stringify({
290 "XPI": "corrupt.xpi"
291 }));
292 gBrowser.selectedTab = gBrowser.addTab();
293 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
294 },
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");
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");
311 Services.perms.remove("example.com", "install");
312 wait_for_notification_close(runNextTest);
313 gBrowser.removeTab(gBrowser.selectedTab);
314 });
315 });
317 var pm = Services.perms;
318 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
320 var triggers = encodeURIComponent(JSON.stringify({
321 "XPI": "incompatible.xpi"
322 }));
323 gBrowser.selectedTab = gBrowser.addTab();
324 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
325 },
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");
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");
343 AddonManager.getAllInstalls(function(aInstalls) {
344 is(aInstalls.length, 0, "Should be no pending installs");
346 AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) {
347 aAddon.uninstall();
349 Services.perms.remove("example.com", "install");
350 wait_for_notification_close(runNextTest);
351 gBrowser.removeTab(gBrowser.selectedTab);
352 });
353 });
354 });
356 aWindow.document.documentElement.acceptDialog();
357 });
358 });
360 var pm = Services.perms;
361 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
363 var triggers = encodeURIComponent(JSON.stringify({
364 "XPI": "restartless.xpi"
365 }));
366 gBrowser.selectedTab = gBrowser.addTab();
367 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
368 },
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");
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");
387 AddonManager.getAllInstalls(function(aInstalls) {
388 is(aInstalls.length, 1, "Should be one pending install");
389 aInstalls[0].cancel();
391 AddonManager.getAddonByID("restartless-xpi@tests.mozilla.org", function(aAddon) {
392 aAddon.uninstall();
394 Services.perms.remove("example.com", "install");
395 wait_for_notification_close(runNextTest);
396 gBrowser.removeTab(gBrowser.selectedTab);
397 });
398 });
399 });
401 aWindow.document.documentElement.acceptDialog();
402 });
403 });
405 var pm = Services.perms;
406 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
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 },
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");
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");
433 AddonManager.getAllInstalls(function(aInstalls) {
434 is(aInstalls.length, 1, "Should be one pending install");
435 aInstalls[0].cancel();
437 wait_for_notification_close(runNextTest);
438 gBrowser.removeTab(gBrowser.selectedTab);
439 });
440 });
442 aWindow.document.documentElement.acceptDialog();
443 });
444 });
446 gBrowser.selectedTab = gBrowser.addTab();
447 gBrowser.loadURI(TESTROOT + "unsigned.xpi");
448 },
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");
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");
463 wait_for_notification_close(runNextTest);
464 gBrowser.removeTab(gBrowser.selectedTab);
465 });
466 }, "addon-install-failed", false);
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 },
479 function test_wronghost() {
480 gBrowser.selectedTab = gBrowser.addTab();
481 gBrowser.addEventListener("load", function() {
482 if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html")
483 return;
485 gBrowser.removeEventListener("load", arguments.callee, true);
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");
500 wait_for_notification_close(runNextTest);
501 gBrowser.removeTab(gBrowser.selectedTab);
502 });
503 });
505 gBrowser.loadURI(TESTROOT + "corrupt.xpi");
506 }, true);
507 gBrowser.loadURI(TESTROOT2 + "enabled.html");
508 },
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");
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");
527 function test_fail() {
528 ok(false, "Reloading should not have hidden the notification");
529 }
531 PopupNotifications.panel.addEventListener("popuphiding", test_fail, false);
533 gBrowser.addEventListener("load", function() {
534 if (gBrowser.currentURI.spec != TESTROOT2 + "enabled.html")
535 return;
537 gBrowser.removeEventListener("load", arguments.callee, true);
539 PopupNotifications.panel.removeEventListener("popuphiding", test_fail, false);
541 AddonManager.getAllInstalls(function(aInstalls) {
542 is(aInstalls.length, 1, "Should be one pending install");
543 aInstalls[0].cancel();
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 });
553 aWindow.document.documentElement.acceptDialog();
554 });
555 });
557 var pm = Services.perms;
558 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
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 },
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");
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");
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;
589 AddonManager.getAddonByID("theme-xpi@tests.mozilla.org", function(aAddon) {
590 isnot(aAddon, null, "Test theme will have been installed");
591 aAddon.uninstall();
593 Services.perms.remove("example.com", "install");
594 wait_for_notification_close(runNextTest);
595 gBrowser.removeTab(gBrowser.selectedTab);
596 });
597 });
598 });
600 aWindow.document.documentElement.acceptDialog();
601 });
602 });
604 var pm = Services.perms;
605 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
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 },
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");
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");
628 AddonManager.getAllInstalls(function(aInstalls) {
629 is(aInstalls.length, 2, "Should be two pending installs");
630 aInstalls[0].cancel();
631 aInstalls[1].cancel();
633 info("Closing browser tab");
634 wait_for_notification_close(runNextTest);
635 gBrowser.removeTab(gBrowser.selectedTab);
636 });
637 });
639 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
640 });
641 });
643 // hide the panel (this simulates the user dismissing it)
644 aPanel.hidePopup();
645 });
647 var triggers = encodeURIComponent(JSON.stringify({
648 "XPI": "unsigned.xpi"
649 }));
650 gBrowser.selectedTab = gBrowser.addTab();
651 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
652 },
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");
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");
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");
676 // Wait for the install confirmation dialog
677 wait_for_install_dialog(function(aWindow) {
678 info("Timeouts after this probably mean bug 589954 regressed");
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");
685 AddonManager.getAllInstalls(function(aInstalls) {
686 is(aInstalls.length, 1, "Should be one pending installs");
687 aInstalls[0].cancel();
689 Services.perms.remove("example.com", "install");
690 wait_for_notification_close(runNextTest);
691 gBrowser.removeTab(gBrowser.selectedTab);
692 });
693 });
695 aWindow.document.documentElement.acceptDialog();
696 });
697 });
699 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
700 });
701 });
703 // hide the panel (this simulates the user dismissing it)
704 aPanel.hidePopup();
705 });
707 aWindow.document.documentElement.acceptDialog();
708 });
709 });
711 var pm = Services.perms;
712 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
714 var triggers = encodeURIComponent(JSON.stringify({
715 "XPI": "unsigned.xpi"
716 }));
717 gBrowser.selectedTab = gBrowser.addTab();
718 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
719 },
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");
727 // Close the notification
728 let anchor = document.getElementById("addons-notification-icon");
729 anchor.click();
730 // Reopen the notification
731 anchor.click();
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");
740 // Cancel the download
741 EventUtils.synthesizeMouse(button, 2, 2, {});
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");
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");
758 AddonManager.getAllInstalls(function(aInstalls) {
759 is(aInstalls.length, 1, "Should be one pending install");
760 aInstalls[0].cancel();
762 Services.perms.remove("example.com", "install");
763 wait_for_notification_close(runNextTest);
764 gBrowser.removeTab(gBrowser.selectedTab);
765 });
766 });
768 aWindow.document.documentElement.acceptDialog();
769 });
771 // Restart the download
772 EventUtils.synthesizeMouse(notification.button, 20, 10, {});
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 });
781 var pm = Services.perms;
782 pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
784 var triggers = encodeURIComponent(JSON.stringify({
785 "XPI": "unsigned.xpi"
786 }));
787 gBrowser.selectedTab = gBrowser.addTab();
788 gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
789 },
791 function test_failed_security() {
792 Services.prefs.setBoolPref(PREF_INSTALL_REQUIREBUILTINCERTS, false);
794 setup_redirect({
795 "Location": TESTROOT + "unsigned.xpi"
796 });
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");
803 // Click on Allow
804 EventUtils.synthesizeMouse(notification.button, 20, 10, {});
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");
812 // Wait for it to fail
813 Services.obs.addObserver(function() {
814 Services.obs.removeObserver(arguments.callee, "addon-install-failed");
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");
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 });
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 ];
838 var gTestStart = null;
840 function runNextTest() {
841 if (gTestStart)
842 info("Test part took " + (Date.now() - gTestStart) + "ms");
844 ok(!PopupNotifications.isPanelOpen, "Notification should be closed");
846 AddonManager.getAllInstalls(function(aInstalls) {
847 is(aInstalls.length, 0, "Should be no active installs");
849 if (TESTS.length == 0) {
850 finish();
851 return;
852 }
854 info("Running " + TESTS[0].name);
855 gTestStart = Date.now();
856 TESTS.shift()();
857 });
858 };
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 };
870 function test() {
871 requestLongerTimeout(4);
872 waitForExplicitFinish();
874 Services.prefs.setBoolPref("extensions.logging.enabled", true);
875 Services.prefs.setBoolPref("extensions.strictCompatibility", true);
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);
882 PopupNotifications.transitionsEnabled = false;
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;
890 AddonManager.getAllInstalls(function(aInstalls) {
891 aInstalls.forEach(function(aInstall) {
892 aInstall.cancel();
893 });
894 });
896 Services.prefs.clearUserPref("extensions.logging.enabled");
897 Services.prefs.clearUserPref("extensions.strictCompatibility");
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 });
905 runNextTest();
906 }