summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg_breakpoints-actual-location2.js
blob: 5cee68795519ee64cd04d68d60039b1b8e561e6c (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
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/ */

/**
 * Bug 1008372: Setting a breakpoint in a line without code should move
 * the icon to the actual location, and if a breakpoint already exists
 * on the new location don't duplicate
 */

const TAB_URL = EXAMPLE_URL + "doc_breakpoint-move.html";

function test() {
  let options = {
    source: TAB_URL,
    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 gController = gDebugger.DebuggerController;
    const actions = bindActionCreators(gPanel);
    const constants = gDebugger.require("./content/constants");
    const queries = gDebugger.require("./content/queries");

    function resumeAndTestBreakpoint(line) {
      return Task.spawn(function* () {
        let event = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES);
        doResume(gPanel);
        yield event;
        testBreakpoint(line);
      });
    }

    function testBreakpoint(line) {
      let bp = gSources._selectedBreakpoint;
      ok(bp, "There should be a selected breakpoint on line " + line);
      is(bp.location.line, line,
         "The breakpoint on line " + line + " was not hit");
    }

    Task.spawn(function* () {
      let onCaretUpdated = waitForCaretAndScopes(gPanel, 16);
      callInTab(gTab, "ermahgerd");
      yield onCaretUpdated;

      is(queries.getBreakpoints(gController.getState()).length, 0,
         "There are no breakpoints in the editor");

      yield actions.addBreakpoint({
        actor: gSources.selectedValue,
        line: 19
      });
      yield actions.addBreakpoint({
        actor: gSources.selectedValue,
        line: 20
      });

      const response = yield actions.addBreakpoint({
        actor: gSources.selectedValue,
        line: 17
      });

      is(response.actualLocation.line, 19,
         "Breakpoint client line is new.");

      yield resumeAndTestBreakpoint(19);

      yield actions.removeBreakpoint({
        actor: gSources.selectedValue,
        line: 19
      });

      yield resumeAndTestBreakpoint(20);
      yield doResume(gPanel);

      callInTab(gTab, "ermahgerd");
      yield waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES);

      yield resumeAndTestBreakpoint(20);
      resumeDebuggerThenCloseAndFinish(gPanel);
    });
  });
}