|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test that we can black box source mapped sources. |
|
6 */ |
|
7 |
|
8 var gDebuggee; |
|
9 var gClient; |
|
10 var gThreadClient; |
|
11 |
|
12 Components.utils.import('resource:///modules/devtools/SourceMap.jsm'); |
|
13 |
|
14 function run_test() |
|
15 { |
|
16 initTestDebuggerServer(); |
|
17 gDebuggee = addTestGlobal("test-black-box"); |
|
18 gClient = new DebuggerClient(DebuggerServer.connectPipe()); |
|
19 gClient.connect(function() { |
|
20 attachTestTabAndResume(gClient, "test-black-box", function(aResponse, aTabClient, aThreadClient) { |
|
21 gThreadClient = aThreadClient; |
|
22 |
|
23 promise.resolve(setup_code()) |
|
24 .then(black_box_code) |
|
25 .then(run_code) |
|
26 .then(test_correct_location) |
|
27 .then(null, function (error) { |
|
28 do_check_true(false, "Should not get an error, got " + error); |
|
29 }) |
|
30 .then(function () { |
|
31 finishClient(gClient); |
|
32 }); |
|
33 }); |
|
34 }); |
|
35 do_test_pending(); |
|
36 } |
|
37 |
|
38 function setup_code() { |
|
39 let { code, map } = (new SourceNode(null, null, null, [ |
|
40 new SourceNode(1, 0, "a.js", "" + function a() { |
|
41 return b(); |
|
42 }), |
|
43 "\n", |
|
44 new SourceNode(1, 0, "b.js", "" + function b() { |
|
45 debugger; // Don't want to stop here. |
|
46 return c(); |
|
47 }), |
|
48 "\n", |
|
49 new SourceNode(1, 0, "c.js", "" + function c() { |
|
50 debugger; // Want to stop here. |
|
51 }), |
|
52 "\n" |
|
53 ])).toStringWithSourceMap({ |
|
54 file: "abc.js", |
|
55 sourceRoot: "http://example.com/" |
|
56 }); |
|
57 |
|
58 code += "//# sourceMappingURL=data:text/json," + map.toString(); |
|
59 |
|
60 Components.utils.evalInSandbox(code, |
|
61 gDebuggee, |
|
62 "1.8", |
|
63 "http://example.com/abc.js"); |
|
64 } |
|
65 |
|
66 function black_box_code() { |
|
67 const d = promise.defer(); |
|
68 |
|
69 gThreadClient.getSources(function ({ sources, error }) { |
|
70 do_check_true(!error, "Shouldn't get an error getting sources"); |
|
71 const source = sources.filter((s) => { |
|
72 return s.url.indexOf("b.js") !== -1; |
|
73 })[0]; |
|
74 do_check_true(!!source, "We should have our source in the sources list"); |
|
75 |
|
76 gThreadClient.source(source).blackBox(function ({ error }) { |
|
77 do_check_true(!error, "Should not get an error black boxing"); |
|
78 d.resolve(true); |
|
79 }); |
|
80 }); |
|
81 |
|
82 return d.promise; |
|
83 } |
|
84 |
|
85 function run_code() { |
|
86 const d = promise.defer(); |
|
87 |
|
88 gClient.addOneTimeListener("paused", function (aEvent, aPacket) { |
|
89 d.resolve(aPacket); |
|
90 gThreadClient.resume(); |
|
91 }); |
|
92 gDebuggee.a(); |
|
93 |
|
94 return d.promise; |
|
95 } |
|
96 |
|
97 function test_correct_location(aPacket) { |
|
98 do_check_eq(aPacket.why.type, "debuggerStatement", |
|
99 "Should hit a debugger statement."); |
|
100 do_check_eq(aPacket.frame.where.url, "http://example.com/c.js", |
|
101 "Should have skipped over the debugger statement in the black boxed source"); |
|
102 } |