browser/devtools/debugger/test/browser_dbg_pretty-print-13.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, even
     6  * when the source URL does not end in ".js", but the content type is
     7  * JavaScript.
     8  */
    10 const TAB_URL = EXAMPLE_URL + "doc_pretty-print-3.html";
    12 let gTab, gDebuggee, gPanel, gDebugger;
    13 let gEditor, gSources;
    15 function test() {
    16   initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    17     gTab = aTab;
    18     gDebuggee = aDebuggee;
    19     gPanel = aPanel;
    20     gDebugger = gPanel.panelWin;
    21     gEditor = gDebugger.DebuggerView.editor;
    22     gSources = gDebugger.DebuggerView.Sources;
    24     promise.all([waitForSourceShown(gPanel, "code_ugly-8"),
    25                  waitForEditorLocationSet(gPanel)])
    26       .then(testSourceIsUgly)
    27       .then(() => {
    28         const finished = waitForSourceShown(gPanel, "code_ugly-8");
    29         clickPrettyPrintButton();
    30         testProgressBarShown();
    31         return finished;
    32       })
    33       .then(testSourceIsPretty)
    34       .then(testEditorShown)
    35       .then(testSourceIsStillPretty)
    36       .then(() => closeDebuggerAndFinish(gPanel))
    37       .then(null, aError => {
    38         ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
    39       });
    40   });
    41 }
    43 function testSourceIsUgly() {
    44   ok(!gEditor.getText().contains("\n  "),
    45      "The source shouldn't be pretty printed yet.");
    46 }
    48 function clickPrettyPrintButton() {
    49   gDebugger.document.getElementById("pretty-print").click();
    50 }
    52 function testProgressBarShown() {
    53   const deck = gDebugger.document.getElementById("editor-deck");
    54   is(deck.selectedIndex, 2, "The progress bar should be shown");
    55 }
    57 function testSourceIsPretty() {
    58   ok(gEditor.getText().contains("\n  "),
    59      "The source should be pretty printed.")
    60 }
    62 function testEditorShown() {
    63   const deck = gDebugger.document.getElementById("editor-deck");
    64   is(deck.selectedIndex, 0, "The editor should be shown");
    65 }
    67 function testSourceIsStillPretty() {
    68   const deferred = promise.defer();
    70   const { source } = gSources.selectedItem.attachment;
    71   gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => {
    72     ok(text.contains("\n  "),
    73        "Subsequent calls to getText return the pretty printed source.");
    74     deferred.resolve();
    75   });
    77   return deferred.promise;
    78 }
    80 registerCleanupFunction(function() {
    81   gTab = null;
    82   gDebuggee = null;
    83   gPanel = null;
    84   gDebugger = null;
    85   gEditor = null;
    86   gSources = null;
    87 });

mercurial