browser_dbg-javascript-tracer-worker.js (1711B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */ 4 5 // Tests tracing web workers 6 7 "use strict"; 8 add_task(async function testTracingWorker() { 9 // We have to enable worker targets and disable this pref to have functional tracing for workers 10 await pushPref("dom.worker.console.dispatch_events_to_main_thread", false); 11 12 const dbg = await initDebugger("doc-scripts.html"); 13 14 // This test covers the Web Console, whereas it is no longer the default output 15 await toggleJsTracerMenuItem(dbg, "#jstracer-menu-item-console"); 16 17 info("Instantiate a worker"); 18 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 19 content.worker = new content.Worker("simple-worker.js"); 20 }); 21 22 await waitFor( 23 () => findAllElements(dbg, "threadsPaneItems").length == 2, 24 "Wait for the two threads to be displayed in the thread pane" 25 ); 26 const threadsEl = findAllElements(dbg, "threadsPaneItems"); 27 is(threadsEl.length, 2, "There are two threads in the thread panel"); 28 29 info("Enable tracing on all threads"); 30 await toggleJsTracer(dbg.toolbox); 31 32 // `timer` is called within the worker via a setInterval of 1 second 33 await hasConsoleMessage(dbg, "setIntervalCallback"); 34 await hasConsoleMessage(dbg, "λ timer"); 35 36 // Also verify that postMessage are traced 37 await SpecialPowers.spawn(gBrowser.selectedBrowser, [], async function () { 38 content.worker.postMessage("foo"); 39 }); 40 41 await hasConsoleMessage(dbg, "DOM | global.message"); 42 await hasConsoleMessage(dbg, "λ onmessage"); 43 44 await dbg.toolbox.closeToolbox(); 45 });