Bug 562899: Quickly displaying multiple different categories will merge the list results. r=Unfocused

This commit is contained in:
Dave Townsend 2010-06-16 20:13:20 -07:00
Родитель 554613eb1a
Коммит e240f69425
6 изменённых файлов: 171 добавлений и 9 удалений

Просмотреть файл

@ -108,6 +108,7 @@ function initialize() {
function shutdown() {
gEventManager.shutdown();
gViewController.shutdown();
}
// Used by external callers to load a specific view into the manager
@ -228,6 +229,7 @@ var gViewController = {
viewPort: null,
currentViewId: "",
currentViewObj: null,
currentViewRequest: 0,
previousViewId: "",
viewObjects: {},
@ -245,6 +247,10 @@ var gViewController = {
window.controllers.appendController(this);
},
shutdown: function() {
this.currentViewRequest = 0;
},
parseViewId: function(aViewId) {
var matchRegex = /^addons:\/\/([^\/]+)\/(.*)$/;
var [,viewType, viewParam] = aViewId.match(matchRegex) || [];
@ -269,6 +275,7 @@ var gViewController = {
let canHide = this.currentViewObj.hide();
if (canHide === false)
return;
this.viewPort.selectedPanel.removeAttribute("loading");
} catch (e) {
// this shouldn't be fatal
Cu.reportError(e);
@ -283,7 +290,15 @@ var gViewController = {
this.currentViewObj = viewObj;
this.viewPort.selectedPanel = this.currentViewObj.node;
this.currentViewObj.show(view.param);
this.viewPort.selectedPanel.setAttribute("loading", "true");
this.currentViewObj.show(view.param, ++this.currentViewRequest);
},
notifyViewChanged: function() {
this.viewPort.selectedPanel.removeAttribute("loading");
var event = document.createEvent("Events");
event.initEvent("ViewChanged", true, true);
this.currentViewObj.node.dispatchEvent(event);
},
commands: {
@ -804,6 +819,7 @@ var gDiscoverView = {
this._browser.goHome();
gViewController.updateCommands();
gViewController.notifyViewChanged();
},
hide: function() { },
@ -836,7 +852,7 @@ var gSearchView = {
}, false);
},
show: function(aQuery) {
show: function(aQuery, aRequest) {
gHeader.setName(gStrings.ext.GetStringFromName("header-search"));
this.showEmptyNotice(false);
@ -848,6 +864,9 @@ var gSearchView = {
var self = this;
AddonManager.getAddonsByTypes(null, function(aAddonsList) {
if (gViewController && aRequest != gViewController.currentViewRequest)
return;
var elementCount = 0;
for (let i = 0; i < aAddonsList.length; i++) {
let addon = aAddonsList[i];
@ -870,6 +889,7 @@ var gSearchView = {
self.showEmptyNotice(true);
gViewController.updateCommands();
gViewController.notifyViewChanged();
});
},
@ -966,7 +986,7 @@ var gListView = {
}, false);
},
show: function(aType) {
show: function(aType, aRequest) {
gHeader.setName(gStrings.ext.GetStringFromName("header-" + aType));
this.showEmptyNotice(false);
@ -1006,19 +1026,24 @@ var gListView = {
self.showEmptyNotice(true);
gViewController.updateCommands();
gViewController.notifyViewChanged();
}
AddonManager.getAddonsByTypes(this._types, function(aAddonsList) {
if (gViewController && aRequest != gViewController.currentViewRequest)
return;
addons = aAddonsList;
updateList();
});
AddonManager.getInstallsByTypes(this._installTypes, function(aInstallsList) {
if (gViewController && aRequest != gViewController.currentViewRequest)
return;
installs = aInstallsList;
updateList();
gEventManager.registerInstallListener(self);
});
},
hide: function() {
@ -1098,17 +1123,21 @@ var gDetailView = {
}, true);
},
show: function(aAddonId) {
show: function(aAddonId, aRequest) {
var self = this;
this.node.setAttribute("loading", true);
this._loadingTimer = setTimeout(function() {
self.node.setAttribute("loading-extended", true);
}, LOADING_MSG_DELAY);
gHeader.showBackButton();
var view = gViewController.currentViewId;
AddonManager.getAddonByID(aAddonId, function(aAddon) {
self.clearLoading();
if (gViewController && aRequest != gViewController.currentViewRequest)
return;
self._addon = aAddon;
gEventManager.registerAddonListener(self, aAddon.id);
@ -1144,6 +1173,7 @@ var gDetailView = {
self.updateState();
gViewController.updateCommands();
gViewController.notifyViewChanged();
});
},
@ -1191,7 +1221,6 @@ var gDetailView = {
this._loadingTimer = null;
}
this.node.removeAttribute("loading");
this.node.removeAttribute("loading-extended");
},

Просмотреть файл

@ -45,6 +45,7 @@ include $(DEPTH)/config/autoconf.mk
_TEST_FILES = \
head.js \
browser_bug562899.js \
browser_updatessl.js \
browser_updatessl.rdf \
browser_installssl.js \

Просмотреть файл

@ -0,0 +1,95 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/
*/
// Simulates quickly switching between different list views to verify that only
// the last selected is displayed
Components.utils.import("resource://gre/modules/AddonManager.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/LightweightThemeManager.jsm");
const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi";
var gManagerWindow;
function test() {
waitForExplicitFinish();
Services.prefs.setBoolPref(PREF_LOGGING_ENABLED, true);
// Add a lightweight theme so at least one theme exists
LightweightThemeManager.currentTheme = {
id: "test",
name: "Test lightweight theme",
headerURL: "http://example.com/header.png"
};
open_manager(null, function(aWindow) {
gManagerWindow = aWindow;
run_next_test();
});
}
function end_test() {
Services.prefs.clearUserPref(PREF_LOGGING_ENABLED);
gManagerWindow.close();
LightweightThemeManager.forgetUsedTheme("test");
finish();
}
// Tests that loading a second view before the first has not finished loading
// does not merge the results
add_test(function() {
var themeCount = null;
var pluginCount = null;
var themeItem = gManagerWindow.document.getElementById("category-themes");
var pluginItem = gManagerWindow.document.getElementById("category-plugins");
var list = gManagerWindow.document.getElementById("addon-list");
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
wait_for_view_load(gManagerWindow, function() {
themeCount = list.childNodes.length;
ok(themeCount > 0, "Test is useless if there are no themes");
EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow);
wait_for_view_load(gManagerWindow, function() {
pluginCount = list.childNodes.length;
ok(pluginCount > 0, "Test is useless if there are no plugins");
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow);
wait_for_view_load(gManagerWindow, function() {
is(list.childNodes.length, pluginCount, "Should only see the plugins");
var item = list.firstChild;
while (item) {
is(item.getAttribute("type"), "plugin", "All items should be plugins");
item = item.nextSibling;
}
// Tests that switching to, from, to the same pane in quick succession
// still only shows the right number of results
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
EventUtils.synthesizeMouse(pluginItem, 2, 2, { }, gManagerWindow);
EventUtils.synthesizeMouse(themeItem, 2, 2, { }, gManagerWindow);
wait_for_view_load(gManagerWindow, function() {
is(list.childNodes.length, themeCount, "Should only see the theme");
var item = list.firstChild;
while (item) {
is(item.getAttribute("type"), "theme", "All items should be theme");
item = item.nextSibling;
}
run_next_test();
});
});
});
});
});

Просмотреть файл

@ -8,7 +8,6 @@ Components.utils.import("resource://gre/modules/Services.jsm");
const xpi = "browser/toolkit/mozapps/extensions/test/browser/browser_installssl.xpi";
const redirect = "browser/toolkit/mozapps/extensions/test/browser/redirect.sjs?";
const SUCCESS = 0;
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
var gTests = [];

Просмотреть файл

@ -7,7 +7,6 @@ Components.utils.import("resource://gre/modules/AddonUpdateChecker.jsm");
const updaterdf = "browser/toolkit/mozapps/extensions/test/browser/browser_updatessl.rdf";
const redirect = "browser/toolkit/mozapps/extensions/test/browser/redirect.sjs?";
const SUCCESS = 0;
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
var gTests = [];

Просмотреть файл

@ -2,6 +2,9 @@
* http://creativecommons.org/publicdomain/zero/1.0/
*/
const MANAGER_URI = "about:addons";
const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
var gPendingTests = [];
var gTestsRun = 0;
@ -21,6 +24,42 @@ function run_next_test() {
gPendingTests.shift()();
}
function wait_for_view_load(aManagerWindow, aCallback) {
if (!aManagerWindow.gViewController.currentViewObj.node.hasAttribute("loading")) {
aCallback(aManagerWindow);
return;
}
aManagerWindow.document.addEventListener("ViewChanged", function() {
aManagerWindow.document.removeEventListener("ViewChanged", arguments.callee, false);
aCallback(aManagerWindow);
}, false);
}
function open_manager(aView, aCallback) {
function setup_manager(aManagerWindow) {
if (aView)
aManagerWindow.loadView(aView);
ok(aManagerWindow != null, "Should have an add-ons manager window");
is(aManagerWindow.location, MANAGER_URI, "Should be displaying the correct UI");
wait_for_view_load(aManagerWindow, aCallback);
}
if ("switchToTabHavingURI" in window) {
switchToTabHavingURI(MANAGER_URI, true, function(aBrowser) {
setup_manager(aBrowser.contentWindow.wrappedJSObject);
});
return;
}
openDialog("about:addons").addEventListener("load", function() {
this.removeEventListener("load", arguments.callee, false);
setup_manager(this);
}, false);
}
function CertOverrideListener(host, bits) {
this.host = host;
this.bits = bits;