1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_server-conditional-bp-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,192 @@ 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 812172: Test adding and modifying 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 + let gTab, gDebuggee, gPanel, gDebugger; 1.15 + let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; 1.16 + 1.17 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.18 + gTab = aTab; 1.19 + gDebuggee = aDebuggee; 1.20 + gPanel = aPanel; 1.21 + gDebugger = gPanel.panelWin; 1.22 + gEditor = gDebugger.DebuggerView.editor; 1.23 + gSources = gDebugger.DebuggerView.Sources; 1.24 + gBreakpoints = gDebugger.DebuggerController.Breakpoints; 1.25 + gBreakpointsAdded = gBreakpoints._added; 1.26 + gBreakpointsRemoving = gBreakpoints._removing; 1.27 + 1.28 + waitForSourceAndCaretAndScopes(gPanel, ".html", 17) 1.29 + .then(() => initialChecks()) 1.30 + .then(() => addBreakpoint1()) 1.31 + .then(() => testBreakpoint(18, false, false, undefined)) 1.32 + .then(() => addBreakpoint2()) 1.33 + .then(() => testBreakpoint(19, false, false, undefined)) 1.34 + .then(() => modBreakpoint2()) 1.35 + .then(() => testBreakpoint(19, false, true, undefined)) 1.36 + .then(() => addBreakpoint3()) 1.37 + .then(() => testBreakpoint(20, true, false, undefined)) 1.38 + .then(() => modBreakpoint3()) 1.39 + .then(() => testBreakpoint(20, true, false, "bamboocha")) 1.40 + .then(() => addBreakpoint4()) 1.41 + .then(() => testBreakpoint(21, false, false, undefined)) 1.42 + .then(() => delBreakpoint4()) 1.43 + .then(() => setCaretPosition(18)) 1.44 + .then(() => testBreakpoint(18, false, false, undefined)) 1.45 + .then(() => setCaretPosition(19)) 1.46 + .then(() => testBreakpoint(19, false, false, undefined)) 1.47 + .then(() => setCaretPosition(20)) 1.48 + .then(() => testBreakpoint(20, true, false, "bamboocha")) 1.49 + .then(() => setCaretPosition(17)) 1.50 + .then(() => testNoBreakpoint(17)) 1.51 + .then(() => setCaretPosition(21)) 1.52 + .then(() => testNoBreakpoint(21)) 1.53 + .then(() => clickOnBreakpoint(0)) 1.54 + .then(() => testBreakpoint(18, false, false, undefined)) 1.55 + .then(() => clickOnBreakpoint(1)) 1.56 + .then(() => testBreakpoint(19, false, false, undefined)) 1.57 + .then(() => clickOnBreakpoint(2)) 1.58 + .then(() => testBreakpoint(20, true, true, "bamboocha")) 1.59 + .then(() => resumeDebuggerThenCloseAndFinish(gPanel)) 1.60 + .then(null, aError => { 1.61 + ok(false, "Got an error: " + aError.message + "\n" + aError.stack); 1.62 + }); 1.63 + 1.64 + gDebuggee.ermahgerd(); 1.65 + }); 1.66 + 1.67 + function initialChecks() { 1.68 + is(gDebugger.gThreadClient.state, "paused", 1.69 + "Should only be getting stack frames while paused."); 1.70 + is(gSources.itemCount, 1, 1.71 + "Found the expected number of sources."); 1.72 + is(gEditor.getText().indexOf("ermahgerd"), 253, 1.73 + "The correct source was loaded initially."); 1.74 + is(gSources.selectedValue, gSources.values[0], 1.75 + "The correct source is selected."); 1.76 + 1.77 + is(gBreakpointsAdded.size, 0, 1.78 + "No breakpoints currently added."); 1.79 + is(gBreakpointsRemoving.size, 0, 1.80 + "No breakpoints currently being removed."); 1.81 + is(gEditor.getBreakpoints().length, 0, 1.82 + "No breakpoints currently shown in the editor."); 1.83 + 1.84 + ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), 1.85 + "_getAdded('foo', 3) returns falsey."); 1.86 + ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), 1.87 + "_getRemoving('bar', 3) returns falsey."); 1.88 + } 1.89 + 1.90 + function addBreakpoint1() { 1.91 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); 1.92 + gPanel.addBreakpoint({ url: gSources.selectedValue, line: 18 }); 1.93 + return finished; 1.94 + } 1.95 + 1.96 + function addBreakpoint2() { 1.97 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); 1.98 + setCaretPosition(19); 1.99 + gSources._onCmdAddBreakpoint(); 1.100 + return finished; 1.101 + } 1.102 + 1.103 + function modBreakpoint2() { 1.104 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_SHOWING); 1.105 + setCaretPosition(19); 1.106 + gSources._onCmdAddConditionalBreakpoint(); 1.107 + return finished; 1.108 + } 1.109 + 1.110 + function addBreakpoint3() { 1.111 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); 1.112 + setCaretPosition(20); 1.113 + gSources._onCmdAddConditionalBreakpoint(); 1.114 + return finished; 1.115 + } 1.116 + 1.117 + function modBreakpoint3() { 1.118 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_HIDING); 1.119 + typeText(gSources._cbTextbox, "bamboocha"); 1.120 + EventUtils.sendKey("RETURN", gDebugger); 1.121 + return finished; 1.122 + } 1.123 + 1.124 + function addBreakpoint4() { 1.125 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED); 1.126 + setCaretPosition(21); 1.127 + gSources._onCmdAddBreakpoint(); 1.128 + return finished; 1.129 + } 1.130 + 1.131 + function delBreakpoint4() { 1.132 + let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED); 1.133 + setCaretPosition(21); 1.134 + gSources._onCmdAddBreakpoint(); 1.135 + return finished; 1.136 + } 1.137 + 1.138 + function testBreakpoint(aLine, aOpenPopupFlag, aPopupVisible, aConditionalExpression) { 1.139 + let selectedUrl = gSources.selectedValue; 1.140 + let selectedBreakpoint = gSources._selectedBreakpointItem; 1.141 + 1.142 + ok(selectedUrl, 1.143 + "There should be a selected item in the sources pane."); 1.144 + ok(selectedBreakpoint, 1.145 + "There should be a selected brekapoint in the sources pane."); 1.146 + 1.147 + is(selectedBreakpoint.attachment.url, selectedUrl, 1.148 + "The breakpoint on line " + aLine + " wasn't added on the correct source."); 1.149 + is(selectedBreakpoint.attachment.line, aLine, 1.150 + "The breakpoint on line " + aLine + " wasn't found."); 1.151 + is(!!selectedBreakpoint.attachment.disabled, false, 1.152 + "The breakpoint on line " + aLine + " should be enabled."); 1.153 + is(!!selectedBreakpoint.attachment.openPopup, aOpenPopupFlag, 1.154 + "The breakpoint on line " + aLine + " should have a correct popup state (1)."); 1.155 + is(gSources._conditionalPopupVisible, aPopupVisible, 1.156 + "The breakpoint on line " + aLine + " should have a correct popup state (2)."); 1.157 + 1.158 + return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => { 1.159 + is(aBreakpointClient.location.url, selectedUrl, 1.160 + "The breakpoint's client url is correct"); 1.161 + is(aBreakpointClient.location.line, aLine, 1.162 + "The breakpoint's client line is correct"); 1.163 + is(aBreakpointClient.condition, aConditionalExpression, 1.164 + "The breakpoint on line " + aLine + " should have a correct conditional expression."); 1.165 + is("condition" in aBreakpointClient, !!aConditionalExpression, 1.166 + "The breakpoint on line " + aLine + " should have a correct conditional state."); 1.167 + 1.168 + ok(isCaretPos(gPanel, aLine), 1.169 + "The editor caret position is not properly set."); 1.170 + }); 1.171 + } 1.172 + 1.173 + function testNoBreakpoint(aLine) { 1.174 + let selectedUrl = gSources.selectedValue; 1.175 + let selectedBreakpoint = gSources._selectedBreakpointItem; 1.176 + 1.177 + ok(selectedUrl, 1.178 + "There should be a selected item in the sources pane for line " + aLine + "."); 1.179 + ok(!selectedBreakpoint, 1.180 + "There should be no selected brekapoint in the sources pane for line " + aLine + "."); 1.181 + 1.182 + ok(isCaretPos(gPanel, aLine), 1.183 + "The editor caret position is not properly set."); 1.184 + } 1.185 + 1.186 + function setCaretPosition(aLine) { 1.187 + gEditor.setCursor({ line: aLine - 1, ch: 0 }); 1.188 + } 1.189 + 1.190 + function clickOnBreakpoint(aIndex) { 1.191 + EventUtils.sendMouseEvent({ type: "click" }, 1.192 + gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex], 1.193 + gDebugger); 1.194 + } 1.195 +}