Skip to content
Snippets Groups Projects
Commit 231cd405 authored by William Durand's avatar William Durand
Browse files

Bug 1824346 - Only uninstall temporary add-ons. r=jdescottes,robwu,devtools-reviewers

parent cb1468a8
No related branches found
No related tags found
No related merge requests found
......@@ -69,9 +69,13 @@ class AddonsActor extends Actor {
async uninstallAddon(addonId) {
const addon = await AddonManager.getAddonByID(addonId);
if (addon) {
await addon.uninstall();
// We only support uninstallation of temporarily loaded add-ons at the
// moment.
if (!addon?.temporarilyInstalled) {
throw new Error(`Could not uninstall add-on "${addonId}"`);
}
await addon.uninstall();
}
}
......
......@@ -6,6 +6,11 @@ http://creativecommons.org/publicdomain/zero/1.0/ */
const { AddonManager } = ChromeUtils.import(
"resource://gre/modules/AddonManager.jsm"
);
const { ExtensionTestUtils } = ChromeUtils.import(
"resource://testing-common/ExtensionXPCShellUtils.jsm"
);
ExtensionTestUtils.init(this);
// The `AddonsManager` test helper can only be called once per test script.
// This `setup` task will run first.
......@@ -121,5 +126,38 @@ add_task(async function test_webext_run_apis() {
}));
equal(addons.length, 0, "expected no add-on installed");
// Attempt to uninstall an add-on that is (no longer) installed.
let error = await sendRequest(transport, {
to: getRootResponse.addonsActor,
type: "uninstallAddon",
addonId,
});
equal(
error?.message,
`Could not uninstall add-on "${addonId}"`,
"expected error"
);
// Attempt to uninstall a non-temporarily loaded extension, which we do not
// allow at the moment. We start by loading an extension, then we call the
// `uninstallAddon`.
const id = "not-a-temporary@extension";
const extension = ExtensionTestUtils.loadExtension({
manifest: {
browser_specific_settings: { gecko: { id } },
},
useAddonManager: "permanent",
});
await extension.startup();
error = await sendRequest(transport, {
to: getRootResponse.addonsActor,
type: "uninstallAddon",
addonId: id,
});
equal(error?.message, `Could not uninstall add-on "${id}"`, "expected error");
await extension.unload();
transport.close();
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment