diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /devtools/server/tests/chrome/test_webextension-addon-debugging-reload.html | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/server/tests/chrome/test_webextension-addon-debugging-reload.html')
-rw-r--r-- | devtools/server/tests/chrome/test_webextension-addon-debugging-reload.html | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/devtools/server/tests/chrome/test_webextension-addon-debugging-reload.html b/devtools/server/tests/chrome/test_webextension-addon-debugging-reload.html new file mode 100644 index 0000000000..420cb0df5e --- /dev/null +++ b/devtools/server/tests/chrome/test_webextension-addon-debugging-reload.html @@ -0,0 +1,122 @@ +<!DOCTYPE HTML> +<html> +<!-- +Bug 1302702 - Test connect to a webextension addon +--> +<head> + <meta charset="utf-8"> + <title>Mozilla Bug</title> + <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> + <script src="webextension-helpers.js"></script> + <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"> +</head> +<body> +<pre id="test"> +<script type="application/javascript"> +"use strict"; + +// NOTE: This test installs the webextension addon using the addon manager, so that +// it can be reloaded using the same actor RDP method used by the developer tools. +add_task(async function test_webextension_addon_debugging_reload() { + const addonID = "test-webext-debugging-reload@test.mozilla.com"; + const addonFile = generateWebExtensionXPI({ + manifest: { + applications: { + gecko: {id: addonID}, + }, + background: { scripts: ["background.js"] }, + }, + files: { + "background.js": function() { + console.log("background page loaded"); + }, + }, + }); + + const {addon} = await promiseInstallFile(addonFile); + await promiseWebExtensionStartup(); + + const addonTarget = await attachAddon(addonID); + ok(addonTarget, "Got an addon target"); + + const matchBackgroundPageFrame = (data) => { + if (data.frames) { + const frameFound = data.frames.filter((frame) => { + return frame.url && frame.url.endsWith("_generated_background_page.html"); + }).pop(); + + return !!frameFound; + } + + return false; + }; + + const matchFrameSelected = (data) => { + return "selected" in data; + }; + + // Test the target addon actor reload behavior. + + let waitFramesUpdated = waitForFramesUpdated(addonTarget, matchBackgroundPageFrame); + let collectFrameSelected = collectFrameUpdates(addonTarget, matchFrameSelected); + + is(ExtensionParent.DebugUtils.debugBrowserPromises.size, 1, + "The expected number of debug browser has been created by the addon actor"); + + info("Reloading the target addon"); + reloadAddon(addonTarget, addonID); + await promiseWebExtensionStartup(); + + is(ExtensionParent.DebugUtils.debugBrowserPromises.size, 1, + "The number of debug browser has not been changed after an addon reload"); + + let frames = await waitFramesUpdated; + const selectedFrame = collectFrameSelected().pop(); + + is(selectedFrame.selected, frames[0].id, "The new background page has been selected"); + is(addonTarget.url, frames[0].url, + "The addon target has the url of the selected frame"); + + // Test the target addon actor once reloaded twice. + + waitFramesUpdated = waitForFramesUpdated(addonTarget, matchBackgroundPageFrame); + collectFrameSelected = collectFrameUpdates(addonTarget, matchFrameSelected); + + info("Reloading the target addon again"); + reloadAddon(addonTarget, addonID); + await promiseWebExtensionStartup(); + + frames = await waitFramesUpdated; + const newSelectedFrame = collectFrameSelected().pop(); + + ok(newSelectedFrame !== selectedFrame, + "The new selected frame is different from the previous on"); + is(newSelectedFrame.selected, frames[0].id, + "The new background page has been selected on the second reload"); + is(addonTarget.url, frames[0].url, + "The addon target has the url of the selected frame"); + + // Expect the target to be automatically closed when the addon + // is finally uninstalled. + + const {client} = addonTarget; + const waitDebuggingClientClosed = new Promise(resolve => { + addonTarget.once("close", resolve); + }); + + const waitShutdown = promiseWebExtensionShutdown(); + addon.uninstall(); + await waitShutdown; + + info("Waiting the addon target to be closed on addon uninstall"); + await waitDebuggingClientClosed; + + // Debugging client has to be closed explicitly when + // the target has been created as remote. + await client.close(); +}); + +</script> +</pre> +</body> +</html> |