зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1596481 - Try to update extensions installed via policy. r=mixedpuppy
Differential Revision: https://phabricator.services.mozilla.com/D74340
This commit is contained in:
Родитель
cdad170543
Коммит
4333cb7419
|
@ -891,12 +891,11 @@ var Policies = {
|
|||
if (!extensionSettings[extensionID].install_url) {
|
||||
throw new Error(`Missing install_url for ${extensionID}`);
|
||||
}
|
||||
if (!addons.find(addon => addon.id == extensionID)) {
|
||||
installAddonFromURL(
|
||||
extensionSettings[extensionID].install_url,
|
||||
extensionID
|
||||
);
|
||||
}
|
||||
installAddonFromURL(
|
||||
extensionSettings[extensionID].install_url,
|
||||
extensionID,
|
||||
addons.find(addon => addon.id == extensionID)
|
||||
);
|
||||
manager.disallowFeature(`uninstall-extension:${extensionID}`);
|
||||
if (
|
||||
extensionSettings[extensionID].installation_mode ==
|
||||
|
@ -1935,7 +1934,15 @@ function replacePathVariables(path) {
|
|||
* Helper function that installs an addon from a URL
|
||||
* and verifies that the addon ID matches.
|
||||
*/
|
||||
function installAddonFromURL(url, extensionID) {
|
||||
function installAddonFromURL(url, extensionID, addon) {
|
||||
if (
|
||||
addon &&
|
||||
addon.sourceURI.spec == url &&
|
||||
!addon.sourceURI.schemeIs("file")
|
||||
) {
|
||||
// It's the same addon, don't reinstall.
|
||||
return;
|
||||
}
|
||||
AddonManager.getInstallForURL(url, {
|
||||
telemetryInfo: { source: "enterprise-policy" },
|
||||
}).then(install => {
|
||||
|
@ -1959,6 +1966,14 @@ function installAddonFromURL(url, extensionID) {
|
|||
install.removeListener(listener);
|
||||
install.cancel();
|
||||
}
|
||||
if (
|
||||
addon &&
|
||||
Services.vc.compare(addon.version, install.addon.version) == 0
|
||||
) {
|
||||
log.debug("Installation cancelled because versions are the same");
|
||||
install.removeListener(listener);
|
||||
install.cancel();
|
||||
}
|
||||
},
|
||||
onDownloadFailed: () => {
|
||||
install.removeListener(listener);
|
||||
|
|
|
@ -0,0 +1,147 @@
|
|||
/* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
const { AddonTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/AddonTestUtils.jsm"
|
||||
);
|
||||
const { AddonManager } = ChromeUtils.import(
|
||||
"resource://gre/modules/AddonManager.jsm"
|
||||
);
|
||||
|
||||
AddonTestUtils.init(this);
|
||||
AddonTestUtils.overrideCertDB();
|
||||
AddonTestUtils.appInfo = getAppInfo();
|
||||
|
||||
const server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] });
|
||||
const BASE_URL = `http://example.com/data`;
|
||||
|
||||
let TEST_NAME = "updatable.xpi";
|
||||
|
||||
/* Test that when a local file addon is updated,
|
||||
the new version gets installed. */
|
||||
add_task(async function test_local_addon_update() {
|
||||
await AddonTestUtils.promiseStartupManager();
|
||||
|
||||
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
|
||||
let id = "updatable1@test";
|
||||
let xpi1 = AddonTestUtils.createTempWebExtensionFile({
|
||||
manifest: {
|
||||
version: "1.0",
|
||||
applications: {
|
||||
gecko: { id },
|
||||
},
|
||||
},
|
||||
});
|
||||
xpi1.copyTo(tmpDir, TEST_NAME);
|
||||
|
||||
await Promise.all([
|
||||
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
|
||||
setupPolicyEngineWithJson({
|
||||
policies: {
|
||||
ExtensionSettings: {
|
||||
"updatable@test": {
|
||||
installation_mode: "force_installed",
|
||||
install_url: Services.io.newFileURI(tmpDir).spec + "/" + TEST_NAME,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
let addon = await AddonManager.getAddonByID(id);
|
||||
notEqual(addon, null, "Addon should not be null");
|
||||
equal(addon.version, "1.0", "Addon 1.0 installed");
|
||||
|
||||
let xpi2 = AddonTestUtils.createTempWebExtensionFile({
|
||||
manifest: {
|
||||
version: "2.0",
|
||||
applications: {
|
||||
gecko: { id },
|
||||
},
|
||||
},
|
||||
});
|
||||
// overwrite the test file
|
||||
xpi2.copyTo(tmpDir, TEST_NAME);
|
||||
|
||||
await Promise.all([
|
||||
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
|
||||
setupPolicyEngineWithJson({
|
||||
policies: {
|
||||
ExtensionSettings: {
|
||||
"updatable@test": {
|
||||
installation_mode: "force_installed",
|
||||
install_url: Services.io.newFileURI(tmpDir).spec + "/" + TEST_NAME,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
addon = await AddonManager.getAddonByID(id);
|
||||
equal(addon.version, "2.0", "Addon 2.0 installed");
|
||||
|
||||
let xpifile = tmpDir.clone();
|
||||
xpifile.append(TEST_NAME);
|
||||
xpifile.remove(false);
|
||||
});
|
||||
|
||||
/* Test that when the url changes,
|
||||
the new version gets installed. */
|
||||
add_task(async function test_newurl_addon_update() {
|
||||
let id = "updatable2@test";
|
||||
|
||||
let xpi1 = AddonTestUtils.createTempWebExtensionFile({
|
||||
manifest: {
|
||||
version: "1.0",
|
||||
applications: {
|
||||
gecko: { id },
|
||||
},
|
||||
},
|
||||
});
|
||||
server.registerFile("/data/policy_test1.xpi", xpi1);
|
||||
|
||||
let xpi2 = AddonTestUtils.createTempWebExtensionFile({
|
||||
manifest: {
|
||||
version: "2.0",
|
||||
applications: {
|
||||
gecko: { id },
|
||||
},
|
||||
},
|
||||
});
|
||||
server.registerFile("/data/policy_test2.xpi", xpi2);
|
||||
|
||||
await Promise.all([
|
||||
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
|
||||
setupPolicyEngineWithJson({
|
||||
policies: {
|
||||
ExtensionSettings: {
|
||||
"updatable2@test": {
|
||||
installation_mode: "force_installed",
|
||||
install_url: `${BASE_URL}/policy_test1.xpi`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
let addon = await AddonManager.getAddonByID(id);
|
||||
notEqual(addon, null, "Addon should not be null");
|
||||
equal(addon.version, "1.0", "Addon 1.0 installed");
|
||||
|
||||
await Promise.all([
|
||||
AddonTestUtils.promiseInstallEvent("onInstallEnded"),
|
||||
setupPolicyEngineWithJson({
|
||||
policies: {
|
||||
ExtensionSettings: {
|
||||
"updatable2@test": {
|
||||
installation_mode: "force_installed",
|
||||
install_url: `${BASE_URL}/policy_test2.xpi`,
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
|
||||
addon = await AddonManager.getAddonByID(id);
|
||||
equal(addon.version, "2.0", "Addon 2.0 installed");
|
||||
});
|
|
@ -5,6 +5,7 @@ support-files =
|
|||
policytest_v0.1.xpi
|
||||
|
||||
[test_3rdparty.js]
|
||||
[test_addon_update.js]
|
||||
[test_appupdateurl.js]
|
||||
[test_clear_blocked_cookies.js]
|
||||
[test_defaultbrowsercheck.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче