Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
4 /**
5 * Make sure that reloading a page with a breakpoint set does not cause it to
6 * fire more than once.
7 */
9 const TAB_URL = EXAMPLE_URL + "doc_included-script.html";
10 const SOURCE_URL = EXAMPLE_URL + "code_location-changes.js";
12 let gTab, gDebuggee, gPanel, gDebugger;
13 let gEditor, gSources;
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;
24 waitForSourceAndCaretAndScopes(gPanel, ".html", 17).then(addBreakpoint);
25 gDebuggee.runDebuggerStatement();
26 });
27 }
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.");
35 testResume();
36 });
38 gPanel.addBreakpoint({ url: SOURCE_URL, line: 5 });
39 }
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).");
49 gDebugger.gThreadClient.resume(testClick);
50 }
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).");
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.");
66 ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHit);
67 });
69 EventUtils.sendMouseEvent({ type: "click" },
70 gDebuggee.document.querySelector("button"),
71 gDebuggee);
72 }
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).");
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.");
88 ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHit);
89 });
91 gDebugger.gThreadClient.resume();
92 }
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).");
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 }
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).");
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.");
124 ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHitAgain);
125 });
127 EventUtils.sendMouseEvent({ type: "click" },
128 gDebuggee.document.querySelector("button"),
129 gDebuggee);
130 }
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).");
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.");
146 ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHitAgain);
147 });
149 gDebugger.gThreadClient.resume();
150 }
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).");
160 showSecondSource();
161 }
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.");
170 ensureCaretAt(gPanel, 1, 1, true).then(showFirstSourceAgain);
171 });
173 EventUtils.sendMouseEvent({ type: "mousedown" },
174 gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[1],
175 gDebugger);
176 }
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.");
185 ensureCaretAt(gPanel, 6, 1, true).then(() => resumeDebuggerThenCloseAndFinish(gPanel));
186 });
188 EventUtils.sendMouseEvent({ type: "mousedown" },
189 gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[0],
190 gDebugger);
191 }
193 registerCleanupFunction(function() {
194 gTab = null;
195 gDebuggee = null;
196 gPanel = null;
197 gDebugger = null;
198 gEditor = null;
199 gSources = null;
200 });