summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-breakpoints-debugger-statement.js
blob: b30bdd96606b162e80f93bb167012b1f8805ef8c (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
91
92
93
94
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */

// Test enabling and disabling a debugger statement using editor context menu

"use strict";

add_task(async function () {
  const dbg = await initDebugger("doc-pause-points.html", "pause-points.js");
  await selectSource(dbg, "pause-points.js");
  await waitForSelectedSource(dbg, "pause-points.js");

  info("Disable the first debugger statement on line 12 by gutter menu");
  rightClickElement(dbg, "gutter", 12);
  await waitForContextMenu(dbg);
  selectContextMenuItem(
    dbg,
    selectors.breakpointContextMenu.disableDbgStatement
  );
  await waitForCondition(dbg, "false");

  let bp = findBreakpoint(dbg, "pause-points.js", 12);
  is(
    bp.options.condition,
    "false",
    "The debugger statement has a conditional breakpoint with 'false' as statement"
  );

  info("Enable the previously disabled debugger statement by gutter menu");
  rightClickElement(dbg, "gutter", 12);
  await waitForContextMenu(dbg);
  selectContextMenuItem(
    dbg,
    selectors.breakpointContextMenu.enableDbgStatement
  );
  await waitForBreakpointWithoutCondition(dbg, "pause-points.js", 12, 0);

  bp = findBreakpoint(dbg, "pause-points.js", 12);
  is(bp.options.condition, null, "The conditional statement is removed");

  info("Enable the breakpoint for the second debugger statement on line 12");
  let bpElements = await waitForAllElements(dbg, "columnBreakpoints");
  Assert.strictEqual(bpElements.length, 2, "2 column breakpoints");
  assertClass(bpElements[0], "active");
  assertClass(bpElements[1], "active", false);

  bpElements[1].click();
  await waitForBreakpointCount(dbg, 2);
  bpElements = findAllElements(dbg, "columnBreakpoints");
  assertClass(bpElements[1], "active");

  info("Disable the second debugger statement by breakpoint menu");
  rightClickEl(dbg, bpElements[1]);
  await waitForContextMenu(dbg);
  selectContextMenuItem(
    dbg,
    selectors.breakpointContextMenu.disableDbgStatement
  );
  await waitForCondition(dbg, "false");

  bp = findBreakpoints(dbg, "pause-points.js", 12)[1];
  is(
    bp.options.condition,
    "false",
    "The second debugger statement has a conditional breakpoint with 'false' as statement"
  );

  info("Enable the second debugger statement by breakpoint menu");
  bpElements = findAllElements(dbg, "columnBreakpoints");
  assertClass(bpElements[1], "has-condition");
  rightClickEl(dbg, bpElements[1]);
  await waitForContextMenu(dbg);
  selectContextMenuItem(
    dbg,
    selectors.breakpointContextMenu.enableDbgStatement
  );
  await waitForBreakpointWithoutCondition(dbg, "pause-points.js", 12, 1);

  bp = findBreakpoints(dbg, "pause-points.js", 12)[1];
  is(bp.options.condition, null, "The conditional statement is removed");
});

function waitForBreakpointWithoutCondition(dbg, url, line, index) {
  return waitForState(dbg, () => {
    const bp = findBreakpoints(dbg, url, line)[index];
    return bp && !bp.options.condition;
  });
}

function findBreakpoints(dbg, url, line) {
  const source = findSource(dbg, url);
  return dbg.selectors.getBreakpointsForSource(source, line);
}