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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | 695 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); |
696 | 696 |
697 // DEL (on empty input) | 697 // DEL (on empty input) |
698 deleteSurroundingText(mConnection, 1, 0); // DEL on empty still sends 1
,0 | 698 deleteSurroundingText(mConnection, 1, 0); // DEL on empty still sends 1
,0 |
699 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | 699 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); |
700 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | 700 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); |
701 } | 701 } |
702 | 702 |
703 @SmallTest | 703 @SmallTest |
704 @Feature({"TextInput", "Main"}) | 704 @Feature({"TextInput", "Main"}) |
| 705 public void testAccentKeyCodesFromPhysicalKeyboard() throws Throwable { |
| 706 DOMUtils.focusNode(mWebContents, "textarea"); |
| 707 assertWaitForKeyboardStatus(true); |
| 708 |
| 709 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); |
| 710 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0,
-1, -1); |
| 711 |
| 712 // h |
| 713 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_H)); |
| 714 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_H)); |
| 715 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 716 |
| 717 // ALT-i (circumflex accent key on virtual keyboard) |
| 718 dispatchKeyEvent( |
| 719 mConnection, new KeyEvent( |
| 720 0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I, 0, KeyEv
ent.META_ALT_ON)); |
| 721 assertUpdateStateCall(mConnection, 1000); |
| 722 assertEquals("hˆ", mConnection.getTextBeforeCursor(9, 0)); |
| 723 dispatchKeyEvent( |
| 724 mConnection, new KeyEvent( |
| 725 0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I, 0, KeyEven
t.META_ALT_ON)); |
| 726 assertEquals("hˆ", mConnection.getTextBeforeCursor(9, 0)); |
| 727 |
| 728 // o |
| 729 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_O)); |
| 730 assertUpdateStateCall(mConnection, 1000); |
| 731 assertEquals("hô", mConnection.getTextBeforeCursor(9, 0)); |
| 732 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_O)); |
| 733 assertEquals("hô", mConnection.getTextBeforeCursor(9, 0)); |
| 734 assertEquals(-1, mConnection.getComposingSpanEnd(mConnection.getEditable
())); |
| 735 |
| 736 // ALT-i |
| 737 dispatchKeyEvent( |
| 738 mConnection, new KeyEvent( |
| 739 0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I, 0, KeyEv
ent.META_ALT_ON)); |
| 740 assertUpdateStateCall(mConnection, 1000); |
| 741 dispatchKeyEvent( |
| 742 mConnection, new KeyEvent( |
| 743 0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I, 0, KeyEven
t.META_ALT_ON)); |
| 744 assertEquals("hôˆ", mConnection.getTextBeforeCursor(9, 0)); |
| 745 |
| 746 // ALT-i again should have no effect |
| 747 dispatchKeyEvent( |
| 748 mConnection, new KeyEvent( |
| 749 0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I, 0, KeyEv
ent.META_ALT_ON)); |
| 750 assertUpdateStateCall(mConnection, 1000); |
| 751 dispatchKeyEvent( |
| 752 mConnection, new KeyEvent( |
| 753 0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I, 0, KeyEven
t.META_ALT_ON)); |
| 754 assertEquals("hôˆ", mConnection.getTextBeforeCursor(9, 0)); |
| 755 |
| 756 // b (cannot be accented, should just appear after) |
| 757 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_B)); |
| 758 assertUpdateStateCall(mConnection, 1000); |
| 759 assertEquals("hôˆb", mConnection.getTextBeforeCursor(9, 0)); |
| 760 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_B)); |
| 761 assertEquals("hôˆb", mConnection.getTextBeforeCursor(9, 0)); |
| 762 assertEquals(-1, mConnection.getComposingSpanEnd(mConnection.getEditable
())); |
| 763 |
| 764 // ALT-i |
| 765 dispatchKeyEvent( |
| 766 mConnection, new KeyEvent( |
| 767 0, 0, KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I, 0, KeyEv
ent.META_ALT_ON)); |
| 768 assertUpdateStateCall(mConnection, 1000); |
| 769 dispatchKeyEvent( |
| 770 mConnection, new KeyEvent( |
| 771 0, 0, KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I, 0, KeyEven
t.META_ALT_ON)); |
| 772 assertEquals("hôˆbˆ", mConnection.getTextBeforeCursor(9, 0)); |
| 773 |
| 774 // Backspace |
| 775 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEven
t.KEYCODE_DEL)); |
| 776 assertUpdateStateCall(mConnection, 1000); |
| 777 assertEquals("hôˆb", mConnection.getTextBeforeCursor(9, 0)); |
| 778 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.
KEYCODE_DEL)); |
| 779 assertEquals("hôˆb", mConnection.getTextBeforeCursor(9, 0)); |
| 780 assertEquals(-1, mConnection.getComposingSpanEnd(mConnection.getEditable
())); |
| 781 } |
| 782 |
| 783 @SmallTest |
| 784 @Feature({"TextInput", "Main"}) |
705 public void testSetComposingRegionOutOfBounds() throws Throwable { | 785 public void testSetComposingRegionOutOfBounds() throws Throwable { |
706 DOMUtils.focusNode(mWebContents, "textarea"); | 786 DOMUtils.focusNode(mWebContents, "textarea"); |
707 assertWaitForKeyboardStatus(true); | 787 assertWaitForKeyboardStatus(true); |
708 | 788 |
709 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); | 789 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); |
710 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0,
-1, -1); | 790 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0,
-1, -1); |
711 setComposingText(mConnection, "hello", 1); | 791 setComposingText(mConnection, "hello", 1); |
712 | 792 |
713 setComposingRegion(mConnection, 0, 0); | 793 setComposingRegion(mConnection, 0, 0); |
714 setComposingRegion(mConnection, 0, 9); | 794 setComposingRegion(mConnection, 0, 9); |
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1049 private void deleteSurroundingText(final AdapterInputConnection connection,
final int before, | 1129 private void deleteSurroundingText(final AdapterInputConnection connection,
final int before, |
1050 final int after) { | 1130 final int after) { |
1051 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 1131 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
1052 @Override | 1132 @Override |
1053 public void run() { | 1133 public void run() { |
1054 connection.deleteSurroundingText(before, after); | 1134 connection.deleteSurroundingText(before, after); |
1055 } | 1135 } |
1056 }); | 1136 }); |
1057 } | 1137 } |
1058 | 1138 |
| 1139 private void dispatchKeyEvent(final AdapterInputConnection connection, final
KeyEvent event) { |
| 1140 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 1141 @Override |
| 1142 public void run() { |
| 1143 mImeAdapter.dispatchKeyEvent(event); |
| 1144 } |
| 1145 }); |
| 1146 } |
| 1147 |
1059 private static class TestAdapterInputConnectionFactory extends | 1148 private static class TestAdapterInputConnectionFactory extends |
1060 ImeAdapter.AdapterInputConnectionFactory { | 1149 ImeAdapter.AdapterInputConnectionFactory { |
1061 @Override | 1150 @Override |
1062 public AdapterInputConnection get(View view, ImeAdapter imeAdapter, | 1151 public AdapterInputConnection get(View view, ImeAdapter imeAdapter, |
1063 Editable editable, EditorInfo outAttrs) { | 1152 Editable editable, EditorInfo outAttrs) { |
1064 return new TestAdapterInputConnection(view, imeAdapter, editable, ou
tAttrs); | 1153 return new TestAdapterInputConnection(view, imeAdapter, editable, ou
tAttrs); |
1065 } | 1154 } |
1066 } | 1155 } |
1067 | 1156 |
1068 private static class TestAdapterInputConnection extends AdapterInputConnecti
on { | 1157 private static class TestAdapterInputConnection extends AdapterInputConnecti
on { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 public void assertEqualState(String text, int selectionStart, int select
ionEnd, | 1191 public void assertEqualState(String text, int selectionStart, int select
ionEnd, |
1103 int compositionStart, int compositionEnd) { | 1192 int compositionStart, int compositionEnd) { |
1104 assertEquals("Text did not match", text, mText); | 1193 assertEquals("Text did not match", text, mText); |
1105 assertEquals("Selection start did not match", selectionStart, mSelec
tionStart); | 1194 assertEquals("Selection start did not match", selectionStart, mSelec
tionStart); |
1106 assertEquals("Selection end did not match", selectionEnd, mSelection
End); | 1195 assertEquals("Selection end did not match", selectionEnd, mSelection
End); |
1107 assertEquals("Composition start did not match", compositionStart, mC
ompositionStart); | 1196 assertEquals("Composition start did not match", compositionStart, mC
ompositionStart); |
1108 assertEquals("Composition end did not match", compositionEnd, mCompo
sitionEnd); | 1197 assertEquals("Composition end did not match", compositionEnd, mCompo
sitionEnd); |
1109 } | 1198 } |
1110 } | 1199 } |
1111 } | 1200 } |
OLD | NEW |