Bug 618502: about:addons can display an empty add-on page after uninstall/restart. r=Unfocused, a=blocks-final

This commit is contained in:
Dave Townsend 2011-01-07 09:08:13 -08:00
parent f1a2e58fc6
commit c141b61178
3 changed files with 79 additions and 5 deletions

View File

@ -548,6 +548,19 @@ var gViewController = {
this.loadViewInternal(aViewId, this.currentViewId);
},
// Replaces the existing view with a new one, rewriting the current history
// entry to match.
replaceView: function(aViewId) {
if (aViewId == this.currentViewId)
return;
gHistory.replaceState({
view: aViewId,
previousView: null
}, document.title);
this.loadViewInternal(aViewId, null);
},
loadInitialView: function(aViewId) {
gHistory.replaceState({
view: aViewId,
@ -1364,9 +1377,13 @@ var gCategories = {
});
},
get selected() {
return this.node.selectedItem ? this.node.selectedItem.value : null;
},
select: function(aId, aPreviousView) {
var view = gViewController.parseViewId(aId);
if (view.type == "detail") {
if (view.type == "detail" && aPreviousView) {
aId = aPreviousView;
view = gViewController.parseViewId(aPreviousView);
}
@ -2183,6 +2200,11 @@ var gDetailView = {
this.node.setAttribute("type", aAddon.type);
// If the search category isn't selected then make sure to select the
// correct category
if (gCategories.selected != "addons://search/")
gCategories.select("addons://list/" + aAddon.type);
document.getElementById("detail-name").textContent = aAddon.name;
var icon = aAddon.icon64URL ? aAddon.icon64URL : aAddon.iconURL;
document.getElementById("detail-icon").src = icon ? icon : null;
@ -2352,7 +2374,10 @@ var gDetailView = {
return;
}
// This case should never happen in normal operation
// This might happen due to session restore restoring us back to an
// add-on that doesn't exist but otherwise shouldn't normally happen.
// Either way just revert to the default view.
gViewController.replaceView(VIEW_DEFAULT);
});
});
},
@ -2360,9 +2385,11 @@ var gDetailView = {
hide: function() {
this._updatePrefs.removeObserver("", this);
this.clearLoading();
gEventManager.unregisterAddonListener(this, this._addon.id);
gEventManager.unregisterInstallListener(this);
this._addon = null;
if (this._addon) {
gEventManager.unregisterAddonListener(this, this._addon.id);
gEventManager.unregisterInstallListener(this);
this._addon = null;
}
},
updateState: function() {

View File

@ -63,6 +63,7 @@ _MAIN_TEST_FILES = \
browser_bug596336.js \
browser_bug608316.js \
browser_bug610764.js \
browser_bug618502.js \
browser_details.js \
browser_discovery.js \
browser_dragdrop.js \

View File

@ -0,0 +1,46 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Bug 608316 - Test that opening the manager to an add-on that doesn't exist
// just loads the default view
var gCategoryUtilities;
function test() {
waitForExplicitFinish();
run_next_test();
}
function end_test() {
finish();
}
add_test(function() {
open_manager("addons://detail/foo", function(aManager) {
gCategoryUtilities = new CategoryUtilities(aManager);
is(gCategoryUtilities.selectedCategory, "discover", "Should fall back to the discovery pane");
close_manager(aManager, run_next_test);
});
});
// Also test that opening directly to an add-on that does exist doesn't break
// and selects the right category
add_test(function() {
gProvider = new MockProvider();
gProvider.createAddons([{
id: "addon1@tests.mozilla.org",
name: "addon 1",
version: "1.0"
}]);
open_manager("addons://detail/addon1@tests.mozilla.org", function(aManager) {
gCategoryUtilities = new CategoryUtilities(aManager);
is(gCategoryUtilities.selectedCategory, "extension", "Should have selected the right category");
close_manager(aManager, run_next_test);
});
});