browser/devtools/debugger/test/browser_dbg_auto-pretty-print-02.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 * Test that auto pretty printing doesn't accidentally toggle
michael@0 6 * pretty printing off when we switch to a minified source
michael@0 7 * that is already pretty printed.
michael@0 8 */
michael@0 9
michael@0 10 const TAB_URL = EXAMPLE_URL + "doc_auto-pretty-print-02.html";
michael@0 11
michael@0 12 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 13 let gEditor, gSources, gPrefs, gOptions, gView;
michael@0 14
michael@0 15 let gFirstSourceLabel = "code_ugly-6.js";
michael@0 16 let gSecondSourceLabel = "code_ugly-7.js";
michael@0 17
michael@0 18 let gOriginalPref = Services.prefs.getBoolPref("devtools.debugger.auto-pretty-print");
michael@0 19 Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", true);
michael@0 20
michael@0 21 function test(){
michael@0 22 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 23 gTab = aTab;
michael@0 24 gDebuggee = aDebuggee;
michael@0 25 gPanel = aPanel;
michael@0 26 gDebugger = gPanel.panelWin;
michael@0 27 gEditor = gDebugger.DebuggerView.editor;
michael@0 28 gSources = gDebugger.DebuggerView.Sources;
michael@0 29 gPrefs = gDebugger.Prefs;
michael@0 30 gOptions = gDebugger.DebuggerView.Options;
michael@0 31 gView = gDebugger.DebuggerView;
michael@0 32
michael@0 33 // Should be on by default.
michael@0 34 testAutoPrettyPrintOn();
michael@0 35
michael@0 36 waitForSourceShown(gPanel, gFirstSourceLabel)
michael@0 37 .then(testSourceIsUgly)
michael@0 38 .then(() => waitForSourceShown(gPanel, gFirstSourceLabel))
michael@0 39 .then(testSourceIsPretty)
michael@0 40 .then(testPrettyPrintButtonOn)
michael@0 41 .then(() => {
michael@0 42 // Switch to the second source.
michael@0 43 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
michael@0 44 gSources.selectedIndex = 1;
michael@0 45 return finished;
michael@0 46 })
michael@0 47 .then(testSecondSourceLabel)
michael@0 48 .then(() => {
michael@0 49 // Switch back to first source.
michael@0 50 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN);
michael@0 51 gSources.selectedIndex = 0;
michael@0 52 return finished;
michael@0 53 })
michael@0 54 .then(testFirstSourceLabel)
michael@0 55 .then(testPrettyPrintButtonOn)
michael@0 56 // Disable auto pretty printing so it does not affect the following tests.
michael@0 57 .then(disableAutoPrettyPrint)
michael@0 58 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 59 .then(null, aError => {
michael@0 60 ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
michael@0 61 })
michael@0 62 });
michael@0 63 }
michael@0 64
michael@0 65 function testSourceIsUgly() {
michael@0 66 ok(!gEditor.getText().contains("\n "),
michael@0 67 "The source shouldn't be pretty printed yet.");
michael@0 68 }
michael@0 69
michael@0 70 function testFirstSourceLabel(){
michael@0 71 ok(gSources.containsValue(EXAMPLE_URL + gFirstSourceLabel),
michael@0 72 "First source url is correct.");
michael@0 73 }
michael@0 74
michael@0 75 function testSecondSourceLabel(){
michael@0 76 ok(gSources.containsValue(EXAMPLE_URL + gSecondSourceLabel),
michael@0 77 "Second source url is correct.");
michael@0 78 }
michael@0 79
michael@0 80 function testAutoPrettyPrintOn(){
michael@0 81 is(gPrefs.autoPrettyPrint, true,
michael@0 82 "The auto-pretty-print pref should be on.");
michael@0 83 is(gOptions._autoPrettyPrint.getAttribute("checked"), "true",
michael@0 84 "The Auto pretty print menu item should be checked.");
michael@0 85 }
michael@0 86
michael@0 87 function testPrettyPrintButtonOn(){
michael@0 88 is(gDebugger.document.getElementById("pretty-print").checked, true,
michael@0 89 "The button should be checked when the source is selected.");
michael@0 90 }
michael@0 91
michael@0 92 function disableAutoPrettyPrint(){
michael@0 93 gOptions._autoPrettyPrint.setAttribute("checked", "false");
michael@0 94 gOptions._toggleAutoPrettyPrint();
michael@0 95 gOptions._onPopupHidden();
michael@0 96 }
michael@0 97
michael@0 98 function testSourceIsPretty() {
michael@0 99 ok(gEditor.getText().contains("\n "),
michael@0 100 "The source should be pretty printed.")
michael@0 101 }
michael@0 102
michael@0 103 registerCleanupFunction(function() {
michael@0 104 gTab = null;
michael@0 105 gDebuggee = null;
michael@0 106 gPanel = null;
michael@0 107 gDebugger = null;
michael@0 108 gEditor = null;
michael@0 109 gSources = null;
michael@0 110 gOptions = null;
michael@0 111 gPrefs = null;
michael@0 112 gView = null;
michael@0 113 Services.prefs.setBoolPref("devtools.debugger.auto-pretty-print", gOriginalPref);
michael@0 114 });

mercurial