@SmallTest
 @Feature({"TextInput"})
 public void testActionBarConfiguredCorrectlyForTextArea() throws Throwable {
   DOMUtils.longPressNode(this, mContentViewCore, "textarea");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   assertTrue(mContentViewCore.getSelectActionHandler().isSelectionEditable());
   assertFalse(mContentViewCore.getSelectActionHandler().isSelectionPassword());
 }
  @SmallTest
  @Feature({"TextInput"})
  public void testSelectActionBarPasswordPaste() throws Exception {
    copyStringToClipboard("SamplePassword2");

    // Select the password field.
    DOMUtils.longPressNode(this, mContentViewCore, "input_password");
    assertWaitForSelectActionBarVisible(true);
    assertTrue(mContentViewCore.hasSelection());
    assertEquals(mContentViewCore.getSelectedText().length(), "SamplePassword".length());

    // Paste "SamplePassword2" into the password field, replacing
    // "SamplePassword".
    assertNotNull(mContentViewCore.getSelectActionHandler());
    selectActionBarPaste();
    assertWaitForSelectActionBarVisible(false);
    assertFalse(mContentViewCore.hasSelection());

    // Ensure the new text matches the pasted text. Note that we can't
    // actually compare strings as password field selections only provide
    // a placeholder with the correct length.
    DOMUtils.longPressNode(this, mContentViewCore, "input_password");
    assertWaitForSelectActionBarVisible(true);
    assertTrue(mContentViewCore.hasSelection());
    assertEquals(mContentViewCore.getSelectedText().length(), "SamplePassword2".length());
  }
 @SmallTest
 @Feature({"TextSelection", "TextInput"})
 public void testCursorPositionAfterHidingActionMode() throws Exception {
   DOMUtils.longPressNode(this, mContentViewCore, "textarea");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarSelectAll();
   assertTrue(mContentViewCore.hasSelection());
   assertWaitForSelectActionBarVisible(true);
   assertEquals(mContentViewCore.getSelectedText(), "SampleTextArea");
   hideSelectActionMode();
   assertWaitForSelectActionBarVisible(false);
   assertTrue(
       CriteriaHelper.pollForUIThreadCriteria(
           new Criteria() {
             @Override
             public boolean isSatisfied() {
               return "SampleTextArea"
                   .equals(
                       mContentViewCore
                           .getImeAdapterForTest()
                           .getInputConnectionForTest()
                           .getTextBeforeCursor(50, 0));
             }
           }));
 }
 @SmallTest
 @Feature({"TextInput"})
 public void testSelectActionBarPasswordCopy() throws Exception {
   DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarCopy();
   assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextOne");
   DOMUtils.longPressNode(this, mContentViewCore, "input_password");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarCopy();
   // Copy option won't be there for Password, hence no change in Clipboard
   // Validating with previous Clipboard content
   assertClipboardContents(mContentViewCore.getContext(), "SamplePlainTextOne");
 }
 @SmallTest
 @Feature({"TextInput"})
 public void testSelectActionBarTextAreaCopy() throws Exception {
   DOMUtils.longPressNode(this, mContentViewCore, "textarea");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarCopy();
   assertClipboardContents(mContentViewCore.getContext(), "SampleTextArea");
 }
 @SmallTest
 @Feature({"TextInput"})
 public void testSelectActionBarPasswordSelectAll() throws Exception {
   DOMUtils.longPressNode(this, mContentViewCore, "input_password");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarSelectAll();
   assertTrue(mContentViewCore.hasSelection());
   assertWaitForSelectActionBarVisible(true);
 }
 /** Disabled due to being flaky. crbug.com/552387 @SmallTest @Feature({"TextInput"}) */
 @DisabledTest
 public void testSelectActionBarInputPaste() throws Exception {
   copyStringToClipboard("SampleTextToCopy");
   DOMUtils.longPressNode(this, mContentViewCore, "input_text");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarPaste();
   DOMUtils.clickNode(this, mContentViewCore, "plain_text_1");
   DOMUtils.longPressNode(this, mContentViewCore, "input_text");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertEquals(mContentViewCore.getSelectedText(), "SampleTextToCopy");
 }
 @SmallTest
 @Feature({"TextInput"})
 public void testSelectActionBarInputCut() throws Exception {
   DOMUtils.longPressNode(this, mContentViewCore, "input_text");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertEquals(mContentViewCore.getSelectedText(), "SampleInputText");
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarCut();
   assertWaitForSelectActionBarVisible(false);
   assertFalse(mContentViewCore.hasSelection());
   assertClipboardContents(mContentViewCore.getContext(), "SampleInputText");
   assertEquals(mContentViewCore.getSelectedText(), "");
 }
  @SmallTest
  @Feature({"TextInput"})
  public void testSelectActionBarSearchAndShareLaunchesNewTask() throws Exception {
    DOMUtils.longPressNode(this, mContentViewCore, "textarea");
    assertWaitForSelectActionBarVisible(true);
    assertTrue(mContentViewCore.hasSelection());
    assertNotNull(mContentViewCore.getSelectActionHandler());
    selectActionBarSearch();
    Intent i = getActivity().getLastSentIntent();
    int new_task_flag = Intent.FLAG_ACTIVITY_NEW_TASK;
    assertEquals(i.getFlags() & new_task_flag, new_task_flag);

    selectActionBarShare();
    i = getActivity().getLastSentIntent();
    assertEquals(i.getFlags() & new_task_flag, new_task_flag);
  }
 @SmallTest
 @Feature({"TextSelection"})
 public void testSelectActionBarPlainTextPaste() throws Exception {
   copyStringToClipboard("SampleTextToCopy");
   DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarPaste();
   DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   // Paste option won't be available for plain text.
   // Hence content won't be changed.
   assertNotSame(mContentViewCore.getSelectedText(), "SampleTextToCopy");
 }
 @SmallTest
 @Feature({"TextSelection"})
 public void testSelectActionBarPlainTextCut() throws Exception {
   copyStringToClipboard("SampleTextToCopy");
   DOMUtils.longPressNode(this, mContentViewCore, "plain_text_1");
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   assertEquals(mContentViewCore.getSelectedText(), "SamplePlainTextOne");
   assertNotNull(mContentViewCore.getSelectActionHandler());
   selectActionBarCut();
   assertWaitForSelectActionBarVisible(true);
   assertTrue(mContentViewCore.hasSelection());
   // Cut option won't be available for plain text.
   // Hence validating previous Clipboard content.
   assertClipboardContents(mContentViewCore.getContext(), "SampleTextToCopy");
 }