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 7a53c32b96b6a0d19e243d5af318f8e660b71567..1ef392cdad2298f3740538953f94b55290c1311c 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 |
@@ -87,7 +87,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 = |
@@ -177,6 +206,26 @@ public class ImeTest extends ContentShellTestBase { |
@SmallTest |
@Feature({"TextInput", "Main"}) |
+ @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 testSetComposingTextForNewCursorPositions() throws Throwable { |
// When newCursorPosition != 1, setComposingText doesn't work for ReplicaInputConnection |
// because there is a bug in BaseInputConnection. |
@@ -194,9 +243,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); |
@@ -212,14 +263,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); |