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 /dom/workers/test/browser_WorkerDebugger.initialize.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 'dom/workers/test/browser_WorkerDebugger.initialize.js')
-rw-r--r-- | dom/workers/test/browser_WorkerDebugger.initialize.js | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/dom/workers/test/browser_WorkerDebugger.initialize.js b/dom/workers/test/browser_WorkerDebugger.initialize.js new file mode 100644 index 0000000000..edc20af4e0 --- /dev/null +++ b/dom/workers/test/browser_WorkerDebugger.initialize.js @@ -0,0 +1,54 @@ +/* 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/. */ + +const wdm = Cc["@mozilla.org/dom/workers/workerdebuggermanager;1"].getService( + Ci.nsIWorkerDebuggerManager +); + +const BASE_URL = "chrome://mochitests/content/browser/dom/workers/test/"; +const WORKER_URL = BASE_URL + "WorkerDebugger.initialize_es_worker.js"; +const DEBUGGER_URL = + BASE_URL + "WorkerDebugger.initialize_debugger_es_worker.js"; + +add_task(async function test() { + const onDbg = waitForRegister(WORKER_URL); + const worker = new Worker(WORKER_URL, { type: "module" }); + + info("Wait for worker message"); + await new Promise(resolve => (worker.onmessage = resolve)); + + const dbg = await onDbg; + + info("Calling WorkerDebugger::Initialize"); + const onDebuggerScriptEvaluated = new Promise(resolve => { + const listener = { + onMessage(msg) { + is(msg, "debugger script ran"); + dbg.removeListener(listener); + resolve(); + }, + }; + dbg.addListener(listener); + }); + dbg.initialize(DEBUGGER_URL); + ok(true, "dbg.initialize didn't throw"); + + info("Waiting for debugger script to be evaluated and dispatching a message"); + await onDebuggerScriptEvaluated; +}); + +function waitForRegister(url, dbgUrl) { + return new Promise(function (resolve) { + wdm.addListener({ + onRegister(dbg) { + if (dbg.url !== url) { + return; + } + ok(true, "Debugger with url " + url + " should be registered."); + wdm.removeListener(this); + resolve(dbg); + }, + }); + }); +} |