OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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; | 5 package org.chromium.content.browser; |
6 | 6 |
7 import android.content.ClipData; | 7 import android.content.ClipData; |
8 import android.content.ClipboardManager; | 8 import android.content.ClipboardManager; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.test.suitebuilder.annotation.SmallTest; | 10 import android.test.suitebuilder.annotation.SmallTest; |
(...skipping 16 matching lines...) Expand all Loading... | |
27 private static final String DATA_URL = UrlUtils.encodeHtmlDataUri( | 27 private static final String DATA_URL = UrlUtils.encodeHtmlDataUri( |
28 "<html><head><meta name=\"viewport\"" | 28 "<html><head><meta name=\"viewport\"" |
29 + "content=\"width=device-width, initial-scale=1.1, maximum-scale=1. 5\" /></head>" | 29 + "content=\"width=device-width, initial-scale=1.1, maximum-scale=1. 5\" /></head>" |
30 + "<body><form action=\"about:blank\">" | 30 + "<body><form action=\"about:blank\">" |
31 + "<input id=\"empty_input_text\" type=\"text\" />" | 31 + "<input id=\"empty_input_text\" type=\"text\" />" |
32 + "<br/><p><span id=\"plain_text_1\">SamplePlainTextOne</span></p>" | 32 + "<br/><p><span id=\"plain_text_1\">SamplePlainTextOne</span></p>" |
33 + "<br/><p><span id=\"plain_text_2\">SamplePlainTextTwo</span></p>" | 33 + "<br/><p><span id=\"plain_text_2\">SamplePlainTextTwo</span></p>" |
34 + "<br/><input id=\"empty_input_text\" type=\"text\" />" | 34 + "<br/><input id=\"empty_input_text\" type=\"text\" />" |
35 + "<br/><input id=\"input_text\" type=\"text\" value=\"SampleInputTe xt\" />" | 35 + "<br/><input id=\"input_text\" type=\"text\" value=\"SampleInputTe xt\" />" |
36 + "<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></tex tarea>" | 36 + "<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></tex tarea>" |
37 + "<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">Sample Text </textarea>" | 37 + "<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">SampleTextA rea</textarea>" |
38 + "<br/><input id=\"readonly_text\" type=\"text\" readonly value=\"S ample Text\"/>" | 38 + "<br/><input id=\"readonly_text\" type=\"text\" readonly value=\"S ample Text\"/>" |
39 + "<br/><input id=\"disabled_text\" type=\"text\" disabled value=\"S ample Text\" />" | 39 + "<br/><input id=\"disabled_text\" type=\"text\" disabled value=\"S ample Text\" />" |
40 + "<br/><input id=\"input_password\" type=\"password\" value=\"Sampl ePassword\" />" | 40 + "<br/><input id=\"input_password\" type=\"password\" value=\"Sampl ePassword\" />" |
41 + "</form></body></html>"); | 41 + "</form></body></html>"); |
42 private ContentViewCore mContentViewCore; | 42 private ContentViewCore mContentViewCore; |
43 | 43 |
44 @Override | 44 @Override |
45 public void setUp() throws Exception { | 45 public void setUp() throws Exception { |
46 super.setUp(); | 46 super.setUp(); |
47 | 47 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); | 230 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); |
231 assertWaitForSelectActionBarVisible(true); | 231 assertWaitForSelectActionBarVisible(true); |
232 assertTrue(mContentViewCore.hasSelection()); | 232 assertTrue(mContentViewCore.hasSelection()); |
233 assertNotNull(mContentViewCore.getSelectActionHandler()); | 233 assertNotNull(mContentViewCore.getSelectActionHandler()); |
234 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionEditabl e()); | 234 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionEditabl e()); |
235 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPasswor d()); | 235 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPasswor d()); |
236 } | 236 } |
237 | 237 |
238 @SmallTest | 238 @SmallTest |
239 @Feature({"TextInput"}) | 239 @Feature({"TextInput"}) |
240 public void testActionBarConfiguredCorrectlyForTextArea() throws Throwable { | |
241 DOMUtils.longPressNode(this, mContentViewCore, "textarea"); | |
242 assertWaitForSelectActionBarVisible(true); | |
243 assertTrue(mContentViewCore.hasSelection()); | |
244 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
245 assertTrue(mContentViewCore.getSelectActionHandler().isSelectionEditable ()); | |
246 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPasswor d()); | |
247 } | |
248 | |
249 @SmallTest | |
250 @Feature({"TextInput"}) | |
240 public void testSelectActionBarPlainTextCopy() throws Exception { | 251 public void testSelectActionBarPlainTextCopy() throws Exception { |
241 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); | 252 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); |
242 assertWaitForSelectActionBarVisible(true); | 253 assertWaitForSelectActionBarVisible(true); |
243 assertTrue(mContentViewCore.hasSelection()); | 254 assertTrue(mContentViewCore.hasSelection()); |
244 assertNotNull(mContentViewCore.getSelectActionHandler()); | 255 assertNotNull(mContentViewCore.getSelectActionHandler()); |
245 selectActionBarCopy(); | 256 selectActionBarCopy(); |
246 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne"); | 257 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne"); |
247 } | 258 } |
248 | 259 |
249 @SmallTest | 260 @SmallTest |
(...skipping 19 matching lines...) Expand all Loading... | |
269 DOMUtils.longPressNode(this, mContentViewCore, "input_password"); | 280 DOMUtils.longPressNode(this, mContentViewCore, "input_password"); |
270 assertWaitForSelectActionBarVisible(true); | 281 assertWaitForSelectActionBarVisible(true); |
271 assertTrue(mContentViewCore.hasSelection()); | 282 assertTrue(mContentViewCore.hasSelection()); |
272 assertNotNull(mContentViewCore.getSelectActionHandler()); | 283 assertNotNull(mContentViewCore.getSelectActionHandler()); |
273 selectActionBarCopy(); | 284 selectActionBarCopy(); |
274 // Copy option won't be there for Password, hence no change in Clipboard | 285 // Copy option won't be there for Password, hence no change in Clipboard |
275 // Validating with previous Clipboard content | 286 // Validating with previous Clipboard content |
276 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne"); | 287 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne"); |
277 } | 288 } |
278 | 289 |
290 @SmallTest | |
291 @Feature({"TextInput"}) | |
292 public void testSelectActionBarTextAreaCopy() throws Exception { | |
293 DOMUtils.longPressNode(this, mContentViewCore, "textarea"); | |
294 assertWaitForSelectActionBarVisible(true); | |
295 assertTrue(mContentViewCore.hasSelection()); | |
296 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
297 selectActionBarCopy(); | |
298 assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea") ; | |
299 } | |
300 | |
301 @SmallTest | |
302 @Feature({"TextSelection"}) | |
303 public void testSelectActionBarPlainTextCut() throws Exception { | |
304 copyStringToClipboard(); | |
305 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); | |
306 assertWaitForSelectActionBarVisible(true); | |
307 assertTrue(mContentViewCore.hasSelection()); | |
308 assertEquals(mContentViewCore.getSelectedText(), "SamplePlainTextOne"); | |
309 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
310 selectActionBarCut(); | |
311 assertWaitForSelectActionBarVisible(true); | |
312 assertTrue(mContentViewCore.hasSelection()); | |
313 // Cut option won't be available for plain text. | |
314 // Hence validating previous Clipboard content. | |
315 assertClipboardContents(mContentViewCore.getContext(), "Text to copy"); | |
316 } | |
317 | |
318 @SmallTest | |
319 @Feature({"TextInput"}) | |
320 public void testSelectActionBarInputCut() throws Exception { | |
321 DOMUtils.longPressNode(this, mContentViewCore, "input_text"); | |
322 assertWaitForSelectActionBarVisible(true); | |
323 assertTrue(mContentViewCore.hasSelection()); | |
324 assertEquals(mContentViewCore.getSelectedText(), "SampleInputText"); | |
325 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
326 selectActionBarCut(); | |
327 assertWaitForSelectActionBarVisible(false); | |
328 assertFalse(mContentViewCore.hasSelection()); | |
329 assertClipboardContents(mContentViewCore.getContext(), "SampleInputText" ); | |
330 assertEquals(mContentViewCore.getSelectedText(), ""); | |
331 } | |
332 | |
333 @SmallTest | |
334 @Feature({"TextInput"}) | |
335 public void testSelectActionBarPasswordCut() throws Exception { | |
336 copyStringToClipboard(); | |
337 DOMUtils.longPressNode(this, mContentViewCore, "input_password"); | |
338 assertWaitForSelectActionBarVisible(true); | |
339 assertTrue(mContentViewCore.hasSelection()); | |
340 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
341 selectActionBarCut(); | |
342 assertWaitForSelectActionBarVisible(true); | |
343 assertTrue(mContentViewCore.hasSelection()); | |
344 // Cut option won't be there for Password, hence no change in Clipboard | |
345 // Validating with previous Clipboard content | |
346 assertClipboardContents(mContentViewCore.getContext(), "Text to copy"); | |
347 } | |
348 | |
349 @SmallTest | |
350 @Feature({"TextInput"}) | |
351 public void testSelectActionBarTextAreaCut() throws Exception { | |
352 DOMUtils.longPressNode(this, mContentViewCore, "textarea"); | |
353 assertWaitForSelectActionBarVisible(true); | |
354 assertTrue(mContentViewCore.hasSelection()); | |
355 assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea"); | |
356 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
357 selectActionBarCut(); | |
358 assertWaitForSelectActionBarVisible(false); | |
359 assertFalse(mContentViewCore.hasSelection()); | |
360 assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea") ; | |
361 assertEquals(mContentViewCore.getSelectedText(), ""); | |
362 } | |
363 | |
364 @SmallTest | |
365 @Feature({"TextSelection"}) | |
366 public void testSelectActionBarPlainTextSelectAll() throws Exception { | |
367 copyStringToClipboard(); | |
368 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); | |
369 assertWaitForSelectActionBarVisible(true); | |
370 assertTrue(mContentViewCore.hasSelection()); | |
371 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
372 selectActionBarSelectAll(); | |
373 assertTrue(mContentViewCore.hasSelection()); | |
374 assertWaitForSelectActionBarVisible(true); | |
375 } | |
376 | |
377 @SmallTest | |
378 @Feature({"TextInput"}) | |
379 public void testSelectActionBarInputSelectAll() throws Exception { | |
380 DOMUtils.longPressNode(this, mContentViewCore, "input_text"); | |
381 assertWaitForSelectActionBarVisible(true); | |
382 assertTrue(mContentViewCore.hasSelection()); | |
383 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
384 selectActionBarSelectAll(); | |
385 assertTrue(mContentViewCore.hasSelection()); | |
386 assertWaitForSelectActionBarVisible(true); | |
387 assertEquals(mContentViewCore.getSelectedText(), "SampleInputText"); | |
388 } | |
389 | |
390 @SmallTest | |
391 @Feature({"TextInput"}) | |
392 public void testSelectActionBarPasswordSelectAll() throws Exception { | |
393 DOMUtils.longPressNode(this, mContentViewCore, "input_password"); | |
394 assertWaitForSelectActionBarVisible(true); | |
395 assertTrue(mContentViewCore.hasSelection()); | |
396 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
397 selectActionBarSelectAll(); | |
398 assertTrue(mContentViewCore.hasSelection()); | |
399 assertWaitForSelectActionBarVisible(true); | |
400 } | |
401 | |
402 @SmallTest | |
403 @Feature({"TextInput"}) | |
404 public void testSelectActionBarTextAreaSelectAll() throws Exception { | |
jdduke (slow)
2014/10/30 17:48:31
Do you have any more similar tests? I'd prefer we
| |
405 DOMUtils.longPressNode(this, mContentViewCore, "textarea"); | |
406 assertWaitForSelectActionBarVisible(true); | |
407 assertTrue(mContentViewCore.hasSelection()); | |
408 assertNotNull(mContentViewCore.getSelectActionHandler()); | |
409 selectActionBarSelectAll(); | |
410 assertTrue(mContentViewCore.hasSelection()); | |
411 assertWaitForSelectActionBarVisible(true); | |
412 assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea"); | |
413 } | |
414 | |
415 private void selectActionBarSelectAll() { | |
416 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
417 @Override | |
418 public void run() { | |
419 mContentViewCore.getSelectActionHandler().selectAll(); | |
420 } | |
421 }); | |
422 } | |
423 | |
424 private void selectActionBarCut() { | |
425 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | |
426 @Override | |
427 public void run() { | |
428 mContentViewCore.getSelectActionHandler().cut(); | |
429 } | |
430 }); | |
431 } | |
432 | |
279 private void selectActionBarCopy() { | 433 private void selectActionBarCopy() { |
280 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 434 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
281 @Override | 435 @Override |
282 public void run() { | 436 public void run() { |
283 mContentViewCore.getSelectActionHandler().copy(); | 437 mContentViewCore.getSelectActionHandler().copy(); |
284 } | 438 } |
285 }); | 439 }); |
286 } | 440 } |
287 | 441 |
288 private void assertClipboardContents(final Context context, final String exp ectedContents) | 442 private void assertClipboardContents(final Context context, final String exp ectedContents) |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
363 | 517 |
364 private void assertWaitForPastePopupStatus(final boolean show) throws Interr uptedException { | 518 private void assertWaitForPastePopupStatus(final boolean show) throws Interr uptedException { |
365 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { | 519 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
366 @Override | 520 @Override |
367 public boolean isSatisfied() { | 521 public boolean isSatisfied() { |
368 return show == mContentViewCore.getPastePopupForTest().isShowing (); | 522 return show == mContentViewCore.getPastePopupForTest().isShowing (); |
369 } | 523 } |
370 })); | 524 })); |
371 } | 525 } |
372 } | 526 } |
OLD | NEW |