1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/debugger/test/browser_dbg_location-changes-04-breakpoint.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,200 @@ 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 + * Make sure that reloading a page with a breakpoint set does not cause it to 1.9 + * fire more than once. 1.10 + */ 1.11 + 1.12 +const TAB_URL = EXAMPLE_URL + "doc_included-script.html"; 1.13 +const SOURCE_URL = EXAMPLE_URL + "code_location-changes.js"; 1.14 + 1.15 +let gTab, gDebuggee, gPanel, gDebugger; 1.16 +let gEditor, gSources; 1.17 + 1.18 +function test() { 1.19 + initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { 1.20 + gTab = aTab; 1.21 + gDebuggee = aDebuggee; 1.22 + gPanel = aPanel; 1.23 + gDebugger = gPanel.panelWin; 1.24 + gEditor = gDebugger.DebuggerView.editor; 1.25 + gSources = gDebugger.DebuggerView.Sources; 1.26 + 1.27 + waitForSourceAndCaretAndScopes(gPanel, ".html", 17).then(addBreakpoint); 1.28 + gDebuggee.runDebuggerStatement(); 1.29 + }); 1.30 +} 1.31 + 1.32 +function addBreakpoint() { 1.33 + waitForSourceAndCaret(gPanel, ".js", 5).then(() => { 1.34 + ok(true, 1.35 + "Switched to the desired function when adding a breakpoint " + 1.36 + "but not passing { noEditorUpdate: true } as an option."); 1.37 + 1.38 + testResume(); 1.39 + }); 1.40 + 1.41 + gPanel.addBreakpoint({ url: SOURCE_URL, line: 5 }); 1.42 +} 1.43 + 1.44 +function testResume() { 1.45 + is(gDebugger.gThreadClient.state, "paused", 1.46 + "The breakpoint wasn't hit yet (1)."); 1.47 + is(gSources.selectedValue, SOURCE_URL, 1.48 + "The currently shown source is incorrect (1)."); 1.49 + ok(isCaretPos(gPanel, 5), 1.50 + "The source editor caret position is incorrect (1)."); 1.51 + 1.52 + gDebugger.gThreadClient.resume(testClick); 1.53 +} 1.54 + 1.55 +function testClick() { 1.56 + isnot(gDebugger.gThreadClient.state, "paused", 1.57 + "The breakpoint wasn't hit yet (2)."); 1.58 + is(gSources.selectedValue, SOURCE_URL, 1.59 + "The currently shown source is incorrect (2)."); 1.60 + ok(isCaretPos(gPanel, 5), 1.61 + "The source editor caret position is incorrect (2)."); 1.62 + 1.63 + gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { 1.64 + is(aPacket.why.type, "breakpoint", 1.65 + "Execution has advanced to the breakpoint."); 1.66 + isnot(aPacket.why.type, "debuggerStatement", 1.67 + "The breakpoint was hit before the debugger statement."); 1.68 + 1.69 + ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHit); 1.70 + }); 1.71 + 1.72 + EventUtils.sendMouseEvent({ type: "click" }, 1.73 + gDebuggee.document.querySelector("button"), 1.74 + gDebuggee); 1.75 +} 1.76 + 1.77 +function afterBreakpointHit() { 1.78 + is(gDebugger.gThreadClient.state, "paused", 1.79 + "The breakpoint was hit (3)."); 1.80 + is(gSources.selectedValue, SOURCE_URL, 1.81 + "The currently shown source is incorrect (3)."); 1.82 + ok(isCaretPos(gPanel, 5), 1.83 + "The source editor caret position is incorrect (3)."); 1.84 + 1.85 + gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { 1.86 + is(aPacket.why.type, "debuggerStatement", 1.87 + "Execution has advanced to the next line."); 1.88 + isnot(aPacket.why.type, "breakpoint", 1.89 + "No ghost breakpoint was hit."); 1.90 + 1.91 + ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHit); 1.92 + }); 1.93 + 1.94 + gDebugger.gThreadClient.resume(); 1.95 +} 1.96 + 1.97 +function afterDebuggerStatementHit() { 1.98 + is(gDebugger.gThreadClient.state, "paused", 1.99 + "The debugger statement was hit (4)."); 1.100 + is(gSources.selectedValue, SOURCE_URL, 1.101 + "The currently shown source is incorrect (4)."); 1.102 + ok(isCaretPos(gPanel, 6), 1.103 + "The source editor caret position is incorrect (4)."); 1.104 + 1.105 + promise.all([ 1.106 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.NEW_SOURCE), 1.107 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCES_ADDED), 1.108 + waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN), 1.109 + reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN) 1.110 + ]).then(testClickAgain); 1.111 +} 1.112 + 1.113 +function testClickAgain() { 1.114 + isnot(gDebugger.gThreadClient.state, "paused", 1.115 + "The breakpoint wasn't hit yet (5)."); 1.116 + is(gSources.selectedValue, SOURCE_URL, 1.117 + "The currently shown source is incorrect (5)."); 1.118 + ok(isCaretPos(gPanel, 1), 1.119 + "The source editor caret position is incorrect (5)."); 1.120 + 1.121 + gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { 1.122 + is(aPacket.why.type, "breakpoint", 1.123 + "Execution has advanced to the breakpoint."); 1.124 + isnot(aPacket.why.type, "debuggerStatement", 1.125 + "The breakpoint was hit before the debugger statement."); 1.126 + 1.127 + ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHitAgain); 1.128 + }); 1.129 + 1.130 + EventUtils.sendMouseEvent({ type: "click" }, 1.131 + gDebuggee.document.querySelector("button"), 1.132 + gDebuggee); 1.133 +} 1.134 + 1.135 +function afterBreakpointHitAgain() { 1.136 + is(gDebugger.gThreadClient.state, "paused", 1.137 + "The breakpoint was hit (6)."); 1.138 + is(gSources.selectedValue, SOURCE_URL, 1.139 + "The currently shown source is incorrect (6)."); 1.140 + ok(isCaretPos(gPanel, 5), 1.141 + "The source editor caret position is incorrect (6)."); 1.142 + 1.143 + gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { 1.144 + is(aPacket.why.type, "debuggerStatement", 1.145 + "Execution has advanced to the next line."); 1.146 + isnot(aPacket.why.type, "breakpoint", 1.147 + "No ghost breakpoint was hit."); 1.148 + 1.149 + ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHitAgain); 1.150 + }); 1.151 + 1.152 + gDebugger.gThreadClient.resume(); 1.153 +} 1.154 + 1.155 +function afterDebuggerStatementHitAgain() { 1.156 + is(gDebugger.gThreadClient.state, "paused", 1.157 + "The debugger statement was hit (7)."); 1.158 + is(gSources.selectedValue, SOURCE_URL, 1.159 + "The currently shown source is incorrect (7)."); 1.160 + ok(isCaretPos(gPanel, 6), 1.161 + "The source editor caret position is incorrect (7)."); 1.162 + 1.163 + showSecondSource(); 1.164 +} 1.165 + 1.166 +function showSecondSource() { 1.167 + gDebugger.once(gDebugger.EVENTS.SOURCE_SHOWN, () => { 1.168 + is(gEditor.getText().indexOf("debugger"), 447, 1.169 + "The correct source is shown in the source editor.") 1.170 + is(gEditor.getBreakpoints().length, 0, 1.171 + "No breakpoints should be shown for the second source."); 1.172 + 1.173 + ensureCaretAt(gPanel, 1, 1, true).then(showFirstSourceAgain); 1.174 + }); 1.175 + 1.176 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.177 + gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[1], 1.178 + gDebugger); 1.179 +} 1.180 + 1.181 +function showFirstSourceAgain() { 1.182 + gDebugger.once(gDebugger.EVENTS.SOURCE_SHOWN, () => { 1.183 + is(gEditor.getText().indexOf("debugger"), 148, 1.184 + "The correct source is shown in the source editor.") 1.185 + is(gEditor.getBreakpoints().length, 1, 1.186 + "One breakpoint should be shown for the first source."); 1.187 + 1.188 + ensureCaretAt(gPanel, 6, 1, true).then(() => resumeDebuggerThenCloseAndFinish(gPanel)); 1.189 + }); 1.190 + 1.191 + EventUtils.sendMouseEvent({ type: "mousedown" }, 1.192 + gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[0], 1.193 + gDebugger); 1.194 +} 1.195 + 1.196 +registerCleanupFunction(function() { 1.197 + gTab = null; 1.198 + gDebuggee = null; 1.199 + gPanel = null; 1.200 + gDebugger = null; 1.201 + gEditor = null; 1.202 + gSources = null; 1.203 +});