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 | * Make sure that reloading a page with a breakpoint set does not cause it to |
michael@0 | 6 | * fire more than once. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_included-script.html"; |
michael@0 | 10 | const SOURCE_URL = EXAMPLE_URL + "code_location-changes.js"; |
michael@0 | 11 | |
michael@0 | 12 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 13 | let gEditor, gSources; |
michael@0 | 14 | |
michael@0 | 15 | function test() { |
michael@0 | 16 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 17 | gTab = aTab; |
michael@0 | 18 | gDebuggee = aDebuggee; |
michael@0 | 19 | gPanel = aPanel; |
michael@0 | 20 | gDebugger = gPanel.panelWin; |
michael@0 | 21 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 22 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 23 | |
michael@0 | 24 | waitForSourceAndCaretAndScopes(gPanel, ".html", 17).then(addBreakpoint); |
michael@0 | 25 | gDebuggee.runDebuggerStatement(); |
michael@0 | 26 | }); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function addBreakpoint() { |
michael@0 | 30 | waitForSourceAndCaret(gPanel, ".js", 5).then(() => { |
michael@0 | 31 | ok(true, |
michael@0 | 32 | "Switched to the desired function when adding a breakpoint " + |
michael@0 | 33 | "but not passing { noEditorUpdate: true } as an option."); |
michael@0 | 34 | |
michael@0 | 35 | testResume(); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | gPanel.addBreakpoint({ url: SOURCE_URL, line: 5 }); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | function testResume() { |
michael@0 | 42 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 43 | "The breakpoint wasn't hit yet (1)."); |
michael@0 | 44 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 45 | "The currently shown source is incorrect (1)."); |
michael@0 | 46 | ok(isCaretPos(gPanel, 5), |
michael@0 | 47 | "The source editor caret position is incorrect (1)."); |
michael@0 | 48 | |
michael@0 | 49 | gDebugger.gThreadClient.resume(testClick); |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | function testClick() { |
michael@0 | 53 | isnot(gDebugger.gThreadClient.state, "paused", |
michael@0 | 54 | "The breakpoint wasn't hit yet (2)."); |
michael@0 | 55 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 56 | "The currently shown source is incorrect (2)."); |
michael@0 | 57 | ok(isCaretPos(gPanel, 5), |
michael@0 | 58 | "The source editor caret position is incorrect (2)."); |
michael@0 | 59 | |
michael@0 | 60 | gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
michael@0 | 61 | is(aPacket.why.type, "breakpoint", |
michael@0 | 62 | "Execution has advanced to the breakpoint."); |
michael@0 | 63 | isnot(aPacket.why.type, "debuggerStatement", |
michael@0 | 64 | "The breakpoint was hit before the debugger statement."); |
michael@0 | 65 | |
michael@0 | 66 | ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHit); |
michael@0 | 67 | }); |
michael@0 | 68 | |
michael@0 | 69 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 70 | gDebuggee.document.querySelector("button"), |
michael@0 | 71 | gDebuggee); |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | function afterBreakpointHit() { |
michael@0 | 75 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 76 | "The breakpoint was hit (3)."); |
michael@0 | 77 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 78 | "The currently shown source is incorrect (3)."); |
michael@0 | 79 | ok(isCaretPos(gPanel, 5), |
michael@0 | 80 | "The source editor caret position is incorrect (3)."); |
michael@0 | 81 | |
michael@0 | 82 | gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
michael@0 | 83 | is(aPacket.why.type, "debuggerStatement", |
michael@0 | 84 | "Execution has advanced to the next line."); |
michael@0 | 85 | isnot(aPacket.why.type, "breakpoint", |
michael@0 | 86 | "No ghost breakpoint was hit."); |
michael@0 | 87 | |
michael@0 | 88 | ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHit); |
michael@0 | 89 | }); |
michael@0 | 90 | |
michael@0 | 91 | gDebugger.gThreadClient.resume(); |
michael@0 | 92 | } |
michael@0 | 93 | |
michael@0 | 94 | function afterDebuggerStatementHit() { |
michael@0 | 95 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 96 | "The debugger statement was hit (4)."); |
michael@0 | 97 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 98 | "The currently shown source is incorrect (4)."); |
michael@0 | 99 | ok(isCaretPos(gPanel, 6), |
michael@0 | 100 | "The source editor caret position is incorrect (4)."); |
michael@0 | 101 | |
michael@0 | 102 | promise.all([ |
michael@0 | 103 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.NEW_SOURCE), |
michael@0 | 104 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCES_ADDED), |
michael@0 | 105 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.SOURCE_SHOWN), |
michael@0 | 106 | reloadActiveTab(gPanel, gDebugger.EVENTS.BREAKPOINT_SHOWN) |
michael@0 | 107 | ]).then(testClickAgain); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function testClickAgain() { |
michael@0 | 111 | isnot(gDebugger.gThreadClient.state, "paused", |
michael@0 | 112 | "The breakpoint wasn't hit yet (5)."); |
michael@0 | 113 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 114 | "The currently shown source is incorrect (5)."); |
michael@0 | 115 | ok(isCaretPos(gPanel, 1), |
michael@0 | 116 | "The source editor caret position is incorrect (5)."); |
michael@0 | 117 | |
michael@0 | 118 | gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
michael@0 | 119 | is(aPacket.why.type, "breakpoint", |
michael@0 | 120 | "Execution has advanced to the breakpoint."); |
michael@0 | 121 | isnot(aPacket.why.type, "debuggerStatement", |
michael@0 | 122 | "The breakpoint was hit before the debugger statement."); |
michael@0 | 123 | |
michael@0 | 124 | ensureCaretAt(gPanel, 5, 1, true).then(afterBreakpointHitAgain); |
michael@0 | 125 | }); |
michael@0 | 126 | |
michael@0 | 127 | EventUtils.sendMouseEvent({ type: "click" }, |
michael@0 | 128 | gDebuggee.document.querySelector("button"), |
michael@0 | 129 | gDebuggee); |
michael@0 | 130 | } |
michael@0 | 131 | |
michael@0 | 132 | function afterBreakpointHitAgain() { |
michael@0 | 133 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 134 | "The breakpoint was hit (6)."); |
michael@0 | 135 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 136 | "The currently shown source is incorrect (6)."); |
michael@0 | 137 | ok(isCaretPos(gPanel, 5), |
michael@0 | 138 | "The source editor caret position is incorrect (6)."); |
michael@0 | 139 | |
michael@0 | 140 | gDebugger.gThreadClient.addOneTimeListener("paused", (aEvent, aPacket) => { |
michael@0 | 141 | is(aPacket.why.type, "debuggerStatement", |
michael@0 | 142 | "Execution has advanced to the next line."); |
michael@0 | 143 | isnot(aPacket.why.type, "breakpoint", |
michael@0 | 144 | "No ghost breakpoint was hit."); |
michael@0 | 145 | |
michael@0 | 146 | ensureCaretAt(gPanel, 6, 1, true).then(afterDebuggerStatementHitAgain); |
michael@0 | 147 | }); |
michael@0 | 148 | |
michael@0 | 149 | gDebugger.gThreadClient.resume(); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | function afterDebuggerStatementHitAgain() { |
michael@0 | 153 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 154 | "The debugger statement was hit (7)."); |
michael@0 | 155 | is(gSources.selectedValue, SOURCE_URL, |
michael@0 | 156 | "The currently shown source is incorrect (7)."); |
michael@0 | 157 | ok(isCaretPos(gPanel, 6), |
michael@0 | 158 | "The source editor caret position is incorrect (7)."); |
michael@0 | 159 | |
michael@0 | 160 | showSecondSource(); |
michael@0 | 161 | } |
michael@0 | 162 | |
michael@0 | 163 | function showSecondSource() { |
michael@0 | 164 | gDebugger.once(gDebugger.EVENTS.SOURCE_SHOWN, () => { |
michael@0 | 165 | is(gEditor.getText().indexOf("debugger"), 447, |
michael@0 | 166 | "The correct source is shown in the source editor.") |
michael@0 | 167 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 168 | "No breakpoints should be shown for the second source."); |
michael@0 | 169 | |
michael@0 | 170 | ensureCaretAt(gPanel, 1, 1, true).then(showFirstSourceAgain); |
michael@0 | 171 | }); |
michael@0 | 172 | |
michael@0 | 173 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 174 | gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[1], |
michael@0 | 175 | gDebugger); |
michael@0 | 176 | } |
michael@0 | 177 | |
michael@0 | 178 | function showFirstSourceAgain() { |
michael@0 | 179 | gDebugger.once(gDebugger.EVENTS.SOURCE_SHOWN, () => { |
michael@0 | 180 | is(gEditor.getText().indexOf("debugger"), 148, |
michael@0 | 181 | "The correct source is shown in the source editor.") |
michael@0 | 182 | is(gEditor.getBreakpoints().length, 1, |
michael@0 | 183 | "One breakpoint should be shown for the first source."); |
michael@0 | 184 | |
michael@0 | 185 | ensureCaretAt(gPanel, 6, 1, true).then(() => resumeDebuggerThenCloseAndFinish(gPanel)); |
michael@0 | 186 | }); |
michael@0 | 187 | |
michael@0 | 188 | EventUtils.sendMouseEvent({ type: "mousedown" }, |
michael@0 | 189 | gDebugger.document.querySelectorAll(".side-menu-widget-item-contents")[0], |
michael@0 | 190 | gDebugger); |
michael@0 | 191 | } |
michael@0 | 192 | |
michael@0 | 193 | registerCleanupFunction(function() { |
michael@0 | 194 | gTab = null; |
michael@0 | 195 | gDebuggee = null; |
michael@0 | 196 | gPanel = null; |
michael@0 | 197 | gDebugger = null; |
michael@0 | 198 | gEditor = null; |
michael@0 | 199 | gSources = null; |
michael@0 | 200 | }); |