summaryrefslogtreecommitdiffstats
path: root/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.sys.mjs
diff options
context:
space:
mode:
Diffstat (limited to 'toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.sys.mjs')
-rw-r--r--toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.sys.mjs62
1 files changed, 62 insertions, 0 deletions
diff --git a/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.sys.mjs b/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.sys.mjs
new file mode 100644
index 0000000000..907631dec1
--- /dev/null
+++ b/toolkit/components/extensions/test/xpcshell/data/TestWorkerWatcherChild.sys.mjs
@@ -0,0 +1,62 @@
+import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
+
+const lazy = {};
+
+XPCOMUtils.defineLazyServiceGetter(
+ lazy,
+ "wdm",
+ "@mozilla.org/dom/workers/workerdebuggermanager;1",
+ "nsIWorkerDebuggerManager"
+);
+
+export 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();
+ }
+}