OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "ui/chromeos/touch_exploration_controller.h" | 5 #include "ui/chromeos/touch_exploration_controller.h" |
6 | 6 |
7 #include "base/test/simple_test_tick_clock.h" | 7 #include "base/test/simple_test_tick_clock.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "ui/aura/client/cursor_client.h" | 9 #include "ui/aura/client/cursor_client.h" |
10 #include "ui/aura/test/aura_test_base.h" | 10 #include "ui/aura/test/aura_test_base.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
117 } else if (on && !touch_exploration_controller_.get()) { | 117 } else if (on && !touch_exploration_controller_.get()) { |
118 touch_exploration_controller_.reset( | 118 touch_exploration_controller_.reset( |
119 new ui::TouchExplorationController(root_window())); | 119 new ui::TouchExplorationController(root_window())); |
120 touch_exploration_controller_->SetEventHandlerForTesting( | 120 touch_exploration_controller_->SetEventHandlerForTesting( |
121 &event_capturer_); | 121 &event_capturer_); |
122 cursor_client()->ShowCursor(); | 122 cursor_client()->ShowCursor(); |
123 cursor_client()->DisableMouseEvents(); | 123 cursor_client()->DisableMouseEvents(); |
124 } | 124 } |
125 } | 125 } |
126 | 126 |
127 void EnterTouchExplorationModeAtLocation(gfx::Point tap_location) { | |
128 ui::TouchEvent touch_press(ui::ET_TOUCH_PRESSED, tap_location, 0, Now()); | |
129 generator_->Dispatch(&touch_press); | |
130 AdvanceSimulatedTimePastTapDelay(); | |
131 EXPECT_TRUE(IsInTouchToMouseMode()); | |
132 } | |
133 | |
127 bool IsInTouchToMouseMode() { | 134 bool IsInTouchToMouseMode() { |
128 aura::client::CursorClient* cursor_client = | 135 aura::client::CursorClient* cursor_client = |
129 aura::client::GetCursorClient(root_window()); | 136 aura::client::GetCursorClient(root_window()); |
130 return cursor_client && | 137 return cursor_client && |
131 cursor_client->IsMouseEventsEnabled() && | 138 cursor_client->IsMouseEventsEnabled() && |
132 !cursor_client->IsCursorVisible(); | 139 !cursor_client->IsCursorVisible(); |
133 } | 140 } |
134 | 141 |
135 bool IsInNoFingersDownState() { | 142 bool IsInNoFingersDownState() { |
136 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); | 143 return touch_exploration_controller_->IsInNoFingersDownStateForTesting(); |
(...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 // This should result in a single touch long press and release | 685 // This should result in a single touch long press and release |
679 // at the location of the tap, not at the location of the double-tap. | 686 // at the location of the tap, not at the location of the double-tap. |
680 // There should be a time delay between the touch press and release. | 687 // There should be a time delay between the touch press and release. |
681 gfx::Point first_tap_location(33, 34); | 688 gfx::Point first_tap_location(33, 34); |
682 generator_->set_current_location(first_tap_location); | 689 generator_->set_current_location(first_tap_location); |
683 generator_->PressTouch(); | 690 generator_->PressTouch(); |
684 generator_->ReleaseTouch(); | 691 generator_->ReleaseTouch(); |
685 gfx::Point second_tap_location(23, 24); | 692 gfx::Point second_tap_location(23, 24); |
686 generator_->set_current_location(second_tap_location); | 693 generator_->set_current_location(second_tap_location); |
687 generator_->PressTouch(); | 694 generator_->PressTouch(); |
688 simulated_clock_->Advance(base::TimeDelta::FromMilliseconds(8000)); | 695 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); |
689 generator_->ReleaseTouch(); | 696 generator_->ReleaseTouch(); |
690 | 697 |
691 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); | 698 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); |
692 ASSERT_EQ(2U, captured_events.size()); | 699 ASSERT_EQ(2U, captured_events.size()); |
693 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 700 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
694 EXPECT_EQ(tap_location, captured_events[0]->location()); | 701 EXPECT_EQ(tap_location, captured_events[0]->location()); |
695 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | 702 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); |
696 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 703 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
697 EXPECT_EQ(tap_location, captured_events[1]->location()); | 704 EXPECT_EQ(tap_location, captured_events[1]->location()); |
698 base::TimeDelta released_time = captured_events[1]->time_stamp(); | 705 base::TimeDelta released_time = captured_events[1]->time_stamp(); |
699 EXPECT_EQ( | 706 EXPECT_EQ(gesture_detector_config_.longpress_timeout, |
700 base::TimeDelta::FromMilliseconds(8000), | 707 released_time - pressed_time); |
701 released_time - pressed_time); | |
702 } | 708 } |
703 | 709 |
710 // Tapping and releasing with a second finger when in touch exploration mode | |
711 // should send a touch press and released to the location of the last | |
712 // successful touch exploration and return to touch explore. | |
713 TEST_F(TouchExplorationTest, SplitTap) { | |
714 SwitchTouchExplorationMode(true); | |
715 gfx::Point initial_touch_location(11, 12); | |
716 gfx::Point second_touch_location(33, 34); | |
717 | |
718 // Tap and hold at one location, and get a mouse move event in touch explore. | |
719 EnterTouchExplorationModeAtLocation(initial_touch_location); | |
720 std::vector<ui::LocatedEvent*> events = | |
721 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); | |
722 ASSERT_EQ(1U, events.size()); | |
723 | |
724 EXPECT_EQ(initial_touch_location, events[0]->location()); | |
725 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | |
726 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | |
727 ClearCapturedEvents(); | |
728 | |
729 // Now tap and release at a different location. This should result in a | |
730 // single touch and release at the location of the first (held) tap, | |
731 // not at the location of the second tap and release. | |
732 // After the release, there is still a finger in touch explore mode. | |
733 ui::TouchEvent split_tap_press( | |
734 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | |
735 generator_->Dispatch(&split_tap_press); | |
736 ui::TouchEvent split_tap_release( | |
737 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | |
738 generator_->Dispatch(&split_tap_release); | |
739 EXPECT_FALSE(IsInNoFingersDownState()); | |
740 | |
741 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); | |
742 ASSERT_EQ(2U, captured_events.size()); | |
743 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | |
744 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | |
745 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | |
746 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | |
747 } | |
748 | |
749 // If split tap is started but the touch explore finger is released first, | |
750 // there should still be a touch press and release sent to the location of | |
751 // the last successful touch exploration. | |
752 // All fingers should be released after the click goes through. | |
dmazzoni
2014/06/16 18:21:20
In the generated/simulated events output by touch
evy
2014/06/16 20:34:20
In this test, that's true - so I'll change it.
I w
| |
753 TEST_F(TouchExplorationTest, SplitTapRelease) { | |
754 SwitchTouchExplorationMode(true); | |
755 | |
756 gfx::Point initial_touch_location(11, 12); | |
757 gfx::Point second_touch_location(33, 34); | |
758 | |
759 // Tap and hold at one location, and get a mouse move event in touch explore. | |
760 EnterTouchExplorationModeAtLocation(initial_touch_location); | |
761 | |
762 std::vector<ui::LocatedEvent*> events = | |
763 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); | |
764 ASSERT_EQ(1U, events.size()); | |
765 | |
766 EXPECT_EQ(initial_touch_location, events[0]->location()); | |
767 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | |
768 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | |
769 ClearCapturedEvents(); | |
770 | |
771 // Now tap at a different location. Release at the first location, | |
772 // then release at the second. This should result in a | |
773 // single touch and release at the location of the first (held) tap, | |
774 // not at the location of the second tap and release. | |
775 ui::TouchEvent split_tap_press( | |
776 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | |
777 generator_->Dispatch(&split_tap_press); | |
778 ui::TouchEvent touch_explore_release( | |
779 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); | |
780 generator_->Dispatch(&touch_explore_release); | |
781 ui::TouchEvent split_tap_release( | |
782 ui::ET_TOUCH_RELEASED, second_touch_location , 1, Now()); | |
783 generator_->Dispatch(&split_tap_release); | |
784 EXPECT_TRUE(IsInNoFingersDownState()); | |
785 | |
786 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); | |
787 ASSERT_EQ(2U, captured_events.size()); | |
788 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | |
789 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | |
790 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | |
791 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | |
792 } | |
793 | |
794 // When in touch exploration mode, making a long press with a second finger | |
795 // should send a touch press and released to the location of the last | |
796 // successful touch exploration. There should be a delay between the | |
797 // touch and release events (right click). | |
798 TEST_F(TouchExplorationTest, SplitTapLongPress) { | |
799 SwitchTouchExplorationMode(true); | |
800 gfx::Point initial_touch_location(11, 12); | |
801 gfx::Point second_touch_location(33, 34); | |
802 | |
803 // Tap and hold at one location, and get a mouse move event in touch explore. | |
804 EnterTouchExplorationModeAtLocation(initial_touch_location); | |
805 | |
806 std::vector<ui::LocatedEvent*> events = | |
807 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); | |
808 ASSERT_EQ(1U, events.size()); | |
809 | |
810 EXPECT_EQ(initial_touch_location, events[0]->location()); | |
811 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | |
812 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | |
813 ClearCapturedEvents(); | |
814 | |
815 // Now tap and release at a different location. This should result in a | |
816 // single touch and release at the location of the first (held) tap, | |
817 // not at the location of the second tap and release. | |
818 // After the release, there is still a finger in touch explore mode. | |
819 ui::TouchEvent split_tap_press( | |
820 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | |
821 generator_->Dispatch(&split_tap_press); | |
822 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | |
823 ui::TouchEvent split_tap_release( | |
824 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | |
825 generator_->Dispatch(&split_tap_release); | |
826 EXPECT_FALSE(IsInNoFingersDownState()); | |
827 | |
828 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); | |
829 ASSERT_EQ(2U, captured_events.size()); | |
830 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | |
831 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | |
832 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | |
833 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | |
834 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | |
835 base::TimeDelta released_time = captured_events[1]->time_stamp(); | |
836 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | |
837 released_time - pressed_time); | |
838 } | |
839 | |
840 // If split tap is started but the touch explore finger is released first, | |
841 // there should still be a touch press and release sent to the location of | |
842 // the last successful touch exploration. If the remaining finger is held | |
843 // as a longpress, there should be a delay between the sent touch and release | |
844 // events (right click). | |
845 // All fingers should be released after the click goes through. | |
846 TEST_F(TouchExplorationTest, SplitTapReleaseLongPress) { | |
847 SwitchTouchExplorationMode(true); | |
848 gfx::Point initial_touch_location(11, 12); | |
849 gfx::Point second_touch_location(33, 34); | |
850 | |
851 // Tap and hold at one location, and get a mouse move event in touch explore. | |
852 EnterTouchExplorationModeAtLocation(initial_touch_location); | |
853 | |
854 std::vector<ui::LocatedEvent*> events = | |
855 GetCapturedEventsOfType(ui::ET_MOUSE_MOVED); | |
856 ASSERT_EQ(1U, events.size()); | |
857 | |
858 EXPECT_EQ(initial_touch_location, events[0]->location()); | |
859 EXPECT_TRUE(events[0]->flags() & ui::EF_IS_SYNTHESIZED); | |
860 EXPECT_TRUE(events[0]->flags() & ui::EF_TOUCH_ACCESSIBILITY); | |
861 ClearCapturedEvents(); | |
862 | |
863 // Now tap at a different location. Release at the first location, | |
864 // then release at the second. This should result in a | |
865 // single touch and release at the location of the first (held) tap, | |
866 // not at the location of the second tap and release. | |
867 // After the release, TouchToMouseMode should still be on. | |
868 ui::TouchEvent split_tap_press( | |
869 ui::ET_TOUCH_PRESSED, second_touch_location, 1, Now()); | |
870 generator_->Dispatch(&split_tap_press); | |
871 ui::TouchEvent touch_explore_release( | |
872 ui::ET_TOUCH_RELEASED, initial_touch_location, 0, Now()); | |
873 generator_->Dispatch(&touch_explore_release); | |
874 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | |
875 ui::TouchEvent split_tap_release( | |
876 ui::ET_TOUCH_RELEASED, second_touch_location, 1, Now()); | |
877 generator_->Dispatch(&split_tap_release); | |
878 EXPECT_TRUE(IsInTouchToMouseMode()); | |
879 | |
880 const ScopedVector<ui::LocatedEvent>& captured_events = GetCapturedEvents(); | |
881 ASSERT_EQ(2U, captured_events.size()); | |
882 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | |
883 EXPECT_EQ(initial_touch_location, captured_events[0]->location()); | |
884 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | |
885 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | |
886 EXPECT_EQ(initial_touch_location, captured_events[1]->location()); | |
887 base::TimeDelta released_time = captured_events[1]->time_stamp(); | |
888 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | |
889 released_time - pressed_time); | |
890 } | |
891 | |
892 | |
704 } // namespace ui | 893 } // namespace ui |
OLD | NEW |