Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.app.Activity; | 7 import android.app.Activity; |
| 8 import android.content.ClipData; | 8 import android.content.ClipData; |
| 9 import android.content.ClipboardManager; | 9 import android.content.ClipboardManager; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 setComposingRegion(0, 4); | 385 setComposingRegion(0, 4); |
| 386 waitAndVerifyStatesAndCalls(4, "hllo ", 1, 1, 0, 4); | 386 waitAndVerifyStatesAndCalls(4, "hllo ", 1, 1, 0, 4); |
| 387 | 387 |
| 388 finishComposingText(); | 388 finishComposingText(); |
| 389 waitAndVerifyStatesAndCalls(5, "hllo ", 1, 1, -1, -1); | 389 waitAndVerifyStatesAndCalls(5, "hllo ", 1, 1, -1, -1); |
| 390 | 390 |
| 391 commitText("\n", 1); | 391 commitText("\n", 1); |
| 392 waitAndVerifyStatesAndCalls(6, "h\nllo ", 2, 2, -1, -1); | 392 waitAndVerifyStatesAndCalls(6, "h\nllo ", 2, 2, -1, -1); |
| 393 } | 393 } |
| 394 | 394 |
| 395 private int getTypedKeycodeGuess(String before, String after) { | |
| 396 KeyEvent ev = ImeAdapter.getTypedKeyEventGuess(before, after); | |
| 397 if (ev == null) return -1; | |
| 398 return ev.getKeyCode(); | |
| 399 } | |
| 400 | |
| 401 @SmallTest | |
| 402 @Feature({"TextInput", "Main"}) | |
| 403 public void testGuessedKeyCodeFromTyping() throws Throwable { | |
| 404 assertEquals(-1, getTypedKeycodeGuess(null, "")); | |
| 405 assertEquals(KeyEvent.KEYCODE_X, getTypedKeycodeGuess(null, "x")); | |
| 406 assertEquals(-1, getTypedKeycodeGuess(null, "xyz")); | |
| 407 | |
| 408 assertEquals(-1, getTypedKeycodeGuess("abc", "abc")); | |
| 409 assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("abc", "")); | |
| 410 | |
| 411 assertEquals(KeyEvent.KEYCODE_H, getTypedKeycodeGuess("", "h")); | |
| 412 assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("h", "")); | |
| 413 assertEquals(KeyEvent.KEYCODE_E, getTypedKeycodeGuess("h", "he")); | |
| 414 assertEquals(KeyEvent.KEYCODE_L, getTypedKeycodeGuess("he", "hel")); | |
| 415 assertEquals(KeyEvent.KEYCODE_O, getTypedKeycodeGuess("hel", "helo")); | |
| 416 assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("helo", "hel")); | |
| 417 assertEquals(KeyEvent.KEYCODE_L, getTypedKeycodeGuess("hel", "hell")); | |
| 418 assertEquals(KeyEvent.KEYCODE_L, getTypedKeycodeGuess("hell", "helll")); | |
| 419 assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("helll", "hell") ); | |
| 420 assertEquals(KeyEvent.KEYCODE_O, getTypedKeycodeGuess("hell", "hello")); | |
| 421 | |
| 422 assertEquals(KeyEvent.KEYCODE_X, getTypedKeycodeGuess("xxx", "xxxx")); | |
| 423 assertEquals(KeyEvent.KEYCODE_X, getTypedKeycodeGuess("xxx", "xxxxx")); | |
| 424 assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("xxx", "xx")); | |
| 425 assertEquals(KeyEvent.KEYCODE_DEL, getTypedKeycodeGuess("xxx", "x")); | |
| 426 | |
| 427 assertEquals(KeyEvent.KEYCODE_Y, getTypedKeycodeGuess("xxx", "xxxy")); | |
| 428 assertEquals(KeyEvent.KEYCODE_Y, getTypedKeycodeGuess("xxx", "xxxxy")); | |
| 429 assertEquals(-1, getTypedKeycodeGuess("xxx", "xy")); | |
| 430 assertEquals(-1, getTypedKeycodeGuess("xxx", "y")); | |
| 431 | |
| 432 assertEquals(-1, getTypedKeycodeGuess("foo", "bar")); | |
| 433 assertEquals(-1, getTypedKeycodeGuess("foo", "bars")); | |
| 434 assertEquals(-1, getTypedKeycodeGuess("foo", "ba")); | |
| 435 | |
| 436 // Some characters also require modifiers so we have to check the full e vent. | |
| 437 KeyEvent ev = ImeAdapter.getTypedKeyEventGuess(null, "!"); | |
| 438 assertEquals(KeyEvent.KEYCODE_1, ev.getKeyCode()); | |
| 439 assertTrue(ev.isShiftPressed()); | |
| 440 } | |
| 441 | |
| 442 /* | 395 /* |
| 443 @SmallTest | 396 @SmallTest |
| 444 @Feature({"TextInput", "Main"}) | 397 @Feature({"TextInput", "Main"}) |
| 445 http://crbug.com/445499 | 398 http://crbug.com/445499 |
| 446 */ | 399 */ |
| 447 @DisabledTest | 400 @DisabledTest |
|
Changwan Ryu
2015/10/09 12:34:28
Nit. Not disabled any more?
aelias_OOO_until_Jul13
2015/10/09 20:42:10
Done.
| |
| 448 public void testKeyCodesWhileComposingText() throws Throwable { | 401 public void testSwipingText() throws Throwable { |
| 449 focusElement("textarea"); | 402 focusElement("textarea"); |
| 450 | 403 |
| 451 // The calls below are a reflection of what the stock Google Keyboard (A ndroid 4.4) sends | 404 // The calls below are a reflection of what the stock Google Keyboard (A ndroid 4.4) sends |
| 452 // when the noted key is touched on screen. Exercise care when altering to make sure | |
| 453 // that the test reflects reality. If this test breaks, it's possible t hat code has | |
| 454 // changed and different calls need to be made instead. | |
| 455 // H | |
| 456 expectUpdateStateCall(); | |
| 457 setComposingText("h", 1); | |
| 458 assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode); | |
|
Changwan Ryu
2015/10/09 12:34:28
Can we separate this as testDeleteSurroundingText
aelias_OOO_until_Jul13
2015/10/09 20:42:10
Done, I brought back the relevant parts as "testDe
| |
| 459 assertUpdateStateCall(1000); | |
| 460 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 461 | |
| 462 // O | |
| 463 expectUpdateStateCall(); | |
| 464 setComposingText("ho", 1); | |
| 465 assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode); | |
| 466 assertUpdateStateCall(1000); | |
| 467 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | |
| 468 | |
| 469 // DEL | |
| 470 expectUpdateStateCall(); | |
| 471 setComposingText("h", 1); | |
| 472 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 473 assertUpdateStateCall(1000); | |
| 474 setComposingRegion(0, 1); // DEL calls cancelComposition() then restarts | |
| 475 setComposingText("h", 1); | |
| 476 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 477 | |
| 478 // I | |
| 479 setComposingText("hi", 1); | |
| 480 assertEquals(KeyEvent.KEYCODE_I, mImeAdapter.mLastSyntheticKeyCode); | |
| 481 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); | |
| 482 | |
| 483 // SPACE | |
| 484 commitText("hi", 1); | |
| 485 assertEquals(-1, mImeAdapter.mLastSyntheticKeyCode); | |
| 486 commitText(" ", 1); | |
| 487 assertEquals(KeyEvent.KEYCODE_SPACE, mImeAdapter.mLastSyntheticKeyCode); | |
| 488 assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0)); | |
| 489 | |
| 490 // DEL | |
| 491 deleteSurroundingText(1, 0); | |
| 492 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 493 setComposingRegion(0, 2); | |
| 494 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); | |
| 495 | |
| 496 // DEL | |
| 497 setComposingText("h", 1); | |
| 498 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 499 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 500 | |
| 501 // DEL | |
| 502 commitText("", 1); | |
| 503 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 504 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | |
| 505 | |
| 506 // DEL (on empty input) | |
| 507 deleteSurroundingText(1, 0); // DEL on empty still sends 1,0 | |
| 508 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 509 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | |
| 510 } | |
| 511 | |
| 512 /* | |
| 513 @SmallTest | |
| 514 @Feature({"TextInput", "Main"}) | |
| 515 http://crbug.com/445499 | |
| 516 */ | |
| 517 @DisabledTest | |
| 518 public void testKeyCodesWhileSwipingText() throws Throwable { | |
| 519 focusElement("textarea"); | |
| 520 | |
| 521 // The calls below are a reflection of what the stock Google Keyboard (A ndroid 4.4) sends | |
| 522 // when the word is swiped on the soft keyboard. Exercise care when alt ering to make sure | 405 // when the word is swiped on the soft keyboard. Exercise care when alt ering to make sure |
| 523 // that the test reflects reality. If this test breaks, it's possible t hat code has | 406 // that the test reflects reality. If this test breaks, it's possible t hat code has |
| 524 // changed and different calls need to be made instead. | 407 // changed and different calls need to be made instead. |
| 525 // "three" | 408 // "three" |
| 526 expectUpdateStateCall(); | 409 expectUpdateStateCall(); |
| 527 setComposingText("three", 1); | 410 setComposingText("three", 1); |
| 528 assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode ); | |
| 529 assertUpdateStateCall(1000); | 411 assertUpdateStateCall(1000); |
| 530 assertEquals("three", mConnection.getTextBeforeCursor(99, 0)); | 412 assertEquals("three", mConnection.getTextBeforeCursor(99, 0)); |
| 531 | 413 |
| 532 // "word" | 414 // "word" |
| 533 commitText("three", 1); | 415 commitText("three", 1); |
| 534 commitText(" ", 1); | 416 commitText(" ", 1); |
| 535 expectUpdateStateCall(); | 417 expectUpdateStateCall(); |
| 536 setComposingText("word", 1); | |
| 537 assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode ); | |
| 538 assertUpdateStateCall(1000); | 418 assertUpdateStateCall(1000); |
| 539 assertEquals("three word", mConnection.getTextBeforeCursor(99, 0)); | 419 assertEquals("three word", mConnection.getTextBeforeCursor(99, 0)); |
| 540 | 420 |
| 541 // "test" | 421 // "test" |
| 542 commitText("word", 1); | 422 commitText("word", 1); |
| 543 commitText(" ", 1); | 423 commitText(" ", 1); |
| 544 expectUpdateStateCall(); | 424 expectUpdateStateCall(); |
| 545 setComposingText("test", 1); | 425 setComposingText("test", 1); |
| 546 assertEquals(KeyEvent.KEYCODE_UNKNOWN, mImeAdapter.mLastSyntheticKeyCode ); | |
| 547 assertUpdateStateCall(1000); | 426 assertUpdateStateCall(1000); |
| 548 assertEquals("three word test", mConnection.getTextBeforeCursor(99, 0)); | 427 assertEquals("three word test", mConnection.getTextBeforeCursor(99, 0)); |
| 549 } | 428 } |
| 550 | 429 |
| 551 @SmallTest | 430 @SmallTest |
| 552 @Feature({"TextInput", "Main"}) | 431 @Feature({"TextInput", "Main"}) |
| 553 public void testDeleteMultiCharacterCodepoint() throws Throwable { | 432 public void testDeleteMultiCharacterCodepoint() throws Throwable { |
| 554 // This smiley is a multi character codepoint. | 433 // This smiley is a multi character codepoint. |
| 555 final String smiley = "\uD83D\uDE0A"; | 434 final String smiley = "\uD83D\uDE0A"; |
| 556 | 435 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 571 } | 450 } |
| 572 | 451 |
| 573 @SmallTest | 452 @SmallTest |
| 574 @Feature({"TextInput", "Main"}) | 453 @Feature({"TextInput", "Main"}) |
| 575 public void testBackspaceKeycode() throws Throwable { | 454 public void testBackspaceKeycode() throws Throwable { |
| 576 focusElement("textarea"); | 455 focusElement("textarea"); |
| 577 | 456 |
| 578 // H | 457 // H |
| 579 expectUpdateStateCall(); | 458 expectUpdateStateCall(); |
| 580 commitText("h", 1); | 459 commitText("h", 1); |
| 581 assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode); | |
| 582 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | 460 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 583 assertUpdateStateCall(1000); | 461 assertUpdateStateCall(1000); |
| 584 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | 462 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 585 | 463 |
| 586 // O | 464 // O |
| 587 expectUpdateStateCall(); | 465 expectUpdateStateCall(); |
| 588 commitText("o", 1); | 466 commitText("o", 1); |
| 589 assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode); | |
| 590 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | 467 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); |
| 591 assertUpdateStateCall(1000); | 468 assertUpdateStateCall(1000); |
| 592 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | 469 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); |
| 593 | 470 |
| 594 // DEL, sent via dispatchKeyEvent like it is in Android WebView or a phy sical keyboard. | 471 // DEL, sent via dispatchKeyEvent like it is in Android WebView or a phy sical keyboard. |
| 595 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL )); | 472 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL )); |
| 596 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)) ; | 473 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)) ; |
| 597 | 474 |
| 598 // DEL | 475 // DEL |
| 599 expectUpdateStateCall(); | 476 expectUpdateStateCall(); |
| 600 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | 477 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 601 assertUpdateStateCall(1000); | 478 assertUpdateStateCall(1000); |
| 602 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | 479 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 603 } | 480 } |
| 604 | 481 |
| 605 @SmallTest | 482 @SmallTest |
| 606 @Feature({"TextInput", "Main"}) | 483 @Feature({"TextInput", "Main"}) |
| 607 public void testRepeatBackspaceKeycode() throws Throwable { | 484 public void testRepeatBackspaceKeycode() throws Throwable { |
| 608 focusElement("textarea"); | 485 focusElement("textarea"); |
| 609 | 486 |
| 610 // H | 487 // H |
| 611 expectUpdateStateCall(); | 488 expectUpdateStateCall(); |
| 612 commitText("h", 1); | 489 commitText("h", 1); |
| 613 assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode); | |
| 614 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | 490 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 615 assertUpdateStateCall(1000); | 491 assertUpdateStateCall(1000); |
| 616 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | 492 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); |
| 617 | 493 |
| 618 // O | 494 // O |
| 619 expectUpdateStateCall(); | 495 expectUpdateStateCall(); |
| 620 commitText("o", 1); | 496 commitText("o", 1); |
| 621 assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode); | |
| 622 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | 497 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); |
| 623 assertUpdateStateCall(1000); | 498 assertUpdateStateCall(1000); |
| 624 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | 499 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); |
| 625 | 500 |
| 626 // Multiple keydowns should each delete one character (this is for physi cal keyboard | 501 // Multiple keydowns should each delete one character (this is for physi cal keyboard |
| 627 // key-repeat). | 502 // key-repeat). |
| 628 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL )); | 503 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL )); |
| 629 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL )); | 504 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL )); |
| 630 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)) ; | 505 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DEL)) ; |
| 631 | 506 |
| 632 // DEL | 507 // DEL |
| 633 expectUpdateStateCall(); | 508 expectUpdateStateCall(); |
| 634 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | 509 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); |
| 635 assertUpdateStateCall(1000); | 510 assertUpdateStateCall(1000); |
| 636 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | 511 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); |
| 637 } | 512 } |
| 638 | 513 |
| 639 @SmallTest | 514 @SmallTest |
| 640 @Feature({"TextInput", "Main"}) | 515 @Feature({"TextInput", "Main"}) |
| 641 public void testKeyCodesWhileTypingText() throws Throwable { | |
| 642 focusElement("textarea"); | |
| 643 | |
| 644 // The calls below are a reflection of what the Hacker's Keyboard sends when the noted | |
| 645 // key is touched on screen. Exercise care when altering to make sure t hat the test | |
| 646 // reflects reality. | |
| 647 // H | |
| 648 expectUpdateStateCall(); | |
| 649 commitText("h", 1); | |
| 650 assertEquals(KeyEvent.KEYCODE_H, mImeAdapter.mLastSyntheticKeyCode); | |
| 651 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 652 assertUpdateStateCall(1000); | |
| 653 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 654 | |
| 655 // O | |
| 656 expectUpdateStateCall(); | |
| 657 commitText("o", 1); | |
| 658 assertEquals(KeyEvent.KEYCODE_O, mImeAdapter.mLastSyntheticKeyCode); | |
| 659 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | |
| 660 assertUpdateStateCall(1000); | |
| 661 assertEquals("ho", mConnection.getTextBeforeCursor(9, 0)); | |
| 662 | |
| 663 // DEL | |
| 664 expectUpdateStateCall(); | |
| 665 deleteSurroundingText(1, 0); | |
| 666 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 667 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 668 assertUpdateStateCall(1000); | |
| 669 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 670 | |
| 671 // I | |
| 672 expectUpdateStateCall(); | |
| 673 commitText("i", 1); | |
| 674 assertEquals(KeyEvent.KEYCODE_I, mImeAdapter.mLastSyntheticKeyCode); | |
| 675 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); | |
| 676 assertUpdateStateCall(1000); | |
| 677 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); | |
| 678 | |
| 679 // SPACE | |
| 680 expectUpdateStateCall(); | |
| 681 commitText(" ", 1); | |
| 682 assertEquals(KeyEvent.KEYCODE_SPACE, mImeAdapter.mLastSyntheticKeyCode); | |
| 683 assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0)); | |
| 684 assertUpdateStateCall(1000); | |
| 685 assertEquals("hi ", mConnection.getTextBeforeCursor(9, 0)); | |
| 686 | |
| 687 // DEL | |
| 688 expectUpdateStateCall(); | |
| 689 deleteSurroundingText(1, 0); | |
| 690 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 691 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); | |
| 692 assertUpdateStateCall(1000); | |
| 693 assertEquals("hi", mConnection.getTextBeforeCursor(9, 0)); | |
| 694 | |
| 695 // DEL | |
| 696 expectUpdateStateCall(); | |
| 697 deleteSurroundingText(1, 0); | |
| 698 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 699 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 700 assertUpdateStateCall(1000); | |
| 701 assertEquals("h", mConnection.getTextBeforeCursor(9, 0)); | |
| 702 | |
| 703 // DEL | |
| 704 expectUpdateStateCall(); | |
| 705 deleteSurroundingText(1, 0); | |
| 706 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 707 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | |
| 708 assertUpdateStateCall(1000); | |
| 709 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | |
| 710 | |
| 711 // DEL (on empty input) | |
| 712 deleteSurroundingText(1, 0); // DEL on empty still sends 1,0 | |
| 713 assertEquals(KeyEvent.KEYCODE_DEL, mImeAdapter.mLastSyntheticKeyCode); | |
| 714 assertEquals("", mConnection.getTextBeforeCursor(9, 0)); | |
| 715 } | |
| 716 | |
| 717 @SmallTest | |
| 718 @Feature({"TextInput", "Main"}) | |
| 719 public void testPhysicalKeyboard() throws Throwable { | 516 public void testPhysicalKeyboard() throws Throwable { |
| 720 focusElement("textarea"); | 517 focusElement("textarea"); |
| 721 // Type 'a' using a physical keyboard. | 518 // Type 'a' using a physical keyboard. |
| 722 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A)) ; | 519 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_A)) ; |
| 723 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A)); | 520 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_A)); |
| 724 waitAndVerifyStatesAndCalls(1, "a", 1, 1, -1, -1); | 521 waitAndVerifyStatesAndCalls(1, "a", 1, 1, -1, -1); |
| 725 | 522 |
| 726 // Type 'enter' key. | 523 // Type 'enter' key. |
| 727 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENT ER)); | 524 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENT ER)); |
| 728 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER )); | 525 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_ENTER )); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 867 public void testDpadKeyCodesWhileSwipingText() throws Throwable { | 664 public void testDpadKeyCodesWhileSwipingText() throws Throwable { |
| 868 focusElement("textarea"); | 665 focusElement("textarea"); |
| 869 | 666 |
| 870 // DPAD_CENTER should cause keyboard to appear | 667 // DPAD_CENTER should cause keyboard to appear |
| 871 expectUpdateStateCall(); | 668 expectUpdateStateCall(); |
| 872 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPA D_CENTER)); | 669 dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPA D_CENTER)); |
| 873 assertUpdateStateCall(1000); | 670 assertUpdateStateCall(1000); |
| 874 } | 671 } |
| 875 | 672 |
| 876 @SmallTest | 673 @SmallTest |
| 877 @Feature({"TextInput", "Main"}) | |
| 878 public void testTransitionsWhileComposingText() throws Throwable { | |
| 879 focusElement("textarea"); // Default with autocomplete="on" | |
| 880 | |
| 881 // H | |
| 882 // Since autocomplete="on" by default, COMPOSITION_KEY_CODE is emitted a s key code | |
| 883 expectUpdateStateCall(); | |
| 884 setComposingText("h", 1); | |
| 885 assertEquals(COMPOSITION_KEY_CODE, mImeAdapter.mLastSyntheticKeyCode); | |
| 886 | |
| 887 // Simulate switch of input fields. | |
| 888 finishComposingText(); | |
| 889 | |
| 890 // H | |
| 891 expectUpdateStateCall(); | |
| 892 setComposingText("h", 1); | |
| 893 assertEquals(COMPOSITION_KEY_CODE, mImeAdapter.mLastSyntheticKeyCode); | |
| 894 } | |
| 895 | |
| 896 @SmallTest | |
| 897 @Feature({"TextInput", "Main"}) | |
| 898 public void testTransitionsWhileEmittingKeyCode() throws Throwable { | |
| 899 focusElement("textarea2"); // Default with autocomplete="off" | |
| 900 | |
| 901 // H | |
| 902 // Although autocomplete="off", we still emit COMPOSITION_KEY_CODE since synthesized | |
| 903 // keycodes are disabled. | |
| 904 expectUpdateStateCall(); | |
| 905 setComposingText("h", 1); | |
| 906 assertEquals(COMPOSITION_KEY_CODE, mImeAdapter.mLastSyntheticKeyCode); | |
| 907 | |
| 908 // Simulate switch of input fields. | |
| 909 finishComposingText(); | |
| 910 | |
| 911 // H | |
| 912 expectUpdateStateCall(); | |
| 913 setComposingText("h", 1); | |
| 914 assertEquals(COMPOSITION_KEY_CODE, mImeAdapter.mLastSyntheticKeyCode); | |
| 915 } | |
| 916 | |
| 917 @SmallTest | |
| 918 @Feature({"TextInput"}) | 674 @Feature({"TextInput"}) |
| 919 public void testPastePopupShowAndHide() throws Throwable { | 675 public void testPastePopupShowAndHide() throws Throwable { |
| 920 commitText("hello", 1); | 676 commitText("hello", 1); |
| 921 waitAndVerifyStatesAndCalls(1, "hello", 5, 5, -1, -1); | 677 waitAndVerifyStatesAndCalls(1, "hello", 5, 5, -1, -1); |
| 922 | 678 |
| 923 selectAll(); | 679 selectAll(); |
| 924 waitAndVerifyStatesAndCalls(2, "hello", 0, 5, -1, -1); | 680 waitAndVerifyStatesAndCalls(2, "hello", 0, 5, -1, -1); |
| 925 | 681 |
| 926 cut(); | 682 cut(); |
| 927 waitAndVerifyStatesAndCalls(0, "", 0, 0, -1, -1); | 683 waitAndVerifyStatesAndCalls(0, "", 0, 0, -1, -1); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1267 public void assertEqualState(String text, int selectionStart, int select ionEnd, | 1023 public void assertEqualState(String text, int selectionStart, int select ionEnd, |
| 1268 int compositionStart, int compositionEnd) { | 1024 int compositionStart, int compositionEnd) { |
| 1269 assertEquals("Text did not match", text, mText); | 1025 assertEquals("Text did not match", text, mText); |
| 1270 assertEquals("Selection start did not match", selectionStart, mSelec tionStart); | 1026 assertEquals("Selection start did not match", selectionStart, mSelec tionStart); |
| 1271 assertEquals("Selection end did not match", selectionEnd, mSelection End); | 1027 assertEquals("Selection end did not match", selectionEnd, mSelection End); |
| 1272 assertEquals("Composition start did not match", compositionStart, mC ompositionStart); | 1028 assertEquals("Composition start did not match", compositionStart, mC ompositionStart); |
| 1273 assertEquals("Composition end did not match", compositionEnd, mCompo sitionEnd); | 1029 assertEquals("Composition end did not match", compositionEnd, mCompo sitionEnd); |
| 1274 } | 1030 } |
| 1275 } | 1031 } |
| 1276 } | 1032 } |
| OLD | NEW |