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

/**
 * Test that reattaching to a previously detached thread works.
 */

var gClient, gDebuggee, gThreadClient, gTabClient;

function run_test()
{
  initTestDebuggerServer();
  gDebuggee = testGlobal("test-reattach");
  DebuggerServer.addTestGlobal(gDebuggee);

  let transport = DebuggerServer.connectPipe();
  gClient = new DebuggerClient(transport);
  gClient.connect().then(() => {
    attachTestTab(gClient, "test-reattach", (aReply, aTabClient) => {
      gTabClient = aTabClient;
      test_attach();
    });
  });
  do_test_pending();
}

function test_attach()
{
  gTabClient.attachThread({}, (aResponse, aThreadClient) => {
    do_check_eq(aThreadClient.state, "paused");
    gThreadClient = aThreadClient;
    aThreadClient.resume(test_detach);
  });
}

function test_detach()
{
  gThreadClient.detach(() => {
    do_check_eq(gThreadClient.state, "detached");
    do_check_eq(gTabClient.thread, null);
    test_reattach();
  });
}

function test_reattach()
{
  gTabClient.attachThread({}, (aResponse, aThreadClient) => {
    do_check_neq(gThreadClient, aThreadClient);
    do_check_eq(aThreadClient.state, "paused");
    do_check_eq(gTabClient.thread, aThreadClient);
    aThreadClient.resume(cleanup);
  });
}

function cleanup()
{
  gClient.close().then(do_test_finished);
}