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

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

Issue 759033002: Handle accent keys from physical keyboards. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed review comments and moved common dead-key code to public static method Created 6 years 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 | « content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java ('k') | 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 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
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 assertUpdateStateCall(mConnection, 1000);
626 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0));
627 dispatchKeyEvent(mConnection, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent. KEYCODE_O));
628 assertEquals("hiô", mConnection.getTextBeforeCursor(9, 0));
629 }
630
631 @SmallTest
632 @Feature({"TextInput", "Main"})
594 public void testSetComposingRegionOutOfBounds() throws Throwable { 633 public void testSetComposingRegionOutOfBounds() throws Throwable {
595 DOMUtils.focusNode(mWebContents, "textarea"); 634 DOMUtils.focusNode(mWebContents, "textarea");
596 assertWaitForKeyboardStatus(true); 635 assertWaitForKeyboardStatus(true);
597 636
598 mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); 637 mConnection = (TestAdapterInputConnection) getAdapterInputConnection();
599 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1); 638 waitAndVerifyEditableCallback(mConnection.mImeUpdateQueue, 0, "", 0, 0, -1, -1);
600 setComposingText(mConnection, "hello", 1); 639 setComposingText(mConnection, "hello", 1);
601 640
602 setComposingRegion(mConnection, 0, 0); 641 setComposingRegion(mConnection, 0, 0);
603 setComposingRegion(mConnection, 0, 9); 642 setComposingRegion(mConnection, 0, 9);
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
902 private void deleteSurroundingText(final AdapterInputConnection connection, final int before, 941 private void deleteSurroundingText(final AdapterInputConnection connection, final int before,
903 final int after) { 942 final int after) {
904 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 943 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
905 @Override 944 @Override
906 public void run() { 945 public void run() {
907 connection.deleteSurroundingText(before, after); 946 connection.deleteSurroundingText(before, after);
908 } 947 }
909 }); 948 });
910 } 949 }
911 950
951 private void dispatchKeyEvent(final AdapterInputConnection connection, final KeyEvent event) {
952 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
953 @Override
954 public void run() {
955 mImeAdapter.dispatchKeyEvent(event);
956 }
957 });
958 }
959
912 private static class TestAdapterInputConnectionFactory extends 960 private static class TestAdapterInputConnectionFactory extends
913 ImeAdapter.AdapterInputConnectionFactory { 961 ImeAdapter.AdapterInputConnectionFactory {
914 @Override 962 @Override
915 public AdapterInputConnection get(View view, ImeAdapter imeAdapter, 963 public AdapterInputConnection get(View view, ImeAdapter imeAdapter,
916 Editable editable, EditorInfo outAttrs) { 964 Editable editable, EditorInfo outAttrs) {
917 return new TestAdapterInputConnection(view, imeAdapter, editable, ou tAttrs); 965 return new TestAdapterInputConnection(view, imeAdapter, editable, ou tAttrs);
918 } 966 }
919 } 967 }
920 968
921 private static class TestAdapterInputConnection extends AdapterInputConnecti on { 969 private static class TestAdapterInputConnection extends AdapterInputConnecti on {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 public void assertEqualState(String text, int selectionStart, int select ionEnd, 1003 public void assertEqualState(String text, int selectionStart, int select ionEnd,
956 int compositionStart, int compositionEnd) { 1004 int compositionStart, int compositionEnd) {
957 assertEquals("Text did not match", text, mText); 1005 assertEquals("Text did not match", text, mText);
958 assertEquals("Selection start did not match", selectionStart, mSelec tionStart); 1006 assertEquals("Selection start did not match", selectionStart, mSelec tionStart);
959 assertEquals("Selection end did not match", selectionEnd, mSelection End); 1007 assertEquals("Selection end did not match", selectionEnd, mSelection End);
960 assertEquals("Composition start did not match", compositionStart, mC ompositionStart); 1008 assertEquals("Composition start did not match", compositionStart, mC ompositionStart);
961 assertEquals("Composition end did not match", compositionEnd, mCompo sitionEnd); 1009 assertEquals("Composition end did not match", compositionEnd, mCompo sitionEnd);
962 } 1010 }
963 } 1011 }
964 } 1012 }
OLDNEW
« no previous file with comments | « content/public/android/java/src/org/chromium/content/browser/input/ImeAdapter.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698