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++; |
+ } |
+ } |
} |