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 727429: Test the debugger watch expressions.
6 */
8 const TAB_URL = EXAMPLE_URL + "doc_watch-expressions.html";
10 function test() {
11 // Debug test slaves are a bit slow at this test.
12 requestLongerTimeout(2);
14 let gTab, gDebuggee, gPanel, gDebugger;
15 let gEditor, gWatch, gVariables;
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;
26 gDebugger.DebuggerView.toggleInstrumentsPane({ visible: true, animated: false });
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 });
36 function performTest() {
37 is(gWatch.getAllStrings().length, 0,
38 "There should initially be no watch expressions.");
40 addAndCheckExpressions(1, 0, "a");
41 addAndCheckExpressions(2, 0, "b");
42 addAndCheckExpressions(3, 0, "c");
44 removeAndCheckExpression(2, 1, "a");
45 removeAndCheckExpression(1, 0, "a");
47 addAndCheckExpressions(2, 0, "", true);
48 gEditor.focus();
49 is(gWatch.getAllStrings().length, 1,
50 "Empty watch expressions are automatically removed.");
52 addAndCheckExpressions(2, 0, "a", true);
53 gEditor.focus();
54 is(gWatch.getAllStrings().length, 1,
55 "Duplicate watch expressions are automatically removed.");
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.");
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.");
71 addAndCheckCustomExpression(2, 0, "bazΩΩka");
72 addAndCheckCustomExpression(3, 0, "bambøøcha");
74 EventUtils.sendMouseEvent({ type: "click" },
75 gWatch.getItemAtIndex(0).attachment.view.closeNode,
76 gDebugger);
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).");
85 EventUtils.sendMouseEvent({ type: "click" },
86 gWatch.getItemAtIndex(0).attachment.view.closeNode,
87 gDebugger);
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).");
94 EventUtils.sendMouseEvent({ type: "click" },
95 gWatch.getItemAtIndex(0).attachment.view.closeNode,
96 gDebugger);
98 is(gWatch.getAllStrings().length, 0,
99 "Watch expressions are removed when the close button is pressed.");
101 EventUtils.sendMouseEvent({ type: "click" },
102 gWatch.widget._parent,
103 gDebugger);
105 is(gWatch.getAllStrings().length, 1,
106 "Watch expressions are added when the view container is pressed.");
107 }
109 function addAndCheckCustomExpression(aTotal, aIndex, aString, noBlur) {
110 addAndCheckExpressions(aTotal, aIndex, "", true);
112 for (let i = 0; i < aString.length; i++) {
113 EventUtils.sendChar(aString[i], gDebugger);
114 }
116 gEditor.focus();
118 let element = gWatch.getItemAtIndex(aIndex).target;
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).");
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).");
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 }
136 function addAndCheckExpressions(aTotal, aIndex, aString, noBlur) {
137 gWatch.addExpression(aString);
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).");
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.");
149 let element = gWatch.getItemAtIndex(aIndex).target;
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.");
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).");
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.");
170 is(gVariables.parentNode.scrollTop, 0,
171 "The variables view should be scrolled to top");
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).");
178 if (!noBlur) {
179 gEditor.focus();
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).");
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).");
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 }
198 function removeAndCheckExpression(aTotal, aIndex, aString) {
199 gWatch.removeAt(aIndex);
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).");
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.");
211 let element = gWatch.getItemAtIndex(aIndex).target;
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).");
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).");
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 }