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

Side by Side Diff: content/public/android/javatests/src/org/chromium/content/browser/input/ImeLollipopTest.java

Issue 1589953005: Support InputMethodManager#updateCursorAnchorInfo for Android 5.0 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments in #38 Created 4 years, 9 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package org.chromium.content.browser.input;
6
7 import android.annotation.TargetApi;
8 import android.os.Build;
9 import android.test.suitebuilder.annotation.MediumTest;
10 import android.view.inputmethod.CursorAnchorInfo;
11 import android.view.inputmethod.InputConnection;
12
13 import org.chromium.base.ThreadUtils;
14 import org.chromium.base.test.util.Feature;
15 import org.chromium.base.test.util.MinAndroidSdkLevel;
16 import org.chromium.content.browser.test.util.Criteria;
17 import org.chromium.content.browser.test.util.CriteriaHelper;
18
19 /**
20 * Integration tests for text input for Android L (or above) features.
21 */
22 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
23 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
24 public class ImeLollipopTest extends ImeTest {
25 @MediumTest
26 @Feature({"TextInput"})
27 public void testUpdateCursorAnchorInfo() throws Throwable {
28 requestCursorUpdates(InputConnection.CURSOR_UPDATE_MONITOR);
29
30 // In "MONITOR" mode, the change should be notified.
31 setComposingText("ab", 1);
32 waitForUpdateCursorAnchorInfoComposingText("ab");
33
34 CursorAnchorInfo info = mInputMethodManagerWrapper.getLastCursorAnchorIn fo();
35 assertEquals(0, info.getComposingTextStart());
36 assertNotNull(info.getCharacterBounds(0));
37 assertNotNull(info.getCharacterBounds(1));
38 assertNull(info.getCharacterBounds(2));
39
40 // Should be notified not only once. Further change should be sent, too.
41 setComposingText("abcd", 1);
42 waitForUpdateCursorAnchorInfoComposingText("abcd");
43
44 info = mInputMethodManagerWrapper.getLastCursorAnchorInfo();
45 assertEquals(0, info.getComposingTextStart());
46 assertNotNull(info.getCharacterBounds(0));
47 assertNotNull(info.getCharacterBounds(1));
48 assertNotNull(info.getCharacterBounds(2));
49 assertNotNull(info.getCharacterBounds(3));
50 assertNull(info.getCharacterBounds(4));
51
52 // In "IMMEDIATE" mode, even when there's no change, we should be notifi ed at least once.
53 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
54 @Override
55 public void run() {
56 mInputMethodManagerWrapper.clearLastCursorAnchorInfo();
57 }
58 });
59 requestCursorUpdates(InputConnection.CURSOR_UPDATE_IMMEDIATE);
60 waitForUpdateCursorAnchorInfoComposingText("abcd");
61 }
62
63 private void requestCursorUpdates(final int cursorUpdateMode) {
64 final InputConnection connection = mConnection;
65 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
66 @Override
67 public void run() {
68 connection.requestCursorUpdates(cursorUpdateMode);
69 }
70 });
71 }
72
73 private void waitForUpdateCursorAnchorInfoCallCount(final int expected)
74 throws InterruptedException {
75 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
76 @Override
77 public boolean isSatisfied() {
78 int actual = mInputMethodManagerWrapper.getUpdateCursorAnchorIn foCounter();
79 updateFailureReason("Expected: {" + expected + "}, Actual: {" + actual + "}");
80 return expected == actual;
81 }
82 });
83 }
84
85 private void waitForUpdateCursorAnchorInfoComposingText(final String expecte d)
86 throws InterruptedException {
87 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
88 @Override
89 public boolean isSatisfied() {
90 CursorAnchorInfo info = mInputMethodManagerWrapper.getLastCursor AnchorInfo();
91 String actual = (info == null ? "" : info.getComposingText().toS tring());
92 updateFailureReason("Expected: {" + expected + "}, Actual: {" + actual + "}");
93 return expected.equals(actual);
94 }
95 });
96 }
97 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698