summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/unit/test_actor-registry-actor.js
blob: 8b0abfbbb886322bb0097858647129b55f811d9b (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Check that you can register new actors via the ActorRegistrationActor.
 */

var gClient;
var gRegistryFront;
var gActorFront;
var gOldPref;

const { ActorRegistryFront } = require("devtools/shared/fronts/actor-registry");

function run_test()
{
  gOldPref = Services.prefs.getBoolPref("devtools.debugger.forbid-certified-apps");
  Services.prefs.setBoolPref("devtools.debugger.forbid-certified-apps", false);
  initTestDebuggerServer();
  DebuggerServer.addBrowserActors();
  gClient = new DebuggerClient(DebuggerServer.connectPipe());
  gClient.connect().then(getRegistry);
  do_test_pending();
}

function getRegistry() {
  gClient.listTabs((response) => {
    gRegistryFront = ActorRegistryFront(gClient, response);
    registerNewActor();
  });
}

function registerNewActor() {
  let options = {
    prefix: "helloActor",
    constructor: "HelloActor",
    type: { global: true }
  };

  gRegistryFront
    .registerActor("resource://test/hello-actor.js", options)
    .then(actorFront => gActorFront = actorFront)
    .then(talkToNewActor)
    .then(null, e => {
      DevToolsUtils.reportException("registerNewActor", e);
      do_check_true(false);
    });
}

function talkToNewActor() {
  gClient.listTabs(({ helloActor }) => {
    do_check_true(!!helloActor);
    gClient.request({
      to: helloActor,
      type: "hello"
    }, response => {
      do_check_true(!response.error);
      unregisterNewActor();
    });
  });
}

function unregisterNewActor() {
  gActorFront
    .unregister()
    .then(testActorIsUnregistered)
    .then(null, e => {
      DevToolsUtils.reportException("unregisterNewActor", e);
      do_check_true(false);
    });
}

function testActorIsUnregistered() {
  gClient.listTabs(({ helloActor }) => {
    do_check_true(!helloActor);

    Services.prefs.setBoolPref("devtools.debugger.forbid-certified-apps", gOldPref);
    finishClient(gClient);
  });
}