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 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/ */
6 "use strict";
8 let gWindow = null;
9 var gFrame = null;
11 const kMarkerOffsetY = 6;
12 const kCommonWaitMs = 5000;
13 const kCommonPollMs = 100;
15 ///////////////////////////////////////////////////
16 // content (non-editable) tests
17 ///////////////////////////////////////////////////
19 function setUpAndTearDown() {
20 emptyClipboard();
21 if (gWindow)
22 clearSelection(gWindow);
23 if (gFrame)
24 clearSelection(gFrame);
25 yield waitForCondition(function () {
26 return !SelectionHelperUI.isSelectionUIVisible;
27 }, kCommonWaitMs, kCommonPollMs);
28 InputSourceHelper.isPrecise = false;
29 InputSourceHelper.fireUpdate();
30 }
32 gTests.push({
33 desc: "normalize browser",
34 setUp: setUpAndTearDown,
35 tearDown: setUpAndTearDown,
36 run: function test() {
37 info(chromeRoot + "browser_selection_basic.html");
38 yield addTab(chromeRoot + "browser_selection_basic.html");
40 yield waitForCondition(function () {
41 return !BrowserUI.isStartTabVisible;
42 }, 10000, 100);
44 yield hideContextUI();
46 gWindow = Browser.selectedTab.browser.contentWindow;
47 },
48 });
50 gTests.push({
51 desc: "tap-hold to select",
52 setUp: setUpAndTearDown,
53 tearDown: setUpAndTearDown,
54 run: function test() {
55 sendContextMenuClick(30, 20);
57 yield waitForCondition(function () {
58 return SelectionHelperUI.isSelectionUIVisible;
59 }, kCommonWaitMs, kCommonPollMs);
61 is(getTrimmedSelection(gWindow).toString(), "There", "selection test");
62 },
63 });
65 gTests.push({
66 desc: "appbar interactions",
67 setUp: setUpAndTearDown,
68 tearDown: setUpAndTearDown,
69 run: function test() {
70 sendContextMenuClick(100, 20);
72 yield waitForCondition(function () {
73 return SelectionHelperUI.isSelectionUIVisible;
74 }, kCommonWaitMs, kCommonPollMs);
76 is(SelectionHelperUI.isActive, true, "selection active");
77 is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test");
79 yield fireAppBarDisplayEvent();
81 ok(ContextUI.isVisible, true, "appbar visible");
83 yield hideContextUI();
85 ok(!ContextUI.isVisible, true, "appbar hidden");
86 },
87 });
89 gTests.push({
90 desc: "simple drag selection",
91 setUp: setUpAndTearDown,
92 tearDown: setUpAndTearDown,
93 run: function test() {
94 yield waitForMs(100);
95 sendContextMenuClick(100, 20);
97 yield waitForCondition(function () {
98 return SelectionHelperUI.isSelectionUIVisible;
99 }, kCommonWaitMs, kCommonPollMs);
101 is(SelectionHelperUI.isActive, true, "selection active");
102 is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test");
104 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
106 let touchdrag = new TouchDragAndHold();
107 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 190, ypos);
108 touchdrag.end();
110 yield waitForCondition(function () {
111 return !SelectionHelperUI.hasActiveDrag;
112 }, kCommonWaitMs, kCommonPollMs);
113 yield SelectionHelperUI.pingSelectionHandler();
115 is(SelectionHelperUI.isActive, true, "selection active");
116 is(getTrimmedSelection(gWindow).toString(), "nothing so VERY", "selection test");
117 },
118 });
120 gTests.push({
121 desc: "expand / collapse selection",
122 setUp: setUpAndTearDown,
123 tearDown: setUpAndTearDown,
124 run: function test() {
125 sendContextMenuClick(30, 20);
127 yield waitForCondition(function () {
128 return SelectionHelperUI.isSelectionUIVisible;
129 }, kCommonWaitMs, kCommonPollMs);
131 is(SelectionHelperUI.isActive, true, "initial active");
132 is(getTrimmedSelection(gWindow).toString(), "There", "initial selection test");
134 for (let count = 0; count < 5; count++) {
135 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
137 let touchdrag = new TouchDragAndHold();
138 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
139 touchdrag.end();
141 yield waitForCondition(function () {
142 return !SelectionHelperUI.hasActiveDrag;
143 }, kCommonWaitMs, kCommonPollMs);
144 yield SelectionHelperUI.pingSelectionHandler();
146 is(getTrimmedSelection(gWindow).toString(),
147 "There was nothing so VERY remarkable in that; nor did Alice think it so",
148 "long selection test");
150 is(SelectionHelperUI.isActive, true, "selection active");
152 touchdrag = new TouchDragAndHold();
153 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 40, ypos);
154 touchdrag.end();
156 yield waitForCondition(function () {
157 return !SelectionHelperUI.hasActiveDrag;
158 }, kCommonWaitMs, kCommonPollMs);
159 yield SelectionHelperUI.pingSelectionHandler();
161 is(SelectionHelperUI.isActive, true, "selection active");
162 is(getTrimmedSelection(gWindow).toString(), "There was", "short selection test");
163 }
164 },
165 });
167 gTests.push({
168 desc: "expand / collapse selection scolled content",
169 setUp: setUpAndTearDown,
170 run: function test() {
171 let scrollPromise = waitForEvent(gWindow, "scroll");
172 gWindow.scrollBy(0, 200);
173 yield scrollPromise;
174 ok(scrollPromise && !(scrollPromise instanceof Error), "scrollPromise error");
176 sendContextMenuClick(106, 20);
178 yield waitForCondition(function () {
179 return SelectionHelperUI.isSelectionUIVisible;
180 }, kCommonWaitMs, kCommonPollMs);
182 is(SelectionHelperUI.isActive, true, "selection active");
183 is(getTrimmedSelection(gWindow).toString(), "moment", "selection test");
185 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
187 let touchdrag = new TouchDragAndHold();
188 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
189 touchdrag.end();
191 yield waitForCondition(function () {
192 return !SelectionHelperUI.hasActiveDrag;
193 }, kCommonWaitMs, kCommonPollMs);
194 yield SelectionHelperUI.pingSelectionHandler();
196 is(getTrimmedSelection(gWindow).toString(),
197 "moment down went Alice after it, never once considering how in",
198 "selection test");
200 is(SelectionHelperUI.isActive, true, "selection active");
202 touchdrag = new TouchDragAndHold();
203 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 150, ypos);
204 touchdrag.end();
206 yield waitForCondition(function () {
207 return !SelectionHelperUI.hasActiveDrag;
208 }, kCommonWaitMs, kCommonPollMs);
209 yield SelectionHelperUI.pingSelectionHandler();
211 is(getTrimmedSelection(gWindow).toString(), "moment down went", "selection test");
213 touchdrag = new TouchDragAndHold();
214 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
215 touchdrag.end();
217 yield waitForCondition(function () {
218 return !SelectionHelperUI.hasActiveDrag;
219 }, kCommonWaitMs, kCommonPollMs);
220 yield SelectionHelperUI.pingSelectionHandler();
222 is(getTrimmedSelection(gWindow).toString(),
223 "moment down went Alice after it, never once considering how in",
224 "selection test");
226 touchdrag = new TouchDragAndHold();
227 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 160, ypos);
228 touchdrag.end();
230 yield waitForCondition(function () {
231 return !SelectionHelperUI.hasActiveDrag;
232 }, kCommonWaitMs, kCommonPollMs);
233 yield SelectionHelperUI.pingSelectionHandler();
235 is(getTrimmedSelection(gWindow).toString(),
236 "moment down went",
237 "selection test");
238 },
239 tearDown: function tearDown() {
240 let scrollPromise = waitForEvent(gWindow, "scroll");
241 gWindow.scrollBy(0, -200);
242 yield scrollPromise;
243 emptyClipboard();
244 if (gWindow)
245 clearSelection(gWindow);
246 if (gFrame)
247 clearSelection(gFrame);
248 yield waitForCondition(function () {
249 return !SelectionHelperUI.isSelectionUIVisible;
250 }, kCommonWaitMs, kCommonPollMs);
251 yield hideContextUI();
252 },
253 });
255 gTests.push({
256 desc: "tap on selection clears selection in content",
257 setUp: setUpAndTearDown,
258 run: function test() {
260 sendContextMenuClick(30, 20);
262 yield waitForCondition(function () {
263 return SelectionHelperUI.isSelectionUIVisible;
264 }, kCommonWaitMs, kCommonPollMs);
266 sendTap(gWindow, 30, 20);
268 yield waitForCondition(function () {
269 return !SelectionHelperUI.isSelectionUIVisible;
270 }, kCommonWaitMs, kCommonPollMs);
271 },
272 tearDown: setUpAndTearDown,
273 });
275 gTests.push({
276 desc: "tap off selection clears selection in content",
277 setUp: setUpAndTearDown,
278 run: function test() {
280 sendContextMenuClick(30, 20);
282 yield waitForCondition(function () {
283 return SelectionHelperUI.isSelectionUIVisible;
284 }, kCommonWaitMs, kCommonPollMs);
286 sendTap(gWindow, 30, 100);
288 yield waitForCondition(function () {
289 return !SelectionHelperUI.isSelectionUIVisible;
290 }, kCommonWaitMs, kCommonPollMs);
291 },
292 tearDown: setUpAndTearDown,
293 });
295 gTests.push({
296 desc: "bug 903737 - right click targeting",
297 setUp: setUpAndTearDown,
298 run: function test() {
299 yield hideContextUI();
300 let range = gWindow.document.createRange();
301 range.selectNode(gWindow.document.getElementById("seldiv"));
302 gWindow.getSelection().addRange(range);
303 let promise = waitForEvent(document, "popupshown");
304 sendContextMenuClickToElement(gWindow, gWindow.document.getElementById("seldiv"));
305 yield promise;
306 promise = waitForEvent(document, "popuphidden");
307 ContextMenuUI.hide();
308 yield promise;
309 let emptydiv = gWindow.document.getElementById("emptydiv");
310 let coords = logicalCoordsForElement(emptydiv);
311 InputSourceHelper.isPrecise = true;
312 sendContextMenuClick(coords.x, coords.y);
313 yield waitForCondition(function () {
314 return ContextUI.tabbarVisible;
315 });
316 yield hideContextUI();
317 },
318 tearDown: setUpAndTearDown,
319 });
321 gTests.push({
322 desc: "Bug 960886 - selection monocles being spilled over to other tabs " +
323 "when switching.",
324 setUp: setUpAndTearDown,
325 run: function test() {
326 let initialTab = Browser.selectedTab;
328 // Create additional tab to which we will switch later
329 info(chromeRoot + "browser_selection_basic.html");
330 let lastTab = yield addTab(chromeRoot + "browser_selection_basic.html");
332 // Switch back to the initial tab
333 let tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect");
334 Browser.selectedTab = initialTab;
335 yield tabSelectPromise;
336 yield hideContextUI();
338 // Make selection
339 sendContextMenuClick(30, 20);
340 yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible);
342 // Switch to another tab
343 tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect");
344 Browser.selectedTab = lastTab;
345 yield tabSelectPromise;
347 yield waitForCondition(()=>!SelectionHelperUI.isSelectionUIVisible);
349 Browser.closeTab(Browser.selectedTab, { forceClose: true });
350 },
351 tearDown: setUpAndTearDown
352 });
354 function test() {
355 if (!isLandscapeMode()) {
356 todo(false, "browser_selection_tests need landscape mode to run.");
357 return;
358 }
359 runTests();
360 }