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

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

Issue 2370663002: Remove logic to reset input method more than needed (Closed)
Patch Set: fix test, fix IMC Created 3 years, 11 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/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 8b16ed9338effead8f88e12988076d94a94d47c4..346a3202ff04bca9061692916b498c5bc2f04b1e 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
@@ -69,7 +69,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 =
@@ -214,6 +246,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);
@@ -227,9 +278,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);
@@ -245,14 +298,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);

Powered by Google App Engine
This is Rietveld 408576698