diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /toolkit/mozapps/extensions/test/xpcshell/test_distribution.js | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_distribution.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_distribution.js | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_distribution.js b/toolkit/mozapps/extensions/test/xpcshell/test_distribution.js new file mode 100644 index 0000000000..61231160d8 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_distribution.js @@ -0,0 +1,115 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// This verifies that add-ons distributed with the application get installed +// correctly + +// Allow distributed add-ons to install +Services.prefs.setBoolPref("extensions.installDistroAddons", true); + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + +const profileDir = gProfD.clone(); +profileDir.append("extensions"); +const distroDir = gProfD.clone(); +distroDir.append("distribution"); +distroDir.append("extensions"); +registerDirectory("XREAppDist", distroDir.parent); + +async function setOldModificationTime() { + // Make sure the installed extension has an old modification time so any + // changes will be detected + await promiseShutdownManager(); + let extension = gProfD.clone(); + extension.append("extensions"); + extension.append(`${ID}.xpi`); + setExtensionModifiedTime(extension, Date.now() - MAKE_FILE_OLD_DIFFERENCE); + await promiseStartupManager(); +} + +const ID = "addon@tests.mozilla.org"; + +async function writeDistroAddon(version) { + let xpi = await createTempWebExtensionFile({ + manifest: { + version, + browser_specific_settings: { gecko: { id: ID } }, + }, + }); + xpi.copyTo(distroDir, `${ID}.xpi`); +} + +// Tests that on the first startup the add-on gets installed +add_task(async function run_test_1() { + await writeDistroAddon("1.0"); + await promiseStartupManager(); + + let a1 = await AddonManager.getAddonByID(ID); + Assert.notEqual(a1, null); + Assert.equal(a1.version, "1.0"); + Assert.ok(a1.isActive); + Assert.equal(a1.scope, AddonManager.SCOPE_PROFILE); + Assert.ok(!a1.foreignInstall); +}); + +// Tests that starting with a newer version in the distribution dir doesn't +// install it yet +add_task(async function run_test_2() { + await setOldModificationTime(); + + await writeDistroAddon("2.0"); + await promiseRestartManager(); + + let a1 = await AddonManager.getAddonByID(ID); + Assert.notEqual(a1, null); + Assert.equal(a1.version, "1.0"); + Assert.ok(a1.isActive); + Assert.equal(a1.scope, AddonManager.SCOPE_PROFILE); +}); + +// Test that an app upgrade installs the newer version +add_task(async function run_test_3() { + await promiseRestartManager("2"); + + let a1 = await AddonManager.getAddonByID(ID); + Assert.notEqual(a1, null); + Assert.equal(a1.version, "2.0"); + Assert.ok(a1.isActive); + Assert.equal(a1.scope, AddonManager.SCOPE_PROFILE); + Assert.ok(!a1.foreignInstall); +}); + +// Test that an app upgrade doesn't downgrade the extension +add_task(async function run_test_4() { + await setOldModificationTime(); + + await writeDistroAddon("1.0"); + await promiseRestartManager("3"); + + let a1 = await AddonManager.getAddonByID(ID); + Assert.notEqual(a1, null); + Assert.equal(a1.version, "2.0"); + Assert.ok(a1.isActive); + Assert.equal(a1.scope, AddonManager.SCOPE_PROFILE); +}); + +// Tests that after uninstalling a restart doesn't re-install the extension +add_task(async function run_test_5() { + let a1 = await AddonManager.getAddonByID(ID); + await a1.uninstall(); + + await promiseRestartManager(); + + let a1_2 = await AddonManager.getAddonByID(ID); + Assert.equal(a1_2, null); +}); + +// Tests that upgrading the application still doesn't re-install the uninstalled +// extension +add_task(async function run_test_6() { + await promiseRestartManager("4"); + + let a1 = await AddonManager.getAddonByID(ID); + Assert.equal(a1, null); +}); |