Bug 566597: Firefox still wears the active lightweight theme even it has been removed. r=dtownsend
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 08 Jun 2010 09:45:30 -0700
changeset 43314 6c3d62593a9e91d842e6f458a930da72b204d143
parent 43313 33760547ecf7edc099b4ca4abc5cb475d9dfb86a
child 43316 1aacd24d112fed4fca15216a6c932cf0f2749808
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)
reviewersdtownsend
bugs566597
milestone1.9.3a5pre
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 566597: Firefox still wears the active lightweight theme even it has been removed. r=dtownsend
toolkit/mozapps/extensions/LightweightThemeManager.jsm
toolkit/mozapps/extensions/test/xpcshell/test_theme.js
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -139,17 +139,17 @@ var LightweightThemeManager = {
     if (!theme)
       return;
 
     let wrapper = new AddonWrapper(theme);
     AddonManagerPrivate.callAddonListeners("onUninstalling", wrapper, false);
 
     var currentTheme = this.currentTheme;
     if (currentTheme && currentTheme.id == aId) {
-      _prefs.setBoolPref("isThemeSelected", false);
+      this.themeChanged(null);
       AddonManagerPrivate.notifyAddonChanged(null, ADDON_TYPE, false);
     }
 
     _updateUsedThemes(_usedThemesExceptId(aId));
     AddonManagerPrivate.callAddonListeners("onUninstalled", wrapper);
   },
 
   previewTheme: function (aData) {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
@@ -8,16 +8,33 @@ Components.utils.import("resource://gre/
 
 const PREF_GENERAL_SKINS_SELECTEDSKIN = "general.skins.selectedSkin";
 
 Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
 
 const profileDir = gProfD.clone();
 profileDir.append("extensions");
 
+// Observer to ensure a "lightweight-theme-styling-update" notification is sent
+// when expected
+var gLWThemeChanged = false;
+var LightweightThemeObserver = {
+  observe: function(aSubject, aTopic, aData) {
+    if (aTopic != "lightweight-theme-styling-update")
+      return;
+
+    gLWThemeChanged = true;
+  }
+};
+
+AM_Cc["@mozilla.org/observer-service;1"]
+     .getService(Components.interfaces.nsIObserverService)
+     .addObserver(LightweightThemeObserver, "lightweight-theme-styling-update", false);
+
+
 function run_test() {
   do_test_pending();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   Services.prefs.setCharPref(PREF_GENERAL_SKINS_SELECTEDSKIN, "theme1/1.0");
   var dest = profileDir.clone();
   dest.append("theme1@tests.mozilla.org");
   writeInstallRDFToDir({
@@ -141,16 +158,17 @@ function check_test_1() {
 
     do_check_neq(t2, null);
     do_check_false(t2.userDisabled);
     do_check_false(t2.appDisabled);
     do_check_true(t2.isActive);
     do_check_true(isThemeInAddonsList(profileDir, t2.id));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_false(hasFlag(t2.permissions, AddonManager.PERM_CAN_ENABLE));
+    do_check_false(gLWThemeChanged);
 
     run_test_2();
   });
 }
 
 // Removing the active theme should fall back to the default (not ideal in this
 // case since we don't have the default theme installed)
 function run_test_2() {
@@ -168,16 +186,17 @@ function run_test_2() {
     do_check_false(t1.appDisabled);
     do_check_false(t1.isActive);
     do_check_false(isThemeInAddonsList(profileDir, t1.id));
     do_check_false(hasFlag(t1.permissions, AddonManager.PERM_CAN_DISABLE));
     do_check_true(hasFlag(t1.permissions, AddonManager.PERM_CAN_ENABLE));
 
     do_check_eq(t2, null);
     do_check_false(isThemeInAddonsList(profileDir, "theme2@tests.mozilla.org"));
+    do_check_false(gLWThemeChanged);
 
     run_test_3();
   });
 }
 
 // Installing a lightweight theme should happen instantly and disable the default theme
 function run_test_3() {
   var dest = profileDir.clone();
@@ -257,16 +276,19 @@ function run_test_3() {
         else {
           dump("Checking theme " + a.id + "\n");
           do_check_false(a.isActive);
           do_check_true(a.userDisabled);
         }
       });
       do_check_true(seen);
 
+      do_check_true(gLWThemeChanged);
+      gLWThemeChanged = false;
+
       run_test_4();
     });
   });
 }
 
 // Installing a second lightweight theme should disable the first with no restart
 function run_test_4() {
   prepare_test({
@@ -324,16 +346,19 @@ function run_test_4() {
         else {
           dump("Checking theme " + a.id + "\n");
           do_check_false(a.isActive);
           do_check_true(a.userDisabled);
         }
       });
       do_check_true(seen);
 
+      do_check_true(gLWThemeChanged);
+      gLWThemeChanged = false;
+
       run_test_5();
     });
   });
 }
 
 // Switching to a custom theme should disable the lightweight theme and require
 // a restart. Cancelling that should also be possible.
 function run_test_5() {
@@ -380,16 +405,17 @@ function run_test_5() {
 
     do_check_false(t2.isActive);
     do_check_false(t2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations));
     do_check_true(p2.isActive);
     do_check_true(p2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations));
     do_check_true(hasFlag(AddonManager.PERM_CAN_ENABLE, p2.permissions));
+    do_check_false(gLWThemeChanged);
 
     check_test_5();
   });
 }
 
 function check_test_5() {
   restartManager(0);
 
@@ -397,16 +423,19 @@ function check_test_5() {
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
     do_check_true(t2.isActive);
     do_check_false(t2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, t2.pendingOperations));
     do_check_false(p2.isActive);
     do_check_true(p2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, p2.pendingOperations));
 
+    do_check_true(gLWThemeChanged);
+    gLWThemeChanged = false;
+
     run_test_6();
   });
 }
 
 // Switching from a custom theme to a lightweight theme should require a restart
 function run_test_6() {
   prepare_test({
     "2@personas.mozilla.org": [
@@ -450,16 +479,17 @@ function run_test_6() {
     ensure_test_completed();
 
     do_check_false(p2.isActive);
     do_check_false(p2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
     do_check_true(t2.isActive);
     do_check_true(t2.userDisabled);
     do_check_true(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
+    do_check_false(gLWThemeChanged);
 
     check_test_6();
   });
 }
 
 function check_test_6() {
   restartManager(0);
 
@@ -467,16 +497,19 @@ function check_test_6() {
                                "theme2@tests.mozilla.org"], function([p2, t2]) {
     do_check_true(p2.isActive);
     do_check_false(p2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_ENABLE, p2.pendingOperations));
     do_check_false(t2.isActive);
     do_check_true(t2.userDisabled);
     do_check_false(hasFlag(AddonManager.PENDING_DISABLE, t2.pendingOperations));
 
+    do_check_true(gLWThemeChanged);
+    gLWThemeChanged = false;
+
     run_test_7();
   });
 }
 
 // Uninstalling a lightweight theme should not require a restart
 function run_test_7() {
   prepare_test({
     "1@personas.mozilla.org": [
@@ -485,23 +518,26 @@ function run_test_7() {
     ]
   });
 
   AddonManager.getAddonByID("1@personas.mozilla.org", function(p1) {
     p1.uninstall();
 
     ensure_test_completed();
     do_check_eq(LightweightThemeManager.usedThemes.length, 1);
+    do_check_false(gLWThemeChanged);
 
     run_test_8();
   });
 }
 
 // Uninstalling a lightweight theme in use should not require a restart and it
 // should reactivate the default theme
+// Also, uninstalling a lightweight theme in use should send a
+// "lightweight-theme-styling-update" notification through the observer service
 function run_test_8() {
   prepare_test({
     "2@personas.mozilla.org": [
       ["onUninstalling", false],
       "onUninstalled"
     ],
     "default@tests.mozilla.org": [
       ["onEnabling", false],
@@ -510,16 +546,19 @@ function run_test_8() {
   });
 
   AddonManager.getAddonByID("2@personas.mozilla.org", function(p2) {
     p2.uninstall();
 
     ensure_test_completed();
     do_check_eq(LightweightThemeManager.usedThemes.length, 0);
 
+    do_check_true(gLWThemeChanged);
+    gLWThemeChanged = false;
+
     run_test_9();
   });
 }
 
 // Uninstalling a theme not in use should not require a restart
 function run_test_9() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     prepare_test({
@@ -530,16 +569,17 @@ function run_test_9() {
     });
 
     t1.uninstall();
 
     ensure_test_completed();
 
     AddonManager.getAddonByID("theme1@tests.mozilla.org", function(newt1) {
       do_check_eq(newt1, null);
+      do_check_false(gLWThemeChanged);
 
       run_test_10();
     });
   });
 }
 
 // Uninstalling a custom theme in use should require a restart
 function run_test_10() {
@@ -575,16 +615,17 @@ function run_test_10() {
         "default@tests.mozilla.org": [
           "onEnabling"
         ]
       });
 
       t2.uninstall();
 
       ensure_test_completed();
+      do_check_false(gLWThemeChanged);
 
       restartManager(0);
 
       run_test_11();
     });
   });
 }
 
@@ -619,16 +660,17 @@ function run_test_11() {
 function check_test_11() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     var preview = profileDir.clone();
     preview.append("theme1@tests.mozilla.org");
     preview.append("preview.png");
     do_check_eq(t1.screenshots.length, 1);
     do_check_eq(t1.screenshots[0], NetUtil.newURI(preview).spec);
+    do_check_false(gLWThemeChanged);
 
     run_test_12();
   });
 }
 
 // Updating a custom theme not in use should not require a restart
 function run_test_12() {
   prepare_test({ }, [
@@ -655,16 +697,17 @@ function run_test_12() {
     ], check_test_12);
     install.install();
   });
 }
 
 function check_test_12() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
+    do_check_false(gLWThemeChanged);
 
     run_test_13();
   });
 }
 
 // Updating a custom theme in use should require a restart
 function run_test_13() {
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
@@ -708,16 +751,17 @@ function run_test_13() {
 }
 
 function check_test_13() {
   restartManager(1);
 
   AddonManager.getAddonByID("theme1@tests.mozilla.org", function(t1) {
     do_check_neq(t1, null);
     do_check_true(t1.isActive);
+    do_check_false(gLWThemeChanged);
     t1.uninstall();
     restartManager();
 
     run_test_14();
   });
 }
 
 // Switching from a lightweight theme to the default theme should not require
@@ -752,11 +796,14 @@ function run_test_14() {
     });
 
     d.userDisabled = false;
     ensure_test_completed();
 
     do_check_false(d.userDisabled);
     do_check_true(d.isActive);
 
+    do_check_true(gLWThemeChanged);
+    gLWThemeChanged = false;
+
     end_test();
   });
 }