browser/devtools/debugger/test/browser_dbg_watch-expressions-01.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:3a201da12771
1 /* Any copyright is dedicated to the Public Domain.
2 http://creativecommons.org/publicdomain/zero/1.0/ */
3
4 /**
5 * Bug 727429: Test the debugger watch expressions.
6 */
7
8 const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html";
9
10 function test() {
11 // Debug test slaves are a bit slow at this test.
12 requestLongerTimeout(2);
13
14 let gTab, gDebuggee, gPanel, gDebugger;
15 let gEditor, gWatch, gVariables;
16
17 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
18 gTab = aTab;
19 gDebuggee = aDebuggee;
20 gPanel = aPanel;
21 gDebugger = gPanel.panelWin;
22 gEditor = gDebugger.DebuggerView.editor;
23 gWatch = gDebugger.DebuggerView.WatchExpressions;
24 gVariables = gDebugger.DebuggerView.Variables;
25
26 gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false });
27
28 waitForSourceShown(gPanel, ".html")
29 .then(() => performTest())
30 .then(() => closeDebuggerAndFinish(gPanel))
31 .then(null, aError => {
32 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
33 });
34 });
35
36 function performTest() {
37 is(gWatch.getAllStrings().length, 0,
38 "There should initially be no watch expressions.");
39
40 addAndCheckExpressions(1, 0, "a");
41 addAndCheckExpressions(2, 0, "b");
42 addAndCheckExpressions(3, 0, "c");
43
44 removeAndCheckExpression(2, 1, "a");
45 removeAndCheckExpression(1, 0, "a");
46
47 addAndCheckExpressions(2, 0, "", true);
48 gEditor.focus();
49 is(gWatch.getAllStrings().length, 1,
50 "Empty watch expressions are automatically removed.");
51
52 addAndCheckExpressions(2, 0, "a", true);
53 gEditor.focus();
54 is(gWatch.getAllStrings().length, 1,
55 "Duplicate watch expressions are automatically removed.");
56
57 addAndCheckExpressions(2, 0, "a\t", true);
58 addAndCheckExpressions(2, 0, "a\r", true);
59 addAndCheckExpressions(2, 0, "a\n", true);
60 gEditor.focus();
61 is(gWatch.getAllStrings().length, 1,
62 "Duplicate watch expressions are automatically removed.");
63
64 addAndCheckExpressions(2, 0, "\ta", true);
65 addAndCheckExpressions(2, 0, "\ra", true);
66 addAndCheckExpressions(2, 0, "\na", true);
67 gEditor.focus();
68 is(gWatch.getAllStrings().length, 1,
69 "Duplicate watch expressions are automatically removed.");
70
71 addAndCheckCustomExpression(2, 0, "bazΩΩka");
72 addAndCheckCustomExpression(3, 0, "bambøøcha");
73
74 EventUtils.sendMouseEvent({ type: "click" },
75 gWatch.getItemAtIndex(0).attachment.view.closeNode,
76 gDebugger);
77
78 is(gWatch.getAllStrings().length, 2,
79 "Watch expressions are removed when the close button is pressed.");
80 is(gWatch.getAllStrings()[0], "bazΩΩka",
81 "The expression at index " + 0 + " should be correct (1).");
82 is(gWatch.getAllStrings()[1], "a",
83 "The expression at index " + 1 + " should be correct (2).");
84
85 EventUtils.sendMouseEvent({ type: "click" },
86 gWatch.getItemAtIndex(0).attachment.view.closeNode,
87 gDebugger);
88
89 is(gWatch.getAllStrings().length, 1,
90 "Watch expressions are removed when the close button is pressed.");
91 is(gWatch.getAllStrings()[0], "a",
92 "The expression at index " + 0 + " should be correct (3).");
93
94 EventUtils.sendMouseEvent({ type: "click" },
95 gWatch.getItemAtIndex(0).attachment.view.closeNode,
96 gDebugger);
97
98 is(gWatch.getAllStrings().length, 0,
99 "Watch expressions are removed when the close button is pressed.");
100
101 EventUtils.sendMouseEvent({ type: "click" },
102 gWatch.widget._parent,
103 gDebugger);
104
105 is(gWatch.getAllStrings().length, 1,
106 "Watch expressions are added when the view container is pressed.");
107 }
108
109 function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) {
110 addAndCheckExpressions(aTotal, aIndex, "", true);
111
112 for (let i = 0; i < aString.length; i++) {
113 EventUtils.sendChar(aString[i], gDebugger);
114 }
115
116 gEditor.focus();
117
118 let element = gWatch.getItemAtIndex(aIndex).target;
119
120 is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, "",
121 "The initial expression at index " + aIndex + " should be correct (1).");
122 is(gWatch.getItemForElement(element).attachment.initialExpression, "",
123 "The initial expression at index " + aIndex + " should be correct (2).");
124
125 is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
126 "The expression at index " + aIndex + " should be correct (1).");
127 is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
128 "The expression at index " + aIndex + " should be correct (2).");
129
130 is(gWatch.getString(aIndex), aString,
131 "The expression at index " + aIndex + " should be correct (3).");
132 is(gWatch.getAllStrings()[aIndex], aString,
133 "The expression at index " + aIndex + " should be correct (4).");
134 }
135
136 function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) {
137 gWatch.addExpression(aString);
138
139 is(gWatch.getAllStrings().length, aTotal,
140 "There should be " + aTotal + " watch expressions available (1).");
141 is(gWatch.itemCount, aTotal,
142 "There should be " + aTotal + " watch expressions available (2).");
143
144 ok(gWatch.getItemAtIndex(aIndex),
145 "The expression at index " + aIndex + " should be available.");
146 is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
147 "The expression at index " + aIndex + " should have an initial expression.");
148
149 let element = gWatch.getItemAtIndex(aIndex).target;
150
151 ok(element,
152 "There should be a new expression item in the view.");
153 ok(gWatch.getItemForElement(element),
154 "The watch expression item should be accessible.");
155 is(gWatch.getItemForElement(element), gWatch.getItemAtIndex(aIndex),
156 "The correct watch expression item was accessed.");
157
158 ok(gWatch.widget.getItemAtIndex(aIndex) instanceof XULElement,
159 "The correct watch expression element was accessed (1).");
160 is(element, gWatch.widget.getItemAtIndex(aIndex),
161 "The correct watch expression element was accessed (2).");
162
163 is(gWatch.getItemForElement(element).attachment.view.arrowNode.hidden, false,
164 "The arrow node should be visible.");
165 is(gWatch.getItemForElement(element).attachment.view.closeNode.hidden, false,
166 "The close button should be visible.");
167 is(gWatch.getItemForElement(element).attachment.view.inputNode.getAttribute("focused"), "true",
168 "The textbox input should be focused.");
169
170 is(gVariables.parentNode.scrollTop, 0,
171 "The variables view should be scrolled to top");
172
173 is(gWatch.items[0], gWatch.getItemAtIndex(aIndex),
174 "The correct watch expression was added to the cache (1).");
175 is(gWatch.items[0], gWatch.getItemForElement(element),
176 "The correct watch expression was added to the cache (2).");
177
178 if (!noBlur) {
179 gEditor.focus();
180
181 is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
182 "The initial expression at index " + aIndex + " should be correct (1).");
183 is(gWatch.getItemForElement(element).attachment.initialExpression, aString,
184 "The initial expression at index " + aIndex + " should be correct (2).");
185
186 is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
187 "The expression at index " + aIndex + " should be correct (1).");
188 is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
189 "The expression at index " + aIndex + " should be correct (2).");
190
191 is(gWatch.getString(aIndex), aString,
192 "The expression at index " + aIndex + " should be correct (3).");
193 is(gWatch.getAllStrings()[aIndex], aString,
194 "The expression at index " + aIndex + " should be correct (4).");
195 }
196 }
197
198 function removeAndCheckExpression(aTotal, aIndex, aString) {
199 gWatch.removeAt(aIndex);
200
201 is(gWatch.getAllStrings().length, aTotal,
202 "There should be " + aTotal + " watch expressions available (1).");
203 is(gWatch.itemCount, aTotal,
204 "There should be " + aTotal + " watch expressions available (2).");
205
206 ok(gWatch.getItemAtIndex(aIndex),
207 "The expression at index " + aIndex + " should still be available.");
208 is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
209 "The expression at index " + aIndex + " should still have an initial expression.");
210
211 let element = gWatch.getItemAtIndex(aIndex).target;
212
213 is(gWatch.getItemAtIndex(aIndex).attachment.initialExpression, aString,
214 "The initial expression at index " + aIndex + " should be correct (1).");
215 is(gWatch.getItemForElement(element).attachment.initialExpression, aString,
216 "The initial expression at index " + aIndex + " should be correct (2).");
217
218 is(gWatch.getItemAtIndex(aIndex).attachment.currentExpression, aString,
219 "The expression at index " + aIndex + " should be correct (1).");
220 is(gWatch.getItemForElement(element).attachment.currentExpression, aString,
221 "The expression at index " + aIndex + " should be correct (2).");
222
223 is(gWatch.getString(aIndex), aString,
224 "The expression at index " + aIndex + " should be correct (3).");
225 is(gWatch.getAllStrings()[aIndex], aString,
226 "The expression at index " + aIndex + " should be correct (4).");
227 }
228 }

mercurial