| 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 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 // This should result in a single touch press at the location of the tap, | 769 // This should result in a single touch press at the location of the tap, |
| 770 // not at the location of the double-tap. | 770 // not at the location of the double-tap. |
| 771 gfx::Point first_tap_location(13, 14); | 771 gfx::Point first_tap_location(13, 14); |
| 772 generator_->set_current_location(first_tap_location); | 772 generator_->set_current_location(first_tap_location); |
| 773 generator_->PressTouchId(1); | 773 generator_->PressTouchId(1); |
| 774 generator_->ReleaseTouchId(1); | 774 generator_->ReleaseTouchId(1); |
| 775 gfx::Point second_tap_location(15, 16); | 775 gfx::Point second_tap_location(15, 16); |
| 776 generator_->set_current_location(second_tap_location); | 776 generator_->set_current_location(second_tap_location); |
| 777 generator_->PressTouchId(1); | 777 generator_->PressTouchId(1); |
| 778 // Advance to the finger passing through. | 778 // Advance to the finger passing through. |
| 779 AdvanceSimulatedTimePastPassthroughDelay(); | 779 AdvanceSimulatedTimePastTapDelay(); |
| 780 | 780 |
| 781 gfx::Vector2d passthrough_offset = second_tap_location - tap_location; | 781 gfx::Vector2d passthrough_offset = second_tap_location - tap_location; |
| 782 | 782 |
| 783 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 783 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
| 784 ASSERT_EQ(1U, captured_events.size()); | 784 ASSERT_EQ(1U, captured_events.size()); |
| 785 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 785 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 786 EXPECT_EQ(second_tap_location - passthrough_offset, | 786 EXPECT_EQ(second_tap_location - passthrough_offset, |
| 787 captured_events[0]->location()); | 787 captured_events[0]->location()); |
| 788 | 788 |
| 789 ClearCapturedEvents(); | 789 ClearCapturedEvents(); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 857 // at the location of the tap, not at the location of the double-tap. | 857 // at the location of the tap, not at the location of the double-tap. |
| 858 // There should be a time delay between the touch press and release. | 858 // There should be a time delay between the touch press and release. |
| 859 gfx::Point first_tap_location(33, 34); | 859 gfx::Point first_tap_location(33, 34); |
| 860 generator_->set_current_location(first_tap_location); | 860 generator_->set_current_location(first_tap_location); |
| 861 generator_->PressTouch(); | 861 generator_->PressTouch(); |
| 862 generator_->ReleaseTouch(); | 862 generator_->ReleaseTouch(); |
| 863 gfx::Point second_tap_location(23, 24); | 863 gfx::Point second_tap_location(23, 24); |
| 864 generator_->set_current_location(second_tap_location); | 864 generator_->set_current_location(second_tap_location); |
| 865 generator_->PressTouch(); | 865 generator_->PressTouch(); |
| 866 // Advance to the finger passing through, and then to the longpress timeout. | 866 // Advance to the finger passing through, and then to the longpress timeout. |
| 867 AdvanceSimulatedTimePastPassthroughDelay(); | 867 AdvanceSimulatedTimePastTapDelay(); |
| 868 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | 868 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); |
| 869 generator_->ReleaseTouch(); | 869 generator_->ReleaseTouch(); |
| 870 | 870 |
| 871 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 871 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
| 872 ASSERT_EQ(2U, captured_events.size()); | 872 ASSERT_EQ(2U, captured_events.size()); |
| 873 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | 873 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); |
| 874 EXPECT_EQ(tap_location, captured_events[0]->location()); | 874 EXPECT_EQ(tap_location, captured_events[0]->location()); |
| 875 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | 875 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); |
| 876 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); | 876 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[1]->type()); |
| 877 EXPECT_EQ(tap_location, captured_events[1]->location()); | 877 EXPECT_EQ(tap_location, captured_events[1]->location()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 909 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | 909 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); |
| 910 ASSERT_EQ(4U, captured_events.size()); | 910 ASSERT_EQ(4U, captured_events.size()); |
| 911 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | 911 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); |
| 912 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); | 912 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); |
| 913 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[2]->type()); | 913 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[2]->type()); |
| 914 EXPECT_EQ(tap_location, captured_events[2]->location()); | 914 EXPECT_EQ(tap_location, captured_events[2]->location()); |
| 915 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[3]->type()); | 915 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[3]->type()); |
| 916 EXPECT_EQ(tap_location, captured_events[3]->location()); | 916 EXPECT_EQ(tap_location, captured_events[3]->location()); |
| 917 } | 917 } |
| 918 | 918 |
| 919 // Single-tapping and holding should send a touch press and release through to | |
| 920 // the location of the last successful touch exploration. There should be a | |
| 921 // delay between the touch and release events (right click). The user should | |
| 922 // not enter passthrough mode - touch moves should be discarded. | |
| 923 TEST_F(TouchExplorationTest, SingleTapLongPress) { | |
| 924 SwitchTouchExplorationMode(true); | |
| 925 | |
| 926 // Tap once to simulate a mouse moved event. | |
| 927 gfx::Point initial_location(11, 12); | |
| 928 generator_->set_current_location(initial_location); | |
| 929 generator_->PressTouch(); | |
| 930 AdvanceSimulatedTimePastTapDelay(); | |
| 931 ClearCapturedEvents(); | |
| 932 | |
| 933 // Move to another location for single tap | |
| 934 gfx::Point tap_location(22, 23); | |
| 935 generator_->MoveTouch(tap_location); | |
| 936 generator_->ReleaseTouch(); | |
| 937 | |
| 938 std::vector<ui::LocatedEvent*> captured_events = GetCapturedLocatedEvents(); | |
| 939 ASSERT_EQ(2U, captured_events.size()); | |
| 940 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[0]->type()); | |
| 941 EXPECT_EQ(ui::ET_MOUSE_MOVED, captured_events[1]->type()); | |
| 942 ClearCapturedEvents(); | |
| 943 | |
| 944 // Tap again for a long press single tap. | |
| 945 gfx::Point final_location(33, 34); | |
| 946 generator_->set_current_location(final_location); | |
| 947 generator_->PressTouch(); | |
| 948 simulated_clock_->Advance(gesture_detector_config_.longpress_timeout); | |
| 949 | |
| 950 captured_events = GetCapturedLocatedEvents(); | |
| 951 ASSERT_EQ(1U, captured_events.size()); | |
| 952 EXPECT_EQ(ui::ET_TOUCH_PRESSED, captured_events[0]->type()); | |
| 953 EXPECT_EQ(tap_location, captured_events[0]->location()); | |
| 954 base::TimeDelta pressed_time = captured_events[0]->time_stamp(); | |
| 955 ClearCapturedEvents(); | |
| 956 | |
| 957 // Touch moves should not send any events through, since the user should be | |
| 958 // in a wait for release state. | |
| 959 gfx::Point move_location(44, 45); | |
| 960 generator_->MoveTouch(move_location); | |
| 961 captured_events = GetCapturedLocatedEvents(); | |
| 962 ASSERT_EQ(0U, captured_events.size()); | |
| 963 | |
| 964 generator_->ReleaseTouch(); | |
| 965 captured_events = GetCapturedLocatedEvents(); | |
| 966 ASSERT_EQ(1U, captured_events.size()); | |
| 967 EXPECT_EQ(ui::ET_TOUCH_RELEASED, captured_events[0]->type()); | |
| 968 EXPECT_EQ(tap_location, captured_events[0]->location()); | |
| 969 base::TimeDelta released_time = captured_events[0]->time_stamp(); | |
| 970 EXPECT_EQ(gesture_detector_config_.longpress_timeout, | |
| 971 released_time - pressed_time); | |
| 972 } | |
| 973 | |
| 974 // Double-tapping without coming from touch exploration (no previous touch | 919 // Double-tapping without coming from touch exploration (no previous touch |
| 975 // exploration event) should not generate any events. | 920 // exploration event) should not generate any events. |
| 976 TEST_F(TouchExplorationTest, DoubleTapNoTouchExplore) { | 921 TEST_F(TouchExplorationTest, DoubleTapNoTouchExplore) { |
| 977 SwitchTouchExplorationMode(true); | 922 SwitchTouchExplorationMode(true); |
| 978 | 923 |
| 979 // Double-tap without any previous touch. | 924 // Double-tap without any previous touch. |
| 980 // Touch exploration mode has not been entered, so there is no previous | 925 // Touch exploration mode has not been entered, so there is no previous |
| 981 // touch exploration event. The double-tap should be discarded, and no events | 926 // touch exploration event. The double-tap should be discarded, and no events |
| 982 // should be generated at all. | 927 // should be generated at all. |
| 983 gfx::Point double_tap_location(33, 34); | 928 gfx::Point double_tap_location(33, 34); |
| (...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1999 generator_->PressTouch(); | 1944 generator_->PressTouch(); |
| 2000 generator_->MoveTouch(initial_press); | 1945 generator_->MoveTouch(initial_press); |
| 2001 generator_->MoveTouch(*point); | 1946 generator_->MoveTouch(*point); |
| 2002 generator_->ReleaseTouch(); | 1947 generator_->ReleaseTouch(); |
| 2003 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); | 1948 ASSERT_EQ(1U, delegate_.NumExitScreenSounds()); |
| 2004 delegate_.ResetCountersToZero(); | 1949 delegate_.ResetCountersToZero(); |
| 2005 } | 1950 } |
| 2006 } | 1951 } |
| 2007 | 1952 |
| 2008 } // namespace ui | 1953 } // namespace ui |
| OLD | NEW |