browser/devtools/debugger/test/browser_dbg_tracing-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_tracing-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,109 @@
     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 + * Test that we get the expected frame enter/exit logs in the tracer view.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_tracing-01.html";
    1.12 +
    1.13 +let gTab, gDebuggee, gPanel, gDebugger;
    1.14 +
    1.15 +function test() {
    1.16 +  SpecialPowers.pushPrefEnv({'set': [["devtools.debugger.tracer", true]]}, () => {
    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 +
    1.23 +      waitForSourceShown(gPanel, "code_tracing-01.js")
    1.24 +        .then(() => startTracing(gPanel))
    1.25 +        .then(clickButton)
    1.26 +        .then(() => waitForClientEvents(aPanel, "traces"))
    1.27 +        .then(testTraceLogs)
    1.28 +        .then(() => stopTracing(gPanel))
    1.29 +        .then(() => {
    1.30 +          const deferred = promise.defer();
    1.31 +          SpecialPowers.popPrefEnv(deferred.resolve);
    1.32 +          return deferred.promise;
    1.33 +        })
    1.34 +        .then(() => closeDebuggerAndFinish(gPanel))
    1.35 +        .then(null, aError => {
    1.36 +          ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.37 +        });
    1.38 +    });
    1.39 +  });
    1.40 +}
    1.41 +
    1.42 +function clickButton() {
    1.43 +  EventUtils.sendMouseEvent({ type: "click" },
    1.44 +                            gDebuggee.document.querySelector("button"),
    1.45 +                            gDebuggee);
    1.46 +}
    1.47 +
    1.48 +function testTraceLogs() {
    1.49 +  const onclickLogs = filterTraces(gPanel,
    1.50 +                                   t => t.querySelector(".trace-name[value=onclick]"));
    1.51 +  is(onclickLogs.length, 2, "Should have two logs from 'onclick'");
    1.52 +  ok(onclickLogs[0].querySelector(".trace-call"),
    1.53 +     "The first 'onclick' log should be a call.");
    1.54 +  ok(onclickLogs[1].querySelector(".trace-return"),
    1.55 +     "The second 'onclick' log should be a return.");
    1.56 +  for (let t of onclickLogs) {
    1.57 +    ok(t.querySelector(".trace-item").getAttribute("tooltiptext")
    1.58 +        .contains("doc_tracing-01.html"));
    1.59 +  }
    1.60 +
    1.61 +  const nonOnclickLogs = filterTraces(gPanel,
    1.62 +                                      t => !t.querySelector(".trace-name[value=onclick]"));
    1.63 +  for (let t of nonOnclickLogs) {
    1.64 +    ok(t.querySelector(".trace-item").getAttribute("tooltiptext")
    1.65 +        .contains("code_tracing-01.js"));
    1.66 +  }
    1.67 +
    1.68 +  const mainLogs = filterTraces(gPanel,
    1.69 +                                t => t.querySelector(".trace-name[value=main]"));
    1.70 +  is(mainLogs.length, 2, "Should have an enter and an exit for 'main'");
    1.71 +  ok(mainLogs[0].querySelector(".trace-call"),
    1.72 +     "The first 'main' log should be a call.");
    1.73 +  ok(mainLogs[1].querySelector(".trace-return"),
    1.74 +     "The second 'main' log should be a return.");
    1.75 +
    1.76 +  const factorialLogs = filterTraces(gPanel,
    1.77 +                                     t => t.querySelector(".trace-name[value=factorial]"));
    1.78 +  is(factorialLogs.length, 10, "Should have 5 enter, and 5 exit frames for 'factorial'");
    1.79 +  ok(factorialLogs.slice(0, 5).every(t => t.querySelector(".trace-call")),
    1.80 +     "The first five 'factorial' logs should be calls.");
    1.81 +  ok(factorialLogs.slice(5).every(t => t.querySelector(".trace-return")),
    1.82 +     "The second five 'factorial' logs should be returns.")
    1.83 +
    1.84 +  // Test that the depth affects padding so that calls are indented properly.
    1.85 +  let lastDepth = -Infinity;
    1.86 +  for (let t of factorialLogs.slice(0, 5)) {
    1.87 +    let depth = parseInt(t.querySelector(".trace-item").style.MozPaddingStart, 10);
    1.88 +    ok(depth > lastDepth, "The depth should be increasing");
    1.89 +    lastDepth = depth;
    1.90 +  }
    1.91 +  lastDepth = Infinity;
    1.92 +  for (let t of factorialLogs.slice(5)) {
    1.93 +    let depth = parseInt(t.querySelector(".trace-item").style.MozPaddingStart, 10);
    1.94 +    ok(depth < lastDepth, "The depth should be decreasing");
    1.95 +    lastDepth = depth;
    1.96 +  }
    1.97 +
    1.98 +  const throwerLogs = filterTraces(gPanel,
    1.99 +                                   t => t.querySelector(".trace-name[value=thrower]"));
   1.100 +  is(throwerLogs.length, 2, "Should have an enter and an exit for 'thrower'");
   1.101 +  ok(throwerLogs[0].querySelector(".trace-call"),
   1.102 +     "The first 'thrower' log should be a call.");
   1.103 +  ok(throwerLogs[1].querySelector(".trace-throw",
   1.104 +     "The second 'thrower' log should be a throw."));
   1.105 +}
   1.106 +
   1.107 +registerCleanupFunction(function() {
   1.108 +  gTab = null;
   1.109 +  gDebuggee = null;
   1.110 +  gPanel = null;
   1.111 +  gDebugger = null;
   1.112 +});

mercurial