browser/devtools/debugger/test/browser_dbg_pretty-print-09.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-09.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,89 @@
     1.4 +/* -*- Mode: javascript; js-indent-level: 2; -*- */
     1.5 +/* Any copyright is dedicated to the Public Domain.
     1.6 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.7 +
     1.8 +// Test pretty printing source mapped sources.
     1.9 +
    1.10 +var gDebuggee;
    1.11 +var gClient;
    1.12 +var gThreadClient;
    1.13 +var gSource;
    1.14 +
    1.15 +let gTab, gDebuggee, gPanel, gClient, gThreadClient, gSource;
    1.16 +
    1.17 +const TAB_URL = EXAMPLE_URL + "doc_pretty-print-2.html";
    1.18 +
    1.19 +function test() {
    1.20 +  initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
    1.21 +    gTab = aTab;
    1.22 +    gDebuggee = aDebuggee;
    1.23 +    gPanel = aPanel;
    1.24 +    gClient = gPanel.panelWin.gClient;
    1.25 +    gThreadClient = gPanel.panelWin.DebuggerController.activeThread;
    1.26 +
    1.27 +    findSource();
    1.28 +  });
    1.29 +}
    1.30 +
    1.31 +const dataUrl = s => "data:text/javascript," + s;
    1.32 +
    1.33 +// These should match the instructions in code_ugly-4.js.
    1.34 +const A = "function a(){b()}";
    1.35 +const A_URL = dataUrl(A);
    1.36 +const B = "function b(){debugger}";
    1.37 +const B_URL = dataUrl(B);
    1.38 +
    1.39 +function findSource() {
    1.40 +  gThreadClient.getSources(({ error, sources }) => {
    1.41 +    ok(!error);
    1.42 +    sources = sources.filter(s => s.url === B_URL);
    1.43 +    is(sources.length, 1);
    1.44 +    gSource = sources[0];
    1.45 +    prettyPrint();
    1.46 +  });
    1.47 +}
    1.48 +
    1.49 +function prettyPrint() {
    1.50 +  gThreadClient.source(gSource).prettyPrint(2, runCode);
    1.51 +}
    1.52 +
    1.53 +function runCode({ error }) {
    1.54 +  ok(!error);
    1.55 +  gClient.addOneTimeListener("paused", testDbgStatement);
    1.56 +  gDebuggee.a();
    1.57 +}
    1.58 +
    1.59 +function testDbgStatement(event, { frame, why }) {
    1.60 +  is(why.type, "debuggerStatement");
    1.61 +  const { url, line } = frame.where;
    1.62 +  is(url, B_URL);
    1.63 +  is(line, 2);
    1.64 +
    1.65 +  disablePrettyPrint();
    1.66 +}
    1.67 +
    1.68 +function disablePrettyPrint() {
    1.69 +  gThreadClient.source(gSource).disablePrettyPrint(testUgly);
    1.70 +}
    1.71 +
    1.72 +function testUgly({ error, source }) {
    1.73 +  ok(!error);
    1.74 +  ok(!source.contains("\n  "));
    1.75 +  getFrame();
    1.76 +}
    1.77 +
    1.78 +function getFrame() {
    1.79 +  gThreadClient.getFrames(0, 1, testFrame);
    1.80 +}
    1.81 +
    1.82 +function testFrame({ frames: [frame] }) {
    1.83 +  const { url, line } = frame.where;
    1.84 +  is(url, B_URL);
    1.85 +  is(line, 1);
    1.86 +
    1.87 +  resumeDebuggerThenCloseAndFinish(gPanel);
    1.88 +}
    1.89 +
    1.90 +registerCleanupFunction(function() {
    1.91 +  gTab = gDebuggee = gPanel = gClient = gThreadClient = null;
    1.92 +});

mercurial