From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../test/xpcshell/test_update_compatmode.js | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js') diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js b/toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js new file mode 100644 index 0000000000..85ec556f95 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_update_compatmode.js @@ -0,0 +1,112 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// This verifies that add-on update check correctly fills in the +// %COMPATIBILITY_MODE% token in the update URL. + +// The test extension uses an insecure update url. +Services.prefs.setBoolPref(PREF_EM_CHECK_UPDATE_SECURITY, false); + +let testserver = createHttpServer({ hosts: ["example.com"] }); + +let lastMode; +testserver.registerPathHandler("/update.json", (request, response) => { + let params = new URLSearchParams(request.queryString); + lastMode = params.get("mode"); + + response.setHeader("content-type", "application/json", true); + response.write(JSON.stringify({ addons: {} })); +}); + +const ID_NORMAL = "compatmode@tests.mozilla.org"; +const ID_STRICT = "compatmode-strict@tests.mozilla.org"; + +add_task(async function setup() { + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + + let xpi = await createAddon({ + id: ID_NORMAL, + updateURL: "http://example.com/update.json?mode=%COMPATIBILITY_MODE%", + targetApplications: [ + { + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1", + }, + ], + }); + await manuallyInstall(xpi, AddonTestUtils.profileExtensions, ID_NORMAL); + + xpi = await createAddon({ + id: ID_STRICT, + updateURL: "http://example.com/update.json?mode=%COMPATIBILITY_MODE%", + strictCompatibility: true, + targetApplications: [ + { + id: "xpcshell@tests.mozilla.org", + minVersion: "1", + maxVersion: "1", + }, + ], + }); + await manuallyInstall(xpi, AddonTestUtils.profileExtensions, ID_STRICT); + + await promiseStartupManager(); +}); + +// Strict compatibility checking disabled. +add_task(async function test_strict_disabled() { + Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); + let addon = await AddonManager.getAddonByID(ID_NORMAL); + Assert.notEqual(addon, null); + + await promiseFindAddonUpdates(addon, AddonManager.UPDATE_WHEN_USER_REQUESTED); + Assert.equal( + lastMode, + "normal", + "COMPATIBIILITY_MODE normal was set correctly" + ); +}); + +// Strict compatibility checking enabled. +add_task(async function test_strict_enabled() { + Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, true); + let addon = await AddonManager.getAddonByID(ID_NORMAL); + Assert.notEqual(addon, null); + + await promiseFindAddonUpdates(addon, AddonManager.UPDATE_WHEN_USER_REQUESTED); + Assert.equal( + lastMode, + "strict", + "COMPATIBILITY_MODE strict was set correctly" + ); +}); + +// Strict compatibility checking opt-in. +add_task(async function test_strict_optin() { + Services.prefs.setBoolPref(PREF_EM_STRICT_COMPATIBILITY, false); + let addon = await AddonManager.getAddonByID(ID_STRICT); + Assert.notEqual(addon, null); + + await promiseFindAddonUpdates(addon, AddonManager.UPDATE_WHEN_USER_REQUESTED); + Assert.equal( + lastMode, + "normal", + "COMPATIBILITY_MODE is normal even for an addon with strictCompatibility" + ); +}); + +// Compatibility checking disabled. +add_task(async function test_compat_disabled() { + AddonManager.checkCompatibility = false; + let addon = await AddonManager.getAddonByID(ID_NORMAL); + Assert.notEqual(addon, null); + + await promiseFindAddonUpdates(addon, AddonManager.UPDATE_WHEN_USER_REQUESTED); + Assert.equal( + lastMode, + "ignore", + "COMPATIBILITY_MODE ignore was set correctly" + ); +}); -- cgit v1.2.3