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

mercurial