Example #1
0
  @SmallTest
  @Feature({"TextInput", "Main"})
  public void testAccentKeyCodesFromPhysicalKeyboard() throws Throwable {
    DOMUtils.focusNode(mWebContents, "textarea");
    assertWaitForKeyboardStatus(true);

    // The calls below are a reflection of what a physical keyboard sends when the noted
    // key is pressed on the device.  Exercise care when altering to make sure that the test
    // reflects reality.
    mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
    waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);

    // H
    dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_H));
    dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_H));
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // I
    dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I));
    dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I));
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));

    // ALT-I  (circomflex accent key on virtual keyboard)
    dispatchKeyEvent(
        mConnection,
        new KeyEvent(0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I, 0, KeyEvent.META_ALT_ON));
    dispatchKeyEvent(
        mConnection,
        new KeyEvent(0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I, 0, KeyEvent.META_ALT_ON));
    assertEquals("hiˆ", mConnection.getTextBeforeCursor(9, 0));

    // O  (accented key)
    dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_O));
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));
    dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_O));
    assertEquals("hiô", mConnection.getTextBeforeCursor(9, 0));
  }
Example #2
0
  /*
  @SmallTest
  @Feature({"TextInput", "Main"})
  http://crbug.com/445499
  */
  @DisabledTest
  public void testKeyCodesWhileSwipingText() throws Throwable {
    DOMUtils.focusNode(mWebContents, "textarea");
    assertWaitForKeyboardStatus(true);

    // The calls below are a reflection of what the stock Google Keyboard (Android 4.4) sends
    // when the word is swiped on the soft keyboard.  Exercise care when altering to make sure
    // that the test reflects reality.  If this test breaks, it's possible that code has
    // changed and different calls need to be made instead.
    mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
    waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);

    // "three"
    expectUpdateStateCall(mConnection);
    setComposingText(mConnection, "three", 1);
    assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode);
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("three", mConnection.getTextBeforeCursor(99, 0));

    // "word"
    commitText(mConnection, "three", 1);
    commitText(mConnection, " ", 1);
    expectUpdateStateCall(mConnection);
    setComposingText(mConnection, "word", 1);
    assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode);
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("three word", mConnection.getTextBeforeCursor(99, 0));

    // "test"
    commitText(mConnection, "word", 1);
    commitText(mConnection, " ", 1);
    expectUpdateStateCall(mConnection);
    setComposingText(mConnection, "test", 1);
    assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode);
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("three word test", mConnection.getTextBeforeCursor(99, 0));
  }
Example #3
0
  @SmallTest
  @Feature({"TextInput", "Main"})
  public void testKeyCodesWhileTypingText() throws Throwable {
    DOMUtils.focusNode(mWebContents, "textarea");
    assertWaitForKeyboardStatus(true);

    // The calls below are a reflection of what the Hacker's Keyboard sends when the noted
    // key is touched on screen.  Exercise care when altering to make sure that the test
    // reflects reality.
    mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
    waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);

    // H
    expectUpdateStateCall(mConnection);
    commitText(mConnection, "h", 1);
    assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // O
    expectUpdateStateCall(mConnection);
    commitText(mConnection, "o", 1);
    assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("ho", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("ho", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    expectUpdateStateCall(mConnection);
    deleteSurroundingText(mConnection, 1, 0);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // I
    expectUpdateStateCall(mConnection);
    commitText(mConnection, "i", 1);
    assertEquals(KeyEvent.KEYCODE_I, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));

    // SPACE
    expectUpdateStateCall(mConnection);
    commitText(mConnection, " ", 1);
    assertEquals(KeyEvent.KEYCODE_SPACE, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    expectUpdateStateCall(mConnection);
    deleteSurroundingText(mConnection, 1, 0);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    expectUpdateStateCall(mConnection);
    deleteSurroundingText(mConnection, 1, 0);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    expectUpdateStateCall(mConnection);
    deleteSurroundingText(mConnection, 1, 0);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("", mConnection.getTextBeforeCursor(9, 0));
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("", mConnection.getTextBeforeCursor(9, 0));

    // DEL (on empty input)
    deleteSurroundingText(mConnection, 1, 0); // DEL on empty still sends 1,0
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("", mConnection.getTextBeforeCursor(9, 0));
  }
Example #4
0
  /*
  @SmallTest
  @Feature({"TextInput", "Main"})
  http://crbug.com/445499
  */
  @DisabledTest
  public void testKeyCodesWhileComposingText() throws Throwable {
    DOMUtils.focusNode(mWebContents, "textarea");
    assertWaitForKeyboardStatus(true);

    // The calls below are a reflection of what the stock Google Keyboard (Android 4.4) sends
    // when the noted key is touched on screen.  Exercise care when altering to make sure
    // that the test reflects reality.  If this test breaks, it's possible that code has
    // changed and different calls need to be made instead.
    mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
    waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);

    // H
    expectUpdateStateCall(mConnection);
    setComposingText(mConnection, "h", 1);
    assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode);
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // O
    expectUpdateStateCall(mConnection);
    setComposingText(mConnection, "ho", 1);
    assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode);
    assertUpdateStateCall(mConnection, 1000);
    assertEquals("ho", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    expectUpdateStateCall(mConnection);
    setComposingText(mConnection, "h", 1);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertUpdateStateCall(mConnection, 1000);
    setComposingRegion(mConnection, 0, 1); // DEL calls cancelComposition() then restarts
    setComposingText(mConnection, "h", 1);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // I
    setComposingText(mConnection, "hi", 1);
    assertEquals(KeyEvent.KEYCODE_I, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));

    // SPACE
    commitText(mConnection, "hi", 1);
    assertEquals(-1, mImeAdapter.mLastSyntheticKeyCode);
    commitText(mConnection, " ", 1);
    assertEquals(KeyEvent.KEYCODE_SPACE, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    deleteSurroundingText(mConnection, 1, 0);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    setComposingRegion(mConnection, 0, 2);
    assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    setComposingText(mConnection, "h", 1);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("h", mConnection.getTextBeforeCursor(9, 0));

    // DEL
    commitText(mConnection, "", 1);
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("", mConnection.getTextBeforeCursor(9, 0));

    // DEL (on empty input)
    deleteSurroundingText(mConnection, 1, 0); // DEL on empty still sends 1,0
    assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode);
    assertEquals("", mConnection.getTextBeforeCursor(9, 0));
  }