browser/devtools/debugger/test/browser_dbg_server-conditional-bp-02.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 * Bug 812172: Test adding and modifying conditional breakpoints (with server-side support)
michael@0 6 */
michael@0 7
michael@0 8 const TAB_URL = EXAMPLE_URL + "doc_conditional-breakpoints.html";
michael@0 9
michael@0 10 function test() {
michael@0 11 let gTab, gDebuggee, gPanel, gDebugger;
michael@0 12 let gEditor, gSources, gBreakpoints, gBreakpointsAdded, gBreakpointsRemoving;
michael@0 13
michael@0 14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
michael@0 15 gTab = aTab;
michael@0 16 gDebuggee = aDebuggee;
michael@0 17 gPanel = aPanel;
michael@0 18 gDebugger = gPanel.panelWin;
michael@0 19 gEditor = gDebugger.DebuggerView.editor;
michael@0 20 gSources = gDebugger.DebuggerView.Sources;
michael@0 21 gBreakpoints = gDebugger.DebuggerController.Breakpoints;
michael@0 22 gBreakpointsAdded = gBreakpoints._added;
michael@0 23 gBreakpointsRemoving = gBreakpoints._removing;
michael@0 24
michael@0 25 waitForSourceAndCaretAndScopes(gPanel, ".html", 17)
michael@0 26 .then(() => initialChecks())
michael@0 27 .then(() => addBreakpoint1())
michael@0 28 .then(() => testBreakpoint(18, false, false, undefined))
michael@0 29 .then(() => addBreakpoint2())
michael@0 30 .then(() => testBreakpoint(19, false, false, undefined))
michael@0 31 .then(() => modBreakpoint2())
michael@0 32 .then(() => testBreakpoint(19, false, true, undefined))
michael@0 33 .then(() => addBreakpoint3())
michael@0 34 .then(() => testBreakpoint(20, true, false, undefined))
michael@0 35 .then(() => modBreakpoint3())
michael@0 36 .then(() => testBreakpoint(20, true, false, "bamboocha"))
michael@0 37 .then(() => addBreakpoint4())
michael@0 38 .then(() => testBreakpoint(21, false, false, undefined))
michael@0 39 .then(() => delBreakpoint4())
michael@0 40 .then(() => setCaretPosition(18))
michael@0 41 .then(() => testBreakpoint(18, false, false, undefined))
michael@0 42 .then(() => setCaretPosition(19))
michael@0 43 .then(() => testBreakpoint(19, false, false, undefined))
michael@0 44 .then(() => setCaretPosition(20))
michael@0 45 .then(() => testBreakpoint(20, true, false, "bamboocha"))
michael@0 46 .then(() => setCaretPosition(17))
michael@0 47 .then(() => testNoBreakpoint(17))
michael@0 48 .then(() => setCaretPosition(21))
michael@0 49 .then(() => testNoBreakpoint(21))
michael@0 50 .then(() => clickOnBreakpoint(0))
michael@0 51 .then(() => testBreakpoint(18, false, false, undefined))
michael@0 52 .then(() => clickOnBreakpoint(1))
michael@0 53 .then(() => testBreakpoint(19, false, false, undefined))
michael@0 54 .then(() => clickOnBreakpoint(2))
michael@0 55 .then(() => testBreakpoint(20, true, true, "bamboocha"))
michael@0 56 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
michael@0 57 .then(null, aError => {
michael@0 58 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
michael@0 59 });
michael@0 60
michael@0 61 gDebuggee.ermahgerd();
michael@0 62 });
michael@0 63
michael@0 64 function initialChecks() {
michael@0 65 is(gDebugger.gThreadClient.state, "paused",
michael@0 66 "Should only be getting stack frames while paused.");
michael@0 67 is(gSources.itemCount, 1,
michael@0 68 "Found the expected number of sources.");
michael@0 69 is(gEditor.getText().indexOf("ermahgerd"), 253,
michael@0 70 "The correct source was loaded initially.");
michael@0 71 is(gSources.selectedValue, gSources.values[0],
michael@0 72 "The correct source is selected.");
michael@0 73
michael@0 74 is(gBreakpointsAdded.size, 0,
michael@0 75 "No breakpoints currently added.");
michael@0 76 is(gBreakpointsRemoving.size, 0,
michael@0 77 "No breakpoints currently being removed.");
michael@0 78 is(gEditor.getBreakpoints().length, 0,
michael@0 79 "No breakpoints currently shown in the editor.");
michael@0 80
michael@0 81 ok(!gBreakpoints._getAdded({ url: "foo", line: 3 }),
michael@0 82 "_getAdded('foo', 3) returns falsey.");
michael@0 83 ok(!gBreakpoints._getRemoving({ url: "bar", line: 3 }),
michael@0 84 "_getRemoving('bar', 3) returns falsey.");
michael@0 85 }
michael@0 86
michael@0 87 function addBreakpoint1() {
michael@0 88 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED);
michael@0 89 gPanel.addBreakpoint({ url: gSources.selectedValue, line: 18 });
michael@0 90 return finished;
michael@0 91 }
michael@0 92
michael@0 93 function addBreakpoint2() {
michael@0 94 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED);
michael@0 95 setCaretPosition(19);
michael@0 96 gSources._onCmdAddBreakpoint();
michael@0 97 return finished;
michael@0 98 }
michael@0 99
michael@0 100 function modBreakpoint2() {
michael@0 101 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_SHOWING);
michael@0 102 setCaretPosition(19);
michael@0 103 gSources._onCmdAddConditionalBreakpoint();
michael@0 104 return finished;
michael@0 105 }
michael@0 106
michael@0 107 function addBreakpoint3() {
michael@0 108 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED);
michael@0 109 setCaretPosition(20);
michael@0 110 gSources._onCmdAddConditionalBreakpoint();
michael@0 111 return finished;
michael@0 112 }
michael@0 113
michael@0 114 function modBreakpoint3() {
michael@0 115 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.CONDITIONAL_BREAKPOINT_POPUP_HIDING);
michael@0 116 typeText(gSources._cbTextbox, "bamboocha");
michael@0 117 EventUtils.sendKey("RETURN", gDebugger);
michael@0 118 return finished;
michael@0 119 }
michael@0 120
michael@0 121 function addBreakpoint4() {
michael@0 122 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_ADDED);
michael@0 123 setCaretPosition(21);
michael@0 124 gSources._onCmdAddBreakpoint();
michael@0 125 return finished;
michael@0 126 }
michael@0 127
michael@0 128 function delBreakpoint4() {
michael@0 129 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.BREAKPOINT_REMOVED);
michael@0 130 setCaretPosition(21);
michael@0 131 gSources._onCmdAddBreakpoint();
michael@0 132 return finished;
michael@0 133 }
michael@0 134
michael@0 135 function testBreakpoint(aLine, aOpenPopupFlag, aPopupVisible, aConditionalExpression) {
michael@0 136 let selectedUrl = gSources.selectedValue;
michael@0 137 let selectedBreakpoint = gSources._selectedBreakpointItem;
michael@0 138
michael@0 139 ok(selectedUrl,
michael@0 140 "There should be a selected item in the sources pane.");
michael@0 141 ok(selectedBreakpoint,
michael@0 142 "There should be a selected brekapoint in the sources pane.");
michael@0 143
michael@0 144 is(selectedBreakpoint.attachment.url, selectedUrl,
michael@0 145 "The breakpoint on line " + aLine + " wasn't added on the correct source.");
michael@0 146 is(selectedBreakpoint.attachment.line, aLine,
michael@0 147 "The breakpoint on line " + aLine + " wasn't found.");
michael@0 148 is(!!selectedBreakpoint.attachment.disabled, false,
michael@0 149 "The breakpoint on line " + aLine + " should be enabled.");
michael@0 150 is(!!selectedBreakpoint.attachment.openPopup, aOpenPopupFlag,
michael@0 151 "The breakpoint on line " + aLine + " should have a correct popup state (1).");
michael@0 152 is(gSources._conditionalPopupVisible, aPopupVisible,
michael@0 153 "The breakpoint on line " + aLine + " should have a correct popup state (2).");
michael@0 154
michael@0 155 return gBreakpoints._getAdded(selectedBreakpoint.attachment).then(aBreakpointClient => {
michael@0 156 is(aBreakpointClient.location.url, selectedUrl,
michael@0 157 "The breakpoint's client url is correct");
michael@0 158 is(aBreakpointClient.location.line, aLine,
michael@0 159 "The breakpoint's client line is correct");
michael@0 160 is(aBreakpointClient.condition, aConditionalExpression,
michael@0 161 "The breakpoint on line " + aLine + " should have a correct conditional expression.");
michael@0 162 is("condition" in aBreakpointClient, !!aConditionalExpression,
michael@0 163 "The breakpoint on line " + aLine + " should have a correct conditional state.");
michael@0 164
michael@0 165 ok(isCaretPos(gPanel, aLine),
michael@0 166 "The editor caret position is not properly set.");
michael@0 167 });
michael@0 168 }
michael@0 169
michael@0 170 function testNoBreakpoint(aLine) {
michael@0 171 let selectedUrl = gSources.selectedValue;
michael@0 172 let selectedBreakpoint = gSources._selectedBreakpointItem;
michael@0 173
michael@0 174 ok(selectedUrl,
michael@0 175 "There should be a selected item in the sources pane for line " + aLine + ".");
michael@0 176 ok(!selectedBreakpoint,
michael@0 177 "There should be no selected brekapoint in the sources pane for line " + aLine + ".");
michael@0 178
michael@0 179 ok(isCaretPos(gPanel, aLine),
michael@0 180 "The editor caret position is not properly set.");
michael@0 181 }
michael@0 182
michael@0 183 function setCaretPosition(aLine) {
michael@0 184 gEditor.setCursor({ line: aLine - 1, ch: 0 });
michael@0 185 }
michael@0 186
michael@0 187 function clickOnBreakpoint(aIndex) {
michael@0 188 EventUtils.sendMouseEvent({ type: "click" },
michael@0 189 gDebugger.document.querySelectorAll(".dbg-breakpoint")[aIndex],
michael@0 190 gDebugger);
michael@0 191 }
michael@0 192 }

mercurial