browser/devtools/debugger/test/browser_dbg_server-conditional-bp-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 740825: Test adding conditional breakpoints (with server-side support)
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 // Linux debug test slaves are a bit slow at this test sometimes.
michael@0 12 requestLongerTimeout(2);
michael@0 13
michael@0 14 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 15 let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving;
michael@0 16
michael@0 17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 18 gTab = aTab;
michael@0 19 gDebuggee = aDebuggee;
michael@0 20 gPanel = aPanel;
michael@0 21 gDebugger = gPanel.panelWin;
michael@0 22 gEditor = gDebugger.DebuggerView.editor;
michael@0 23 gSources = gDebugger.DebuggerView.Sources;
michael@0 24 gBreakpoints = gDebugger.DebuggerController.Breakpoints;
michael@0 25 gBreakpointsAdded = gBreakpoints._added;
michael@0 26 gBreakpointsRemoving = gBreakpoints._removing;
michael@0 27
michael@0 28 waitForSourceAndCaretAndScopes(gPanel, ".html", 17)
michael@0 29 .then(() => addBreakpoints())
michael@0 30 .then(() => initialChecks())
michael@0 31 .then(() => resumeAndTestBreakpoint(20))
michael@0 32 .then(() => resumeAndTestBreakpoint(21))
michael@0 33 .then(() => resumeAndTestBreakpoint(22))
michael@0 34 .then(() => resumeAndTestBreakpoint(23))
michael@0 35 .then(() => resumeAndTestBreakpoint(24))
michael@0 36 .then(() => resumeAndTestBreakpoint(25))
michael@0 37 .then(() => resumeAndTestBreakpoint(27))
michael@0 38 .then(() => resumeAndTestBreakpoint(28))
michael@0 39 .then(() => resumeAndTestBreakpoint(29))
michael@0 40 .then(() => resumeAndTestNoBreakpoint())
michael@0 41 .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN, 13))
michael@0 42 .then(() => testAfterReload())
michael@0 43 .then(() => closeDebuggerAndFinish(gPanel))
michael@0 44 .then(null, aError => {
michael@0 45 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 46 });
michael@0 47
michael@0 48 gDebuggee.ermahgerd();
michael@0 49 });
michael@0 50
michael@0 51 function addBreakpoints() {
michael@0 52 return promise.resolve(null)
michael@0 53 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 54 line: 18,
michael@0 55 condition: "undefined"
michael@0 56 }))
michael@0 57 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 58 line: 19,
michael@0 59 condition: "null"
michael@0 60 }))
michael@0 61 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 62 line: 20,
michael@0 63 condition: "42"
michael@0 64 }))
michael@0 65 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 66 line: 21,
michael@0 67 condition: "true"
michael@0 68 }))
michael@0 69 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 70 line: 22,
michael@0 71 condition: "'nasu'"
michael@0 72 }))
michael@0 73 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 74 line: 23,
michael@0 75 condition: "/regexp/"
michael@0 76 }))
michael@0 77 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 78 line: 24,
michael@0 79 condition: "({})"
michael@0 80 }))
michael@0 81 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 82 line: 25,
michael@0 83 condition: "(function() {})"
michael@0 84 }))
michael@0 85 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 86 line: 26,
michael@0 87 condition: "(function() { return false; })()"
michael@0 88 }))
michael@0 89 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 90 line: 27,
michael@0 91 condition: "a"
michael@0 92 }))
michael@0 93 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 94 line: 28,
michael@0 95 condition: "a !== undefined"
michael@0 96 }))
michael@0 97 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 98 line: 29,
michael@0 99 condition: "a !== null"
michael@0 100 }))
michael@0 101 .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue,
michael@0 102 line: 30,
michael@0 103 condition: "b"
michael@0 104 }));
michael@0 105 }
michael@0 106
michael@0 107 function initialChecks() {
michael@0 108 is(gDebugger.gThreadClient.state, "paused",
michael@0 109 "Should only be getting stack frames while paused.");
michael@0 110 is(gSources.itemCount, 1,
michael@0 111 "Found the expected number of sources.");
michael@0 112 is(gEditor.getText().indexOf("ermahgerd"), 253,
michael@0 113 "The correct source was loaded initially.");
michael@0 114 is(gSources.selectedValue, gSources.values[0],
michael@0 115 "The correct source is selected.");
michael@0 116
michael@0 117 is(gBreakpointsAdded.size, 13,
michael@0 118 "13 breakpoints currently added.");
michael@0 119 is(gBreakpointsRemoving.size, 0,
michael@0 120 "No breakpoints currently being removed.");
michael@0 121 is(gEditor.getBreakpoints().length, 13,
michael@0 122 "13 breakpoints currently shown in the editor.");
michael@0 123
michael@0 124 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
michael@0 125 "_getAdded('foo', 3) returns falsey.");
michael@0 126 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
michael@0 127 "_getRemoving('bar', 3) returns falsey.");
michael@0 128 }
michael@0 129
michael@0 130 function resumeAndTestBreakpoint(aLine) {
michael@0 131 let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine));
michael@0 132
michael@0 133 EventUtils.sendMouseEvent({ type: "mousedown" },
michael@0 134 gDebugger.document.getElementById("resume"),
michael@0 135 gDebugger);
michael@0 136
michael@0 137 return finished;
michael@0 138 }
michael@0 139
michael@0 140 function resumeAndTestNoBreakpoint() {
michael@0 141 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => {
michael@0 142 is(gSources.itemCount, 1,
michael@0 143 "Found the expected number of sources.");
michael@0 144 is(gEditor.getText().indexOf("ermahgerd"), 253,
michael@0 145 "The correct source was loaded initially.");
michael@0 146 is(gSources.selectedValue, gSources.values[0],
michael@0 147 "The correct source is selected.");
michael@0 148
michael@0 149 ok(gSources.selectedItem,
michael@0 150 "There should be a selected source in the sources pane.")
michael@0 151 ok(!gSources._selectedBreakpointItem,
michael@0 152 "There should be no selected breakpoint in the sources pane.")
michael@0 153 is(gSources._conditionalPopupVisible, false,
michael@0 154 "The breakpoint conditional expression popup should not be shown.");
michael@0 155
michael@0 156 is(gDebugger.document.querySelectorAll(".dbg-stackframe").length, 0,
michael@0 157 "There should be no visible stackframes.");
michael@0 158 is(gDebugger.document.querySelectorAll(".dbg-breakpoint").length, 13,
michael@0 159 "There should be thirteen visible breakpoints.");
michael@0 160 });
michael@0 161
michael@0 162 gDebugger.gThreadClient.resume();
michael@0 163
michael@0 164 return finished;
michael@0 165 }
michael@0 166
michael@0 167 function testBreakpoint(aLine, aHighlightBreakpoint) {
michael@0 168 // Highlight the breakpoint only if required.
michael@0 169 if (aHighlightBreakpoint) {
michael@0 170 let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine));
michael@0 171 gSources.highlightBreakpoint({ url: gSources.selectedValue, line: aLine });
michael@0 172 return finished;
michael@0 173 }
michael@0 174
michael@0 175 let selectedUrl = gSources.selectedValue;
michael@0 176 let selectedBreakpoint = gSources._selectedBreakpointItem;
michael@0 177
michael@0 178 ok(selectedUrl,
michael@0 179 "There should be a selected item in the sources pane.");
michael@0 180 ok(selectedBreakpoint,
michael@0 181 "There should be a selected brekapoint in the sources pane.");
michael@0 182
michael@0 183 is(selectedBreakpoint.attachment.url, selectedUrl,
michael@0 184 "The breakpoint on line " + aLine + " wasn't added on the correct source.");
michael@0 185 is(selectedBreakpoint.attachment.line, aLine,
michael@0 186 "The breakpoint on line " + aLine + " wasn't found.");
michael@0 187 is(!!selectedBreakpoint.attachment.disabled, false,
michael@0 188 "The breakpoint on line " + aLine + " should be enabled.");
michael@0 189 is(!!selectedBreakpoint.attachment.openPopup, false,
michael@0 190 "The breakpoint on line " + aLine + " should not have opened a popup.");
michael@0 191 is(gSources._conditionalPopupVisible, false,
michael@0 192 "The breakpoint conditional expression popup should not have been shown.");
michael@0 193
michael@0 194 return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => {
michael@0 195 is(aBreakpointClient.location.url, selectedUrl,
michael@0 196 "The breakpoint's client url is correct");
michael@0 197 is(aBreakpointClient.location.line, aLine,
michael@0 198 "The breakpoint's client line is correct");
michael@0 199 isnot(aBreakpointClient.condition, undefined,
michael@0 200 "The breakpoint on line " + aLine + " should have a conditional expression.");
michael@0 201
michael@0 202 ok(isCaretPos(gPanel, aLine),
michael@0 203 "The editor caret position is not properly set.");
michael@0 204 });
michael@0 205 }
michael@0 206
michael@0 207 function testAfterReload() {
michael@0 208 let selectedUrl = gSources.selectedValue;
michael@0 209 let selectedBreakpoint = gSources._selectedBreakpointItem;
michael@0 210
michael@0 211 ok(selectedUrl,
michael@0 212 "There should be a selected item in the sources pane after reload.");
michael@0 213 ok(!selectedBreakpoint,
michael@0 214 "There should be no selected brekapoint in the sources pane after reload.");
michael@0 215
michael@0 216 return promise.resolve(null)
michael@0 217 .then(() => testBreakpoint(18, true))
michael@0 218 .then(() => testBreakpoint(19, true))
michael@0 219 .then(() => testBreakpoint(20, true))
michael@0 220 .then(() => testBreakpoint(21, true))
michael@0 221 .then(() => testBreakpoint(22, true))
michael@0 222 .then(() => testBreakpoint(23, true))
michael@0 223 .then(() => testBreakpoint(24, true))
michael@0 224 .then(() => testBreakpoint(25, true))
michael@0 225 .then(() => testBreakpoint(26, true))
michael@0 226 .then(() => testBreakpoint(27, true))
michael@0 227 .then(() => testBreakpoint(28, true))
michael@0 228 .then(() => testBreakpoint(29, true))
michael@0 229 .then(() => testBreakpoint(30, true))
michael@0 230 .then(() => {
michael@0 231 is(gSources.itemCount, 1,
michael@0 232 "Found the expected number of sources.");
michael@0 233 is(gEditor.getText().indexOf("ermahgerd"), 253,
michael@0 234 "The correct source was loaded again.");
michael@0 235 is(gSources.selectedValue, gSources.values[0],
michael@0 236 "The correct source is selected.");
michael@0 237
michael@0 238 ok(gSources.selectedItem,
michael@0 239 "There should be a selected source in the sources pane.")
michael@0 240 ok(gSources._selectedBreakpointItem,
michael@0 241 "There should be a selected breakpoint in the sources pane.")
michael@0 242 is(gSources._conditionalPopupVisible, false,
michael@0 243 "The breakpoint conditional expression popup should not be shown.");
michael@0 244 });
michael@0 245 }
michael@0 246 }

mercurial