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

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

Issue 2766393004: Convert most of the rest of instrumentation tests in content (Closed)
Patch Set: Keep @CommenLineFlags Created 3 years, 8 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
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.graphics.Matrix; 8 import android.graphics.Matrix;
9 import android.graphics.RectF; 9 import android.graphics.RectF;
10 import android.os.Build; 10 import android.os.Build;
11 import android.support.test.filters.SmallTest; 11 import android.support.test.filters.SmallTest;
12 import android.test.InstrumentationTestCase;
13 import android.text.TextUtils; 12 import android.text.TextUtils;
14 import android.view.View; 13 import android.view.View;
15 import android.view.inputmethod.CursorAnchorInfo; 14 import android.view.inputmethod.CursorAnchorInfo;
16 15
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19
20 import org.chromium.base.test.BaseJUnit4ClassRunner;
17 import org.chromium.base.test.util.Feature; 21 import org.chromium.base.test.util.Feature;
18 import org.chromium.base.test.util.MinAndroidSdkLevel; 22 import org.chromium.base.test.util.MinAndroidSdkLevel;
19 import org.chromium.content.browser.RenderCoordinates; 23 import org.chromium.content.browser.RenderCoordinates;
20 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper; 24 import org.chromium.content.browser.test.util.TestInputMethodManagerWrapper;
21 25
22 /** 26 /**
23 * Test for {@link CursorAnchorInfoController}. 27 * Test for {@link CursorAnchorInfoController}.
24 */ 28 */
29 @RunWith(BaseJUnit4ClassRunner.class)
25 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP) 30 @MinAndroidSdkLevel(Build.VERSION_CODES.LOLLIPOP)
26 @TargetApi(Build.VERSION_CODES.LOLLIPOP) 31 @TargetApi(Build.VERSION_CODES.LOLLIPOP)
27 public class CursorAnchorInfoControllerTest extends InstrumentationTestCase { 32 public class CursorAnchorInfoControllerTest {
28 private static RenderCoordinates createRenderCoordinates(float deviceScaleFa ctor, 33 private static RenderCoordinates createRenderCoordinates(float deviceScaleFa ctor,
29 float contentOffsetYPix) { 34 float contentOffsetYPix) {
30 RenderCoordinates renderCoordinates = new RenderCoordinates(); 35 RenderCoordinates renderCoordinates = new RenderCoordinates();
31 renderCoordinates.setFrameInfoForTest(deviceScaleFactor, contentOffsetYP ix); 36 renderCoordinates.setFrameInfoForTest(deviceScaleFactor, contentOffsetYP ix);
32 return renderCoordinates; 37 return renderCoordinates;
33 } 38 }
34 39
35 private static final class TestViewDelegate implements CursorAnchorInfoContr oller.ViewDelegate { 40 private static final class TestViewDelegate implements CursorAnchorInfoContr oller.ViewDelegate {
36 public int locationX; 41 public int locationX;
37 public int locationY; 42 public int locationY;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 mComposingTextStart = compositionStart; 85 mComposingTextStart = compositionStart;
81 mComposingTextEnd = compositionEnd; 86 mComposingTextEnd = compositionEnd;
82 controller.invalidateLastCursorAnchorInfo(); 87 controller.invalidateLastCursorAnchorInfo();
83 } 88 }
84 89
85 public void clearTextAndSelection(CursorAnchorInfoController controller) { 90 public void clearTextAndSelection(CursorAnchorInfoController controller) {
86 updateTextAndSelection(controller, null, -1, -1, -1, -1); 91 updateTextAndSelection(controller, null, -1, -1, -1, -1);
87 } 92 }
88 } 93 }
89 94
90 private void assertScaleAndTranslate(float expectedScale, float expectedTran slateX, 95 private static class AssertionHelper {
jbudorick 2017/04/04 00:39:55 What's the motivation behind moving these into a p
the real yoland 2017/04/04 17:41:25 Because CursorAnchorInfo is lollipop and above, JU
jbudorick 2017/04/04 19:51:17 huh, interesting.
91 float expectedTranslateY, CursorAnchorInfo actual) { 96 static void assertScaleAndTranslate(float expectedScale, float expectedT ranslateX,
92 Matrix expectedMatrix = new Matrix(); 97 float expectedTranslateY, CursorAnchorInfo actual) {
93 expectedMatrix.setScale(expectedScale, expectedScale); 98 Matrix expectedMatrix = new Matrix();
94 expectedMatrix.postTranslate(expectedTranslateX, expectedTranslateY); 99 expectedMatrix.setScale(expectedScale, expectedScale);
95 assertEquals(expectedMatrix, actual.getMatrix()); 100 expectedMatrix.postTranslate(expectedTranslateX, expectedTranslateY) ;
101 Assert.assertEquals(expectedMatrix, actual.getMatrix());
102 }
103
104 static void assertHasInsertionMarker(int expectedFlags, float expectedHo rizontal,
105 float expectedTop, float expectedBaseline, float expectedBottom,
106 CursorAnchorInfo actual) {
107 Assert.assertEquals(expectedFlags, actual.getInsertionMarkerFlags()) ;
108 Assert.assertEquals(expectedHorizontal, actual.getInsertionMarkerHor izontal(), 0);
109 Assert.assertEquals(expectedTop, actual.getInsertionMarkerTop(), 0);
110 Assert.assertEquals(expectedBaseline, actual.getInsertionMarkerBasel ine(), 0);
111 Assert.assertEquals(expectedBottom, actual.getInsertionMarkerBottom( ), 0);
112 }
113
114 static void assertHasNoInsertionMarker(CursorAnchorInfo actual) {
115 Assert.assertEquals(0, actual.getInsertionMarkerFlags());
116 Assert.assertTrue(Float.isNaN(actual.getInsertionMarkerHorizontal()) );
117 Assert.assertTrue(Float.isNaN(actual.getInsertionMarkerTop()));
118 Assert.assertTrue(Float.isNaN(actual.getInsertionMarkerBaseline()));
119 Assert.assertTrue(Float.isNaN(actual.getInsertionMarkerBottom()));
120 }
121
122 static void assertComposingText(CharSequence expectedComposingText,
123 int expectedComposingTextStart, CursorAnchorInfo actual) {
124 Assert.assertTrue(TextUtils.equals(expectedComposingText, actual.get ComposingText()));
125 Assert.assertEquals(expectedComposingTextStart, actual.getComposingT extStart());
126 }
127
128 static void assertSelection(
129 int expecteSelectionStart, int expecteSelectionEnd, CursorAnchor Info actual) {
130 Assert.assertEquals(expecteSelectionStart, actual.getSelectionStart( ));
131 Assert.assertEquals(expecteSelectionEnd, actual.getSelectionEnd());
132 }
96 } 133 }
97 134
98 private void assertHasInsertionMarker(int expectedFlags, float expectedHoriz ontal, 135 @Test
99 float expectedTop, float expectedBaseline, float expectedBottom,
100 CursorAnchorInfo actual) {
101 assertEquals(expectedFlags, actual.getInsertionMarkerFlags());
102 assertEquals(expectedHorizontal, actual.getInsertionMarkerHorizontal());
103 assertEquals(expectedTop, actual.getInsertionMarkerTop());
104 assertEquals(expectedBaseline, actual.getInsertionMarkerBaseline());
105 assertEquals(expectedBottom, actual.getInsertionMarkerBottom());
106 }
107
108 private void assertHasNoInsertionMarker(CursorAnchorInfo actual) {
109 assertEquals(0, actual.getInsertionMarkerFlags());
110 assertTrue(Float.isNaN(actual.getInsertionMarkerHorizontal()));
111 assertTrue(Float.isNaN(actual.getInsertionMarkerTop()));
112 assertTrue(Float.isNaN(actual.getInsertionMarkerBaseline()));
113 assertTrue(Float.isNaN(actual.getInsertionMarkerBottom()));
114 }
115
116 private void assertComposingText(CharSequence expectedComposingText,
117 int expectedComposingTextStart, CursorAnchorInfo actual) {
118 assertTrue(TextUtils.equals(expectedComposingText, actual.getComposingTe xt()));
119 assertEquals(expectedComposingTextStart, actual.getComposingTextStart()) ;
120 }
121
122 private void assertSelection(int expecteSelectionStart, int expecteSelection End,
123 CursorAnchorInfo actual) {
124 assertEquals(expecteSelectionStart, actual.getSelectionStart());
125 assertEquals(expecteSelectionEnd, actual.getSelectionEnd());
126 }
127
128 @SmallTest 136 @SmallTest
129 @Feature({"Input-Text-IME"}) 137 @Feature({"Input-Text-IME"})
130 public void testFocusedNodeChanged() { 138 public void testFocusedNodeChanged() {
131 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 139 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
132 TestViewDelegate viewDelegate = new TestViewDelegate(); 140 TestViewDelegate viewDelegate = new TestViewDelegate();
133 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 141 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
134 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 142 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
135 immw, composingTextDelegate, viewDelegate); 143 immw, composingTextDelegate, viewDelegate);
136 View view = null; 144 View view = null;
137 145
138 viewDelegate.locationX = 0; 146 viewDelegate.locationX = 0;
139 viewDelegate.locationY = 0; 147 viewDelegate.locationY = 0;
140 148
141 assertFalse( 149 Assert.assertFalse(
142 "IC#onRequestCursorUpdates() must be rejected if the focused nod e is not editable.", 150 "IC#onRequestCursorUpdates() must be rejected if the focused nod e is not editable.",
143 controller.onRequestCursorUpdates( 151 controller.onRequestCursorUpdates(
144 false /* immediate request */, true /* monitor request * /, view)); 152 false /* immediate request */, true /* monitor request * /, view));
145 153
146 // Make sure that the focused node is considered to be non-editable by d efault. 154 // Make sure that the focused node is considered to be non-editable by d efault.
147 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 155 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
148 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 156 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
149 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 157 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
150 true, true, 2.0f, 0.0f, 3.0f, view); 158 true, true, 2.0f, 0.0f, 3.0f, view);
151 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 159 Assert.assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
152 160
153 controller.focusedNodeChanged(false); 161 controller.focusedNodeChanged(false);
154 composingTextDelegate.clearTextAndSelection(controller); 162 composingTextDelegate.clearTextAndSelection(controller);
155 163
156 // Make sure that the controller does not crash even if it is called whi le the focused node 164 // Make sure that the controller does not crash even if it is called whi le the focused node
157 // is not editable. 165 // is not editable.
158 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}, view); 166 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}, view);
159 composingTextDelegate.updateTextAndSelection(controller, "1", 0, 1, 0, 1 ); 167 composingTextDelegate.updateTextAndSelection(controller, "1", 0, 1, 0, 1 );
160 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f), 168 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f),
161 true, true, 2.0f, 0.0f, 3.0f, view); 169 true, true, 2.0f, 0.0f, 3.0f, view);
162 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 170 Assert.assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
163 } 171 }
164 172
173 @Test
165 @SmallTest 174 @SmallTest
166 @Feature({"Input-Text-IME"}) 175 @Feature({"Input-Text-IME"})
167 public void testImmediateMode() { 176 public void testImmediateMode() {
168 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 177 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
169 TestViewDelegate viewDelegate = new TestViewDelegate(); 178 TestViewDelegate viewDelegate = new TestViewDelegate();
170 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 179 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
171 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 180 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
172 immw, composingTextDelegate, viewDelegate); 181 immw, composingTextDelegate, viewDelegate);
173 View view = null; 182 View view = null;
174 viewDelegate.locationX = 0; 183 viewDelegate.locationX = 0;
175 viewDelegate.locationY = 0; 184 viewDelegate.locationY = 0;
176 185
177 controller.focusedNodeChanged(true); 186 controller.focusedNodeChanged(true);
178 composingTextDelegate.clearTextAndSelection(controller); 187 composingTextDelegate.clearTextAndSelection(controller);
179 188
180 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes 189 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes
181 // available with #onUpdateFrameInfo(). 190 // available with #onUpdateFrameInfo().
182 assertTrue(controller.onRequestCursorUpdates( 191 Assert.assertTrue(controller.onRequestCursorUpdates(
183 true /* immediate request */, false /* monitor request */, view) ); 192 true /* immediate request */, false /* monitor request */, view) );
184 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 193 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
185 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 194 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
186 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 195 Assert.assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
187 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 196 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
188 true, true, 2.0f, 0.0f, 3.0f, view); 197 true, true, 2.0f, 0.0f, 3.0f, view);
189 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 198 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
190 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 199 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
191 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 200 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
192 3.0f, immw.getLastCursorAnchorInfo()); 201 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
193 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 202 Assert.assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
194 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 203 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
195 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 204 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
196 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 205 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
197 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 206 AssertionHelper.assertComposingText("0", 0, immw.getLastCursorAnchorInfo ());
198 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 207 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
199 immw.clearLastCursorAnchorInfo(); 208 immw.clearLastCursorAnchorInfo();
200 209
201 // Make sure that 2nd call of #onUpdateFrameInfo() is ignored. 210 // Make sure that 2nd call of #onUpdateFrameInfo() is ignored.
202 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f), 211 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f),
203 true, true, 2.0f, 0.0f, 3.0f, view); 212 true, true, 2.0f, 0.0f, 3.0f, view);
204 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 213 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
205 214
206 // Make sure that #onUpdateFrameInfo() is immediately called because the matrix info is 215 // Make sure that #onUpdateFrameInfo() is immediately called because the matrix info is
207 // already available. 216 // already available.
208 assertTrue(controller.onRequestCursorUpdates( 217 Assert.assertTrue(controller.onRequestCursorUpdates(
209 true /* immediate request */, false /* monitor request */, view) ); 218 true /* immediate request */, false /* monitor request */, view) );
210 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 219 Assert.assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
211 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 220 AssertionHelper.assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
212 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 221 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
213 3.0f, immw.getLastCursorAnchorInfo()); 222 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
214 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 223 Assert.assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
215 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 224 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
216 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 225 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
217 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 226 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
218 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 227 AssertionHelper.assertComposingText("0", 0, immw.getLastCursorAnchorInfo ());
219 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 228 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
220 immw.clearLastCursorAnchorInfo(); 229 immw.clearLastCursorAnchorInfo();
221 230
222 // Make sure that CURSOR_UPDATE_IMMEDIATE and CURSOR_UPDATE_MONITOR can be specified at 231 // Make sure that CURSOR_UPDATE_IMMEDIATE and CURSOR_UPDATE_MONITOR can be specified at
223 // the same time. 232 // the same time.
224 assertTrue(controller.onRequestCursorUpdates( 233 Assert.assertTrue(controller.onRequestCursorUpdates(
225 true /* immediate request*/, true /* monitor request */, view)); 234 true /* immediate request*/, true /* monitor request */, view));
226 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter()); 235 Assert.assertEquals(3, immw.getUpdateCursorAnchorInfoCounter());
227 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 236 AssertionHelper.assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
228 immw.clearLastCursorAnchorInfo(); 237 immw.clearLastCursorAnchorInfo();
229 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 238 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
230 true, true, 2.0f, 0.0f, 3.0f, view); 239 true, true, 2.0f, 0.0f, 3.0f, view);
231 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 240 Assert.assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
232 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 241 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
233 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 242 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
234 3.0f, immw.getLastCursorAnchorInfo()); 243 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
235 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 244 Assert.assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
236 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 245 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
237 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 246 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
238 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 247 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
239 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 248 AssertionHelper.assertComposingText("0", 0, immw.getLastCursorAnchorInfo ());
240 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 249 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
241 immw.clearLastCursorAnchorInfo(); 250 immw.clearLastCursorAnchorInfo();
242 251
243 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes 252 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes
244 // non-editable. 253 // non-editable.
245 controller.focusedNodeChanged(false); 254 controller.focusedNodeChanged(false);
246 controller.focusedNodeChanged(true); 255 controller.focusedNodeChanged(true);
247 composingTextDelegate.clearTextAndSelection(controller); 256 composingTextDelegate.clearTextAndSelection(controller);
248 assertTrue(controller.onRequestCursorUpdates( 257 Assert.assertTrue(controller.onRequestCursorUpdates(
249 true /* immediate request */, false /* monitor request */, view) ); 258 true /* immediate request */, false /* monitor request */, view) );
250 controller.focusedNodeChanged(false); 259 controller.focusedNodeChanged(false);
251 composingTextDelegate.clearTextAndSelection(controller); 260 composingTextDelegate.clearTextAndSelection(controller);
252 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f), 261 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 100.0f),
253 true, true, 2.0f, 0.0f, 3.0f, view); 262 true, true, 2.0f, 0.0f, 3.0f, view);
254 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 263 Assert.assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
255 264
256 // Make sure that CURSOR_UPDATE_IMMEDIATE can be enabled again. 265 // Make sure that CURSOR_UPDATE_IMMEDIATE can be enabled again.
257 controller.focusedNodeChanged(true); 266 controller.focusedNodeChanged(true);
258 composingTextDelegate.clearTextAndSelection(controller); 267 composingTextDelegate.clearTextAndSelection(controller);
259 assertTrue(controller.onRequestCursorUpdates( 268 Assert.assertTrue(controller.onRequestCursorUpdates(
260 true /* immediate request */, false /* monitor request */, view) ); 269 true /* immediate request */, false /* monitor request */, view) );
261 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 270 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
262 true, true, 2.0f, 0.0f, 3.0f, view); 271 true, true, 2.0f, 0.0f, 3.0f, view);
263 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 272 Assert.assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
264 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 273 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
265 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 274 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
266 3.0f, immw.getLastCursorAnchorInfo()); 275 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
267 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 276 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(0));
268 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 277 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(0));
269 assertComposingText(null, -1, immw.getLastCursorAnchorInfo()); 278 AssertionHelper.assertComposingText(null, -1, immw.getLastCursorAnchorIn fo());
270 assertSelection(-1, -1, immw.getLastCursorAnchorInfo()); 279 AssertionHelper.assertSelection(-1, -1, immw.getLastCursorAnchorInfo());
271 immw.clearLastCursorAnchorInfo(); 280 immw.clearLastCursorAnchorInfo();
272 } 281 }
273 282
283 @Test
274 @SmallTest 284 @SmallTest
275 @Feature({"Input-Text-IME"}) 285 @Feature({"Input-Text-IME"})
276 public void testMonitorMode() { 286 public void testMonitorMode() {
277 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 287 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
278 TestViewDelegate viewDelegate = new TestViewDelegate(); 288 TestViewDelegate viewDelegate = new TestViewDelegate();
279 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 289 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
280 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 290 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
281 immw, composingTextDelegate, viewDelegate); 291 immw, composingTextDelegate, viewDelegate);
282 View view = null; 292 View view = null;
283 viewDelegate.locationX = 0; 293 viewDelegate.locationX = 0;
284 viewDelegate.locationY = 0; 294 viewDelegate.locationY = 0;
285 295
286 controller.focusedNodeChanged(true); 296 controller.focusedNodeChanged(true);
287 composingTextDelegate.clearTextAndSelection(controller); 297 composingTextDelegate.clearTextAndSelection(controller);
288 298
289 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes 299 // Make sure that #updateCursorAnchorInfo() is not be called until the m atrix info becomes
290 // available with #onUpdateFrameInfo(). 300 // available with #onUpdateFrameInfo().
291 assertTrue(controller.onRequestCursorUpdates( 301 Assert.assertTrue(controller.onRequestCursorUpdates(
292 false /* immediate request */, true /* monitor request */, view) ); 302 false /* immediate request */, true /* monitor request */, view) );
293 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 303 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
294 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 304 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
295 assertEquals(0, immw.getUpdateCursorAnchorInfoCounter()); 305 Assert.assertEquals(0, immw.getUpdateCursorAnchorInfoCounter());
296 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 306 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
297 true, true, 2.0f, 0.0f, 3.0f, view); 307 true, true, 2.0f, 0.0f, 3.0f, view);
298 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 308 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
299 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 309 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
300 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 310 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
301 3.0f, immw.getLastCursorAnchorInfo()); 311 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
302 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 312 Assert.assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
303 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 313 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
304 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 314 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
305 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 315 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
306 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 316 AssertionHelper.assertComposingText("0", 0, immw.getLastCursorAnchorInfo ());
307 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 317 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
308 immw.clearLastCursorAnchorInfo(); 318 immw.clearLastCursorAnchorInfo();
309 319
310 // Make sure that #updateCursorAnchorInfo() is not be called if any coor dinate parameter is 320 // Make sure that #updateCursorAnchorInfo() is not be called if any coor dinate parameter is
311 // changed for better performance. 321 // changed for better performance.
312 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 322 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
313 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 323 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
314 true, true, 2.0f, 0.0f, 3.0f, view); 324 true, true, 2.0f, 0.0f, 3.0f, view);
315 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 325 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
316 326
317 // Make sure that #updateCursorAnchorInfo() is called if #setComposition CharacterBounds() 327 // Make sure that #updateCursorAnchorInfo() is called if #setComposition CharacterBounds()
318 // is called with a different parameter. 328 // is called with a different parameter.
319 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}, view); 329 controller.setCompositionCharacterBounds(new float[] {30.0f, 1.0f, 32.0f , 3.0f}, view);
320 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 330 Assert.assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
321 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 331 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
322 true, true, 2.0f, 0.0f, 3.0f, view); 332 true, true, 2.0f, 0.0f, 3.0f, view);
323 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 333 Assert.assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
324 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 334 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
325 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 335 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
326 3.0f, immw.getLastCursorAnchorInfo()); 336 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
327 assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f), 337 Assert.assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f),
328 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 338 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
329 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 339 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
330 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 340 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
331 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 341 AssertionHelper.assertComposingText("0", 0, immw.getLastCursorAnchorInfo ());
332 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 342 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
333 immw.clearLastCursorAnchorInfo(); 343 immw.clearLastCursorAnchorInfo();
334 344
335 // Make sure that #updateCursorAnchorInfo() is called if #updateTextAndS election() 345 // Make sure that #updateCursorAnchorInfo() is called if #updateTextAndS election()
336 // is called with a different parameter. 346 // is called with a different parameter.
337 composingTextDelegate.updateTextAndSelection(controller, "1", 0, 1, 0, 1 ); 347 composingTextDelegate.updateTextAndSelection(controller, "1", 0, 1, 0, 1 );
338 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 348 Assert.assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
339 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 349 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
340 true, true, 2.0f, 0.0f, 3.0f, view); 350 true, true, 2.0f, 0.0f, 3.0f, view);
341 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter()); 351 Assert.assertEquals(3, immw.getUpdateCursorAnchorInfoCounter());
342 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 352 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
343 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 353 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
344 3.0f, immw.getLastCursorAnchorInfo()); 354 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
345 assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f), 355 Assert.assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f),
346 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 356 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
347 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 357 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
348 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 358 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
349 assertComposingText("1", 0, immw.getLastCursorAnchorInfo()); 359 AssertionHelper.assertComposingText("1", 0, immw.getLastCursorAnchorInfo ());
350 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 360 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
351 immw.clearLastCursorAnchorInfo(); 361 immw.clearLastCursorAnchorInfo();
352 362
353 // Make sure that #updateCursorAnchorInfo() is called if #onUpdateFrameI nfo() 363 // Make sure that #updateCursorAnchorInfo() is called if #onUpdateFrameI nfo()
354 // is called with a different parameter. 364 // is called with a different parameter.
355 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f), 365 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f),
356 true, true, 2.0f, 0.0f, 3.0f, view); 366 true, true, 2.0f, 0.0f, 3.0f, view);
357 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 367 Assert.assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
358 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 368 AssertionHelper.assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
359 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 369 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
360 3.0f, immw.getLastCursorAnchorInfo()); 370 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
361 assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f), 371 Assert.assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f),
362 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 372 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
363 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 373 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
364 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 374 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
365 assertComposingText("1", 0, immw.getLastCursorAnchorInfo()); 375 AssertionHelper.assertComposingText("1", 0, immw.getLastCursorAnchorInfo ());
366 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 376 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
367 immw.clearLastCursorAnchorInfo(); 377 immw.clearLastCursorAnchorInfo();
368 378
369 // Make sure that #updateCursorAnchorInfo() is called when the view orig in is changed. 379 // Make sure that #updateCursorAnchorInfo() is called when the view orig in is changed.
370 viewDelegate.locationX = 7; 380 viewDelegate.locationX = 7;
371 viewDelegate.locationY = 9; 381 viewDelegate.locationY = 9;
372 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f), 382 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f),
373 true, true, 2.0f, 0.0f, 3.0f, view); 383 true, true, 2.0f, 0.0f, 3.0f, view);
374 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 384 Assert.assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
375 assertScaleAndTranslate(2.0f, 7.0f, 9.0f, immw.getLastCursorAnchorInfo() ); 385 AssertionHelper.assertScaleAndTranslate(2.0f, 7.0f, 9.0f, immw.getLastCu rsorAnchorInfo());
376 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 386 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
377 3.0f, immw.getLastCursorAnchorInfo()); 387 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
378 assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f), 388 Assert.assertEquals(new RectF(30.0f, 1.0f, 32.0f, 3.0f),
379 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 389 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
380 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 390 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
381 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 391 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
382 assertComposingText("1", 0, immw.getLastCursorAnchorInfo()); 392 AssertionHelper.assertComposingText("1", 0, immw.getLastCursorAnchorInfo ());
383 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 393 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
384 immw.clearLastCursorAnchorInfo(); 394 immw.clearLastCursorAnchorInfo();
385 395
386 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes 396 // Make sure that CURSOR_UPDATE_IMMEDIATE is cleared if the focused node becomes
387 // non-editable. 397 // non-editable.
388 controller.focusedNodeChanged(false); 398 controller.focusedNodeChanged(false);
389 controller.focusedNodeChanged(true); 399 controller.focusedNodeChanged(true);
390 composingTextDelegate.clearTextAndSelection(controller); 400 composingTextDelegate.clearTextAndSelection(controller);
391 assertTrue(controller.onRequestCursorUpdates( 401 Assert.assertTrue(controller.onRequestCursorUpdates(
392 false /* immediate request */, true /* monitor request */, view) ); 402 false /* immediate request */, true /* monitor request */, view) );
393 controller.focusedNodeChanged(false); 403 controller.focusedNodeChanged(false);
394 composingTextDelegate.clearTextAndSelection(controller); 404 composingTextDelegate.clearTextAndSelection(controller);
395 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 405 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
396 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 406 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
397 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 407 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
398 true, true, 2.0f, 0.0f, 3.0f, view); 408 true, true, 2.0f, 0.0f, 3.0f, view);
399 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 409 Assert.assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
400 410
401 // Make sure that CURSOR_UPDATE_MONITOR can be enabled again. 411 // Make sure that CURSOR_UPDATE_MONITOR can be enabled again.
402 controller.focusedNodeChanged(true); 412 controller.focusedNodeChanged(true);
403 composingTextDelegate.clearTextAndSelection(controller); 413 composingTextDelegate.clearTextAndSelection(controller);
404 assertTrue(controller.onRequestCursorUpdates( 414 Assert.assertTrue(controller.onRequestCursorUpdates(
405 false /* immediate request */, true /* monitor request */, view) ); 415 false /* immediate request */, true /* monitor request */, view) );
406 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view); 416 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f}, view);
407 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 ); 417 composingTextDelegate.updateTextAndSelection(controller, "0", 0, 1, 0, 1 );
408 assertEquals(5, immw.getUpdateCursorAnchorInfoCounter()); 418 Assert.assertEquals(5, immw.getUpdateCursorAnchorInfoCounter());
409 viewDelegate.locationX = 0; 419 viewDelegate.locationX = 0;
410 viewDelegate.locationY = 0; 420 viewDelegate.locationY = 0;
411 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 421 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
412 true, true, 2.0f, 0.0f, 3.0f, view); 422 true, true, 2.0f, 0.0f, 3.0f, view);
413 assertEquals(6, immw.getUpdateCursorAnchorInfoCounter()); 423 Assert.assertEquals(6, immw.getUpdateCursorAnchorInfoCounter());
414 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 424 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
415 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 2.0f, 0.0f, 3.0f, 425 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 2.0f,
416 3.0f, immw.getLastCursorAnchorInfo()); 426 0.0f, 3.0f, 3.0f, immw.getLastCursorAnchorInfo());
417 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 427 Assert.assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
418 immw.getLastCursorAnchorInfo().getCharacterBounds(0)); 428 immw.getLastCursorAnchorInfo().getCharacterBounds(0));
419 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 429 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
420 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0)); 430 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0));
421 assertComposingText("0", 0, immw.getLastCursorAnchorInfo()); 431 AssertionHelper.assertComposingText("0", 0, immw.getLastCursorAnchorInfo ());
422 assertSelection(0, 1, immw.getLastCursorAnchorInfo()); 432 AssertionHelper.assertSelection(0, 1, immw.getLastCursorAnchorInfo());
423 immw.clearLastCursorAnchorInfo(); 433 immw.clearLastCursorAnchorInfo();
424 } 434 }
425 435
436 @Test
426 @SmallTest 437 @SmallTest
427 @Feature({"Input-Text-IME"}) 438 @Feature({"Input-Text-IME"})
428 public void testSetCompositionCharacterBounds() { 439 public void testSetCompositionCharacterBounds() {
429 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 440 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
430 TestViewDelegate viewDelegate = new TestViewDelegate(); 441 TestViewDelegate viewDelegate = new TestViewDelegate();
431 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 442 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
432 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 443 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
433 immw, composingTextDelegate, viewDelegate); 444 immw, composingTextDelegate, viewDelegate);
434 View view = null; 445 View view = null;
435 446
436 viewDelegate.locationX = 0; 447 viewDelegate.locationX = 0;
437 viewDelegate.locationY = 0; 448 viewDelegate.locationY = 0;
438 449
439 controller.focusedNodeChanged(true); 450 controller.focusedNodeChanged(true);
440 composingTextDelegate.clearTextAndSelection(controller); 451 composingTextDelegate.clearTextAndSelection(controller);
441 assertTrue(controller.onRequestCursorUpdates( 452 Assert.assertTrue(controller.onRequestCursorUpdates(
442 false /* immediate request */, true /* monitor request */, view) ); 453 false /* immediate request */, true /* monitor request */, view) );
443 454
444 composingTextDelegate.updateTextAndSelection(controller, "01234", 1, 3, 1, 1); 455 composingTextDelegate.updateTextAndSelection(controller, "01234", 1, 3, 1, 1);
445 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f, 456 controller.setCompositionCharacterBounds(new float[] {0.0f, 1.0f, 2.0f, 3.0f,
446 4.0f, 1.1f, 6.0f, 2.9f}, view); 457 4.0f, 1.1f, 6.0f, 2.9f}, view);
447 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 458 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
448 false, false, Float.NaN, Float.NaN, Float.NaN, view); 459 false, false, Float.NaN, Float.NaN, Float.NaN, view);
449 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 460 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
450 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 461 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(0));
451 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 462 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(0));
452 assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f), 463 Assert.assertEquals(new RectF(0.0f, 1.0f, 2.0f, 3.0f),
453 immw.getLastCursorAnchorInfo().getCharacterBounds(1)); 464 immw.getLastCursorAnchorInfo().getCharacterBounds(1));
454 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 465 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
455 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1)); 466 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1));
456 assertEquals(new RectF(4.0f, 1.1f, 6.0f, 2.9f), 467 Assert.assertEquals(new RectF(4.0f, 1.1f, 6.0f, 2.9f),
457 immw.getLastCursorAnchorInfo().getCharacterBounds(2)); 468 immw.getLastCursorAnchorInfo().getCharacterBounds(2));
458 assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 469 Assert.assertEquals(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION,
459 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(2)); 470 immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(2));
460 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(3)) ; 471 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(3));
461 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(3 )); 472 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(3));
462 assertComposingText("12", 1, immw.getLastCursorAnchorInfo()); 473 AssertionHelper.assertComposingText("12", 1, immw.getLastCursorAnchorInf o());
463 assertSelection(1, 1, immw.getLastCursorAnchorInfo()); 474 AssertionHelper.assertSelection(1, 1, immw.getLastCursorAnchorInfo());
464 } 475 }
465 476
477 @Test
466 @SmallTest 478 @SmallTest
467 @Feature({"Input-Text-IME"}) 479 @Feature({"Input-Text-IME"})
468 public void testUpdateTextAndSelection() { 480 public void testUpdateTextAndSelection() {
469 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 481 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
470 TestViewDelegate viewDelegate = new TestViewDelegate(); 482 TestViewDelegate viewDelegate = new TestViewDelegate();
471 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 483 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
472 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 484 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
473 immw, composingTextDelegate, viewDelegate); 485 immw, composingTextDelegate, viewDelegate);
474 View view = null; 486 View view = null;
475 487
476 viewDelegate.locationX = 0; 488 viewDelegate.locationX = 0;
477 viewDelegate.locationY = 0; 489 viewDelegate.locationY = 0;
478 490
479 controller.focusedNodeChanged(true); 491 controller.focusedNodeChanged(true);
480 composingTextDelegate.clearTextAndSelection(controller); 492 composingTextDelegate.clearTextAndSelection(controller);
481 assertTrue(controller.onRequestCursorUpdates( 493 Assert.assertTrue(controller.onRequestCursorUpdates(
482 false /* immediate request */, true /* monitor request */, view) ); 494 false /* immediate request */, true /* monitor request */, view) );
483 495
484 composingTextDelegate.updateTextAndSelection(controller, "01234", 3, 3, 1, 1); 496 composingTextDelegate.updateTextAndSelection(controller, "01234", 3, 3, 1, 1);
485 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 497 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
486 false, false, Float.NaN, Float.NaN, Float.NaN, view); 498 false, false, Float.NaN, Float.NaN, Float.NaN, view);
487 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 499 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
488 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(0)) ; 500 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(0));
489 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(0 )); 501 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(0));
490 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(1)) ; 502 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(1));
491 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(1 )); 503 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(1));
492 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(2)) ; 504 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(2));
493 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(2 )); 505 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(2));
494 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(3)) ; 506 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(3));
495 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(3 )); 507 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(3));
496 assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBounds(4)) ; 508 Assert.assertEquals(null, immw.getLastCursorAnchorInfo().getCharacterBou nds(4));
497 assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBoundsFlags(4 )); 509 Assert.assertEquals(0, immw.getLastCursorAnchorInfo().getCharacterBounds Flags(4));
498 assertComposingText("", 3, immw.getLastCursorAnchorInfo()); 510 AssertionHelper.assertComposingText("", 3, immw.getLastCursorAnchorInfo( ));
499 assertSelection(1, 1, immw.getLastCursorAnchorInfo()); 511 AssertionHelper.assertSelection(1, 1, immw.getLastCursorAnchorInfo());
500 } 512 }
501 513
514 @Test
502 @SmallTest 515 @SmallTest
503 @Feature({"Input-Text-IME"}) 516 @Feature({"Input-Text-IME"})
504 public void testInsertionMarker() { 517 public void testInsertionMarker() {
505 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 518 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
506 TestViewDelegate viewDelegate = new TestViewDelegate(); 519 TestViewDelegate viewDelegate = new TestViewDelegate();
507 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 520 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
508 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 521 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
509 immw, composingTextDelegate, viewDelegate); 522 immw, composingTextDelegate, viewDelegate);
510 View view = null; 523 View view = null;
511 524
512 controller.focusedNodeChanged(true); 525 controller.focusedNodeChanged(true);
513 composingTextDelegate.clearTextAndSelection(controller); 526 composingTextDelegate.clearTextAndSelection(controller);
514 assertTrue(controller.onRequestCursorUpdates( 527 Assert.assertTrue(controller.onRequestCursorUpdates(
515 false /* immediate request */, true /* monitor request */, view) ); 528 false /* immediate request */, true /* monitor request */, view) );
516 529
517 // Test no insertion marker. 530 // Test no insertion marker.
518 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 531 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
519 false, false, Float.NaN, Float.NaN, Float.NaN, view); 532 false, false, Float.NaN, Float.NaN, Float.NaN, view);
520 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 533 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
521 assertHasNoInsertionMarker(immw.getLastCursorAnchorInfo()); 534 AssertionHelper.assertHasNoInsertionMarker(immw.getLastCursorAnchorInfo( ));
522 immw.clearLastCursorAnchorInfo(); 535 immw.clearLastCursorAnchorInfo();
523 536
524 // Test a visible insertion marker. 537 // Test a visible insertion marker.
525 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 538 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
526 true, true, 10.0f, 23.0f, 29.0f, view); 539 true, true, 10.0f, 23.0f, 29.0f, view);
527 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 540 Assert.assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
528 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIBLE_REGION, 541 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_VISIB LE_REGION, 10.0f,
529 10.0f, 23.0f, 29.0f, 29.0f, immw.getLastCursorAnchorInfo()); 542 23.0f, 29.0f, 29.0f, immw.getLastCursorAnchorInfo());
530 immw.clearLastCursorAnchorInfo(); 543 immw.clearLastCursorAnchorInfo();
531 544
532 // Test a invisible insertion marker. 545 // Test a invisible insertion marker.
533 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 546 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
534 true, false, 10.0f, 23.0f, 29.0f, view); 547 true, false, 10.0f, 23.0f, 29.0f, view);
535 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter()); 548 Assert.assertEquals(3, immw.getUpdateCursorAnchorInfoCounter());
536 assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_INVISIBLE_REGION, 549 AssertionHelper.assertHasInsertionMarker(CursorAnchorInfo.FLAG_HAS_INVIS IBLE_REGION, 10.0f,
537 10.0f, 23.0f, 29.0f, 29.0f, immw.getLastCursorAnchorInfo()); 550 23.0f, 29.0f, 29.0f, immw.getLastCursorAnchorInfo());
538 immw.clearLastCursorAnchorInfo(); 551 immw.clearLastCursorAnchorInfo();
539 } 552 }
540 553
554 @Test
541 @SmallTest 555 @SmallTest
542 @Feature({"Input-Text-IME"}) 556 @Feature({"Input-Text-IME"})
543 public void testMatrix() { 557 public void testMatrix() {
544 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull); 558 TestInputMethodManagerWrapper immw = new TestInputMethodManagerWrapper(n ull);
545 TestViewDelegate viewDelegate = new TestViewDelegate(); 559 TestViewDelegate viewDelegate = new TestViewDelegate();
546 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate(); 560 TestComposingTextDelegate composingTextDelegate = new TestComposingTextD elegate();
547 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest( 561 CursorAnchorInfoController controller = CursorAnchorInfoController.creat eForTest(
548 immw, composingTextDelegate, viewDelegate); 562 immw, composingTextDelegate, viewDelegate);
549 View view = null; 563 View view = null;
550 564
551 controller.focusedNodeChanged(true); 565 controller.focusedNodeChanged(true);
552 composingTextDelegate.clearTextAndSelection(controller); 566 composingTextDelegate.clearTextAndSelection(controller);
553 assertTrue(controller.onRequestCursorUpdates( 567 Assert.assertTrue(controller.onRequestCursorUpdates(
554 false /* immediate request */, true /* monitor request */, view) ); 568 false /* immediate request */, true /* monitor request */, view) );
555 569
556 // Test no transformation 570 // Test no transformation
557 viewDelegate.locationX = 0; 571 viewDelegate.locationX = 0;
558 viewDelegate.locationY = 0; 572 viewDelegate.locationY = 0;
559 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f), 573 controller.onUpdateFrameInfo(createRenderCoordinates(1.0f, 0.0f),
560 false, false, Float.NaN, Float.NaN, Float.NaN, view); 574 false, false, Float.NaN, Float.NaN, Float.NaN, view);
561 assertEquals(1, immw.getUpdateCursorAnchorInfoCounter()); 575 Assert.assertEquals(1, immw.getUpdateCursorAnchorInfoCounter());
562 assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 576 AssertionHelper.assertScaleAndTranslate(1.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
563 immw.clearLastCursorAnchorInfo(); 577 immw.clearLastCursorAnchorInfo();
564 578
565 // device scale factor == 2.0 579 // device scale factor == 2.0
566 viewDelegate.locationX = 0; 580 viewDelegate.locationX = 0;
567 viewDelegate.locationY = 0; 581 viewDelegate.locationY = 0;
568 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f), 582 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f),
569 false, false, Float.NaN, Float.NaN, Float.NaN, view); 583 false, false, Float.NaN, Float.NaN, Float.NaN, view);
570 assertEquals(2, immw.getUpdateCursorAnchorInfoCounter()); 584 Assert.assertEquals(2, immw.getUpdateCursorAnchorInfoCounter());
571 assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCursorAnchorInfo() ); 585 AssertionHelper.assertScaleAndTranslate(2.0f, 0.0f, 0.0f, immw.getLastCu rsorAnchorInfo());
572 immw.clearLastCursorAnchorInfo(); 586 immw.clearLastCursorAnchorInfo();
573 587
574 // device scale factor == 2.0 588 // device scale factor == 2.0
575 // view origin == (10, 141) 589 // view origin == (10, 141)
576 viewDelegate.locationX = 10; 590 viewDelegate.locationX = 10;
577 viewDelegate.locationY = 141; 591 viewDelegate.locationY = 141;
578 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f), 592 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 0.0f),
579 false, false, Float.NaN, Float.NaN, Float.NaN, view); 593 false, false, Float.NaN, Float.NaN, Float.NaN, view);
580 assertEquals(3, immw.getUpdateCursorAnchorInfoCounter()); 594 Assert.assertEquals(3, immw.getUpdateCursorAnchorInfoCounter());
581 assertScaleAndTranslate(2.0f, 10.0f, 141.0f, immw.getLastCursorAnchorInf o()); 595 AssertionHelper.assertScaleAndTranslate(
596 2.0f, 10.0f, 141.0f, immw.getLastCursorAnchorInfo());
582 immw.clearLastCursorAnchorInfo(); 597 immw.clearLastCursorAnchorInfo();
583 598
584 // device scale factor == 2.0 599 // device scale factor == 2.0
585 // content offset Y = 40.0f 600 // content offset Y = 40.0f
586 // view origin == (10, 141) 601 // view origin == (10, 141)
587 viewDelegate.locationX = 10; 602 viewDelegate.locationX = 10;
588 viewDelegate.locationY = 141; 603 viewDelegate.locationY = 141;
589 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 40.0f), 604 controller.onUpdateFrameInfo(createRenderCoordinates(2.0f, 40.0f),
590 false, false, Float.NaN, Float.NaN, Float.NaN, view); 605 false, false, Float.NaN, Float.NaN, Float.NaN, view);
591 assertEquals(4, immw.getUpdateCursorAnchorInfoCounter()); 606 Assert.assertEquals(4, immw.getUpdateCursorAnchorInfoCounter());
592 assertScaleAndTranslate(2.0f, 10.0f, 181.0f, immw.getLastCursorAnchorInf o()); 607 AssertionHelper.assertScaleAndTranslate(
608 2.0f, 10.0f, 181.0f, immw.getLastCursorAnchorInfo());
593 immw.clearLastCursorAnchorInfo(); 609 immw.clearLastCursorAnchorInfo();
594 } 610 }
595 } 611 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698