browser/devtools/debugger/test/browser_dbg_breakpoints-disabled-reload.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:55d954a789df
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Test that disabled breakpoints survive target navigation.
6 */
7
8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
9
10 function test() {
11 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
12 let gDebugger = aPanel.panelWin;
13 let gEvents = gDebugger.EVENTS;
14 let gEditor = gDebugger.DebuggerView.editor;
15 let gSources = gDebugger.DebuggerView.Sources;
16 let gBreakpoints = gDebugger.DebuggerController.Breakpoints;
17 let gBreakpointLocation = { url: EXAMPLE_URL + "code_script-switching-01.js", line: 5 };
18
19 Task.spawn(function() {
20 yield waitForSourceShown(aPanel, "-01.js");
21 yield aPanel.addBreakpoint(gBreakpointLocation);
22
23 yield ensureThreadClientState(aPanel, "resumed");
24 yield testWhenBreakpointEnabledAndFirstSourceShown();
25
26 yield reloadActiveTab(aPanel, gEvents.SOURCE_SHOWN);
27 yield testWhenBreakpointEnabledAndSecondSourceShown();
28
29 yield gSources.disableBreakpoint(gBreakpointLocation);
30 yield reloadActiveTab(aPanel, gEvents.SOURCE_SHOWN);
31 yield testWhenBreakpointDisabledAndSecondSourceShown();
32
33 yield gSources.enableBreakpoint(gBreakpointLocation);
34 yield reloadActiveTab(aPanel, gEvents.SOURCE_SHOWN);
35 yield testWhenBreakpointEnabledAndSecondSourceShown();
36
37 yield resumeDebuggerThenCloseAndFinish(aPanel);
38 });
39
40 function verifyView({ disabled, visible }) {
41 return Task.spawn(function() {
42 // It takes a tick for the checkbox in the SideMenuWidget and the
43 // gutter in the editor to get updated.
44 yield waitForTick();
45
46 let breakpointItem = gSources.getBreakpoint(gBreakpointLocation);
47 let visibleBreakpoints = gEditor.getBreakpoints();
48 is(!!breakpointItem.attachment.disabled, disabled,
49 "The selected brekapoint state was correct.");
50 is(breakpointItem.attachment.view.checkbox.hasAttribute("checked"), !disabled,
51 "The selected brekapoint's checkbox state was correct.");
52
53 // Source editor starts counting line and column numbers from 0.
54 let breakpointLine = breakpointItem.attachment.line - 1;
55 let matchedBreakpoints = visibleBreakpoints.filter(e => e.line == breakpointLine);
56 is(!!matchedBreakpoints.length, visible,
57 "The selected breakpoint's visibility in the editor was correct.");
58 });
59 }
60
61 // All the following executeSoon()'s are required to spin the event loop
62 // before causing the debuggee to pause, to allow functions to yield first.
63
64 function testWhenBreakpointEnabledAndFirstSourceShown() {
65 return Task.spawn(function() {
66 yield ensureSourceIs(aPanel, "-01.js");
67 yield verifyView({ disabled: false, visible: true });
68
69 executeSoon(() => aDebuggee.firstCall());
70 yield waitForDebuggerEvents(aPanel, gEvents.FETCHED_SCOPES);
71 yield ensureSourceIs(aPanel, "-01.js");
72 yield ensureCaretAt(aPanel, 5);
73 yield verifyView({ disabled: false, visible: true });
74
75 executeSoon(() => gDebugger.gThreadClient.resume());
76 yield waitForSourceAndCaretAndScopes(aPanel, "-02.js", 1);
77 yield verifyView({ disabled: false, visible: false });
78 });
79 }
80
81 function testWhenBreakpointEnabledAndSecondSourceShown() {
82 return Task.spawn(function() {
83 yield ensureSourceIs(aPanel, "-02.js", true);
84 yield verifyView({ disabled: false, visible: false });
85
86 executeSoon(() => aDebuggee.firstCall());
87 yield waitForSourceAndCaretAndScopes(aPanel, "-01.js", 1);
88 yield verifyView({ disabled: false, visible: true });
89
90 executeSoon(() => gDebugger.gThreadClient.resume());
91 yield waitForSourceAndCaretAndScopes(aPanel, "-02.js", 1);
92 yield verifyView({ disabled: false, visible: false });
93 });
94 }
95
96 function testWhenBreakpointDisabledAndSecondSourceShown() {
97 return Task.spawn(function() {
98 yield ensureSourceIs(aPanel, "-02.js", true);
99 yield verifyView({ disabled: true, visible: false });
100
101 executeSoon(() => aDebuggee.firstCall());
102 yield waitForDebuggerEvents(aPanel, gEvents.FETCHED_SCOPES);
103 yield ensureSourceIs(aPanel, "-02.js");
104 yield ensureCaretAt(aPanel, 1);
105 yield verifyView({ disabled: true, visible: false });
106
107 executeSoon(() => gDebugger.gThreadClient.resume());
108 yield waitForDebuggerEvents(aPanel, gEvents.AFTER_FRAMES_CLEARED);
109 yield ensureSourceIs(aPanel, "-02.js");
110 yield ensureCaretAt(aPanel, 1);
111 yield verifyView({ disabled: true, visible: false });
112 });
113 }
114 });
115 }

mercurial