Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1434)

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/ContentViewCoreSelectionTest.java

Issue 690613003: Adding Unit Test Coverage for Select Action Bar Cut, Paste, Select All options (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added Paste Test cases. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 13 matching lines...) Expand all
24 * Integration tests for text selection-related behavior. 24 * Integration tests for text selection-related behavior.
25 */ 25 */
26 public class ContentViewCoreSelectionTest extends ContentShellTestBase { 26 public class ContentViewCoreSelectionTest extends ContentShellTestBase {
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\" />"
35 + "<br/><input id=\"input_text\" type=\"text\" value=\"SampleInputTe xt\" />" 34 + "<br/><input id=\"input_text\" type=\"text\" value=\"SampleInputTe xt\" />"
36 + "<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></tex tarea>" 35 + "<br/><textarea id=\"empty_textarea\" rows=\"2\" cols=\"20\"></tex tarea>"
37 + "<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">Sample Text </textarea>" 36 + "<br/><textarea id=\"textarea\" rows=\"2\" cols=\"20\">SampleTextA rea</textarea>"
38 + "<br/><input id=\"readonly_text\" type=\"text\" readonly value=\"S ample Text\"/>" 37 + "<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\" />" 38 + "<br/><input id=\"disabled_text\" type=\"text\" disabled value=\"S ample Text\" />"
40 + "<br/><input id=\"input_password\" type=\"password\" value=\"Sampl ePassword\" />" 39 + "<br/><input id=\"input_password\" type=\"password\" value=\"Sampl ePassword\" />"
41 + "</form></body></html>"); 40 + "</form></body></html>");
42 private ContentViewCore mContentViewCore; 41 private ContentViewCore mContentViewCore;
43 42
44 @Override 43 @Override
45 public void setUp() throws Exception { 44 public void setUp() throws Exception {
46 super.setUp(); 45 super.setUp();
47 46
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); 229 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
231 assertWaitForSelectActionBarVisible(true); 230 assertWaitForSelectActionBarVisible(true);
232 assertTrue(mContentViewCore.hasSelection()); 231 assertTrue(mContentViewCore.hasSelection());
233 assertNotNull(mContentViewCore.getSelectActionHandler()); 232 assertNotNull(mContentViewCore.getSelectActionHandler());
234 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionEditabl e()); 233 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionEditabl e());
235 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPasswor d()); 234 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPasswor d());
236 } 235 }
237 236
238 @SmallTest 237 @SmallTest
239 @Feature({"TextInput"}) 238 @Feature({"TextInput"})
239 public void testActionBarConfiguredCorrectlyForTextArea() throws Throwable {
240 DOMUtils.longPressNode(this, mContentViewCore, "textarea");
241 assertWaitForSelectActionBarVisible(true);
242 assertTrue(mContentViewCore.hasSelection());
243 assertNotNull(mContentViewCore.getSelectActionHandler());
244 assertTrue(mContentViewCore.getSelectActionHandler().isSelectionEditable ());
245 assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPasswor d());
246 }
247
248 @SmallTest
249 @Feature({"TextInput"})
240 public void testSelectActionBarPlainTextCopy() throws Exception { 250 public void testSelectActionBarPlainTextCopy() throws Exception {
241 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1"); 251 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
242 assertWaitForSelectActionBarVisible(true); 252 assertWaitForSelectActionBarVisible(true);
243 assertTrue(mContentViewCore.hasSelection()); 253 assertTrue(mContentViewCore.hasSelection());
244 assertNotNull(mContentViewCore.getSelectActionHandler()); 254 assertNotNull(mContentViewCore.getSelectActionHandler());
245 selectActionBarCopy(); 255 selectActionBarCopy();
246 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne"); 256 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne");
247 } 257 }
248 258
249 @SmallTest 259 @SmallTest
(...skipping 19 matching lines...) Expand all
269 DOMUtils.longPressNode(this, mContentViewCore, "input_password"); 279 DOMUtils.longPressNode(this, mContentViewCore, "input_password");
270 assertWaitForSelectActionBarVisible(true); 280 assertWaitForSelectActionBarVisible(true);
271 assertTrue(mContentViewCore.hasSelection()); 281 assertTrue(mContentViewCore.hasSelection());
272 assertNotNull(mContentViewCore.getSelectActionHandler()); 282 assertNotNull(mContentViewCore.getSelectActionHandler());
273 selectActionBarCopy(); 283 selectActionBarCopy();
274 // Copy option won't be there for Password, hence no change in Clipboard 284 // Copy option won't be there for Password, hence no change in Clipboard
275 // Validating with previous Clipboard content 285 // Validating with previous Clipboard content
276 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne"); 286 assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextO ne");
277 } 287 }
278 288
289 @SmallTest
290 @Feature({"TextInput"})
291 public void testSelectActionBarTextAreaCopy() throws Exception {
292 DOMUtils.longPressNode(this, mContentViewCore, "textarea");
293 assertWaitForSelectActionBarVisible(true);
294 assertTrue(mContentViewCore.hasSelection());
295 assertNotNull(mContentViewCore.getSelectActionHandler());
296 selectActionBarCopy();
297 assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea") ;
298 }
299
300 @SmallTest
301 @Feature({"TextSelection"})
302 public void testSelectActionBarPlainTextCut() throws Exception {
303 copyStringToClipboard();
304 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
305 assertWaitForSelectActionBarVisible(true);
306 assertTrue(mContentViewCore.hasSelection());
307 assertEquals(mContentViewCore.getSelectedText(), "SamplePlainTextOne");
308 assertNotNull(mContentViewCore.getSelectActionHandler());
309 selectActionBarCut();
310 assertWaitForSelectActionBarVisible(true);
311 assertTrue(mContentViewCore.hasSelection());
312 // Cut option won't be available for plain text.
313 // Hence validating previous Clipboard content.
314 assertClipboardContents(mContentViewCore.getContext(), "SampleTextToCopy ");
315 }
316
317 @SmallTest
318 @Feature({"TextInput"})
319 public void testSelectActionBarInputCut() throws Exception {
320 DOMUtils.longPressNode(this, mContentViewCore, "input_text");
321 assertWaitForSelectActionBarVisible(true);
322 assertTrue(mContentViewCore.hasSelection());
323 assertEquals(mContentViewCore.getSelectedText(), "SampleInputText");
324 assertNotNull(mContentViewCore.getSelectActionHandler());
325 selectActionBarCut();
326 assertWaitForSelectActionBarVisible(false);
327 assertFalse(mContentViewCore.hasSelection());
328 assertClipboardContents(mContentViewCore.getContext(), "SampleInputText" );
329 assertEquals(mContentViewCore.getSelectedText(), "");
330 }
331
332 @SmallTest
333 @Feature({"TextInput"})
334 public void testSelectActionBarPasswordCut() throws Exception {
335 copyStringToClipboard();
336 DOMUtils.longPressNode(this, mContentViewCore, "input_password");
337 assertWaitForSelectActionBarVisible(true);
338 assertTrue(mContentViewCore.hasSelection());
339 assertNotNull(mContentViewCore.getSelectActionHandler());
340 selectActionBarCut();
341 assertWaitForSelectActionBarVisible(true);
342 assertTrue(mContentViewCore.hasSelection());
343 // Cut option won't be there for Password, hence no change in Clipboard
344 // Validating with previous Clipboard content
345 assertClipboardContents(mContentViewCore.getContext(), "SampleTextToCopy ");
346 }
347
348 @SmallTest
349 @Feature({"TextInput"})
350 public void testSelectActionBarTextAreaCut() throws Exception {
351 DOMUtils.longPressNode(this, mContentViewCore, "textarea");
352 assertWaitForSelectActionBarVisible(true);
353 assertTrue(mContentViewCore.hasSelection());
354 assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea");
355 assertNotNull(mContentViewCore.getSelectActionHandler());
356 selectActionBarCut();
357 assertWaitForSelectActionBarVisible(false);
358 assertFalse(mContentViewCore.hasSelection());
359 assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea") ;
360 assertEquals(mContentViewCore.getSelectedText(), "");
361 }
362
363 @SmallTest
364 @Feature({"TextSelection"})
365 public void testSelectActionBarPlainTextSelectAll() throws Exception {
366 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
367 assertWaitForSelectActionBarVisible(true);
368 assertTrue(mContentViewCore.hasSelection());
369 assertNotNull(mContentViewCore.getSelectActionHandler());
370 selectActionBarSelectAll();
371 assertTrue(mContentViewCore.hasSelection());
372 assertWaitForSelectActionBarVisible(true);
373 }
374
375 @SmallTest
376 @Feature({"TextInput"})
377 public void testSelectActionBarInputSelectAll() throws Exception {
378 DOMUtils.longPressNode(this, mContentViewCore, "input_text");
379 assertWaitForSelectActionBarVisible(true);
380 assertTrue(mContentViewCore.hasSelection());
381 assertNotNull(mContentViewCore.getSelectActionHandler());
382 selectActionBarSelectAll();
383 assertTrue(mContentViewCore.hasSelection());
384 assertWaitForSelectActionBarVisible(true);
385 assertEquals(mContentViewCore.getSelectedText(), "SampleInputText");
386 }
387
388 @SmallTest
389 @Feature({"TextInput"})
390 public void testSelectActionBarPasswordSelectAll() throws Exception {
391 DOMUtils.longPressNode(this, mContentViewCore, "input_password");
392 assertWaitForSelectActionBarVisible(true);
393 assertTrue(mContentViewCore.hasSelection());
394 assertNotNull(mContentViewCore.getSelectActionHandler());
395 selectActionBarSelectAll();
396 assertTrue(mContentViewCore.hasSelection());
397 assertWaitForSelectActionBarVisible(true);
jdduke (slow) 2014/10/31 17:39:41 Don't you also want to assert that getSelectedText
AKVT 2014/10/31 17:52:09 Actually selected text we can't validate positivel
jdduke (slow) 2014/10/31 17:57:06 Hmm, nah this is OK.
398 }
399
400 @SmallTest
401 @Feature({"TextInput"})
402 public void testSelectActionBarTextAreaSelectAll() throws Exception {
403 DOMUtils.longPressNode(this, mContentViewCore, "textarea");
404 assertWaitForSelectActionBarVisible(true);
405 assertTrue(mContentViewCore.hasSelection());
406 assertNotNull(mContentViewCore.getSelectActionHandler());
407 selectActionBarSelectAll();
408 assertTrue(mContentViewCore.hasSelection());
409 assertWaitForSelectActionBarVisible(true);
410 assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea");
411 }
412
413 @SmallTest
414 @Feature({"TextSelection"})
415 public void testSelectActionBarPlainTextPaste() throws Exception {
416 copyStringToClipboard();
417 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
418 assertWaitForSelectActionBarVisible(true);
419 assertTrue(mContentViewCore.hasSelection());
420 assertNotNull(mContentViewCore.getSelectActionHandler());
421 selectActionBarPaste();
422 DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
423 assertWaitForSelectActionBarVisible(true);
424 assertTrue(mContentViewCore.hasSelection());
425 // Paste option won't be available for plain text.
426 // Hence content won't be changed.
427 assertNotSame(mContentViewCore.getSelectedText(), "SampleTextToCopy");
428 }
429
430 @SmallTest
431 @Feature({"TextInput"})
432 public void testSelectActionBarInputPaste() throws Exception {
433 copyStringToClipboard();
434 DOMUtils.longPressNode(this, mContentViewCore, "input_text");
435 assertWaitForSelectActionBarVisible(true);
436 assertTrue(mContentViewCore.hasSelection());
437 assertNotNull(mContentViewCore.getSelectActionHandler());
438 selectActionBarPaste();
439 DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
440 DOMUtils.longPressNode(this, mContentViewCore, "input_text");
441 assertWaitForSelectActionBarVisible(true);
442 assertTrue(mContentViewCore.hasSelection());
443 assertEquals(mContentViewCore.getSelectedText(), "SampleTextToCopy");
444 }
445
446 @SmallTest
447 @Feature({"TextInput"})
448 public void testSelectActionBarPasswordPaste() throws Exception {
449 copyStringToClipboard();
450 DOMUtils.longPressNode(this, mContentViewCore, "input_password");
451 assertWaitForSelectActionBarVisible(true);
452 assertTrue(mContentViewCore.hasSelection());
453 assertNotNull(mContentViewCore.getSelectActionHandler());
454 selectActionBarPaste();
455 // Paste option won't be there for Password, hence no action happens
jdduke (slow) 2014/10/31 17:39:41 This comment is misleading (as are several others)
AKVT 2014/10/31 17:52:09 My intention is even if we call paste, expected ac
456 DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
457 DOMUtils.longPressNode(this, mContentViewCore, "input_password");
458 assertWaitForSelectActionBarVisible(true);
459 assertTrue(mContentViewCore.hasSelection());
460 assertNotSame(mContentViewCore.getSelectedText(), "SampleTextToCopy");
461 }
462
463 @SmallTest
464 @Feature({"TextInput"})
465 public void testSelectActionBarTextAreaPaste() throws Exception {
466 copyStringToClipboard();
467 DOMUtils.longPressNode(this, mContentViewCore, "textarea");
468 assertWaitForSelectActionBarVisible(true);
469 assertTrue(mContentViewCore.hasSelection());
470 assertNotNull(mContentViewCore.getSelectActionHandler());
471 selectActionBarPaste();
472 DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
473 DOMUtils.longPressNode(this, mContentViewCore, "textarea");
474 assertWaitForSelectActionBarVisible(true);
475 assertTrue(mContentViewCore.hasSelection());
476 assertEquals(mContentViewCore.getSelectedText(), "SampleTextToCopy");
477 }
478
479 private void selectActionBarPaste() {
480 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
481 @Override
482 public void run() {
483 mContentViewCore.getSelectActionHandler().paste();
484 }
485 });
486 }
487
488 private void selectActionBarSelectAll() {
489 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
490 @Override
491 public void run() {
492 mContentViewCore.getSelectActionHandler().selectAll();
493 }
494 });
495 }
496
497 private void selectActionBarCut() {
498 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
499 @Override
500 public void run() {
501 mContentViewCore.getSelectActionHandler().cut();
jdduke (slow) 2014/10/31 17:39:41 The biggest problem I have with these tests is tha
AKVT 2014/10/31 17:52:09 IMO, even though we have a SelectActionModeCallbac
502 }
503 });
504 }
505
279 private void selectActionBarCopy() { 506 private void selectActionBarCopy() {
280 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 507 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
281 @Override 508 @Override
282 public void run() { 509 public void run() {
283 mContentViewCore.getSelectActionHandler().copy(); 510 mContentViewCore.getSelectActionHandler().copy();
284 } 511 }
285 }); 512 });
286 } 513 }
287 514
288 private void assertClipboardContents(final Context context, final String exp ectedContents) 515 private void assertClipboardContents(final Context context, final String exp ectedContents)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 private void requestFocusOnUiThread(final boolean gainFocus) { 573 private void requestFocusOnUiThread(final boolean gainFocus) {
347 final ContentViewCore contentViewCore = mContentViewCore; 574 final ContentViewCore contentViewCore = mContentViewCore;
348 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 575 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
349 @Override 576 @Override
350 public void run() { 577 public void run() {
351 contentViewCore.onFocusChanged(gainFocus); 578 contentViewCore.onFocusChanged(gainFocus);
352 } 579 }
353 }); 580 });
354 } 581 }
355 582
356 private void copyStringToClipboard() { 583 private void copyStringToClipboard() {
jdduke (slow) 2014/10/31 17:39:41 Could you make this function take a string, so it'
AKVT 2014/10/31 17:52:09 Done.
357 ClipboardManager clipboardManager = 584 ClipboardManager clipboardManager =
358 (ClipboardManager) getActivity().getSystemService( 585 (ClipboardManager) getActivity().getSystemService(
359 Context.CLIPBOARD_SERVICE); 586 Context.CLIPBOARD_SERVICE);
360 ClipData clip = ClipData.newPlainText("test", "Text to copy"); 587 ClipData clip = ClipData.newPlainText("test", "SampleTextToCopy");
361 clipboardManager.setPrimaryClip(clip); 588 clipboardManager.setPrimaryClip(clip);
362 } 589 }
363 590
364 private void assertWaitForPastePopupStatus(final boolean show) throws Interr uptedException { 591 private void assertWaitForPastePopupStatus(final boolean show) throws Interr uptedException {
365 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { 592 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
366 @Override 593 @Override
367 public boolean isSatisfied() { 594 public boolean isSatisfied() {
368 return show == mContentViewCore.getPastePopupForTest().isShowing (); 595 return show == mContentViewCore.getPastePopupForTest().isShowing ();
369 } 596 }
370 })); 597 }));
371 } 598 }
372 } 599 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698