Bug 596336: Allow modifying the userDisabled property of new installs. r=robstrong, a=blocks-betaN
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 12 Oct 2010 12:15:40 -0700
changeset 55373 83c1aa707d32db48a01d7896fde907613c3fd950
parent 55372 35dc1d30acf67590c17d0e24b86db226f1adb9a4
child 55374 59f185971b5c748b3770a5334226c893b950411d
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobstrong, blocks-betaN
bugs596336
milestone2.0b8pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 596336: Allow modifying the userDisabled property of new installs. r=robstrong, a=blocks-betaN
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
toolkit/mozapps/extensions/test/xpcshell/test_install.js
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -1532,16 +1532,18 @@ var XPIProvider = {
       try {
         // If not load it
         if (!newAddon) {
           let file = aInstallLocation.getLocationForID(aOldAddon.id);
           if (file.isFile())
             newAddon = loadManifestFromZipFile(file);
           else
             newAddon = loadManifestFromDir(file);
+          // Carry over the userDisabled setting for add-ons that just appeared
+          newAddon.userDisabled = aOldAddon.userDisabled;
         }
 
         // The ID in the manifest that was loaded must match the ID of the old
         // add-on.
         if (newAddon.id != aOldAddon.id)
           throw new Error("Incorrect id in install manifest");
       }
       catch (e) {
@@ -3931,17 +3933,16 @@ var XPIDatabase = {
    */
   updateAddonMetadata: function XPIDB_updateAddonMetadata(aOldAddon, aNewAddon,
                                                           aDescriptor) {
     this.beginTransaction();
 
     // Any errors in here should rollback the transaction
     try {
       this.removeAddonMetadata(aOldAddon);
-      aNewAddon.userDisabled = aOldAddon.userDisabled;
       aNewAddon.installDate = aOldAddon.installDate;
       aNewAddon.applyBackgroundUpdates = aOldAddon.applyBackgroundUpdates;
       this.addAddonMetadata(aNewAddon, aDescriptor);
       this.commitTransaction();
     }
     catch (e) {
       this.rollbackTransaction();
       throw e;
@@ -4213,16 +4214,18 @@ function AddonInstall(aCallback, aInstal
       }
     }
 
     try {
       let self = this;
       this.loadManifest(function() {
         XPIDatabase.getVisibleAddonForID(self.addon.id, function(aAddon) {
           self.existingAddon = aAddon;
+          if (aAddon)
+            self.addon.userDisabled = aAddon.userDisabled;
           self.addon.updateDate = Date.now();
           self.addon.installDate = aAddon ? aAddon.installDate : self.addon.updateDate;
 
           if (!self.addon.isCompatible) {
             // TODO Should we send some event here?
             self.state = AddonManager.STATE_CHECKING;
             new UpdateChecker(self.addon, {
               onUpdateFinished: function(aAddon) {
@@ -4866,16 +4869,18 @@ AddonInstall.prototype = {
 
   /**
    * Notify listeners that the download completed.
    */
   downloadCompleted: function() {
     let self = this;
     XPIDatabase.getVisibleAddonForID(this.addon.id, function(aAddon) {
       self.existingAddon = aAddon;
+      if (aAddon)
+        self.addon.userDisabled = aAddon.userDisabled;
       self.addon.updateDate = Date.now();
       self.addon.installDate = aAddon ? aAddon.installDate : self.addon.updateDate;
       self.state = AddonManager.STATE_DOWNLOADED;
       if (AddonManagerPrivate.callInstallListeners("onDownloadEnded",
                                                    self.listeners,
                                                    self.wrapper)) {
         // If a listener changed our state then do not proceed with the install
         if (self.state != AddonManager.STATE_DOWNLOADED)
--- a/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_bootstrap.js
@@ -632,18 +632,89 @@ function run_test_14() {
     do_check_not_in_crash_annotation("bootstrap1@tests.mozilla.org", "3.0");
 
     b1.uninstall();
 
     run_test_15();
   });
 }
 
+// Tests that upgrading a disabled bootstrapped extension still calls uninstall
+// and install but doesn't startup the new version
+function run_test_15() {
+  installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
+    AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
+      do_check_neq(b1, null);
+      do_check_eq(b1.version, "1.0");
+      do_check_false(b1.appDisabled);
+      do_check_false(b1.userDisabled);
+      do_check_true(b1.isActive);
+      do_check_eq(getInstalledVersion(), 1);
+      do_check_eq(getActiveVersion(), 1);
+
+      b1.userDisabled = true;
+      do_check_false(b1.isActive);
+      do_check_eq(getInstalledVersion(), 1);
+      do_check_eq(getActiveVersion(), 0);
+
+      prepare_test({ }, [
+        "onNewInstall"
+      ]);
+
+      AddonManager.getInstallForFile(do_get_addon("test_bootstrap1_2"), function(install) {
+        ensure_test_completed();
+
+        do_check_neq(install, null);
+        do_check_true(install.addon.userDisabled);
+
+        prepare_test({
+          "bootstrap1@tests.mozilla.org": [
+            ["onInstalling", false],
+            "onInstalled"
+          ]
+        }, [
+          "onInstallStarted",
+          "onInstallEnded",
+        ], check_test_15);
+        install.install();
+      });
+    });
+  });
+}
+
+function check_test_15() {
+  AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
+    do_check_neq(b1, null);
+    do_check_eq(b1.version, "2.0");
+    do_check_false(b1.appDisabled);
+    do_check_true(b1.userDisabled);
+    do_check_false(b1.isActive);
+    do_check_eq(getInstalledVersion(), 2);
+    do_check_eq(getActiveVersion(), 0);
+
+    restartManager();
+
+    AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
+      do_check_neq(b1, null);
+      do_check_eq(b1.version, "2.0");
+      do_check_false(b1.appDisabled);
+      do_check_true(b1.userDisabled);
+      do_check_false(b1.isActive);
+      do_check_eq(getInstalledVersion(), 2);
+      do_check_eq(getActiveVersion(), 0);
+
+      b1.uninstall();
+
+      run_test_16();
+    });
+  });
+}
+
 // Tests that bootstrapped extensions don't get loaded when in safe mode
-function run_test_15() {
+function run_test_16() {
   installAllFiles([do_get_addon("test_bootstrap1_1")], function() {
     AddonManager.getAddonByID("bootstrap1@tests.mozilla.org", function(b1) {
       // Should have installed and started
       do_check_eq(getInstalledVersion(), 1);
       do_check_eq(getActiveVersion(), 1);
       do_check_true(b1.isActive);
       do_check_eq(b1.iconURL, "chrome://foo/skin/icon.png");
       do_check_eq(b1.aboutURL, "chrome://foo/content/about.xul");
--- a/toolkit/mozapps/extensions/test/xpcshell/test_install.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_install.js
@@ -942,16 +942,20 @@ function check_test_13(install) {
     do_check_eq(olda2.pendingUpgrade, null);
 
     restartManager();
 
     // Check that the upgrade did not complete
     AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
       do_check_eq(a2.version, "2.0");
 
+      a2.uninstall();
+
+      restartManager();
+
       run_test_14();
     });
   });
 }
 
 // Check that cancelling the install from onDownloadStarted actually cancels it
 function run_test_14() {
   prepare_test({ }, [
@@ -1030,10 +1034,150 @@ function check_test_15(install) {
 
   install.addListener({
     onInstallStarted: function() {
       do_throw("Install should not have continued");
     }
   });
 
   // Allow the listener to return to see if it starts installing
-  do_execute_soon(end_test);
+  do_execute_soon(run_test_16);
+}
+
+// Verify that the userDisabled value carries over to the upgrade by default
+function run_test_16() {
+  restartManager();
+
+  let url = "http://localhost:4444/addons/test_install2_1.xpi";
+  AddonManager.getInstallForURL(url, function(aInstall) {
+    aInstall.addListener({
+      onInstallStarted: function() {
+        do_check_false(aInstall.addon.userDisabled);
+        aInstall.addon.userDisabled = true;
+      },
+
+      onInstallEnded: function() {
+        restartManager();
+
+        AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
+          do_check_true(a2.userDisabled);
+          do_check_false(a2.isActive);
+
+          let url = "http://localhost:4444/addons/test_install2_2.xpi";
+          AddonManager.getInstallForURL(url, function(aInstall) {
+            aInstall.addListener({
+              onInstallEnded: function() {
+                do_check_true(aInstall.addon.userDisabled);
+
+                restartManager();
+
+                AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
+                  do_check_true(a2.userDisabled);
+                  do_check_false(a2.isActive);
+
+                  a2.uninstall();
+                  restartManager();
+
+                  run_test_17();
+                });
+              }
+            });
+            aInstall.install();
+          }, "application/x-xpinstall");
+        });
+      }
+    });
+    aInstall.install();
+  }, "application/x-xpinstall");
 }
+
+// Verify that changing the userDisabled value before onInstallEnded works
+function run_test_17() {
+  let url = "http://localhost:4444/addons/test_install2_1.xpi";
+  AddonManager.getInstallForURL(url, function(aInstall) {
+    aInstall.addListener({
+      onInstallEnded: function() {
+        do_check_false(aInstall.addon.userDisabled);
+
+        restartManager();
+
+        AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
+          do_check_false(a2.userDisabled);
+          do_check_true(a2.isActive);
+
+          let url = "http://localhost:4444/addons/test_install2_2.xpi";
+          AddonManager.getInstallForURL(url, function(aInstall) {
+            aInstall.addListener({
+              onInstallStarted: function() {
+                do_check_false(aInstall.addon.userDisabled);
+                aInstall.addon.userDisabled = true;
+              },
+
+              onInstallEnded: function() {
+                restartManager();
+
+                AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
+                  do_check_true(a2.userDisabled);
+                  do_check_false(a2.isActive);
+
+                  a2.uninstall();
+                  restartManager();
+
+                  run_test_18();
+                });
+              }
+            });
+            aInstall.install();
+          }, "application/x-xpinstall");
+        });
+      }
+    });
+    aInstall.install();
+  }, "application/x-xpinstall");
+}
+
+// Verify that changing the userDisabled value before onInstallEnded works
+function run_test_18() {
+  let url = "http://localhost:4444/addons/test_install2_1.xpi";
+  AddonManager.getInstallForURL(url, function(aInstall) {
+    aInstall.addListener({
+      onInstallStarted: function() {
+        do_check_false(aInstall.addon.userDisabled);
+        aInstall.addon.userDisabled = true;
+      },
+
+      onInstallEnded: function() {
+        restartManager();
+
+        AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
+          do_check_true(a2.userDisabled);
+          do_check_false(a2.isActive);
+
+          let url = "http://localhost:4444/addons/test_install2_2.xpi";
+          AddonManager.getInstallForURL(url, function(aInstall) {
+            aInstall.addListener({
+              onInstallStarted: function() {
+                do_check_true(aInstall.addon.userDisabled);
+                aInstall.addon.userDisabled = false;
+              },
+
+              onInstallEnded: function() {
+                restartManager();
+
+                AddonManager.getAddonByID("addon2@tests.mozilla.org", function(a2) {
+                  do_check_false(a2.userDisabled);
+                  do_check_true(a2.isActive);
+
+                  a2.uninstall();
+                  restartManager();
+
+                  end_test();
+                });
+              }
+            });
+            aInstall.install();
+          }, "application/x-xpinstall");
+        });
+      }
+    });
+    aInstall.install();
+  }, "application/x-xpinstall");
+}