OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser.webcontents; | 5 package org.chromium.content.browser.webcontents; |
6 | 6 |
7 import android.support.test.filters.SmallTest; | 7 import android.support.test.filters.SmallTest; |
8 | 8 |
| 9 import org.junit.Assert; |
| 10 import org.junit.Rule; |
| 11 import org.junit.Test; |
| 12 import org.junit.runner.RunWith; |
| 13 |
| 14 import org.chromium.base.test.BaseJUnit4ClassRunner; |
9 import org.chromium.base.test.util.CallbackHelper; | 15 import org.chromium.base.test.util.CallbackHelper; |
10 import org.chromium.base.test.util.UrlUtils; | 16 import org.chromium.base.test.util.UrlUtils; |
11 import org.chromium.content.browser.test.util.JavaScriptUtils; | 17 import org.chromium.content.browser.test.util.JavaScriptUtils; |
12 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; | 18 import org.chromium.content_public.browser.AccessibilitySnapshotCallback; |
13 import org.chromium.content_public.browser.AccessibilitySnapshotNode; | 19 import org.chromium.content_public.browser.AccessibilitySnapshotNode; |
14 import org.chromium.content_shell_apk.ContentShellTestBase; | 20 import org.chromium.content_shell_apk.ContentShellActivityTestRule; |
15 | 21 |
16 /** | 22 /** |
17 * Accessibility snapshot tests for Assist feature. | 23 * Accessibility snapshot tests for Assist feature. |
18 */ | 24 */ |
19 public class AccessibilitySnapshotTest extends ContentShellTestBase { | 25 @RunWith(BaseJUnit4ClassRunner.class) |
| 26 public class AccessibilitySnapshotTest { |
| 27 private static final double ASSERTION_DELTA = 0; |
| 28 |
| 29 @Rule |
| 30 public ContentShellActivityTestRule mActivityTestRule = new ContentShellActi
vityTestRule(); |
| 31 |
20 private static class AccessibilityCallbackHelper extends CallbackHelper { | 32 private static class AccessibilityCallbackHelper extends CallbackHelper { |
21 private AccessibilitySnapshotNode mRoot; | 33 private AccessibilitySnapshotNode mRoot; |
22 | 34 |
23 public void notifyCalled(AccessibilitySnapshotNode root) { | 35 public void notifyCalled(AccessibilitySnapshotNode root) { |
24 mRoot = root; | 36 mRoot = root; |
25 super.notifyCalled(); | 37 super.notifyCalled(); |
26 } | 38 } |
27 | 39 |
28 public AccessibilitySnapshotNode getValue() { | 40 public AccessibilitySnapshotNode getValue() { |
29 return mRoot; | 41 return mRoot; |
30 } | 42 } |
31 } | 43 } |
32 | 44 |
33 private AccessibilitySnapshotNode receiveAccessibilitySnapshot(String data,
String js) | 45 private AccessibilitySnapshotNode receiveAccessibilitySnapshot(String data,
String js) |
34 throws Throwable { | 46 throws Throwable { |
35 launchContentShellWithUrl(UrlUtils.encodeHtmlDataUri(data)); | 47 mActivityTestRule.launchContentShellWithUrl(UrlUtils.encodeHtmlDataUri(d
ata)); |
36 waitForActiveShellToBeDoneLoading(); | 48 mActivityTestRule.waitForActiveShellToBeDoneLoading(); |
37 if (js != null) { | 49 if (js != null) { |
38 JavaScriptUtils.executeJavaScriptAndWaitForResult(getWebContents(),
js); | 50 JavaScriptUtils.executeJavaScriptAndWaitForResult( |
| 51 mActivityTestRule.getWebContents(), js); |
39 } | 52 } |
40 | 53 |
41 final AccessibilityCallbackHelper callbackHelper = new AccessibilityCall
backHelper(); | 54 final AccessibilityCallbackHelper callbackHelper = new AccessibilityCall
backHelper(); |
42 final AccessibilitySnapshotCallback callback = new AccessibilitySnapshot
Callback() { | 55 final AccessibilitySnapshotCallback callback = new AccessibilitySnapshot
Callback() { |
43 @Override | 56 @Override |
44 public void onAccessibilitySnapshot(AccessibilitySnapshotNode root)
{ | 57 public void onAccessibilitySnapshot(AccessibilitySnapshotNode root)
{ |
45 callbackHelper.notifyCalled(root); | 58 callbackHelper.notifyCalled(root); |
46 } | 59 } |
47 }; | 60 }; |
48 // read the callbackcount before executing the call on UI thread, since
it may | 61 // read the callbackcount before executing the call on UI thread, since
it may |
49 // synchronously complete. | 62 // synchronously complete. |
50 final int callbackCount = callbackHelper.getCallCount(); | 63 final int callbackCount = callbackHelper.getCallCount(); |
51 runTestOnUiThread(new Runnable() { | 64 mActivityTestRule.runOnUiThread(new Runnable() { |
52 @Override | 65 @Override |
53 public void run() { | 66 public void run() { |
54 getWebContents().requestAccessibilitySnapshot(callback); | 67 mActivityTestRule.getWebContents().requestAccessibilitySnapshot(
callback); |
55 } | 68 } |
56 }); | 69 }); |
57 callbackHelper.waitForCallback(callbackCount); | 70 callbackHelper.waitForCallback(callbackCount); |
58 return callbackHelper.getValue(); | 71 return callbackHelper.getValue(); |
59 } | 72 } |
60 | 73 |
61 /** | 74 /** |
62 * Verifies that AX tree is returned. | 75 * Verifies that AX tree is returned. |
63 */ | 76 */ |
| 77 @Test |
64 @SmallTest | 78 @SmallTest |
65 public void testRequestAccessibilitySnapshot() throws Throwable { | 79 public void testRequestAccessibilitySnapshot() throws Throwable { |
66 final String data = "<button>Click</button>"; | 80 final String data = "<button>Click</button>"; |
67 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 81 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
68 assertEquals(1, root.children.size()); | 82 Assert.assertEquals(1, root.children.size()); |
69 assertEquals("", root.text); | 83 Assert.assertEquals("", root.text); |
70 AccessibilitySnapshotNode child = root.children.get(0); | 84 AccessibilitySnapshotNode child = root.children.get(0); |
71 assertEquals(1, child.children.size()); | 85 Assert.assertEquals(1, child.children.size()); |
72 assertEquals("", child.text); | 86 Assert.assertEquals("", child.text); |
73 AccessibilitySnapshotNode grandChild = child.children.get(0); | 87 AccessibilitySnapshotNode grandChild = child.children.get(0); |
74 assertEquals(0, grandChild.children.size()); | 88 Assert.assertEquals(0, grandChild.children.size()); |
75 assertEquals("Click", grandChild.text); | 89 Assert.assertEquals("Click", grandChild.text); |
76 } | 90 } |
77 | 91 |
| 92 @Test |
78 @SmallTest | 93 @SmallTest |
79 public void testRequestAccessibilitySnapshotColors() throws Throwable { | 94 public void testRequestAccessibilitySnapshotColors() throws Throwable { |
80 final String data = "<p style=\"color:#123456;background:#abcdef\">color
</p>"; | 95 final String data = "<p style=\"color:#123456;background:#abcdef\">color
</p>"; |
81 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 96 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
82 assertEquals(1, root.children.size()); | 97 Assert.assertEquals(1, root.children.size()); |
83 assertEquals("", root.text); | 98 Assert.assertEquals("", root.text); |
84 AccessibilitySnapshotNode child = root.children.get(0); | 99 AccessibilitySnapshotNode child = root.children.get(0); |
85 assertEquals("color", child.text); | 100 Assert.assertEquals("color", child.text); |
86 assertTrue(child.hasStyle); | 101 Assert.assertTrue(child.hasStyle); |
87 assertEquals("ff123456", Integer.toHexString(child.color)); | 102 Assert.assertEquals("ff123456", Integer.toHexString(child.color)); |
88 assertEquals("ffabcdef", Integer.toHexString(child.bgcolor)); | 103 Assert.assertEquals("ffabcdef", Integer.toHexString(child.bgcolor)); |
89 } | 104 } |
90 | 105 |
| 106 @Test |
91 @SmallTest | 107 @SmallTest |
92 public void testRequestAccessibilitySnapshotFontSize() throws Throwable { | 108 public void testRequestAccessibilitySnapshotFontSize() throws Throwable { |
93 final String data = "<html><head><style> " | 109 final String data = "<html><head><style> " |
94 + " p { font-size:16px; transform: scale(2); }" | 110 + " p { font-size:16px; transform: scale(2); }" |
95 + " </style></head><body><p>foo</p></body></html>"; | 111 + " </style></head><body><p>foo</p></body></html>"; |
96 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 112 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
97 assertEquals(1, root.children.size()); | 113 Assert.assertEquals(1, root.children.size()); |
98 assertEquals("", root.text); | 114 Assert.assertEquals("", root.text); |
99 AccessibilitySnapshotNode child = root.children.get(0); | 115 AccessibilitySnapshotNode child = root.children.get(0); |
100 assertTrue(child.hasStyle); | 116 Assert.assertTrue(child.hasStyle); |
101 assertEquals("foo", child.text); | 117 Assert.assertEquals("foo", child.text); |
102 | 118 |
103 // The font size should take the scale into account. | 119 // The font size should take the scale into account. |
104 assertEquals(32.0, child.textSize, 1.0); | 120 Assert.assertEquals(32.0, child.textSize, 1.0); |
105 } | 121 } |
106 | 122 |
| 123 @Test |
107 @SmallTest | 124 @SmallTest |
108 public void testRequestAccessibilitySnapshotStyles() throws Throwable { | 125 public void testRequestAccessibilitySnapshotStyles() throws Throwable { |
109 final String data = "<html><head><style> " | 126 final String data = "<html><head><style> " |
110 + " body { font: italic bold 12px Courier; }" | 127 + " body { font: italic bold 12px Courier; }" |
111 + " </style></head><body><p>foo</p></body></html>"; | 128 + " </style></head><body><p>foo</p></body></html>"; |
112 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 129 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
113 assertEquals(1, root.children.size()); | 130 Assert.assertEquals(1, root.children.size()); |
114 assertEquals("", root.text); | 131 Assert.assertEquals("", root.text); |
115 AccessibilitySnapshotNode child = root.children.get(0); | 132 AccessibilitySnapshotNode child = root.children.get(0); |
116 assertEquals("foo", child.text); | 133 Assert.assertEquals("foo", child.text); |
117 assertTrue(child.hasStyle); | 134 Assert.assertTrue(child.hasStyle); |
118 assertTrue(child.bold); | 135 Assert.assertTrue(child.bold); |
119 assertTrue(child.italic); | 136 Assert.assertTrue(child.italic); |
120 assertFalse(child.lineThrough); | 137 Assert.assertFalse(child.lineThrough); |
121 assertFalse(child.underline); | 138 Assert.assertFalse(child.underline); |
122 } | 139 } |
123 | 140 |
| 141 @Test |
124 @SmallTest | 142 @SmallTest |
125 public void testRequestAccessibilitySnapshotStrongStyle() throws Throwable { | 143 public void testRequestAccessibilitySnapshotStrongStyle() throws Throwable { |
126 final String data = "<html><body><p>foo</p><p><strong>bar</strong></p></
body></html>"; | 144 final String data = "<html><body><p>foo</p><p><strong>bar</strong></p></
body></html>"; |
127 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 145 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
128 assertEquals(2, root.children.size()); | 146 Assert.assertEquals(2, root.children.size()); |
129 assertEquals("", root.text); | 147 Assert.assertEquals("", root.text); |
130 AccessibilitySnapshotNode child1 = root.children.get(0); | 148 AccessibilitySnapshotNode child1 = root.children.get(0); |
131 assertEquals("foo", child1.text); | 149 Assert.assertEquals("foo", child1.text); |
132 assertTrue(child1.hasStyle); | 150 Assert.assertTrue(child1.hasStyle); |
133 assertFalse(child1.bold); | 151 Assert.assertFalse(child1.bold); |
134 AccessibilitySnapshotNode child2 = root.children.get(1); | 152 AccessibilitySnapshotNode child2 = root.children.get(1); |
135 AccessibilitySnapshotNode child2child = child2.children.get(0); | 153 AccessibilitySnapshotNode child2child = child2.children.get(0); |
136 assertEquals("bar", child2child.text); | 154 Assert.assertEquals("bar", child2child.text); |
137 assertEquals(child1.textSize, child2child.textSize); | 155 Assert.assertEquals(child1.textSize, child2child.textSize, ASSERTION_DEL
TA); |
138 assertTrue(child2child.bold); | 156 Assert.assertTrue(child2child.bold); |
139 } | 157 } |
140 | 158 |
| 159 @Test |
141 @SmallTest | 160 @SmallTest |
142 public void testRequestAccessibilitySnapshotItalicStyle() throws Throwable { | 161 public void testRequestAccessibilitySnapshotItalicStyle() throws Throwable { |
143 final String data = "<html><body><i>foo</i></body></html>"; | 162 final String data = "<html><body><i>foo</i></body></html>"; |
144 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 163 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
145 assertEquals(1, root.children.size()); | 164 Assert.assertEquals(1, root.children.size()); |
146 assertEquals("", root.text); | 165 Assert.assertEquals("", root.text); |
147 AccessibilitySnapshotNode child = root.children.get(0); | 166 AccessibilitySnapshotNode child = root.children.get(0); |
148 AccessibilitySnapshotNode grandchild = child.children.get(0); | 167 AccessibilitySnapshotNode grandchild = child.children.get(0); |
149 assertEquals("foo", grandchild.text); | 168 Assert.assertEquals("foo", grandchild.text); |
150 assertTrue(grandchild.hasStyle); | 169 Assert.assertTrue(grandchild.hasStyle); |
151 assertTrue(grandchild.italic); | 170 Assert.assertTrue(grandchild.italic); |
152 } | 171 } |
153 | 172 |
| 173 @Test |
154 @SmallTest | 174 @SmallTest |
155 public void testRequestAccessibilitySnapshotBoldStyle() throws Throwable { | 175 public void testRequestAccessibilitySnapshotBoldStyle() throws Throwable { |
156 final String data = "<html><body><b>foo</b></body></html>"; | 176 final String data = "<html><body><b>foo</b></body></html>"; |
157 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 177 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
158 assertEquals(1, root.children.size()); | 178 Assert.assertEquals(1, root.children.size()); |
159 assertEquals("", root.text); | 179 Assert.assertEquals("", root.text); |
160 AccessibilitySnapshotNode child = root.children.get(0); | 180 AccessibilitySnapshotNode child = root.children.get(0); |
161 AccessibilitySnapshotNode grandchild = child.children.get(0); | 181 AccessibilitySnapshotNode grandchild = child.children.get(0); |
162 assertEquals("foo", grandchild.text); | 182 Assert.assertEquals("foo", grandchild.text); |
163 assertTrue(grandchild.hasStyle); | 183 Assert.assertTrue(grandchild.hasStyle); |
164 assertTrue(grandchild.bold); | 184 Assert.assertTrue(grandchild.bold); |
165 } | 185 } |
166 | 186 |
| 187 @Test |
167 @SmallTest | 188 @SmallTest |
168 public void testRequestAccessibilitySnapshotNoStyle() throws Throwable { | 189 public void testRequestAccessibilitySnapshotNoStyle() throws Throwable { |
169 final String data = "<table><thead></thead></table>"; | 190 final String data = "<table><thead></thead></table>"; |
170 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 191 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
171 assertEquals(1, root.children.size()); | 192 Assert.assertEquals(1, root.children.size()); |
172 assertEquals("", root.text); | 193 Assert.assertEquals("", root.text); |
173 AccessibilitySnapshotNode grandChild = root.children.get(0).children.get
(0); | 194 AccessibilitySnapshotNode grandChild = root.children.get(0).children.get
(0); |
174 assertFalse(grandChild.hasStyle); | 195 Assert.assertFalse(grandChild.hasStyle); |
175 } | 196 } |
176 | 197 |
177 private String getSelectionScript(String node1, int start, String node2, int
end) { | 198 private String getSelectionScript(String node1, int start, String node2, int
end) { |
178 return "var element1 = document.getElementById('" + node1 + "');" | 199 return "var element1 = document.getElementById('" + node1 + "');" |
179 + "var node1 = element1.childNodes.item(0);" | 200 + "var node1 = element1.childNodes.item(0);" |
180 + "var range=document.createRange();" | 201 + "var range=document.createRange();" |
181 + "range.setStart(node1," + start + ");" | 202 + "range.setStart(node1," + start + ");" |
182 + "var element2 = document.getElementById('" + node2 + "');" | 203 + "var element2 = document.getElementById('" + node2 + "');" |
183 + "var node2 = element2.childNodes.item(0);" | 204 + "var node2 = element2.childNodes.item(0);" |
184 + "range.setEnd(node2," + end + ");" | 205 + "range.setEnd(node2," + end + ");" |
185 + "var selection=window.getSelection();" | 206 + "var selection=window.getSelection();" |
186 + "selection.removeAllRanges();" | 207 + "selection.removeAllRanges();" |
187 + "selection.addRange(range);"; | 208 + "selection.addRange(range);"; |
188 } | 209 } |
189 | 210 |
| 211 @Test |
190 @SmallTest | 212 @SmallTest |
191 public void testRequestAccessibilitySnapshotOneCharacterSelection() throws T
hrowable { | 213 public void testRequestAccessibilitySnapshotOneCharacterSelection() throws T
hrowable { |
192 final String data = "<html><body><b id='node'>foo</b></body></html>"; | 214 final String data = "<html><body><b id='node'>foo</b></body></html>"; |
193 | 215 |
194 AccessibilitySnapshotNode root = | 216 AccessibilitySnapshotNode root = |
195 receiveAccessibilitySnapshot(data, getSelectionScript("node", 0,
"node", 1)); | 217 receiveAccessibilitySnapshot(data, getSelectionScript("node", 0,
"node", 1)); |
196 assertEquals(1, root.children.size()); | 218 Assert.assertEquals(1, root.children.size()); |
197 assertEquals("", root.text); | 219 Assert.assertEquals("", root.text); |
198 AccessibilitySnapshotNode child = root.children.get(0); | 220 AccessibilitySnapshotNode child = root.children.get(0); |
199 AccessibilitySnapshotNode grandchild = child.children.get(0); | 221 AccessibilitySnapshotNode grandchild = child.children.get(0); |
200 assertEquals("foo", grandchild.text); | 222 Assert.assertEquals("foo", grandchild.text); |
201 assertEquals(0, grandchild.startSelection); | 223 Assert.assertEquals(0, grandchild.startSelection); |
202 assertEquals(1, grandchild.endSelection); | 224 Assert.assertEquals(1, grandchild.endSelection); |
203 } | 225 } |
204 | 226 |
| 227 @Test |
| 228 |
205 @SmallTest | 229 @SmallTest |
206 public void testRequestAccessibilitySnapshotOneNodeSelection() throws Throwa
ble { | 230 public void testRequestAccessibilitySnapshotOneNodeSelection() throws Throwa
ble { |
207 final String data = "<html><body><b id='node'>foo</b></body></html>"; | 231 final String data = "<html><body><b id='node'>foo</b></body></html>"; |
208 | 232 |
209 AccessibilitySnapshotNode root = | 233 AccessibilitySnapshotNode root = |
210 receiveAccessibilitySnapshot(data, getSelectionScript("node", 0,
"node", 3)); | 234 receiveAccessibilitySnapshot(data, getSelectionScript("node", 0,
"node", 3)); |
211 assertEquals(1, root.children.size()); | 235 Assert.assertEquals(1, root.children.size()); |
212 assertEquals("", root.text); | 236 Assert.assertEquals("", root.text); |
213 AccessibilitySnapshotNode child = root.children.get(0); | 237 AccessibilitySnapshotNode child = root.children.get(0); |
214 AccessibilitySnapshotNode grandchild = child.children.get(0); | 238 AccessibilitySnapshotNode grandchild = child.children.get(0); |
215 assertEquals("foo", grandchild.text); | 239 Assert.assertEquals("foo", grandchild.text); |
216 assertEquals(0, grandchild.startSelection); | 240 Assert.assertEquals(0, grandchild.startSelection); |
217 assertEquals(3, grandchild.endSelection); | 241 Assert.assertEquals(3, grandchild.endSelection); |
218 } | 242 } |
219 | 243 |
| 244 @Test |
220 @SmallTest | 245 @SmallTest |
221 public void testRequestAccessibilitySnapshotSubsequentNodeSelection() throws
Throwable { | 246 public void testRequestAccessibilitySnapshotSubsequentNodeSelection() throws
Throwable { |
222 final String data = "<html><body><b id='node1'>foo</b><b id='node2'>bar<
/b></body></html>"; | 247 final String data = "<html><body><b id='node1'>foo</b><b id='node2'>bar<
/b></body></html>"; |
223 | 248 |
224 AccessibilitySnapshotNode root = | 249 AccessibilitySnapshotNode root = |
225 receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1
, "node2", 1)); | 250 receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1
, "node2", 1)); |
226 assertEquals(1, root.children.size()); | 251 Assert.assertEquals(1, root.children.size()); |
227 assertEquals("", root.text); | 252 Assert.assertEquals("", root.text); |
228 AccessibilitySnapshotNode child = root.children.get(0); | 253 AccessibilitySnapshotNode child = root.children.get(0); |
229 AccessibilitySnapshotNode grandchild = child.children.get(0); | 254 AccessibilitySnapshotNode grandchild = child.children.get(0); |
230 assertEquals("foo", grandchild.text); | 255 Assert.assertEquals("foo", grandchild.text); |
231 assertEquals(1, grandchild.startSelection); | 256 Assert.assertEquals(1, grandchild.startSelection); |
232 assertEquals(3, grandchild.endSelection); | 257 Assert.assertEquals(3, grandchild.endSelection); |
233 grandchild = child.children.get(1); | 258 grandchild = child.children.get(1); |
234 assertEquals("bar", grandchild.text); | 259 Assert.assertEquals("bar", grandchild.text); |
235 assertEquals(0, grandchild.startSelection); | 260 Assert.assertEquals(0, grandchild.startSelection); |
236 assertEquals(1, grandchild.endSelection); | 261 Assert.assertEquals(1, grandchild.endSelection); |
237 } | 262 } |
238 | 263 |
| 264 @Test |
239 @SmallTest | 265 @SmallTest |
240 public void testRequestAccessibilitySnapshotMultiNodeSelection() throws Thro
wable { | 266 public void testRequestAccessibilitySnapshotMultiNodeSelection() throws Thro
wable { |
241 final String data = | 267 final String data = |
242 "<html><body><b id='node1'>foo</b><b>middle</b><b id='node2'>bar
</b></body></html>"; | 268 "<html><body><b id='node1'>foo</b><b>middle</b><b id='node2'>bar
</b></body></html>"; |
243 | 269 |
244 AccessibilitySnapshotNode root = | 270 AccessibilitySnapshotNode root = |
245 receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1
, "node2", 1)); | 271 receiveAccessibilitySnapshot(data, getSelectionScript("node1", 1
, "node2", 1)); |
246 assertEquals(1, root.children.size()); | 272 Assert.assertEquals(1, root.children.size()); |
247 assertEquals("", root.text); | 273 Assert.assertEquals("", root.text); |
248 AccessibilitySnapshotNode child = root.children.get(0); | 274 AccessibilitySnapshotNode child = root.children.get(0); |
249 AccessibilitySnapshotNode grandchild = child.children.get(0); | 275 AccessibilitySnapshotNode grandchild = child.children.get(0); |
250 assertEquals("foo", grandchild.text); | 276 Assert.assertEquals("foo", grandchild.text); |
251 assertEquals(1, grandchild.startSelection); | 277 Assert.assertEquals(1, grandchild.startSelection); |
252 assertEquals(3, grandchild.endSelection); | 278 Assert.assertEquals(3, grandchild.endSelection); |
253 grandchild = child.children.get(1); | 279 grandchild = child.children.get(1); |
254 assertEquals("middle", grandchild.text); | 280 Assert.assertEquals("middle", grandchild.text); |
255 assertEquals(0, grandchild.startSelection); | 281 Assert.assertEquals(0, grandchild.startSelection); |
256 assertEquals(6, grandchild.endSelection); | 282 Assert.assertEquals(6, grandchild.endSelection); |
257 grandchild = child.children.get(2); | 283 grandchild = child.children.get(2); |
258 assertEquals("bar", grandchild.text); | 284 Assert.assertEquals("bar", grandchild.text); |
259 assertEquals(0, grandchild.startSelection); | 285 Assert.assertEquals(0, grandchild.startSelection); |
260 assertEquals(1, grandchild.endSelection); | 286 Assert.assertEquals(1, grandchild.endSelection); |
261 } | 287 } |
262 | 288 |
| 289 @Test |
263 @SmallTest | 290 @SmallTest |
264 public void testRequestAccessibilitySnapshotInputSelection() throws Throwabl
e { | 291 public void testRequestAccessibilitySnapshotInputSelection() throws Throwabl
e { |
265 final String data = "<html><body><input id='input' value='Hello, world'>
</body></html>"; | 292 final String data = "<html><body><input id='input' value='Hello, world'>
</body></html>"; |
266 final String js = "var input = document.getElementById('input');" | 293 final String js = "var input = document.getElementById('input');" |
267 + "input.select();" | 294 + "input.select();" |
268 + "input.selectionStart = 0;" | 295 + "input.selectionStart = 0;" |
269 + "input.selectionEnd = 5;"; | 296 + "input.selectionEnd = 5;"; |
270 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, js); | 297 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, js); |
271 assertEquals(1, root.children.size()); | 298 Assert.assertEquals(1, root.children.size()); |
272 assertEquals("", root.text); | 299 Assert.assertEquals("", root.text); |
273 AccessibilitySnapshotNode child = root.children.get(0); | 300 AccessibilitySnapshotNode child = root.children.get(0); |
274 AccessibilitySnapshotNode grandchild = child.children.get(0); | 301 AccessibilitySnapshotNode grandchild = child.children.get(0); |
275 assertEquals("Hello, world", grandchild.text); | 302 Assert.assertEquals("Hello, world", grandchild.text); |
276 assertEquals(0, grandchild.startSelection); | 303 Assert.assertEquals(0, grandchild.startSelection); |
277 assertEquals(5, grandchild.endSelection); | 304 Assert.assertEquals(5, grandchild.endSelection); |
278 } | 305 } |
279 | 306 |
| 307 @Test |
280 @SmallTest | 308 @SmallTest |
281 public void testRequestAccessibilitySnapshotPasswordField() throws Throwable
{ | 309 public void testRequestAccessibilitySnapshotPasswordField() throws Throwable
{ |
282 final String data = | 310 final String data = |
283 "<html><body><input id='input' type='password' value='foo'></bod
y></html>"; | 311 "<html><body><input id='input' type='password' value='foo'></bod
y></html>"; |
284 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); | 312 AccessibilitySnapshotNode root = receiveAccessibilitySnapshot(data, null
); |
285 assertEquals(1, root.children.size()); | 313 Assert.assertEquals(1, root.children.size()); |
286 assertEquals("", root.text); | 314 Assert.assertEquals("", root.text); |
287 AccessibilitySnapshotNode child = root.children.get(0); | 315 AccessibilitySnapshotNode child = root.children.get(0); |
288 AccessibilitySnapshotNode grandchild = child.children.get(0); | 316 AccessibilitySnapshotNode grandchild = child.children.get(0); |
289 assertEquals("•••", grandchild.text); | 317 Assert.assertEquals("•••", grandchild.text); |
290 } | 318 } |
291 } | 319 } |
OLD | NEW |