browser/devtools/debugger/test/browser_dbg_breakpoints-contextmenu.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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 * Test if the context menu associated with each breakpoint does what it should.
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_script-switching-01.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 // Debug test slaves are a bit slow at this test.
michael@0 12 requestLongerTimeout(2);
michael@0 13
michael@0 14 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 15 let gSources, gBreakpoints;
michael@0 16
michael@0 17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 18 gTab = aTab;
michael@0 19 gDebuggee = aDebuggee;
michael@0 20 gPanel = aPanel;
michael@0 21 gDebugger = gPanel.panelWin;
michael@0 22 gSources = gDebugger.DebuggerView.Sources;
michael@0 23 gBreakpoints = gDebugger.DebuggerController.Breakpoints;
michael@0 24
michael@0 25 waitForSourceShown(gPanel, "-01.js")
michael@0 26 .then(performTestWhileNotPaused)
michael@0 27 .then(performTestWhilePaused)
michael@0 28 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
michael@0 29 .then(null, aError => {
michael@0 30 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 31 });
michael@0 32 });
michael@0 33
michael@0 34 function addBreakpoints() {
michael@0 35 return promise.resolve(null)
michael@0 36 .then(() => gPanel.addBreakpoint({ url: gSources.values[0], line: 5 }))
michael@0 37 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 6 }))
michael@0 38 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 7 }))
michael@0 39 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 8 }))
michael@0 40 .then(() => gPanel.addBreakpoint({ url: gSources.values[1], line: 9 }))
michael@0 41 .then(() => ensureThreadClientState(gPanel, "resumed"));
michael@0 42 }
michael@0 43
michael@0 44 function performTestWhileNotPaused() {
michael@0 45 info("Performing test while not paused...");
michael@0 46
michael@0 47 return addBreakpoints()
michael@0 48 .then(initialChecks)
michael@0 49 .then(() => checkBreakpointToggleSelf(0))
michael@0 50 .then(() => checkBreakpointToggleOthers(0))
michael@0 51 .then(() => checkBreakpointToggleSelf(1))
michael@0 52 .then(() => checkBreakpointToggleOthers(1))
michael@0 53 .then(() => checkBreakpointToggleSelf(2))
michael@0 54 .then(() => checkBreakpointToggleOthers(2))
michael@0 55 .then(() => checkBreakpointToggleSelf(3))
michael@0 56 .then(() => checkBreakpointToggleOthers(3))
michael@0 57 .then(() => checkBreakpointToggleSelf(4))
michael@0 58 .then(() => checkBreakpointToggleOthers(4))
michael@0 59 .then(testDeleteAll);
michael@0 60 }
michael@0 61
michael@0 62 function performTestWhilePaused() {
michael@0 63 info("Performing test while paused...");
michael@0 64
michael@0 65 return addBreakpoints()
michael@0 66 .then(initialChecks)
michael@0 67 .then(pauseAndCheck)
michael@0 68 .then(() => checkBreakpointToggleSelf(0))
michael@0 69 .then(() => checkBreakpointToggleOthers(0))
michael@0 70 .then(() => checkBreakpointToggleSelf(1))
michael@0 71 .then(() => checkBreakpointToggleOthers(1))
michael@0 72 .then(() => checkBreakpointToggleSelf(2))
michael@0 73 .then(() => checkBreakpointToggleOthers(2))
michael@0 74 .then(() => checkBreakpointToggleSelf(3))
michael@0 75 .then(() => checkBreakpointToggleOthers(3))
michael@0 76 .then(() => checkBreakpointToggleSelf(4))
michael@0 77 .then(() => checkBreakpointToggleOthers(4))
michael@0 78 .then(testDeleteAll);
michael@0 79 }
michael@0 80
michael@0 81 function pauseAndCheck() {
michael@0 82 let finished = waitForSourceAndCaretAndScopes(gPanel, "-01.js", 5).then(() => {
michael@0 83 is(gSources.selectedValue, EXAMPLE_URL + "code_script-switching-01.js",
michael@0 84 "The currently selected source is incorrect (3).");
michael@0 85 is(gSources.selectedIndex, 0,
michael@0 86 "The currently selected source is incorrect (4).");
michael@0 87 ok(isCaretPos(gPanel, 5),
michael@0 88 "The editor location is correct after pausing.");
michael@0 89 });
michael@0 90
michael@0 91 is(gSources.selectedValue, EXAMPLE_URL + "code_script-switching-02.js",
michael@0 92 "The currently selected source is incorrect (1).");
michael@0 93 is(gSources.selectedIndex, 1,
michael@0 94 "The currently selected source is incorrect (2).");
michael@0 95 ok(isCaretPos(gPanel, 9),
michael@0 96 "The editor location is correct before pausing.");
michael@0 97
michael@0 98 // Spin the event loop before causing the debuggee to pause, to allow
michael@0 99 // this function to return first.
michael@0 100 executeSoon(() => {
michael@0 101 EventUtils.sendMouseEvent({ type: "click" },
michael@0 102 gDebuggee.document.querySelector("button"),
michael@0 103 gDebuggee);
michael@0 104 });
michael@0 105
michael@0 106 return finished;
michael@0 107 }
michael@0 108
michael@0 109 function initialChecks() {
michael@0 110 for (let source of gSources) {
michael@0 111 for (let breakpoint of source) {
michael@0 112 ok(gBreakpoints._getAdded(breakpoint.attachment),
michael@0 113 "All breakpoint items should have corresponding promises (1).");
michael@0 114 ok(!gBreakpoints._getRemoving(breakpoint.attachment),
michael@0 115 "All breakpoint items should have corresponding promises (2).");
michael@0 116 ok(breakpoint.attachment.actor,
michael@0 117 "All breakpoint items should have corresponding promises (3).");
michael@0 118 is(!!breakpoint.attachment.disabled, false,
michael@0 119 "All breakpoints should initially be enabled.");
michael@0 120
michael@0 121 let prefix = "bp-cMenu-"; // "breakpoints context menu"
michael@0 122 let identifier = gBreakpoints.getIdentifier(breakpoint.attachment);
michael@0 123 let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
michael@0 124 let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
michael@0 125
michael@0 126 is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
michael@0 127 "The 'Enable breakpoint' context menu item should initially be hidden'.");
michael@0 128 ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
michael@0 129 "The 'Disable breakpoint' context menu item should initially not be hidden'.");
michael@0 130 is(breakpoint.attachment.view.checkbox.getAttribute("checked"), "true",
michael@0 131 "All breakpoints should initially have a checked checkbox.");
michael@0 132 }
michael@0 133 }
michael@0 134 }
michael@0 135
michael@0 136 function checkBreakpointToggleSelf(aIndex) {
michael@0 137 let deferred = promise.defer();
michael@0 138
michael@0 139 EventUtils.sendMouseEvent({ type: "click" },
michael@0 140 gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex],
michael@0 141 gDebugger);
michael@0 142
michael@0 143 let selectedBreakpoint = gSources._selectedBreakpointItem;
michael@0 144
michael@0 145 ok(gBreakpoints._getAdded(selectedBreakpoint.attachment),
michael@0 146 "There should be a breakpoint client available (1).");
michael@0 147 ok(!gBreakpoints._getRemoving(selectedBreakpoint.attachment),
michael@0 148 "There should be a breakpoint client available (2).");
michael@0 149 ok(selectedBreakpoint.attachment.actor,
michael@0 150 "There should be a breakpoint client available (3).");
michael@0 151 is(!!selectedBreakpoint.attachment.disabled, false,
michael@0 152 "The breakpoint should not be disabled yet (" + aIndex + ").");
michael@0 153
michael@0 154 gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => {
michael@0 155 ok(aBreakpointClient,
michael@0 156 "There should be a breakpoint client available as a promise.");
michael@0 157 });
michael@0 158
michael@0 159 let prefix = "bp-cMenu-"; // "breakpoints context menu"
michael@0 160 let identifier = gBreakpoints.getIdentifier(selectedBreakpoint.attachment);
michael@0 161 let enableSelfId = prefix + "enableSelf-" + identifier + "-menuitem";
michael@0 162 let disableSelfId = prefix + "disableSelf-" + identifier + "-menuitem";
michael@0 163
michael@0 164 is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
michael@0 165 "The 'Enable breakpoint' context menu item should be hidden'.");
michael@0 166 ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
michael@0 167 "The 'Disable breakpoint' context menu item should not be hidden'.");
michael@0 168
michael@0 169 ok(isCaretPos(gPanel, selectedBreakpoint.attachment.line),
michael@0 170 "The source editor caret position was incorrect (" + aIndex + ").");
michael@0 171
michael@0 172 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED).then(() => {
michael@0 173 ok(!gBreakpoints._getAdded(selectedBreakpoint.attachment),
michael@0 174 "There should be no breakpoint client available (4).");
michael@0 175
michael@0 176 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED).then(() => {
michael@0 177 ok(gBreakpoints._getAdded(selectedBreakpoint.attachment),
michael@0 178 "There should be a breakpoint client available (5).");
michael@0 179
michael@0 180 deferred.resolve();
michael@0 181 });
michael@0 182
michael@0 183 // Test re-disabling this breakpoint.
michael@0 184 gSources._onEnableSelf(selectedBreakpoint.attachment);
michael@0 185 is(selectedBreakpoint.attachment.disabled, false,
michael@0 186 "The current breakpoint should now be enabled.")
michael@0 187
michael@0 188 is(gDebugger.document.getElementById(enableSelfId).getAttribute("hidden"), "true",
michael@0 189 "The 'Enable breakpoint' context menu item should be hidden'.");
michael@0 190 ok(!gDebugger.document.getElementById(disableSelfId).hasAttribute("hidden"),
michael@0 191 "The 'Disable breakpoint' context menu item should not be hidden'.");
michael@0 192 ok(selectedBreakpoint.attachment.view.checkbox.hasAttribute("checked"),
michael@0 193 "The breakpoint should now be checked.");
michael@0 194 });
michael@0 195
michael@0 196 // Test disabling this breakpoint.
michael@0 197 gSources._onDisableSelf(selectedBreakpoint.attachment);
michael@0 198 is(selectedBreakpoint.attachment.disabled, true,
michael@0 199 "The current breakpoint should now be disabled.")
michael@0 200
michael@0 201 ok(!gDebugger.document.getElementById(enableSelfId).hasAttribute("hidden"),
michael@0 202 "The 'Enable breakpoint' context menu item should not be hidden'.");
michael@0 203 is(gDebugger.document.getElementById(disableSelfId).getAttribute("hidden"), "true",
michael@0 204 "The 'Disable breakpoint' context menu item should be hidden'.");
michael@0 205 ok(!selectedBreakpoint.attachment.view.checkbox.hasAttribute("checked"),
michael@0 206 "The breakpoint should now be unchecked.");
michael@0 207
michael@0 208 return deferred.promise;
michael@0 209 }
michael@0 210
michael@0 211 function checkBreakpointToggleOthers(aIndex) {
michael@0 212 let deferred = promise.defer();
michael@0 213
michael@0 214 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 4).then(() => {
michael@0 215 let selectedBreakpoint = gSources._selectedBreakpointItem;
michael@0 216
michael@0 217 ok(gBreakpoints._getAdded(selectedBreakpoint.attachment),
michael@0 218 "There should be a breakpoint client available (6).");
michael@0 219 ok(!gBreakpoints._getRemoving(selectedBreakpoint.attachment),
michael@0 220 "There should be a breakpoint client available (7).");
michael@0 221 ok(selectedBreakpoint.attachment.actor,
michael@0 222 "There should be a breakpoint client available (8).");
michael@0 223 is(!!selectedBreakpoint.attachment.disabled, false,
michael@0 224 "The targetted breakpoint should not have been disabled (" + aIndex + ").");
michael@0 225
michael@0 226 for (let source of gSources) {
michael@0 227 for (let otherBreakpoint of source) {
michael@0 228 if (otherBreakpoint != selectedBreakpoint) {
michael@0 229 ok(!gBreakpoints._getAdded(otherBreakpoint.attachment),
michael@0 230 "There should be no breakpoint client for a disabled breakpoint (9).");
michael@0 231 is(otherBreakpoint.attachment.disabled, true,
michael@0 232 "Non-targetted breakpoints should have been disabled (10).");
michael@0 233 }
michael@0 234 }
michael@0 235 }
michael@0 236
michael@0 237 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED, 4).then(() => {
michael@0 238 for (let source of gSources) {
michael@0 239 for (let someBreakpoint of source) {
michael@0 240 ok(gBreakpoints._getAdded(someBreakpoint.attachment),
michael@0 241 "There should be a breakpoint client for all enabled breakpoints (11).");
michael@0 242 is(someBreakpoint.attachment.disabled, false,
michael@0 243 "All breakpoints should now have been enabled (12).");
michael@0 244 }
michael@0 245 }
michael@0 246
michael@0 247 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 5).then(() => {
michael@0 248 for (let source of gSources) {
michael@0 249 for (let someBreakpoint of source) {
michael@0 250 ok(!gBreakpoints._getAdded(someBreakpoint.attachment),
michael@0 251 "There should be no breakpoint client for a disabled breakpoint (13).");
michael@0 252 is(someBreakpoint.attachment.disabled, true,
michael@0 253 "All breakpoints should now have been disabled (14).");
michael@0 254 }
michael@0 255 }
michael@0 256
michael@0 257 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED, 5).then(() => {
michael@0 258 for (let source of gSources) {
michael@0 259 for (let someBreakpoint of source) {
michael@0 260 ok(gBreakpoints._getAdded(someBreakpoint.attachment),
michael@0 261 "There should be a breakpoint client for all enabled breakpoints (15).");
michael@0 262 is(someBreakpoint.attachment.disabled, false,
michael@0 263 "All breakpoints should now have been enabled (16).");
michael@0 264 }
michael@0 265 }
michael@0 266
michael@0 267 // Done.
michael@0 268 deferred.resolve();
michael@0 269 });
michael@0 270
michael@0 271 // Test re-enabling all breakpoints.
michael@0 272 enableAll();
michael@0 273 });
michael@0 274
michael@0 275 // Test disabling all breakpoints.
michael@0 276 disableAll();
michael@0 277 });
michael@0 278
michael@0 279 // Test re-enabling other breakpoints.
michael@0 280 enableOthers();
michael@0 281 });
michael@0 282
michael@0 283 // Test disabling other breakpoints.
michael@0 284 disableOthers();
michael@0 285
michael@0 286 return deferred.promise;
michael@0 287 }
michael@0 288
michael@0 289 function testDeleteAll() {
michael@0 290 let deferred = promise.defer();
michael@0 291
michael@0 292 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED, 5).then(() => {
michael@0 293 ok(!gSources._selectedBreakpointItem,
michael@0 294 "There should be no breakpoint available after removing all breakpoints.");
michael@0 295
michael@0 296 for (let source of gSources) {
michael@0 297 for (let otherBreakpoint of source) {
michael@0 298 ok(false, "It's a trap!");
michael@0 299 }
michael@0 300 }
michael@0 301
michael@0 302 // Done.
michael@0 303 deferred.resolve()
michael@0 304 });
michael@0 305
michael@0 306 // Test deleting all breakpoints.
michael@0 307 deleteAll();
michael@0 308
michael@0 309 return deferred.promise;
michael@0 310 }
michael@0 311
michael@0 312 function disableOthers() {
michael@0 313 gSources._onDisableOthers(gSources._selectedBreakpointItem.attachment);
michael@0 314 }
michael@0 315 function enableOthers() {
michael@0 316 gSources._onEnableOthers(gSources._selectedBreakpointItem.attachment);
michael@0 317 }
michael@0 318 function disableAll() {
michael@0 319 gSources._onDisableAll();
michael@0 320 }
michael@0 321 function enableAll() {
michael@0 322 gSources._onEnableAll();
michael@0 323 }
michael@0 324 function deleteAll() {
michael@0 325 gSources._onDeleteAll();
michael@0 326 }
michael@0 327 }

mercurial