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

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

Issue 1403453002: Delete best-effort keycode guessing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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
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.content.Context; 7 import android.content.Context;
8 import android.os.IBinder; 8 import android.os.IBinder;
9 import android.os.ResultReceiver; 9 import android.os.ResultReceiver;
10 import android.test.suitebuilder.annotation.MediumTest; 10 import android.test.suitebuilder.annotation.MediumTest;
11 import android.test.suitebuilder.annotation.SmallTest; 11 import android.test.suitebuilder.annotation.SmallTest;
12 import android.text.Editable; 12 import android.text.Editable;
13 import android.text.Selection; 13 import android.text.Selection;
14 import android.view.KeyEvent;
15 import android.view.View; 14 import android.view.View;
16 import android.view.inputmethod.BaseInputConnection; 15 import android.view.inputmethod.BaseInputConnection;
17 import android.view.inputmethod.EditorInfo; 16 import android.view.inputmethod.EditorInfo;
18 17
19 import org.chromium.base.test.util.Feature; 18 import org.chromium.base.test.util.Feature;
20 import org.chromium.content.browser.input.AdapterInputConnection.ImeState; 19 import org.chromium.content.browser.input.AdapterInputConnection.ImeState;
21 import org.chromium.content.browser.input.ImeAdapter.ImeAdapterDelegate; 20 import org.chromium.content.browser.input.ImeAdapter.ImeAdapterDelegate;
22 import org.chromium.content_shell_apk.ContentShellTestBase; 21 import org.chromium.content_shell_apk.ContentShellTestBase;
23 22
24 import java.util.ArrayList; 23 import java.util.ArrayList;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 mConnection.endBatchEdit(); 98 mConnection.endBatchEdit();
100 mConnection.setComposingText("test", 1); 99 mConnection.setComposingText("test", 1);
101 assertEquals(0, mWrapper.getUpdateSelectionCallCount()); 100 assertEquals(0, mWrapper.getUpdateSelectionCallCount());
102 mConnection.endBatchEdit(); 101 mConnection.endBatchEdit();
103 assertEquals(1, mWrapper.getUpdateSelectionCallCount()); 102 assertEquals(1, mWrapper.getUpdateSelectionCallCount());
104 mWrapper.verifyUpdateSelectionCall(0, 4, 4, 0, 4); 103 mWrapper.verifyUpdateSelectionCall(0, 4, 4, 0, 4);
105 } 104 }
106 105
107 @MediumTest 106 @MediumTest
108 @Feature({"TextInput", "Main"}) 107 @Feature({"TextInput", "Main"})
109 public void testDeleteSurroundingText() throws Throwable { 108 public void testDeleteSurroundingText() throws Throwable {
Changwan Ryu 2015/10/09 12:34:28 Probably we should remove this test now. IMO this
aelias_OOO_until_Jul13 2015/10/09 20:42:10 Done.
110 // Tests back deletion of a single character with empty input. 109 // Tests back deletion of a single character with empty input.
111 mConnection.deleteSurroundingText(1, 0); 110 mConnection.deleteSurroundingText(1, 0);
112 assertEquals(0, mImeAdapter.getDeleteSurroundingTextCallCount()); 111 assertEquals(1, mImeAdapter.getDeleteSurroundingTextCallCount());
113 Integer[] keyEvents = mImeAdapter.getKeyEvents();
114 assertEquals(1, keyEvents.length);
115 assertEquals(KeyEvent.KEYCODE_DEL, keyEvents[0].intValue());
116 112
117 // Tests forward deletion of a single character with non-empty input. 113 // Tests forward deletion of a single character with non-empty input.
118 mEditable.replace(0, mEditable.length(), " hello"); 114 mEditable.replace(0, mEditable.length(), " hello");
119 Selection.setSelection(mEditable, 0, 0); 115 Selection.setSelection(mEditable, 0, 0);
120 mConnection.deleteSurroundingText(0, 1); 116 mConnection.deleteSurroundingText(0, 1);
121 assertEquals(0, mImeAdapter.getDeleteSurroundingTextCallCount()); 117 assertEquals(2, mImeAdapter.getDeleteSurroundingTextCallCount());
122 keyEvents = mImeAdapter.getKeyEvents();
123 assertEquals(2, keyEvents.length);
124 assertEquals(KeyEvent.KEYCODE_FORWARD_DEL, keyEvents[1].intValue());
125 118
126 // Tests back deletion of multiple characters with non-empty input. 119 // Tests back deletion of multiple characters with non-empty input.
127 mEditable.replace(0, mEditable.length(), "hello "); 120 mEditable.replace(0, mEditable.length(), "hello ");
128 Selection.setSelection(mEditable, mEditable.length(), mEditable.length() ); 121 Selection.setSelection(mEditable, mEditable.length(), mEditable.length() );
129 mConnection.deleteSurroundingText(2, 0); 122 mConnection.deleteSurroundingText(2, 0);
130 assertEquals(1, mImeAdapter.getDeleteSurroundingTextCallCount()); 123 assertEquals(3, mImeAdapter.getDeleteSurroundingTextCallCount());
131 assertEquals(2, mImeAdapter.getKeyEvents().length);
132 } 124 }
133 125
134 @MediumTest 126 @MediumTest
135 @Feature({"TextInput", "Main"}) 127 @Feature({"TextInput", "Main"})
136 public void testNewConnectionFinishesComposingText() throws Throwable { 128 public void testNewConnectionFinishesComposingText() throws Throwable {
137 mConnection.setComposingText("abc", 1); 129 mConnection.setComposingText("abc", 1);
138 assertEquals(0, BaseInputConnection.getComposingSpanStart(mEditable)); 130 assertEquals(0, BaseInputConnection.getComposingSpanStart(mEditable));
139 assertEquals(3, BaseInputConnection.getComposingSpanEnd(mEditable)); 131 assertEquals(3, BaseInputConnection.getComposingSpanEnd(mEditable));
140 132
141 mConnection = new AdapterInputConnection( 133 mConnection = new AdapterInputConnection(
(...skipping 13 matching lines...) Expand all
155 super(wrapper, embedder); 147 super(wrapper, embedder);
156 } 148 }
157 149
158 @Override 150 @Override
159 public boolean deleteSurroundingText(int beforeLength, int afterLength) { 151 public boolean deleteSurroundingText(int beforeLength, int afterLength) {
160 ++mDeleteSurroundingTextCounter; 152 ++mDeleteSurroundingTextCounter;
161 return true; 153 return true;
162 } 154 }
163 155
164 @Override 156 @Override
165 public void sendKeyEventWithKeyCode(int keyCode, int flags) { 157 public void sendSyntheticKeyPress(int keyCode, int flags) {
166 mKeyEventQueue.add(keyCode); 158 mKeyEventQueue.add(keyCode);
167 } 159 }
168 160
169 @Override 161 @Override
170 protected void finishComposingText() { 162 protected void finishComposingText() {
171 ++mFinishComposingTextCounter; 163 ++mFinishComposingTextCounter;
172 super.finishComposingText(); 164 super.finishComposingText();
173 } 165 }
174 166
175 public int getDeleteSurroundingTextCallCount() { 167 public int getDeleteSurroundingTextCallCount() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 243
252 private static void assertCorrectState(String text, int selectionStart, int selectionEnd, 244 private static void assertCorrectState(String text, int selectionStart, int selectionEnd,
253 int compositionStart, int compositionEnd, ImeState actual) { 245 int compositionStart, int compositionEnd, ImeState actual) {
254 assertEquals("Text did not match", text, actual.text); 246 assertEquals("Text did not match", text, actual.text);
255 assertEquals("Selection start did not match", selectionStart, actual.sel ectionStart); 247 assertEquals("Selection start did not match", selectionStart, actual.sel ectionStart);
256 assertEquals("Selection end did not match", selectionEnd, actual.selecti onEnd); 248 assertEquals("Selection end did not match", selectionEnd, actual.selecti onEnd);
257 assertEquals("Composition start did not match", compositionStart, actual .compositionStart); 249 assertEquals("Composition start did not match", compositionStart, actual .compositionStart);
258 assertEquals("Composition end did not match", compositionEnd, actual.com positionEnd); 250 assertEquals("Composition end did not match", compositionEnd, actual.com positionEnd);
259 } 251 }
260 } 252 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698