browser/devtools/debugger/test/browser_dbg_breakpoints-highlight.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-highlight.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,104 @@
     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 if breakpoints are highlighted when they should.
     1.9 + */
    1.10 +
    1.11 +const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
    1.12 +
    1.13 +function test() {
    1.14 +  let gTab, gDebuggee, gPanel, gDebugger;
    1.15 +  let gEditor, gSources;
    1.16 +
    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 +    gEditor = gDebugger.DebuggerView.editor;
    1.23 +    gSources = gDebugger.DebuggerView.Sources;
    1.24 +
    1.25 +    waitForSourceShown(gPanel, "-01.js")
    1.26 +      .then(addBreakpoints)
    1.27 +      .then(() => clickBreakpointAndCheck(0, 0, 5))
    1.28 +      .then(() => clickBreakpointAndCheck(1, 1, 6))
    1.29 +      .then(() => clickBreakpointAndCheck(2, 1, 7))
    1.30 +      .then(() => clickBreakpointAndCheck(3, 1, 8))
    1.31 +      .then(() => clickBreakpointAndCheck(4, 1, 9))
    1.32 +      .then(() => ensureThreadClientState(gPanel, "resumed"))
    1.33 +      .then(() => closeDebuggerAndFinish(gPanel))
    1.34 +      .then(null, aError => {
    1.35 +        ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
    1.36 +      });
    1.37 +  });
    1.38 +
    1.39 +  function addBreakpoints() {
    1.40 +    return promise.resolve(null)
    1.41 +      .then(() => initialChecks(0, 1))
    1.42 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[0], line: 5 }))
    1.43 +      .then(() => initialChecks(0, 5))
    1.44 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 6 }))
    1.45 +      .then(() => waitForSourceShown(gPanel, "-02.js"))
    1.46 +      .then(() => waitForCaretUpdated(gPanel, 6))
    1.47 +      .then(() => initialChecks(1, 6))
    1.48 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 7 }))
    1.49 +      .then(() => initialChecks(1, 7))
    1.50 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 8 }))
    1.51 +      .then(() => initialChecks(1, 8))
    1.52 +      .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 9 }))
    1.53 +      .then(() => initialChecks(1, 9));
    1.54 +  }
    1.55 +
    1.56 +  function initialChecks(aSourceIndex, aCaretLine) {
    1.57 +    checkEditorContents(aSourceIndex);
    1.58 +
    1.59 +    is(gSources.selectedLabel, gSources.items[aSourceIndex].label,
    1.60 +      "The currently selected source label is incorrect (0).");
    1.61 +    is(gSources.selectedValue, gSources.items[aSourceIndex].value,
    1.62 +      "The currently selected source value is incorrect (0).");
    1.63 +    ok(isCaretPos(gPanel, aCaretLine),
    1.64 +      "The editor caret line and column were incorrect (0).");
    1.65 +  }
    1.66 +
    1.67 +  function clickBreakpointAndCheck(aBreakpointIndex, aSourceIndex, aCaretLine) {
    1.68 +    let finished = waitForCaretUpdated(gPanel, aCaretLine).then(() => {
    1.69 +      checkHighlight(gSources.values[aSourceIndex], aCaretLine);
    1.70 +      checkEditorContents(aSourceIndex);
    1.71 +
    1.72 +      is(gSources.selectedLabel, gSources.items[aSourceIndex].label,
    1.73 +        "The currently selected source label is incorrect (1).");
    1.74 +      is(gSources.selectedValue, gSources.items[aSourceIndex].value,
    1.75 +        "The currently selected source value is incorrect (1).");
    1.76 +      ok(isCaretPos(gPanel, aCaretLine),
    1.77 +        "The editor caret line and column were incorrect (1).");
    1.78 +    });
    1.79 +
    1.80 +    EventUtils.sendMouseEvent({ type: "click" },
    1.81 +      gDebugger.document.querySelectorAll(".dbg-breakpoint")[aBreakpointIndex],
    1.82 +      gDebugger);
    1.83 +
    1.84 +    return finished;
    1.85 +  }
    1.86 +
    1.87 +  function checkHighlight(aUrl, aLine) {
    1.88 +    is(gSources._selectedBreakpointItem, gSources.getBreakpoint({ url: aUrl, line: aLine }),
    1.89 +      "The currently selected breakpoint item is incorrect.");
    1.90 +    is(gSources._selectedBreakpointItem.attachment.url, aUrl,
    1.91 +      "The selected breakpoint item's source location attachment is incorrect.");
    1.92 +    is(gSources._selectedBreakpointItem.attachment.line, aLine,
    1.93 +      "The selected breakpoint item's source line number is incorrect.");
    1.94 +    ok(gSources._selectedBreakpointItem.target.classList.contains("selected"),
    1.95 +      "The selected breakpoint item's target should have a selected class.");
    1.96 +  }
    1.97 +
    1.98 +  function checkEditorContents(aSourceIndex) {
    1.99 +    if (aSourceIndex == 0) {
   1.100 +      is(gEditor.getText().indexOf("firstCall"), 118,
   1.101 +        "The first source is correctly displayed.");
   1.102 +    } else {
   1.103 +      is(gEditor.getText().indexOf("debugger"), 172,
   1.104 +        "The second source is correctly displayed.");
   1.105 +    }
   1.106 +  }
   1.107 +}

mercurial