Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5 * Make sure that clicking the pretty print button prettifies the source.
6 */
8 const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html";
10 let gTab, gDebuggee, gPanel, gDebugger;
11 let gEditor, gSources;
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;
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 }
40 function testSourceIsUgly() {
41 ok(!gEditor.getText().contains("\n "),
42 "The source shouldn't be pretty printed yet.");
43 }
45 function clickPrettyPrintButton() {
46 gDebugger.document.getElementById("pretty-print").click();
47 }
49 function testProgressBarShown() {
50 const deck = gDebugger.document.getElementById("editor-deck");
51 is(deck.selectedIndex, 2, "The progress bar should be shown");
52 }
54 function testSourceIsPretty() {
55 ok(gEditor.getText().contains("\n "),
56 "The source should be pretty printed.")
57 }
59 function testEditorShown() {
60 const deck = gDebugger.document.getElementById("editor-deck");
61 is(deck.selectedIndex, 0, "The editor should be shown");
62 }
64 function testSourceIsStillPretty() {
65 const deferred = promise.defer();
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 });
74 return deferred.promise;
75 }
77 registerCleanupFunction(function() {
78 gTab = null;
79 gDebuggee = null;
80 gPanel = null;
81 gDebugger = null;
82 gEditor = null;
83 gSources = null;
84 });