|
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 // sub frame content 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_frame_content.html"); |
|
38 yield addTab(chromeRoot + "browser_selection_frame_content.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 gFrame = gWindow.document.getElementById("frame1"); |
|
48 }, |
|
49 }); |
|
50 |
|
51 gTests.push({ |
|
52 desc: "iframe basic selection", |
|
53 setUp: setUpAndTearDown, |
|
54 tearDown: setUpAndTearDown, |
|
55 run: function test() { |
|
56 gFrame.focus(); |
|
57 |
|
58 sendContextMenuClick(165, 35); |
|
59 |
|
60 yield waitForCondition(function () { |
|
61 return SelectionHelperUI.isSelectionUIVisible; |
|
62 }, kCommonWaitMs, kCommonPollMs); |
|
63 |
|
64 // active state |
|
65 is(SelectionHelperUI.isActive, true, "selection active"); |
|
66 // check text selection |
|
67 is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test"); |
|
68 }, |
|
69 }); |
|
70 |
|
71 gTests.push({ |
|
72 desc: "iframe expand / collapse selection", |
|
73 setUp: setUpAndTearDown, |
|
74 tearDown: setUpAndTearDown, |
|
75 run: function test() { |
|
76 gFrame.focus(); |
|
77 |
|
78 sendContextMenuClick(162, 180); |
|
79 |
|
80 yield waitForCondition(function () { |
|
81 return SelectionHelperUI.isSelectionUIVisible; |
|
82 }, kCommonWaitMs, kCommonPollMs); |
|
83 |
|
84 // active state |
|
85 is(SelectionHelperUI.isActive, true, "selection active"); |
|
86 is(getTrimmedSelection(gFrame).toString(), "Alice", "selection test"); |
|
87 |
|
88 let ypos = SelectionHelperUI.endMark.yPos + kMarkerOffsetY; |
|
89 |
|
90 let touchdrag = new TouchDragAndHold(); |
|
91 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 640, ypos); |
|
92 touchdrag.end(); |
|
93 |
|
94 yield waitForCondition(function () { |
|
95 return !SelectionHelperUI.hasActiveDrag; |
|
96 }, kCommonWaitMs, kCommonPollMs); |
|
97 yield SelectionHelperUI.pingSelectionHandler(); |
|
98 |
|
99 is(SelectionHelperUI.isActive, true, "selection active"); |
|
100 is(getTrimmedSelection(gFrame).toString(), "Alice was beginning to get very tired of sitting by her sister on the bank", |
|
101 "selection test"); |
|
102 |
|
103 touchdrag = new TouchDragAndHold(); |
|
104 yield touchdrag.start(gWindow, SelectionHelperUI.endMark.xPos, ypos, 320, ypos); |
|
105 touchdrag.end(); |
|
106 |
|
107 yield waitForCondition(function () { |
|
108 return !SelectionHelperUI.hasActiveDrag; |
|
109 }, kCommonWaitMs, kCommonPollMs); |
|
110 yield SelectionHelperUI.pingSelectionHandler(); |
|
111 |
|
112 is(SelectionHelperUI.isActive, true, "selection active"); |
|
113 is(getTrimmedSelection(gFrame).toString(), "Alice was beginning to get very", "selection test"); |
|
114 }, |
|
115 }); |
|
116 |
|
117 gTests.push({ |
|
118 desc: "scrolled iframe selection", |
|
119 setUp: setUpAndTearDown, |
|
120 run: function test() { |
|
121 gFrame.focus(); |
|
122 |
|
123 let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); |
|
124 gFrame.contentDocument.defaultView.scrollBy(0, 200); |
|
125 yield scrollPromise; |
|
126 |
|
127 sendContextMenuClick(30, 240); |
|
128 |
|
129 yield waitForCondition(function () { |
|
130 return SelectionHelperUI.isSelectionUIVisible; |
|
131 }, kCommonWaitMs, kCommonPollMs); |
|
132 |
|
133 is(SelectionHelperUI.isActive, true, "selection active"); |
|
134 is(getTrimmedSelection(gFrame).toString(), "started", "selection test"); |
|
135 |
|
136 let promise = waitForEvent(document, "popupshown"); |
|
137 sendContextMenuClickToSelection(gFrame.contentDocument.defaultView); |
|
138 |
|
139 yield promise; |
|
140 ok(promise && !(promise instanceof Error), "promise error"); |
|
141 ok(ContextMenuUI._menuPopup.visible, "is visible"); |
|
142 |
|
143 let menuItem = document.getElementById("context-copy"); |
|
144 ok(menuItem, "menu item exists"); |
|
145 ok(!menuItem.hidden, "menu item visible"); |
|
146 let popupPromise = waitForEvent(document, "popuphidden"); |
|
147 sendElementTap(gWindow, menuItem); |
|
148 yield popupPromise; |
|
149 ok(popupPromise && !(popupPromise instanceof Error), "promise error"); |
|
150 |
|
151 // The wait is needed to give time to populate the clipboard. |
|
152 let string = ""; |
|
153 yield waitForCondition(function () { |
|
154 string = SpecialPowers.getClipboardData("text/unicode"); |
|
155 return string === "started"; |
|
156 }); |
|
157 is(string, "started", "copy text"); |
|
158 |
|
159 }, |
|
160 tearDown: function tearDown() { |
|
161 emptyClipboard(); |
|
162 let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); |
|
163 gFrame.contentDocument.defaultView.scrollBy(0, -200); |
|
164 yield scrollPromise; |
|
165 clearSelection(gWindow); |
|
166 clearSelection(gFrame); |
|
167 yield waitForCondition(function () { |
|
168 return !SelectionHelperUI.isSelectionUIVisible; |
|
169 }, kCommonWaitMs, kCommonPollMs); |
|
170 yield hideContextUI(); |
|
171 }, |
|
172 }); |
|
173 |
|
174 gTests.push({ |
|
175 desc: "iframe within scrolled page selection", |
|
176 setUp: setUpAndTearDown, |
|
177 run: function test() { |
|
178 gFrame.focus(); |
|
179 |
|
180 let scrollPromise = waitForEvent(gWindow, "scroll"); |
|
181 gWindow.scrollBy(0, 200); |
|
182 yield scrollPromise; |
|
183 |
|
184 scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); |
|
185 gFrame.contentDocument.defaultView.scrollBy(0, 200); |
|
186 yield scrollPromise; |
|
187 |
|
188 sendContextMenuClick(114, 130); |
|
189 |
|
190 yield waitForCondition(function () { |
|
191 return SelectionHelperUI.isSelectionUIVisible; |
|
192 }, kCommonWaitMs, kCommonPollMs); |
|
193 |
|
194 is(SelectionHelperUI.isActive, true, "selection active"); |
|
195 is(getTrimmedSelection(gFrame).toString(), "moment", "selection test"); |
|
196 }, |
|
197 tearDown: function tearDown() { |
|
198 emptyClipboard(); |
|
199 clearSelection(gWindow); |
|
200 clearSelection(gFrame); |
|
201 let scrollPromise = waitForEvent(gFrame.contentDocument.defaultView, "scroll"); |
|
202 gFrame.contentDocument.defaultView.scrollBy(0, -200); |
|
203 yield scrollPromise; |
|
204 scrollPromise = waitForEvent(gWindow, "scroll"); |
|
205 gWindow.scrollBy(0, -200); |
|
206 yield scrollPromise; |
|
207 yield waitForCondition(function () { |
|
208 return !SelectionHelperUI.isSelectionUIVisible; |
|
209 }, kCommonWaitMs, kCommonPollMs); |
|
210 yield hideContextUI(); |
|
211 }, |
|
212 }); |
|
213 |
|
214 function test() { |
|
215 if (!isLandscapeMode()) { |
|
216 todo(false, "browser_selection_tests need landscape mode to run."); |
|
217 return; |
|
218 } |
|
219 runTests(); |
|
220 } |