summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_breakpoints-highlight.js
blob: d04a752ca5f281d4e361e9a1b99ea061a188c88a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Test if breakpoints are highlighted when they should.
 */

const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";

function test() {
  let options = {
    source: EXAMPLE_URL + "code_script-switching-01.js",
    line: 1
  };
  initDebugger(TAB_URL, options).then(([aTab,, aPanel]) => {
    const gTab = aTab;
    const gPanel = aPanel;
    const gDebugger = gPanel.panelWin;
    const gEditor = gDebugger.DebuggerView.editor;
    const gSources = gDebugger.DebuggerView.Sources;
    const queries = gDebugger.require("./content/queries");
    const actions = bindActionCreators(gPanel);
    const getState = gDebugger.DebuggerController.getState;

    const addBreakpoints = Task.async(function* () {
      yield actions.addBreakpoint({ actor: gSources.values[0], line: 5 });
      yield actions.addBreakpoint({ actor: gSources.values[1], line: 6 });
      yield actions.addBreakpoint({ actor: gSources.values[1], line: 7 });
      yield actions.addBreakpoint({ actor: gSources.values[1], line: 8 });
      yield actions.addBreakpoint({ actor: gSources.values[1], line: 9 });
    });

    function clickBreakpointAndCheck(aBreakpointIndex, aSourceIndex, aCaretLine) {
      let finished = waitForCaretUpdated(gPanel, aCaretLine).then(() => {
        checkHighlight(gSources.values[aSourceIndex], aCaretLine);
        checkEditorContents(aSourceIndex);

        is(queries.getSelectedSource(getState()).actor,
           gSources.items[aSourceIndex].value,
           "The currently selected source value is incorrect (1).");
        ok(isCaretPos(gPanel, aCaretLine),
           "The editor caret line and column were incorrect (1).");
      });

      EventUtils.sendMouseEvent(
        { type: "click" },
        gDebugger.document.querySelectorAll(".dbg-breakpoint")[aBreakpointIndex],
        gDebugger
      );

      return finished;
    }

    function checkHighlight(actor, line) {
      let breakpoint = gSources._selectedBreakpoint;
      let breakpointItem = gSources._getBreakpoint(breakpoint);

      is(breakpoint.location.actor, actor,
         "The currently selected breakpoint actor is incorrect.");
      is(breakpoint.location.line, line,
         "The currently selected breakpoint line is incorrect.");
      is(breakpointItem.attachment.actor, actor,
         "The selected breakpoint item's source location attachment is incorrect.");
      ok(breakpointItem.target.classList.contains("selected"),
         "The selected breakpoint item's target should have a selected class.");
    }

    function checkEditorContents(aSourceIndex) {
      if (aSourceIndex == 0) {
        is(gEditor.getText().indexOf("firstCall"), 118,
           "The first source is correctly displayed.");
      } else {
        is(gEditor.getText().indexOf("debugger"), 166,
           "The second source is correctly displayed.");
      }
    }

    Task.spawn(function* () {
      yield addBreakpoints();
      yield clickBreakpointAndCheck(0, 0, 5);
      yield clickBreakpointAndCheck(1, 1, 6);
      yield clickBreakpointAndCheck(2, 1, 7);
      yield clickBreakpointAndCheck(3, 1, 8);
      yield clickBreakpointAndCheck(4, 1, 9);
      closeDebuggerAndFinish(gPanel);
    });
  });
}