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

Unified Diff: content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java

Issue 12093068: Adding missing UpdateTextInputState calls after each ime event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding an Android IME test Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java
diff --git a/content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java b/content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java
index 2b0cf2764bbed0e6d030795053fc55213121d275..e63a8ace96430e0cd3aac0cc33328bbf87688e15 100644
--- a/content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java
+++ b/content/public/android/javatests/src/org/chromium/content/browser/ImeTest.java
@@ -5,9 +5,13 @@
package org.chromium.content.browser;
import android.test.suitebuilder.annotation.MediumTest;
+import android.test.suitebuilder.annotation.SmallTest;
+import android.view.View;
import android.view.inputmethod.EditorInfo;
import org.chromium.base.test.util.Feature;
+import org.chromium.content.browser.ImeAdapter.AdapterInputConnection;
+import org.chromium.content.browser.ImeAdapter.AdapterInputConnectionFactory;
import org.chromium.content.browser.test.util.Criteria;
import org.chromium.content.browser.test.util.CriteriaHelper;
import org.chromium.content.browser.test.util.DOMUtils;
@@ -34,7 +38,7 @@ public class ImeTest extends ContentShellTestBase {
DOMUtils.clickNode(this, view, viewClient, "input_text");
assertWaitForKeyboardStatus(true);
- getAdapterInputConnection().setComposingText("hello", 5);
+ getAdapterInputConnection().setComposingText("hello", 1);
getAdapterInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO);
// Since hiding the keyboard is an asynchronous task, it might take an arbitrary amount
@@ -44,6 +48,65 @@ public class ImeTest extends ContentShellTestBase {
assertWaitForKeyboardStatus(false);
}
+ @SmallTest
+ @Feature({"TextInput", "Main"})
+ public void testGetTextUpdatesAfterEnteringText() throws Throwable {
+ launchContentShellWithUrl(DATA_URL);
+ assertTrue("Page failed to load", waitForActiveShellToBeDoneLoading());
+
+ getContentViewCore().setAdapterInputConnectionFactory(
+ new TestAdapterInputConnectionFactory());
+
+ final ContentView view = getActivity().getActiveContentView();
+ final TestCallbackHelperContainer viewClient =
+ new TestCallbackHelperContainer(view);
+ DOMUtils.clickNode(this, view, viewClient, "input_text");
+ assertWaitForKeyboardStatus(true);
+
+ TestAdapterInputConnection connection =
+ (TestAdapterInputConnection) getAdapterInputConnection();
+ ImeAdapter adapter = getImeAdapter();
+
+ assertWaitForSetEditableCallback(1, connection);
+ assertEquals("", connection.mText);
+ assertEquals(0, connection.mSelectionStart);
+ assertEquals(0, connection.mSelectionEnd);
+ assertEquals(-1, connection.mCompositionStart);
+ assertEquals(-1, connection.mCompositionEnd);
+
+ adapter.checkCompositionQueueAndCallNative("h", 1, false);
+ assertWaitForSetEditableCallback(2, connection);
+ assertEquals("h", connection.mText);
+ assertEquals(1, connection.mSelectionStart);
+ assertEquals(1, connection.mSelectionEnd);
+ assertEquals(0, connection.mCompositionStart);
+ assertEquals(1, connection.mCompositionEnd);
+
+ adapter.checkCompositionQueueAndCallNative("he", 1, false);
+ assertWaitForSetEditableCallback(3, connection);
+ assertEquals("he", connection.mText);
+ assertEquals(2, connection.mSelectionStart);
+ assertEquals(2, connection.mSelectionEnd);
+ assertEquals(0, connection.mCompositionStart);
+ assertEquals(2, connection.mCompositionEnd);
+
+ adapter.checkCompositionQueueAndCallNative("hel", 1, false);
+ assertWaitForSetEditableCallback(4, connection);
+ assertEquals("hel", connection.mText);
+ assertEquals(3, connection.mSelectionStart);
+ assertEquals(3, connection.mSelectionEnd);
+ assertEquals(0, connection.mCompositionStart);
+ assertEquals(3, connection.mCompositionEnd);
+
+ adapter.checkCompositionQueueAndCallNative("hel", 1, true);
+ assertWaitForSetEditableCallback(5, connection);
+ assertEquals("hel", connection.mText);
+ assertEquals(3, connection.mSelectionStart);
+ assertEquals(3, connection.mSelectionEnd);
+ assertEquals(-1, connection.mCompositionStart);
+ assertEquals(-1, connection.mCompositionEnd);
+ }
+
private void assertWaitForKeyboardStatus(final boolean show) throws Throwable {
assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
@Override
@@ -53,6 +116,16 @@ public class ImeTest extends ContentShellTestBase {
}));
}
+ private void assertWaitForSetEditableCallback(final int callbackNumber,
+ final TestAdapterInputConnection connection) throws Throwable {
+ assertTrue(CriteriaHelper.pollForCriteria(new Criteria() {
+ @Override
+ public boolean isSatisfied() {
+ return callbackNumber == connection.mSetEditableTextCallCounter;
+ }
+ }));
+ }
+
private ImeAdapter getImeAdapter() {
return getContentViewCore().getImeAdapterForTest();
}
@@ -60,4 +133,39 @@ public class ImeTest extends ContentShellTestBase {
private ImeAdapter.AdapterInputConnection getAdapterInputConnection() {
return getContentViewCore().getInputConnectionForTest();
}
+
+ static public class TestAdapterInputConnectionFactory extends
Ted C 2013/02/06 00:59:00 public before static....and these should probably
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
+ ImeAdapter.AdapterInputConnectionFactory {
Ted C 2013/02/06 00:59:00 indent +4
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
+ @Override
+ public AdapterInputConnection get(View view, ImeAdapter imeAdapter,
+ EditorInfo outAttrs) {
+ return new TestAdapterInputConnection(view, imeAdapter, outAttrs);
+ }
+ }
+
+ static public class TestAdapterInputConnection extends ImeAdapter.AdapterInputConnection {
Ted C 2013/02/06 00:59:00 same comment as above
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
+ public int mSetEditableTextCallCounter;
Ted C 2013/02/06 00:59:00 I would make all these protected.
aurimas (slooooooooow) 2013/02/06 02:25:44 Done.
+
+ public String mText;
+ public int mSelectionStart;
+ public int mSelectionEnd;
+ public int mCompositionStart;
+ public int mCompositionEnd;
+
+ public TestAdapterInputConnection(View view, ImeAdapter imeAdapter, EditorInfo outAttrs) {
+ super(view, imeAdapter, outAttrs);
+ mSetEditableTextCallCounter = 0;
+ }
+
+ @Override
+ public void setEditableText(String text, int selectionStart, int selectionEnd,
+ int compositionStart, int compositionEnd) {
+ mText = text;
+ mSelectionStart = selectionStart;
+ mSelectionEnd = selectionEnd;
+ mCompositionStart = compositionStart;
+ mCompositionEnd = compositionEnd;
+ mSetEditableTextCallCounter++;
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698