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: * Test that auto pretty printing doesn't accidentally toggle michael@0: * pretty printing off when we switch to a minified source michael@0: * that is already pretty printed. michael@0: */ michael@0: michael@0: const TAB_URL = EXAMPLE_URL + "doc_auto-pretty-print-02.html"; michael@0: michael@0: let gTab, gDebuggee, gPanel, gDebugger; michael@0: let gEditor, gSources, gPrefs, gOptions, gView; michael@0: michael@0: let gFirstSourceLabel = "code_ugly-6.js"; michael@0: let gSecondSourceLabel = "code_ugly-7.js"; michael@0: michael@0: let gOriginalPref = Services.prefs.getBoolPref("devtools.debugger.auto-pretty-print"); michael@0: Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true); 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: gPrefs = gDebugger.Prefs; michael@0: gOptions = gDebugger.DebuggerView.Options; michael@0: gView = gDebugger.DebuggerView; michael@0: michael@0: // Should be on by default. michael@0: testAutoPrettyPrintOn(); michael@0: michael@0: waitForSourceShown(gPanel, gFirstSourceLabel) michael@0: .then(testSourceIsUgly) michael@0: .then(() => waitForSourceShown(gPanel, gFirstSourceLabel)) michael@0: .then(testSourceIsPretty) michael@0: .then(testPrettyPrintButtonOn) michael@0: .then(() => { michael@0: // Switch to the second source. michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); michael@0: gSources.selectedIndex = 1; michael@0: return finished; michael@0: }) michael@0: .then(testSecondSourceLabel) michael@0: .then(() => { michael@0: // Switch back to first source. michael@0: let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); michael@0: gSources.selectedIndex = 0; michael@0: return finished; michael@0: }) michael@0: .then(testFirstSourceLabel) michael@0: .then(testPrettyPrintButtonOn) michael@0: // Disable auto pretty printing so it does not affect the following tests. michael@0: .then(disableAutoPrettyPrint) 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 testFirstSourceLabel(){ michael@0: ok(gSources.containsValue(EXAMPLE_URL + gFirstSourceLabel), michael@0: "First source url is correct."); michael@0: } michael@0: michael@0: function testSecondSourceLabel(){ michael@0: ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel), michael@0: "Second source url is correct."); michael@0: } michael@0: michael@0: function testAutoPrettyPrintOn(){ michael@0: is(gPrefs.autoPrettyPrint, true, michael@0: "The auto-pretty-print pref should be on."); michael@0: is(gOptions._autoPrettyPrint.getAttribute("checked"), "true", michael@0: "The Auto pretty print menu item should be checked."); michael@0: } michael@0: michael@0: function testPrettyPrintButtonOn(){ michael@0: is(gDebugger.document.getElementById("pretty-print").checked, true, michael@0: "The button should be checked when the source is selected."); michael@0: } michael@0: michael@0: function disableAutoPrettyPrint(){ michael@0: gOptions._autoPrettyPrint.setAttribute("checked", "false"); michael@0: gOptions._toggleAutoPrettyPrint(); michael@0: gOptions._onPopupHidden(); 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: 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: gOptions = null; michael@0: gPrefs = null; michael@0: gView = null; michael@0: Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref); michael@0: });