forked from mirrors/gecko-dev
Bug 1895341 - Add install_type "admin" to the management API. r=rpl
Differential Revision: https://phabricator.services.mozilla.com/D209582
This commit is contained in:
parent
da73bd4d72
commit
2f9ab8fab6
4 changed files with 59 additions and 2 deletions
|
|
@ -8,10 +8,14 @@ const { AddonTestUtils } = ChromeUtils.importESModule(
|
|||
const { AddonManager } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/AddonManager.sys.mjs"
|
||||
);
|
||||
const { ExtensionTestUtils } = ChromeUtils.importESModule(
|
||||
"resource://testing-common/ExtensionXPCShellUtils.sys.mjs"
|
||||
);
|
||||
|
||||
AddonTestUtils.init(this);
|
||||
AddonTestUtils.overrideCertDB();
|
||||
AddonTestUtils.appInfo = getAppInfo();
|
||||
ExtensionTestUtils.init(this);
|
||||
|
||||
const server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] });
|
||||
const BASE_URL = `http://example.com/data`;
|
||||
|
|
@ -21,6 +25,34 @@ let themeID = "policytheme@mozilla.com";
|
|||
|
||||
let fileURL;
|
||||
|
||||
async function assertManagementAPIInstallType(addonId, expectedInstallType) {
|
||||
const addon = await AddonManager.getAddonByID(addonId);
|
||||
const expectInstalledByPolicy = expectedInstallType === "admin";
|
||||
equal(
|
||||
addon.isInstalledByEnterprisePolicy,
|
||||
expectInstalledByPolicy,
|
||||
`Addon should ${
|
||||
expectInstalledByPolicy ? "be" : "NOT be"
|
||||
} marked as installed by enterprise policy`
|
||||
);
|
||||
const policy = WebExtensionPolicy.getByID(addonId);
|
||||
const pageURL = policy.extension.baseURI.resolve(
|
||||
"_generated_background_page.html"
|
||||
);
|
||||
const page = await ExtensionTestUtils.loadContentPage(pageURL);
|
||||
const { id, installType } = await page.spawn([], async () => {
|
||||
const res = await this.content.wrappedJSObject.browser.management.getSelf();
|
||||
return { id: res.id, installType: res.installType };
|
||||
});
|
||||
await page.close();
|
||||
Assert.equal(id, addonId, "Got results for the expected addon id");
|
||||
Assert.equal(
|
||||
installType,
|
||||
expectedInstallType,
|
||||
"Got the expected installType on policy installed extension"
|
||||
);
|
||||
}
|
||||
|
||||
add_setup(async function setup() {
|
||||
await AddonTestUtils.promiseStartupManager();
|
||||
|
||||
|
|
@ -115,7 +147,14 @@ add_task(async function test_addon_allowed() {
|
|||
);
|
||||
await install.install();
|
||||
notEqual(install.addon, null, "Addon should not be null");
|
||||
await assertManagementAPIInstallType(install.addon.id, "normal");
|
||||
equal(install.addon.appDisabled, false, "Addon should not be disabled");
|
||||
equal(
|
||||
install.addon.isInstalledByEnterprisePolicy,
|
||||
false,
|
||||
"Addon should NOT be marked as installed by enterprise policy"
|
||||
);
|
||||
|
||||
await install.addon.uninstall();
|
||||
});
|
||||
|
||||
|
|
@ -169,6 +208,8 @@ add_task(async function test_addon_forceinstalled() {
|
|||
0,
|
||||
"Addon should not be able to be disabled."
|
||||
);
|
||||
await assertManagementAPIInstallType(addon.id, "admin");
|
||||
|
||||
await addon.uninstall();
|
||||
});
|
||||
|
||||
|
|
@ -199,6 +240,8 @@ add_task(async function test_addon_normalinstalled() {
|
|||
0,
|
||||
"Addon should be able to be disabled."
|
||||
);
|
||||
await assertManagementAPIInstallType(addon.id, "admin");
|
||||
|
||||
await addon.uninstall();
|
||||
});
|
||||
|
||||
|
|
@ -290,6 +333,7 @@ add_task(async function test_addon_normalinstalled_file() {
|
|||
0,
|
||||
"Addon should be able to be disabled."
|
||||
);
|
||||
await assertManagementAPIInstallType(addon.id, "admin");
|
||||
|
||||
await addon.uninstall();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ const installType = addon => {
|
|||
return "sideload";
|
||||
} else if (addon.isSystem) {
|
||||
return "other";
|
||||
} else if (addon.isInstalledByEnterprisePolicy) {
|
||||
return "admin";
|
||||
}
|
||||
return "normal";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@
|
|||
},
|
||||
{
|
||||
"id": "ExtensionInstallType",
|
||||
"description": "How the extension was installed. One of<br><var>development</var>: The extension was loaded unpacked in developer mode,<br><var>normal</var>: The extension was installed normally via an .xpi file,<br><var>sideload</var>: The extension was installed by other software on the machine,<br><var>other</var>: The extension was installed by other means.",
|
||||
"description": "How the extension was installed. One of<br><var>development</var>: The extension was loaded unpacked in developer mode,<br><var>normal</var>: The extension was installed normally via an .xpi file,<br><var>sideload</var>: The extension was installed by other software on the machine,<br><var>admin</var>: The extension was installed by policy,<br><var>other</var>: The extension was installed by other means.",
|
||||
"type": "string",
|
||||
"enum": ["development", "normal", "sideload", "other"]
|
||||
"enum": ["development", "normal", "sideload", "admin", "other"]
|
||||
},
|
||||
{
|
||||
"id": "ExtensionInfo",
|
||||
|
|
|
|||
|
|
@ -1427,6 +1427,17 @@ AddonWrapper = class {
|
|||
return addon.location.name == KEY_APP_PROFILE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the addon is configured to be installed
|
||||
* by enterprise policy.
|
||||
*/
|
||||
get isInstalledByEnterprisePolicy() {
|
||||
const policySettings = Services.policies?.getExtensionSettings(this.id);
|
||||
return ["force_installed", "normal_installed"].includes(
|
||||
policySettings?.installation_mode
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Required permissions that extension has access to based on its manifest.
|
||||
* In mv3 this doesn't include host_permissions.
|
||||
|
|
|
|||
Loading…
Reference in a new issue