Index: content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java |
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java b/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java |
index 704441b743a5ac6465a3e649ad94fb057d1d0aa8..0746c2c21e4c6b710e83a4265f7d1fab5aa24a55 100644 |
--- a/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java |
+++ b/content/public/android/javatests/src/org/chromium/content/browser/input/ImeTest.java |
@@ -11,10 +11,12 @@ import android.content.Context; |
import android.content.res.Configuration; |
import android.test.suitebuilder.annotation.MediumTest; |
import android.test.suitebuilder.annotation.SmallTest; |
+import android.text.Editable; |
import android.text.TextUtils; |
import android.view.KeyEvent; |
import android.view.View; |
import android.view.inputmethod.EditorInfo; |
+import android.view.inputmethod.InputConnection; |
import org.chromium.base.ThreadUtils; |
import org.chromium.base.test.util.Feature; |
@@ -55,8 +57,8 @@ public class ImeTest extends ContentShellTestBase { |
+ "<br/><p><span id=\"plain_text\">This is Plain Text One</span></p>" |
+ "</form></body></html>"); |
- private TestAdapterInputConnection mConnection; |
- private TestAdapterInputConnectionFactory mConnectionFactory; |
+ private TestInputConnection mConnection; |
+ private TestInputConnectionFactory mConnectionFactory; |
private ImeAdapter mImeAdapter; |
private ContentViewCore mContentViewCore; |
@@ -76,7 +78,7 @@ public class ImeTest extends ContentShellTestBase { |
mInputMethodManagerWrapper = new TestInputMethodManagerWrapper(mContentViewCore); |
getImeAdapter().setInputMethodManagerWrapperForTest(mInputMethodManagerWrapper); |
assertEquals(0, mInputMethodManagerWrapper.getShowSoftInputCounter()); |
- mConnectionFactory = new TestAdapterInputConnectionFactory(); |
+ mConnectionFactory = new TestInputConnectionFactory(); |
getImeAdapter().setInputConnectionFactory(mConnectionFactory); |
mCallbackContainer = new TestCallbackHelperContainer(mContentViewCore); |
@@ -86,13 +88,13 @@ public class ImeTest extends ContentShellTestBase { |
DOMUtils.clickNode(this, mContentViewCore, "input_text"); |
assertWaitForKeyboardStatus(true); |
- mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); |
+ mConnection = (TestInputConnection) getInputConnection(); |
mImeAdapter = getImeAdapter(); |
waitAndVerifyStatesAndCalls(0, "", 0, 0, -1, -1); |
waitForKeyboardStates(1, 0, 1, new Integer[] {TextInputType.TEXT}); |
- assertEquals(0, mInputMethodManagerWrapper.getEditorInfo().initialSelStart); |
- assertEquals(0, mInputMethodManagerWrapper.getEditorInfo().initialSelEnd); |
+ assertEquals(0, mConnectionFactory.getOutAttrs().initialSelStart); |
+ assertEquals(0, mConnectionFactory.getOutAttrs().initialSelEnd); |
resetAllStates(); |
} |
@@ -182,15 +184,12 @@ public class ImeTest extends ContentShellTestBase { |
public void testEnterTextAndRefocus() throws Exception { |
commitText("hello", 1); |
waitAndVerifyStatesAndCalls(0, "hello", 5, 5, -1, -1); |
- |
- DOMUtils.clickNode(this, mContentViewCore, "input_radio"); |
- assertWaitForKeyboardStatus(false); |
- |
+ restartInput(); |
DOMUtils.clickNode(this, mContentViewCore, "input_text"); |
assertWaitForKeyboardStatus(true); |
- assertEquals(5, mInputMethodManagerWrapper.getEditorInfo().initialSelStart); |
- assertEquals(5, mInputMethodManagerWrapper.getEditorInfo().initialSelEnd); |
+ assertEquals(5, mConnectionFactory.getOutAttrs().initialSelStart); |
+ assertEquals(5, mConnectionFactory.getOutAttrs().initialSelEnd); |
} |
@SmallTest |
@@ -252,21 +251,11 @@ public class ImeTest extends ContentShellTestBase { |
} |
private String getKeyboardStates() { |
- try { |
- return ThreadUtils.runOnUiThreadBlocking(new Callable<String>() { |
- @Override |
- public String call() throws Exception { |
- int showCount = mInputMethodManagerWrapper.getShowSoftInputCounter(); |
- int hideCount = mInputMethodManagerWrapper.getHideSoftInputCounter(); |
- int restartCount = mInputMethodManagerWrapper.getRestartInputCounter(); |
- Integer[] history = mConnectionFactory.getTextInputTypeHistory(); |
- return stringifyKeyboardStates(showCount, hideCount, restartCount, history); |
- } |
- }); |
- } catch (ExecutionException e) { |
- e.printStackTrace(); |
- return null; |
- } |
+ int showCount = mInputMethodManagerWrapper.getShowSoftInputCounter(); |
+ int hideCount = mInputMethodManagerWrapper.getHideSoftInputCounter(); |
+ int restartCount = mInputMethodManagerWrapper.getRestartInputCounter(); |
+ Integer[] history = mConnectionFactory.getTextInputTypeHistory(); |
+ return stringifyKeyboardStates(showCount, hideCount, restartCount, history); |
} |
private String stringifyKeyboardStates(int show, int hide, int restart, Integer[] history) { |
@@ -1013,21 +1002,44 @@ public class ImeTest extends ContentShellTestBase { |
public void testRestartInputWhileComposingText() throws Throwable { |
setComposingText("abc", 1); |
waitAndVerifyStatesAndCalls(0, "abc", 3, 3, 0, 3); |
- ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
- @Override |
- public void run() { |
- mImeAdapter.restartInput(); |
- } |
- }); |
+ restartInput(); |
// We don't do anything when input gets restarted. But we depend on Android's |
// InputMethodManager and/or input methods to call finishComposingText() in setting |
// current input connection as active or finishing the current input connection. |
assertNoFurtherStateUpdate(1); |
} |
+ @MediumTest |
+ @Feature({"TextInput"}) |
+ public void testRestartInputKeepsTextAndCursor() throws Exception { |
+ commitText("ab", 2); |
+ restartInput(); |
+ assertEquals("ab", getTextBeforeCursor(10, 0)); |
+ } |
+ |
+ private CharSequence getTextBeforeCursor(final int length, final int flags) |
+ throws ExecutionException { |
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<CharSequence>() { |
+ @Override |
+ public CharSequence call() { |
+ return mConnection.getTextBeforeCursor(length, flags); |
+ } |
+ }); |
+ } |
+ |
+ private CharSequence getTextAfterCursor(final int length, final int flags) |
+ throws ExecutionException { |
+ return ThreadUtils.runOnUiThreadBlocking(new Callable<CharSequence>() { |
+ @Override |
+ public CharSequence call() { |
+ return mConnection.getTextAfterCursor(length, flags); |
+ } |
+ }); |
+ } |
+ |
private void performGo(TestCallbackHelperContainer testCallbackHelperContainer) |
throws Throwable { |
- final AdapterInputConnection inputConnection = mConnection; |
+ final InputConnection inputConnection = mConnection; |
handleBlockingCallbackAction( |
testCallbackHelperContainer.getOnPageFinishedHelper(), |
new Runnable() { |
@@ -1045,7 +1057,7 @@ public class ImeTest extends ContentShellTestBase { |
// We do not check the other way around: in some cases we need to keep |
// input connection even when the last known status is 'hidden'. |
// See crbug.com/569332 for more details. |
- if (show && getAdapterInputConnection() == null) { |
+ if (show && getInputConnection() == null) { |
updateFailureReason("input connection should not be null."); |
return false; |
} |
@@ -1135,10 +1147,19 @@ public class ImeTest extends ContentShellTestBase { |
return mContentViewCore.getImeAdapterForTest(); |
} |
- private AdapterInputConnection getAdapterInputConnection() { |
+ private ChromiumBaseInputConnection getInputConnection() { |
return mContentViewCore.getImeAdapterForTest().getInputConnectionForTest(); |
} |
+ private void restartInput() { |
+ ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
+ @Override |
+ public void run() { |
+ mImeAdapter.restartInput(); |
+ } |
+ }); |
+ } |
+ |
private void copy() { |
final WebContents webContents = mWebContents; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@@ -1190,7 +1211,7 @@ public class ImeTest extends ContentShellTestBase { |
} |
private void commitText(final CharSequence text, final int newCursorPosition) { |
- final AdapterInputConnection connection = mConnection; |
+ final InputConnection connection = mConnection; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -1200,7 +1221,7 @@ public class ImeTest extends ContentShellTestBase { |
} |
private void setSelection(final int start, final int end) { |
- final AdapterInputConnection connection = mConnection; |
+ final InputConnection connection = mConnection; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -1210,7 +1231,7 @@ public class ImeTest extends ContentShellTestBase { |
} |
private void setComposingRegion(final int start, final int end) { |
- final AdapterInputConnection connection = mConnection; |
+ final InputConnection connection = mConnection; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -1220,7 +1241,7 @@ public class ImeTest extends ContentShellTestBase { |
} |
private void setComposingText(final CharSequence text, final int newCursorPosition) { |
- final AdapterInputConnection connection = mConnection; |
+ final InputConnection connection = mConnection; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -1230,7 +1251,7 @@ public class ImeTest extends ContentShellTestBase { |
} |
private void finishComposingText() { |
- final AdapterInputConnection connection = mConnection; |
+ final InputConnection connection = mConnection; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -1240,7 +1261,7 @@ public class ImeTest extends ContentShellTestBase { |
} |
private void deleteSurroundingText(final int before, final int after) { |
- final AdapterInputConnection connection = mConnection; |
+ final InputConnection connection = mConnection; |
ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
@Override |
public void run() { |
@@ -1288,20 +1309,21 @@ public class ImeTest extends ContentShellTestBase { |
} |
}); |
// When we focus another element, the connection may be recreated. |
- mConnection = (TestAdapterInputConnection) getAdapterInputConnection(); |
+ mConnection = (TestInputConnection) getInputConnection(); |
} |
- private static class TestAdapterInputConnectionFactory extends |
- ImeAdapter.AdapterInputConnectionFactory { |
+ private static class TestInputConnectionFactory extends ReplicaInputConnection.Factory { |
private final List<TestImeState> mImeStateList = new ArrayList<>(); |
private final List<Integer> mTextInputTypeList = new ArrayList<>(); |
+ private EditorInfo mOutAttrs; |
@Override |
- public AdapterInputConnection get(View view, ImeAdapter imeAdapter, int initialSelStart, |
- int initialSelEnd, EditorInfo outAttrs) { |
- mTextInputTypeList.add(imeAdapter.getTextInputType()); |
- return new TestAdapterInputConnection( |
- mImeStateList, view, imeAdapter, initialSelStart, initialSelEnd, outAttrs); |
+ public ReplicaInputConnection initializeAndGet(View view, ImeAdapter imeAdapter, |
+ int inputType, int inputFlags, EditorInfo outAttrs) { |
+ mTextInputTypeList.add(inputType); |
+ mOutAttrs = outAttrs; |
+ return new TestInputConnection( |
+ mImeStateList, view, imeAdapter, mEditable, inputType, inputFlags, outAttrs); |
} |
public List<TestImeState> getImeStateList() { |
@@ -1317,25 +1339,29 @@ public class ImeTest extends ContentShellTestBase { |
public void clearTextInputTypeHistory() { |
mTextInputTypeList.clear(); |
} |
+ |
+ public EditorInfo getOutAttrs() { |
+ return mOutAttrs; |
+ } |
} |
- private static class TestAdapterInputConnection extends AdapterInputConnection { |
+ private static class TestInputConnection extends ReplicaInputConnection { |
private final List<TestImeState> mImeStateList; |
- public TestAdapterInputConnection(List<TestImeState> imeStateList, View view, |
- ImeAdapter imeAdapter, int initialSelStart, int initialSelEnd, |
+ public TestInputConnection(List<TestImeState> imeStateList, View view, |
+ ImeAdapter imeAdapter, Editable editable, int inputType, int inputFlags, |
EditorInfo outAttrs) { |
- super(view, imeAdapter, initialSelStart, initialSelEnd, outAttrs); |
+ super(view, imeAdapter, new ThreadManager(), editable, inputType, inputFlags, outAttrs); |
mImeStateList = imeStateList; |
} |
@Override |
- public void updateState(String text, int selectionStart, int selectionEnd, |
- int compositionStart, int compositionEnd, boolean requiredAck) { |
+ public void updateStateOnUiThread(String text, int selectionStart, int selectionEnd, |
+ int compositionStart, int compositionEnd, boolean singleLine, boolean requiredAck) { |
mImeStateList.add(new TestImeState( |
text, selectionStart, selectionEnd, compositionStart, compositionEnd)); |
- super.updateState(text, selectionStart, selectionEnd, compositionStart, |
- compositionEnd, requiredAck); |
+ super.updateStateOnUiThread(text, selectionStart, selectionEnd, compositionStart, |
+ compositionEnd, singleLine, requiredAck); |
} |
} |