1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_server-conditional-bp-01.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,246 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Bug 740825: Test adding conditional breakpoints (with server-side support) 1.9 + */ 1.10 + 1.11 +const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html"; 1.12 + 1.13 +function test() { 1.14 + // Linux debug test slaves are a bit slow at this test sometimes. 1.15 + requestLongerTimeout(2); 1.16 + 1.17 + let gTab, gDebuggee, gPanel, gDebugger; 1.18 + let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; 1.19 + 1.20 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.21 + gTab = aTab; 1.22 + gDebuggee = aDebuggee; 1.23 + gPanel = aPanel; 1.24 + gDebugger = gPanel.panelWin; 1.25 + gEditor = gDebugger.DebuggerView.editor; 1.26 + gSources = gDebugger.DebuggerView.Sources; 1.27 + gBreakpoints = gDebugger.DebuggerController.Breakpoints; 1.28 + gBreakpointsAdded = gBreakpoints._added; 1.29 + gBreakpointsRemoving = gBreakpoints._removing; 1.30 + 1.31 + waitForSourceAndCaretAndScopes(gPanel, ".html", 17) 1.32 + .then(() => addBreakpoints()) 1.33 + .then(() => initialChecks()) 1.34 + .then(() => resumeAndTestBreakpoint(20)) 1.35 + .then(() => resumeAndTestBreakpoint(21)) 1.36 + .then(() => resumeAndTestBreakpoint(22)) 1.37 + .then(() => resumeAndTestBreakpoint(23)) 1.38 + .then(() => resumeAndTestBreakpoint(24)) 1.39 + .then(() => resumeAndTestBreakpoint(25)) 1.40 + .then(() => resumeAndTestBreakpoint(27)) 1.41 + .then(() => resumeAndTestBreakpoint(28)) 1.42 + .then(() => resumeAndTestBreakpoint(29)) 1.43 + .then(() => resumeAndTestNoBreakpoint()) 1.44 + .then(() => reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN, 13)) 1.45 + .then(() => testAfterReload()) 1.46 + .then(() => closeDebuggerAndFinish(gPanel)) 1.47 + .then(null, aError => { 1.48 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.49 + }); 1.50 + 1.51 + gDebuggee.ermahgerd(); 1.52 + }); 1.53 + 1.54 + function addBreakpoints() { 1.55 + return promise.resolve(null) 1.56 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.57 + line: 18, 1.58 + condition: "undefined" 1.59 + })) 1.60 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.61 + line: 19, 1.62 + condition: "null" 1.63 + })) 1.64 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.65 + line: 20, 1.66 + condition: "42" 1.67 + })) 1.68 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.69 + line: 21, 1.70 + condition: "true" 1.71 + })) 1.72 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.73 + line: 22, 1.74 + condition: "'nasu'" 1.75 + })) 1.76 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.77 + line: 23, 1.78 + condition: "/regexp/" 1.79 + })) 1.80 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.81 + line: 24, 1.82 + condition: "({})" 1.83 + })) 1.84 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.85 + line: 25, 1.86 + condition: "(function() {})" 1.87 + })) 1.88 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.89 + line: 26, 1.90 + condition: "(function() { return false; })()" 1.91 + })) 1.92 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.93 + line: 27, 1.94 + condition: "a" 1.95 + })) 1.96 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.97 + line: 28, 1.98 + condition: "a !== undefined" 1.99 + })) 1.100 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.101 + line: 29, 1.102 + condition: "a !== null" 1.103 + })) 1.104 + .then(() => gPanel.addBreakpoint({ url: gSources.selectedValue, 1.105 + line: 30, 1.106 + condition: "b" 1.107 + })); 1.108 + } 1.109 + 1.110 + function initialChecks() { 1.111 + is(gDebugger.gThreadClient.state, "paused", 1.112 + "Should only be getting stack frames while paused."); 1.113 + is(gSources.itemCount, 1, 1.114 + "Found the expected number of sources."); 1.115 + is(gEditor.getText().indexOf("ermahgerd"), 253, 1.116 + "The correct source was loaded initially."); 1.117 + is(gSources.selectedValue, gSources.values[0], 1.118 + "The correct source is selected."); 1.119 + 1.120 + is(gBreakpointsAdded.size, 13, 1.121 + "13 breakpoints currently added."); 1.122 + is(gBreakpointsRemoving.size, 0, 1.123 + "No breakpoints currently being removed."); 1.124 + is(gEditor.getBreakpoints().length, 13, 1.125 + "13 breakpoints currently shown in the editor."); 1.126 + 1.127 + ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), 1.128 + "_getAdded('foo', 3) returns falsey."); 1.129 + ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), 1.130 + "_getRemoving('bar', 3) returns falsey."); 1.131 + } 1.132 + 1.133 + function resumeAndTestBreakpoint(aLine) { 1.134 + let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine)); 1.135 + 1.136 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.137 + gDebugger.document.getElementById("resume"), 1.138 + gDebugger); 1.139 + 1.140 + return finished; 1.141 + } 1.142 + 1.143 + function resumeAndTestNoBreakpoint() { 1.144 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { 1.145 + is(gSources.itemCount, 1, 1.146 + "Found the expected number of sources."); 1.147 + is(gEditor.getText().indexOf("ermahgerd"), 253, 1.148 + "The correct source was loaded initially."); 1.149 + is(gSources.selectedValue, gSources.values[0], 1.150 + "The correct source is selected."); 1.151 + 1.152 + ok(gSources.selectedItem, 1.153 + "There should be a selected source in the sources pane.") 1.154 + ok(!gSources._selectedBreakpointItem, 1.155 + "There should be no selected breakpoint in the sources pane.") 1.156 + is(gSources._conditionalPopupVisible, false, 1.157 + "The breakpoint conditional expression popup should not be shown."); 1.158 + 1.159 + is(gDebugger.document.querySelectorAll(".dbg-stackframe").length, 0, 1.160 + "There should be no visible stackframes."); 1.161 + is(gDebugger.document.querySelectorAll(".dbg-breakpoint").length, 13, 1.162 + "There should be thirteen visible breakpoints."); 1.163 + }); 1.164 + 1.165 + gDebugger.gThreadClient.resume(); 1.166 + 1.167 + return finished; 1.168 + } 1.169 + 1.170 + function testBreakpoint(aLine, aHighlightBreakpoint) { 1.171 + // Highlight the breakpoint only if required. 1.172 + if (aHighlightBreakpoint) { 1.173 + let finished = waitForCaretUpdated(gPanel, aLine).then(() => testBreakpoint(aLine)); 1.174 + gSources.highlightBreakpoint({ url: gSources.selectedValue, line: aLine }); 1.175 + return finished; 1.176 + } 1.177 + 1.178 + let selectedUrl = gSources.selectedValue; 1.179 + let selectedBreakpoint = gSources._selectedBreakpointItem; 1.180 + 1.181 + ok(selectedUrl, 1.182 + "There should be a selected item in the sources pane."); 1.183 + ok(selectedBreakpoint, 1.184 + "There should be a selected brekapoint in the sources pane."); 1.185 + 1.186 + is(selectedBreakpoint.attachment.url, selectedUrl, 1.187 + "The breakpoint on line " + aLine + " wasn't added on the correct source."); 1.188 + is(selectedBreakpoint.attachment.line, aLine, 1.189 + "The breakpoint on line " + aLine + " wasn't found."); 1.190 + is(!!selectedBreakpoint.attachment.disabled, false, 1.191 + "The breakpoint on line " + aLine + " should be enabled."); 1.192 + is(!!selectedBreakpoint.attachment.openPopup, false, 1.193 + "The breakpoint on line " + aLine + " should not have opened a popup."); 1.194 + is(gSources._conditionalPopupVisible, false, 1.195 + "The breakpoint conditional expression popup should not have been shown."); 1.196 + 1.197 + return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => { 1.198 + is(aBreakpointClient.location.url, selectedUrl, 1.199 + "The breakpoint's client url is correct"); 1.200 + is(aBreakpointClient.location.line, aLine, 1.201 + "The breakpoint's client line is correct"); 1.202 + isnot(aBreakpointClient.condition, undefined, 1.203 + "The breakpoint on line " + aLine + " should have a conditional expression."); 1.204 + 1.205 + ok(isCaretPos(gPanel, aLine), 1.206 + "The editor caret position is not properly set."); 1.207 + }); 1.208 + } 1.209 + 1.210 + function testAfterReload() { 1.211 + let selectedUrl = gSources.selectedValue; 1.212 + let selectedBreakpoint = gSources._selectedBreakpointItem; 1.213 + 1.214 + ok(selectedUrl, 1.215 + "There should be a selected item in the sources pane after reload."); 1.216 + ok(!selectedBreakpoint, 1.217 + "There should be no selected brekapoint in the sources pane after reload."); 1.218 + 1.219 + return promise.resolve(null) 1.220 + .then(() => testBreakpoint(18, true)) 1.221 + .then(() => testBreakpoint(19, true)) 1.222 + .then(() => testBreakpoint(20, true)) 1.223 + .then(() => testBreakpoint(21, true)) 1.224 + .then(() => testBreakpoint(22, true)) 1.225 + .then(() => testBreakpoint(23, true)) 1.226 + .then(() => testBreakpoint(24, true)) 1.227 + .then(() => testBreakpoint(25, true)) 1.228 + .then(() => testBreakpoint(26, true)) 1.229 + .then(() => testBreakpoint(27, true)) 1.230 + .then(() => testBreakpoint(28, true)) 1.231 + .then(() => testBreakpoint(29, true)) 1.232 + .then(() => testBreakpoint(30, true)) 1.233 + .then(() => { 1.234 + is(gSources.itemCount, 1, 1.235 + "Found the expected number of sources."); 1.236 + is(gEditor.getText().indexOf("ermahgerd"), 253, 1.237 + "The correct source was loaded again."); 1.238 + is(gSources.selectedValue, gSources.values[0], 1.239 + "The correct source is selected."); 1.240 + 1.241 + ok(gSources.selectedItem, 1.242 + "There should be a selected source in the sources pane.") 1.243 + ok(gSources._selectedBreakpointItem, 1.244 + "There should be a selected breakpoint in the sources pane.") 1.245 + is(gSources._conditionalPopupVisible, false, 1.246 + "The breakpoint conditional expression popup should not be shown."); 1.247 + }); 1.248 + } 1.249 +}