Bug 565064: Update theme disabled states when changing builds. r=robstrong
authorDave Townsend <dtownsend@oxymoronical.com>
Fri, 02 Jul 2010 16:03:34 -0700
changeset 47199 d048a5c7195faeebb3f4ceef2e9566ed23ba3b23
parent 47198 443b653e6b2e5b417e160ad57956149e20d32564
child 47200 2725e6f722cb3f582fe1e2bc4fe5af796ed9859c
push id14268
push userdtownsend@mozilla.com
push dateSat, 03 Jul 2010 14:00:53 +0000
treeherdermozilla-central@2725e6f722cb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrobstrong
bugs565064
milestone2.0b2pre
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 565064: Update theme disabled states when changing builds. r=robstrong
toolkit/mozapps/extensions/XPIProvider.jsm
toolkit/mozapps/extensions/test/xpcshell/test_theme.js
--- a/toolkit/mozapps/extensions/XPIProvider.jsm
+++ b/toolkit/mozapps/extensions/XPIProvider.jsm
@@ -1412,47 +1412,54 @@ var XPIProvider = {
             changed = true;
           }
         }
       }
 
       // App version changed, we may need to update the appDisabled property.
       if (aUpdateCompatibility) {
         let appDisabled = !isUsableAddon(aOldAddon);
-
-        // If the property has changed update the database.
-        if (appDisabled != aOldAddon.appDisabled) {
+        let userDisabled = aOldAddon.userDisabled;
+        // Sync the userDisabled flag to the selectedSkin
+        if (aOldAddon.type == "theme")
+          userDisabled = aOldAddon.internalName != XPIProvider.selectedSkin;
+        let wasDisabled = aOldAddon.appDisabled || aOldAddon.userDisabled;
+        let isDisabled = appDisabled || userDisabled;
+
+        // If either property has changed update the database.
+        if (appDisabled != aOldAddon.appDisabled ||
+            userDisabled != aOldAddon.userDisabled) {
           LOG("Add-on " + aOldAddon.id + " changed appDisabled state to " +
-              appDisabled);
+              appDisabled + " and userDisabled state to " + userDisabled);
           XPIDatabase.setAddonProperties(aOldAddon, {
-            appDisabled: appDisabled
+            appDisabled: appDisabled,
+            userDisabled: userDisabled
           });
-
-          // If this is a visible add-on and it isn't userDisabled then we
-          // may need a restart or to update the bootstrap list.
-          if (aOldAddon.visible && !aOldAddon.userDisabled) {
-            if (aOldAddon.bootstrap) {
-              // When visible and not userDisabled, active is the opposite of
-              // appDisabled.
-              aOldAddon.active = !aOldAddon.appDisabled;
-              XPIDatabase.updateAddonActive(aOldAddon);
-              if (aOldAddon.active) {
-                XPIProvider.bootstrappedAddons[aOldAddon.id] = {
-                  version: aOldAddon.version,
-                  descriptor: aAddonState.descriptor
-                };
-              }
-              else {
-                delete XPIProvider.bootstrappedAddons[aOldAddon.id];
-              }
+        }
+
+        // If this is a visible add-on and it has changed disabled state then we
+        // may need a restart or to update the bootstrap list.
+        if (aOldAddon.visible && wasDisabled != isDisabled) {
+          if (aOldAddon.bootstrap) {
+            // Update the add-ons active state
+            aOldAddon.active = !isDisabled;
+            XPIDatabase.updateAddonActive(aOldAddon);
+            if (aOldAddon.active) {
+              XPIProvider.bootstrappedAddons[aOldAddon.id] = {
+                version: aOldAddon.version,
+                descriptor: aAddonState.descriptor
+              };
             }
             else {
-              changed = true;
+              delete XPIProvider.bootstrappedAddons[aOldAddon.id];
             }
           }
+          else {
+            changed = true;
+          }
         }
       }
 
       return changed;
     }
 
     /**
      * Called when an add-on has been removed.
--- a/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
@@ -883,11 +883,37 @@ function run_test_16() {
     do_check_false(d.userDisabled);
     do_check_false(d.appDisabled);
     do_check_true(d.isActive);
 
     do_check_true(t1.userDisabled);
     do_check_true(t1.appDisabled);
     do_check_false(t1.isActive);
 
+    run_test_17();
+  });
+}
+
+// Verifies that if the selected theme pref is changed by a different version
+// of the application that we correctly reset it when it points to an
+// incompatible theme
+function run_test_17() {
+  restartManager(1, "2");
+  shutdownManager();
+
+  Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0");
+
+  restartManager(1, "3");
+
+  do_check_eq(Services.prefs.getCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN), "classic/1.0");
+  AddonManager.getAddonsByIDs(["default@tests.mozilla.org",
+                               "theme1@tests.mozilla.org"], function([d, t1]) {
+    do_check_false(d.userDisabled);
+    do_check_false(d.appDisabled);
+    do_check_true(d.isActive);
+
+    do_check_true(t1.userDisabled);
+    do_check_true(t1.appDisabled);
+    do_check_false(t1.isActive);
+
     end_test();
   });
 }