|
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 gInput = null; |
|
10 |
|
11 const kCommonWaitMs = 7000; |
|
12 const kCommonPollMs = 200; |
|
13 |
|
14 /////////////////////////////////////////////////// |
|
15 // form input tests |
|
16 /////////////////////////////////////////////////// |
|
17 |
|
18 function setUpAndTearDown() { |
|
19 emptyClipboard(); |
|
20 if (gWindow) |
|
21 clearSelection(gWindow); |
|
22 if (gInput) |
|
23 clearSelection(gInput); |
|
24 yield waitForCondition(function () { |
|
25 return !SelectionHelperUI.isSelectionUIVisible; |
|
26 }, kCommonWaitMs, kCommonPollMs); |
|
27 InputSourceHelper.isPrecise = false; |
|
28 InputSourceHelper.fireUpdate(); |
|
29 } |
|
30 |
|
31 /* |
|
32 5px top margin |
|
33 25px tall text input |
|
34 300px wide |
|
35 */ |
|
36 |
|
37 gTests.push({ |
|
38 desc: "normalize browser", |
|
39 setUp: setUpAndTearDown, |
|
40 tearDown: setUpAndTearDown, |
|
41 run: function test() { |
|
42 info(chromeRoot + "browser_selection_inputs.html"); |
|
43 yield addTab(chromeRoot + "browser_selection_inputs.html"); |
|
44 |
|
45 yield waitForCondition(function () { |
|
46 return !BrowserUI.isStartTabVisible; |
|
47 }); |
|
48 |
|
49 yield hideContextUI(); |
|
50 |
|
51 gWindow = Browser.selectedTab.browser.contentWindow; |
|
52 gInput = gWindow.document.getElementById("a"); |
|
53 }, |
|
54 }); |
|
55 |
|
56 gTests.push({ |
|
57 desc: "basic text input selection", |
|
58 setUp: setUpAndTearDown, |
|
59 tearDown: setUpAndTearDown, |
|
60 run: function test() { |
|
61 gInput.blur(); |
|
62 gInput.selectionStart = gInput.selectionEnd = 0; |
|
63 |
|
64 let promise = waitForEvent(document, "popupshown"); |
|
65 sendContextMenuClick(200, 17); |
|
66 yield promise; |
|
67 |
|
68 checkContextUIMenuItemVisibility(["context-select", |
|
69 "context-select-all"]); |
|
70 |
|
71 let menuItem = document.getElementById("context-select"); |
|
72 ok(menuItem, "menu item exists"); |
|
73 ok(!menuItem.hidden, "menu item visible"); |
|
74 let popupPromise = waitForEvent(document, "popuphidden"); |
|
75 sendElementTap(gWindow, menuItem); |
|
76 yield popupPromise; |
|
77 |
|
78 yield waitForCondition(function () { |
|
79 return SelectionHelperUI.isSelectionUIVisible; |
|
80 }, kCommonWaitMs, kCommonPollMs); |
|
81 |
|
82 is(getTrimmedSelection(gInput).toString(), "went", "selection test"); |
|
83 is(gWindow.document.activeElement, gInput, "input focused"); |
|
84 }, |
|
85 }); |
|
86 |
|
87 gTests.push({ |
|
88 desc: "drag left to scroll", |
|
89 setUp: setUpAndTearDown, |
|
90 tearDown: setUpAndTearDown, |
|
91 run: function test() { |
|
92 gInput.selectionStart = gInput.selectionEnd = gInput.value.length; |
|
93 yield waitForEvent(window, "scroll"); |
|
94 |
|
95 let promise = waitForEvent(document, "popupshown"); |
|
96 sendContextMenuClick(190, 17); |
|
97 yield promise; |
|
98 |
|
99 checkContextUIMenuItemVisibility(["context-select", |
|
100 "context-select-all"]); |
|
101 |
|
102 let menuItem = document.getElementById("context-select"); |
|
103 ok(menuItem, "menu item exists"); |
|
104 ok(!menuItem.hidden, "menu item visible"); |
|
105 let popupPromise = waitForEvent(document, "popuphidden"); |
|
106 sendElementTap(gWindow, menuItem); |
|
107 yield popupPromise; |
|
108 |
|
109 yield waitForCondition(function () { |
|
110 return SelectionHelperUI.isSelectionUIVisible; |
|
111 }, kCommonWaitMs, kCommonPollMs); |
|
112 |
|
113 // check text selection |
|
114 is(getTrimmedSelection(gInput).toString(), "way", "selection test"); |
|
115 |
|
116 // to the left |
|
117 let xpos = SelectionHelperUI.startMark.xPos; |
|
118 let ypos = SelectionHelperUI.startMark.yPos + 10; |
|
119 var touchdrag = new TouchDragAndHold(); |
|
120 yield touchdrag.start(gWindow, xpos, ypos, 10, ypos); |
|
121 yield waitForCondition(function () { |
|
122 return getTrimmedSelection(gInput).toString() == |
|
123 "The rabbit-hole went straight on like a tunnel for some way"; |
|
124 }, kCommonWaitMs, kCommonPollMs); |
|
125 touchdrag.end(); |
|
126 |
|
127 yield waitForCondition(function () { |
|
128 return !SelectionHelperUI.hasActiveDrag; |
|
129 }, kCommonWaitMs, kCommonPollMs); |
|
130 yield SelectionHelperUI.pingSelectionHandler(); |
|
131 }, |
|
132 }); |
|
133 |
|
134 gTests.push({ |
|
135 desc: "drag right to scroll and bug 862025", |
|
136 setUp: setUpAndTearDown, |
|
137 tearDown: setUpAndTearDown, |
|
138 run: function test() { |
|
139 gInput.selectionStart = gInput.selectionEnd = 0; |
|
140 yield waitForEvent(window, "scroll"); |
|
141 |
|
142 let promise = waitForEvent(document, "popupshown"); |
|
143 sendContextMenuClick(230, 17); |
|
144 yield promise; |
|
145 |
|
146 checkContextUIMenuItemVisibility(["context-select", |
|
147 "context-select-all"]); |
|
148 |
|
149 let menuItem = document.getElementById("context-select"); |
|
150 ok(menuItem, "menu item exists"); |
|
151 ok(!menuItem.hidden, "menu item visible"); |
|
152 let popupPromise = waitForEvent(document, "popuphidden"); |
|
153 sendElementTap(gWindow, menuItem); |
|
154 yield popupPromise; |
|
155 |
|
156 yield waitForCondition(function () { |
|
157 return SelectionHelperUI.isSelectionUIVisible; |
|
158 }, kCommonWaitMs, kCommonPollMs); |
|
159 |
|
160 // check text selection |
|
161 is(getTrimmedSelection(gInput).toString(), "straight", "selection test"); |
|
162 |
|
163 // to the right with scroll |
|
164 let xpos = SelectionHelperUI.endMark.xPos; |
|
165 let ystartpos = SelectionHelperUI.endMark.yPos + 10; |
|
166 var touchdrag = new TouchDragAndHold(); |
|
167 yield touchdrag.start(gWindow, xpos, ystartpos, 510, ystartpos); |
|
168 // hold the monocle in position outside the edit to trigger drag |
|
169 yield waitForCondition(function () { |
|
170 return getTrimmedSelection(gInput).toString() == |
|
171 "straight on like a tunnel for some way and then dipped suddenly down"; |
|
172 }, kCommonWaitMs, kCommonPollMs); |
|
173 touchdrag.end(); |
|
174 |
|
175 yield waitForCondition(function () { |
|
176 return !SelectionHelperUI.hasActiveDrag; |
|
177 }, kCommonWaitMs, kCommonPollMs); |
|
178 yield SelectionHelperUI.pingSelectionHandler(); |
|
179 |
|
180 // straight down - selection shouldn't change |
|
181 let xpos = SelectionHelperUI.endMark.xPos; |
|
182 let ypos = SelectionHelperUI.endMark.yPos + 10; |
|
183 yield touchdrag.start(gWindow, xpos, ypos, xpos, ypos + 150); |
|
184 // no touchend here, we want to continue the drag below |
|
185 |
|
186 yield SelectionHelperUI.pingSelectionHandler(); |
|
187 is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for some way and then dipped suddenly down", "selection test"); |
|
188 |
|
189 // left and up with no scrolling - selection should shrink |
|
190 yield touchdrag.move(135, ystartpos); |
|
191 touchdrag.end(); |
|
192 |
|
193 yield SelectionHelperUI.pingSelectionHandler(); |
|
194 is(getTrimmedSelection(gInput).toString(), "straight on like a tunnel for", "selection test"); |
|
195 }, |
|
196 }); |
|
197 |
|
198 gTests.push({ |
|
199 desc: "Bug 858206 - Drag selection monocles should not push other monocles " + |
|
200 "out of the way.", |
|
201 setUp: setUpAndTearDown, |
|
202 tearDown: setUpAndTearDown, |
|
203 run: function test() { |
|
204 let inputOriginalValue = gInput.value; |
|
205 |
|
206 gInput.value = "The rabbit-hole went straight on"; |
|
207 |
|
208 let promise = waitForEvent(document, "popupshown"); |
|
209 sendContextMenuClickToElement(gWindow, gInput, 150); |
|
210 yield promise; |
|
211 |
|
212 // Make initial selection |
|
213 promise = waitForEvent(document, "popuphidden"); |
|
214 sendElementTap(gWindow, document.getElementById("context-select")); |
|
215 yield promise; |
|
216 |
|
217 yield waitForCondition(() => SelectionHelperUI.isSelectionUIVisible, |
|
218 kCommonWaitMs, kCommonPollMs); |
|
219 is(getTrimmedSelection(gInput).toString(), "straight"); |
|
220 |
|
221 // Swap monocles when dragging with end monocle |
|
222 let startXPos = SelectionHelperUI.endMark.xPos; |
|
223 let startYPos = SelectionHelperUI.endMark.yPos + 10; |
|
224 let touchDrag = new TouchDragAndHold(); |
|
225 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300, |
|
226 startYPos); |
|
227 |
|
228 yield waitForCondition(() => getTrimmedSelection(gInput).toString() == |
|
229 "The rabbit-hole went", kCommonWaitMs, kCommonPollMs); |
|
230 touchDrag.end(); |
|
231 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, |
|
232 kCommonWaitMs, kCommonPollMs); |
|
233 yield SelectionHelperUI.pingSelectionHandler(); |
|
234 |
|
235 // Swap monocles when dragging with start monocle |
|
236 startXPos = SelectionHelperUI.startMark.xPos; |
|
237 startYPos = SelectionHelperUI.startMark.yPos + 10; |
|
238 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300, |
|
239 startYPos); |
|
240 yield waitForCondition(() => getTrimmedSelection(gInput).toString() == |
|
241 "straight on", kCommonWaitMs, kCommonPollMs); |
|
242 touchDrag.end(); |
|
243 yield waitForCondition(() => !SelectionHelperUI.hasActiveDrag, |
|
244 kCommonWaitMs, kCommonPollMs); |
|
245 yield SelectionHelperUI.pingSelectionHandler(); |
|
246 |
|
247 // Swap monocles right after caret-to-selection mode switch from start |
|
248 gInput.selectionStart = gInput.selectionEnd = 0; |
|
249 sendElementTap(gWindow, gInput, 0, 0); |
|
250 |
|
251 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible && |
|
252 SelectionHelperUI.isCaretUIVisible); |
|
253 |
|
254 startXPos = SelectionHelperUI.caretMark.xPos; |
|
255 startYPos = SelectionHelperUI.caretMark.yPos + 10; |
|
256 |
|
257 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos + 300, |
|
258 startYPos); |
|
259 yield waitForCondition(() => getTrimmedSelection(gInput).toString() == |
|
260 "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs); |
|
261 touchDrag.end(); |
|
262 |
|
263 sendTap(gWindow, 10, 10); |
|
264 yield waitForCondition(() => !SelectionHelperUI.isSelectionUIVisible); |
|
265 |
|
266 // Swap monocles right after caret-to-selection mode switch from end |
|
267 gInput.selectionStart = gInput.selectionEnd = gInput.value.length; |
|
268 let inputSelectionRectangle = gInput.QueryInterface(Ci.nsIDOMNSEditableElement). |
|
269 editor.selection.getRangeAt(0).getClientRects()[0]; |
|
270 sendTap(gWindow, inputSelectionRectangle.right, |
|
271 inputSelectionRectangle.top); |
|
272 |
|
273 yield waitForCondition(() => SelectionHelperUI.isCaretUIVisible); |
|
274 |
|
275 startXPos = SelectionHelperUI.caretMark.xPos; |
|
276 startYPos = SelectionHelperUI.caretMark.yPos + 10; |
|
277 |
|
278 yield touchDrag.start(gWindow, startXPos, startYPos, startXPos - 300, |
|
279 startYPos); |
|
280 yield waitForCondition(() => getTrimmedSelection(gInput).toString() == |
|
281 "The rabbit-hole went straight on", kCommonWaitMs, kCommonPollMs); |
|
282 touchDrag.end(); |
|
283 |
|
284 gInput.value = inputOriginalValue; |
|
285 } |
|
286 }); |
|
287 |
|
288 function test() { |
|
289 if (!isLandscapeMode()) { |
|
290 todo(false, "browser_selection_tests need landscape mode to run."); |
|
291 return; |
|
292 } |
|
293 // XXX need this until bugs 886624 and 859742 are fully resolved |
|
294 setDevPixelEqualToPx(); |
|
295 runTests(); |
|
296 } |