browser/devtools/debugger/test/browser_dbg_pretty-print-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/debugger/test/browser_dbg_pretty-print-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +/**
     1.8 + * Make sure that clicking the pretty print button prettifies the source.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_pretty-print.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +let gEditor, gSources;
    1.15 +
    1.16 +function test() {
    1.17 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.18 +    gTab = aTab;
    1.19 +    gDebuggee = aDebuggee;
    1.20 +    gPanel = aPanel;
    1.21 +    gDebugger = gPanel.panelWin;
    1.22 +    gEditor = gDebugger.DebuggerView.editor;
    1.23 +    gSources = gDebugger.DebuggerView.Sources;
    1.24 +
    1.25 +    waitForSourceShown(gPanel, "code_ugly.js")
    1.26 +      .then(testSourceIsUgly)
    1.27 +      .then(() => {
    1.28 +        const finished = waitForSourceShown(gPanel, "code_ugly.js");
    1.29 +        clickPrettyPrintButton();
    1.30 +        testProgressBarShown();
    1.31 +        return finished;
    1.32 +      })
    1.33 +      .then(testSourceIsPretty)
    1.34 +      .then(testEditorShown)
    1.35 +      .then(testSourceIsStillPretty)
    1.36 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.37 +      .then(null, aError => {
    1.38 +        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
    1.39 +      });
    1.40 +  });
    1.41 +}
    1.42 +
    1.43 +function testSourceIsUgly() {
    1.44 +  ok(!gEditor.getText().contains("\n  "),
    1.45 +     "The source shouldn't be pretty printed yet.");
    1.46 +}
    1.47 +
    1.48 +function clickPrettyPrintButton() {
    1.49 +  gDebugger.document.getElementById("pretty-print").click();
    1.50 +}
    1.51 +
    1.52 +function testProgressBarShown() {
    1.53 +  const deck = gDebugger.document.getElementById("editor-deck");
    1.54 +  is(deck.selectedIndex, 2, "The progress bar should be shown");
    1.55 +}
    1.56 +
    1.57 +function testSourceIsPretty() {
    1.58 +  ok(gEditor.getText().contains("\n  "),
    1.59 +     "The source should be pretty printed.")
    1.60 +}
    1.61 +
    1.62 +function testEditorShown() {
    1.63 +  const deck = gDebugger.document.getElementById("editor-deck");
    1.64 +  is(deck.selectedIndex, 0, "The editor should be shown");
    1.65 +}
    1.66 +
    1.67 +function testSourceIsStillPretty() {
    1.68 +  const deferred = promise.defer();
    1.69 +
    1.70 +  const { source } = gSources.selectedItem.attachment;
    1.71 +  gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => {
    1.72 +    ok(text.contains("\n  "),
    1.73 +       "Subsequent calls to getText return the pretty printed source.");
    1.74 +    deferred.resolve();
    1.75 +  });
    1.76 +
    1.77 +  return deferred.promise;
    1.78 +}
    1.79 +
    1.80 +registerCleanupFunction(function() {
    1.81 +  gTab = null;
    1.82 +  gDebuggee = null;
    1.83 +  gPanel = null;
    1.84 +  gDebugger = null;
    1.85 +  gEditor = null;
    1.86 +  gSources = null;
    1.87 +});

mercurial