|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 Cu.import("resource://gre/modules/devtools/dbg-server.jsm"); |
|
5 Cu.import("resource://gre/modules/devtools/dbg-client.jsm"); |
|
6 |
|
7 var gClient; |
|
8 var gDebuggee; |
|
9 |
|
10 const xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); |
|
11 |
|
12 function run_test() |
|
13 { |
|
14 initTestDebuggerServer(); |
|
15 gDebuggee = testGlobal("test-1"); |
|
16 DebuggerServer.addTestGlobal(gDebuggee); |
|
17 |
|
18 let transport = DebuggerServer.connectPipe(); |
|
19 gClient = new DebuggerClient(transport); |
|
20 gClient.addListener("connected", function(aEvent, aType, aTraits) { |
|
21 gClient.listTabs((aResponse) => { |
|
22 do_check_true('tabs' in aResponse); |
|
23 for (let tab of aResponse.tabs) { |
|
24 if (tab.title == "test-1") { |
|
25 test_attach_tab(tab.actor); |
|
26 return false; |
|
27 } |
|
28 } |
|
29 do_check_true(false); // We should have found our tab in the list. |
|
30 return undefined; |
|
31 }); |
|
32 }); |
|
33 |
|
34 gClient.connect(); |
|
35 |
|
36 do_test_pending(); |
|
37 } |
|
38 |
|
39 // Attach to |aTabActor|, and check the response. |
|
40 function test_attach_tab(aTabActor) |
|
41 { |
|
42 gClient.request({ to: aTabActor, type: "attach" }, function(aResponse) { |
|
43 do_check_false("error" in aResponse); |
|
44 do_check_eq(aResponse.from, aTabActor); |
|
45 do_check_eq(aResponse.type, "tabAttached"); |
|
46 do_check_true(typeof aResponse.threadActor === "string"); |
|
47 |
|
48 test_attach_thread(aResponse.threadActor); |
|
49 }); |
|
50 } |
|
51 |
|
52 // Attach to |aThreadActor|, check the response, and resume it. |
|
53 function test_attach_thread(aThreadActor) |
|
54 { |
|
55 gClient.request({ to: aThreadActor, type: "attach" }, function(aResponse) { |
|
56 do_check_false("error" in aResponse); |
|
57 do_check_eq(aResponse.from, aThreadActor); |
|
58 do_check_eq(aResponse.type, "paused"); |
|
59 do_check_true("why" in aResponse); |
|
60 do_check_eq(aResponse.why.type, "attached"); |
|
61 |
|
62 test_resume_thread(aThreadActor); |
|
63 }); |
|
64 } |
|
65 |
|
66 // Resume |aThreadActor|, and see that it stops at the 'debugger' |
|
67 // statement. |
|
68 function test_resume_thread(aThreadActor) |
|
69 { |
|
70 // Allow the client to resume execution. |
|
71 gClient.request({ to: aThreadActor, type: "resume" }, function (aResponse) { |
|
72 do_check_false("error" in aResponse); |
|
73 do_check_eq(aResponse.from, aThreadActor); |
|
74 do_check_eq(aResponse.type, "resumed"); |
|
75 |
|
76 do_check_eq(xpcInspector.eventLoopNestLevel, 0); |
|
77 |
|
78 // Now that we know we're resumed, we can make the debuggee do something. |
|
79 Cu.evalInSandbox("var a = true; var b = false; debugger; var b = true;", gDebuggee); |
|
80 // Now make sure that we've run the code after the debugger statement... |
|
81 do_check_true(gDebuggee.b); |
|
82 }); |
|
83 |
|
84 gClient.addListener("paused", function(aName, aPacket) { |
|
85 do_check_eq(aName, "paused"); |
|
86 do_check_false("error" in aPacket); |
|
87 do_check_eq(aPacket.from, aThreadActor); |
|
88 do_check_eq(aPacket.type, "paused"); |
|
89 do_check_true("actor" in aPacket); |
|
90 do_check_true("why" in aPacket) |
|
91 do_check_eq(aPacket.why.type, "debuggerStatement"); |
|
92 |
|
93 // Reach around the protocol to check that the debuggee is in the state |
|
94 // we expect. |
|
95 do_check_true(gDebuggee.a); |
|
96 do_check_false(gDebuggee.b); |
|
97 |
|
98 do_check_eq(xpcInspector.eventLoopNestLevel, 1); |
|
99 |
|
100 // Let the debuggee continue execution. |
|
101 gClient.request({ to: aThreadActor, type: "resume" }, cleanup); |
|
102 }); |
|
103 } |
|
104 |
|
105 function cleanup() |
|
106 { |
|
107 gClient.addListener("closed", function(aEvent, aResult) { |
|
108 do_test_finished(); |
|
109 }); |
|
110 |
|
111 try { |
|
112 let xpcInspector = Cc["@mozilla.org/jsinspector;1"].getService(Ci.nsIJSInspector); |
|
113 do_check_eq(xpcInspector.eventLoopNestLevel, 0); |
|
114 } catch(e) { |
|
115 dump(e); |
|
116 } |
|
117 |
|
118 gClient.close(); |
|
119 } |