browser/devtools/debugger/test/browser_dbg_breakpoints-new-script.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_breakpoints-new-script.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,90 @@
     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 + * Bug 771452: Make sure that setting a breakpoint in an inline source doesn't
     1.9 + * add it twice.
    1.10 + */
    1.11 +
    1.12 +const TAB_URL = EXAMPLE_URL + "doc_inline-script.html";
    1.13 +
    1.14 +let gTab, gDebuggee, gPanel, gDebugger;
    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 +
    1.23 +    addBreakpoint();
    1.24 +  });
    1.25 +}
    1.26 +
    1.27 +function addBreakpoint() {
    1.28 +  waitForSourceAndCaretAndScopes(gPanel, ".html", 16).then(() => {
    1.29 +    is(gDebugger.gThreadClient.state, "paused",
    1.30 +      "The debugger statement was reached.");
    1.31 +    ok(isCaretPos(gPanel, 16),
    1.32 +      "The source editor caret position is incorrect (1).");
    1.33 +
    1.34 +    gPanel.addBreakpoint({ url: TAB_URL, line: 20 }).then(() => {
    1.35 +      testResume();
    1.36 +    });
    1.37 +  });
    1.38 +
    1.39 +  gDebuggee.runDebuggerStatement();
    1.40 +}
    1.41 +
    1.42 +function testResume() {
    1.43 +  is(gDebugger.gThreadClient.state, "paused",
    1.44 +    "The breakpoint wasn't hit yet.");
    1.45 +
    1.46 +  gDebugger.gThreadClient.resume(() => {
    1.47 +    gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
    1.48 +      waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => {
    1.49 +        is(aPacket.why.type, "breakpoint",
    1.50 +          "Execution has advanced to the next breakpoint.");
    1.51 +        isnot(aPacket.why.type, "debuggerStatement",
    1.52 +          "The breakpoint was hit before the debugger statement.");
    1.53 +        ok(isCaretPos(gPanel, 20),
    1.54 +          "The source editor caret position is incorrect (2).");
    1.55 +
    1.56 +        testBreakpointHit();
    1.57 +      });
    1.58 +    });
    1.59 +
    1.60 +    EventUtils.sendMouseEvent({ type: "click" },
    1.61 +      gDebuggee.document.querySelector("button"),
    1.62 +      gDebuggee);
    1.63 +  });
    1.64 +}
    1.65 +
    1.66 +function testBreakpointHit() {
    1.67 +  is(gDebugger.gThreadClient.state, "paused",
    1.68 +    "The breakpoint was hit.");
    1.69 +
    1.70 +  gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => {
    1.71 +    waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => {
    1.72 +      is(aPacket.why.type, "debuggerStatement",
    1.73 +        "Execution has advanced to the next line.");
    1.74 +      isnot(aPacket.why.type, "breakpoint",
    1.75 +        "No ghost breakpoint was hit.");
    1.76 +      ok(isCaretPos(gPanel, 20),
    1.77 +        "The source editor caret position is incorrect (3).");
    1.78 +
    1.79 +      resumeDebuggerThenCloseAndFinish(gPanel);
    1.80 +    });
    1.81 +  });
    1.82 +
    1.83 +  EventUtils.sendMouseEvent({ type: "mousedown" },
    1.84 +    gDebugger.document.getElementById("resume"),
    1.85 +    gDebugger);
    1.86 +}
    1.87 +
    1.88 +registerCleanupFunction(function() {
    1.89 +  gTab = null;
    1.90 +  gDebuggee = null;
    1.91 +  gPanel = null;
    1.92 +  gDebugger = null;
    1.93 +});

mercurial