browser/devtools/debugger/test/browser_dbg_pretty-print-13.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-13.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     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, even
     1.9 + * when the source URL does not end in ".js", but the content type is
    1.10 + * JavaScript.
    1.11 + */
    1.12 +
    1.13 +const TAB_URL = EXAMPLE_URL + "doc_pretty-print-3.html";
    1.14 +
    1.15 +let gTab, gDebuggee, gPanel, gDebugger;
    1.16 +let gEditor, gSources;
    1.17 +
    1.18 +function test() {
    1.19 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.20 +    gTab = aTab;
    1.21 +    gDebuggee = aDebuggee;
    1.22 +    gPanel = aPanel;
    1.23 +    gDebugger = gPanel.panelWin;
    1.24 +    gEditor = gDebugger.DebuggerView.editor;
    1.25 +    gSources = gDebugger.DebuggerView.Sources;
    1.26 +
    1.27 +    promise.all([waitForSourceShown(gPanel, "code_ugly-8"),
    1.28 +                 waitForEditorLocationSet(gPanel)])
    1.29 +      .then(testSourceIsUgly)
    1.30 +      .then(() => {
    1.31 +        const finished = waitForSourceShown(gPanel, "code_ugly-8");
    1.32 +        clickPrettyPrintButton();
    1.33 +        testProgressBarShown();
    1.34 +        return finished;
    1.35 +      })
    1.36 +      .then(testSourceIsPretty)
    1.37 +      .then(testEditorShown)
    1.38 +      .then(testSourceIsStillPretty)
    1.39 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.40 +      .then(null, aError => {
    1.41 +        ok(false, "Got an error: " + DevToolsUtils.safeErrorString(aError));
    1.42 +      });
    1.43 +  });
    1.44 +}
    1.45 +
    1.46 +function testSourceIsUgly() {
    1.47 +  ok(!gEditor.getText().contains("\n  "),
    1.48 +     "The source shouldn't be pretty printed yet.");
    1.49 +}
    1.50 +
    1.51 +function clickPrettyPrintButton() {
    1.52 +  gDebugger.document.getElementById("pretty-print").click();
    1.53 +}
    1.54 +
    1.55 +function testProgressBarShown() {
    1.56 +  const deck = gDebugger.document.getElementById("editor-deck");
    1.57 +  is(deck.selectedIndex, 2, "The progress bar should be shown");
    1.58 +}
    1.59 +
    1.60 +function testSourceIsPretty() {
    1.61 +  ok(gEditor.getText().contains("\n  "),
    1.62 +     "The source should be pretty printed.")
    1.63 +}
    1.64 +
    1.65 +function testEditorShown() {
    1.66 +  const deck = gDebugger.document.getElementById("editor-deck");
    1.67 +  is(deck.selectedIndex, 0, "The editor should be shown");
    1.68 +}
    1.69 +
    1.70 +function testSourceIsStillPretty() {
    1.71 +  const deferred = promise.defer();
    1.72 +
    1.73 +  const { source } = gSources.selectedItem.attachment;
    1.74 +  gDebugger.DebuggerController.SourceScripts.getText(source).then(([, text]) => {
    1.75 +    ok(text.contains("\n  "),
    1.76 +       "Subsequent calls to getText return the pretty printed source.");
    1.77 +    deferred.resolve();
    1.78 +  });
    1.79 +
    1.80 +  return deferred.promise;
    1.81 +}
    1.82 +
    1.83 +registerCleanupFunction(function() {
    1.84 +  gTab = null;
    1.85 +  gDebuggee = null;
    1.86 +  gPanel = null;
    1.87 +  gDebugger = null;
    1.88 +  gEditor = null;
    1.89 +  gSources = null;
    1.90 +});

mercurial