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 | * Bug 723071: Test adding a pane to display the list of breakpoints across |
michael@0 | 6 | * all sources in the debuggee. |
michael@0 | 7 | */ |
michael@0 | 8 | |
michael@0 | 9 | const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html"; |
michael@0 | 10 | |
michael@0 | 11 | function test() { |
michael@0 | 12 | let gTab, gDebuggee, gPanel, gDebugger; |
michael@0 | 13 | let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving; |
michael@0 | 14 | |
michael@0 | 15 | initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => { |
michael@0 | 16 | gTab = aTab; |
michael@0 | 17 | gDebuggee = aDebuggee; |
michael@0 | 18 | gPanel = aPanel; |
michael@0 | 19 | gDebugger = gPanel.panelWin; |
michael@0 | 20 | gEditor = gDebugger.DebuggerView.editor; |
michael@0 | 21 | gSources = gDebugger.DebuggerView.Sources; |
michael@0 | 22 | gBreakpoints = gDebugger.DebuggerController.Breakpoints; |
michael@0 | 23 | gBreakpointsAdded = gBreakpoints._added; |
michael@0 | 24 | gBreakpointsRemoving = gBreakpoints._removing; |
michael@0 | 25 | |
michael@0 | 26 | waitForSourceAndCaretAndScopes(gPanel, "-02.js", 1).then(performTest); |
michael@0 | 27 | gDebuggee.firstCall(); |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | let breakpointsAdded = 0; |
michael@0 | 31 | let breakpointsDisabled = 0; |
michael@0 | 32 | let breakpointsRemoved = 0; |
michael@0 | 33 | |
michael@0 | 34 | function performTest() { |
michael@0 | 35 | is(gDebugger.gThreadClient.state, "paused", |
michael@0 | 36 | "Should only be getting stack frames while paused."); |
michael@0 | 37 | is(gSources.itemCount, 2, |
michael@0 | 38 | "Found the expected number of sources."); |
michael@0 | 39 | is(gEditor.getText().indexOf("debugger"), 172, |
michael@0 | 40 | "The correct source was loaded initially."); |
michael@0 | 41 | is(gSources.selectedValue, gSources.values[1], |
michael@0 | 42 | "The correct source is selected."); |
michael@0 | 43 | |
michael@0 | 44 | is(gBreakpointsAdded.size, 0, |
michael@0 | 45 | "No breakpoints currently added."); |
michael@0 | 46 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 47 | "No breakpoints currently being removed."); |
michael@0 | 48 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 49 | "No breakpoints currently shown in the editor."); |
michael@0 | 50 | |
michael@0 | 51 | ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }), |
michael@0 | 52 | "_getAdded('foo', 3) returns falsey."); |
michael@0 | 53 | ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }), |
michael@0 | 54 | "_getRemoving('bar', 3) returns falsey."); |
michael@0 | 55 | |
michael@0 | 56 | let breakpointsParent = gSources.widget._parent; |
michael@0 | 57 | let breakpointsList = gSources.widget._list; |
michael@0 | 58 | |
michael@0 | 59 | is(breakpointsParent.childNodes.length, 1, // one sources list |
michael@0 | 60 | "Found junk in the breakpoints container."); |
michael@0 | 61 | is(breakpointsList.childNodes.length, 1, // one sources group |
michael@0 | 62 | "Found junk in the breakpoints container."); |
michael@0 | 63 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0, |
michael@0 | 64 | "No breakpoints should be visible at this point."); |
michael@0 | 65 | |
michael@0 | 66 | addBreakpoints(true).then(() => { |
michael@0 | 67 | is(breakpointsAdded, 3, |
michael@0 | 68 | "Should have added 3 breakpoints so far."); |
michael@0 | 69 | is(breakpointsDisabled, 0, |
michael@0 | 70 | "Shouldn't have disabled anything so far."); |
michael@0 | 71 | is(breakpointsRemoved, 0, |
michael@0 | 72 | "Shouldn't have removed anything so far."); |
michael@0 | 73 | |
michael@0 | 74 | is(breakpointsParent.childNodes.length, 1, // one sources list |
michael@0 | 75 | "Found junk in the breakpoints container."); |
michael@0 | 76 | is(breakpointsList.childNodes.length, 1, // one sources group |
michael@0 | 77 | "Found junk in the breakpoints container."); |
michael@0 | 78 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 3, |
michael@0 | 79 | "3 breakpoints should be visible at this point."); |
michael@0 | 80 | |
michael@0 | 81 | disableBreakpoints().then(() => { |
michael@0 | 82 | is(breakpointsAdded, 3, |
michael@0 | 83 | "Should still have 3 breakpoints added so far."); |
michael@0 | 84 | is(breakpointsDisabled, 3, |
michael@0 | 85 | "Should have 3 disabled breakpoints."); |
michael@0 | 86 | is(breakpointsRemoved, 0, |
michael@0 | 87 | "Shouldn't have removed anything so far."); |
michael@0 | 88 | |
michael@0 | 89 | is(breakpointsParent.childNodes.length, 1, // one sources list |
michael@0 | 90 | "Found junk in the breakpoints container."); |
michael@0 | 91 | is(breakpointsList.childNodes.length, 1, // one sources group |
michael@0 | 92 | "Found junk in the breakpoints container."); |
michael@0 | 93 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded, |
michael@0 | 94 | "Should have the same number of breakpoints in the pane."); |
michael@0 | 95 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsDisabled, |
michael@0 | 96 | "Should have the same number of disabled breakpoints."); |
michael@0 | 97 | |
michael@0 | 98 | addBreakpoints().then(() => { |
michael@0 | 99 | is(breakpointsAdded, 3, |
michael@0 | 100 | "Should still have only 3 breakpoints added so far."); |
michael@0 | 101 | is(breakpointsDisabled, 3, |
michael@0 | 102 | "Should still have 3 disabled breakpoints."); |
michael@0 | 103 | is(breakpointsRemoved, 0, |
michael@0 | 104 | "Shouldn't have removed anything so far."); |
michael@0 | 105 | |
michael@0 | 106 | is(breakpointsParent.childNodes.length, 1, // one sources list |
michael@0 | 107 | "Found junk in the breakpoints container."); |
michael@0 | 108 | is(breakpointsList.childNodes.length, 1, // one sources group |
michael@0 | 109 | "Found junk in the breakpoints container."); |
michael@0 | 110 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded, |
michael@0 | 111 | "Since half of the breakpoints already existed, but disabled, " + |
michael@0 | 112 | "only half of the added breakpoints are actually in the pane."); |
michael@0 | 113 | |
michael@0 | 114 | removeBreakpoints().then(() => { |
michael@0 | 115 | is(breakpointsRemoved, 3, |
michael@0 | 116 | "Should have 3 removed breakpoints."); |
michael@0 | 117 | |
michael@0 | 118 | is(breakpointsParent.childNodes.length, 1, // one sources list |
michael@0 | 119 | "Found junk in the breakpoints container."); |
michael@0 | 120 | is(breakpointsList.childNodes.length, 1, // one sources group |
michael@0 | 121 | "Found junk in the breakpoints container."); |
michael@0 | 122 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, 0, |
michael@0 | 123 | "No breakpoints should be visible at this point."); |
michael@0 | 124 | |
michael@0 | 125 | waitForDebuggerEvents(gPanel, gDebugger.EVENTS.AFTER_FRAMES_CLEARED).then(() => { |
michael@0 | 126 | finalCheck(); |
michael@0 | 127 | closeDebuggerAndFinish(gPanel); |
michael@0 | 128 | }); |
michael@0 | 129 | |
michael@0 | 130 | gDebugger.gThreadClient.resume(); |
michael@0 | 131 | }); |
michael@0 | 132 | }); |
michael@0 | 133 | }); |
michael@0 | 134 | }); |
michael@0 | 135 | |
michael@0 | 136 | function addBreakpoints(aIncrementFlag) { |
michael@0 | 137 | let deferred = promise.defer(); |
michael@0 | 138 | |
michael@0 | 139 | gPanel.addBreakpoint({ url: gSources.selectedValue, line: 6 }).then(aClient => { |
michael@0 | 140 | onBreakpointAdd(aClient, { |
michael@0 | 141 | increment: aIncrementFlag, |
michael@0 | 142 | line: 6, |
michael@0 | 143 | text: "eval(\"debugger;\");" |
michael@0 | 144 | }); |
michael@0 | 145 | |
michael@0 | 146 | gPanel.addBreakpoint({ url: gSources.selectedValue, line: 7 }).then(aClient => { |
michael@0 | 147 | onBreakpointAdd(aClient, { |
michael@0 | 148 | increment: aIncrementFlag, |
michael@0 | 149 | line: 7, |
michael@0 | 150 | text: "function foo() {}" |
michael@0 | 151 | }); |
michael@0 | 152 | |
michael@0 | 153 | gPanel.addBreakpoint({ url: gSources.selectedValue, line: 9 }).then(aClient => { |
michael@0 | 154 | onBreakpointAdd(aClient, { |
michael@0 | 155 | increment: aIncrementFlag, |
michael@0 | 156 | line: 9, |
michael@0 | 157 | text: "foo();" |
michael@0 | 158 | }); |
michael@0 | 159 | |
michael@0 | 160 | deferred.resolve(); |
michael@0 | 161 | }); |
michael@0 | 162 | }); |
michael@0 | 163 | }); |
michael@0 | 164 | |
michael@0 | 165 | return deferred.promise; |
michael@0 | 166 | } |
michael@0 | 167 | |
michael@0 | 168 | function disableBreakpoints() { |
michael@0 | 169 | let deferred = promise.defer(); |
michael@0 | 170 | |
michael@0 | 171 | let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint"); |
michael@0 | 172 | info("Nodes to disable: " + breakpointsAdded.length); |
michael@0 | 173 | |
michael@0 | 174 | is(nodes.length, breakpointsAdded, |
michael@0 | 175 | "The number of nodes to disable is incorrect."); |
michael@0 | 176 | |
michael@0 | 177 | for (let node of nodes) { |
michael@0 | 178 | info("Disabling breakpoint: " + node.id); |
michael@0 | 179 | |
michael@0 | 180 | let sourceItem = gSources.getItemForElement(node); |
michael@0 | 181 | let breakpointItem = gSources.getItemForElement.call(sourceItem, node); |
michael@0 | 182 | info("Found data: " + breakpointItem.attachment.toSource()); |
michael@0 | 183 | |
michael@0 | 184 | gSources.disableBreakpoint(breakpointItem.attachment).then(() => { |
michael@0 | 185 | if (++breakpointsDisabled == breakpointsAdded) { |
michael@0 | 186 | deferred.resolve(); |
michael@0 | 187 | } |
michael@0 | 188 | }); |
michael@0 | 189 | } |
michael@0 | 190 | |
michael@0 | 191 | return deferred.promise; |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | function removeBreakpoints() { |
michael@0 | 195 | let deferred = promise.defer(); |
michael@0 | 196 | |
michael@0 | 197 | let nodes = breakpointsList.querySelectorAll(".dbg-breakpoint"); |
michael@0 | 198 | info("Nodes to remove: " + breakpointsAdded.length); |
michael@0 | 199 | |
michael@0 | 200 | is(nodes.length, breakpointsAdded, |
michael@0 | 201 | "The number of nodes to remove is incorrect."); |
michael@0 | 202 | |
michael@0 | 203 | for (let node of nodes) { |
michael@0 | 204 | info("Removing breakpoint: " + node.id); |
michael@0 | 205 | |
michael@0 | 206 | let sourceItem = gSources.getItemForElement(node); |
michael@0 | 207 | let breakpointItem = gSources.getItemForElement.call(sourceItem, node); |
michael@0 | 208 | info("Found data: " + breakpointItem.attachment.toSource()); |
michael@0 | 209 | |
michael@0 | 210 | gPanel.removeBreakpoint(breakpointItem.attachment).then(() => { |
michael@0 | 211 | if (++breakpointsRemoved == breakpointsAdded) { |
michael@0 | 212 | deferred.resolve(); |
michael@0 | 213 | } |
michael@0 | 214 | }); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | return deferred.promise; |
michael@0 | 218 | } |
michael@0 | 219 | |
michael@0 | 220 | function onBreakpointAdd(aBreakpointClient, aTestData) { |
michael@0 | 221 | if (aTestData.increment) { |
michael@0 | 222 | breakpointsAdded++; |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | is(breakpointsList.querySelectorAll(".dbg-breakpoint").length, breakpointsAdded, |
michael@0 | 226 | aTestData.increment |
michael@0 | 227 | ? "Should have added a breakpoint in the pane." |
michael@0 | 228 | : "Should have the same number of breakpoints in the pane."); |
michael@0 | 229 | |
michael@0 | 230 | let identifier = gBreakpoints.getIdentifier(aBreakpointClient.location); |
michael@0 | 231 | let node = gDebugger.document.getElementById("breakpoint-" + identifier); |
michael@0 | 232 | let line = node.getElementsByClassName("dbg-breakpoint-line")[0]; |
michael@0 | 233 | let text = node.getElementsByClassName("dbg-breakpoint-text")[0]; |
michael@0 | 234 | let check = node.querySelector("checkbox"); |
michael@0 | 235 | |
michael@0 | 236 | ok(node, |
michael@0 | 237 | "Breakpoint element found successfully."); |
michael@0 | 238 | is(line.getAttribute("value"), aTestData.line, |
michael@0 | 239 | "The expected information wasn't found in the breakpoint element."); |
michael@0 | 240 | is(text.getAttribute("value"), aTestData.text, |
michael@0 | 241 | "The expected line text wasn't found in the breakpoint element."); |
michael@0 | 242 | is(check.getAttribute("checked"), "true", |
michael@0 | 243 | "The breakpoint enable checkbox is checked as expected."); |
michael@0 | 244 | } |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | function finalCheck() { |
michael@0 | 248 | is(gBreakpointsAdded.size, 0, |
michael@0 | 249 | "No breakpoints currently added."); |
michael@0 | 250 | is(gBreakpointsRemoving.size, 0, |
michael@0 | 251 | "No breakpoints currently being removed."); |
michael@0 | 252 | is(gEditor.getBreakpoints().length, 0, |
michael@0 | 253 | "No breakpoints currently shown in the editor."); |
michael@0 | 254 | } |
michael@0 | 255 | } |