diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js | |
parent | Initial commit. (diff) | |
download | firefox-upstream.tar.xz firefox-upstream.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js')
-rw-r--r-- | toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js b/toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js new file mode 100644 index 0000000000..9762d17dbe --- /dev/null +++ b/toolkit/mozapps/extensions/test/xpcshell/test_syncGUID.js @@ -0,0 +1,115 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +// restartManager() mucks with XPIProvider.jsm importing, so we hack around. +this.__defineGetter__("XPIProvider", function() { + return ChromeUtils.import( + "resource://gre/modules/addons/XPIProvider.jsm" + ).XPIProvider; +}); + +const UUID_PATTERN = /^\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}$/i; + +const ADDONS = [ + { + id: "addon1@tests.mozilla.org", + name: "Test 1", + }, + { + id: "addon2@tests.mozilla.org", + name: "Real Test 2", + }, +]; + +let xpis; + +add_task(async function setup() { + Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false); + + createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9"); + await promiseStartupManager(); + + xpis = await Promise.all( + ADDONS.map(info => + createTempWebExtensionFile({ + manifest: { + name: info.name, + browser_specific_settings: { gecko: { id: info.id } }, + }, + }) + ) + ); +}); + +add_task(async function test_getter_and_setter() { + await promiseInstallFile(xpis[0]); + + let addon = await AddonManager.getAddonByID(ADDONS[0].id); + Assert.notEqual(addon, null); + Assert.notEqual(addon.syncGUID, null); + Assert.ok(UUID_PATTERN.test(addon.syncGUID)); + + let newGUID = "foo"; + + addon.syncGUID = newGUID; + Assert.equal(newGUID, addon.syncGUID); + + // Verify change made it to DB. + let newAddon = await AddonManager.getAddonByID(ADDONS[0].id); + Assert.notEqual(newAddon, null); + Assert.equal(newGUID, newAddon.syncGUID); +}); + +add_task(async function test_fetch_by_guid_unknown_guid() { + let addon = await XPIProvider.getAddonBySyncGUID("XXXX"); + Assert.equal(null, addon); +}); + +// Ensure setting an extension to an existing syncGUID results in error. +add_task(async function test_error_on_duplicate_syncguid_insert() { + await promiseInstallAllFiles(xpis); + + let addons = await AddonManager.getAddonsByIDs(ADDONS.map(a => a.id)); + let initialGUID = addons[1].syncGUID; + + Assert.throws( + () => { + addons[1].syncGUID = addons[0].syncGUID; + }, + /Addon sync GUID conflict/, + "Assigning conflicting sync guids throws" + ); + + await promiseRestartManager(); + + let addon = await AddonManager.getAddonByID(ADDONS[1].id); + Assert.equal(initialGUID, addon.syncGUID); +}); + +add_task(async function test_fetch_by_guid_known_guid() { + let addon = await AddonManager.getAddonByID(ADDONS[0].id); + Assert.notEqual(null, addon); + Assert.notEqual(null, addon.syncGUID); + + let syncGUID = addon.syncGUID; + + let newAddon = await XPIProvider.getAddonBySyncGUID(syncGUID); + Assert.notEqual(null, newAddon); + Assert.equal(syncGUID, newAddon.syncGUID); +}); + +add_task(async function test_addon_manager_get_by_sync_guid() { + let addon = await AddonManager.getAddonByID(ADDONS[0].id); + Assert.notEqual(null, addon.syncGUID); + + let syncGUID = addon.syncGUID; + + let newAddon = await AddonManager.getAddonBySyncGUID(syncGUID); + Assert.notEqual(null, newAddon); + Assert.equal(addon.id, newAddon.id); + Assert.equal(syncGUID, newAddon.syncGUID); + + let missing = await AddonManager.getAddonBySyncGUID("DOES_NOT_EXIST"); + Assert.equal(undefined, missing); +}); |