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 5276a36b54d305ec8d10d4514e8f973bed56ee94..0d666842b8b2cdc8605c8499ed1384517adb13d0 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(); |
} |
@@ -164,15 +166,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 |
@@ -227,21 +226,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) { |
@@ -988,12 +977,7 @@ 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. |
@@ -1050,6 +1034,14 @@ public class ImeTest extends ContentShellTestBase { |
waitAndVerifyStatesAndCalls(8, "aibefcd", 1, 1, -1, -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>() { |
@@ -1072,7 +1064,7 @@ public class ImeTest extends ContentShellTestBase { |
private void performGo(TestCallbackHelperContainer testCallbackHelperContainer) |
throws Throwable { |
- final AdapterInputConnection inputConnection = mConnection; |
+ final InputConnection inputConnection = mConnection; |
handleBlockingCallbackAction( |
testCallbackHelperContainer.getOnPageFinishedHelper(), |
new Runnable() { |
@@ -1090,7 +1082,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; |
} |
@@ -1180,10 +1172,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() { |
@@ -1235,7 +1236,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() { |
@@ -1245,7 +1246,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() { |
@@ -1255,7 +1256,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() { |
@@ -1265,7 +1266,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() { |
@@ -1275,7 +1276,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() { |
@@ -1285,7 +1286,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() { |
@@ -1333,20 +1334,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 AdapterInputConnection.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 AdapterInputConnection get(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() { |
@@ -1362,25 +1364,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 AdapterInputConnection { |
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); |
} |
} |