Bug 1972314 - Mark extensions installed by Extensions policy as admin. a=pascalc

Original Revision: https://phabricator.services.mozilla.com/D253831

Differential Revision: https://phabricator.services.mozilla.com/D256821
This commit is contained in:
Michael Kaply
2025-07-10 16:35:39 +00:00
committed by pchevrel@mozilla.com
parent cbf82e81ad
commit 206f5fce02
7 changed files with 65 additions and 39 deletions

View File

@@ -27,6 +27,9 @@ ChromeUtils.defineESModuleGetters(lazy, {
const { EnterprisePolicyTesting } = ChromeUtils.importESModule(
"resource://testing-common/EnterprisePolicyTesting.sys.mjs"
);
const { ExtensionTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/ExtensionXPCShellUtils.sys.mjs"
);
updateAppInfo({
name: "XPCShell",
@@ -148,3 +151,31 @@ function checkUnsetPref(prefName) {
`Pref ${prefName} is not set on the default branch`
);
}
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"
);
}

View File

@@ -9,9 +9,6 @@ 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();

View File

@@ -59,6 +59,8 @@ add_task(async function test_addon_forceinstalled_remote() {
0,
"Addon should not be able to be disabled."
);
await assertManagementAPIInstallType(addon.id, "admin");
await addon.uninstall();
});

View File

@@ -8,9 +8,6 @@ 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();
@@ -27,34 +24,6 @@ let policyOnlyID = "policy_installed_only@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"
);
}
function waitForAddonInstall(addonId) {
return new Promise(resolve => {
let listener = {