Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 093defc

Browse files
author
Jason Laster
committed
Bug 1537598 - Test Column Breakpoints. r=davidwalsh
Differential Revision: https://phabricator.services.mozilla.com/D26708 --HG-- extra : moz-landing-system : lando
1 parent 4f20558 commit 093defc

4 files changed

Lines changed: 163 additions & 169 deletions

File tree

devtools/client/debugger/new/test/mochitest/.eslintrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"selectSource": false,
3636
"prettyPrint": false,
3737
"closeTab": false,
38+
"pushPref": false,
3839

3940
// Globals introduced in debugger-specific head.js
4041
"getCM": false,
@@ -47,14 +48,18 @@
4748
"waitForThreadEvents": false,
4849
"waitForState": false,
4950
"waitForElement": false,
51+
"waitForAllElements": false,
5052
"waitForElementWithSelector": false,
5153
"waitForPaused": false,
5254
"waitForSources": false,
5355
"waitForSource": false,
5456
"waitForLoadedSource": false,
5557
"waitForSelectedSource": false,
5658
"waitForBreakpointCount": false,
59+
"waitForCondition": false,
60+
"waitForLog": false,
5761
"isPaused": false,
62+
"assertClass": false,
5863
"assertSourceCount": false,
5964
"assertEditorBreakpoint": false,
6065
"assertBreakpointSnippet": false,
@@ -86,7 +91,9 @@
8691
"clickElementWithSelector": false,
8792
"clickDOMElement": false,
8893
"rightClickElement": false,
94+
"rightClickEl": false,
8995
"clickGutter": false,
96+
"typeInPanel": false,
9097
"selectMenuItem": false,
9198
"selectContextMenuItem": false,
9299
"togglePauseOnExceptions": false,
Lines changed: 76 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,104 @@
1-
/* Any copyright is dedicated to the Public Domain.
2-
* http://creativecommons.org/publicdomain/zero/1.0/ */
3-
4-
function getColumnBreakpointElements(dbg) {
5-
return findAllElementsWithSelector(dbg, ".column-breakpoint");
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
4+
5+
async function enableFirstBreakpoint(dbg) {
6+
getCM(dbg).setCursor({ line: 32, ch: 0 });
7+
await addBreakpoint(dbg, "long", 32);
8+
const bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
9+
10+
ok(bpMarkers.length === 2, "2 column breakpoints");
11+
assertClass(bpMarkers[0], "active");
12+
assertClass(bpMarkers[1], "active", false);
613
}
714

8-
async function assertConditionalBreakpointIsFocused(dbg) {
9-
const input = findElement(dbg, "conditionalPanelInput");
10-
await waitForElementFocus(dbg, input);
11-
}
15+
async function enableSecondBreakpoint(dbg) {
16+
let bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
1217

13-
function waitForElementFocus(dbg, el) {
14-
const doc = dbg.win.document;
15-
return waitFor(() => doc.activeElement == el && doc.hasFocus());
16-
}
18+
bpMarkers[1].click();
19+
await waitForBreakpointCount(dbg, 2);
1720

18-
function hasCondition(marker) {
19-
return marker.classList.contains("has-condition");
21+
bpMarkers = findAllElements(dbg, "columnBreakpoints");
22+
assertClass(bpMarkers[1], "active");
23+
await waitForAllElements(dbg, "breakpointItems", 2);
2024
}
2125

2226
async function setConditionalBreakpoint(dbg, index, condition) {
23-
const {
24-
addConditionalBreakpoint,
25-
editConditionalBreakpoint
26-
} = selectors.gutterContextMenu;
27-
// Make this work with either add or edit menu items
28-
const selector = `${addConditionalBreakpoint},${editConditionalBreakpoint}`;
29-
30-
rightClickElement(dbg, "breakpointItem", index);
31-
selectContextMenuItem(dbg, selector);
32-
await waitForElement(dbg, "conditionalPanelInput");
33-
await assertConditionalBreakpointIsFocused(dbg);
34-
35-
// Position cursor reliably at the end of the text.
36-
pressKey(dbg, "End");
37-
type(dbg, condition);
38-
pressKey(dbg, "Enter");
27+
let bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
28+
rightClickEl(dbg, bpMarkers[index]);
29+
selectContextMenuItem(dbg, selectors.addConditionItem);
30+
await typeInPanel(dbg, condition);
31+
await waitForCondition(dbg, condition);
32+
33+
bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
34+
assertClass(bpMarkers[index], "has-condition");
3935
}
4036

41-
function removeBreakpointViaContext(dbg, index) {
42-
rightClickElement(dbg, "breakpointItem", index);
43-
selectContextMenuItem(dbg, "#node-menu-delete-self");
44-
}
37+
async function setLogPoint(dbg, index, expression) {
38+
let bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
39+
rightClickEl(dbg, bpMarkers[index]);
4540

46-
// Test enabling and disabling a breakpoint using the check boxes
47-
add_task(async function() {
48-
const dbg = await initDebugger("doc-scripts.html", "simple1");
49-
await pushPref("devtools.debugger.features.column-breakpoints", false);
41+
selectContextMenuItem(dbg, selectors.addLogItem);
42+
await typeInPanel(dbg, expression);
43+
await waitForLog(dbg, expression);
5044

51-
if(!Services.prefs.getBoolPref("devtools.debugger.features.column-breakpoints")) {
52-
ok(true, "This test only applies when column breakpoints are on");
53-
return;
54-
}
45+
bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
46+
assertClass(bpMarkers[index], "has-log");
47+
}
5548

56-
await selectSource(dbg, "simple1");
49+
async function disableBreakpoint(dbg, index) {
50+
rightClickElement(dbg, "columnBreakpoints");
51+
selectContextMenuItem(dbg, selectors.disableItem);
5752

58-
// Scroll down to desired line so that column breakpoints render
59-
getCM(dbg).setCursor({ line: 15, ch: 0 });
53+
await waitForState(dbg, state => {
54+
const bp = dbg.selectors.getBreakpointsList(state)[index];
55+
return bp.disabled;
56+
});
6057

61-
// Create a breakpoint at 15:undefined
62-
await addBreakpoint(dbg, "simple1", 15);
58+
const bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
59+
assertClass(bpMarkers[0], "disabled");
60+
}
6361

64-
// Wait for column breakpoint markers
65-
await waitForElementWithSelector(dbg, ".column-breakpoint");
62+
async function removeFirstBreakpoint(dbg) {
63+
let bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
6664

67-
let columnBreakpointMarkers = getColumnBreakpointElements(dbg);
68-
ok(
69-
columnBreakpointMarkers.length === 2,
70-
"2 column breakpoint markers display"
71-
);
65+
bpMarkers[0].click();
66+
bpMarkers = await waitForAllElements(dbg, "columnBreakpoints");
67+
assertClass(bpMarkers[0], "active", false);
68+
}
7269

73-
// Create a breakpoint at 15:8
74-
columnBreakpointMarkers[0].click();
70+
async function removeAllBreakpoints(dbg, line, count) {
71+
clickGutter(dbg, 32);
72+
await waitForBreakpointCount(dbg, 0);
7573

76-
// Create a breakpoint at 15:28
77-
columnBreakpointMarkers[1].click();
74+
ok(findAllElements(dbg, "columnBreakpoints").length == 0);
75+
}
7876

79-
// Wait for breakpoints in right panel to render
80-
await waitForState(dbg, state => {
81-
return dbg.win.document.querySelectorAll(".breakpoints-list .breakpoint").length === 3;
82-
})
77+
add_task(async function() {
78+
const dbg = await initDebugger("doc-scripts.html", "simple1");
79+
await selectSource(dbg, "long");
8380

84-
// Scroll down in secondary pane so element we want to right-click is showing
85-
dbg.win.document.querySelector(".secondary-panes").scrollTop = 100;
81+
info("1. Add a column breakpoint on line 32");
82+
await enableFirstBreakpoint(dbg);
8683

87-
// Set a condition at 15:8
88-
await setConditionalBreakpoint(dbg, 4, "Eight");
84+
info("2. Click on the second breakpoint on line 32");
85+
await enableSecondBreakpoint(dbg);
8986

90-
// Ensure column breakpoint is yellow
91-
await waitForElementWithSelector(dbg, ".column-breakpoint.has-condition");
87+
info("3. Add a condition to the first breakpoint");
88+
await setConditionalBreakpoint(dbg, 0, "foo");
9289

93-
// Remove the breakpoint from 15:undefined via the secondary pane context menu
94-
removeBreakpointViaContext(dbg, 3);
90+
info("4. Add a log to the first breakpoint");
91+
await setLogPoint(dbg, 0, "bar");
9592

96-
// Ensure that there's still a marker on line 15
97-
await waitForState(dbg, state => dbg.selectors.getBreakpointCount(state) == 2);
98-
await waitForElementWithSelector(dbg, ".column-breakpoint.has-condition");
99-
columnBreakpointMarkers = getColumnBreakpointElements(dbg);
100-
ok(hasCondition(columnBreakpointMarkers[0]), "First column breakpoint has conditional style");
93+
info("5. Disable the first breakpoint");
94+
await disableBreakpoint(dbg, 0);
10195

102-
// Remove the breakpoint from 15:8
103-
removeBreakpointViaContext(dbg, 3);
96+
info("6. Remove the first breakpoint");
97+
await removeFirstBreakpoint(dbg);
10498

105-
// Ensure there's still a marker and it has no condition
106-
await waitForState(dbg, state => dbg.selectors.getBreakpointCount(state) == 1);
107-
await waitForElementWithSelector(dbg, ".column-breakpoint");
99+
info("7. Add a condition to the second breakpoint");
100+
await setConditionalBreakpoint(dbg, 1, "foo2");
108101

109-
// Ensure the first column breakpoint has no conditional style
110-
await waitFor(() => !hasCondition(getColumnBreakpointElements(dbg)[0]));
102+
info("8. test removing the breakpoints by clicking in the gutter");
103+
await removeAllBreakpoints(dbg, 32, 0);
111104
});

devtools/client/debugger/new/test/mochitest/browser_dbg-breakpoints-cond.js

Lines changed: 13 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -31,77 +31,29 @@ function assertEditorBreakpoint(
3131
);
3232
}
3333

34-
function waitForElementFocus(dbg, el) {
35-
const doc = dbg.win.document;
36-
return waitFor(() => doc.activeElement == el && doc.hasFocus());
37-
}
38-
39-
function waitForBreakpoint(dbg, url, line) {
40-
return waitForState(dbg, () => findBreakpoint(dbg, url, line));
41-
}
42-
43-
function waitForBreakpointWithCondition(dbg, url, line, cond) {
44-
return waitForState(dbg, () => {
45-
const bp = findBreakpoint(dbg, url, line);
46-
return (
47-
bp && bp.options.condition && (!cond || bp.options.condition == cond)
48-
);
49-
});
50-
}
51-
52-
function waitForBreakpointWithLog(dbg, url, line) {
53-
return waitForState(dbg, () => {
54-
const bp = findBreakpoint(dbg, url, line);
55-
return bp && bp.options.logValue;
56-
});
57-
}
58-
5934
function waitForBreakpointWithoutCondition(dbg, url, line) {
6035
return waitForState(dbg, () => {
6136
const bp = findBreakpoint(dbg, url, line);
6237
return bp && !bp.options.condition;
6338
});
6439
}
6540

66-
async function assertConditionalBreakpointIsFocused(dbg) {
67-
const input = findElement(dbg, "conditionalPanelInput");
68-
await waitForElementFocus(dbg, input);
69-
}
70-
7141
async function setConditionalBreakpoint(dbg, index, condition) {
72-
const {
73-
addConditionalBreakpoint,
74-
editConditionalBreakpoint
75-
} = selectors.gutterContextMenu;
42+
const { addConditionItem, editConditionItem } = selectors;
7643
// Make this work with either add or edit menu items
77-
const selector = `${addConditionalBreakpoint},${editConditionalBreakpoint}`;
78-
44+
const selector = `${addConditionItem},${editConditionItem}`;
7945
rightClickElement(dbg, "gutter", index);
8046
selectContextMenuItem(dbg, selector);
81-
await waitForElement(dbg, "conditionalPanelInput");
82-
await assertConditionalBreakpointIsFocused(dbg);
83-
84-
// Position cursor reliably at the end of the text.
85-
pressKey(dbg, "End");
86-
type(dbg, condition);
87-
pressKey(dbg, "Enter");
47+
typeInPanel(dbg, condition);
8848
}
8949

9050
async function setLogPoint(dbg, index, value) {
91-
const { addLogPoint, editLogPoint } = selectors.gutterContextMenu;
92-
93-
// Make this work with either add or edit menu items
94-
const selector = `${addLogPoint},${editLogPoint}`;
95-
9651
rightClickElement(dbg, "gutter", index);
97-
selectContextMenuItem(dbg, selector);
98-
await waitForElement(dbg, "conditionalPanelInput");
99-
await assertConditionalBreakpointIsFocused(dbg);
100-
101-
// Position cursor reliably at the end of the text.
102-
pressKey(dbg, "End");
103-
type(dbg, value);
104-
pressKey(dbg, "Enter");
52+
selectContextMenuItem(
53+
dbg,
54+
`${selectors.addLogItem},${selectors.editLogItem}`
55+
);
56+
await typeInPanel(dbg, value);
10557
}
10658

10759
add_task(async function() {
@@ -112,17 +64,17 @@ add_task(async function() {
11264
await selectSource(dbg, "simple2");
11365
await waitForSelectedSource(dbg, "simple2");
11466

67+
info("Set condition `1`");
11568
await setConditionalBreakpoint(dbg, 5, "1");
116-
await waitForDispatch(dbg, "SET_BREAKPOINT");
117-
await waitForBreakpointWithCondition(dbg, "simple2", 5);
69+
await waitForCondition(dbg, 1);
11870

11971
let bp = findBreakpoint(dbg, "simple2", 5);
12072
is(bp.options.condition, "1", "breakpoint is created with the condition");
12173
await assertEditorBreakpoint(dbg, 5, { hasCondition: true });
12274

12375
info("Edit the conditional breakpoint set above");
12476
await setConditionalBreakpoint(dbg, 5, "2");
125-
await waitForBreakpointWithCondition(dbg, "simple2", 5, "12");
77+
await waitForCondition(dbg, 12);
12678

12779
bp = findBreakpoint(dbg, "simple2", 5);
12880
is(bp.options.condition, "12", "breakpoint is created with the condition");
@@ -138,7 +90,7 @@ add_task(async function() {
13890
clickElement(dbg, "gutter", 5);
13991
await waitForDispatch(dbg, "SET_BREAKPOINT");
14092
await setConditionalBreakpoint(dbg, 5, "1");
141-
await waitForBreakpointWithCondition(dbg, "simple2", 5);
93+
await waitForCondition(dbg, 1);
14294

14395
bp = findBreakpoint(dbg, "simple2", 5);
14496
is(bp.options.condition, "1", "breakpoint is created with the condition");
@@ -153,7 +105,7 @@ add_task(async function() {
153105

154106
info('Add "log point"');
155107
await setLogPoint(dbg, 5, "44");
156-
await waitForBreakpointWithLog(dbg, "simple2", 5);
108+
await waitForLog(dbg, 44);
157109
await assertEditorBreakpoint(dbg, 5, { hasLog: true });
158110

159111
bp = findBreakpoint(dbg, "simple2", 5);

0 commit comments

Comments
 (0)