|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Test if the breakpoints toggle button works as advertised when there are |
|
6 * some breakpoints already disabled. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
|
10 |
|
11 function test() { |
|
12 let gTab, gDebuggee, gPanel, gDebugger; |
|
13 let gSources, gBreakpoints; |
|
14 |
|
15 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
16 gTab = aTab; |
|
17 gDebuggee = aDebuggee; |
|
18 gPanel = aPanel; |
|
19 gDebugger = gPanel.panelWin; |
|
20 gSources = gDebugger.DebuggerView.Sources; |
|
21 gBreakpoints = gDebugger.DebuggerController.Breakpoints; |
|
22 |
|
23 waitForSourceShown(gPanel, "-01.js") |
|
24 .then(addBreakpoints) |
|
25 .then(disableSomeBreakpoints) |
|
26 .then(testToggleBreakpoints) |
|
27 .then(testEnableBreakpoints) |
|
28 .then(() => ensureThreadClientState(gPanel, "resumed")) |
|
29 .then(() => closeDebuggerAndFinish(gPanel)) |
|
30 .then(null, aError => { |
|
31 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
32 }); |
|
33 }); |
|
34 |
|
35 function addBreakpoints() { |
|
36 return promise.resolve(null) |
|
37 .then(() => gPanel.addBreakpoint({ url: gSources.values[0], line: 5 })) |
|
38 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 6 })) |
|
39 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 7 })) |
|
40 .then(() => ensureThreadClientState(gPanel, "resumed")); |
|
41 } |
|
42 |
|
43 function disableSomeBreakpoints() { |
|
44 return promise.all([ |
|
45 gSources.disableBreakpoint({ url: gSources.values[0], line: 5 }), |
|
46 gSources.disableBreakpoint({ url: gSources.values[1], line: 6 }) |
|
47 ]); |
|
48 } |
|
49 |
|
50 function testToggleBreakpoints() { |
|
51 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 1); |
|
52 gSources.toggleBreakpoints(); |
|
53 return finished.then(() => checkBreakpointsDisabled(true)); |
|
54 } |
|
55 |
|
56 function testEnableBreakpoints() { |
|
57 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED, 3); |
|
58 gSources.toggleBreakpoints(); |
|
59 return finished.then(() => checkBreakpointsDisabled(false)); |
|
60 } |
|
61 |
|
62 function checkBreakpointsDisabled(aState, aTotal = 3) { |
|
63 let breakpoints = gSources.getAllBreakpoints(); |
|
64 |
|
65 is(breakpoints.length, aTotal, |
|
66 "Breakpoints should still be set."); |
|
67 is(breakpoints.filter(e => e.attachment.disabled == aState).length, aTotal, |
|
68 "Breakpoints should be " + (aState ? "disabled" : "enabled") + "."); |
|
69 } |
|
70 } |