Bug 1552184 - Go to discover if detail view add-on can't be found r=rpl

Differential Revision: https://phabricator.services.mozilla.com/D31457

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mark Striemer 2019-05-27 15:39:47 +00:00
parent 52bea1fda2
commit 760dbbdc88
3 changed files with 40 additions and 2 deletions

View File

@ -156,6 +156,7 @@ function getOptionsType(addon, type) {
* @param {string} param The (optional) param for the view.
*/
let loadViewFn;
let replaceWithDefaultViewFn;
let setCategoryFn;
let _templates = {};
@ -2079,6 +2080,12 @@ class DetailView {
async render() {
let addon = await AddonManager.getAddonByID(this.id);
if (!addon) {
replaceWithDefaultViewFn();
return;
}
let card = document.createElement("addon-card");
// Ensure the category for this add-on type is selected.
@ -2153,6 +2160,7 @@ let root = null;
function initialize(opts) {
root = document.getElementById("main");
loadViewFn = opts.loadViewFn;
replaceWithDefaultViewFn = opts.replaceWithDefaultViewFn;
setCategoryFn = opts.setCategoryFn;
AddonCardListenerHandler.startup();
window.addEventListener("unload", () => {

View File

@ -3842,12 +3842,15 @@ const addonTypes = new Set([
]);
const htmlViewOpts = {
loadViewFn(type, param) {
let viewId = `addons://${type}`;
let viewId = `addons://${type}/`;
if (param) {
viewId += "/" + encodeURIComponent(param);
viewId += encodeURIComponent(param);
}
gViewController.loadView(viewId);
},
replaceWithDefaultViewFn() {
gViewController.replaceView(gViewDefault);
},
setCategoryFn(name) {
if (addonTypes.has(name)) {
gCategories.select(`addons://list/${name}`);

View File

@ -640,6 +640,33 @@ add_task(async function testPrivateBrowsingExtension() {
await closeView(win);
});
add_task(async function testInvalidExtension() {
let win = await open_manager("addons://detail/foo");
let categoryUtils = new CategoryUtilities(win);
is(categoryUtils.selectedCategory, "discover",
"Should fall back to the discovery pane");
ok(!gBrowser.canGoBack, "The view has been replaced");
await close_manager(win);
});
add_task(async function testInvalidExtensionNoDiscover() {
await SpecialPowers.pushPrefEnv({
set: [["extensions.getAddons.showPane", false]],
});
let win = await open_manager("addons://detail/foo");
let categoryUtils = new CategoryUtilities(win);
is(categoryUtils.selectedCategory, "extension",
"Should fall back to the extension list if discover is disabled");
ok(!gBrowser.canGoBack, "The view has been replaced");
await close_manager(win);
await SpecialPowers.popPrefEnv();
});
add_task(async function testExternalUninstall() {
let id = "remove@mochi.test";
let extension = ExtensionTestUtils.loadExtension({