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_sideloads.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 '')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js | 117 |
1 files changed, 117 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js b/toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js new file mode 100644 index 0000000000..f2ffe8e855 --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_sideloads.js @@ -0,0 +1,117 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "49"); + +const ID1 = "addon1@tests.mozilla.org"; +const ID2 = "addon2@tests.mozilla.org"; +const ID3 = "addon3@tests.mozilla.org"; + +async function createWebExtension(details) { + let options = { + manifest: { + browser_specific_settings: { gecko: { id: details.id } }, + + name: details.name, + + permissions: details.permissions, + }, + }; + + if (details.iconURL) { + options.manifest.icons = { 64: details.iconURL }; + } + + let xpi = AddonTestUtils.createTempWebExtensionFile(options); + + await AddonTestUtils.manuallyInstall(xpi); +} + +add_task(async function test_sideloading() { + Services.prefs.setIntPref("extensions.autoDisableScopes", 15); + Services.prefs.setIntPref("extensions.startupScanScopes", 0); + + await createWebExtension({ + id: ID1, + name: "Test 1", + userDisabled: true, + permissions: ["tabs", "https://*/*"], + iconURL: "foo-icon.png", + }); + + await createWebExtension({ + id: ID2, + name: "Test 2", + permissions: ["<all_urls>"], + }); + + await createWebExtension({ + id: ID3, + name: "Test 3", + permissions: ["<all_urls>"], + }); + + await promiseStartupManager(); + + let sideloaded = await AddonManagerPrivate.getNewSideloads(); + + sideloaded.sort((a, b) => a.id.localeCompare(b.id)); + + deepEqual( + sideloaded.map(a => a.id), + [ID1, ID2, ID3], + "Got the correct sideload add-ons" + ); + + deepEqual( + sideloaded.map(a => a.userDisabled), + [true, true, true], + "All sideloaded add-ons are disabled" + ); +}); + +add_task(async function test_getNewSideload_on_invalid_extension() { + let destDir = AddonTestUtils.profileExtensions.clone(); + + let xpi = AddonTestUtils.createTempWebExtensionFile({ + manifest: { + browser_specific_settings: { gecko: { id: "@invalid-extension" } }, + name: "Invalid Extension", + }, + }); + + // Create an invalid sideload by creating a file name that doesn't match the + // actual extension id. + await IOUtils.copy( + xpi.path, + PathUtils.join(destDir.path, "@wrong-extension-filename.xpi") + ); + + // Verify that getNewSideloads does not reject or throw when one of the sideloaded extensions + // is invalid. + const newSideloads = await AddonManagerPrivate.getNewSideloads(); + + const sideloadsInfo = newSideloads + .sort((a, b) => a.id.localeCompare(b.id)) + .map(({ id, seen, userDisabled, permissions }) => { + return { + id, + seen, + userDisabled, + canEnable: Boolean(permissions & AddonManager.PERM_CAN_ENABLE), + }; + }); + + const expectedInfo = { seen: false, userDisabled: true, canEnable: true }; + + Assert.deepEqual( + sideloadsInfo, + [ + { id: ID1, ...expectedInfo }, + { id: ID2, ...expectedInfo }, + { id: ID3, ...expectedInfo }, + ], + "Got the expected sideloaded extensions" + ); +}); |