summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-breakpoint-skipping.js
blob: f995df2b6b755891051073c6c1abf3d63cd25dc6 (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
/* 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/>. */

/*
 * Tests toggling the skip pausing button and
 * invoking functions without pausing.
 */

"use strict";

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

  info("Adding a breakpoint should remove the skipped pausing state");
  await skipPausing(dbg);
  await waitForState(dbg, () => dbg.selectors.getSkipPausing());
  await addBreakpoint(dbg, "simple3.js", 2);
  await waitForState(dbg, () => !dbg.selectors.getSkipPausing());
  invokeInTab("simple");
  await waitForPaused(dbg);
  ok(true, "The breakpoint has been hit after a breakpoint was created");
  await resume(dbg);

  info("Toggling a breakpoint should remove the skipped pausing state");
  // First disable the breakpoint to ensure skip pausing gets turned off
  // during a disable
  await skipPausing(dbg);
  await disableBreakpoint(dbg, 0);
  await waitForState(dbg, () => !dbg.selectors.getSkipPausing());
  // Then re-enable the breakpoint to ensure skip pausing gets turned off
  // during an enable
  await skipPausing(dbg);
  await waitForState(dbg, () => dbg.selectors.getSkipPausing());
  toggleBreakpoint(dbg, 0);
  await waitForState(dbg, () => !dbg.selectors.getSkipPausing());
  await waitForDispatch(dbg.store, "SET_BREAKPOINT");
  invokeInTab("simple");
  await waitForPaused(dbg);
  ok(true, "The breakpoint has been hit after skip pausing was disabled");
  await resume(dbg);

  info("Disabling a breakpoint should remove the skipped pausing state");
  await addBreakpoint(dbg, "simple3.js", 3);
  await skipPausing(dbg);
  await disableBreakpoint(dbg, 0);
  await waitForState(dbg, () => !dbg.selectors.getSkipPausing());
  invokeInTab("simple");
  await waitForPaused(dbg);
  ok(true, "The breakpoint has been hit after skip pausing was disabled again");
  await resume(dbg);

  info("Removing a breakpoint should remove the skipped pause state");
  toggleBreakpoint(dbg, 0);
  await skipPausing(dbg);
  const source = findSource(dbg, "simple3.js");
  removeBreakpoint(dbg, source.id, 3);
  const wait = waitForDispatch(dbg.store, "TOGGLE_SKIP_PAUSING");
  await waitForState(dbg, () => !dbg.selectors.getSkipPausing());
  await wait;
  invokeInTab("simple");
  await waitForPaused(dbg);
  // Unfortunately required as the test harness throws if preview doesn't
  // complete before the end of the test.
  await waitForDispatch(dbg.store, "ADD_INLINE_PREVIEW");
  ok(true, "Breakpoint is hit after a breakpoint was removed");
  await resume(dbg);
});

function skipPausing(dbg) {
  clickElementWithSelector(dbg, ".command-bar-skip-pausing");
  return waitForState(dbg, () => dbg.selectors.getSkipPausing());
}

function toggleBreakpoint(dbg, index) {
  const breakpoints = findAllElements(dbg, "breakpointItems");
  const bp = breakpoints[index];
  const input = bp.querySelector("input");
  input.click();
}

async function disableBreakpoint(dbg, index) {
  const disabled = waitForDispatch(dbg.store, "SET_BREAKPOINT");
  toggleBreakpoint(dbg, index);
  await disabled;
}