|
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 kCommonWaitMs = 5000; |
|
12 const kCommonPollMs = 100; |
|
13 |
|
14 /////////////////////////////////////////////////// |
|
15 // text area tests |
|
16 /////////////////////////////////////////////////// |
|
17 |
|
18 gTests.push({ |
|
19 desc: "normalize browser", |
|
20 run: function test() { |
|
21 info(chromeRoot + "res/textblock01.html"); |
|
22 yield addTab(chromeRoot + "res/textblock01.html"); |
|
23 |
|
24 yield waitForCondition(function () { |
|
25 return !BrowserUI.isStartTabVisible; |
|
26 }); |
|
27 |
|
28 yield hideContextUI(); |
|
29 |
|
30 InputSourceHelper.isPrecise = false; |
|
31 InputSourceHelper.fireUpdate(); |
|
32 }, |
|
33 }); |
|
34 |
|
35 gTests.push({ |
|
36 desc: "nav bar display", |
|
37 run: function test() { |
|
38 gWindow = window; |
|
39 |
|
40 yield showNavBar(); |
|
41 |
|
42 let edit = document.getElementById("urlbar-edit"); |
|
43 |
|
44 sendElementTap(window, edit, 100, 10); |
|
45 |
|
46 ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active"); |
|
47 |
|
48 sendElementTap(window, edit, 70, 10); |
|
49 |
|
50 ok(SelectionHelperUI.isCaretUIVisible, "caret ui active"); |
|
51 |
|
52 // to the right |
|
53 let xpos = SelectionHelperUI.caretMark.xPos; |
|
54 let ypos = SelectionHelperUI.caretMark.yPos + 10; |
|
55 var touchdrag = new TouchDragAndHold(); |
|
56 yield touchdrag.start(gWindow, xpos, ypos, 900, ypos); |
|
57 yield waitForCondition(function () { |
|
58 return getTrimmedSelection(edit).toString() == |
|
59 "mochitests/content/metro/browser/metro/base/tests/mochitest/res/textblock01.html"; |
|
60 }, kCommonWaitMs, kCommonPollMs); |
|
61 touchdrag.end(); |
|
62 yield waitForMs(100); |
|
63 |
|
64 ok(SelectionHelperUI.isSelectionUIVisible, "selection ui active"); |
|
65 }, |
|
66 }); |
|
67 |
|
68 gTests.push({ |
|
69 desc: "bug 887120 - tap & hold to paste into urlbar", |
|
70 run: function() { |
|
71 gWindow = window; |
|
72 |
|
73 yield showNavBar(); |
|
74 let edit = document.getElementById("urlbar-edit"); |
|
75 |
|
76 SpecialPowers.clipboardCopyString("mozilla"); |
|
77 sendContextMenuClickToElement(window, edit); |
|
78 yield waitForEvent(document, "popupshown"); |
|
79 |
|
80 ok(ContextMenuUI._menuPopup.visible, "is visible"); |
|
81 let paste = document.getElementById("context-paste"); |
|
82 ok(!paste.hidden, "paste item is visible"); |
|
83 |
|
84 sendElementTap(window, paste); |
|
85 ok(edit.popup.popupOpen, "bug: popup should be showing"); |
|
86 |
|
87 clearSelection(edit); |
|
88 yield waitForCondition(function () { |
|
89 return !SelectionHelperUI.isSelectionUIVisible; |
|
90 }); |
|
91 } |
|
92 }); |
|
93 |
|
94 gTests.push({ |
|
95 desc: "bug 895284 - tap selection", |
|
96 run: function() { |
|
97 gWindow = window; |
|
98 |
|
99 yield showNavBar(); |
|
100 let edit = document.getElementById("urlbar-edit"); |
|
101 edit.value = "wikipedia.org"; |
|
102 edit.select(); |
|
103 |
|
104 let editCoords = logicalCoordsForElement(edit); |
|
105 |
|
106 // wait for popup animation to complete, it interferes with edit selection testing |
|
107 let autocompletePopup = document.getElementById("urlbar-autocomplete-scroll"); |
|
108 yield waitForEvent(autocompletePopup, "transitionend"); |
|
109 |
|
110 SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x, |
|
111 editCoords.y, edit); |
|
112 ok(SelectionHelperUI.isSelectionUIVisible, "selection enabled"); |
|
113 |
|
114 let selection = edit.QueryInterface(Components.interfaces.nsIDOMXULTextBoxElement) |
|
115 .editor.selection; |
|
116 let rects = selection.getRangeAt(0).getClientRects(); |
|
117 let midX = Math.ceil(((rects[0].right - rects[0].left) * .5) + rects[0].left); |
|
118 let midY = Math.ceil(((rects[0].bottom - rects[0].top) * .5) + rects[0].top); |
|
119 |
|
120 sendTap(window, midX, midY); |
|
121 |
|
122 ok(SelectionHelperUI.isCaretUIVisible, "caret browsing enabled"); |
|
123 |
|
124 clearSelection(edit); |
|
125 yield waitForCondition(function () { |
|
126 return !SelectionHelperUI.isSelectionUIVisible; |
|
127 }); |
|
128 } |
|
129 }); |
|
130 |
|
131 gTests.push({ |
|
132 desc: "bug 894713 - blur shuts down selection handling", |
|
133 run: function() { |
|
134 gWindow = window; |
|
135 yield showNavBar(); |
|
136 let edit = document.getElementById("urlbar-edit"); |
|
137 edit.value = "wikipedia.org"; |
|
138 edit.select(); |
|
139 let editCoords = logicalCoordsForElement(edit); |
|
140 SelectionHelperUI.attachEditSession(ChromeSelectionHandler, editCoords.x, |
|
141 editCoords.y, edit); |
|
142 edit.blur(); |
|
143 ok(!SelectionHelperUI.isSelectionUIVisible, "selection no longer enabled"); |
|
144 clearSelection(edit); |
|
145 yield waitForCondition(function () { |
|
146 return !SelectionHelperUI.isSelectionUIVisible; |
|
147 }); |
|
148 } |
|
149 }); |
|
150 |
|
151 function getClipboardCondition(aExpected) { |
|
152 return () => aExpected == SpecialPowers.getClipboardData("text/unicode"); |
|
153 } |
|
154 |
|
155 gTests.push({ |
|
156 desc: "bug 894715 - URLs selected by touch are copied with trimming", |
|
157 run: function () { |
|
158 gWindow = window; |
|
159 yield showNavBar(); |
|
160 |
|
161 let edit = document.getElementById("urlbar-edit"); |
|
162 edit.value = "http://www.wikipedia.org/"; |
|
163 |
|
164 sendElementTap(window, edit); |
|
165 edit.select(); |
|
166 |
|
167 let panel = ContextMenuUI._menuPopup._panel; |
|
168 let promise = waitForEvent(panel, "popupshown") |
|
169 sendContextMenuClickToElement(window, edit); |
|
170 ok((yield promise), "show context menu"); |
|
171 |
|
172 let copy = document.getElementById("context-copy"); |
|
173 ok(!copy.hidden, "copy menu item is visible") |
|
174 |
|
175 let condition = getClipboardCondition("http://www.wikipedia.org/"); |
|
176 let promise = waitForCondition(condition); |
|
177 sendElementTap(window, copy); |
|
178 ok((yield promise), "copy text onto clipboard") |
|
179 |
|
180 clearSelection(edit); |
|
181 edit.blur(); |
|
182 } |
|
183 }) |
|
184 |
|
185 gTests.push({ |
|
186 desc: "bug 965832 - selection monocles move with the nav bar", |
|
187 run: function() { |
|
188 yield showNavBar(); |
|
189 |
|
190 let originalUtils = Services.metro; |
|
191 Services.metro = { |
|
192 keyboardHeight: 0, |
|
193 keyboardVisible: false |
|
194 }; |
|
195 registerCleanupFunction(function() { |
|
196 Services.metro = originalUtils; |
|
197 }); |
|
198 |
|
199 let edit = document.getElementById("urlbar-edit"); |
|
200 edit.value = "http://www.wikipedia.org/"; |
|
201 |
|
202 sendElementTap(window, edit); |
|
203 |
|
204 let promise = waitForEvent(window, "MozDeckOffsetChanged"); |
|
205 Services.metro.keyboardHeight = 300; |
|
206 Services.metro.keyboardVisible = true; |
|
207 Services.obs.notifyObservers(null, "metro_softkeyboard_shown", null); |
|
208 yield promise; |
|
209 |
|
210 yield waitForCondition(function () { |
|
211 return SelectionHelperUI.isSelectionUIVisible; |
|
212 }); |
|
213 |
|
214 promise = waitForEvent(window, "MozDeckOffsetChanged"); |
|
215 Services.metro.keyboardHeight = 0; |
|
216 Services.metro.keyboardVisible = false; |
|
217 Services.obs.notifyObservers(null, "metro_softkeyboard_hidden", null); |
|
218 yield promise; |
|
219 |
|
220 yield waitForCondition(function () { |
|
221 return SelectionHelperUI.isSelectionUIVisible; |
|
222 }); |
|
223 |
|
224 clearSelection(edit); |
|
225 edit.blur(); |
|
226 |
|
227 yield waitForCondition(function () { |
|
228 return !SelectionHelperUI.isSelectionUIVisible; |
|
229 }); |
|
230 } |
|
231 }); |
|
232 |
|
233 gTests.push({ |
|
234 desc: "Bug 957646 - Selection monocles sometimes don't display when tapping" + |
|
235 " text in the nav bar.", |
|
236 run: function() { |
|
237 yield showNavBar(); |
|
238 |
|
239 let edit = document.getElementById("urlbar-edit"); |
|
240 edit.value = "about:mozilla"; |
|
241 |
|
242 let editRectangle = edit.getBoundingClientRect(); |
|
243 |
|
244 // Tap outside the input but close enough for fluffing to take effect. |
|
245 sendTap(window, editRectangle.left + 50, editRectangle.top - 2); |
|
246 |
|
247 yield waitForCondition(function () { |
|
248 return SelectionHelperUI.isSelectionUIVisible; |
|
249 }); |
|
250 } |
|
251 }); |
|
252 |
|
253 gTests.push({ |
|
254 desc: "Bug 972574 - Monocles not matching selection after double tap" + |
|
255 " in URL text field.", |
|
256 run: function() { |
|
257 yield showNavBar(); |
|
258 |
|
259 let MARGIN_OF_ERROR = 15; |
|
260 let EST_URLTEXT_WIDTH = 125; |
|
261 |
|
262 let edit = document.getElementById("urlbar-edit"); |
|
263 edit.value = "http://www.wikipedia.org/"; |
|
264 |
|
265 // Determine a tap point centered on URL. |
|
266 let editRectangle = edit.getBoundingClientRect(); |
|
267 let midX = editRectangle.left + Math.ceil(EST_URLTEXT_WIDTH / 2); |
|
268 let midY = editRectangle.top + Math.ceil(editRectangle.height / 2); |
|
269 |
|
270 // Tap inside the input for fluffing to take effect. |
|
271 sendTap(window, midX, midY); |
|
272 |
|
273 // Double-tap inside the input to selectALL. |
|
274 sendDoubleTap(window, midX, midY); |
|
275 |
|
276 // Check for start/end monocles positioned within accepted margins. |
|
277 checkMonoclePositionRange("start", |
|
278 Math.ceil(editRectangle.left - MARGIN_OF_ERROR), |
|
279 Math.ceil(editRectangle.left + MARGIN_OF_ERROR), |
|
280 Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR), |
|
281 Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR)); |
|
282 checkMonoclePositionRange("end", |
|
283 Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH - MARGIN_OF_ERROR), |
|
284 Math.ceil(editRectangle.left + EST_URLTEXT_WIDTH + MARGIN_OF_ERROR), |
|
285 Math.ceil(editRectangle.top + editRectangle.height - MARGIN_OF_ERROR), |
|
286 Math.ceil(editRectangle.top + editRectangle.height + MARGIN_OF_ERROR)); |
|
287 } |
|
288 }); |
|
289 |
|
290 gTests.push({ |
|
291 desc: "Bug 972428 - grippers not appearing under the URL field when adding " + |
|
292 "text.", |
|
293 run: function() { |
|
294 let inputField = document.getElementById("urlbar-edit").inputField; |
|
295 let inputFieldRectangle = inputField.getBoundingClientRect(); |
|
296 |
|
297 let chromeHandlerSpy = spyOnMethod(ChromeSelectionHandler, "msgHandler"); |
|
298 |
|
299 // Reset URL to empty string |
|
300 inputField.value = ""; |
|
301 inputField.blur(); |
|
302 |
|
303 // Activate URL input |
|
304 sendTap(window, inputFieldRectangle.left + 50, inputFieldRectangle.top + 5); |
|
305 |
|
306 // Wait until ChromeSelectionHandler tries to attach selection |
|
307 yield waitForCondition(() => chromeHandlerSpy.argsForCall.some( |
|
308 (args) => args[0] == "Browser:SelectionAttach")); |
|
309 |
|
310 ok(!SelectHelperUI.isSelectionUIVisible && !SelectHelperUI.isCaretUIVisible, |
|
311 "Neither CaretUI nor SelectionUI is visible on empty input."); |
|
312 |
|
313 inputField.value = "Test text"; |
|
314 |
|
315 sendTap(window, inputFieldRectangle.left + 10, inputFieldRectangle.top + 5); |
|
316 |
|
317 yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible); |
|
318 chromeHandlerSpy.restore(); |
|
319 inputField.blur(); |
|
320 } |
|
321 }); |
|
322 |
|
323 gTests.push({ |
|
324 desc: "Bug 858206 - Drag selection monocles should not push other monocles " + |
|
325 "out of the way.", |
|
326 run: function test() { |
|
327 yield showNavBar(); |
|
328 |
|
329 let edit = document.getElementById("urlbar-edit"); |
|
330 edit.value = "about:mozilla"; |
|
331 |
|
332 let editRectangle = edit.getBoundingClientRect(); |
|
333 |
|
334 sendTap(window, editRectangle.left, editRectangle.top); |
|
335 |
|
336 yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible); |
|
337 |
|
338 let selection = edit.QueryInterface( |
|
339 Components.interfaces.nsIDOMXULTextBoxElement).editor.selection; |
|
340 let selectionRectangle = selection.getRangeAt(0).getClientRects()[0]; |
|
341 |
|
342 // Place caret to the input start |
|
343 sendTap(window, selectionRectangle.left + 2, selectionRectangle.top + 2); |
|
344 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible && |
|
345 SelectionHelperUI.isCaretUIVisible); |
|
346 |
|
347 let startXPos = SelectionHelperUI.caretMark.xPos; |
|
348 let startYPos = SelectionHelperUI.caretMark.yPos + 10; |
|
349 let touchDrag = new TouchDragAndHold(); |
|
350 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200, |
|
351 startYPos); |
|
352 yield waitForCondition(() => getTrimmedSelection(edit).toString() == |
|
353 "about:mozilla", kCommonWaitMs, kCommonPollMs); |
|
354 |
|
355 touchDrag.end(); |
|
356 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, |
|
357 kCommonWaitMs, kCommonPollMs); |
|
358 |
|
359 // Place caret to the input end |
|
360 sendTap(window, selectionRectangle.right - 2, selectionRectangle.top + 2); |
|
361 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible && |
|
362 SelectionHelperUI.isCaretUIVisible); |
|
363 |
|
364 startXPos = SelectionHelperUI.caretMark.xPos; |
|
365 startYPos = SelectionHelperUI.caretMark.yPos + 10; |
|
366 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200, |
|
367 startYPos); |
|
368 yield waitForCondition(() => getTrimmedSelection(edit).toString() == |
|
369 "about:mozilla", kCommonWaitMs, kCommonPollMs); |
|
370 |
|
371 touchDrag.end(); |
|
372 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, |
|
373 kCommonWaitMs, kCommonPollMs); |
|
374 |
|
375 // Place caret in the middle |
|
376 let midX = Math.ceil(((selectionRectangle.right - selectionRectangle.left) * |
|
377 .5) + selectionRectangle.left); |
|
378 let midY = Math.ceil(((selectionRectangle.bottom - selectionRectangle.top) * |
|
379 .5) + selectionRectangle.top); |
|
380 |
|
381 sendTap(window, midX, midY); |
|
382 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible && |
|
383 SelectionHelperUI.isCaretUIVisible); |
|
384 |
|
385 startXPos = SelectionHelperUI.caretMark.xPos; |
|
386 startYPos = SelectionHelperUI.caretMark.yPos + 10; |
|
387 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 200, |
|
388 startYPos); |
|
389 yield waitForCondition(() => getTrimmedSelection(edit).toString() == |
|
390 "about:", kCommonWaitMs, kCommonPollMs); |
|
391 |
|
392 touchDrag.end(); |
|
393 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, |
|
394 kCommonWaitMs, kCommonPollMs); |
|
395 |
|
396 // Now try to swap monocles |
|
397 startXPos = SelectionHelperUI.startMark.xPos; |
|
398 startYPos = SelectionHelperUI.startMark.yPos + 10; |
|
399 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 200, |
|
400 startYPos); |
|
401 yield waitForCondition(() => getTrimmedSelection(edit).toString() == |
|
402 "mozilla", kCommonWaitMs, kCommonPollMs); |
|
403 touchDrag.end(); |
|
404 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag && |
|
405 SelectionHelperUI.isSelectionUIVisible, kCommonWaitMs, kCommonPollMs); |
|
406 } |
|
407 }); |
|
408 |
|
409 function test() { |
|
410 if (!isLandscapeMode()) { |
|
411 todo(false, "browser_selection_tests need landscape mode to run."); |
|
412 return; |
|
413 } |
|
414 runTests(); |
|
415 } |