Bug 591024: Only show "Available Updates" pane when pending updates are available. r=Unfocused, a=blocks-final

This commit is contained in:
Dave Townsend 2010-11-30 15:33:39 -08:00
parent e7d2a6945f
commit 3fa515c462
3 changed files with 90 additions and 65 deletions

View File

@ -2404,7 +2404,6 @@ var gUpdatesView = {
_updateSelected: null, _updateSelected: null,
_updatePrefs: null, _updatePrefs: null,
_categoryItem: null, _categoryItem: null,
_numManualUpdaters: 0,
initialize: function() { initialize: function() {
this.node = document.getElementById("updates-view"); this.node = document.getElementById("updates-view");
@ -2423,7 +2422,6 @@ var gUpdatesView = {
this._updatePrefs = Services.prefs.getBranch("extensions.update."); this._updatePrefs = Services.prefs.getBranch("extensions.update.");
this._updatePrefs.QueryInterface(Ci.nsIPrefBranch2); this._updatePrefs.QueryInterface(Ci.nsIPrefBranch2);
this._updatePrefs.addObserver("", this, false); this._updatePrefs.addObserver("", this, false);
this.updateManualUpdatersCount(true);
this.updateAvailableCount(true); this.updateAvailableCount(true);
AddonManager.addAddonListener(this); AddonManager.addAddonListener(this);
@ -2454,6 +2452,8 @@ var gUpdatesView = {
hide: function() { hide: function() {
this._updateSelected.hidden = true; this._updateSelected.hidden = true;
this._categoryItem.disabled = this._categoryItem.badgeCount == 0;
}, },
_showRecentUpdates: function(aRequest) { _showRecentUpdates: function(aRequest) {
@ -2550,45 +2550,12 @@ var gUpdatesView = {
observe: function(aSubject, aTopic, aData) { observe: function(aSubject, aTopic, aData) {
if (aTopic != "nsPref:changed") if (aTopic != "nsPref:changed")
return; return;
if (aData == "autoUpdateDefault")
this.updateManualUpdatersCount();
}, },
maybeRefresh: function() { maybeRefresh: function() {
if (gViewController.currentViewId == "addons://updates/available") { if (gViewController.currentViewId == "addons://updates/available")
this._showAvailableUpdates(true); this._showAvailableUpdates(true);
} else { this.updateAvailableCount();
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();
});
}, },
updateAvailableCount: function(aInitializing) { updateAvailableCount: function(aInitializing) {
@ -2599,6 +2566,8 @@ var gUpdatesView = {
var count = aInstallsList.filter(function(aInstall) { var count = aInstallsList.filter(function(aInstall) {
return self.isManualUpdate(aInstall, true); return self.isManualUpdate(aInstall, true);
}).length; }).length;
self._categoryItem.disabled = gViewController.currentViewObj != self &&
count == 0;
self._categoryItem.badgeCount = count; self._categoryItem.badgeCount = count;
if (aInitializing) if (aInitializing)
notifyInitialized(); notifyInitialized();
@ -2653,18 +2622,8 @@ var gUpdatesView = {
this.maybeRefresh(); this.maybeRefresh();
}, },
onExternalInstall: function(aAddon) { onInstallStarted: function(aInstall) {
if (!shouldAutoUpdate(aAddon)) { this.updateAvailableCount();
this._numManualUpdaters++;
this.maybeShowCategory();
}
},
onInstallEnded: function(aAddon) {
if (!shouldAutoUpdate(aAddon)) {
this._numManualUpdaters++;
this.maybeShowCategory();
}
}, },
onInstallCancelled: function(aInstall) { onInstallCancelled: function(aInstall) {
@ -2675,7 +2634,7 @@ var gUpdatesView = {
onPropertyChanged: function(aAddon, aProperties) { onPropertyChanged: function(aAddon, aProperties) {
if (aProperties.indexOf("applyBackgroundUpdates") != -1) if (aProperties.indexOf("applyBackgroundUpdates") != -1)
this.updateManualUpdatersCount(); this.updateAvailableCount();
} }
}; };

View File

@ -48,25 +48,16 @@ add_test(function() {
applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE applyBackgroundUpdates: AddonManager.AUTOUPDATE_DISABLE
}]); }]);
is(gCategoryUtilities.isVisible(gAvailableCategory), true, "Available Updates category should now be visible"); is(gCategoryUtilities.isVisible(gAvailableCategory), false, "Available Updates category should still be hidden");
gAvailableCategory.addEventListener("CategoryVisible", function() { run_next_test();
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;
}); });
add_test(function() { add_test(function() {
gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() { gAvailableCategory.addEventListener("CategoryBadgeUpdated", function() {
gAvailableCategory.removeEventListener("CategoryBadgeUpdated", arguments.callee, false); 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"); is(gAvailableCategory.badgeCount, 1, "Badge for Available Updates should now be 1");
run_next_test(); run_next_test();
}, false); }, false);
@ -165,6 +156,17 @@ add_test(function() {
add_test(function() { 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 list = gManagerWindow.document.getElementById("updates-list");
var item = list.firstChild; var item = list.firstChild;
var updateBtn = item._updateBtn; var updateBtn = item._updateBtn;
@ -178,11 +180,63 @@ add_test(function() {
}, },
onInstallEnded: function() { onInstallEnded: function() {
install.removeTestListener(this); install.removeTestListener(this);
info("install ended"); info("Install ended");
is_element_hidden(item._installStatus, "Install progress widget should be hidden"); 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); install.addTestListener(listener);
EventUtils.synthesizeMouseAtCenter(updateBtn, { }, gManagerWindow); 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)
}]);
});

View File

@ -540,6 +540,7 @@ MockProvider.prototype = {
*/ */
addInstall: function MP_addInstall(aInstall) { addInstall: function MP_addInstall(aInstall) {
this.installs.push(aInstall); this.installs.push(aInstall);
aInstall._provider = this;
if (!this.started) if (!this.started)
return; return;
@ -547,6 +548,16 @@ MockProvider.prototype = {
aInstall.callListeners("onNewInstall"); 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 * Creates a set of mock add-on objects and adds them to the list of add-ons
* managed by this provider. * managed by this provider.
@ -1023,6 +1034,7 @@ MockInstall.prototype = {
AddonManagerPrivate.callAddonListeners("onInstalling", this.addon); AddonManagerPrivate.callAddonListeners("onInstalling", this.addon);
this.state = AddonManager.STATE_INSTALLED; this.state = AddonManager.STATE_INSTALLED;
this._provider.removeInstall(this);
this.callListeners("onInstallEnded"); this.callListeners("onInstallEnded");
break; break;
case AddonManager.STATE_DOWNLOADING: case AddonManager.STATE_DOWNLOADING: