diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /toolkit/mozapps/extensions/test/xpcshell/test_update_addontype.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_update_addontype.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_update_addontype.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_update_addontype.js b/toolkit/mozapps/extensions/test/xpcshell/test_update_addontype.js new file mode 100644 index 0000000000..ca324cf4ef --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_addontype.js @@ -0,0 +1,75 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// The test extension uses an insecure update url. +Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); + +let server = AddonTestUtils.createHttpServer({ hosts: ["example.com"] }); + +add_task(async function setup() { + await ExtensionTestUtils.startAddonManager(); +}); + +add_task(async function test_update_theme_to_extension() { + const THEME_ID = "theme@tests.mozilla.org"; + await promiseInstallWebExtension({ + manifest: { + version: "1.0", + theme: {}, + browser_specific_settings: { + gecko: { + id: THEME_ID, + update_url: "http://example.com/update.json", + }, + }, + }, + }); + + let xpi = await createTempWebExtensionFile({ + manifest: { + version: "2.0", + browser_specific_settings: { gecko: { id: THEME_ID } }, + }, + }); + + server.registerFile("/addon.xpi", xpi); + AddonTestUtils.registerJSON(server, "/update.json", { + addons: { + [THEME_ID]: { + updates: [ + { + version: "2.0", + update_link: "http://example.com/addon.xpi", + }, + ], + }, + }, + }); + + let addon = await promiseAddonByID(THEME_ID); + Assert.notEqual(addon, null); + Assert.equal(addon.type, "theme"); + Assert.equal(addon.version, "1.0"); + + let update = await promiseFindAddonUpdates( + addon, + AddonManager.UPDATE_WHEN_USER_REQUESTED + ); + let install = update.updateAvailable; + Assert.notEqual(install, null, "Found available update"); + // Although the downloaded xpi is an "extension", install.type is "theme" + // because install.type reflects the type of the add-on that is being updated. + Assert.equal(install.type, "theme"); + Assert.equal(install.version, "2.0"); + Assert.equal(install.state, AddonManager.STATE_AVAILABLE); + Assert.equal(install.existingAddon, addon); + + await Assert.rejects( + install.install(), + err => install.error == AddonManager.ERROR_UNEXPECTED_ADDON_TYPE, + "Refusing to change addon type from theme to extension" + ); + + await addon.uninstall(); +}); |