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