michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Make sure that clicking the pretty print button prettifies the source, even michael@0: * when the source URL does not end in ".js", but the content type is michael@0: * JavaScript. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_pretty-print-3.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources; michael@0: michael@0: function test() { michael@0: initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { michael@0: gTab = aTab; michael@0: gDebuggee = aDebuggee; michael@0: gPanel = aPanel; michael@0: gDebugger = gPanel.panelWin; michael@0: gEditor = gDebugger.DebuggerView.editor; michael@0: gSources = gDebugger.DebuggerView.Sources; michael@0: michael@0: promise.all([waitForSourceShown(gPanel, "code_ugly-8"), michael@0: waitForEditorLocationSet(gPanel)]) michael@0: .then(testSourceIsUgly) michael@0: .then(() => { michael@0: const finished = waitForSourceShown(gPanel, "code_ugly-8"); michael@0: clickPrettyPrintButton(); michael@0: testProgressBarShown(); michael@0: return finished; michael@0: }) michael@0: .then(testSourceIsPretty) michael@0: .then(testEditorShown) michael@0: .then(testSourceIsStillPretty) michael@0: .then(() => closeDebuggerAndFinish(gPanel)) michael@0: .then(null, aError => { michael@0: ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError)); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function testSourceIsUgly() { michael@0: ok(!gEditor.getText().contains("\n "), michael@0: "The source shouldn't be pretty printed yet."); michael@0: } michael@0: michael@0: function clickPrettyPrintButton() { michael@0: gDebugger.document.getElementById("pretty-print").click(); michael@0: } michael@0: michael@0: function testProgressBarShown() { michael@0: const deck = gDebugger.document.getElementById("editor-deck"); michael@0: is(deck.selectedIndex, 2, "The progress bar should be shown"); michael@0: } michael@0: michael@0: function testSourceIsPretty() { michael@0: ok(gEditor.getText().contains("\n "), michael@0: "The source should be pretty printed.") michael@0: } michael@0: michael@0: function testEditorShown() { michael@0: const deck = gDebugger.document.getElementById("editor-deck"); michael@0: is(deck.selectedIndex, 0, "The editor should be shown"); michael@0: } michael@0: michael@0: function testSourceIsStillPretty() { michael@0: const deferred = promise.defer(); michael@0: michael@0: const { source } = gSources.selectedItem.attachment; michael@0: gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => { michael@0: ok(text.contains("\n "), michael@0: "Subsequent calls to getText return the pretty printed source."); michael@0: deferred.resolve(); michael@0: }); michael@0: michael@0: return deferred.promise; michael@0: } michael@0: michael@0: registerCleanupFunction(function() { michael@0: gTab = null; michael@0: gDebuggee = null; michael@0: gPanel = null; michael@0: gDebugger = null; michael@0: gEditor = null; michael@0: gSources = null; michael@0: });