|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Make sure that reloading a page with a breakpoint set does not cause it to |
|
6 * fire more than once. |
|
7 */ |
|
8 |
|
9 const TAB_URL = EXAMPLE_URL + "doc_included-script.html"; |
|
10 const SOURCE_URL = EXAMPLE_URL + "code_location-changes.js"; |
|
11 |
|
12 let gTab, gDebuggee, gPanel, gDebugger; |
|
13 let gEditor, gSources; |
|
14 |
|
15 function test() { |
|
16 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
|
17 gTab = aTab; |
|
18 gDebuggee = aDebuggee; |
|
19 gPanel = aPanel; |
|
20 gDebugger = gPanel.panelWin; |
|
21 gEditor = gDebugger.DebuggerView.editor; |
|
22 gSources = gDebugger.DebuggerView.Sources; |
|
23 |
|
24 waitForSourceAndCaretAndScopes(gPanel, ".html", 17).then(addBreakpoint); |
|
25 gDebuggee.runDebuggerStatement(); |
|
26 }); |
|
27 } |
|
28 |
|
29 function addBreakpoint() { |
|
30 waitForSourceAndCaret(gPanel, ".js", 5).then(() => { |
|
31 ok(true, |
|
32 "Switched to the desired function when adding a breakpoint " + |
|
33 "but not passing { noEditorUpdate: true } as an option."); |
|
34 |
|
35 testResume(); |
|
36 }); |
|
37 |
|
38 gPanel.addBreakpoint({ url: SOURCE_URL, line: 5 }); |
|
39 } |
|
40 |
|
41 function testResume() { |
|
42 is(gDebugger.gThreadClient.state, "paused", |
|
43 "The breakpoint wasn't hit yet (1)."); |
|
44 is(gSources.selectedValue, SOURCE_URL, |
|
45 "The currently shown source is incorrect (1)."); |
|
46 ok(isCaretPos(gPanel, 5), |
|
47 "The source editor caret position is incorrect (1)."); |
|
48 |
|
49 gDebugger.gThreadClient.resume(testClick); |
|
50 } |
|
51 |
|
52 function testClick() { |
|
53 isnot(gDebugger.gThreadClient.state, "paused", |
|
54 "The breakpoint wasn't hit yet (2)."); |
|
55 is(gSources.selectedValue, SOURCE_URL, |
|
56 "The currently shown source is incorrect (2)."); |
|
57 ok(isCaretPos(gPanel, 5), |
|
58 "The source editor caret position is incorrect (2)."); |
|
59 |
|
60 gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
|
61 is(aPacket.why.type, "breakpoint", |
|
62 "Execution has advanced to the breakpoint."); |
|
63 isnot(aPacket.why.type, "debuggerStatement", |
|
64 "The breakpoint was hit before the debugger statement."); |
|
65 |
|
66 ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHit); |
|
67 }); |
|
68 |
|
69 EventUtils.sendMouseEvent({ type: "click" }, |
|
70 gDebuggee.document.querySelector("button"), |
|
71 gDebuggee); |
|
72 } |
|
73 |
|
74 function afterBreakpointHit() { |
|
75 is(gDebugger.gThreadClient.state, "paused", |
|
76 "The breakpoint was hit (3)."); |
|
77 is(gSources.selectedValue, SOURCE_URL, |
|
78 "The currently shown source is incorrect (3)."); |
|
79 ok(isCaretPos(gPanel, 5), |
|
80 "The source editor caret position is incorrect (3)."); |
|
81 |
|
82 gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
|
83 is(aPacket.why.type, "debuggerStatement", |
|
84 "Execution has advanced to the next line."); |
|
85 isnot(aPacket.why.type, "breakpoint", |
|
86 "No ghost breakpoint was hit."); |
|
87 |
|
88 ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHit); |
|
89 }); |
|
90 |
|
91 gDebugger.gThreadClient.resume(); |
|
92 } |
|
93 |
|
94 function afterDebuggerStatementHit() { |
|
95 is(gDebugger.gThreadClient.state, "paused", |
|
96 "The debugger statement was hit (4)."); |
|
97 is(gSources.selectedValue, SOURCE_URL, |
|
98 "The currently shown source is incorrect (4)."); |
|
99 ok(isCaretPos(gPanel, 6), |
|
100 "The source editor caret position is incorrect (4)."); |
|
101 |
|
102 promise.all([ |
|
103 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.NEW_SOURCE), |
|
104 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCES_ADDED), |
|
105 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN), |
|
106 reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN) |
|
107 ]).then(testClickAgain); |
|
108 } |
|
109 |
|
110 function testClickAgain() { |
|
111 isnot(gDebugger.gThreadClient.state, "paused", |
|
112 "The breakpoint wasn't hit yet (5)."); |
|
113 is(gSources.selectedValue, SOURCE_URL, |
|
114 "The currently shown source is incorrect (5)."); |
|
115 ok(isCaretPos(gPanel, 1), |
|
116 "The source editor caret position is incorrect (5)."); |
|
117 |
|
118 gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
|
119 is(aPacket.why.type, "breakpoint", |
|
120 "Execution has advanced to the breakpoint."); |
|
121 isnot(aPacket.why.type, "debuggerStatement", |
|
122 "The breakpoint was hit before the debugger statement."); |
|
123 |
|
124 ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHitAgain); |
|
125 }); |
|
126 |
|
127 EventUtils.sendMouseEvent({ type: "click" }, |
|
128 gDebuggee.document.querySelector("button"), |
|
129 gDebuggee); |
|
130 } |
|
131 |
|
132 function afterBreakpointHitAgain() { |
|
133 is(gDebugger.gThreadClient.state, "paused", |
|
134 "The breakpoint was hit (6)."); |
|
135 is(gSources.selectedValue, SOURCE_URL, |
|
136 "The currently shown source is incorrect (6)."); |
|
137 ok(isCaretPos(gPanel, 5), |
|
138 "The source editor caret position is incorrect (6)."); |
|
139 |
|
140 gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
|
141 is(aPacket.why.type, "debuggerStatement", |
|
142 "Execution has advanced to the next line."); |
|
143 isnot(aPacket.why.type, "breakpoint", |
|
144 "No ghost breakpoint was hit."); |
|
145 |
|
146 ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHitAgain); |
|
147 }); |
|
148 |
|
149 gDebugger.gThreadClient.resume(); |
|
150 } |
|
151 |
|
152 function afterDebuggerStatementHitAgain() { |
|
153 is(gDebugger.gThreadClient.state, "paused", |
|
154 "The debugger statement was hit (7)."); |
|
155 is(gSources.selectedValue, SOURCE_URL, |
|
156 "The currently shown source is incorrect (7)."); |
|
157 ok(isCaretPos(gPanel, 6), |
|
158 "The source editor caret position is incorrect (7)."); |
|
159 |
|
160 showSecondSource(); |
|
161 } |
|
162 |
|
163 function showSecondSource() { |
|
164 gDebugger.once(gDebugger.EVENTS.SOURCE_SHOWN, () => { |
|
165 is(gEditor.getText().indexOf("debugger"), 447, |
|
166 "The correct source is shown in the source editor.") |
|
167 is(gEditor.getBreakpoints().length, 0, |
|
168 "No breakpoints should be shown for the second source."); |
|
169 |
|
170 ensureCaretAt(gPanel, 1, 1, true).then(showFirstSourceAgain); |
|
171 }); |
|
172 |
|
173 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
174 gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[1], |
|
175 gDebugger); |
|
176 } |
|
177 |
|
178 function showFirstSourceAgain() { |
|
179 gDebugger.once(gDebugger.EVENTS.SOURCE_SHOWN, () => { |
|
180 is(gEditor.getText().indexOf("debugger"), 148, |
|
181 "The correct source is shown in the source editor.") |
|
182 is(gEditor.getBreakpoints().length, 1, |
|
183 "One breakpoint should be shown for the first source."); |
|
184 |
|
185 ensureCaretAt(gPanel, 6, 1, true).then(() => resumeDebuggerThenCloseAndFinish(gPanel)); |
|
186 }); |
|
187 |
|
188 EventUtils.sendMouseEvent({ type: "mousedown" }, |
|
189 gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[0], |
|
190 gDebugger); |
|
191 } |
|
192 |
|
193 registerCleanupFunction(function() { |
|
194 gTab = null; |
|
195 gDebuggee = null; |
|
196 gPanel = null; |
|
197 gDebugger = null; |
|
198 gEditor = null; |
|
199 gSources = null; |
|
200 }); |