|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Bug 812172: Test adding and modifying conditional breakpoints (with server-side support) |
|
6 */ |
|
7 |
|
8 const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html"; |
|
9 |
|
10 function test() { |
|
11 let gTab, gDebuggee, gPanel, gDebugger; |
|
12 let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; |
|
13 |
|
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
15 gTab = aTab; |
|
16 gDebuggee = aDebuggee; |
|
17 gPanel = aPanel; |
|
18 gDebugger = gPanel.panelWin; |
|
19 gEditor = gDebugger.DebuggerView.editor; |
|
20 gSources = gDebugger.DebuggerView.Sources; |
|
21 gBreakpoints = gDebugger.DebuggerController.Breakpoints; |
|
22 gBreakpointsAdded = gBreakpoints._added; |
|
23 gBreakpointsRemoving = gBreakpoints._removing; |
|
24 |
|
25 waitForSourceAndCaretAndScopes(gPanel, ".html", 17) |
|
26 .then(() => initialChecks()) |
|
27 .then(() => addBreakpoint1()) |
|
28 .then(() => testBreakpoint(18, false, false, undefined)) |
|
29 .then(() => addBreakpoint2()) |
|
30 .then(() => testBreakpoint(19, false, false, undefined)) |
|
31 .then(() => modBreakpoint2()) |
|
32 .then(() => testBreakpoint(19, false, true, undefined)) |
|
33 .then(() => addBreakpoint3()) |
|
34 .then(() => testBreakpoint(20, true, false, undefined)) |
|
35 .then(() => modBreakpoint3()) |
|
36 .then(() => testBreakpoint(20, true, false, "bamboocha")) |
|
37 .then(() => addBreakpoint4()) |
|
38 .then(() => testBreakpoint(21, false, false, undefined)) |
|
39 .then(() => delBreakpoint4()) |
|
40 .then(() => setCaretPosition(18)) |
|
41 .then(() => testBreakpoint(18, false, false, undefined)) |
|
42 .then(() => setCaretPosition(19)) |
|
43 .then(() => testBreakpoint(19, false, false, undefined)) |
|
44 .then(() => setCaretPosition(20)) |
|
45 .then(() => testBreakpoint(20, true, false, "bamboocha")) |
|
46 .then(() => setCaretPosition(17)) |
|
47 .then(() => testNoBreakpoint(17)) |
|
48 .then(() => setCaretPosition(21)) |
|
49 .then(() => testNoBreakpoint(21)) |
|
50 .then(() => clickOnBreakpoint(0)) |
|
51 .then(() => testBreakpoint(18, false, false, undefined)) |
|
52 .then(() => clickOnBreakpoint(1)) |
|
53 .then(() => testBreakpoint(19, false, false, undefined)) |
|
54 .then(() => clickOnBreakpoint(2)) |
|
55 .then(() => testBreakpoint(20, true, true, "bamboocha")) |
|
56 .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) |
|
57 .then(null, aError => { |
|
58 ok(false, "Got an error: " + aError.message + "\n" + aError.stack); |
|
59 }); |
|
60 |
|
61 gDebuggee.ermahgerd(); |
|
62 }); |
|
63 |
|
64 function initialChecks() { |
|
65 is(gDebugger.gThreadClient.state, "paused", |
|
66 "Should only be getting stack frames while paused."); |
|
67 is(gSources.itemCount, 1, |
|
68 "Found the expected number of sources."); |
|
69 is(gEditor.getText().indexOf("ermahgerd"), 253, |
|
70 "The correct source was loaded initially."); |
|
71 is(gSources.selectedValue, gSources.values[0], |
|
72 "The correct source is selected."); |
|
73 |
|
74 is(gBreakpointsAdded.size, 0, |
|
75 "No breakpoints currently added."); |
|
76 is(gBreakpointsRemoving.size, 0, |
|
77 "No breakpoints currently being removed."); |
|
78 is(gEditor.getBreakpoints().length, 0, |
|
79 "No breakpoints currently shown in the editor."); |
|
80 |
|
81 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), |
|
82 "_getAdded('foo', 3) returns falsey."); |
|
83 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), |
|
84 "_getRemoving('bar', 3) returns falsey."); |
|
85 } |
|
86 |
|
87 function addBreakpoint1() { |
|
88 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); |
|
89 gPanel.addBreakpoint({ url: gSources.selectedValue, line: 18 }); |
|
90 return finished; |
|
91 } |
|
92 |
|
93 function addBreakpoint2() { |
|
94 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); |
|
95 setCaretPosition(19); |
|
96 gSources._onCmdAddBreakpoint(); |
|
97 return finished; |
|
98 } |
|
99 |
|
100 function modBreakpoint2() { |
|
101 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_SHOWING); |
|
102 setCaretPosition(19); |
|
103 gSources._onCmdAddConditionalBreakpoint(); |
|
104 return finished; |
|
105 } |
|
106 |
|
107 function addBreakpoint3() { |
|
108 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); |
|
109 setCaretPosition(20); |
|
110 gSources._onCmdAddConditionalBreakpoint(); |
|
111 return finished; |
|
112 } |
|
113 |
|
114 function modBreakpoint3() { |
|
115 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_HIDING); |
|
116 typeText(gSources._cbTextbox, "bamboocha"); |
|
117 EventUtils.sendKey("RETURN", gDebugger); |
|
118 return finished; |
|
119 } |
|
120 |
|
121 function addBreakpoint4() { |
|
122 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); |
|
123 setCaretPosition(21); |
|
124 gSources._onCmdAddBreakpoint(); |
|
125 return finished; |
|
126 } |
|
127 |
|
128 function delBreakpoint4() { |
|
129 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED); |
|
130 setCaretPosition(21); |
|
131 gSources._onCmdAddBreakpoint(); |
|
132 return finished; |
|
133 } |
|
134 |
|
135 function testBreakpoint(aLine, aOpenPopupFlag, aPopupVisible, aConditionalExpression) { |
|
136 let selectedUrl = gSources.selectedValue; |
|
137 let selectedBreakpoint = gSources._selectedBreakpointItem; |
|
138 |
|
139 ok(selectedUrl, |
|
140 "There should be a selected item in the sources pane."); |
|
141 ok(selectedBreakpoint, |
|
142 "There should be a selected brekapoint in the sources pane."); |
|
143 |
|
144 is(selectedBreakpoint.attachment.url, selectedUrl, |
|
145 "The breakpoint on line " + aLine + " wasn't added on the correct source."); |
|
146 is(selectedBreakpoint.attachment.line, aLine, |
|
147 "The breakpoint on line " + aLine + " wasn't found."); |
|
148 is(!!selectedBreakpoint.attachment.disabled, false, |
|
149 "The breakpoint on line " + aLine + " should be enabled."); |
|
150 is(!!selectedBreakpoint.attachment.openPopup, aOpenPopupFlag, |
|
151 "The breakpoint on line " + aLine + " should have a correct popup state (1)."); |
|
152 is(gSources._conditionalPopupVisible, aPopupVisible, |
|
153 "The breakpoint on line " + aLine + " should have a correct popup state (2)."); |
|
154 |
|
155 return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => { |
|
156 is(aBreakpointClient.location.url, selectedUrl, |
|
157 "The breakpoint's client url is correct"); |
|
158 is(aBreakpointClient.location.line, aLine, |
|
159 "The breakpoint's client line is correct"); |
|
160 is(aBreakpointClient.condition, aConditionalExpression, |
|
161 "The breakpoint on line " + aLine + " should have a correct conditional expression."); |
|
162 is("condition" in aBreakpointClient, !!aConditionalExpression, |
|
163 "The breakpoint on line " + aLine + " should have a correct conditional state."); |
|
164 |
|
165 ok(isCaretPos(gPanel, aLine), |
|
166 "The editor caret position is not properly set."); |
|
167 }); |
|
168 } |
|
169 |
|
170 function testNoBreakpoint(aLine) { |
|
171 let selectedUrl = gSources.selectedValue; |
|
172 let selectedBreakpoint = gSources._selectedBreakpointItem; |
|
173 |
|
174 ok(selectedUrl, |
|
175 "There should be a selected item in the sources pane for line " + aLine + "."); |
|
176 ok(!selectedBreakpoint, |
|
177 "There should be no selected brekapoint in the sources pane for line " + aLine + "."); |
|
178 |
|
179 ok(isCaretPos(gPanel, aLine), |
|
180 "The editor caret position is not properly set."); |
|
181 } |
|
182 |
|
183 function setCaretPosition(aLine) { |
|
184 gEditor.setCursor({ line: aLine - 1, ch: 0 }); |
|
185 } |
|
186 |
|
187 function clickOnBreakpoint(aIndex) { |
|
188 EventUtils.sendMouseEvent({ type: "click" }, |
|
189 gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex], |
|
190 gDebugger); |
|
191 } |
|
192 } |