Bug 706292 - Hide the automatic update settings from the add-on details for the hotfix extension. r=Unfocused
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 18 Apr 2012 14:39:29 -0400
changeset 94150 ccb2effe31c05a921296c6c8729dbb54a1bef1e3
parent 94149 00bcf77af39cc3742ce8537e6bb19163ccb0b837
child 94151 d5a02a324330fe44c39c32e2b32221685c32eb5a
push id9496
push usermozilla@noorenberghe.ca
push dateWed, 16 May 2012 23:07:20 +0000
treeherdermozilla-inbound@ccb2effe31c0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersUnfocused
bugs706292
milestone15.0a1
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 706292 - Hide the automatic update settings from the add-on details for the hotfix extension. r=Unfocused
toolkit/mozapps/extensions/AddonManager.jsm
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_details.js
toolkit/mozapps/extensions/test/xpcshell/test_pref_properties.js
--- a/toolkit/mozapps/extensions/AddonManager.jsm
+++ b/toolkit/mozapps/extensions/AddonManager.jsm
@@ -404,16 +404,17 @@ function AddonType(aId, aLocaleURI, aLoc
 
 var gStarted = false;
 var gCheckCompatibility = true;
 var gStrictCompatibility = true;
 var gCheckUpdateSecurityDefault = true;
 var gCheckUpdateSecurity = gCheckUpdateSecurityDefault;
 var gUpdateEnabled = true;
 var gAutoUpdateDefault = true;
+var gHotfixID = null;
 
 /**
  * This is the real manager, kept here rather than in AddonManager to keep its
  * contents hidden from API users.
  */
 var AddonManagerInternal = {
   managerListeners: [],
   installListeners: [],
@@ -533,16 +534,21 @@ var AddonManagerInternal = {
     } catch (e) {}
     Services.prefs.addObserver(PREF_EM_UPDATE_ENABLED, this, false);
 
     try {
       gAutoUpdateDefault = Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT);
     } catch (e) {}
     Services.prefs.addObserver(PREF_EM_AUTOUPDATE_DEFAULT, this, false);
 
+    try {
+      gHotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
+    } catch (e) {}
+    Services.prefs.addObserver(PREF_EM_HOTFIX_ID, this, false);
+
     // Ensure all default providers have had a chance to register themselves
     DEFAULT_PROVIDERS.forEach(function(url) {
       try {
         Components.utils.import(url, {});
       }
       catch (e) {
         ERROR("Exception loading default provider \"" + url + "\"", e);
       }
@@ -659,16 +665,17 @@ var AddonManagerInternal = {
    * up everything in order for automated tests to fake restarts.
    */
   shutdown: function AMI_shutdown() {
     Services.prefs.removeObserver(PREF_EM_CHECK_COMPATIBILITY, this);
     Services.prefs.removeObserver(PREF_EM_STRICT_COMPATIBILITY, this);
     Services.prefs.removeObserver(PREF_EM_CHECK_UPDATE_SECURITY, this);
     Services.prefs.removeObserver(PREF_EM_UPDATE_ENABLED, this);
     Services.prefs.removeObserver(PREF_EM_AUTOUPDATE_DEFAULT, this);
+    Services.prefs.removeObserver(PREF_EM_HOTFIX_ID, this);
 
     this.providers.forEach(function(provider) {
       callProvider(provider, "shutdown");
     });
 
     this.managerListeners.splice(0, this.managerListeners.length);
     this.installListeners.splice(0, this.installListeners.length);
     this.addonListeners.splice(0, this.addonListeners.length);
@@ -747,16 +754,24 @@ var AddonManagerInternal = {
           gAutoUpdateDefault = Services.prefs.getBoolPref(PREF_EM_AUTOUPDATE_DEFAULT);
         } catch(e) {
           gAutoUpdateDefault = true;
         }
 
         this.callManagerListeners("onUpdateModeChanged");
         break;
       }
+      case PREF_EM_HOTFIX_ID: {
+        try {
+          gHotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
+        } catch(e) {
+          gHotfixID = null;
+        }
+        break;
+      }
     }
   },
 
   /**
    * Replaces %...% strings in an addon url (update and updateInfo) with
    * appropriate values.
    *
    * @param  aAddon
@@ -820,19 +835,17 @@ var AddonManagerInternal = {
     return uri.replace(/\+/g, "%2B");
   },
 
   /**
    * Performs a background update check by starting an update for all add-ons
    * that can be updated.
    */
   backgroundUpdateCheck: function AMI_backgroundUpdateCheck() {
-    let hotfixID = null;
-    if (Services.prefs.getPrefType(PREF_EM_HOTFIX_ID) == Ci.nsIPrefBranch.PREF_STRING)
-      hotfixID = Services.prefs.getCharPref(PREF_EM_HOTFIX_ID);
+    let hotfixID = this.hotfixID;
 
     let checkHotfix = hotfixID &&
                       Services.prefs.getBoolPref(PREF_APP_UPDATE_ENABLED) &&
                       Services.prefs.getBoolPref(PREF_APP_UPDATE_AUTO);
 
     if (!this.updateEnabled && !checkHotfix)
       return;
 
@@ -1683,17 +1696,21 @@ var AddonManagerInternal = {
     return gUpdateEnabled;
   },
 
   set updateEnabled(aValue) {
     aValue = !!aValue;
     if (aValue != gUpdateEnabled)
       Services.prefs.setBoolPref(PREF_EM_UPDATE_ENABLED, aValue);
     return aValue;
-  }
+  },
+
+  get hotfixID() {
+    return gHotfixID;
+  },
 };
 
 /**
  * Should not be used outside of core Mozilla code. This is a private API for
  * the startup and platform integration code to use. Refer to the methods on
  * AddonManagerInternal for documentation however note that these methods are
  * subject to change at any time.
  */
@@ -2063,16 +2080,20 @@ var AddonManager = {
   get autoUpdateDefault() {
     return AddonManagerInternal.autoUpdateDefault;
   },
 
   set autoUpdateDefault(aValue) {
     AddonManagerInternal.autoUpdateDefault = aValue;
   },
 
+  get hotfixID() {
+    return AddonManagerInternal.hotfixID;
+  },
+
   escapeAddonURI: function AM_escapeAddonURI(aAddon, aUri, aAppVersion) {
     return AddonManagerInternal.escapeAddonURI(aAddon, aUri, aAppVersion);
   }
 };
 
 Object.freeze(AddonManagerInternal);
 Object.freeze(AddonManagerPrivate);
 Object.freeze(AddonManager);
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -2667,17 +2667,17 @@ var gDetailView = {
     var downloadsRow = document.getElementById("detail-downloads");
     if (aAddon.totalDownloads && aIsRemote) {
       var downloads = aAddon.totalDownloads;
       downloadsRow.value = downloads;
     } else {
       downloadsRow.value = null;
     }
 
-    var canUpdate = !aIsRemote && hasPermission(aAddon, "upgrade");
+    var canUpdate = !aIsRemote && hasPermission(aAddon, "upgrade") && aAddon.id != AddonManager.hotfixID;
     document.getElementById("detail-updates-row").hidden = !canUpdate;
 
     if ("applyBackgroundUpdates" in aAddon) {
       this._autoUpdate.hidden = false;
       this._autoUpdate.value = aAddon.applyBackgroundUpdates;
       let hideFindUpdates = AddonManager.shouldAutoUpdate(this._addon);
       document.getElementById("detail-findUpdates-btn").hidden = hideFindUpdates;
     } else {
--- a/toolkit/mozapps/extensions/test/browser/browser_details.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_details.js
@@ -2,16 +2,17 @@
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 // Tests various aspects of the details view
 
 const PREF_AUTOUPDATE_DEFAULT = "extensions.update.autoUpdateDefault"
 const PREF_GETADDONS_GETSEARCHRESULTS = "extensions.getAddons.search.url";
 const SEARCH_URL = TESTROOT + "browser_details.xml";
+const PREF_EM_HOTFIX_ID = "extensions.hotfix.id";
 
 var gManagerWindow;
 var gCategoryUtilities;
 var gProvider;
 
 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
 var gVersion = Services.appinfo.version;
 var gBlocklistURL = Services.urlFormatter.formatURLPref("extensions.blocklist.detailsURL");
@@ -42,16 +43,17 @@ function get(aId) {
   return gManagerWindow.document.getElementById(aId);
 }
 
 function test() {
   requestLongerTimeout(2);
   // Turn on searching for this test
   Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
   Services.prefs.setCharPref(PREF_GETADDONS_GETSEARCHRESULTS, SEARCH_URL);
+  Services.prefs.setCharPref(PREF_EM_HOTFIX_ID, "hotfix@tests.mozilla.org");
 
   waitForExplicitFinish();
 
   gProvider = new MockProvider();
 
   gProvider.createAddons([{
     id: "addon1@tests.mozilla.org",
     name: "Test add-on 1",
@@ -136,27 +138,31 @@ function test() {
     name: "Test add-on 7",
     _userDisabled: true,
     isActive: false
   }, {
     id: "addon8@tests.mozilla.org",
     blocklistURL: "http://example.com/addon8@tests.mozilla.org",
     name: "Test add-on 8",
     blocklistState: Ci.nsIBlocklistService.STATE_OUTDATED
+  }, {
+    id: "hotfix@tests.mozilla.org",
+    name: "Test hotfix 1",
   }]);
 
   open_manager(null, function(aWindow) {
     gManagerWindow = aWindow;
     gCategoryUtilities = new CategoryUtilities(gManagerWindow);
 
     run_next_test();
   });
 }
 
 function end_test() {
+  Services.prefs.clearUserPref(PREF_EM_HOTFIX_ID);
   close_manager(gManagerWindow, function() {
     finish();
   });
 }
 
 // Opens and tests the details view for add-on 1
 add_test(function() {
   open_details("addon1@tests.mozilla.org", "extension", function() {
@@ -170,16 +176,17 @@ add_test(function() {
     is(get("detail-screenshot").height, "", "Screenshot dimensions should not be set");
     is(get("detail-desc").textContent, "Short description", "Description should be correct");
     is(get("detail-fulldesc").textContent, "Longer description", "Full description should be correct");
 
     is_element_visible(get("detail-contributions"), "Contributions section should be visible");
     is_element_visible(get("detail-contrib-suggested"), "Contributions amount should be visible");
     ok(get("detail-contrib-suggested").value, "$0.99");
 
+    is_element_visible(get("detail-updates-row"), "Updates should not be hidden");
     is_element_hidden(get("detail-dateUpdated"), "Update date should be hidden");
 
     is_element_visible(get("detail-rating-row"), "Rating row should not be hidden");
     is_element_visible(get("detail-rating"), "Rating should not be hidden");
     is(get("detail-rating").averageRating, 4, "Rating should be correct");
     is_element_visible(get("detail-reviews"), "Reviews should not be hidden");
     is(get("detail-reviews").href, "http://example.com/reviews", "Review URL should be correct");
     is(get("detail-reviews").value, "5 reviews", "Review text should be correct");
@@ -331,16 +338,17 @@ add_test(function() {
     is_element_visible(get("detail-screenshot"), "Screenshot should be visible");
     is(get("detail-screenshot").src, "chrome://branding/content/icon64.png", "Should be showing the thumbnail");
     is(get("detail-screenshot").width, 160, "Screenshot dimensions should be set");
     is(get("detail-screenshot").height, 120, "Screenshot dimensions should be set");
     is(get("detail-screenshot").hasAttribute("loading"), true, "Screenshot should have loading attribute");
 
     is_element_hidden(get("detail-contributions"), "Contributions section should be hidden");
 
+    is_element_visible(get("detail-updates-row"), "Updates should not be hidden");
     is_element_visible(get("detail-dateUpdated"), "Update date should not be hidden");
     is(get("detail-dateUpdated").value, formatDate(gDate), "Update date should be correct");
 
     is_element_visible(get("detail-rating-row"), "Rating row should not be hidden");
     is_element_hidden(get("detail-rating"), "Rating should be hidden");
     is_element_visible(get("detail-reviews"), "Reviews should not be hidden");
     is(get("detail-reviews").href, "http://example.com/reviews", "Review URL should be correct");
     is(get("detail-reviews").value, "1 review", "Review text should be correct");
@@ -673,16 +681,36 @@ add_test(function() {
       is_element_hidden(get("detail-error-link"), "Error link should be hidden");
       is_element_hidden(get("detail-pending"), "Pending message should be hidden");
 
       run_next_test();
     });
   });
 });
 
+// Opens and tests the details view for hotfix 1
+add_test(function() {
+  open_details("hotfix@tests.mozilla.org", "extension", function() {
+    is(get("detail-name").textContent, "Test hotfix 1", "Name should be correct");
+
+    is_element_hidden(get("detail-updates-row"), "Updates should be hidden");
+
+    is_element_hidden(get("detail-prefs-btn"), "Preferences button should be hidden");
+    is_element_hidden(get("detail-enable-btn"), "Enable button should be hidden");
+    is_element_visible(get("detail-disable-btn"), "Disable button should be visible");
+    is_element_visible(get("detail-uninstall-btn"), "Remove button should be visible");
+
+    is_element_hidden(get("detail-warning"), "Warning message should be hidden");
+    is_element_hidden(get("detail-warning-link"), "Warning link should be hidden");
+    is_element_hidden(get("detail-pending"), "Pending message should be hidden");
+
+    run_next_test();
+  });
+});
+
 // Tests that upgrades with onExternalInstall apply immediately
 add_test(function() {
   open_details("addon1@tests.mozilla.org", "extension", function() {
     gProvider.createAddons([{
       id: "addon1@tests.mozilla.org",
       name: "Test add-on replacement",
       version: "2.5",
       description: "Short description replacement",
--- a/toolkit/mozapps/extensions/test/xpcshell/test_pref_properties.js
+++ b/toolkit/mozapps/extensions/test/xpcshell/test_pref_properties.js
@@ -200,13 +200,28 @@ function run_test() {
   do_check_true(AddonManager.checkUpdateSecurity);
   if (!AddonManager.checkUpdateSecurityDefault)
     do_check_true(Services.prefs.getBoolPref("extensions.checkUpdateSecurity"));
   else
     do_check_false(Services.prefs.prefHasUserValue("extensions.checkUpdateSecurity"));
 
   gManagerEventsListener.shutdown();
 
+  // AddonManager.hotfixID
+  let hotfixID = "hotfix@tests.mozilla.org";
+  Services.prefs.setCharPref("extensions.hotfix.id", hotfixID);
+  do_check_eq(AddonManager.hotfixID, hotfixID);
+  // Change the pref and make sure the property is updated
+  hotfixID = "hotfix2@tests.mozilla.org";
+  Services.prefs.setCharPref("extensions.hotfix.id", hotfixID);
+  do_check_eq(AddonManager.hotfixID, hotfixID);
+  // Test an invalid pref value
+  hotfixID = 99;
+  Services.prefs.deleteBranch("extensions.hotfix.id");
+  Services.prefs.setIntPref("extensions.hotfix.id", hotfixID);
+  do_check_eq(AddonManager.hotfixID, null);
+  Services.prefs.clearUserPref("extensions.hotfix.id");
+
   // After removing the listener, ensure we get no further events.
   gManagerEventsListener.expect([]);
   AddonManager.updateEnabled = false;
   gManagerEventsListener.checkExpected();
 }