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