Bug 1715965 - Handle errors for local XPIs installed by policy. r=mixedpuppy

Differential Revision: https://phabricator.services.mozilla.com/D120763
This commit is contained in:
Mike Kaply 2021-07-27 14:42:43 +00:00
parent f8c21b0734
commit 9760bc5f64
3 changed files with 46 additions and 2 deletions

View File

@ -2423,6 +2423,14 @@ function installAddonFromURL(url, extensionID, addon) {
log.debug(`Installation succeeded - ${url}`);
},
};
// If it's a local file install, onDownloadEnded is never called.
// So we call it manually, to handle some error cases.
if (url.startsWith("file:")) {
listener.onDownloadEnded(install);
if (install.state == AddonManager.STATE_CANCELLED) {
return;
}
}
install.addListener(listener);
install.install();
});

View File

@ -45,7 +45,7 @@ add_task(async function test_local_addon_update() {
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"updatable@test": {
"updatable1@test": {
installation_mode: "force_installed",
install_url: Services.io.newFileURI(tmpDir).spec + "/" + TEST_NAME,
},
@ -74,7 +74,7 @@ add_task(async function test_local_addon_update() {
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"updatable@test": {
"updatable1@test": {
installation_mode: "force_installed",
install_url: Services.io.newFileURI(tmpDir).spec + "/" + TEST_NAME,
},

View File

@ -19,6 +19,8 @@ const BASE_URL = `http://example.com/data`;
let addonID = "policytest2@mozilla.com";
let themeID = "policytheme@mozilla.com";
let fileURL;
add_task(async function setup() {
await AddonTestUtils.promiseStartupManager();
@ -33,6 +35,9 @@ add_task(async function setup() {
});
server.registerFile("/data/policy_test.xpi", webExtensionFile);
fileURL = Services.io
.newFileURI(webExtensionFile)
.QueryInterface(Ci.nsIFileURL);
});
add_task(async function test_extensionsettings() {
@ -253,3 +258,34 @@ add_task(async function test_theme() {
let addon = await AddonManager.getAddonByID(themeID);
await addon.uninstall();
});
add_task(async function test_addon_normalinstalled_file() {
await Promise.all([
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
setupPolicyEngineWithJson({
policies: {
ExtensionSettings: {
"policytest2@mozilla.com": {
installation_mode: "normal_installed",
install_url: fileURL.spec,
},
},
},
}),
]);
let addon = await AddonManager.getAddonByID(addonID);
notEqual(addon, null, "Addon should not be null");
equal(addon.appDisabled, false, "Addon should not be disabled");
equal(
addon.permissions & AddonManager.PERM_CAN_UNINSTALL,
0,
"Addon should not be able to be uninstalled."
);
notEqual(
addon.permissions & AddonManager.PERM_CAN_DISABLE,
0,
"Addon should be able to be disabled."
);
await addon.uninstall();
});