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

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

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

Powered by Google App Engine
This is Rietveld 408576698