summaryrefslogtreecommitdiffstats
path: root/devtools/server/tests/unit/test_dbgglobal.js
blob: ff429193208f99b4f1b443767c4af01dce5e4552 (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
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

function run_test()
{
  // Should get an exception if we try to interact with DebuggerServer
  // before we initialize it...
  check_except(function () {
    DebuggerServer.createListener();
  });
  check_except(DebuggerServer.closeAllListeners);
  check_except(DebuggerServer.connectPipe);

  // Allow incoming connections.
  DebuggerServer.init();

  // These should still fail because we haven't added a createRootActor
  // implementation yet.
  check_except(function () {
    DebuggerServer.createListener();
  });
  check_except(DebuggerServer.closeAllListeners);
  check_except(DebuggerServer.connectPipe);

  DebuggerServer.registerModule("xpcshell-test/testactors");

  // Now they should work.
  DebuggerServer.createListener();
  DebuggerServer.closeAllListeners();

  // Make sure we got the test's root actor all set up.
  let client1 = DebuggerServer.connectPipe();
  client1.hooks = {
    onPacket: function (aPacket1) {
      do_check_eq(aPacket1.from, "root");
      do_check_eq(aPacket1.applicationType, "xpcshell-tests");

      // Spin up a second connection, make sure it has its own root
      // actor.
      let client2 = DebuggerServer.connectPipe();
      client2.hooks = {
        onPacket: function (aPacket2) {
          do_check_eq(aPacket2.from, "root");
          do_check_neq(aPacket1.testConnectionPrefix,
                       aPacket2.testConnectionPrefix);
          client2.close();
        },
        onClosed: function (aResult) {
          client1.close();
        },
      };
      client2.ready();
    },

    onClosed: function (aResult) {
      do_test_finished();
    },
  };

  client1.ready();
  do_test_pending();
}