1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_auto-pretty-print-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,111 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Test auto pretty printing. 1.8 + 1.9 +const TAB_URL = EXAMPLE_URL + "doc_auto-pretty-print-01.html"; 1.10 + 1.11 +let gTab, gDebuggee, gPanel, gDebugger; 1.12 +let gEditor, gSources, gPrefs, gOptions, gView; 1.13 + 1.14 +let gFirstSourceLabel = "code_ugly-5.js"; 1.15 +let gSecondSourceLabel = "code_ugly-6.js"; 1.16 + 1.17 +let gOriginalPref = Services.prefs.getBoolPref("devtools.debugger.auto-pretty-print"); 1.18 +Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true); 1.19 + 1.20 +function test(){ 1.21 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.22 + gTab = aTab; 1.23 + gDebuggee = aDebuggee; 1.24 + gPanel = aPanel; 1.25 + gDebugger = gPanel.panelWin; 1.26 + gEditor = gDebugger.DebuggerView.editor; 1.27 + gSources = gDebugger.DebuggerView.Sources; 1.28 + gPrefs = gDebugger.Prefs; 1.29 + gOptions = gDebugger.DebuggerView.Options; 1.30 + gView = gDebugger.DebuggerView; 1.31 + 1.32 + // Should be on by default. 1.33 + testAutoPrettyPrintOn(); 1.34 + 1.35 + waitForSourceShown(gPanel, gFirstSourceLabel) 1.36 + .then(testSourceIsUgly) 1.37 + .then(() => waitForSourceShown(gPanel, gFirstSourceLabel)) 1.38 + .then(testSourceIsPretty) 1.39 + .then(disableAutoPrettyPrint) 1.40 + .then(testAutoPrettyPrintOff) 1.41 + .then(() => { 1.42 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN); 1.43 + gSources.selectedIndex = 1; 1.44 + return finished; 1.45 + }) 1.46 + .then(testSecondSourceLabel) 1.47 + .then(testSourceIsUgly) 1.48 + // Re-enable auto pretty printing for browser_dbg_auto-pretty-print-02.js 1.49 + .then(enableAutoPrettyPrint) 1.50 + .then(() => closeDebuggerAndFinish(gPanel)) 1.51 + .then(null, aError => { 1.52 + ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError)); 1.53 + }) 1.54 + }); 1.55 +} 1.56 + 1.57 +function testSourceIsUgly() { 1.58 + ok(!gEditor.getText().contains("\n "), 1.59 + "The source shouldn't be pretty printed yet."); 1.60 +} 1.61 + 1.62 +function testSecondSourceLabel(){ 1.63 + ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel), 1.64 + "Second source url is correct."); 1.65 +} 1.66 + 1.67 +function testProgressBarShown() { 1.68 + const deck = gDebugger.document.getElementById("editor-deck"); 1.69 + is(deck.selectedIndex, 2, "The progress bar should be shown"); 1.70 +} 1.71 + 1.72 +function testAutoPrettyPrintOn(){ 1.73 + is(gPrefs.autoPrettyPrint, true, 1.74 + "The auto-pretty-print pref should be on."); 1.75 + is(gOptions._autoPrettyPrint.getAttribute("checked"), "true", 1.76 + "The Auto pretty print menu item should be checked."); 1.77 +} 1.78 + 1.79 +function disableAutoPrettyPrint(){ 1.80 + gOptions._autoPrettyPrint.setAttribute("checked", "false"); 1.81 + gOptions._toggleAutoPrettyPrint(); 1.82 + gOptions._onPopupHidden(); 1.83 +} 1.84 + 1.85 +function enableAutoPrettyPrint(){ 1.86 + gOptions._autoPrettyPrint.setAttribute("checked", "true"); 1.87 + gOptions._toggleAutoPrettyPrint(); 1.88 + gOptions._onPopupHidden(); 1.89 +} 1.90 + 1.91 +function testAutoPrettyPrintOff(){ 1.92 + is(gPrefs.autoPrettyPrint, false, 1.93 + "The auto-pretty-print pref should be off."); 1.94 + isnot(gOptions._autoPrettyPrint.getAttribute("checked"), "true", 1.95 + "The Auto pretty print menu item should not be checked."); 1.96 +} 1.97 + 1.98 +function testSourceIsPretty() { 1.99 + ok(gEditor.getText().contains("\n "), 1.100 + "The source should be pretty printed.") 1.101 +} 1.102 + 1.103 +registerCleanupFunction(function() { 1.104 + gTab = null; 1.105 + gDebuggee = null; 1.106 + gPanel = null; 1.107 + gDebugger = null; 1.108 + gEditor = null; 1.109 + gSources = null; 1.110 + gOptions = null; 1.111 + gPrefs = null; 1.112 + gView = null; 1.113 + Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref); 1.114 +});