browser_dbg-browser-toolbox-workers.js (3051B)
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 // Test that all kinds of workers show up properly in the multiprocess browser 6 // toolbox. 7 8 "use strict"; 9 10 requestLongerTimeout(4); 11 12 Services.scriptloader.loadSubScript( 13 "chrome://mochitests/content/browser/devtools/client/framework/browser-toolbox/test/helpers-browser-toolbox.js", 14 this 15 ); 16 const WORKER_ESM = 17 "chrome://mochitests/content/browser/devtools/client/debugger/test/mochitest/examples/worker-esm.mjs"; 18 19 add_task(async function () { 20 await pushPref("devtools.browsertoolbox.scope", "everything"); 21 await pushPref("dom.serviceWorkers.enabled", true); 22 await pushPref("dom.serviceWorkers.testing.enabled", true); 23 24 const ToolboxTask = await initBrowserToolboxTask(); 25 await ToolboxTask.spawn(selectors, () => { 26 const { 27 LocalizationHelper, 28 } = require("resource://devtools/shared/l10n.js"); 29 // We have to expose this symbol as global for waitForSelectedSource 30 this.DEBUGGER_L10N = new LocalizationHelper( 31 "devtools/client/locales/debugger.properties" 32 ); 33 }); 34 await ToolboxTask.importFunctions({ 35 waitUntil, 36 waitForAllTargetsToBeAttached, 37 createDebuggerContext, 38 isWasmBinarySource, 39 DEBUGGER_L10N, 40 waitForState, 41 waitForSelectedSource, 42 createLocation, 43 getUnicodeUrlPath, 44 findSource, 45 selectSource, 46 assertTextContentOnLine, 47 getEditorContent, 48 getCMEditor, 49 }); 50 51 await addTab(`${EXAMPLE_URL}doc-all-workers.html`); 52 53 globalThis.worker = new ChromeWorker(WORKER_ESM, { type: "module" }); 54 55 await ToolboxTask.spawn(null, async () => { 56 /* global gToolbox */ 57 await gToolbox.selectTool("jsdebugger"); 58 59 const dbg = createDebuggerContext(gToolbox); 60 61 await waitUntil(() => { 62 const threads = dbg.selectors.getThreads(); 63 function hasWorker(workerName) { 64 // eslint-disable-next-line max-nested-callbacks 65 return threads.some(({ name }) => name == workerName); 66 } 67 return ( 68 hasWorker("simple-worker.js") && 69 hasWorker("shared-worker.js") && 70 hasWorker("service-worker.sjs") && 71 hasWorker("worker-esm.mjs") 72 ); 73 }); 74 75 await waitForAllTargetsToBeAttached(gToolbox.commands.targetCommand); 76 77 await waitUntil(() => findSource(dbg, "worker-esm.mjs", { silent: true })); 78 await selectSource(dbg, "worker-esm.mjs"); 79 assertTextContentOnLine( 80 dbg, 81 7, 82 'console.log("Worker ESM main script", foo);' 83 ); 84 await waitUntil(() => 85 findSource(dbg, "worker-esm-dep.mjs", { silent: true }) 86 ); 87 await selectSource(dbg, "worker-esm-dep.mjs"); 88 assertTextContentOnLine(dbg, 1, 'console.log("Worker ESM dependency");'); 89 }); 90 ok(true, "All workers appear in browser toolbox debugger"); 91 92 globalThis.worker.terminate(); 93 delete globalThis.worker; 94 95 invokeInTab("unregisterServiceWorker"); 96 97 await ToolboxTask.destroy(); 98 });