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/client/webconsole/test/browser/browser_jsterm_await_paused.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.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/client/webconsole/test/browser/browser_jsterm_await_paused.js')
-rw-r--r-- | devtools/client/webconsole/test/browser/browser_jsterm_await_paused.js | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/devtools/client/webconsole/test/browser/browser_jsterm_await_paused.js b/devtools/client/webconsole/test/browser/browser_jsterm_await_paused.js new file mode 100644 index 0000000000..ef1604f9c7 --- /dev/null +++ b/devtools/client/webconsole/test/browser/browser_jsterm_await_paused.js @@ -0,0 +1,86 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ */ + +// Test that top-level await expression work as expected when debugger is paused. + +"use strict"; + +const TEST_URI = `data:text/html;charset=utf-8,<!DOCTYPE html>Web Console test top-level await when debugger paused`; + +add_task(async function () { + // Enable await mapping. + await pushPref("devtools.debugger.features.map-await-expression", true); + + // Force the split console to be closed. + await pushPref("devtools.toolbox.splitconsoleEnabled", false); + const hud = await openNewTabAndConsole(TEST_URI); + + const pauseExpression = `(() => { + var inPausedExpression = ["bar"]; + /* Will pause the script and open the debugger panel */ + debugger; + return "pauseExpression-res"; + })()`; + execute(hud, pauseExpression); + + // wait for the debugger to be opened and paused. + const toolbox = await gDevTools.getToolboxForTab(gBrowser.selectedTab); + + await waitFor(() => toolbox.getPanel("jsdebugger")); + const dbg = createDebuggerContext(toolbox); + await waitForPaused(dbg); + + await toolbox.openSplitConsole(); + + const awaitExpression = `await new Promise(res => { + const result = ["res", ...inPausedExpression]; + setTimeout(() => res(result), 2000); + console.log("awaitExpression executed"); + })`; + + const onAwaitResultMessage = waitForMessageByType( + hud, + `[ "res", "bar" ]`, + ".result" + ); + const onAwaitExpressionExecuted = waitForMessageByType( + hud, + "awaitExpression executed", + ".console-api" + ); + execute(hud, awaitExpression); + + // We send an evaluation just after the await one to ensure the await evaluation was + // done. We can't await on the previous execution because it waits for the result to + // be send, which won't happen until we resume the debugger. + await executeAndWaitForResultMessage(hud, `"smoke"`, `"smoke"`); + + // Give the engine some time to evaluate the await expression before resuming. + // Otherwise the awaitExpression may be evaluate while the thread is already resumed! + await onAwaitExpressionExecuted; + + // Click on the resume button to not be paused anymore. + await resume(dbg); + + info("Wait for the paused expression result to be displayed"); + await waitFor(() => findEvaluationResultMessage(hud, "pauseExpression-res")); + + await onAwaitResultMessage; + const messages = hud.ui.outputNode.querySelectorAll( + ".message.result .message-body" + ); + const messagesText = Array.from(messages).map(n => n.textContent); + const expectedMessages = [ + // Result of "smoke" + `"smoke"`, + // The result of pauseExpression (after smoke since pauseExpression iife was paused) + `"pauseExpression-res"`, + // Result of await + `Array [ "res", "bar" ]`, + ]; + Assert.deepEqual( + messagesText, + expectedMessages, + "The output contains the the expected messages, in the expected order" + ); +}); |