Bug 611559 - Backgrounds never have PERM_CAN_DISABLE, even when they can be disabled; r,a=Mossop
authorBlair McBride <bmcbride@mozilla.com>
Sat, 19 Feb 2011 01:14:11 +1300
changeset 63032 7394613d075056f0861dd2ff9fbce9ba4b956a07
parent 63031 91f89c7d20868a2c74d90464d1b7871099ff2bc9
child 63033 7b6be2af0613624f8984438dc5014d22f8b7370a
push id18997
push usereakhgari@mozilla.com
push dateThu, 24 Feb 2011 00:28:36 +0000
treeherdermozilla-central@1c9cd44cff88 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs611559
milestone2.0b13pre
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 611559 - Backgrounds never have PERM_CAN_DISABLE, even when they can be disabled; r,a=Mossop
toolkit/mozapps/extensions/LightweightThemeManager.jsm
toolkit/mozapps/extensions/test/browser/browser_bug591465.js
toolkit/mozapps/extensions/test/browser/browser_list.js
toolkit/mozapps/extensions/test/xpcshell/test_dss.js
toolkit/mozapps/extensions/test/xpcshell/test_theme.js
--- a/toolkit/mozapps/extensions/LightweightThemeManager.jsm
+++ b/toolkit/mozapps/extensions/LightweightThemeManager.jsm
@@ -82,20 +82,21 @@ const PERSIST_FILES = {
   return this._maxUsedThemes;
 });
 
 __defineSetter__("_maxUsedThemes", function(aVal) {
   delete this._maxUsedThemes;
   return this._maxUsedThemes = aVal;
 });
 
-// Holds the ID of the theme being enabled while sending out the events so
-// cached AddonWrapper instances can return correct values for permissions and
-// pendingOperations
+// Holds the ID of the theme being enabled or disabled while sending out the
+// events so cached AddonWrapper instances can return correct values for
+// permissions and pendingOperations
 var _themeIDBeingEnabled = null;
+var _themeIDBeingDisbled = null;
 
 var LightweightThemeManager = {
   get usedThemes () {
     try {
       return JSON.parse(_prefs.getComplexValue("usedThemes",
                                                Ci.nsISupportsString).data);
     } catch (e) {
       return [];
@@ -325,26 +326,28 @@ var LightweightThemeManager = {
       }
     }
     catch (e) {
     }
 
     if (current) {
       if (current.id == id)
         return;
+      _themeIDBeingDisbled = current.id;
       let wrapper = new AddonWrapper(current);
       if (aPendingRestart) {
         Services.prefs.setCharPref(PREF_LWTHEME_TO_SELECT, "");
         AddonManagerPrivate.callAddonListeners("onDisabling", wrapper, true);
       }
       else {
         AddonManagerPrivate.callAddonListeners("onDisabling", wrapper, false);
         this.themeChanged(null);
         AddonManagerPrivate.callAddonListeners("onDisabled", wrapper);
       }
+      _themeIDBeingDisbled = null;
     }
 
     if (id) {
       let theme = this.getUsedTheme(id);
       _themeIDBeingEnabled = id;
       let wrapper = new AddonWrapper(theme);
       if (aPendingRestart) {
         AddonManagerPrivate.callAddonListeners("onEnabling", wrapper, true);
@@ -472,22 +475,26 @@ function AddonWrapper(aTheme) {
     // probably not worth exposing.
     return null;
   });
 
   this.__defineGetter__("permissions", function() {
     let permissions = AddonManager.PERM_CAN_UNINSTALL;
     if (this.userDisabled)
       permissions |= AddonManager.PERM_CAN_ENABLE;
+    else
+      permissions |= AddonManager.PERM_CAN_DISABLE;
     return permissions;
   });
 
   this.__defineGetter__("userDisabled", function() {
     if (_themeIDBeingEnabled == aTheme.id)
       return false;
+    if (_themeIDBeingDisbled == aTheme.id)
+      return true;
 
     try {
       let toSelect = Services.prefs.getCharPref(PREF_LWTHEME_TO_SELECT);
       return aTheme.id != toSelect;
     }
     catch (e) {
       let current = LightweightThemeManager.currentTheme;
       return !current || current.id != aTheme.id;
--- a/toolkit/mozapps/extensions/test/browser/browser_bug591465.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_bug591465.js
@@ -1,22 +1,38 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Bug 591465 - Context menu of add-ons miss context related state change entries
 
+
+Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
+
+
 const PREF_GETADDONS_MAXRESULTS = "extensions.getAddons.maxResults";
 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
 const SEARCH_URL = TESTROOT + "browser_bug591465.xml";
 const SEARCH_QUERY = "SEARCH";
 
 var gManagerWindow;
 var gProvider;
 var gContextMenu;
+var gLWTheme = {
+                id: "4",
+                version: "1",
+                name: "Bling",
+                description: "SO MUCH BLING!",
+                author: "Pixel Pusher",
+                homepageURL: "http://localhost:4444/data/index.html",
+                headerURL: "http://localhost:4444/data/header.png",
+                footerURL: "http://localhost:4444/data/footer.png",
+                previewURL: "http://localhost:4444/data/preview.png",
+                iconURL: "http://localhost:4444/data/icon.png"
+              };
 
 
 function test() {
   waitForExplicitFinish();
 
   gProvider = new MockProvider();
 
   gProvider.createAddons([{
@@ -42,16 +58,17 @@ function test() {
    }, {
     id: "theme3@tests.mozilla.org",
     name: "theme 3",
     version: "1.0",
     type: "theme",
     permissions: 0
   }]);
 
+
   open_manager("addons://list/extension", function(aWindow) {
     gManagerWindow = aWindow;
     gContextMenu = aWindow.document.getElementById("addonitem-popup");
     run_next_test();
   });
 }
 
 
@@ -223,16 +240,106 @@ add_test(function() {
 
   info("Opening context menu on disabled theme item");
   EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
   EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
 });
 
 
 add_test(function() {
+  LightweightThemeManager.currentTheme = gLWTheme;
+
+  var el = get_addon_element(gManagerWindow, "4@personas.mozilla.org");
+
+  gContextMenu.addEventListener("popupshown", function() {
+    gContextMenu.removeEventListener("popupshown", arguments.callee, false);
+
+    check_contextmenu(true, true, false, false, false);
+
+    gContextMenu.hidePopup();
+    run_next_test();
+  }, false);
+
+  info("Opening context menu on enabled LW theme item");
+  EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
+  EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
+});
+
+
+add_test(function() {
+  LightweightThemeManager.currentTheme = null;
+
+  var el = get_addon_element(gManagerWindow, "4@personas.mozilla.org");
+
+  gContextMenu.addEventListener("popupshown", function() {
+    gContextMenu.removeEventListener("popupshown", arguments.callee, false);
+
+    check_contextmenu(true, false, false, false, false);
+
+    gContextMenu.hidePopup();
+    run_next_test();
+  }, false);
+
+  info("Opening context menu on disabled LW theme item");
+  EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
+  EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
+});
+
+
+add_test(function() {
+  LightweightThemeManager.currentTheme = gLWTheme;
+
+  gManagerWindow.loadView("addons://detail/4@personas.mozilla.org");
+  wait_for_view_load(gManagerWindow, function() {
+
+    gContextMenu.addEventListener("popupshown", function() {
+      gContextMenu.removeEventListener("popupshown", arguments.callee, false);
+
+      check_contextmenu(true, true, false, true, false);
+
+      gContextMenu.hidePopup();
+      run_next_test();
+    }, false);
+
+    info("Opening context menu on enabled LW theme, in detail view");
+    var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container");
+    EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
+    EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
+  });
+});
+
+
+add_test(function() {
+  LightweightThemeManager.currentTheme = null;
+
+  gManagerWindow.loadView("addons://detail/4@personas.mozilla.org");
+  wait_for_view_load(gManagerWindow, function() {
+
+    gContextMenu.addEventListener("popupshown", function() {
+      gContextMenu.removeEventListener("popupshown", arguments.callee, false);
+
+      check_contextmenu(true, false, false, true, false);
+
+      gContextMenu.hidePopup();
+
+      AddonManager.getAddonByID("4@personas.mozilla.org", function(aAddon) {
+        aAddon.uninstall();
+        run_next_test();
+      });
+    }, false);
+
+    info("Opening context menu on disabled LW theme, in detail view");
+    var el = gManagerWindow.document.querySelector("#detail-view .detail-view-container");
+    EventUtils.synthesizeMouse(el, 4, 4, { }, gManagerWindow);
+    EventUtils.synthesizeMouse(el, 4, 4, { type: "contextmenu", button: 2 }, gManagerWindow);
+  });
+});
+
+
+add_test(function() {
   gManagerWindow.loadView("addons://detail/addon1@tests.mozilla.org");
   wait_for_view_load(gManagerWindow, function() {
 
     gContextMenu.addEventListener("popupshown", function() {
       gContextMenu.removeEventListener("popupshown", arguments.callee, false);
 
       check_contextmenu(false, true, false, true, false);
 
--- a/toolkit/mozapps/extensions/test/browser/browser_list.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_list.js
@@ -1,24 +1,41 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests the list view
 
+Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
+
+
 var gProvider;
 var gManagerWindow;
 var gCategoryUtilities;
 
 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
 var gVersion = Services.appinfo.version;
 var gBlocklistURL = Services.urlFormatter.formatURLPref("extensions.blocklist.detailsURL");
 var gPluginURL = Services.urlFormatter.formatURLPref("plugins.update.url");
 var gDate = new Date(2010, 7, 16);
 
+var gLWTheme = {
+                id: "4",
+                version: "1",
+                name: "Bling",
+                description: "SO MUCH BLING!",
+                author: "Pixel Pusher",
+                homepageURL: "http://localhost:4444/data/index.html",
+                headerURL: "http://localhost:4444/data/header.png",
+                footerURL: "http://localhost:4444/data/footer.png",
+                previewURL: "http://localhost:4444/data/preview.png",
+                iconURL: "http://localhost:4444/data/icon.png"
+              };
+
+
 function test() {
   waitForExplicitFinish();
 
   gProvider = new MockProvider();
 
   gProvider.createAddons([{
     id: "addon1@tests.mozilla.org",
     name: "Test add-on",
@@ -624,8 +641,37 @@ add_test(function() {
 
   try {
     Services.prefs.clearUserPref("accessibility.tabfocus_applies_to_xul");
   }
   catch (e) { }
 
   run_next_test();
 });
+
+
+add_test(function() {
+  info("Enabling lightweight theme");
+  LightweightThemeManager.currentTheme = gLWTheme;
+  
+  gManagerWindow.loadView("addons://list/theme");
+  wait_for_view_load(gManagerWindow, function() {
+    var addon = get_addon_element(gManagerWindow, "4@personas.mozilla.org");
+
+    is_element_hidden(get_node(addon, "preferences-btn"), "Preferences button should be hidden");
+    is_element_hidden(get_node(addon, "enable-btn"), "Enable button should be hidden");
+    is_element_visible(get_node(addon, "disable-btn"), "Disable button should be visible");
+    is_element_visible(get_node(addon, "remove-btn"), "Remove button should be visible");
+
+    info("Disabling lightweight theme");
+    LightweightThemeManager.currentTheme = null;
+
+    is_element_hidden(get_node(addon, "preferences-btn"), "Preferences button should be hidden");
+    is_element_visible(get_node(addon, "enable-btn"), "Enable button should be hidden");
+    is_element_hidden(get_node(addon, "disable-btn"), "Disable button should be visible");
+    is_element_visible(get_node(addon, "remove-btn"), "Remove button should be visible");
+
+    AddonManager.getAddonByID("4@personas.mozilla.org", function(aAddon) {
+      aAddon.uninstall();
+      run_next_test();
+    });
+  });
+});
--- a/toolkit/mozapps/extensions/test/xpcshell/test_dss.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_dss.js
@@ -253,17 +253,17 @@ function run_test_3() {
     do_check_eq(p1.screenshots[0], "http://localhost:4444/data/preview.png");
     do_check_false(p1.appDisabled);
     do_check_false(p1.userDisabled);
     do_check_true(p1.isCompatible);
     do_check_true(p1.providesUpdatesSecurely);
     do_check_eq(p1.blocklistState, 0);
     do_check_true(p1.isActive);
     do_check_eq(p1.pendingOperations, 0);
-    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL);
+    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE);
     do_check_eq(p1.scope, AddonManager.SCOPE_PROFILE);
     do_check_true("isCompatibleWith" in p1);
     do_check_true("findUpdates" in p1);
 
     AddonManager.getAddonsByTypes(["theme"], function(addons) {
       let seen = false;
       addons.forEach(function(a) {
         if (a.id == "1@personas.mozilla.org") {
@@ -319,24 +319,24 @@ function run_test_4() {
 
   AddonManager.getAddonsByIDs(["1@personas.mozilla.org",
                                "2@personas.mozilla.org"], function([p1, p2]) {
     do_check_neq(null, p2);
     do_check_false(p2.appDisabled);
     do_check_false(p2.userDisabled);
     do_check_true(p2.isActive);
     do_check_eq(p2.pendingOperations, 0);
-    do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL);
+    do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE);
 
     do_check_neq(null, p1);
     do_check_false(p1.appDisabled);
     do_check_true(p1.userDisabled);
     do_check_false(p1.isActive);
     do_check_eq(p1.pendingOperations, 0);
-    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL + AddonManager.PERM_CAN_ENABLE);
+    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_ENABLE);
 
     AddonManager.getAddonsByTypes(["theme"], function(addons) {
       let seen = false;
       addons.forEach(function(a) {
         if (a.id == "2@personas.mozilla.org") {
           seen = true;
         }
         else {
--- a/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_theme.js
@@ -268,17 +268,17 @@ function run_test_3() {
     do_check_eq(p1.screenshots[0], "http://localhost:4444/data/preview.png");
     do_check_false(p1.appDisabled);
     do_check_false(p1.userDisabled);
     do_check_true(p1.isCompatible);
     do_check_true(p1.providesUpdatesSecurely);
     do_check_eq(p1.blocklistState, 0);
     do_check_true(p1.isActive);
     do_check_eq(p1.pendingOperations, 0);
-    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL);
+    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE);
     do_check_eq(p1.scope, AddonManager.SCOPE_PROFILE);
     do_check_true("isCompatibleWith" in p1);
     do_check_true("findUpdates" in p1);
     do_check_eq(p1.installDate.getTime(), p1.updateDate.getTime());
 
     // Should have been installed sometime in the last few seconds.
     let difference = Date.now() - p1.installDate.getTime();
     if (difference > MAX_INSTALL_TIME)
@@ -342,32 +342,32 @@ function run_test_4() {
 
   AddonManager.getAddonsByIDs(["1@personas.mozilla.org",
                                "2@personas.mozilla.org"], function([p1, p2]) {
     do_check_neq(null, p2);
     do_check_false(p2.appDisabled);
     do_check_false(p2.userDisabled);
     do_check_true(p2.isActive);
     do_check_eq(p2.pendingOperations, 0);
-    do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL);
+    do_check_eq(p2.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_DISABLE);
     do_check_eq(p2.installDate.getTime(), p2.updateDate.getTime());
 
     // Should have been installed sometime in the last few seconds.
     let difference = Date.now() - p2.installDate.getTime();
     if (difference > MAX_INSTALL_TIME)
       do_throw("Add-on was installed " + difference + "ms ago");
     else if (difference < 0)
       do_throw("Add-on was installed " + difference + "ms in the future");
 
     do_check_neq(null, p1);
     do_check_false(p1.appDisabled);
     do_check_true(p1.userDisabled);
     do_check_false(p1.isActive);
     do_check_eq(p1.pendingOperations, 0);
-    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL + AddonManager.PERM_CAN_ENABLE);
+    do_check_eq(p1.permissions, AddonManager.PERM_CAN_UNINSTALL | AddonManager.PERM_CAN_ENABLE);
 
     AddonManager.getAddonsByTypes(["theme"], function(addons) {
       let seen = false;
       addons.forEach(function(a) {
         if (a.id == "2@personas.mozilla.org") {
           seen = true;
         }
         else {