toolkit/devtools/server/tests/unit/test_breakpoint-12.js

branch
TOR_BUG_3246
changeset 7
129ffea94266
equal deleted inserted replaced
-1:000000000000 0:331634aaca6a
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Make sure that setting a breakpoint twice in a line without bytecodes works
6 * as expected.
7 */
8
9 const NUM_BREAKPOINTS = 10;
10 var gDebuggee;
11 var gClient;
12 var gThreadClient;
13 var gPath = getFilePath('test_breakpoint-12.js');
14 var gBpActor;
15 var gCount = 1;
16
17 function run_test()
18 {
19 initTestDebuggerServer();
20 gDebuggee = addTestGlobal("test-stack");
21 gClient = new DebuggerClient(DebuggerServer.connectPipe());
22 gClient.connect(function () {
23 attachTestTabAndResume(gClient, "test-stack", function (aResponse, aTabClient, aThreadClient) {
24 gThreadClient = aThreadClient;
25 test_child_skip_breakpoint();
26 });
27 });
28 do_test_pending();
29 }
30
31 function test_child_skip_breakpoint()
32 {
33 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
34 let location = { url: gPath, line: gDebuggee.line0 + 3};
35 gThreadClient.setBreakpoint(location, function (aResponse, bpClient) {
36 // Check that the breakpoint has properly skipped forward one line.
37 do_check_eq(aResponse.actualLocation.url, location.url);
38 do_check_eq(aResponse.actualLocation.line, location.line + 1);
39 gBpActor = aResponse.actor;
40
41 // Set more breakpoints at the same location.
42 set_breakpoints(location);
43 });
44
45 });
46
47 gDebuggee.eval("var line0 = Error().lineNumber;\n" +
48 "function foo() {\n" + // line0 + 1
49 " this.a = 1;\n" + // line0 + 2
50 " // A comment.\n" + // line0 + 3
51 " this.b = 2;\n" + // line0 + 4
52 "}\n" + // line0 + 5
53 "debugger;\n" + // line0 + 6
54 "foo();\n"); // line0 + 7
55 }
56
57 // Set many breakpoints at the same location.
58 function set_breakpoints(location) {
59 do_check_neq(gCount, NUM_BREAKPOINTS);
60 gThreadClient.setBreakpoint(location, function (aResponse, bpClient) {
61 // Check that the breakpoint has properly skipped forward one line.
62 do_check_eq(aResponse.actualLocation.url, location.url);
63 do_check_eq(aResponse.actualLocation.line, location.line + 1);
64 // Check that the same breakpoint actor was returned.
65 do_check_eq(aResponse.actor, gBpActor);
66
67 if (++gCount < NUM_BREAKPOINTS) {
68 set_breakpoints(location);
69 return;
70 }
71
72 // After setting all the breakpoints, check that only one has effectively
73 // remained.
74 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
75 // Check the return value.
76 do_check_eq(aPacket.type, "paused");
77 do_check_eq(aPacket.frame.where.url, gPath);
78 do_check_eq(aPacket.frame.where.line, location.line + 1);
79 do_check_eq(aPacket.why.type, "breakpoint");
80 do_check_eq(aPacket.why.actors[0], bpClient.actor);
81 // Check that the breakpoint worked.
82 do_check_eq(gDebuggee.a, 1);
83 do_check_eq(gDebuggee.b, undefined);
84
85 gThreadClient.addOneTimeListener("paused", function (aEvent, aPacket) {
86 // We don't expect any more pauses after the breakpoint was hit once.
87 do_check_true(false);
88 });
89 gThreadClient.resume(function () {
90 // Give any remaining breakpoints a chance to trigger.
91 do_timeout(1000, finishClient.bind(null, gClient));
92 });
93
94 });
95 // Continue until the breakpoint is hit.
96 gThreadClient.resume();
97 });
98
99 }

mercurial