diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /devtools/server/tests/xpcshell/test_addon_reload.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/xpcshell/test_addon_reload.js')
-rw-r--r-- | devtools/server/tests/xpcshell/test_addon_reload.js | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/devtools/server/tests/xpcshell/test_addon_reload.js b/devtools/server/tests/xpcshell/test_addon_reload.js new file mode 100644 index 0000000000..e0054f03cc --- /dev/null +++ b/devtools/server/tests/xpcshell/test_addon_reload.js @@ -0,0 +1,116 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { AddonManager } = ChromeUtils.importESModule( + "resource://gre/modules/AddonManager.sys.mjs" +); + +function promiseAddonEvent(event) { + return new Promise(resolve => { + const listener = { + [event](...args) { + AddonManager.removeAddonListener(listener); + resolve(args); + }, + }; + + AddonManager.addAddonListener(listener); + }); +} + +function promiseWebExtensionStartup() { + const { Management } = ChromeUtils.importESModule( + "resource://gre/modules/Extension.sys.mjs" + ); + + return new Promise(resolve => { + const listener = (evt, extension) => { + Management.off("ready", listener); + resolve(extension); + }; + + Management.on("ready", listener); + }); +} + +async function reloadAddon(addonFront) { + // The add-on will be re-installed after a successful reload. + const onInstalled = promiseAddonEvent("onInstalled"); + await addonFront.reload(); + await onInstalled; +} + +function getSupportFile(path) { + const allowMissing = false; + return do_get_file(path, allowMissing); +} + +add_task(async function testReloadExitedAddon() { + await startupAddonsManager(); + + DevToolsServer.init(); + DevToolsServer.registerAllActors(); + + const client = new DevToolsClient(DevToolsServer.connectPipe()); + await client.connect(); + + // Install our main add-on to trigger reloads on. + const addonFile = getSupportFile("addons/web-extension"); + const [installedAddon] = await Promise.all([ + AddonManager.installTemporaryAddon(addonFile), + promiseWebExtensionStartup(), + ]); + + // Install a decoy add-on. + const addonFile2 = getSupportFile("addons/web-extension2"); + const [installedAddon2] = await Promise.all([ + AddonManager.installTemporaryAddon(addonFile2), + promiseWebExtensionStartup(), + ]); + + const addonFront = await client.mainRoot.getAddon({ id: installedAddon.id }); + + await Promise.all([reloadAddon(addonFront), promiseWebExtensionStartup()]); + + // Uninstall the decoy add-on, which should cause its actor to exit. + const onUninstalled = promiseAddonEvent("onUninstalled"); + installedAddon2.uninstall(); + await onUninstalled; + + // Try to re-list all add-ons after a reload. + // This was throwing an exception because of the exited actor. + const newAddonFront = await client.mainRoot.getAddon({ + id: installedAddon.id, + }); + equal(newAddonFront.id, addonFront.id); + + // The fronts should be the same after the reload + equal(newAddonFront, addonFront); + + const onAddonListChanged = client.mainRoot.once("addonListChanged"); + + // Install an upgrade version of the first add-on. + const addonUpgradeFile = getSupportFile("addons/web-extension-upgrade"); + const [upgradedAddon] = await Promise.all([ + AddonManager.installTemporaryAddon(addonUpgradeFile), + promiseWebExtensionStartup(), + ]); + + // Waiting for addonListChanged unsolicited event + await onAddonListChanged; + + // re-list all add-ons after an upgrade. + const upgradedAddonFront = await client.mainRoot.getAddon({ + id: upgradedAddon.id, + }); + equal(upgradedAddonFront.id, addonFront.id); + // The fronts should be the same after the upgrade. + equal(upgradedAddonFront, addonFront); + + // The addon metadata has been updated. + equal(upgradedAddonFront.name, "Test Addons Actor Upgrade"); + + await close(client); +}); |