|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that clicking the pretty print button prettifies the source. |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html"; |
|
9 |
|
10 let gTab, gDebuggee, gPanel, gDebugger; |
|
11 let gEditor, gSources; |
|
12 |
|
13 function test() { |
|
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
15 gTab = aTab; |
|
16 gDebuggee = aDebuggee; |
|
17 gPanel = aPanel; |
|
18 gDebugger = gPanel.panelWin; |
|
19 gEditor = gDebugger.DebuggerView.editor; |
|
20 gSources = gDebugger.DebuggerView.Sources; |
|
21 |
|
22 waitForSourceShown(gPanel, "code_ugly.js") |
|
23 .then(testSourceIsUgly) |
|
24 .then(() => { |
|
25 const finished = waitForSourceShown(gPanel, "code_ugly.js"); |
|
26 clickPrettyPrintButton(); |
|
27 testProgressBarShown(); |
|
28 return finished; |
|
29 }) |
|
30 .then(testSourceIsPretty) |
|
31 .then(testEditorShown) |
|
32 .then(testSourceIsStillPretty) |
|
33 .then(() => closeDebuggerAndFinish(gPanel)) |
|
34 .then(null, aError => { |
|
35 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError)); |
|
36 }); |
|
37 }); |
|
38 } |
|
39 |
|
40 function testSourceIsUgly() { |
|
41 ok(!gEditor.getText().contains("\n "), |
|
42 "The source shouldn't be pretty printed yet."); |
|
43 } |
|
44 |
|
45 function clickPrettyPrintButton() { |
|
46 gDebugger.document.getElementById("pretty-print").click(); |
|
47 } |
|
48 |
|
49 function testProgressBarShown() { |
|
50 const deck = gDebugger.document.getElementById("editor-deck"); |
|
51 is(deck.selectedIndex, 2, "The progress bar should be shown"); |
|
52 } |
|
53 |
|
54 function testSourceIsPretty() { |
|
55 ok(gEditor.getText().contains("\n "), |
|
56 "The source should be pretty printed.") |
|
57 } |
|
58 |
|
59 function testEditorShown() { |
|
60 const deck = gDebugger.document.getElementById("editor-deck"); |
|
61 is(deck.selectedIndex, 0, "The editor should be shown"); |
|
62 } |
|
63 |
|
64 function testSourceIsStillPretty() { |
|
65 const deferred = promise.defer(); |
|
66 |
|
67 const { source } = gSources.selectedItem.attachment; |
|
68 gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => { |
|
69 ok(text.contains("\n "), |
|
70 "Subsequent calls to getText return the pretty printed source."); |
|
71 deferred.resolve(); |
|
72 }); |
|
73 |
|
74 return deferred.promise; |
|
75 } |
|
76 |
|
77 registerCleanupFunction(function() { |
|
78 gTab = null; |
|
79 gDebuggee = null; |
|
80 gPanel = null; |
|
81 gDebugger = null; |
|
82 gEditor = null; |
|
83 gSources = null; |
|
84 }); |