browser/metro/base/tests/mochitest/browser_selection_basic.js

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:ad0cc01ac9bc
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/ */
5
6 "use strict";
7
8 let gWindow = null;
9 var gFrame = null;
10
11 const kMarkerOffsetY = 6;
12 const kCommonWaitMs = 5000;
13 const kCommonPollMs = 100;
14
15 ///////////////////////////////////////////////////
16 // content (non-editable) tests
17 ///////////////////////////////////////////////////
18
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 }
31
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");
39
40 yield waitForCondition(function () {
41 return !BrowserUI.isStartTabVisible;
42 }, 10000, 100);
43
44 yield hideContextUI();
45
46 gWindow = Browser.selectedTab.browser.contentWindow;
47 },
48 });
49
50 gTests.push({
51 desc: "tap-hold to select",
52 setUp: setUpAndTearDown,
53 tearDown: setUpAndTearDown,
54 run: function test() {
55 sendContextMenuClick(30, 20);
56
57 yield waitForCondition(function () {
58 return SelectionHelperUI.isSelectionUIVisible;
59 }, kCommonWaitMs, kCommonPollMs);
60
61 is(getTrimmedSelection(gWindow).toString(), "There", "selection test");
62 },
63 });
64
65 gTests.push({
66 desc: "appbar interactions",
67 setUp: setUpAndTearDown,
68 tearDown: setUpAndTearDown,
69 run: function test() {
70 sendContextMenuClick(100, 20);
71
72 yield waitForCondition(function () {
73 return SelectionHelperUI.isSelectionUIVisible;
74 }, kCommonWaitMs, kCommonPollMs);
75
76 is(SelectionHelperUI.isActive, true, "selection active");
77 is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test");
78
79 yield fireAppBarDisplayEvent();
80
81 ok(ContextUI.isVisible, true, "appbar visible");
82
83 yield hideContextUI();
84
85 ok(!ContextUI.isVisible, true, "appbar hidden");
86 },
87 });
88
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);
96
97 yield waitForCondition(function () {
98 return SelectionHelperUI.isSelectionUIVisible;
99 }, kCommonWaitMs, kCommonPollMs);
100
101 is(SelectionHelperUI.isActive, true, "selection active");
102 is(getTrimmedSelection(gWindow).toString(), "nothing", "selection test");
103
104 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
105
106 let touchdrag = new TouchDragAndHold();
107 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 190, ypos);
108 touchdrag.end();
109
110 yield waitForCondition(function () {
111 return !SelectionHelperUI.hasActiveDrag;
112 }, kCommonWaitMs, kCommonPollMs);
113 yield SelectionHelperUI.pingSelectionHandler();
114
115 is(SelectionHelperUI.isActive, true, "selection active");
116 is(getTrimmedSelection(gWindow).toString(), "nothing so VERY", "selection test");
117 },
118 });
119
120 gTests.push({
121 desc: "expand / collapse selection",
122 setUp: setUpAndTearDown,
123 tearDown: setUpAndTearDown,
124 run: function test() {
125 sendContextMenuClick(30, 20);
126
127 yield waitForCondition(function () {
128 return SelectionHelperUI.isSelectionUIVisible;
129 }, kCommonWaitMs, kCommonPollMs);
130
131 is(SelectionHelperUI.isActive, true, "initial active");
132 is(getTrimmedSelection(gWindow).toString(), "There", "initial selection test");
133
134 for (let count = 0; count < 5; count++) {
135 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
136
137 let touchdrag = new TouchDragAndHold();
138 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
139 touchdrag.end();
140
141 yield waitForCondition(function () {
142 return !SelectionHelperUI.hasActiveDrag;
143 }, kCommonWaitMs, kCommonPollMs);
144 yield SelectionHelperUI.pingSelectionHandler();
145
146 is(getTrimmedSelection(gWindow).toString(),
147 "There was nothing so VERY remarkable in that; nor did Alice think it so",
148 "long selection test");
149
150 is(SelectionHelperUI.isActive, true, "selection active");
151
152 touchdrag = new TouchDragAndHold();
153 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 40, ypos);
154 touchdrag.end();
155
156 yield waitForCondition(function () {
157 return !SelectionHelperUI.hasActiveDrag;
158 }, kCommonWaitMs, kCommonPollMs);
159 yield SelectionHelperUI.pingSelectionHandler();
160
161 is(SelectionHelperUI.isActive, true, "selection active");
162 is(getTrimmedSelection(gWindow).toString(), "There was", "short selection test");
163 }
164 },
165 });
166
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");
175
176 sendContextMenuClick(106, 20);
177
178 yield waitForCondition(function () {
179 return SelectionHelperUI.isSelectionUIVisible;
180 }, kCommonWaitMs, kCommonPollMs);
181
182 is(SelectionHelperUI.isActive, true, "selection active");
183 is(getTrimmedSelection(gWindow).toString(), "moment", "selection test");
184
185 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY;
186
187 let touchdrag = new TouchDragAndHold();
188 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
189 touchdrag.end();
190
191 yield waitForCondition(function () {
192 return !SelectionHelperUI.hasActiveDrag;
193 }, kCommonWaitMs, kCommonPollMs);
194 yield SelectionHelperUI.pingSelectionHandler();
195
196 is(getTrimmedSelection(gWindow).toString(),
197 "moment down went Alice after it, never once considering how in",
198 "selection test");
199
200 is(SelectionHelperUI.isActive, true, "selection active");
201
202 touchdrag = new TouchDragAndHold();
203 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 150, ypos);
204 touchdrag.end();
205
206 yield waitForCondition(function () {
207 return !SelectionHelperUI.hasActiveDrag;
208 }, kCommonWaitMs, kCommonPollMs);
209 yield SelectionHelperUI.pingSelectionHandler();
210
211 is(getTrimmedSelection(gWindow).toString(), "moment down went", "selection test");
212
213 touchdrag = new TouchDragAndHold();
214 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 550, ypos);
215 touchdrag.end();
216
217 yield waitForCondition(function () {
218 return !SelectionHelperUI.hasActiveDrag;
219 }, kCommonWaitMs, kCommonPollMs);
220 yield SelectionHelperUI.pingSelectionHandler();
221
222 is(getTrimmedSelection(gWindow).toString(),
223 "moment down went Alice after it, never once considering how in",
224 "selection test");
225
226 touchdrag = new TouchDragAndHold();
227 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 160, ypos);
228 touchdrag.end();
229
230 yield waitForCondition(function () {
231 return !SelectionHelperUI.hasActiveDrag;
232 }, kCommonWaitMs, kCommonPollMs);
233 yield SelectionHelperUI.pingSelectionHandler();
234
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 });
254
255 gTests.push({
256 desc: "tap on selection clears selection in content",
257 setUp: setUpAndTearDown,
258 run: function test() {
259
260 sendContextMenuClick(30, 20);
261
262 yield waitForCondition(function () {
263 return SelectionHelperUI.isSelectionUIVisible;
264 }, kCommonWaitMs, kCommonPollMs);
265
266 sendTap(gWindow, 30, 20);
267
268 yield waitForCondition(function () {
269 return !SelectionHelperUI.isSelectionUIVisible;
270 }, kCommonWaitMs, kCommonPollMs);
271 },
272 tearDown: setUpAndTearDown,
273 });
274
275 gTests.push({
276 desc: "tap off selection clears selection in content",
277 setUp: setUpAndTearDown,
278 run: function test() {
279
280 sendContextMenuClick(30, 20);
281
282 yield waitForCondition(function () {
283 return SelectionHelperUI.isSelectionUIVisible;
284 }, kCommonWaitMs, kCommonPollMs);
285
286 sendTap(gWindow, 30, 100);
287
288 yield waitForCondition(function () {
289 return !SelectionHelperUI.isSelectionUIVisible;
290 }, kCommonWaitMs, kCommonPollMs);
291 },
292 tearDown: setUpAndTearDown,
293 });
294
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 });
320
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;
327
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");
331
332 // Switch back to the initial tab
333 let tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect");
334 Browser.selectedTab = initialTab;
335 yield tabSelectPromise;
336 yield hideContextUI();
337
338 // Make selection
339 sendContextMenuClick(30, 20);
340 yield waitForCondition(()=>SelectionHelperUI.isSelectionUIVisible);
341
342 // Switch to another tab
343 tabSelectPromise = waitForEvent(Elements.tabList, "TabSelect");
344 Browser.selectedTab = lastTab;
345 yield tabSelectPromise;
346
347 yield waitForCondition(()=>!SelectionHelperUI.isSelectionUIVisible);
348
349 Browser.closeTab(Browser.selectedTab, { forceClose: true });
350 },
351 tearDown: setUpAndTearDown
352 });
353
354 function test() {
355 if (!isLandscapeMode()) {
356 todo(false, "browser_selection_tests need landscape mode to run.");
357 return;
358 }
359 runTests();
360 }

mercurial