Bug 591024: Only show "Available Updates" pane when pending updates are available. r=Unfocused, a=blocks-final
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 30 Nov 2010 15:33:39 -0800
changeset 58519 f2927563659beb2123500b88a5a88471647b00fa
parent 58518 b42658175de0dd03f6404d91f1ec20518d98ba0c
child 58520 3f004b291c654e274f7259173306ab4d94b40cad
push id1
push usershaver@mozilla.com
push dateTue, 04 Jan 2011 17:58:04 +0000
reviewersUnfocused, blocks-final
bugs591024
milestone2.0b8pre
Bug 591024: Only show "Available Updates" pane when pending updates are available. r=Unfocused, a=blocks-final
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_manualupdates.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -2399,17 +2399,16 @@ var gDetailView = {
 var gUpdatesView = {
   node: null,
   _listBox: null,
   _emptyNotice: null,
   _sorters: null,
   _updateSelected: null,
   _updatePrefs: null,
   _categoryItem: null,
-  _numManualUpdaters: 0,
 
   initialize: function() {
     this.node = document.getElementById("updates-view");
     this._listBox = document.getElementById("updates-list");
     this._emptyNotice = document.getElementById("updates-list-empty");
     this._sorters = document.getElementById("updates-sorters");
     this._sorters.handler = this;
 
@@ -2418,17 +2417,16 @@ var gUpdatesView = {
     this._updateSelected = document.getElementById("update-selected-btn");
     this._updateSelected.addEventListener("command", function() {
       gUpdatesView.installSelected();
     }, false);
 
     this._updatePrefs = Services.prefs.getBranch("extensions.update.");
     this._updatePrefs.QueryInterface(Ci.nsIPrefBranch2);
     this._updatePrefs.addObserver("", this, false);
-    this.updateManualUpdatersCount(true);
     this.updateAvailableCount(true);
 
     AddonManager.addAddonListener(this);
     AddonManager.addInstallListener(this);
   },
 
   shutdown: function() {
     AddonManager.removeAddonListener(this);
@@ -2449,16 +2447,18 @@ var gUpdatesView = {
     if (aType == "recent")
       this._showRecentUpdates(aRequest);
     else
       this._showAvailableUpdates(false, aRequest);
   },
 
   hide: function() {
     this._updateSelected.hidden = true;
+
+    this._categoryItem.disabled = this._categoryItem.badgeCount == 0;
   },
 
   _showRecentUpdates: function(aRequest) {
     var self = this;
     AddonManager.getAllAddons(function(aAddonsList) {
       if (gViewController && aRequest != gViewController.currentViewRequest)
         return;
 
@@ -2545,65 +2545,34 @@ var gUpdatesView = {
     if (isManual && aOnlyAvailable)
       return isInState(aInstall, "available");
     return isManual;
   },
 
   observe: function(aSubject, aTopic, aData) {
     if (aTopic != "nsPref:changed")
       return;
-    if (aData == "autoUpdateDefault")
-      this.updateManualUpdatersCount();
   },
 
   maybeRefresh: function() {
-    if (gViewController.currentViewId == "addons://updates/available") {
+    if (gViewController.currentViewId == "addons://updates/available")
       this._showAvailableUpdates(true);
-    } else {
-      this.updateManualUpdatersCount();
-      this.updateAvailableCount();
-    }
-  },
-
-  maybeShowCategory: function() {
-    var hide = this._numManualUpdaters == 0;
-    if (this._categoryItem.disabled != hide) {
-      this._categoryItem.disabled = hide;
-      var event = document.createEvent("Events");
-      event.initEvent("CategoryVisible", true, true);
-      this._categoryItem.dispatchEvent(event);
-    }
-  },
-
-  updateManualUpdatersCount: function(aInitializing) {
-    if (aInitializing)
-      gPendingInitializations++;
-    var self = this;
-    var autoUpdateDefault = AddonManager.autoUpdateDefault;
-    AddonManager.getAllAddons(function(aAddonList) {
-      var manualUpdaters = aAddonList.filter(function(aAddon) {
-        if (!("applyBackgroundUpdates" in aAddon))
-          return false;
-        return !shouldAutoUpdate(aAddon, autoUpdateDefault);
-      });
-      self._numManualUpdaters = manualUpdaters.length;
-      self.maybeShowCategory();
-      if (aInitializing)
-        notifyInitialized();
-    });
+    this.updateAvailableCount();
   },
 
   updateAvailableCount: function(aInitializing) {
     if (aInitializing)
       gPendingInitializations++;
     var self = this;
     AddonManager.getAllInstalls(function(aInstallsList) {
       var count = aInstallsList.filter(function(aInstall) {
         return self.isManualUpdate(aInstall, true);
       }).length;
+      self._categoryItem.disabled = gViewController.currentViewObj != self &&
+                                    count == 0;
       self._categoryItem.badgeCount = count;
       if (aInitializing)
         notifyInitialized();
     });
   },
   
   maybeDisableUpdateSelected: function() {
     for (let i = 0; i < this._listBox.childNodes.length; i++) {
@@ -2648,39 +2617,29 @@ var gUpdatesView = {
   },
 
   onNewInstall: function(aInstall) {
     if (!this.isManualUpdate(aInstall))
       return;
     this.maybeRefresh();
   },
 
-  onExternalInstall: function(aAddon) {
-    if (!shouldAutoUpdate(aAddon)) {
-      this._numManualUpdaters++;
-      this.maybeShowCategory();
-    }
-  },
-
-  onInstallEnded: function(aAddon) {
-    if (!shouldAutoUpdate(aAddon)) {
-      this._numManualUpdaters++;
-      this.maybeShowCategory();
-    }
+  onInstallStarted: function(aInstall) {
+    this.updateAvailableCount();
   },
 
   onInstallCancelled: function(aInstall) {
     if (!this.isManualUpdate(aInstall))
       return;
     this.maybeRefresh();
   },
 
   onPropertyChanged: function(aAddon, aProperties) {
     if (aProperties.indexOf("applyBackgroundUpdates") != -1)
-      this.updateManualUpdatersCount();
+      this.updateAvailableCount();
   }
 };
 
 
 var gDragDrop = {
   onDragOver: function(aEvent) {
     var types = aEvent.dataTransfer.types;
     if (types.contains("text/uri-list") ||
--- a/toolkit/mozapps/extensions/test/browser/browser_manualupdates.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_manualupdates.js
@@ -43,35 +43,26 @@ add_test(function() {
     id: "addon2@tests.mozilla.org",
     name: "manually updating addon",
     version: "1.0",
     isCompatible: false,
     blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED,
     applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
   }]);
   
-  is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible");
-  
-  gAvailableCategory.addEventListener("CategoryVisible", function() {
-    gAvailableCategory.removeEventListener("CategoryVisible", arguments.callee, false);
-    is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should not be visible");
-    gAvailableCategory.addEventListener("CategoryVisible", function() {
-      gAvailableCategory.removeEventListener("CategoryVisible", arguments.callee, false);
-      is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should be visible");
-      run_next_test();
-    }, false);
-    gProvider.addons[1].applyBackgroundUpdates = AddonManager.AUTOUPDATE_DISABLE;
-  }, false);
-  gProvider.addons[1].applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
+  is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should still be hidden");
+
+  run_next_test();
 });
 
 
 add_test(function() {
   gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() {
     gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false);
+    is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible");
     is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1");
     run_next_test();
   }, false);
 
   gCategoryUtilities.openType("extension", function() {
     gProvider.createInstalls([{
       name: "manually updating addon (new and improved!)",
       existingAddon: gProvider.addons[1],
@@ -160,29 +151,92 @@ add_test(function() {
 
   }, false);
   EventUtils.synthesizeMouseAtCenter(item._relNotesToggle, { }, gManagerWindow);
   is_element_visible(item._relNotesLoading, "Release notes loading message should be visible");
 });
 
 
 add_test(function() {
+  var badgeUpdated = false;
+  var installCompleted = false;
+
+  gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() {
+    gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false);
+    if (installCompleted)
+      run_next_test();
+    else
+      badgeUpdated = true;
+  }, false);
+
   var list = gManagerWindow.document.getElementById("updates-list");
   var item = list.firstChild;
   var updateBtn = item._updateBtn;
   is_element_visible(updateBtn, "Update button should be visible");
 
   var install = gProvider.installs[0];
   var listener = {
     onInstallStarted: function() {
       info("Install started");
       is_element_visible(item._installStatus, "Install progress widget should be visible");
     },
     onInstallEnded: function() {
       install.removeTestListener(this);
-      info("install ended");
+      info("Install ended");
       is_element_hidden(item._installStatus, "Install progress widget should be hidden");
-      run_next_test();
+
+      if (badgeUpdated)
+        run_next_test();
+      else
+        installCompleted = true;
     }
   };
   install.addTestListener(listener);
   EventUtils.synthesizeMouseAtCenter(updateBtn, { }, gManagerWindow);
 });
+
+
+add_test(function() {
+  is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should still be visible");
+  is(gAvailableCategory.badgeCount, 0, "Badge for Available Updates should now be 0");
+
+  gCategoryUtilities.openType("extension", function() {
+    is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should be hidden");
+
+    close_manager(gManagerWindow, function() {
+      open_manager(null, function(aWindow) {
+        gManagerWindow = aWindow;
+        gCategoryUtilities = new CategoryUtilities(gManagerWindow);
+        gAvailableCategory = gManagerWindow.gCategories.get("addons://updates/available");
+
+        is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should be hidden");
+
+        run_next_test();
+      });
+    });
+  });
+});
+
+add_test(function() {
+  gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() {
+    gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false);
+    is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible");
+    is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1");
+
+    gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() {
+      gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false);
+      is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should now be hidden");
+
+      run_next_test();
+    }, false);
+
+    AddonManager.getAddonByID("addon2@tests.mozilla.org", function(aAddon) {
+      aAddon.applyBackgroundUpdates = AddonManager.AUTOUPDATE_ENABLE;
+    });
+  }, false);
+
+  gProvider.createInstalls([{
+    name: "manually updating addon (new and even more improved!)",
+    existingAddon: gProvider.addons[1],
+    version: "1.2",
+    releaseNotesURI: Services.io.newURI(TESTROOT + "thereIsNoFileHere.xhtml", null, null)
+  }]);
+});
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -535,23 +535,34 @@ MockProvider.prototype = {
    * Adds an add-on install to the list of installs that this provider exposes
    * to the AddonManager, dispatching appropriate events in the process.
    *
    * @param  aInstall
    *         The add-on install to add
    */
   addInstall: function MP_addInstall(aInstall) {
     this.installs.push(aInstall);
+    aInstall._provider = this;
 
     if (!this.started)
       return;
 
     aInstall.callListeners("onNewInstall");
   },
 
+  removeInstall: function MP_removeInstall(aInstall) {
+    var pos = this.installs.indexOf(aInstall);
+    if (pos == -1) {
+      ok(false, "Tried to remove an install that wasn't registered with the mock provider");
+      return;
+    }
+
+    this.installs.splice(pos, 1);
+  },
+
   /**
    * Creates a set of mock add-on objects and adds them to the list of add-ons
    * managed by this provider.
    *
    * @param  aAddonProperties
    *         An array of objects containing properties describing the add-ons
    * @return Array of the new MockAddons
    */
@@ -1018,16 +1029,17 @@ MockInstall.prototype = {
           this.state = AddonManager.STATE_CANCELLED;
           this.callListeners("onInstallCancelled");
           return;
         }
 
         AddonManagerPrivate.callAddonListeners("onInstalling", this.addon);
 
         this.state = AddonManager.STATE_INSTALLED;
+        this._provider.removeInstall(this);
         this.callListeners("onInstallEnded");
         break;
       case AddonManager.STATE_DOWNLOADING:
       case AddonManager.STATE_CHECKING:
       case AddonManger.STATE_INSTALLING:
         // Installation is already running
         return;
       default: