|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test that when we add 2 breakpoints to the same line at different columns and |
|
6 * then remove one of them, we don't remove them both. |
|
7 */ |
|
8 |
|
9 var gDebuggee; |
|
10 var gClient; |
|
11 var gThreadClient; |
|
12 |
|
13 function run_test() |
|
14 { |
|
15 initTestDebuggerServer(); |
|
16 gDebuggee = addTestGlobal("test-breakpoints"); |
|
17 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
18 gClient.connect(function() { |
|
19 attachTestTabAndResume(gClient, "test-breakpoints", function(aResponse, aTabClient, aThreadClient) { |
|
20 gThreadClient = aThreadClient; |
|
21 test_breakpoints_columns(); |
|
22 }); |
|
23 }); |
|
24 do_test_pending(); |
|
25 } |
|
26 |
|
27 const URL = "http://example.com/benderbendingrodriguez.js"; |
|
28 |
|
29 const code = |
|
30 "(" + function (global) { |
|
31 global.foo = function () { |
|
32 Math.abs(-1); Math.log(0.5); |
|
33 debugger; |
|
34 }; |
|
35 debugger; |
|
36 } + "(this))"; |
|
37 |
|
38 const firstLocation = { |
|
39 url: URL, |
|
40 line: 3, |
|
41 column: 4 |
|
42 }; |
|
43 |
|
44 const secondLocation = { |
|
45 url: URL, |
|
46 line: 3, |
|
47 column: 18 |
|
48 }; |
|
49 |
|
50 function test_breakpoints_columns() { |
|
51 gClient.addOneTimeListener("paused", set_breakpoints); |
|
52 |
|
53 Components.utils.evalInSandbox(code, gDebuggee, "1.8", URL, 1); |
|
54 } |
|
55 |
|
56 function set_breakpoints() { |
|
57 let first, second; |
|
58 |
|
59 gThreadClient.setBreakpoint(firstLocation, function ({ error, actualLocation }, |
|
60 aBreakpointClient) { |
|
61 do_check_true(!error, "Should not get an error setting the breakpoint"); |
|
62 do_check_true(!actualLocation, "Should not get an actualLocation"); |
|
63 first = aBreakpointClient; |
|
64 |
|
65 gThreadClient.setBreakpoint(secondLocation, function ({ error, actualLocation }, |
|
66 aBreakpointClient) { |
|
67 do_check_true(!error, "Should not get an error setting the breakpoint"); |
|
68 do_check_true(!actualLocation, "Should not get an actualLocation"); |
|
69 second = aBreakpointClient; |
|
70 |
|
71 test_different_actors(first, second); |
|
72 }); |
|
73 }); |
|
74 } |
|
75 |
|
76 function test_different_actors(aFirst, aSecond) { |
|
77 do_check_neq(aFirst.actor, aSecond.actor, |
|
78 "Each breakpoint should have a different actor"); |
|
79 test_remove_one(aFirst, aSecond); |
|
80 } |
|
81 |
|
82 function test_remove_one(aFirst, aSecond) { |
|
83 aFirst.remove(function ({error}) { |
|
84 do_check_true(!error, "Should not get an error removing a breakpoint"); |
|
85 |
|
86 let hitSecond; |
|
87 gClient.addListener("paused", function _onPaused(aEvent, {why, frame}) { |
|
88 if (why.type == "breakpoint") { |
|
89 hitSecond = true; |
|
90 do_check_eq(why.actors.length, 1, |
|
91 "Should only be paused because of one breakpoint actor"); |
|
92 do_check_eq(why.actors[0], aSecond.actor, |
|
93 "Should be paused because of the correct breakpoint actor"); |
|
94 do_check_eq(frame.where.line, secondLocation.line, |
|
95 "Should be at the right line"); |
|
96 do_check_eq(frame.where.column, secondLocation.column, |
|
97 "Should be at the right column"); |
|
98 gThreadClient.resume(); |
|
99 return; |
|
100 } |
|
101 |
|
102 if (why.type == "debuggerStatement") { |
|
103 gClient.removeListener("paused", _onPaused); |
|
104 do_check_true(hitSecond, |
|
105 "We should still hit `second`, but not `first`."); |
|
106 |
|
107 finishClient(gClient); |
|
108 return; |
|
109 } |
|
110 |
|
111 do_check_true(false, "Should never get here"); |
|
112 }); |
|
113 |
|
114 gThreadClient.resume(() => gDebuggee.foo()); |
|
115 }); |
|
116 } |