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