summaryrefslogtreecommitdiffstats
path: root/devtools/client/shared/sourceeditor/test/CodeMirrorTestActors.sys.mjs
blob: bb0457599b708bc206bf8fb372809ddc2bcb2206 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

let gCallback;

export class CodeMirrorTestParent extends JSWindowActorParent {
  static setCallback(callback) {
    gCallback = callback;
  }

  receiveMessage(message) {
    if (gCallback) {
      gCallback(message.name, message.data);
    }
  }
}

export class CodeMirrorTestChild extends JSWindowActorChild {
  handleEvent(event) {
    if (event.type == "DOMWindowCreated") {
      this.contentWindow.wrappedJSObject.mozilla_setStatus = (
        statusMsg,
        type,
        customMsg
      ) => {
        this.sendAsyncMessage("setStatus", {
          statusMsg,
          type,
          customMsg,
        });
      };

      this.check();
    }
  }

  check() {
    const doc = this.contentWindow.document;
    const out = doc.getElementById("status");
    if (!out || !out.classList.contains("done")) {
      this.contentWindow.setTimeout(() => this.check(), 100);
      return;
    }

    this.sendAsyncMessage("done", {
      failed: this.contentWindow.wrappedJSObject.failed,
    });
  }
}