summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm')
-rw-r--r--toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm68
1 files changed, 68 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm b/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm
new file mode 100644
index 0000000000..47120687e0
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.jsm
@@ -0,0 +1,68 @@
+"use strict";
+
+var EXPORTED_SYMBOLS = ["TestWorkerWatcherChild"];
+
+const { XPCOMUtils } = ChromeUtils.importESModule(
+ "resource://gre/modules/XPCOMUtils.sys.mjs"
+);
+
+const lazy = {};
+
+XPCOMUtils.defineLazyServiceGetter(
+ lazy,
+ "wdm",
+ "@mozilla.org/dom/workers/workerdebuggermanager;1",
+ "nsIWorkerDebuggerManager"
+);
+
+class TestWorkerWatcherChild extends JSProcessActorChild {
+ async receiveMessage(msg) {
+ switch (msg.name) {
+ case "Test:StartWatchingWorkers":
+ this.startWatchingWorkers();
+ break;
+ case "Test:StopWatchingWorkers":
+ this.stopWatchingWorkers();
+ break;
+ default:
+ // Ensure the test case will fail if this JSProcessActorChild does receive
+ // unexpected messages.
+ return Promise.reject(
+ new Error(`Unexpected message received: ${msg.name}`)
+ );
+ }
+ }
+
+ startWatchingWorkers() {
+ if (!this._workerDebuggerListener) {
+ const actor = this;
+ this._workerDebuggerListener = {
+ onRegister(dbg) {
+ actor.sendAsyncMessage("Test:WorkerSpawned", {
+ workerType: dbg.type,
+ workerUrl: dbg.url,
+ });
+ },
+ onUnregister(dbg) {
+ actor.sendAsyncMessage("Test:WorkerTerminated", {
+ workerType: dbg.type,
+ workerUrl: dbg.url,
+ });
+ },
+ };
+
+ lazy.wdm.addListener(this._workerDebuggerListener);
+ }
+ }
+
+ stopWatchingWorkers() {
+ if (this._workerDebuggerListener) {
+ lazy.wdm.removeListener(this._workerDebuggerListener);
+ this._workerDebuggerListener = null;
+ }
+ }
+
+ willDestroy() {
+ this.stopWatchingWorkers();
+ }
+}