|
1 /* -*- Mode: javascript; js-indent-level: 2; -*- */ |
|
2 /* Any copyright is dedicated to the Public Domain. |
|
3 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
4 |
|
5 // Test stepping through pretty printed sources. |
|
6 |
|
7 let gTab, gDebuggee, gPanel, gClient, gThreadClient, gSource; |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html"; |
|
10 |
|
11 function test() { |
|
12 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
13 gTab = aTab; |
|
14 gDebuggee = aDebuggee; |
|
15 gPanel = aPanel; |
|
16 gClient = gPanel.panelWin.gClient; |
|
17 gThreadClient = gPanel.panelWin.DebuggerController.activeThread; |
|
18 |
|
19 gDebuggee.noop = x => x; |
|
20 findSource(); |
|
21 }); |
|
22 } |
|
23 |
|
24 let CODE_URL; |
|
25 |
|
26 const BP_LOCATION = { |
|
27 line: 5, |
|
28 column: 11 |
|
29 }; |
|
30 |
|
31 function findSource() { |
|
32 gThreadClient.getSources(({ error, sources }) => { |
|
33 ok(!error); |
|
34 sources = sources.filter(s => s.url.contains("code_ugly-3.js")); |
|
35 is(sources.length, 1); |
|
36 [gSource] = sources; |
|
37 CODE_URL = BP_LOCATION.url = gSource.url; |
|
38 |
|
39 prettyPrintSource(sources[0]); |
|
40 }); |
|
41 } |
|
42 |
|
43 function prettyPrintSource(source) { |
|
44 gThreadClient.source(gSource).prettyPrint(2, runCode); |
|
45 } |
|
46 |
|
47 function runCode({ error }) { |
|
48 ok(!error); |
|
49 gClient.addOneTimeListener("paused", testDbgStatement); |
|
50 gDebuggee.main3(); |
|
51 } |
|
52 |
|
53 function testDbgStatement(event, { why, frame }) { |
|
54 is(why.type, "debuggerStatement"); |
|
55 const { url, line, column } = frame.where; |
|
56 is(url, CODE_URL); |
|
57 is(line, 3); |
|
58 setBreakpoint(); |
|
59 } |
|
60 |
|
61 function setBreakpoint() { |
|
62 gThreadClient.setBreakpoint(BP_LOCATION, ({ error, actualLocation }) => { |
|
63 ok(!error); |
|
64 ok(!actualLocation); |
|
65 testStepping(); |
|
66 }); |
|
67 } |
|
68 |
|
69 function testStepping() { |
|
70 gClient.addOneTimeListener("paused", (event, { why, frame }) => { |
|
71 is(why.type, "resumeLimit"); |
|
72 const { url, line } = frame.where; |
|
73 is(url, CODE_URL); |
|
74 is(line, 4); |
|
75 testHitBreakpoint(); |
|
76 }); |
|
77 gThreadClient.stepIn(); |
|
78 } |
|
79 |
|
80 function testHitBreakpoint() { |
|
81 gClient.addOneTimeListener("paused", (event, { why, frame }) => { |
|
82 is(why.type, "breakpoint"); |
|
83 const { url, line } = frame.where; |
|
84 is(url, CODE_URL); |
|
85 is(line, BP_LOCATION.line); |
|
86 |
|
87 resumeDebuggerThenCloseAndFinish(gPanel); |
|
88 }); |
|
89 gThreadClient.resume(); |
|
90 } |
|
91 |
|
92 registerCleanupFunction(function() { |
|
93 gTab = gDebuggee = gPanel = gClient = gThreadClient = gSource = null; |
|
94 }); |