summaryrefslogtreecommitdiffstats
path: root/devtools/client/debugger/test/mochitest/browser_dbg-state-based-panels.js
blob: 2f07390c480752ac577f7d8f39efa215e7442ef6 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* 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/>. */

"use strict";

// Tests that breakpoint panels open when their relevant breakpoint is hit
add_task(async function testBreakpointsPaneOpenOnPause() {
  const dbg = await initDebugger("doc-sources.html", "simple1.js");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  info("Confirm the breakpoints pane is closed");
  is(getPaneElements(dbg).length, 1);

  await selectSource(dbg, "simple1.js");
  await addBreakpoint(dbg, "simple1.js", 4);

  info("Trigger the breakpoint ane ensure we're paused");
  invokeInTab("main");
  await waitForPaused(dbg, "simple1.js");

  info("Confirm the breakpoints pane is open");
  is(getPaneElements(dbg).length, 2);

  await resume(dbg);

  info("Confirm the breakpoints pane is closed again");
  is(getPaneElements(dbg).length, 1);
});

// Tests that the breakpoint pane remains closed on stepping
add_task(async function testBreakpointsPanePersistOnStepping() {
  const dbg = await initDebugger("doc-scripts.html", "simple3.js");

  await selectSource(dbg, "simple3.js");
  await addBreakpoint(dbg, "simple3.js", 9);
  await waitForBreakpoint(dbg, "simple3.js", 9);

  invokeInTab("nestedA");
  await waitForPaused(dbg, "simple3.js");

  is(getPaneElements(dbg).length, 2, "Breakpoints pane is open");

  info("Close breakpoints pane");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is closed");

  info("Step into nestedB");

  await stepIn(dbg);

  ok(isFrameSelected(dbg, 1, "nestedB"), "nestedB  frame is selected");

  is(getPaneElements(dbg).length, 1, "Breakpoints pane is still closed");
});

// Tests that the breakpoint pane remains closed on call-stack frame selection
add_task(async function testBreakpointsPanePersistOnFrameSelection() {
  const dbg = await initDebugger("doc-scripts.html", "simple3.js");

  info("Close breakpoints pane");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is closed");

  await selectSource(dbg, "simple3.js");
  await addBreakpoint(dbg, "simple3.js", 13);
  await waitForBreakpoint(dbg, "simple3.js", 13);

  invokeInTab("nestedA");
  await waitForPaused(dbg, "simple3.js");

  is(getPaneElements(dbg).length, 2, "Breakpoints pane is open");

  info("Close breakpoints pane");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is closed");

  is(getFrameList(dbg).length, 2, "Call stack has two frames");

  info("Click on second call stack frame");

  await clickElement(dbg, "frame", 2);

  ok(isFrameSelected(dbg, 2, "nestedA"), "Second frame is selected");

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is still closed");
});

// Tests that the breakpoint pane persists when toggled during pause
add_task(async function testBreakpointsPanePersistOnPauseToggle() {
  const dbg = await initDebugger("doc-scripts.html", "simple3.js");

  await selectSource(dbg, "simple3.js");
  await addBreakpoint(dbg, "simple3.js", 9);
  await waitForBreakpoint(dbg, "simple3.js", 9);

  info("Close breakpoint pane");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is closed");

  info("Trigger breakpoint");

  invokeInTab("nestedA");
  await waitForPaused(dbg, "simple3.js");

  is(getPaneElements(dbg).length, 2, "Breakpoints pane is open");

  info("Close breakpoint pane and reopen it");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 1, "Breakpoints pane is closed");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 2, "Breakpoints pane is open");

  await resume(dbg);

  is(getPaneElements(dbg).length, 2, "Breakpoints pane is still open");
});

// Tests that the breakpoint pane remains closed when event breakpoints log is toggled
add_task(async function testBreakpointsPanePersistOnPauseToggle() {
  const dbg = await initDebugger("doc-scripts.html", "simple3.js");

  await selectSource(dbg, "simple3.js");
  await addBreakpoint(dbg, "simple3.js", 9);
  await waitForBreakpoint(dbg, "simple3.js", 9);

  info("Trigger breakpoint");

  invokeInTab("nestedA");
  await waitForPaused(dbg, "simple3.js");

  info("Close breakpoint pane");

  clickElementWithSelector(dbg, ".breakpoints-pane h2");

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is closed");

  info("Check event listener breakpoints log box");
  const wait = waitForDispatch(dbg.store, "TOGGLE_EVENT_LISTENERS");
  await clickElement(dbg, "logEventsCheckbox");
  await wait;

  is(getPaneElements(dbg).length, 1, "Breakpoint pane is still closed");
});

function getPaneElements(dbg) {
  return findElementWithSelector(dbg, ".breakpoints-pane").childNodes;
}

function getFrameList(dbg) {
  return dbg.win.document.querySelectorAll(".call-stack-pane .frame");
}