Bug 672485 - Ensure window watcher is defined. r=dtownsend,jst
☠☠ backed out by aa9f527a4928 ☠ ☠
authorBlair McBride <bmcbride@mozilla.com>
Thu, 11 Aug 2011 14:29:48 +1200
changeset 74200 84ce41f8cec7abf76d97d9c6822da1e1dd83bbf2
parent 74199 1221d45e7acad7a93d9eb3962b38dbe6315e8bde
child 74201 3948d561f905727d10bb285b9420eb513f863629
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersdtownsend, jst
bugs672485
milestone8.0a1
Bug 672485 - Ensure window watcher is defined. r=dtownsend,jst
toolkit/mozapps/extensions/amWebInstallListener.js
toolkit/mozapps/extensions/test/xpinstall/Makefile.in
toolkit/mozapps/extensions/test/xpinstall/browser_bug672485.js
--- a/toolkit/mozapps/extensions/amWebInstallListener.js
+++ b/toolkit/mozapps/extensions/amWebInstallListener.js
@@ -49,16 +49,18 @@
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cr = Components.results;
 
 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
 Components.utils.import("resource://gre/modules/AddonManager.jsm");
 Components.utils.import("resource://gre/modules/Services.jsm");
 
+const URI_XPINSTALL_DIALOG = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
+
 // Installation can begin from any of these states
 const READY_STATES = [
   AddonManager.STATE_AVAILABLE,
   AddonManager.STATE_DOWNLOAD_FAILED,
   AddonManager.STATE_INSTALL_FAILED,
   AddonManager.STATE_CANCELLED
 ];
 
@@ -199,18 +201,23 @@ Installer.prototype = {
       catch (e) {}
     }
 
     let args = {};
     args.url = this.url;
     args.installs = this.downloads;
     args.wrappedJSObject = args;
 
-    Services.ww.openWindow(this.window, "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul",
-                           null, "chrome,modal,centerscreen", args);
+    try {
+      Services.ww.openWindow(this.window, URI_XPINSTALL_DIALOG,
+                             null, "chrome,modal,centerscreen", args);
+    } catch (e) {
+      this.downloads.forEach(function(aInstall) aInstall.cancel());
+      notifyObservers("addon-install-failed", this.window, this.url, failed);
+    }
   },
 
   /**
    * Checks if all installs are now complete and if so notifies observers.
    */
   checkAllInstalled: function() {
     var failed = [];
 
--- a/toolkit/mozapps/extensions/test/xpinstall/Makefile.in
+++ b/toolkit/mozapps/extensions/test/xpinstall/Makefile.in
@@ -93,16 +93,17 @@ include $(topsrcdir)/config/rules.mk
                  browser_httphash4.js \
                  browser_httphash5.js \
                  browser_httphash6.js \
                  browser_badargs.js \
                  browser_badargs2.js \
                  browser_bug611242.js \
                  browser_bug638292.js \
                  browser_bug645699.js \
+                 browser_bug672485.js \
                  unsigned.xpi \
                  signed.xpi \
                  signed2.xpi \
                  signed-no-o.xpi \
                  signed-no-cn.xpi \
                  signed-untrusted.xpi \
                  signed-tampered.xpi \
                  theme.xpi \
new file mode 100644
--- /dev/null
+++ b/toolkit/mozapps/extensions/test/xpinstall/browser_bug672485.js
@@ -0,0 +1,48 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+function test() {
+  Harness.installConfirmCallback = confirm_install;
+  Harness.installFailedCallback = failed_install;
+  Harness.installEndedCallback = complete_install;
+  Harness.installsCompletedCallback = finish_test;
+  Harness.setup();
+  
+  delete Services.ww;
+  is(Services.ww, undefined, "Services.ww should now be undefined");
+
+  var pm = Services.perms;
+  pm.add(makeURI("http://example.com/"), "install", pm.ALLOW_ACTION);
+
+  var triggers = encodeURIComponent(JSON.stringify({
+    "Unsigned XPI": TESTROOT + "unsigned.xpi"
+  }));
+  gBrowser.selectedTab = gBrowser.addTab();
+  gBrowser.loadURI(TESTROOT + "installtrigger.html?" + triggers);
+}
+
+function confirm_install(window) {
+  ok(false, "Should not see the install dialog");
+  return false;
+}
+
+function failed_install() {
+  ok(true, "Install should fail");
+}
+
+function complete_install() {
+  ok(false, "Install should not have completed");
+  return false;
+}
+
+function finish_test(count) {
+  is(count, 0, "0 Add-ons should have been successfully installed");
+
+  gBrowser.removeCurrentTab();
+  
+  Services.ww = Cc["@mozilla.org/embedcomp/window-watcher;1"]
+                  .getService(Ci.nsIWindowWatcher);
+  
+  Harness.finish();
+}