OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.content.browser.input; | 5 package org.chromium.content.browser.input; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.os.Build; | 8 import android.os.Build; |
9 import android.support.test.filters.MediumTest; | 9 import android.support.test.filters.MediumTest; |
10 import android.view.inputmethod.CursorAnchorInfo; | 10 import android.view.inputmethod.CursorAnchorInfo; |
11 import android.view.inputmethod.InputConnection; | 11 import android.view.inputmethod.InputConnection; |
12 | 12 |
| 13 import org.junit.Assert; |
| 14 import org.junit.Before; |
| 15 import org.junit.Rule; |
| 16 import org.junit.Test; |
| 17 import org.junit.runner.RunWith; |
| 18 |
13 import org.chromium.base.ThreadUtils; | 19 import org.chromium.base.ThreadUtils; |
14 import org.chromium.base.test.util.Feature; | 20 import org.chromium.base.test.util.Feature; |
15 import org.chromium.base.test.util.MinAndroidSdkLevel; | 21 import org.chromium.base.test.util.MinAndroidSdkLevel; |
16 import org.chromium.base.test.util.RetryOnFailure; | 22 import org.chromium.base.test.util.RetryOnFailure; |
| 23 import org.chromium.content.browser.test.ContentJUnit4ClassRunner; |
17 import org.chromium.content.browser.test.util.Criteria; | 24 import org.chromium.content.browser.test.util.Criteria; |
18 import org.chromium.content.browser.test.util.CriteriaHelper; | 25 import org.chromium.content.browser.test.util.CriteriaHelper; |
19 | 26 |
20 import java.util.concurrent.Callable; | 27 import java.util.concurrent.Callable; |
21 | 28 |
22 /** | 29 /** |
23 * Integration tests for text input for Android L (or above) features. | 30 * Integration tests for text input for Android L (or above) features. |
24 */ | 31 */ |
| 32 @RunWith(ContentJUnit4ClassRunner.class) |
25 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) | 33 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) |
26 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 34 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
27 public class ImeLollipopTest extends ImeTest { | 35 public class ImeLollipopTest { |
| 36 @Rule |
| 37 public ImeActivityTestRule mRule = new ImeActivityTestRule(); |
| 38 |
| 39 @Before |
| 40 public void setUp() throws Exception { |
| 41 mRule.setUp(); |
| 42 } |
| 43 |
| 44 @Test |
28 @MediumTest | 45 @MediumTest |
29 @Feature({"TextInput"}) | 46 @Feature({"TextInput"}) |
30 @RetryOnFailure | 47 @RetryOnFailure |
31 public void testUpdateCursorAnchorInfo() throws Throwable { | 48 public void testUpdateCursorAnchorInfo() throws Throwable { |
32 requestCursorUpdates(InputConnection.CURSOR_UPDATE_MONITOR); | 49 requestCursorUpdates(InputConnection.CURSOR_UPDATE_MONITOR); |
33 | 50 |
34 // In "MONITOR" mode, the change should be notified. | 51 // In "MONITOR" mode, the change should be notified. |
35 setComposingText("ab", 1); | 52 mRule.setComposingText("ab", 1); |
36 waitForUpdateCursorAnchorInfoComposingText("ab"); | 53 waitForUpdateCursorAnchorInfoComposingText("ab"); |
37 | 54 |
38 CursorAnchorInfo info = mInputMethodManagerWrapper.getLastCursorAnchorIn
fo(); | 55 CursorAnchorInfo info = mRule.getInputMethodManagerWrapper().getLastCurs
orAnchorInfo(); |
39 assertEquals(0, info.getComposingTextStart()); | 56 Assert.assertEquals(0, info.getComposingTextStart()); |
40 assertNotNull(info.getCharacterBounds(0)); | 57 Assert.assertNotNull(info.getCharacterBounds(0)); |
41 assertNotNull(info.getCharacterBounds(1)); | 58 Assert.assertNotNull(info.getCharacterBounds(1)); |
42 assertNull(info.getCharacterBounds(2)); | 59 Assert.assertNull(info.getCharacterBounds(2)); |
43 | 60 |
44 // Should be notified not only once. Further change should be sent, too. | 61 // Should be notified not only once. Further change should be sent, too. |
45 setComposingText("abcd", 1); | 62 mRule.setComposingText("abcd", 1); |
46 waitForUpdateCursorAnchorInfoComposingText("abcd"); | 63 waitForUpdateCursorAnchorInfoComposingText("abcd"); |
47 | 64 |
48 info = mInputMethodManagerWrapper.getLastCursorAnchorInfo(); | 65 info = mRule.getInputMethodManagerWrapper().getLastCursorAnchorInfo(); |
49 assertEquals(0, info.getComposingTextStart()); | 66 Assert.assertEquals(0, info.getComposingTextStart()); |
50 assertNotNull(info.getCharacterBounds(0)); | 67 Assert.assertNotNull(info.getCharacterBounds(0)); |
51 assertNotNull(info.getCharacterBounds(1)); | 68 Assert.assertNotNull(info.getCharacterBounds(1)); |
52 assertNotNull(info.getCharacterBounds(2)); | 69 Assert.assertNotNull(info.getCharacterBounds(2)); |
53 assertNotNull(info.getCharacterBounds(3)); | 70 Assert.assertNotNull(info.getCharacterBounds(3)); |
54 assertNull(info.getCharacterBounds(4)); | 71 Assert.assertNull(info.getCharacterBounds(4)); |
55 | 72 |
56 // In "IMMEDIATE" mode, even when there's no change, we should be notifi
ed at least once. | 73 // In "IMMEDIATE" mode, even when there's no change, we should be notifi
ed at least once. |
57 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 74 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
58 @Override | 75 @Override |
59 public void run() { | 76 public void run() { |
60 mInputMethodManagerWrapper.clearLastCursorAnchorInfo(); | 77 mRule.getInputMethodManagerWrapper().clearLastCursorAnchorInfo()
; |
61 } | 78 } |
62 }); | 79 }); |
63 requestCursorUpdates(InputConnection.CURSOR_UPDATE_IMMEDIATE); | 80 requestCursorUpdates(InputConnection.CURSOR_UPDATE_IMMEDIATE); |
64 waitForUpdateCursorAnchorInfoComposingText("abcd"); | 81 waitForUpdateCursorAnchorInfoComposingText("abcd"); |
65 | 82 |
66 setComposingText("abcde", 2); | 83 mRule.setComposingText("abcde", 2); |
67 requestCursorUpdates(InputConnection.CURSOR_UPDATE_IMMEDIATE); | 84 requestCursorUpdates(InputConnection.CURSOR_UPDATE_IMMEDIATE); |
68 waitForUpdateCursorAnchorInfoComposingText("abcde"); | 85 waitForUpdateCursorAnchorInfoComposingText("abcde"); |
69 } | 86 } |
70 | 87 |
71 private void requestCursorUpdates(final int cursorUpdateMode) throws Excepti
on { | 88 private void requestCursorUpdates(final int cursorUpdateMode) throws Excepti
on { |
72 final InputConnection connection = mConnection; | 89 final InputConnection connection = mRule.getConnection(); |
73 runBlockingOnImeThread(new Callable<Void>() { | 90 mRule.runBlockingOnImeThread(new Callable<Void>() { |
74 @Override | 91 @Override |
75 public Void call() { | 92 public Void call() { |
76 connection.requestCursorUpdates(cursorUpdateMode); | 93 connection.requestCursorUpdates(cursorUpdateMode); |
77 return null; | 94 return null; |
78 } | 95 } |
79 }); | 96 }); |
80 } | 97 } |
81 | 98 |
82 private void waitForUpdateCursorAnchorInfoComposingText(final String expecte
d) { | 99 private void waitForUpdateCursorAnchorInfoComposingText(final String expecte
d) { |
83 CriteriaHelper.pollUiThread(new Criteria() { | 100 CriteriaHelper.pollUiThread(new Criteria() { |
84 @Override | 101 @Override |
85 public boolean isSatisfied() { | 102 public boolean isSatisfied() { |
86 CursorAnchorInfo info = mInputMethodManagerWrapper.getLastCursor
AnchorInfo(); | 103 CursorAnchorInfo info = |
| 104 mRule.getInputMethodManagerWrapper().getLastCursorAnchor
Info(); |
87 if (info != null && info.getComposingText() == null) { | 105 if (info != null && info.getComposingText() == null) { |
88 updateFailureReason("info.getCompositingText() returned null
"); | 106 updateFailureReason("info.getCompositingText() returned null
"); |
89 return false; | 107 return false; |
90 } | 108 } |
91 | 109 |
92 String actual = (info == null ? "" : info.getComposingText().toS
tring()); | 110 String actual = (info == null ? "" : info.getComposingText().toS
tring()); |
93 updateFailureReason("Expected: {" + expected + "}, Actual: {" +
actual + "}"); | 111 updateFailureReason("Expected: {" + expected + "}, Actual: {" +
actual + "}"); |
94 return expected.equals(actual); | 112 return expected.equals(actual); |
95 } | 113 } |
96 }); | 114 }); |
97 } | 115 } |
98 } | 116 } |
OLD | NEW |