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 8466f40d17881e18cc51686c1e18cf861c41d064..9e12d499f834d55222fac5996a486c88a2b374ad 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 |
@@ -86,7 +86,36 @@ public class ImeTest extends ContentShellTestBase { |
mContentViewCore = getContentViewCore(); |
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; |
+ } |
+ // This emulates keyboard app's behavior that finishes composition when |
+ // selection is outside composition. |
+ if (oldComp != null && oldComp.start() != oldComp.end() |
+ && (newSel.start() != newComp.end() || newSel.end() != newComp.end())) { |
+ try { |
+ finishComposingText(); |
+ } catch (Exception e) { |
+ e.printStackTrace(); |
+ fail(); |
+ } |
+ } |
+ } |
+ }; |
getImeAdapter().setInputMethodManagerWrapperForTest(mInputMethodManagerWrapper); |
assertEquals(0, mInputMethodManagerWrapper.getShowSoftInputCounter()); |
mConnectionFactory = |
@@ -176,7 +205,27 @@ public class ImeTest extends ContentShellTestBase { |
@SmallTest |
@Feature({"TextInput", "Main"}) |
- public void testSetComposingTextForNewCursorPositions() throws Throwable { |
+ @RetryOnFailure |
+ public void testKeyboardAppFinishesCompositionOnUnexpectedSelectionChange() throws Throwable { |
+ commitText("01234567890123456789", 1); |
+ setSelection(5, 5); |
+ setComposingRegion(4, 5); |
+ |
+ waitAndVerifyUpdateSelection(0, 20, 20, -1, -1); |
+ waitAndVerifyUpdateSelection(1, 5, 5, -1, -1); |
+ waitAndVerifyUpdateSelection(2, 5, 5, 4, 5); |
+ |
+ // Unexpected selection change occurs, e.g., the user clicks on an area. |
+ DOMUtils.clickNode(this, mContentViewCore, "input_text"); |
+ waitAndVerifyUpdateSelection(3, 0, 20, 4, 5); |
+ // Keyboard app finishes composition. We emulate this in TestInputMethodManagerWrapper. |
+ waitAndVerifyUpdateSelection(4, 0, 20, -1, -1); |
+ } |
+ |
+ @SmallTest |
+ @Feature({"TextInput", "Main"}) |
+ @RetryOnFailure |
+ public void testSetComposingTextForDifferentnewCursorPositions() throws Throwable { |
// When newCursorPosition != 1, setComposingText doesn't work for ReplicaInputConnection |
// because there is a bug in BaseInputConnection. |
if (usingReplicaInputConnection()) return; |
@@ -193,9 +242,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); |
@@ -211,14 +262,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); |