browser/devtools/debugger/test/browser_dbg_pretty-print-06.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-06.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     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 prettifying JS sources with type errors works as expected.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_included-script.html";
    1.12 +const JS_URL = EXAMPLE_URL + "code_location-changes.js";
    1.13 +
    1.14 +let gTab, gDebuggee, gPanel, gDebugger, gClient;
    1.15 +let gEditor, gSources, gControllerSources, gPrettyPrinted;
    1.16 +
    1.17 +function test() {
    1.18 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.19 +    gTab = aTab;
    1.20 +    gDebuggee = aDebuggee;
    1.21 +    gPanel = aPanel;
    1.22 +    gDebugger = gPanel.panelWin;
    1.23 +    gClient = gDebugger.gClient;
    1.24 +    gEditor = gDebugger.DebuggerView.editor;
    1.25 +    gSources = gDebugger.DebuggerView.Sources;
    1.26 +    gControllerSources = gDebugger.DebuggerController.SourceScripts;
    1.27 +
    1.28 +    // We can't feed javascript files with syntax errors to the debugger,
    1.29 +    // because they will never run, thus sometimes getting gc'd before the
    1.30 +    // debugger is opened, or even before the target finishes navigating.
    1.31 +    // Make the client lie about being able to parse perfectly fine code.
    1.32 +    gClient.request = (function (aOriginalRequestMethod) {
    1.33 +      return function (aPacket, aCallback) {
    1.34 +        if (aPacket.type == "prettyPrint") {
    1.35 +          gPrettyPrinted = true;
    1.36 +          return executeSoon(() => aCallback({ error: "prettyPrintError" }));
    1.37 +        }
    1.38 +        return aOriginalRequestMethod(aPacket, aCallback);
    1.39 +      };
    1.40 +    }(gClient.request));
    1.41 +
    1.42 +    Task.spawn(function() {
    1.43 +      yield waitForSourceShown(gPanel, JS_URL);
    1.44 +
    1.45 +      // From this point onward, the source editor's text should never change.
    1.46 +      gEditor.once("change", () => {
    1.47 +        ok(false, "The source editor text shouldn't have changed.");
    1.48 +      });
    1.49 +
    1.50 +      is(gSources.selectedValue, JS_URL,
    1.51 +        "The correct source is currently selected.");
    1.52 +      ok(gEditor.getText().contains("myFunction"),
    1.53 +        "The source shouldn't be pretty printed yet.");
    1.54 +
    1.55 +      clickPrettyPrintButton();
    1.56 +
    1.57 +      let { source } = gSources.selectedItem.attachment;
    1.58 +      try {
    1.59 +        yield gControllerSources.togglePrettyPrint(source);
    1.60 +        ok(false, "The promise for a prettified source should be rejected!");
    1.61 +      } catch ([source, error]) {
    1.62 +        ok(error.contains("prettyPrintError"),
    1.63 +          "The promise was correctly rejected with a meaningful message.");
    1.64 +      }
    1.65 +
    1.66 +      let [source, text] = yield gControllerSources.getText(source);
    1.67 +      is(gSources.selectedValue, JS_URL,
    1.68 +        "The correct source is still selected.");
    1.69 +      ok(gEditor.getText().contains("myFunction"),
    1.70 +        "The displayed source hasn't changed.");
    1.71 +      ok(text.contains("myFunction"),
    1.72 +        "The cached source text wasn't altered in any way.");
    1.73 +
    1.74 +      is(gPrettyPrinted, true,
    1.75 +        "The hijacked pretty print method was executed.");
    1.76 +
    1.77 +      yield closeDebuggerAndFinish(gPanel);
    1.78 +    });
    1.79 +  });
    1.80 +}
    1.81 +
    1.82 +function clickPrettyPrintButton() {
    1.83 +  gDebugger.document.getElementById("pretty-print").click();
    1.84 +}
    1.85 +
    1.86 +registerCleanupFunction(function() {
    1.87 +  gTab = null;
    1.88 +  gDebuggee = null;
    1.89 +  gPanel = null;
    1.90 +  gDebugger = null;
    1.91 +  gClient = null;
    1.92 +  gEditor = null;
    1.93 +  gSources = null;
    1.94 +  gControllerSources = null;
    1.95 +  gPrettyPrinted = null;
    1.96 +});

mercurial