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.
michael@0 | 1 | /* Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | /** |
michael@0 | 5 | * Bug 723069: Test the debugger breakpoint API and connection to the |
michael@0 | 6 | * source editor. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 13 | let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; |
michael@0 | 14 | |
michael@0 | 15 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 16 | gTab = aTab; |
michael@0 | 17 | gDebuggee = aDebuggee; |
michael@0 | 18 | gPanel = aPanel; |
michael@0 | 19 | gDebugger = gPanel.panelWin; |
michael@0 | 20 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 21 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 22 | gBreakpoints = gDebugger.DebuggerController.Breakpoints; |
michael@0 | 23 | gBreakpointsAdded = gBreakpoints._added; |
michael@0 | 24 | gBreakpointsRemoving = gBreakpoints._removing; |
michael@0 | 25 | |
michael@0 | 26 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest); |
michael@0 | 27 | gDebuggee.firstCall(); |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | function performTest() { |
michael@0 | 31 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 32 | "Should only be getting stack frames while paused."); |
michael@0 | 33 | is(gSources.itemCount, 2, |
michael@0 | 34 | "Found the expected number of sources."); |
michael@0 | 35 | is(gEditor.getText().indexOf("debugger"), 172, |
michael@0 | 36 | "The correct source was loaded initially."); |
michael@0 | 37 | is(gSources.selectedValue, gSources.values[1], |
michael@0 | 38 | "The correct source is selected."); |
michael@0 | 39 | |
michael@0 | 40 | is(gBreakpointsAdded.size, 0, |
michael@0 | 41 | "No breakpoints currently added."); |
michael@0 | 42 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 43 | "No breakpoints currently being removed."); |
michael@0 | 44 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 45 | "No breakpoints currently shown in the editor."); |
michael@0 | 46 | |
michael@0 | 47 | ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), |
michael@0 | 48 | "_getAdded('foo', 3) returns falsey."); |
michael@0 | 49 | ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), |
michael@0 | 50 | "_getRemoving('bar', 3) returns falsey."); |
michael@0 | 51 | |
michael@0 | 52 | is(gSources.values[1], gSources.selectedValue, |
michael@0 | 53 | "The second source should be currently selected."); |
michael@0 | 54 | |
michael@0 | 55 | info("Add the first breakpoint."); |
michael@0 | 56 | let location = { url: gSources.selectedValue, line: 6 }; |
michael@0 | 57 | gEditor.once("breakpointAdded", onEditorBreakpointAddFirst); |
michael@0 | 58 | gPanel.addBreakpoint(location).then(onBreakpointAddFirst); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | let breakpointsAdded = 0; |
michael@0 | 62 | let breakpointsRemoved = 0; |
michael@0 | 63 | let editorBreakpointChanges = 0; |
michael@0 | 64 | |
michael@0 | 65 | function onEditorBreakpointAddFirst(aEvent, aLine) { |
michael@0 | 66 | editorBreakpointChanges++; |
michael@0 | 67 | |
michael@0 | 68 | ok(aEvent, |
michael@0 | 69 | "breakpoint1 added to the editor."); |
michael@0 | 70 | is(aLine, 5, |
michael@0 | 71 | "Editor breakpoint line is correct."); |
michael@0 | 72 | |
michael@0 | 73 | is(gEditor.getBreakpoints().length, 1, |
michael@0 | 74 | "editor.getBreakpoints().length is correct."); |
michael@0 | 75 | } |
michael@0 | 76 | |
michael@0 | 77 | function onBreakpointAddFirst(aBreakpointClient) { |
michael@0 | 78 | breakpointsAdded++; |
michael@0 | 79 | |
michael@0 | 80 | ok(aBreakpointClient, |
michael@0 | 81 | "breakpoint1 added, client received."); |
michael@0 | 82 | is(aBreakpointClient.location.url, gSources.selectedValue, |
michael@0 | 83 | "breakpoint1 client url is correct."); |
michael@0 | 84 | is(aBreakpointClient.location.line, 6, |
michael@0 | 85 | "breakpoint1 client line is correct."); |
michael@0 | 86 | |
michael@0 | 87 | ok(gBreakpoints._getAdded(aBreakpointClient.location), |
michael@0 | 88 | "breakpoint1 client found in the list of added breakpoints."); |
michael@0 | 89 | ok(!gBreakpoints._getRemoving(aBreakpointClient.location), |
michael@0 | 90 | "breakpoint1 client found in the list of removing breakpoints."); |
michael@0 | 91 | |
michael@0 | 92 | is(gBreakpointsAdded.size, 1, |
michael@0 | 93 | "The list of added breakpoints holds only one breakpoint."); |
michael@0 | 94 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 95 | "The list of removing breakpoints holds no breakpoint."); |
michael@0 | 96 | |
michael@0 | 97 | gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => { |
michael@0 | 98 | is(aClient, aBreakpointClient, |
michael@0 | 99 | "_getAdded() returns the correct breakpoint."); |
michael@0 | 100 | }); |
michael@0 | 101 | |
michael@0 | 102 | is(gSources.values[1], gSources.selectedValue, |
michael@0 | 103 | "The second source should be currently selected."); |
michael@0 | 104 | |
michael@0 | 105 | info("Remove the first breakpoint."); |
michael@0 | 106 | gEditor.once("breakpointRemoved", onEditorBreakpointRemoveFirst); |
michael@0 | 107 | gPanel.removeBreakpoint(aBreakpointClient.location).then(onBreakpointRemoveFirst); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function onEditorBreakpointRemoveFirst(aEvent, aLine) { |
michael@0 | 111 | editorBreakpointChanges++; |
michael@0 | 112 | |
michael@0 | 113 | ok(aEvent, |
michael@0 | 114 | "breakpoint1 removed from the editor."); |
michael@0 | 115 | is(aLine, 5, |
michael@0 | 116 | "Editor breakpoint line is correct."); |
michael@0 | 117 | |
michael@0 | 118 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 119 | "editor.getBreakpoints().length is correct."); |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | function onBreakpointRemoveFirst(aLocation) { |
michael@0 | 123 | breakpointsRemoved++; |
michael@0 | 124 | |
michael@0 | 125 | ok(aLocation, |
michael@0 | 126 | "breakpoint1 removed"); |
michael@0 | 127 | is(aLocation.url, gSources.selectedValue, |
michael@0 | 128 | "breakpoint1 removal url is correct."); |
michael@0 | 129 | is(aLocation.line, 6, |
michael@0 | 130 | "breakpoint1 removal line is correct."); |
michael@0 | 131 | |
michael@0 | 132 | testBreakpointAddBackground(); |
michael@0 | 133 | } |
michael@0 | 134 | |
michael@0 | 135 | function testBreakpointAddBackground() { |
michael@0 | 136 | is(gBreakpointsAdded.size, 0, |
michael@0 | 137 | "No breakpoints currently added."); |
michael@0 | 138 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 139 | "No breakpoints currently being removed."); |
michael@0 | 140 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 141 | "No breakpoints currently shown in the editor."); |
michael@0 | 142 | |
michael@0 | 143 | ok(!gBreakpoints._getAdded({ url: gSources.selectedValue, line: 6 }), |
michael@0 | 144 | "_getAdded('gSources.selectedValue', 6) returns falsey."); |
michael@0 | 145 | ok(!gBreakpoints._getRemoving({ url: gSources.selectedValue, line: 6 }), |
michael@0 | 146 | "_getRemoving('gSources.selectedValue', 6) returns falsey."); |
michael@0 | 147 | |
michael@0 | 148 | is(gSources.values[1], gSources.selectedValue, |
michael@0 | 149 | "The second source should be currently selected."); |
michael@0 | 150 | |
michael@0 | 151 | info("Add a breakpoint to the first source, which is not selected."); |
michael@0 | 152 | let location = { url: gSources.values[0], line: 5 }; |
michael@0 | 153 | let options = { noEditorUpdate: true }; |
michael@0 | 154 | gEditor.on("breakpointAdded", onEditorBreakpointAddBackgroundTrap); |
michael@0 | 155 | gPanel.addBreakpoint(location, options).then(onBreakpointAddBackground); |
michael@0 | 156 | } |
michael@0 | 157 | |
michael@0 | 158 | function onEditorBreakpointAddBackgroundTrap() { |
michael@0 | 159 | // Trap listener: no breakpoint must be added to the editor when a |
michael@0 | 160 | // breakpoint is added to a source that is not currently selected. |
michael@0 | 161 | editorBreakpointChanges++; |
michael@0 | 162 | ok(false, "breakpoint2 must not be added to the editor."); |
michael@0 | 163 | } |
michael@0 | 164 | |
michael@0 | 165 | function onBreakpointAddBackground(aBreakpointClient, aResponseError) { |
michael@0 | 166 | breakpointsAdded++; |
michael@0 | 167 | |
michael@0 | 168 | ok(aBreakpointClient, |
michael@0 | 169 | "breakpoint2 added, client received"); |
michael@0 | 170 | is(aBreakpointClient.location.url, gSources.values[0], |
michael@0 | 171 | "breakpoint2 client url is correct."); |
michael@0 | 172 | is(aBreakpointClient.location.line, 5, |
michael@0 | 173 | "breakpoint2 client line is correct."); |
michael@0 | 174 | |
michael@0 | 175 | ok(gBreakpoints._getAdded(aBreakpointClient.location), |
michael@0 | 176 | "breakpoint2 client found in the list of added breakpoints."); |
michael@0 | 177 | ok(!gBreakpoints._getRemoving(aBreakpointClient.location), |
michael@0 | 178 | "breakpoint2 client found in the list of removing breakpoints."); |
michael@0 | 179 | |
michael@0 | 180 | is(gBreakpointsAdded.size, 1, |
michael@0 | 181 | "The list of added breakpoints holds only one breakpoint."); |
michael@0 | 182 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 183 | "The list of removing breakpoints holds no breakpoint."); |
michael@0 | 184 | |
michael@0 | 185 | gBreakpoints._getAdded(aBreakpointClient.location).then(aClient => { |
michael@0 | 186 | is(aClient, aBreakpointClient, |
michael@0 | 187 | "_getAdded() returns the correct breakpoint."); |
michael@0 | 188 | }); |
michael@0 | 189 | |
michael@0 | 190 | is(gSources.values[1], gSources.selectedValue, |
michael@0 | 191 | "The second source should be currently selected."); |
michael@0 | 192 | |
michael@0 | 193 | // Remove the trap listener. |
michael@0 | 194 | gEditor.off("breakpointAdded", onEditorBreakpointAddBackgroundTrap); |
michael@0 | 195 | |
michael@0 | 196 | info("Switch to the first source, which is not yet selected"); |
michael@0 | 197 | gEditor.once("breakpointAdded", onEditorBreakpointAddSwitch); |
michael@0 | 198 | gEditor.once("change", onEditorTextChanged); |
michael@0 | 199 | gSources.selectedIndex = 0; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | function onEditorBreakpointAddSwitch(aEvent, aLine) { |
michael@0 | 203 | editorBreakpointChanges++; |
michael@0 | 204 | |
michael@0 | 205 | ok(aEvent, |
michael@0 | 206 | "breakpoint2 added to the editor."); |
michael@0 | 207 | is(aLine, 4, |
michael@0 | 208 | "Editor breakpoint line is correct."); |
michael@0 | 209 | |
michael@0 | 210 | is(gEditor.getBreakpoints().length, 1, |
michael@0 | 211 | "editor.getBreakpoints().length is correct"); |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | function onEditorTextChanged() { |
michael@0 | 215 | // Wait for the actual text to be shown. |
michael@0 | 216 | if (gEditor.getText() == gDebugger.L10N.getStr("loadingText")) |
michael@0 | 217 | return void gEditor.once("change", onEditorTextChanged); |
michael@0 | 218 | |
michael@0 | 219 | is(gEditor.getText().indexOf("debugger"), -1, |
michael@0 | 220 | "The second source is no longer displayed."); |
michael@0 | 221 | is(gEditor.getText().indexOf("firstCall"), 118, |
michael@0 | 222 | "The first source is displayed."); |
michael@0 | 223 | |
michael@0 | 224 | is(gSources.values[0], gSources.selectedValue, |
michael@0 | 225 | "The first source should be currently selected."); |
michael@0 | 226 | |
michael@0 | 227 | let window = gEditor.container.contentWindow; |
michael@0 | 228 | executeSoon(() => window.mozRequestAnimationFrame(onReadyForClick)); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | function onReadyForClick() { |
michael@0 | 232 | info("Remove the second breakpoint using the mouse."); |
michael@0 | 233 | gEditor.once("breakpointRemoved", onEditorBreakpointRemoveSecond); |
michael@0 | 234 | |
michael@0 | 235 | let iframe = gEditor.container; |
michael@0 | 236 | let testWin = iframe.ownerDocument.defaultView; |
michael@0 | 237 | |
michael@0 | 238 | // Flush the layout for the iframe. |
michael@0 | 239 | info("rect " + iframe.contentDocument.documentElement.getBoundingClientRect()); |
michael@0 | 240 | |
michael@0 | 241 | let utils = testWin |
michael@0 | 242 | .QueryInterface(Ci.nsIInterfaceRequestor) |
michael@0 | 243 | .getInterface(Ci.nsIDOMWindowUtils); |
michael@0 | 244 | |
michael@0 | 245 | let coords = gEditor.getCoordsFromPosition({ line: 4, ch: 0 }); |
michael@0 | 246 | let rect = iframe.getBoundingClientRect(); |
michael@0 | 247 | let left = rect.left + 10; |
michael@0 | 248 | let top = rect.top + coords.top + 4; |
michael@0 | 249 | utils.sendMouseEventToWindow("mousedown", left, top, 0, 1, 0, false, 0, 0); |
michael@0 | 250 | utils.sendMouseEventToWindow("mouseup", left, top, 0, 1, 0, false, 0, 0); |
michael@0 | 251 | } |
michael@0 | 252 | |
michael@0 | 253 | function onEditorBreakpointRemoveSecond(aEvent, aLine) { |
michael@0 | 254 | editorBreakpointChanges++; |
michael@0 | 255 | |
michael@0 | 256 | ok(aEvent, |
michael@0 | 257 | "breakpoint2 removed from the editor."); |
michael@0 | 258 | is(aLine, 4, |
michael@0 | 259 | "Editor breakpoint line is correct."); |
michael@0 | 260 | |
michael@0 | 261 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 262 | "editor.getBreakpoints().length is correct."); |
michael@0 | 263 | |
michael@0 | 264 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { |
michael@0 | 265 | finalCheck(); |
michael@0 | 266 | closeDebuggerAndFinish(gPanel); |
michael@0 | 267 | }); |
michael@0 | 268 | |
michael@0 | 269 | gDebugger.gThreadClient.resume(); |
michael@0 | 270 | } |
michael@0 | 271 | |
michael@0 | 272 | function finalCheck() { |
michael@0 | 273 | is(gBreakpointsAdded.size, 0, |
michael@0 | 274 | "No breakpoints currently added."); |
michael@0 | 275 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 276 | "No breakpoints currently being removed."); |
michael@0 | 277 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 278 | "No breakpoints currently shown in the editor."); |
michael@0 | 279 | |
michael@0 | 280 | ok(!gBreakpoints._getAdded({ url: gSources.values[0], line: 5 }), |
michael@0 | 281 | "_getAdded('gSources.values[0]', 5) returns falsey."); |
michael@0 | 282 | ok(!gBreakpoints._getRemoving({ url: gSources.values[0], line: 5 }), |
michael@0 | 283 | "_getRemoving('gSources.values[0]', 5) returns falsey."); |
michael@0 | 284 | |
michael@0 | 285 | ok(!gBreakpoints._getAdded({ url: gSources.values[1], line: 6 }), |
michael@0 | 286 | "_getAdded('gSources.values[1]', 6) returns falsey."); |
michael@0 | 287 | ok(!gBreakpoints._getRemoving({ url: gSources.values[1], line: 6 }), |
michael@0 | 288 | "_getRemoving('gSources.values[1]', 6) returns falsey."); |
michael@0 | 289 | |
michael@0 | 290 | ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), |
michael@0 | 291 | "_getAdded('foo', 3) returns falsey."); |
michael@0 | 292 | ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), |
michael@0 | 293 | "_getRemoving('bar', 3) returns falsey."); |
michael@0 | 294 | |
michael@0 | 295 | is(breakpointsAdded, 2, |
michael@0 | 296 | "Correct number of breakpoints have been added."); |
michael@0 | 297 | is(breakpointsRemoved, 1, |
michael@0 | 298 | "Correct number of breakpoints have been removed."); |
michael@0 | 299 | is(editorBreakpointChanges, 4, |
michael@0 | 300 | "Correct number of editor breakpoint changes."); |
michael@0 | 301 | } |
michael@0 | 302 | } |