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.

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

mercurial