609 {
610 int selStart = 75;
611 ListenableEditingState editable = sampleEditable(selStart, selStart, SAMPLE_EMOJI_TEXT);
612 InputConnectionAdaptor adaptor = sampleInputConnectionAdaptor(editable);
613
614 KeyEvent downKeyDown = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_LEFT);
615 boolean didConsume;
616
617
618 didConsume = adaptor.handleKeyEvent(downKeyDown);
619 assertTrue(didConsume);
620 assertEquals(Selection.getSelectionStart(editable), 74);
621
622
623 didConsume = adaptor.handleKeyEvent(downKeyDown);
624 assertTrue(didConsume);
625 assertEquals(Selection.getSelectionStart(editable), 73);
626 didConsume = adaptor.handleKeyEvent(downKeyDown);
627 assertTrue(didConsume);
628 assertEquals(Selection.getSelectionStart(editable), 72);
629
630
631 didConsume = adaptor.handleKeyEvent(downKeyDown);
632 assertTrue(didConsume);
633 assertEquals(Selection.getSelectionStart(editable), 69);
634
635
636 adaptor.setSelection(68, 68);
637 didConsume = adaptor.handleKeyEvent(downKeyDown);
638 assertTrue(didConsume);
639 assertEquals(Selection.getSelectionStart(editable), 66);
640 adaptor.setSelection(67, 67);
641 didConsume = adaptor.handleKeyEvent(downKeyDown);
642 assertTrue(didConsume);
643 assertEquals(Selection.getSelectionStart(editable), 66);
644
645
646 didConsume = adaptor.handleKeyEvent(downKeyDown);
647 assertTrue(didConsume);
648 assertEquals(Selection.getSelectionStart(editable), 55);
649
650
651 didConsume = adaptor.handleKeyEvent(downKeyDown);
652 assertTrue(didConsume);
653 assertEquals(Selection.getSelectionStart(editable), 53);
654 didConsume = adaptor.handleKeyEvent(downKeyDown);
655 assertTrue(didConsume);
656 assertEquals(Selection.getSelectionStart(editable), 52);
657 didConsume = adaptor.handleKeyEvent(downKeyDown);
658 assertTrue(didConsume);
659 assertEquals(Selection.getSelectionStart(editable), 51);
660
661
662
663 adaptor.setSelection(39, 39);
664 didConsume = adaptor.handleKeyEvent(downKeyDown);
665 assertTrue(didConsume);
666 assertEquals(Selection.getSelectionStart(editable), 37);
667
668
669 adaptor.setSelection(49, 49);
670 for (
int i = 0;
i < 6;
i++) {
671 didConsume = adaptor.handleKeyEvent(downKeyDown);
672 assertTrue(didConsume);
673 }
674 assertEquals(Selection.getSelectionStart(editable), 37);
675
676
677
678 didConsume = adaptor.handleKeyEvent(downKeyDown);
679 assertTrue(didConsume);
680 assertEquals(Selection.getSelectionStart(editable), 23);
681
682
683 adaptor.setSelection(22, 22);
684 didConsume = adaptor.handleKeyEvent(downKeyDown);
685 assertTrue(didConsume);
686 assertEquals(Selection.getSelectionStart(editable), 21);
687 adaptor.setSelection(22, 22);
688 didConsume = adaptor.handleKeyEvent(downKeyDown);
689 assertTrue(didConsume);
690 assertEquals(Selection.getSelectionStart(editable), 21);
691
692
693 didConsume = adaptor.handleKeyEvent(downKeyDown);
694 assertTrue(didConsume);
695 assertEquals(Selection.getSelectionStart(editable), 19);
696
697
698 didConsume = adaptor.handleKeyEvent(downKeyDown);
699 assertTrue(didConsume);
700 assertEquals(Selection.getSelectionStart(editable), 16);
701
702
703 adaptor.setSelection(14, 14);
704 didConsume = adaptor.handleKeyEvent(downKeyDown);
705 assertTrue(didConsume);
706 assertEquals(Selection.getSelectionStart(editable), 13);
707 adaptor.setSelection(14, 14);
708 didConsume = adaptor.handleKeyEvent(downKeyDown);
709 assertTrue(didConsume);
710 assertEquals(Selection.getSelectionStart(editable), 13);
711
712
713 adaptor.setSelection(12, 12);
714 didConsume = adaptor.handleKeyEvent(downKeyDown);
715 assertTrue(didConsume);
716 assertEquals(Selection.getSelectionStart(editable), 11);
717
718
719 adaptor.setSelection(12, 12);
720 didConsume = adaptor.handleKeyEvent(downKeyDown);
721 assertTrue(didConsume);
722 assertEquals(Selection.getSelectionStart(editable), 11);
723
724
725 didConsume = adaptor.handleKeyEvent(downKeyDown);
726 assertTrue(didConsume);
727 assertEquals(Selection.getSelectionStart(editable), 9);
728
729
730 didConsume = adaptor.handleKeyEvent(downKeyDown);
731 assertTrue(didConsume);
732 assertEquals(Selection.getSelectionStart(editable), 7);
733
734
735 didConsume = adaptor.handleKeyEvent(downKeyDown);
736 assertTrue(didConsume);
737 assertEquals(Selection.getSelectionStart(editable), 3);
738
739
740 didConsume = adaptor.handleKeyEvent(downKeyDown);
741 assertTrue(didConsume);
742 assertEquals(Selection.getSelectionStart(editable), 1);
743
744
745 didConsume = adaptor.handleKeyEvent(downKeyDown);
746 assertTrue(didConsume);
747 assertEquals(Selection.getSelectionStart(editable), 0);
748 }