OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.input; | 5 package org.chromium.content.browser.input; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.ClipData; | 8 import android.content.ClipData; |
9 import android.content.ClipboardManager; | 9 import android.content.ClipboardManager; |
10 import android.content.Context; | 10 import android.content.Context; |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | 584 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); |
585 | 585 |
586 // DEL (on empty input) | 586 // DEL (on empty input) |
587 deleteSurroundingText(mConnection, 1, 0); // DEL on empty still sends 1
,0 | 587 deleteSurroundingText(mConnection, 1, 0); // DEL on empty still sends 1
,0 |
588 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | 588 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); |
589 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | 589 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); |
590 } | 590 } |
591 | 591 |
592 @SmallTest | 592 @SmallTest |
593 @Feature({"TextInput", "Main"}) | 593 @Feature({"TextInput", "Main"}) |
| 594 public void testAccentKeyCodesFromPhysicalKeyboard() throws Throwable { |
| 595 DOMUtils.focusNode(mWebContents, "textarea"); |
| 596 assertWaitForKeyboardStatus(true); |
| 597 |
| 598 // The calls below are a reflection of what a physical keyboard sends wh
en the noted |
| 599 // key is pressed on the device. Exercise care when altering to make su
re that the test |
| 600 // reflects reality. |
| 601 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); |
| 602 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0,
-1, -1); |
| 603 |
| 604 // H |
| 605 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_H)); |
| 606 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_H)); |
| 607 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 608 |
| 609 // I |
| 610 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_I)); |
| 611 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_I)); |
| 612 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); |
| 613 |
| 614 // ALT-I (circomflex accent key on virtual keyboard) |
| 615 dispatchKeyEvent( |
| 616 mConnection, new KeyEvent( |
| 617 0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I, 0, KeyEv
ent.META_ALT_ON)); |
| 618 dispatchKeyEvent( |
| 619 mConnection, new KeyEvent( |
| 620 0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I, 0, KeyEven
t.META_ALT_ON)); |
| 621 assertEquals("hiˆ", mConnection.getTextBeforeCursor(9, 0)); |
| 622 |
| 623 // O (accented key) |
| 624 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_O)); |
| 625 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); |
| 626 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_O)); |
| 627 assertEquals("hiô", mConnection.getTextBeforeCursor(9, 0)); |
| 628 } |
| 629 |
| 630 @SmallTest |
| 631 @Feature({"TextInput", "Main"}) |
594 public void testSetComposingRegionOutOfBounds() throws Throwable { | 632 public void testSetComposingRegionOutOfBounds() throws Throwable { |
595 DOMUtils.focusNode(mWebContents, "textarea"); | 633 DOMUtils.focusNode(mWebContents, "textarea"); |
596 assertWaitForKeyboardStatus(true); | 634 assertWaitForKeyboardStatus(true); |
597 | 635 |
598 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); | 636 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); |
599 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0,
-1, -1); | 637 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0,
-1, -1); |
600 setComposingText(mConnection, "hello", 1); | 638 setComposingText(mConnection, "hello", 1); |
601 | 639 |
602 setComposingRegion(mConnection, 0, 0); | 640 setComposingRegion(mConnection, 0, 0); |
603 setComposingRegion(mConnection, 0, 9); | 641 setComposingRegion(mConnection, 0, 9); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
902 private void deleteSurroundingText(final AdapterInputConnection connection,
final int before, | 940 private void deleteSurroundingText(final AdapterInputConnection connection,
final int before, |
903 final int after) { | 941 final int after) { |
904 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 942 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
905 @Override | 943 @Override |
906 public void run() { | 944 public void run() { |
907 connection.deleteSurroundingText(before, after); | 945 connection.deleteSurroundingText(before, after); |
908 } | 946 } |
909 }); | 947 }); |
910 } | 948 } |
911 | 949 |
| 950 private void dispatchKeyEvent(final AdapterInputConnection connection, final
KeyEvent event) { |
| 951 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 952 @Override |
| 953 public void run() { |
| 954 mImeAdapter.dispatchKeyEvent(event); |
| 955 } |
| 956 }); |
| 957 } |
| 958 |
912 private static class TestAdapterInputConnectionFactory extends | 959 private static class TestAdapterInputConnectionFactory extends |
913 ImeAdapter.AdapterInputConnectionFactory { | 960 ImeAdapter.AdapterInputConnectionFactory { |
914 @Override | 961 @Override |
915 public AdapterInputConnection get(View view, ImeAdapter imeAdapter, | 962 public AdapterInputConnection get(View view, ImeAdapter imeAdapter, |
916 Editable editable, EditorInfo outAttrs) { | 963 Editable editable, EditorInfo outAttrs) { |
917 return new TestAdapterInputConnection(view, imeAdapter, editable, ou
tAttrs); | 964 return new TestAdapterInputConnection(view, imeAdapter, editable, ou
tAttrs); |
918 } | 965 } |
919 } | 966 } |
920 | 967 |
921 private static class TestAdapterInputConnection extends AdapterInputConnecti
on { | 968 private static class TestAdapterInputConnection extends AdapterInputConnecti
on { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 public void assertEqualState(String text, int selectionStart, int select
ionEnd, | 1002 public void assertEqualState(String text, int selectionStart, int select
ionEnd, |
956 int compositionStart, int compositionEnd) { | 1003 int compositionStart, int compositionEnd) { |
957 assertEquals("Text did not match", text, mText); | 1004 assertEquals("Text did not match", text, mText); |
958 assertEquals("Selection start did not match", selectionStart, mSelec
tionStart); | 1005 assertEquals("Selection start did not match", selectionStart, mSelec
tionStart); |
959 assertEquals("Selection end did not match", selectionEnd, mSelection
End); | 1006 assertEquals("Selection end did not match", selectionEnd, mSelection
End); |
960 assertEquals("Composition start did not match", compositionStart, mC
ompositionStart); | 1007 assertEquals("Composition start did not match", compositionStart, mC
ompositionStart); |
961 assertEquals("Composition end did not match", compositionEnd, mCompo
sitionEnd); | 1008 assertEquals("Composition end did not match", compositionEnd, mCompo
sitionEnd); |
962 } | 1009 } |
963 } | 1010 } |
964 } | 1011 } |
OLD | NEW |