|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test basic black boxing. |
|
6 */ |
|
7 |
|
8 var gDebuggee; |
|
9 var gClient; |
|
10 var gThreadClient; |
|
11 |
|
12 function run_test() |
|
13 { |
|
14 initTestDebuggerServer(); |
|
15 gDebuggee = addTestGlobal("test-black-box"); |
|
16 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
17 gClient.connect(function() { |
|
18 attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) { |
|
19 gThreadClient = aThreadClient; |
|
20 test_black_box(); |
|
21 }); |
|
22 }); |
|
23 do_test_pending(); |
|
24 } |
|
25 |
|
26 const BLACK_BOXED_URL = "http://example.com/blackboxme.js"; |
|
27 const SOURCE_URL = "http://example.com/source.js"; |
|
28 |
|
29 function test_black_box() |
|
30 { |
|
31 gClient.addOneTimeListener("paused", function () { |
|
32 gThreadClient.setBreakpoint({ |
|
33 url: SOURCE_URL, |
|
34 line: 2 |
|
35 }, function (aResponse) { |
|
36 do_check_true(!aResponse.error, "Should be able to set breakpoint."); |
|
37 gThreadClient.resume(test_black_box_default); |
|
38 }); |
|
39 }); |
|
40 |
|
41 Components.utils.evalInSandbox( |
|
42 "" + function doStuff(k) { // line 1 |
|
43 let arg = 15; // line 2 - Step in here |
|
44 k(arg); // line 3 |
|
45 }, // line 4 |
|
46 gDebuggee, |
|
47 "1.8", |
|
48 BLACK_BOXED_URL, |
|
49 1 |
|
50 ); |
|
51 |
|
52 Components.utils.evalInSandbox( |
|
53 "" + function runTest() { // line 1 |
|
54 doStuff( // line 2 - Break here |
|
55 function (n) { // line 3 - Step through `doStuff` to here |
|
56 debugger; // line 5 |
|
57 } // line 6 |
|
58 ); // line 7 |
|
59 } // line 8 |
|
60 + "\n debugger;", // line 9 |
|
61 gDebuggee, |
|
62 "1.8", |
|
63 SOURCE_URL, |
|
64 1 |
|
65 ); |
|
66 } |
|
67 |
|
68 function test_black_box_default() { |
|
69 gThreadClient.getSources(function (aResponse) { |
|
70 do_check_true(!aResponse.error, "Should be able to get sources."); |
|
71 |
|
72 let sourceClient = gThreadClient.source( |
|
73 aResponse.sources.filter(s => s.url == BLACK_BOXED_URL)[0]); |
|
74 do_check_true(!sourceClient.isBlackBoxed, |
|
75 "By default the source is not black boxed."); |
|
76 |
|
77 // Test that we can step into `doStuff` when we are not black boxed. |
|
78 runTest( |
|
79 function onSteppedLocation(aLocation) { |
|
80 do_check_eq(aLocation.url, BLACK_BOXED_URL, |
|
81 "Should step into `doStuff`."); |
|
82 do_check_eq(aLocation.line, 2, |
|
83 "Should step into `doStuff`."); |
|
84 }, |
|
85 function onDebuggerStatementFrames(aFrames) { |
|
86 do_check_true(!aFrames.some(f => f.source.isBlackBoxed)); |
|
87 }, |
|
88 test_black_boxing.bind(null, sourceClient) |
|
89 ); |
|
90 }); |
|
91 } |
|
92 |
|
93 function test_black_boxing(aSourceClient) { |
|
94 aSourceClient.blackBox(function (aResponse) { |
|
95 do_check_true(!aResponse.error, "Should not get an error black boxing."); |
|
96 do_check_true(aSourceClient.isBlackBoxed, |
|
97 "The source client should report itself as black boxed correctly."); |
|
98 |
|
99 // Test that we step through `doStuff` when we are black boxed and its frame |
|
100 // doesn't show up. |
|
101 runTest( |
|
102 function onSteppedLocation(aLocation) { |
|
103 do_check_eq(aLocation.url, SOURCE_URL, |
|
104 "Should step through `doStuff`."); |
|
105 do_check_eq(aLocation.line, 3, |
|
106 "Should step through `doStuff`."); |
|
107 }, |
|
108 function onDebuggerStatementFrames(aFrames) { |
|
109 for (let f of aFrames) { |
|
110 if (f.where.url == BLACK_BOXED_URL) { |
|
111 do_check_true(f.source.isBlackBoxed, "Should be black boxed"); |
|
112 } else { |
|
113 do_check_true(!f.source.isBlackBoxed, "Should not be black boxed") |
|
114 } |
|
115 } |
|
116 }, |
|
117 test_unblack_boxing.bind(null, aSourceClient) |
|
118 ); |
|
119 }); |
|
120 } |
|
121 |
|
122 function test_unblack_boxing(aSourceClient) { |
|
123 aSourceClient.unblackBox(function (aResponse) { |
|
124 do_check_true(!aResponse.error, "Should not get an error un-black boxing"); |
|
125 do_check_true(!aSourceClient.isBlackBoxed, "The source is not black boxed."); |
|
126 |
|
127 // Test that we can step into `doStuff` again. |
|
128 runTest( |
|
129 function onSteppedLocation(aLocation) { |
|
130 do_check_eq(aLocation.url, BLACK_BOXED_URL, |
|
131 "Should step into `doStuff`."); |
|
132 do_check_eq(aLocation.line, 2, |
|
133 "Should step into `doStuff`."); |
|
134 }, |
|
135 function onDebuggerStatementFrames(aFrames) { |
|
136 do_check_true(!aFrames.some(f => f.source.isBlackBoxed)); |
|
137 }, |
|
138 finishClient.bind(null, gClient) |
|
139 ); |
|
140 }); |
|
141 } |
|
142 |
|
143 function runTest(aOnSteppedLocation, aOnDebuggerStatementFrames, aFinishedCallback) { |
|
144 gClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
145 do_check_eq(aPacket.why.type, "breakpoint"); |
|
146 gClient.addOneTimeListener("paused", function () { |
|
147 gClient.addOneTimeListener("paused", function () { |
|
148 getCurrentLocation(function (aLocation) { |
|
149 aOnSteppedLocation(aLocation); |
|
150 gClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
151 do_check_eq(aPacket.why.type, "debuggerStatement"); |
|
152 gThreadClient.getFrames(0, 100, function ({frames}) { |
|
153 aOnDebuggerStatementFrames(frames); |
|
154 gThreadClient.resume(aFinishedCallback); |
|
155 }); |
|
156 }); |
|
157 gThreadClient.resume(); |
|
158 }); |
|
159 }); |
|
160 gThreadClient.stepIn(); |
|
161 }); |
|
162 gThreadClient.stepIn(); |
|
163 }); |
|
164 |
|
165 gDebuggee.runTest(); |
|
166 } |
|
167 |
|
168 function getCurrentLocation(aCallback) { |
|
169 gThreadClient.getFrames(0, 1, function ({frames, error}) { |
|
170 do_check_true(!error, "Should not get an error: " + error); |
|
171 let [{where}] = frames; |
|
172 aCallback(where); |
|
173 }); |
|
174 } |