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 * Make sure that the editing or removing watch expressions works properly.
6 */
8 const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html";
10 let gTab, gDebuggee, gPanel, gDebugger;
11 let gL10N, gEditor, gVars, gWatch;
13 function test() {
14 initDebugger(TAB_URL).then(([aTab, aDebuggee, aPanel]) => {
15 gTab = aTab;
16 gDebuggee = aDebuggee;
17 gPanel = aPanel;
18 gDebugger = gPanel.panelWin;
19 gL10N = gDebugger.L10N;
20 gEditor = gDebugger.DebuggerView.editor;
21 gVars = gDebugger.DebuggerView.Variables;
22 gWatch = gDebugger.DebuggerView.WatchExpressions;
24 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS)
25 .then(() => testInitialVariablesInScope())
26 .then(() => testInitialExpressionsInScope())
27 .then(() => testModification("document.title = 42", "document.title = 43", "43", "undefined"))
28 .then(() => testIntegrity1())
29 .then(() => testModification("aArg", "aArg = 44", "44", "44"))
30 .then(() => testIntegrity2())
31 .then(() => testModification("aArg = 44", "\ \t\r\ndocument.title\ \t\r\n", "\"43\"", "44"))
32 .then(() => testIntegrity3())
33 .then(() => testModification("document.title = 43", "\ \t\r\ndocument.title\ \t\r\n", "\"43\"", "44"))
34 .then(() => testIntegrity4())
35 .then(() => testModification("document.title", "\ \t\r\n", "\"43\"", "44"))
36 .then(() => testIntegrity5())
37 .then(() => testExprDeletion("this", "44"))
38 .then(() => testIntegrity6())
39 .then(() => testExprFinalDeletion("ermahgerd", "44"))
40 .then(() => testIntegrity7())
41 .then(() => resumeDebuggerThenCloseAndFinish(gPanel))
42 .then(null, aError => {
43 ok(false, "Got an error: " + aError.message + "\n" + aError.stack);
44 });
46 addExpressions();
47 gDebuggee.ermahgerd();
48 });
49 }
51 function addExpressions() {
52 addExpression("this");
53 addExpression("ermahgerd");
54 addExpression("aArg");
55 addExpression("document.title");
56 addCmdExpression("document.title = 42");
58 is(gWatch.itemCount, 5,
59 "There should be 5 items availalble in the watch expressions view.");
61 is(gWatch.getItemAtIndex(4).attachment.initialExpression, "this",
62 "The first expression's initial value should be correct.");
63 is(gWatch.getItemAtIndex(3).attachment.initialExpression, "ermahgerd",
64 "The second expression's initial value should be correct.");
65 is(gWatch.getItemAtIndex(2).attachment.initialExpression, "aArg",
66 "The third expression's initial value should be correct.");
67 is(gWatch.getItemAtIndex(1).attachment.initialExpression, "document.title",
68 "The fourth expression's initial value should be correct.");
69 is(gWatch.getItemAtIndex(0).attachment.initialExpression, "document.title = 42",
70 "The fifth expression's initial value should be correct.");
72 is(gWatch.getItemAtIndex(4).attachment.currentExpression, "this",
73 "The first expression's current value should be correct.");
74 is(gWatch.getItemAtIndex(3).attachment.currentExpression, "ermahgerd",
75 "The second expression's current value should be correct.");
76 is(gWatch.getItemAtIndex(2).attachment.currentExpression, "aArg",
77 "The third expression's current value should be correct.");
78 is(gWatch.getItemAtIndex(1).attachment.currentExpression, "document.title",
79 "The fourth expression's current value should be correct.");
80 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "document.title = 42",
81 "The fifth expression's current value should be correct.");
82 }
84 function testInitialVariablesInScope() {
85 let localScope = gVars.getScopeAtIndex(1);
86 let argVar = localScope.get("aArg");
88 is(argVar.visible, true,
89 "Should have the right visibility state for 'aArg'.");
90 is(argVar.name, "aArg",
91 "Should have the right name for 'aArg'.");
92 is(argVar.value.type, "undefined",
93 "Should have the right initial value for 'aArg'.");
94 }
96 function testInitialExpressionsInScope() {
97 let exprScope = gVars.getScopeAtIndex(0);
98 let thisExpr = exprScope.get("this");
99 let ermExpr = exprScope.get("ermahgerd");
100 let argExpr = exprScope.get("aArg");
101 let docExpr = exprScope.get("document.title");
102 let docExpr2 = exprScope.get("document.title = 42");
104 ok(exprScope,
105 "There should be a wach expressions scope in the variables view.");
106 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
107 "The scope's name should be marked as 'Watch Expressions'.");
108 is(exprScope._store.size, 5,
109 "There should be 5 evaluations available.");
111 is(thisExpr.visible, true,
112 "Should have the right visibility state for 'this'.");
113 is(thisExpr.target.querySelectorAll(".variables-view-delete").length, 1,
114 "Should have the one close button visible for 'this'.");
115 is(thisExpr.name, "this",
116 "Should have the right name for 'this'.");
117 is(thisExpr.value.type, "object",
118 "Should have the right value type for 'this'.");
119 is(thisExpr.value.class, "Window",
120 "Should have the right value type for 'this'.");
122 is(ermExpr.visible, true,
123 "Should have the right visibility state for 'ermahgerd'.");
124 is(ermExpr.target.querySelectorAll(".variables-view-delete").length, 1,
125 "Should have the one close button visible for 'ermahgerd'.");
126 is(ermExpr.name, "ermahgerd",
127 "Should have the right name for 'ermahgerd'.");
128 is(ermExpr.value.type, "object",
129 "Should have the right value type for 'ermahgerd'.");
130 is(ermExpr.value.class, "Function",
131 "Should have the right value type for 'ermahgerd'.");
133 is(argExpr.visible, true,
134 "Should have the right visibility state for 'aArg'.");
135 is(argExpr.target.querySelectorAll(".variables-view-delete").length, 1,
136 "Should have the one close button visible for 'aArg'.");
137 is(argExpr.name, "aArg",
138 "Should have the right name for 'aArg'.");
139 is(argExpr.value.type, "undefined",
140 "Should have the right value for 'aArg'.");
142 is(docExpr.visible, true,
143 "Should have the right visibility state for 'document.title'.");
144 is(docExpr.target.querySelectorAll(".variables-view-delete").length, 1,
145 "Should have the one close button visible for 'document.title'.");
146 is(docExpr.name, "document.title",
147 "Should have the right name for 'document.title'.");
148 is(docExpr.value, "42",
149 "Should have the right value for 'document.title'.");
151 is(docExpr2.visible, true,
152 "Should have the right visibility state for 'document.title = 42'.");
153 is(docExpr2.target.querySelectorAll(".variables-view-delete").length, 1,
154 "Should have the one close button visible for 'document.title = 42'.");
155 is(docExpr2.name, "document.title = 42",
156 "Should have the right name for 'document.title = 42'.");
157 is(docExpr2.value, 42,
158 "Should have the right value for 'document.title = 42'.");
160 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 5,
161 "There should be 5 hidden nodes in the watch expressions container.");
162 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
163 "There should be 0 visible nodes in the watch expressions container.");
164 }
166 function testModification(aName, aNewValue, aNewResult, aArgResult) {
167 let exprScope = gVars.getScopeAtIndex(0);
168 let exprVar = exprScope.get(aName);
170 let finished = promise.all([
171 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES),
172 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS)
173 ])
174 .then(() => {
175 let localScope = gVars.getScopeAtIndex(1);
176 let argVar = localScope.get("aArg");
178 is(argVar.visible, true,
179 "Should have the right visibility state for 'aArg'.");
180 is(argVar.target.querySelector(".name").getAttribute("value"), "aArg",
181 "Should have the right name for 'aArg'.");
182 is(argVar.target.querySelector(".value").getAttribute("value"), aArgResult,
183 "Should have the right new value for 'aArg'.");
185 let exprScope = gVars.getScopeAtIndex(0);
186 let exprOldVar = exprScope.get(aName);
187 let exprNewVar = exprScope.get(aNewValue.trim());
189 if (!aNewValue.trim()) {
190 ok(!exprOldVar,
191 "The old watch expression should have been removed.");
192 ok(!exprNewVar,
193 "No new watch expression should have been added.");
194 } else {
195 ok(!exprOldVar,
196 "The old watch expression should have been removed.");
197 ok(exprNewVar,
198 "The new watch expression should have been added.");
200 is(exprNewVar.visible, true,
201 "Should have the right visibility state for the watch expression.");
202 is(exprNewVar.target.querySelector(".name").getAttribute("value"), aNewValue.trim(),
203 "Should have the right name for the watch expression.");
204 is(exprNewVar.target.querySelector(".value").getAttribute("value"), aNewResult,
205 "Should have the right new value for the watch expression.");
206 }
207 });
209 let varValue = exprVar.target.querySelector(".title > .name");
210 EventUtils.sendMouseEvent({ type: "dblclick" }, varValue, gDebugger);
212 let varInput = exprVar.target.querySelector(".title > .element-name-input");
213 setText(varInput, aNewValue);
214 EventUtils.sendKey("RETURN", gDebugger);
216 return finished;
217 }
219 function testExprDeletion(aName, aArgResult) {
220 let exprScope = gVars.getScopeAtIndex(0);
221 let exprVar = exprScope.get(aName);
223 let finished = promise.all([
224 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES),
225 waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_WATCH_EXPRESSIONS)
226 ])
227 .then(() => {
228 let localScope = gVars.getScopeAtIndex(1);
229 let argVar = localScope.get("aArg");
231 is(argVar.visible, true,
232 "Should have the right visibility state for 'aArg'.");
233 is(argVar.target.querySelector(".name").getAttribute("value"), "aArg",
234 "Should have the right name for 'aArg'.");
235 is(argVar.target.querySelector(".value").getAttribute("value"), aArgResult,
236 "Should have the right new value for 'aArg'.");
238 let exprScope = gVars.getScopeAtIndex(0);
239 let exprOldVar = exprScope.get(aName);
241 ok(!exprOldVar,
242 "The watch expression should have been deleted.");
243 });
245 let varDelete = exprVar.target.querySelector(".variables-view-delete");
246 EventUtils.sendMouseEvent({ type: "click" }, varDelete, gDebugger);
248 return finished;
249 }
251 function testExprFinalDeletion(aName, aArgResult) {
252 let exprScope = gVars.getScopeAtIndex(0);
253 let exprVar = exprScope.get(aName);
255 let finished = waitForDebuggerEvents(gPanel, gDebugger.EVENTS.FETCHED_SCOPES).then(() => {
256 let localScope = gVars.getScopeAtIndex(0);
257 let argVar = localScope.get("aArg");
259 is(argVar.visible, true,
260 "Should have the right visibility state for 'aArg'.");
261 is(argVar.target.querySelector(".name").getAttribute("value"), "aArg",
262 "Should have the right name for 'aArg'.");
263 is(argVar.target.querySelector(".value").getAttribute("value"), aArgResult,
264 "Should have the right new value for 'aArg'.");
266 let exprScope = gVars.getScopeAtIndex(0);
267 let exprOldVar = exprScope.get(aName);
269 ok(!exprOldVar,
270 "The watch expression should have been deleted.");
271 });
273 let varDelete = exprVar.target.querySelector(".variables-view-delete");
274 EventUtils.sendMouseEvent({ type: "click" }, varDelete, gDebugger);
276 return finished;
277 }
279 function testIntegrity1() {
280 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 5,
281 "There should be 5 hidden nodes in the watch expressions container.");
282 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
283 "There should be 0 visible nodes in the watch expressions container.");
285 let exprScope = gVars.getScopeAtIndex(0);
286 ok(exprScope,
287 "There should be a wach expressions scope in the variables view.");
288 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
289 "The scope's name should be marked as 'Watch Expressions'.");
290 is(exprScope._store.size, 5,
291 "There should be 5 visible evaluations available.");
293 is(gWatch.itemCount, 5,
294 "There should be 5 hidden expression input available.");
295 is(gWatch.getItemAtIndex(0).attachment.view.inputNode.value, "document.title = 43",
296 "The first textbox input value is not the correct one.");
297 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "document.title = 43",
298 "The first textbox input value is not the correct one.");
299 is(gWatch.getItemAtIndex(1).attachment.view.inputNode.value, "document.title",
300 "The second textbox input value is not the correct one.");
301 is(gWatch.getItemAtIndex(1).attachment.currentExpression, "document.title",
302 "The second textbox input value is not the correct one.");
303 is(gWatch.getItemAtIndex(2).attachment.view.inputNode.value, "aArg",
304 "The third textbox input value is not the correct one.");
305 is(gWatch.getItemAtIndex(2).attachment.currentExpression, "aArg",
306 "The third textbox input value is not the correct one.");
307 is(gWatch.getItemAtIndex(3).attachment.view.inputNode.value, "ermahgerd",
308 "The fourth textbox input value is not the correct one.");
309 is(gWatch.getItemAtIndex(3).attachment.currentExpression, "ermahgerd",
310 "The fourth textbox input value is not the correct one.");
311 is(gWatch.getItemAtIndex(4).attachment.view.inputNode.value, "this",
312 "The fifth textbox input value is not the correct one.");
313 is(gWatch.getItemAtIndex(4).attachment.currentExpression, "this",
314 "The fifth textbox input value is not the correct one.");
315 }
317 function testIntegrity2() {
318 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 5,
319 "There should be 5 hidden nodes in the watch expressions container.");
320 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
321 "There should be 0 visible nodes in the watch expressions container.");
323 let exprScope = gVars.getScopeAtIndex(0);
324 ok(exprScope,
325 "There should be a wach expressions scope in the variables view.");
326 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
327 "The scope's name should be marked as 'Watch Expressions'.");
328 is(exprScope._store.size, 5,
329 "There should be 5 visible evaluations available.");
331 is(gWatch.itemCount, 5,
332 "There should be 5 hidden expression input available.");
333 is(gWatch.getItemAtIndex(0).attachment.view.inputNode.value, "document.title = 43",
334 "The first textbox input value is not the correct one.");
335 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "document.title = 43",
336 "The first textbox input value is not the correct one.");
337 is(gWatch.getItemAtIndex(1).attachment.view.inputNode.value, "document.title",
338 "The second textbox input value is not the correct one.");
339 is(gWatch.getItemAtIndex(1).attachment.currentExpression, "document.title",
340 "The second textbox input value is not the correct one.");
341 is(gWatch.getItemAtIndex(2).attachment.view.inputNode.value, "aArg = 44",
342 "The third textbox input value is not the correct one.");
343 is(gWatch.getItemAtIndex(2).attachment.currentExpression, "aArg = 44",
344 "The third textbox input value is not the correct one.");
345 is(gWatch.getItemAtIndex(3).attachment.view.inputNode.value, "ermahgerd",
346 "The fourth textbox input value is not the correct one.");
347 is(gWatch.getItemAtIndex(3).attachment.currentExpression, "ermahgerd",
348 "The fourth textbox input value is not the correct one.");
349 is(gWatch.getItemAtIndex(4).attachment.view.inputNode.value, "this",
350 "The fifth textbox input value is not the correct one.");
351 is(gWatch.getItemAtIndex(4).attachment.currentExpression, "this",
352 "The fifth textbox input value is not the correct one.");
353 }
355 function testIntegrity3() {
356 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 4,
357 "There should be 4 hidden nodes in the watch expressions container.");
358 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
359 "There should be 0 visible nodes in the watch expressions container.");
361 let exprScope = gVars.getScopeAtIndex(0);
362 ok(exprScope,
363 "There should be a wach expressions scope in the variables view.");
364 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
365 "The scope's name should be marked as 'Watch Expressions'.");
366 is(exprScope._store.size, 4,
367 "There should be 4 visible evaluations available.");
369 is(gWatch.itemCount, 4,
370 "There should be 4 hidden expression input available.");
371 is(gWatch.getItemAtIndex(0).attachment.view.inputNode.value, "document.title = 43",
372 "The first textbox input value is not the correct one.");
373 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "document.title = 43",
374 "The first textbox input value is not the correct one.");
375 is(gWatch.getItemAtIndex(1).attachment.view.inputNode.value, "document.title",
376 "The second textbox input value is not the correct one.");
377 is(gWatch.getItemAtIndex(1).attachment.currentExpression, "document.title",
378 "The second textbox input value is not the correct one.");
379 is(gWatch.getItemAtIndex(2).attachment.view.inputNode.value, "ermahgerd",
380 "The third textbox input value is not the correct one.");
381 is(gWatch.getItemAtIndex(2).attachment.currentExpression, "ermahgerd",
382 "The third textbox input value is not the correct one.");
383 is(gWatch.getItemAtIndex(3).attachment.view.inputNode.value, "this",
384 "The fourth textbox input value is not the correct one.");
385 is(gWatch.getItemAtIndex(3).attachment.currentExpression, "this",
386 "The fourth textbox input value is not the correct one.");
387 }
389 function testIntegrity4() {
390 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 3,
391 "There should be 3 hidden nodes in the watch expressions container.");
392 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
393 "There should be 0 visible nodes in the watch expressions container.");
395 let exprScope = gVars.getScopeAtIndex(0);
396 ok(exprScope,
397 "There should be a wach expressions scope in the variables view.");
398 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
399 "The scope's name should be marked as 'Watch Expressions'.");
400 is(exprScope._store.size, 3,
401 "There should be 3 visible evaluations available.");
403 is(gWatch.itemCount, 3,
404 "There should be 3 hidden expression input available.");
405 is(gWatch.getItemAtIndex(0).attachment.view.inputNode.value, "document.title",
406 "The first textbox input value is not the correct one.");
407 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "document.title",
408 "The first textbox input value is not the correct one.");
409 is(gWatch.getItemAtIndex(1).attachment.view.inputNode.value, "ermahgerd",
410 "The second textbox input value is not the correct one.");
411 is(gWatch.getItemAtIndex(1).attachment.currentExpression, "ermahgerd",
412 "The second textbox input value is not the correct one.");
413 is(gWatch.getItemAtIndex(2).attachment.view.inputNode.value, "this",
414 "The third textbox input value is not the correct one.");
415 is(gWatch.getItemAtIndex(2).attachment.currentExpression, "this",
416 "The third textbox input value is not the correct one.");
417 }
419 function testIntegrity5() {
420 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 2,
421 "There should be 2 hidden nodes in the watch expressions container.");
422 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
423 "There should be 0 visible nodes in the watch expressions container.");
425 let exprScope = gVars.getScopeAtIndex(0);
426 ok(exprScope,
427 "There should be a wach expressions scope in the variables view.");
428 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
429 "The scope's name should be marked as 'Watch Expressions'.");
430 is(exprScope._store.size, 2,
431 "There should be 2 visible evaluations available.");
433 is(gWatch.itemCount, 2,
434 "There should be 2 hidden expression input available.");
435 is(gWatch.getItemAtIndex(0).attachment.view.inputNode.value, "ermahgerd",
436 "The first textbox input value is not the correct one.");
437 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "ermahgerd",
438 "The first textbox input value is not the correct one.");
439 is(gWatch.getItemAtIndex(1).attachment.view.inputNode.value, "this",
440 "The second textbox input value is not the correct one.");
441 is(gWatch.getItemAtIndex(1).attachment.currentExpression, "this",
442 "The second textbox input value is not the correct one.");
443 }
445 function testIntegrity6() {
446 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 1,
447 "There should be 1 hidden nodes in the watch expressions container.");
448 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
449 "There should be 0 visible nodes in the watch expressions container.");
451 let exprScope = gVars.getScopeAtIndex(0);
452 ok(exprScope,
453 "There should be a wach expressions scope in the variables view.");
454 is(exprScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
455 "The scope's name should be marked as 'Watch Expressions'.");
456 is(exprScope._store.size, 1,
457 "There should be 1 visible evaluation available.");
459 is(gWatch.itemCount, 1,
460 "There should be 1 hidden expression input available.");
461 is(gWatch.getItemAtIndex(0).attachment.view.inputNode.value, "ermahgerd",
462 "The first textbox input value is not the correct one.");
463 is(gWatch.getItemAtIndex(0).attachment.currentExpression, "ermahgerd",
464 "The first textbox input value is not the correct one.");
465 }
467 function testIntegrity7() {
468 is(gDebugger.document.querySelectorAll(".dbg-expression[hidden=true]").length, 0,
469 "There should be 0 hidden nodes in the watch expressions container.");
470 is(gDebugger.document.querySelectorAll(".dbg-expression:not([hidden=true])").length, 0,
471 "There should be 0 visible nodes in the watch expressions container.");
473 let localScope = gVars.getScopeAtIndex(0);
474 ok(localScope,
475 "There should be a local scope in the variables view.");
476 isnot(localScope.name, gL10N.getStr("watchExpressionsScopeLabel"),
477 "The scope's name should not be marked as 'Watch Expressions'.");
478 isnot(localScope._store.size, 0,
479 "There should be some variables available.");
481 is(gWatch.itemCount, 0,
482 "The watch expressions container should be empty.");
483 }
485 function addExpression(aString) {
486 gWatch.addExpression(aString);
487 gEditor.focus();
488 }
490 function addCmdExpression(aString) {
491 gWatch._onCmdAddExpression(aString);
492 gEditor.focus();
493 }
495 registerCleanupFunction(function() {
496 gTab = null;
497 gDebuggee = null;
498 gPanel = null;
499 gDebugger = null;
500 gL10N = null;
501 gEditor = null;
502 gVars = null;
503 gWatch = null;
504 });