1 /* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text.method.cts; 18 19 import dalvik.annotation.TestLevel; 20 import dalvik.annotation.TestTargetClass; 21 import dalvik.annotation.TestTargetNew; 22 import dalvik.annotation.TestTargets; 23 import dalvik.annotation.ToBeFixed; 24 25 import android.test.AndroidTestCase; 26 import android.text.Editable; 27 import android.text.Selection; 28 import android.text.Spannable; 29 import android.text.Spanned; 30 import android.text.method.DateKeyListener; 31 import android.text.method.MetaKeyKeyListener; 32 import android.view.KeyEvent; 33 import android.view.View; 34 import android.widget.ImageView; 35 36 /** 37 * Test {@link MetaKeyKeyListener}. 38 */ 39 @TestTargetClass(MetaKeyKeyListener.class) 40 public class MetaKeyKeyListenerTest extends AndroidTestCase { 41 @TestTargetNew( 42 level = TestLevel.COMPLETE, 43 method = "onKeyDown", 44 args = {android.view.View.class, android.text.Editable.class, int.class, 45 android.view.KeyEvent.class} 46 ) testPressKey()47 public void testPressKey() { 48 final CharSequence str = "123456"; 49 final MetaKeyKeyListener numberKeyListener = new DateKeyListener(); 50 final View view = new ImageView(getContext()); 51 final Editable content = Editable.Factory.getInstance().newEditable(str); 52 53 content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 54 content.setSpan(Selection.SELECTION_END, 0, 0, Spanned.SPAN_POINT_POINT); 55 numberKeyListener.onKeyDown(view, content, KeyEvent.KEYCODE_0, 56 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0)); 57 assertEquals('0', content.charAt(0)); 58 59 content.setSpan(Selection.SELECTION_START, 1, 1, Spanned.SPAN_POINT_POINT); 60 content.setSpan(Selection.SELECTION_END, 1, 1, Spanned.SPAN_POINT_POINT); 61 numberKeyListener.onKeyDown(view, content, KeyEvent.KEYCODE_2, 62 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_2)); 63 assertEquals('2', content.charAt(1)); 64 65 content.setSpan(Selection.SELECTION_START, 3, 3, Spanned.SPAN_POINT_POINT); 66 content.setSpan(Selection.SELECTION_END, 3, 3, Spanned.SPAN_POINT_POINT); 67 numberKeyListener.onKeyDown(view, content, KeyEvent.KEYCODE_3, 68 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_3)); 69 assertEquals('3', content.charAt(3)); 70 } 71 72 @TestTargetNew( 73 level = TestLevel.COMPLETE, 74 method = "onKeyUp", 75 args = {android.view.View.class, android.text.Editable.class, int.class, 76 android.view.KeyEvent.class} 77 ) testReleaseKey()78 public void testReleaseKey() { 79 final CharSequence str = "123456"; 80 final MetaKeyKeyListener numberKeyListener = new DateKeyListener(); 81 final View view = new ImageView(getContext()); 82 final Editable content = Editable.Factory.getInstance().newEditable(str); 83 84 content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 85 content.setSpan(Selection.SELECTION_END, 0, 0, Spanned.SPAN_POINT_POINT); 86 numberKeyListener.onKeyUp(view, content, KeyEvent.KEYCODE_0, 87 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_0)); 88 assertEquals(str.charAt(0), content.charAt(0)); 89 90 content.setSpan(Selection.SELECTION_START, 1, 1, Spanned.SPAN_POINT_POINT); 91 content.setSpan(Selection.SELECTION_END, 1, 1, Spanned.SPAN_POINT_POINT); 92 numberKeyListener.onKeyUp(view, content, KeyEvent.KEYCODE_2, 93 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_2)); 94 assertEquals(str.charAt(1), content.charAt(1)); 95 96 content.setSpan(Selection.SELECTION_START, 3, 3, Spanned.SPAN_POINT_POINT); 97 content.setSpan(Selection.SELECTION_END, 3, 3, Spanned.SPAN_POINT_POINT); 98 numberKeyListener.onKeyUp(view, content, KeyEvent.KEYCODE_3, 99 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_3)); 100 assertEquals(str.charAt(3), content.charAt(3)); 101 } 102 103 @TestTargetNew( 104 level = TestLevel.COMPLETE, 105 method = "adjustMetaAfterKeypress", 106 args = {android.text.Spannable.class} 107 ) testAdjustMetaAfterKeypress()108 public void testAdjustMetaAfterKeypress() { 109 CharSequence str = "123456"; 110 Spannable content = Editable.Factory.getInstance().newEditable(str); 111 content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 112 int len = str.length(); // for one line less than 100 113 content.setSpan( Selection.SELECTION_END, len, len, Spanned.SPAN_POINT_POINT); 114 MetaKeyKeyListener.adjustMetaAfterKeypress(content); 115 assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_START)); 116 assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END)); 117 118 str = "abc"; 119 content = Editable.Factory.getInstance().newEditable(str); 120 content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 121 len = str.length(); // for one line less than 100 122 content.setSpan( Selection.SELECTION_END, len, len, Spanned.SPAN_POINT_POINT); 123 MetaKeyKeyListener.adjustMetaAfterKeypress(content); 124 assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_START)); 125 assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END)); 126 127 str = "#@%#$^%^"; 128 content = Editable.Factory.getInstance().newEditable(str); 129 content.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 130 len = str.length(); // for one line less than 100 131 content.setSpan( Selection.SELECTION_END, len, len, Spanned.SPAN_POINT_POINT); 132 MetaKeyKeyListener.adjustMetaAfterKeypress(content); 133 assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_START)); 134 assertEquals(Spanned.SPAN_POINT_POINT, content.getSpanFlags(Selection.SELECTION_END)); 135 } 136 137 @TestTargetNew( 138 level = TestLevel.COMPLETE, 139 method = "adjustMetaAfterKeypress", 140 args = {long.class} 141 ) testAdjustMetaAfterKeypress2()142 public void testAdjustMetaAfterKeypress2() { 143 long state = MetaKeyKeyListener.adjustMetaAfterKeypress(MetaKeyKeyListener.META_SHIFT_ON); 144 assertEquals(MetaKeyKeyListener.META_SHIFT_ON, state); 145 146 state = MetaKeyKeyListener.adjustMetaAfterKeypress(MetaKeyKeyListener.META_ALT_ON); 147 assertEquals(MetaKeyKeyListener.META_ALT_ON, state); 148 149 state = MetaKeyKeyListener.adjustMetaAfterKeypress(MetaKeyKeyListener.META_SYM_ON); 150 assertEquals(MetaKeyKeyListener.META_SYM_ON, state); 151 152 state = MetaKeyKeyListener.adjustMetaAfterKeypress(0); 153 assertEquals(0, state); 154 } 155 156 @TestTargetNew( 157 level = TestLevel.COMPLETE, 158 method = "resetMetaState", 159 args = {android.text.Spannable.class} 160 ) testResetMetaState()161 public void testResetMetaState() { 162 CharSequence str = "123456"; 163 Spannable text = Editable.Factory.getInstance().newEditable(str); 164 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 165 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 166 MetaKeyKeyListener.resetMetaState(text); 167 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 168 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 169 170 str = "abc"; 171 text = Editable.Factory.getInstance().newEditable(str); 172 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 173 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 174 MetaKeyKeyListener.resetMetaState(text); 175 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 176 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 177 178 str = "#@%#$^%^"; 179 text = Editable.Factory.getInstance().newEditable(str); 180 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 181 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 182 MetaKeyKeyListener.resetMetaState(text); 183 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 184 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 185 } 186 187 @TestTargets({ 188 @TestTargetNew( 189 level = TestLevel.COMPLETE, 190 method = "getMetaState", 191 args = {java.lang.CharSequence.class} 192 ), 193 @TestTargetNew( 194 level = TestLevel.COMPLETE, 195 method = "getMetaState", 196 args = {java.lang.CharSequence.class, int.class} 197 ) 198 }) testGetMetaState()199 public void testGetMetaState() { 200 assertEquals(0, MetaKeyKeyListener.getMetaState("123456")); 201 assertEquals(0, MetaKeyKeyListener.getMetaState("abc")); 202 assertEquals(0, MetaKeyKeyListener.getMetaState("@#$$#^$^")); 203 204 assertEquals(0, 205 MetaKeyKeyListener.getMetaState("123456"), 206 MetaKeyKeyListener.META_SHIFT_ON); 207 assertEquals(0, 208 MetaKeyKeyListener.getMetaState("abc"), 209 MetaKeyKeyListener.META_ALT_ON); 210 assertEquals(0, 211 MetaKeyKeyListener.getMetaState("@#$$#^$^"), 212 MetaKeyKeyListener.META_SYM_ON); 213 214 assertEquals(0, MetaKeyKeyListener.getMetaState("123456", 0)); 215 assertEquals(0, MetaKeyKeyListener.getMetaState("abc", -1)); 216 assertEquals(0, MetaKeyKeyListener.getMetaState("@#$$#^$^", Integer.MAX_VALUE)); 217 218 assertEquals(0, 219 MetaKeyKeyListener.getMetaState("123456", MetaKeyKeyListener.META_SHIFT_ON)); 220 assertEquals(0, MetaKeyKeyListener.getMetaState("abc", MetaKeyKeyListener.META_ALT_ON)); 221 assertEquals(0, 222 MetaKeyKeyListener.getMetaState("@#$$#^$^", MetaKeyKeyListener.META_SYM_ON)); 223 } 224 225 @TestTargets({ 226 @TestTargetNew( 227 level = TestLevel.COMPLETE, 228 method = "getMetaState", 229 args = {long.class} 230 ), 231 @TestTargetNew( 232 level = TestLevel.COMPLETE, 233 method = "getMetaState", 234 args = {long.class, int.class} 235 ) 236 }) testGetMetaState2()237 public void testGetMetaState2() { 238 assertEquals(0, MetaKeyKeyListener.getMetaState(0)); 239 assertEquals(MetaKeyKeyListener.META_SHIFT_ON, 240 MetaKeyKeyListener.getMetaState(MetaKeyKeyListener.META_SHIFT_ON)); 241 assertEquals(MetaKeyKeyListener.META_CAP_LOCKED, 242 MetaKeyKeyListener.getMetaState(MetaKeyKeyListener.META_CAP_LOCKED)); 243 244 assertEquals(0, MetaKeyKeyListener.getMetaState(0, MetaKeyKeyListener.META_SYM_ON)); 245 assertEquals(1, MetaKeyKeyListener.getMetaState(MetaKeyKeyListener.META_SYM_ON, 246 MetaKeyKeyListener.META_SYM_ON)); 247 assertEquals(2, MetaKeyKeyListener.getMetaState(MetaKeyKeyListener.META_SYM_LOCKED, 248 MetaKeyKeyListener.META_SYM_ON)); 249 } 250 251 @TestTargetNew( 252 level = TestLevel.COMPLETE, 253 method = "isMetaTracker", 254 args = {java.lang.CharSequence.class, java.lang.Object.class} 255 ) testIsMetaTracker()256 public void testIsMetaTracker() { 257 assertFalse(MetaKeyKeyListener.isMetaTracker("123456", new Object())); 258 assertFalse(MetaKeyKeyListener.isMetaTracker("abc", new Object())); 259 assertFalse(MetaKeyKeyListener.isMetaTracker("@#$$#^$^", new Object())); 260 } 261 262 @TestTargetNew( 263 level = TestLevel.COMPLETE, 264 method = "isSelectingMetaTracker", 265 args = {java.lang.CharSequence.class, java.lang.Object.class} 266 ) testIsSelectingMetaTracker()267 public void testIsSelectingMetaTracker() { 268 assertFalse(MetaKeyKeyListener.isSelectingMetaTracker("123456", new Object())); 269 assertFalse(MetaKeyKeyListener.isSelectingMetaTracker("abc", new Object())); 270 assertFalse(MetaKeyKeyListener.isSelectingMetaTracker("@#$$#^$^", new Object())); 271 } 272 273 @TestTargetNew( 274 level = TestLevel.COMPLETE, 275 method = "resetLockedMeta", 276 args = {android.text.Spannable.class} 277 ) 278 @ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete. @throws clause " 279 + "should be added into javadoc") testResetLockedMeta()280 public void testResetLockedMeta() { 281 MockMetaKeyKeyListener mockMetaKeyKeyListener = new MockMetaKeyKeyListener(); 282 283 MockSpannable str = new MockSpannable(); 284 str.setSpan(new Object(), 0, 0, Spannable.SPAN_MARK_MARK 285 | (4 << Spannable.SPAN_USER_SHIFT)); 286 assertFalse(str.hasCalledRemoveSpan()); 287 mockMetaKeyKeyListener.callResetLockedMeta(str); 288 assertTrue(str.hasCalledRemoveSpan()); 289 290 str = new MockSpannable(); 291 str.setSpan(new Object(), 0, 0, Spannable.SPAN_MARK_POINT); 292 assertFalse(str.hasCalledRemoveSpan()); 293 mockMetaKeyKeyListener.callResetLockedMeta(str); 294 assertFalse(str.hasCalledRemoveSpan()); 295 296 try { 297 mockMetaKeyKeyListener.callResetLockedMeta(null); 298 fail("should throw NullPointerException."); 299 } catch (NullPointerException e) { 300 } 301 } 302 303 @TestTargetNew( 304 level = TestLevel.COMPLETE, 305 method = "resetLockedMeta", 306 args = {long.class} 307 ) testResetLockedMeta2()308 public void testResetLockedMeta2() { 309 long state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_CAP_LOCKED); 310 assertEquals(0, state); 311 312 state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_SHIFT_ON); 313 assertEquals(MetaKeyKeyListener.META_SHIFT_ON, state); 314 315 state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_ALT_LOCKED); 316 assertEquals(0, state); 317 318 state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_ALT_ON); 319 assertEquals(MetaKeyKeyListener.META_ALT_ON, state); 320 321 state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_SYM_LOCKED); 322 assertEquals(0, state); 323 324 state = MetaKeyKeyListener.resetLockedMeta(MetaKeyKeyListener.META_SYM_ON); 325 assertEquals(MetaKeyKeyListener.META_SYM_ON, state); 326 } 327 328 @TestTargetNew( 329 level = TestLevel.COMPLETE, 330 method = "clearMetaKeyState", 331 args = {android.view.View.class, android.text.Editable.class, int.class} 332 ) testClearMetaKeyState()333 public void testClearMetaKeyState() { 334 final MetaKeyKeyListener numberKeyListener = new DateKeyListener(); 335 CharSequence str = "123456"; 336 Editable text = Editable.Factory.getInstance().newEditable(str); 337 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 338 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 339 numberKeyListener.clearMetaKeyState(null, text, MetaKeyKeyListener.META_SHIFT_ON); 340 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 341 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 342 343 str = "abc"; 344 text = Editable.Factory.getInstance().newEditable(str); 345 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 346 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 347 numberKeyListener.clearMetaKeyState(null, text, MetaKeyKeyListener.META_ALT_ON); 348 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 349 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 350 351 str = "#@%#$^%^"; 352 text = Editable.Factory.getInstance().newEditable(str); 353 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 354 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 355 numberKeyListener.clearMetaKeyState(null, text, MetaKeyKeyListener.META_SYM_ON); 356 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 357 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 358 } 359 360 @TestTargetNew( 361 level = TestLevel.COMPLETE, 362 method = "clearMetaKeyState", 363 args = {android.text.Editable.class, int.class} 364 ) testClearMetaKeyState2()365 public void testClearMetaKeyState2() { 366 CharSequence str = "123456"; 367 Editable text = Editable.Factory.getInstance().newEditable(str); 368 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 369 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 370 MetaKeyKeyListener.clearMetaKeyState(text, MetaKeyKeyListener.META_SHIFT_ON); 371 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 372 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 373 374 str = "abc"; 375 text = Editable.Factory.getInstance().newEditable(str); 376 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 377 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 378 MetaKeyKeyListener.clearMetaKeyState(text, MetaKeyKeyListener.META_ALT_ON); 379 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 380 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 381 382 str = "#@%#$^%^"; 383 text = Editable.Factory.getInstance().newEditable(str); 384 text.setSpan(Selection.SELECTION_START, 0, 0, Spanned.SPAN_POINT_POINT); 385 text.setSpan(Selection.SELECTION_END, str.length(), str.length(), Spanned.SPAN_POINT_POINT); 386 MetaKeyKeyListener.clearMetaKeyState(text, MetaKeyKeyListener.META_SYM_ON); 387 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_START)); 388 assertEquals(Spanned.SPAN_POINT_POINT, text.getSpanFlags(Selection.SELECTION_END)); 389 } 390 391 @TestTargetNew( 392 level = TestLevel.COMPLETE, 393 method = "clearMetaKeyState", 394 args = {long.class, int.class} 395 ) testClearMetaKeyState3()396 public void testClearMetaKeyState3() { 397 final MetaKeyKeyListener metaKeyKeyListener = new MetaKeyKeyListener() {}; 398 long state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_CAP_LOCKED, 399 MetaKeyKeyListener.META_SHIFT_ON); 400 assertEquals(0, state); 401 402 state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_SHIFT_ON, 403 MetaKeyKeyListener.META_SHIFT_ON); 404 assertEquals(MetaKeyKeyListener.META_SHIFT_ON, state); 405 406 state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_ALT_LOCKED, 407 MetaKeyKeyListener.META_ALT_ON); 408 assertEquals(0, state); 409 410 state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_ALT_ON, 411 MetaKeyKeyListener.META_ALT_ON); 412 assertEquals(MetaKeyKeyListener.META_ALT_ON, state); 413 414 state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_SYM_LOCKED, 415 MetaKeyKeyListener.META_SYM_ON); 416 assertEquals(0, state); 417 418 state = metaKeyKeyListener.clearMetaKeyState(MetaKeyKeyListener.META_SYM_ON, 419 MetaKeyKeyListener.META_SYM_ON); 420 assertEquals(MetaKeyKeyListener.META_SYM_ON, state); 421 } 422 423 @TestTargetNew( 424 level = TestLevel.PARTIAL, 425 method = "handleKeyDown", 426 args = {long.class, int.class, KeyEvent.class} 427 ) testHandleKeyDown()428 public void testHandleKeyDown() { 429 long state = MetaKeyKeyListener.handleKeyDown(MetaKeyKeyListener.META_CAP_LOCKED, 430 KeyEvent.KEYCODE_SHIFT_LEFT, 431 new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_SHIFT_LEFT)); 432 assertEquals(0, state); 433 } 434 435 @TestTargetNew( 436 level = TestLevel.PARTIAL, 437 method = "handleKeyUp", 438 args = {long.class, int.class, KeyEvent.class} 439 ) testHandleKeyUp()440 public void testHandleKeyUp() { 441 long state = MetaKeyKeyListener.handleKeyUp(MetaKeyKeyListener.META_CAP_LOCKED, 442 KeyEvent.KEYCODE_SHIFT_LEFT, 443 new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_SHIFT_LEFT)); 444 assertEquals(MetaKeyKeyListener.META_CAP_LOCKED, state); 445 } 446 447 private class MockMetaKeyKeyListener extends MetaKeyKeyListener { callResetLockedMeta(Spannable content)448 public void callResetLockedMeta(Spannable content) { 449 MetaKeyKeyListener.resetLockedMeta(content); 450 } 451 } 452 453 private class MockSpannable implements Spannable { 454 private int mFlags; 455 private boolean mCalledRemoveSpan = false; 456 hasCalledRemoveSpan()457 public boolean hasCalledRemoveSpan() { 458 return mCalledRemoveSpan; 459 } 460 setSpan(Object what, int start, int end, int flags)461 public void setSpan(Object what, int start, int end, int flags) { 462 mFlags = flags; 463 } 464 removeSpan(Object what)465 public void removeSpan(Object what) { 466 mCalledRemoveSpan = true; 467 } 468 getSpans(int start, int end, Class<T> type)469 public <T> T[] getSpans(int start, int end, Class<T> type) { 470 return null; 471 } 472 getSpanStart(Object tag)473 public int getSpanStart(Object tag) { 474 return 0; 475 } 476 getSpanEnd(Object tag)477 public int getSpanEnd(Object tag) { 478 return 0; 479 } 480 getSpanFlags(Object tag)481 public int getSpanFlags(Object tag) { 482 return mFlags; 483 } 484 485 @SuppressWarnings("unchecked") nextSpanTransition(int start, int limit, Class type)486 public int nextSpanTransition(int start, int limit, Class type) { 487 return 0; 488 } 489 charAt(int index)490 public char charAt(int index) { 491 return 0; 492 } 493 length()494 public int length() { 495 return 0; 496 } 497 subSequence(int start, int end)498 public CharSequence subSequence(int start, int end) { 499 return null; 500 } 501 } 502 } 503