diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /devtools/client/debugger/test/mochitest/browser_dbg-javascript-tracer-worker.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'devtools/client/debugger/test/mochitest/browser_dbg-javascript-tracer-worker.js')
-rw-r--r-- | devtools/client/debugger/test/mochitest/browser_dbg-javascript-tracer-worker.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/devtools/client/debugger/test/mochitest/browser_dbg-javascript-tracer-worker.js b/devtools/client/debugger/test/mochitest/browser_dbg-javascript-tracer-worker.js new file mode 100644 index 0000000000..cabcb1deb8 --- /dev/null +++ b/devtools/client/debugger/test/mochitest/browser_dbg-javascript-tracer-worker.js @@ -0,0 +1,63 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ + +// Tests tracing web workers + +"use strict"; +add_task(async function testTracingWorker() { + await pushPref("devtools.debugger.features.javascript-tracing", true); + + // We have to enable worker targets and disable this pref to have functional tracing for workers + await pushPref("dom.worker.console.dispatch_events_to_main_thread", false); + + const dbg = await initDebugger("doc-scripts.html"); + + info("Instantiate a worker"); + const { targetCommand } = dbg.toolbox.commands; + let onAvailable; + const onNewTarget = new Promise(resolve => { + onAvailable = ({ targetFront }) => { + resolve(targetFront); + }; + }); + await targetCommand.watchTargets({ + types: [targetCommand.TYPES.FRAME], + onAvailable, + }); + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { + content.worker = new content.Worker("simple-worker.js"); + }); + info("Wait for the worker target"); + const workerTarget = await onNewTarget; + + await waitFor( + () => findAllElements(dbg, "threadsPaneItems").length == 2, + "Wait for the two threads to be displayed in the thread pane" + ); + const threadsEl = findAllElements(dbg, "threadsPaneItems"); + is(threadsEl.length, 2, "There are two threads in the thread panel"); + + info("Enable tracing on all threads"); + await clickElement(dbg, "trace"); + info("Wait for tracing to be enabled for the worker"); + await waitForState(dbg, state => { + return dbg.selectors.getIsThreadCurrentlyTracing( + workerTarget.threadFront.actorID + ); + }); + + // `timer` is called within the worker via a setInterval of 1 second + await hasConsoleMessage(dbg, "setIntervalCallback"); + await hasConsoleMessage(dbg, "λ timer"); + + // Also verify that postMessage are traced + await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { + content.worker.postMessage("foo"); + }); + + await hasConsoleMessage(dbg, "DOM(message)"); + await hasConsoleMessage(dbg, "λ onmessage"); + + await dbg.toolbox.closeToolbox(); +}); |