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
|
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
function toggleBreakpoint(dbg, index) {
const bp = findElement(dbg, "breakpointItem", index);
const input = bp.querySelector("input");
input.click();
}
function removeBreakpoint(dbg, index) {
return Task.spawn(function* () {
const bp = findElement(dbg, "breakpointItem", index);
bp.querySelector(".close-btn").click();
yield waitForDispatch(dbg, "REMOVE_BREAKPOINT");
});
}
function disableBreakpoint(dbg, index) {
return Task.spawn(function* () {
toggleBreakpoint(dbg, index);
yield waitForDispatch(dbg, "REMOVE_BREAKPOINT");
});
}
function enableBreakpoint(dbg, index) {
return Task.spawn(function* () {
toggleBreakpoint(dbg, index);
yield waitForDispatch(dbg, "ADD_BREAKPOINT");
});
}
function toggleBreakpoints(dbg) {
return Task.spawn(function* () {
const btn = findElement(dbg, "toggleBreakpoints");
btn.click();
yield waitForDispatch(dbg, "TOGGLE_BREAKPOINTS");
});
}
function findBreakpoint(dbg, url, line) {
const { selectors: { getBreakpoint }, getState } = dbg;
const source = findSource(dbg, url);
return getBreakpoint(getState(), { sourceId: source.id, line });
}
function findBreakpoints(dbg) {
const { selectors: { getBreakpoints }, getState } = dbg;
return getBreakpoints(getState());
}
add_task(function* () {
const dbg = yield initDebugger("doc-scripts.html");
// Create two breakpoints
yield selectSource(dbg, "simple2");
yield addBreakpoint(dbg, "simple2", 3);
yield addBreakpoint(dbg, "simple2", 5);
// Disable the first one
yield disableBreakpoint(dbg, 1);
let bp1 = findBreakpoint(dbg, "simple2", 3);
let bp2 = findBreakpoint(dbg, "simple2", 5);
is(bp1.disabled, true, "first breakpoint is disabled");
is(bp2.disabled, false, "second breakpoint is enabled");
// Disable and Re-Enable the second one
yield disableBreakpoint(dbg, 2);
yield enableBreakpoint(dbg, 2);
bp2 = findBreakpoint(dbg, "simple2", 5);
is(bp2.disabled, false, "second breakpoint is enabled");
});
// toggle all
add_task(function* () {
const dbg = yield initDebugger("doc-scripts.html");
// Create two breakpoints
yield selectSource(dbg, "simple2");
yield addBreakpoint(dbg, "simple2", 3);
yield addBreakpoint(dbg, "simple2", 5);
// Disable all of the breakpoints
yield toggleBreakpoints(dbg);
let bp1 = findBreakpoint(dbg, "simple2", 3);
let bp2 = findBreakpoint(dbg, "simple2", 5);
is(bp1.disabled, true, "first breakpoint is disabled");
is(bp2.disabled, true, "second breakpoint is disabled");
// Enable all of the breakpoints
yield toggleBreakpoints(dbg);
bp1 = findBreakpoint(dbg, "simple2", 3);
bp2 = findBreakpoint(dbg, "simple2", 5);
is(bp1.disabled, false, "first breakpoint is enabled");
is(bp2.disabled, false, "second breakpoint is enabled");
// Remove the breakpoints
yield removeBreakpoint(dbg, 1);
yield removeBreakpoint(dbg, 1);
const bps = findBreakpoints(dbg);
is(bps.size, 0, "breakpoints are removed");
});
|