|
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 pretty printing source mapped sources. |
|
6 |
|
7 var gDebuggee; |
|
8 var gClient; |
|
9 var gThreadClient; |
|
10 var gSource; |
|
11 |
|
12 let gTab, gDebuggee, gPanel, gClient, gThreadClient, gSource; |
|
13 |
|
14 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html"; |
|
15 |
|
16 function test() { |
|
17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
18 gTab = aTab; |
|
19 gDebuggee = aDebuggee; |
|
20 gPanel = aPanel; |
|
21 gClient = gPanel.panelWin.gClient; |
|
22 gThreadClient = gPanel.panelWin.DebuggerController.activeThread; |
|
23 |
|
24 findSource(); |
|
25 }); |
|
26 } |
|
27 |
|
28 const dataUrl = s => "data:text/javascript," + s; |
|
29 |
|
30 // These should match the instructions in code_ugly-4.js. |
|
31 const A = "function a(){b()}"; |
|
32 const A_URL = dataUrl(A); |
|
33 const B = "function b(){debugger}"; |
|
34 const B_URL = dataUrl(B); |
|
35 |
|
36 function findSource() { |
|
37 gThreadClient.getSources(({ error, sources }) => { |
|
38 ok(!error); |
|
39 sources = sources.filter(s => s.url === B_URL); |
|
40 is(sources.length, 1); |
|
41 gSource = sources[0]; |
|
42 prettyPrint(); |
|
43 }); |
|
44 } |
|
45 |
|
46 function prettyPrint() { |
|
47 gThreadClient.source(gSource).prettyPrint(2, runCode); |
|
48 } |
|
49 |
|
50 function runCode({ error }) { |
|
51 ok(!error); |
|
52 gClient.addOneTimeListener("paused", testDbgStatement); |
|
53 gDebuggee.a(); |
|
54 } |
|
55 |
|
56 function testDbgStatement(event, { frame, why }) { |
|
57 is(why.type, "debuggerStatement"); |
|
58 const { url, line } = frame.where; |
|
59 is(url, B_URL); |
|
60 is(line, 2); |
|
61 |
|
62 disablePrettyPrint(); |
|
63 } |
|
64 |
|
65 function disablePrettyPrint() { |
|
66 gThreadClient.source(gSource).disablePrettyPrint(testUgly); |
|
67 } |
|
68 |
|
69 function testUgly({ error, source }) { |
|
70 ok(!error); |
|
71 ok(!source.contains("\n ")); |
|
72 getFrame(); |
|
73 } |
|
74 |
|
75 function getFrame() { |
|
76 gThreadClient.getFrames(0, 1, testFrame); |
|
77 } |
|
78 |
|
79 function testFrame({ frames: [frame] }) { |
|
80 const { url, line } = frame.where; |
|
81 is(url, B_URL); |
|
82 is(line, 1); |
|
83 |
|
84 resumeDebuggerThenCloseAndFinish(gPanel); |
|
85 } |
|
86 |
|
87 registerCleanupFunction(function() { |
|
88 gTab = gDebuggee = gPanel = gClient = gThreadClient = null; |
|
89 }); |