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