browser/devtools/debugger/test/browser_dbg_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 /**
     5  * Make sure that clicking the pretty print button prettifies the source.
     6  */
     8 const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html";
    10 let gTab, gDebuggee, gPanel, gDebugger;
    11 let gEditor, gSources;
    13 function test() {
    14   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    15     gTab = aTab;
    16     gDebuggee = aDebuggee;
    17     gPanel = aPanel;
    18     gDebugger = gPanel.panelWin;
    19     gEditor = gDebugger.DebuggerView.editor;
    20     gSources = gDebugger.DebuggerView.Sources;
    22     waitForSourceShown(gPanel, "code_ugly.js")
    23       .then(testSourceIsUgly)
    24       .then(() => {
    25         const finished = waitForSourceShown(gPanel, "code_ugly.js");
    26         clickPrettyPrintButton();
    27         testProgressBarShown();
    28         return finished;
    29       })
    30       .then(testSourceIsPretty)
    31       .then(testEditorShown)
    32       .then(testSourceIsStillPretty)
    33       .then(() => closeDebuggerAndFinish(gPanel))
    34       .then(null, aError => {
    35         ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
    36       });
    37   });
    38 }
    40 function testSourceIsUgly() {
    41   ok(!gEditor.getText().contains("\n  "),
    42      "The source shouldn't be pretty printed yet.");
    43 }
    45 function clickPrettyPrintButton() {
    46   gDebugger.document.getElementById("pretty-print").click();
    47 }
    49 function testProgressBarShown() {
    50   const deck = gDebugger.document.getElementById("editor-deck");
    51   is(deck.selectedIndex, 2, "The progress bar should be shown");
    52 }
    54 function testSourceIsPretty() {
    55   ok(gEditor.getText().contains("\n  "),
    56      "The source should be pretty printed.")
    57 }
    59 function testEditorShown() {
    60   const deck = gDebugger.document.getElementById("editor-deck");
    61   is(deck.selectedIndex, 0, "The editor should be shown");
    62 }
    64 function testSourceIsStillPretty() {
    65   const deferred = promise.defer();
    67   const { source } = gSources.selectedItem.attachment;
    68   gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => {
    69     ok(text.contains("\n  "),
    70        "Subsequent calls to getText return the pretty printed source.");
    71     deferred.resolve();
    72   });
    74   return deferred.promise;
    75 }
    77 registerCleanupFunction(function() {
    78   gTab = null;
    79   gDebuggee = null;
    80   gPanel = null;
    81   gDebugger = null;
    82   gEditor = null;
    83   gSources = null;
    84 });

mercurial