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