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_types.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_types.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_types.js | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_types.js b/toolkit/mozapps/extensions/test/xpcshell/test_types.js new file mode 100644 index 0000000000..b9a0d3987e --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_types.js @@ -0,0 +1,117 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// This verifies that custom types can be defined and undefined + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2"); + +add_task(async function setup() { + await promiseStartupManager(); +}); + +add_task(async function test_new_addonType() { + Assert.equal(false, AddonManager.hasAddonType("test")); + + // The dumbest provider possible + const provider = {}; + + AddonManagerPrivate.registerProvider(provider, ["test"]); + + Assert.equal(true, AddonManager.hasAddonType("test")); + Assert.equal(false, AddonManager.hasAddonType("t$e%st")); + Assert.equal(false, AddonManager.hasAddonType(null)); + Assert.equal(false, AddonManager.hasAddonType(undefined)); + + AddonManagerPrivate.unregisterProvider(provider); + + Assert.equal(false, AddonManager.hasAddonType("test")); +}); + +add_task(async function test_bad_addonType() { + const provider = {}; + Assert.throws( + () => AddonManagerPrivate.registerProvider(provider, /* addonTypes =*/ {}), + /aTypes must be an array or null/ + ); + + Assert.throws( + () => AddonManagerPrivate.registerProvider(provider, new Set()), + /aTypes must be an array or null/ + ); +}); + +add_task(async function test_addonTypes_should_be_immutable() { + const provider = {}; + const addonTypes = []; + + addonTypes.push("test"); + AddonManagerPrivate.registerProvider(provider, addonTypes); + addonTypes.pop(); + addonTypes.push("test_added"); + // Modifications to addonTypes should not affect AddonManager. + Assert.equal(true, AddonManager.hasAddonType("test")); + Assert.equal(false, AddonManager.hasAddonType("test_added")); + AddonManagerPrivate.unregisterProvider(provider); + + AddonManagerPrivate.registerProvider(provider, addonTypes); + // After re-registering the provider, the type change should have been processed. + Assert.equal(false, AddonManager.hasAddonType("test")); + Assert.equal(true, AddonManager.hasAddonType("test_added")); + AddonManagerPrivate.unregisterProvider(provider); +}); + +add_task(async function test_missing_addonType() { + const dummyAddon = { + id: "some dummy addon from provider without .addonTypes property", + }; + const provider = { + // addonTypes Set is missing. This only happens in unit tests, but let's + // verify that the implementation behaves reasonably. + // A provider without an explicitly registered type may still return an + // entry when getAddonsByTypes is called. + async getAddonsByTypes(types) { + Assert.equal(null, types); + return [dummyAddon]; + }, + }; + + AddonManagerPrivate.registerProvider(provider); // addonTypes not set. + Assert.equal(false, AddonManager.hasAddonType("test")); + Assert.equal(false, AddonManager.hasAddonType(null)); + Assert.equal(false, AddonManager.hasAddonType(undefined)); + + const addons = await AddonManager.getAddonsByTypes(null); + Assert.equal(1, addons.length); + Assert.equal(dummyAddon, addons[0]); + + AddonManagerPrivate.unregisterProvider(provider); +}); + +add_task(async function test_getAddonTypesByProvider() { + let defaultTypes = AddonManagerPrivate.getAddonTypesByProvider("XPIProvider"); + Assert.ok(defaultTypes.includes("extension"), `extension in ${defaultTypes}`); + Assert.throws( + () => AddonManagerPrivate.getAddonTypesByProvider(), + /No addonTypes found for provider: undefined/ + ); + Assert.throws( + () => AddonManagerPrivate.getAddonTypesByProvider("MaybeExistent"), + /No addonTypes found for provider: MaybeExistent/ + ); + + const provider = { name: "MaybeExistent" }; + AddonManagerPrivate.registerProvider(provider, ["test"]); + Assert.deepEqual( + AddonManagerPrivate.getAddonTypesByProvider("MaybeExistent"), + ["test"], + "Newly registered type returned by getAddonTypesByProvider" + ); + + AddonManagerPrivate.unregisterProvider(provider); + + Assert.throws( + () => AddonManagerPrivate.getAddonTypesByProvider("MaybeExistent"), + /No addonTypes found for provider: MaybeExistent/ + ); +}); |