| 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 4e56ad91be3d19bda9ce67f8d7429eec348c83e8..9401829c213ade4070d443b75bc2b5dd1f073fb8 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
|
| @@ -68,7 +68,39 @@ public class ImeTest extends ContentShellTestBase {
|
| mSelectionPopupController = mContentViewCore.getSelectionPopupControllerForTesting();
|
| mWebContents = getWebContents();
|
|
|
| - mInputMethodManagerWrapper = new TestInputMethodManagerWrapper(mContentViewCore);
|
| + mInputMethodManagerWrapper = new TestInputMethodManagerWrapper(mContentViewCore) {
|
| + private boolean mExpectsSelectionOutsideComposition;
|
| +
|
| + @Override
|
| + public void expectsSelectionOutsideComposition() {
|
| + mExpectsSelectionOutsideComposition = true;
|
| + }
|
| +
|
| + @Override
|
| + public void onUpdateSelection(
|
| + Range oldSel, Range oldComp, Range newSel, Range newComp) {
|
| + // We expect that selection will be outside composition in some cases. Keyboard
|
| + // app will not finish composition in this case.
|
| + if (mExpectsSelectionOutsideComposition) {
|
| + mExpectsSelectionOutsideComposition = false;
|
| + return;
|
| + }
|
| + if (oldComp == null || oldComp.start() == oldComp.end()
|
| + || newComp.start() == newComp.end()) {
|
| + return;
|
| + }
|
| + // This emulates keyboard app's behavior that finishes composition when
|
| + // selection is outside composition.
|
| + if (!newSel.intersects(newComp)) {
|
| + try {
|
| + finishComposingText();
|
| + } catch (Exception e) {
|
| + e.printStackTrace();
|
| + fail();
|
| + }
|
| + }
|
| + }
|
| + };
|
| getImeAdapter().setInputMethodManagerWrapperForTest(mInputMethodManagerWrapper);
|
| assertEquals(0, mInputMethodManagerWrapper.getShowSoftInputCounter());
|
| mConnectionFactory =
|
| @@ -213,6 +245,25 @@ public class ImeTest extends ContentShellTestBase {
|
|
|
| @SmallTest
|
| @Feature({"TextInput", "Main"})
|
| + public void testKeyboardAppFinishesCompositionOnUnexpectedSelectionChange() throws Throwable {
|
| + focusElementAndWaitForStateUpdate("textarea");
|
| + commitText("12345", 1);
|
| + setSelection(3, 3);
|
| + setComposingRegion(2, 3);
|
| +
|
| + waitAndVerifyUpdateSelection(0, 5, 5, -1, -1);
|
| + waitAndVerifyUpdateSelection(1, 3, 3, -1, -1);
|
| + waitAndVerifyUpdateSelection(2, 3, 3, 2, 3);
|
| +
|
| + // Unexpected selection change occurs, e.g., the user clicks on an area.
|
| + DOMUtils.clickNode(this, mContentViewCore, "textarea");
|
| + waitAndVerifyUpdateSelection(3, 5, 5, 2, 3);
|
| + // Keyboard app finishes composition. We emulate this in TestInputMethodManagerWrapper.
|
| + waitAndVerifyUpdateSelection(4, 5, 5, -1, -1);
|
| + }
|
| +
|
| + @SmallTest
|
| + @Feature({"TextInput", "Main"})
|
| public void testSetComposingTextForNewCursorPositions() throws Throwable {
|
| // Cursor is on the right of composing text when newCursorPosition > 0.
|
| setComposingText("ab", 1);
|
| @@ -226,9 +277,11 @@ public class ImeTest extends ContentShellTestBase {
|
| waitAndVerifyUpdateSelection(2, 0, 0, 2, 6);
|
|
|
| // Cursor is on the left boundary.
|
| + mInputMethodManagerWrapper.expectsSelectionOutsideComposition();
|
| setComposingText("cd", -2);
|
| waitAndVerifyUpdateSelection(3, 0, 0, 2, 4);
|
|
|
| + mInputMethodManagerWrapper.expectsSelectionOutsideComposition();
|
| // Cursor is between the left boundary and the composing text.
|
| setComposingText("cd", -1);
|
| waitAndVerifyUpdateSelection(4, 1, 1, 2, 4);
|
| @@ -244,14 +297,17 @@ public class ImeTest extends ContentShellTestBase {
|
| setComposingText("ef", 1);
|
| waitAndVerifyUpdateSelection(7, 4, 4, 2, 4);
|
|
|
| + mInputMethodManagerWrapper.expectsSelectionOutsideComposition();
|
| // Cursor is between the composing text and the right boundary.
|
| setComposingText("ef", 2);
|
| waitAndVerifyUpdateSelection(8, 5, 5, 2, 4);
|
|
|
| + mInputMethodManagerWrapper.expectsSelectionOutsideComposition();
|
| // Cursor is on the right boundary.
|
| setComposingText("ef", 3);
|
| waitAndVerifyUpdateSelection(9, 6, 6, 2, 4);
|
|
|
| + mInputMethodManagerWrapper.expectsSelectionOutsideComposition();
|
| // Cursor exceeds the right boundary.
|
| setComposingText("efgh", 100);
|
| waitAndVerifyUpdateSelection(10, 8, 8, 2, 6);
|
|
|