|
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 var gTextArea = null; |
|
11 |
|
12 const kCommonWaitMs = 5000; |
|
13 const kCommonPollMs = 100; |
|
14 |
|
15 /////////////////////////////////////////////////// |
|
16 // form input tests |
|
17 /////////////////////////////////////////////////// |
|
18 |
|
19 function setUpAndTearDown() { |
|
20 emptyClipboard(); |
|
21 if (gWindow) |
|
22 clearSelection(gWindow); |
|
23 if (gFrame) |
|
24 clearSelection(gFrame); |
|
25 if (gTextArea) |
|
26 clearSelection(gTextArea); |
|
27 yield waitForCondition(function () { |
|
28 return !SelectionHelperUI.isSelectionUIVisible; |
|
29 }, kCommonWaitMs, kCommonPollMs); |
|
30 InputSourceHelper.isPrecise = false; |
|
31 InputSourceHelper.fireUpdate(); |
|
32 } |
|
33 |
|
34 gTests.push({ |
|
35 desc: "normalize browser", |
|
36 setUp: setUpAndTearDown, |
|
37 tearDown: setUpAndTearDown, |
|
38 run: function test() { |
|
39 info(chromeRoot + "browser_selection_frame_textarea.html"); |
|
40 yield addTab(chromeRoot + "browser_selection_frame_textarea.html"); |
|
41 |
|
42 yield waitForCondition(function () { |
|
43 return !BrowserUI.isStartTabVisible; |
|
44 }, 10000, 100); |
|
45 |
|
46 yield hideContextUI(); |
|
47 |
|
48 gWindow = Browser.selectedTab.browser.contentWindow; |
|
49 gFrame = gWindow.document.getElementById("frame1"); |
|
50 gTextArea = gFrame.contentDocument.getElementById("textarea"); |
|
51 ok(gWindow != null, "gWindow"); |
|
52 ok(gFrame != null, "gFrame"); |
|
53 ok(gTextArea != null, "gTextArea"); |
|
54 }, |
|
55 }); |
|
56 |
|
57 gTests.push({ |
|
58 desc: "basic selection", |
|
59 setUp: setUpAndTearDown, |
|
60 tearDown: setUpAndTearDown, |
|
61 run: function test() { |
|
62 gTextArea.focus(); |
|
63 gTextArea.selectionStart = gTextArea.selectionEnd = 0; |
|
64 |
|
65 let promise = waitForEvent(document, "popupshown"); |
|
66 sendContextMenuClickToElement(gWindow, gFrame, 220, 80); |
|
67 yield promise; |
|
68 |
|
69 checkContextUIMenuItemVisibility(["context-select", |
|
70 "context-select-all"]); |
|
71 |
|
72 let menuItem = document.getElementById("context-select"); |
|
73 ok(menuItem, "menu item exists"); |
|
74 ok(!menuItem.hidden, "menu item visible"); |
|
75 let popupPromise = waitForEvent(document, "popuphidden"); |
|
76 sendElementTap(gWindow, menuItem); |
|
77 yield popupPromise; |
|
78 |
|
79 yield waitForCondition(function () { |
|
80 return SelectionHelperUI.isSelectionUIVisible; |
|
81 }, kCommonWaitMs, kCommonPollMs); |
|
82 |
|
83 is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test"); |
|
84 |
|
85 checkMonoclePositionRange("start", 260, 280, 675, 690); |
|
86 checkMonoclePositionRange("end", 320, 340, 675, 690); |
|
87 }, |
|
88 }); |
|
89 |
|
90 gTests.push({ |
|
91 desc: "drag selection 1", |
|
92 setUp: setUpAndTearDown, |
|
93 tearDown: setUpAndTearDown, |
|
94 run: function test() { |
|
95 gTextArea.focus(); |
|
96 gTextArea.selectionStart = gTextArea.selectionEnd = 0; |
|
97 |
|
98 let promise = waitForEvent(document, "popupshown"); |
|
99 sendContextMenuClickToElement(gWindow, gFrame, 220, 80); |
|
100 yield promise; |
|
101 |
|
102 checkContextUIMenuItemVisibility(["context-select", |
|
103 "context-select-all"]); |
|
104 |
|
105 let menuItem = document.getElementById("context-select"); |
|
106 ok(menuItem, "menu item exists"); |
|
107 ok(!menuItem.hidden, "menu item visible"); |
|
108 let popupPromise = waitForEvent(document, "popuphidden"); |
|
109 sendElementTap(gWindow, menuItem); |
|
110 yield popupPromise; |
|
111 |
|
112 yield waitForCondition(function () { |
|
113 return SelectionHelperUI.isSelectionUIVisible; |
|
114 }, kCommonWaitMs, kCommonPollMs); |
|
115 |
|
116 is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test"); |
|
117 |
|
118 // end marker to the right |
|
119 let xpos = SelectionHelperUI.endMark.xPos; |
|
120 let ypos = SelectionHelperUI.endMark.yPos + 10; |
|
121 var touchdrag = new TouchDragAndHold(); |
|
122 yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos); |
|
123 yield waitForCondition(function () { |
|
124 return getTrimmedSelection(gTextArea).toString() == |
|
125 "wondered at this,"; |
|
126 }, 6000, 2000); |
|
127 touchdrag.end(); |
|
128 |
|
129 yield waitForCondition(function () { |
|
130 return !SelectionHelperUI.hasActiveDrag; |
|
131 }, kCommonWaitMs, kCommonPollMs); |
|
132 yield SelectionHelperUI.pingSelectionHandler(); |
|
133 |
|
134 // start marker up and to the left |
|
135 let xpos = SelectionHelperUI.startMark.xPos; |
|
136 let ypos = SelectionHelperUI.startMark.yPos + 10; |
|
137 var touchdrag = new TouchDragAndHold(); |
|
138 yield touchdrag.start(gWindow, xpos, ypos, 40, 500); |
|
139 yield waitForCondition(function () { |
|
140 return getTrimmedSelection(gTextArea).toString().substring(0, 17) == |
|
141 "There was nothing"; |
|
142 }, 6000, 2000); |
|
143 touchdrag.end(); |
|
144 |
|
145 let promise = waitForEvent(document, "popupshown"); |
|
146 sendContextMenuClick(250, 640); |
|
147 yield promise; |
|
148 |
|
149 checkContextUIMenuItemVisibility(["context-cut", |
|
150 "context-copy"]); |
|
151 |
|
152 let menuItem = document.getElementById("context-copy"); |
|
153 ok(menuItem, "menu item exists"); |
|
154 ok(!menuItem.hidden, "menu item visible"); |
|
155 let popupPromise = waitForEvent(document, "popuphidden"); |
|
156 sendElementTap(gWindow, menuItem); |
|
157 yield popupPromise; |
|
158 |
|
159 let string = ""; |
|
160 yield waitForCondition(function () { |
|
161 string = SpecialPowers.getClipboardData("text/unicode"); |
|
162 return string.substring(0, 17) === "There was nothing"; |
|
163 }); |
|
164 }, |
|
165 }); |
|
166 |
|
167 gTests.push({ |
|
168 desc: "drag selection 2", |
|
169 setUp: setUpAndTearDown, |
|
170 tearDown: setUpAndTearDown, |
|
171 run: function test() { |
|
172 gTextArea.focus(); |
|
173 gTextArea.selectionStart = gTextArea.selectionEnd = 0; |
|
174 |
|
175 let scrollPromise = waitForEvent(gWindow, "scroll"); |
|
176 gWindow.scrollBy(0, 200); |
|
177 yield scrollPromise; |
|
178 |
|
179 let promise = waitForEvent(document, "popupshown"); |
|
180 sendContextMenuClickToElement(gWindow, gFrame, 220, 80); |
|
181 yield promise; |
|
182 |
|
183 checkContextUIMenuItemVisibility(["context-select", |
|
184 "context-select-all"]); |
|
185 |
|
186 let menuItem = document.getElementById("context-select"); |
|
187 ok(menuItem, "menu item exists"); |
|
188 ok(!menuItem.hidden, "menu item visible"); |
|
189 let popupPromise = waitForEvent(document, "popuphidden"); |
|
190 sendElementTap(gWindow, menuItem); |
|
191 yield popupPromise; |
|
192 |
|
193 yield waitForCondition(function () { |
|
194 return SelectionHelperUI.isSelectionUIVisible; |
|
195 }, kCommonWaitMs, kCommonPollMs); |
|
196 |
|
197 is(getTrimmedSelection(gTextArea).toString(), "wondered", "selection test"); |
|
198 |
|
199 // end marker to the right |
|
200 let xpos = SelectionHelperUI.endMark.xPos; |
|
201 let ypos = SelectionHelperUI.endMark.yPos + 10; |
|
202 var touchdrag = new TouchDragAndHold(); |
|
203 yield touchdrag.start(gWindow, xpos, ypos, xpos + 150, ypos); |
|
204 yield waitForCondition(function () { |
|
205 return getTrimmedSelection(gTextArea).toString() == |
|
206 "wondered at this,"; |
|
207 }, 6000, 2000); |
|
208 touchdrag.end(); |
|
209 |
|
210 yield waitForCondition(function () { |
|
211 return !SelectionHelperUI.hasActiveDrag; |
|
212 }, kCommonWaitMs, kCommonPollMs); |
|
213 yield SelectionHelperUI.pingSelectionHandler(); |
|
214 |
|
215 // start marker up and to the left |
|
216 let xpos = SelectionHelperUI.startMark.xPos; |
|
217 let ypos = SelectionHelperUI.startMark.yPos + 10; |
|
218 var touchdrag = new TouchDragAndHold(); |
|
219 yield touchdrag.start(gWindow, xpos, ypos, 40, 300); |
|
220 yield waitForCondition(function () { |
|
221 return getTrimmedSelection(gTextArea).toString().substring(0, 17) == |
|
222 "There was nothing"; |
|
223 }, 6000, 2000); |
|
224 touchdrag.end(); |
|
225 |
|
226 let promise = waitForEvent(document, "popupshown"); |
|
227 sendContextMenuClick(250, 440); |
|
228 yield promise; |
|
229 |
|
230 checkContextUIMenuItemVisibility(["context-cut", |
|
231 "context-copy"]); |
|
232 |
|
233 let menuItem = document.getElementById("context-copy"); |
|
234 ok(menuItem, "menu item exists"); |
|
235 ok(!menuItem.hidden, "menu item visible"); |
|
236 let popupPromise = waitForEvent(document, "popuphidden"); |
|
237 sendElementTap(gWindow, menuItem); |
|
238 yield popupPromise; |
|
239 |
|
240 let string = ""; |
|
241 yield waitForCondition(function () { |
|
242 string = SpecialPowers.getClipboardData("text/unicode"); |
|
243 return string.substring(0, 17) === "There was nothing"; |
|
244 }); |
|
245 }, |
|
246 }); |
|
247 |
|
248 function test() { |
|
249 if (!isLandscapeMode()) { |
|
250 todo(false, "browser_selection_tests need landscape mode to run."); |
|
251 return; |
|
252 } |
|
253 // XXX need this until bugs 886624 and 859742 are fully resolved |
|
254 setDevPixelEqualToPx(); |
|
255 runTests(); |
|
256 } |