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/events/gesture_detection/gesture_provider.h" | 5 #include "ui/events/gesture_detection/gesture_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 kFakeCoordY + delta_y); | 934 kFakeCoordY + delta_y); |
935 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 935 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
936 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | 936 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); |
937 | 937 |
938 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); | 938 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); |
939 ASSERT_TRUE(scroll_begin_gesture); | 939 ASSERT_TRUE(scroll_begin_gesture); |
940 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); | 940 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); |
941 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); | 941 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); |
942 } | 942 } |
943 | 943 |
944 // Verify that slop regions are checked for one and two finger scrolls, | |
945 // three finger tap doesn't exsit, no slop region for three finger scroll. | |
tdresser
2016/06/10 19:34:57
exsit -> exist
sahel
2016/06/23 22:34:44
Done.
| |
946 TEST_F(GestureProviderTest, SlopRegionCheckOnScroll) { | |
947 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); | |
948 const float scaled_touch_slop = GetTouchSlop(); | |
949 | |
950 base::TimeTicks event_time = base::TimeTicks::Now(); | |
951 | |
952 | |
953 | |
954 // Scroll with one pointer down | |
tdresser
2016/06/10 19:34:58
Missing .'s.
sahel
2016/06/23 22:34:44
Done.
| |
955 MockMotionEvent event = | |
956 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); | |
957 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
958 | |
959 // Move within slop region | |
960 event = ObtainMotionEvent(event_time, | |
961 MotionEvent::ACTION_MOVE, | |
962 0, | |
963 scaled_touch_slop / 2); | |
964 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
965 | |
966 // Exceed slop region | |
967 event = ObtainMotionEvent(event_time, | |
968 MotionEvent::ACTION_MOVE, | |
969 0, | |
970 2 * scaled_touch_slop); | |
971 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
972 | |
973 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, | |
974 0, 2 * scaled_touch_slop); | |
975 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
976 | |
977 | |
978 | |
979 // Scroll with two pointers down | |
980 event_time += kOneSecond; | |
981 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); | |
982 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
983 | |
984 event = ObtainMotionEvent(event_time, | |
985 MotionEvent::ACTION_POINTER_DOWN, | |
986 0, | |
987 0, | |
988 kMaxTwoFingerTapSeparation / 2, | |
989 0); | |
990 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
991 | |
992 // Move within slop region: two finger tap | |
993 event = ObtainMotionEvent(event_time, | |
994 MotionEvent::ACTION_MOVE, | |
995 0, | |
996 scaled_touch_slop / 2, | |
997 kMaxTwoFingerTapSeparation / 2, | |
998 0); | |
999 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1000 | |
1001 event = ObtainMotionEvent(event_time, | |
1002 MotionEvent::ACTION_POINTER_UP, | |
1003 0, | |
1004 scaled_touch_slop / 2, | |
1005 kMaxTwoFingerTapSeparation / 2, | |
1006 0); | |
1007 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1008 | |
1009 // Exceed slop region: scroll | |
1010 event = ObtainMotionEvent(event_time, | |
1011 MotionEvent::ACTION_POINTER_DOWN, | |
1012 0, | |
1013 scaled_touch_slop / 2, | |
1014 kMaxTwoFingerTapSeparation / 2, | |
1015 0); | |
1016 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1017 | |
1018 event = ObtainMotionEvent(event_time, | |
1019 MotionEvent::ACTION_MOVE, | |
1020 0, | |
1021 scaled_touch_slop / 2, | |
1022 kMaxTwoFingerTapSeparation / 2, | |
1023 2 * scaled_touch_slop); | |
1024 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1025 | |
1026 event = ObtainMotionEvent(event_time, | |
1027 MotionEvent::ACTION_POINTER_UP, | |
1028 0, | |
1029 scaled_touch_slop / 2, | |
1030 kMaxTwoFingerTapSeparation / 2, | |
1031 2 * scaled_touch_slop); | |
1032 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1033 | |
1034 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, | |
1035 0, scaled_touch_slop / 2); | |
1036 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1037 | |
1038 | |
1039 | |
1040 // Scroll with three pointers down | |
1041 event_time += kOneSecond; | |
1042 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); | |
1043 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1044 | |
1045 event = ObtainMotionEvent(event_time, | |
1046 MotionEvent::ACTION_POINTER_DOWN, | |
1047 0, | |
1048 0, | |
1049 kMaxTwoFingerTapSeparation / 2, | |
1050 0); | |
1051 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1052 | |
1053 event = ObtainMotionEvent(event_time, | |
1054 MotionEvent::ACTION_POINTER_DOWN, | |
1055 0, | |
1056 0, | |
1057 kMaxTwoFingerTapSeparation / 2, | |
1058 0, | |
1059 2 * kMaxTwoFingerTapSeparation, | |
1060 0); | |
1061 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1062 | |
1063 // Move within slop region, scroll always happens | |
1064 event = ObtainMotionEvent(event_time, | |
1065 MotionEvent::ACTION_MOVE, | |
1066 0, | |
1067 scaled_touch_slop / 2, | |
1068 kMaxTwoFingerTapSeparation / 2, | |
1069 0, | |
1070 2 * kMaxTwoFingerTapSeparation, | |
1071 0); | |
1072 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
1073 | |
1074 | |
1075 | |
1076 // One finger scroll | |
1077 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | |
1078 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | |
1079 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | |
1080 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type()); | |
1081 | |
1082 // Two finger scroll | |
1083 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(4).type()); | |
1084 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(5).type()); | |
1085 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(6).type()); | |
1086 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(7).type()); | |
1087 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(8).type()); | |
1088 | |
1089 // Three finger scroll | |
1090 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(9).type()); | |
1091 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(10).type()); | |
1092 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(11).type()); | |
1093 | |
1094 EXPECT_EQ(12U, GetReceivedGestureCount()); | |
1095 | |
1096 } | |
1097 | |
944 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { | 1098 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { |
945 base::TimeTicks event_time = base::TimeTicks::Now(); | 1099 base::TimeTicks event_time = base::TimeTicks::Now(); |
946 | 1100 |
947 MockMotionEvent event = | 1101 MockMotionEvent event = |
948 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 1102 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
949 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1103 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
950 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 1104 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
951 MotionEvent::ACTION_MOVE, | 1105 MotionEvent::ACTION_MOVE, |
952 kFakeCoordX * 5, | 1106 kFakeCoordX * 5, |
953 kFakeCoordY * 5); | 1107 kFakeCoordY * 5); |
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2148 | 2302 |
2149 event = ObtainMotionEvent(event_time, | 2303 event = ObtainMotionEvent(event_time, |
2150 MotionEvent::ACTION_POINTER_UP, | 2304 MotionEvent::ACTION_POINTER_UP, |
2151 0, | 2305 0, |
2152 0, | 2306 0, |
2153 kMaxTwoFingerTapSeparation, | 2307 kMaxTwoFingerTapSeparation, |
2154 0); | 2308 0); |
2155 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2309 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2156 | 2310 |
2157 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | 2311 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); |
2158 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | 2312 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type()); |
2159 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | 2313 EXPECT_EQ(2U, GetReceivedGestureCount()); |
2160 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(3).type()); | |
2161 EXPECT_EQ(4U, GetReceivedGestureCount()); | |
2162 | |
2163 EXPECT_EQ(kMockTouchRadius * 2, | 2314 EXPECT_EQ(kMockTouchRadius * 2, |
2164 GetReceivedGesture(3).details.first_finger_width()); | 2315 GetReceivedGesture(1).details.first_finger_width()); |
2165 EXPECT_EQ(kMockTouchRadius * 2, | 2316 EXPECT_EQ(kMockTouchRadius * 2, |
2166 GetReceivedGesture(3).details.first_finger_height()); | 2317 GetReceivedGesture(1).details.first_finger_height()); |
2167 } | 2318 } |
2168 | 2319 |
2169 // Test preventing a two finger tap via finger movement. | 2320 // Test preventing a two finger tap via finger movement. |
2170 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { | 2321 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { |
2171 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); | 2322 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); |
2172 const float scaled_touch_slop = GetTouchSlop(); | 2323 const float scaled_touch_slop = GetTouchSlop(); |
2173 base::TimeTicks event_time = base::TimeTicks::Now(); | 2324 base::TimeTicks event_time = base::TimeTicks::Now(); |
2174 | 2325 |
2175 MockMotionEvent event = ObtainMotionEvent( | 2326 MockMotionEvent event = ObtainMotionEvent( |
2176 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | 2327 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); |
2177 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2328 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2178 | 2329 |
2179 event = ObtainMotionEvent(event_time, | 2330 event = ObtainMotionEvent(event_time, |
2180 MotionEvent::ACTION_POINTER_DOWN, | 2331 MotionEvent::ACTION_POINTER_DOWN, |
2181 kFakeCoordX, | 2332 kFakeCoordX, |
2182 kFakeCoordY, | 2333 kFakeCoordY, |
2183 kFakeCoordX, | 2334 kFakeCoordX, |
2184 kFakeCoordY); | 2335 kFakeCoordY); |
2185 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2336 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2186 | 2337 |
2187 event = ObtainMotionEvent(event_time, | 2338 event = ObtainMotionEvent(event_time, |
2188 MotionEvent::ACTION_MOVE, | 2339 MotionEvent::ACTION_MOVE, |
2189 kFakeCoordX, | 2340 kFakeCoordX, |
2190 kFakeCoordY, | 2341 kFakeCoordY, |
2191 kFakeCoordX + scaled_touch_slop + 0.1, | 2342 kFakeCoordX + 2 * scaled_touch_slop + 2, |
2192 kFakeCoordY); | 2343 kFakeCoordY); |
2193 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2344 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2194 | 2345 |
2195 event = ObtainMotionEvent(event_time, | 2346 event = ObtainMotionEvent(event_time, |
2196 MotionEvent::ACTION_POINTER_UP, | 2347 MotionEvent::ACTION_POINTER_UP, |
2197 kFakeCoordX, | 2348 kFakeCoordX, |
2198 kFakeCoordY, | 2349 kFakeCoordY, |
2199 kFakeCoordX, | 2350 kFakeCoordX, |
2200 kFakeCoordY); | 2351 kFakeCoordY); |
2201 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2352 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2202 | 2353 |
2203 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); | 2354 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); |
2204 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); | 2355 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); |
2205 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); | 2356 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); |
2206 EXPECT_FLOAT_EQ((scaled_touch_slop + 0.1) / 2, | 2357 // d_x = 2 * scaled_touch_slop + 2, |
2358 // d_focus_x = scaled_touch_slop + 1, | |
2359 // touch_slop / event.GetPointerCount() is deducted from first scroll, | |
2360 // scroll_x = scaled_touch_slop + 1 - scaled_touch_slop / 2 | |
2361 EXPECT_FLOAT_EQ(scaled_touch_slop / 2 + 1, | |
2207 GetReceivedGesture(2).details.scroll_x()); | 2362 GetReceivedGesture(2).details.scroll_x()); |
2208 EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y()); | 2363 EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y()); |
2209 EXPECT_EQ(3U, GetReceivedGestureCount()); | 2364 EXPECT_EQ(3U, GetReceivedGestureCount()); |
2210 } | 2365 } |
2211 | 2366 |
2212 // Test preventing a two finger tap by waiting too long before releasing the | 2367 // Test preventing a two finger tap by waiting too long before releasing the |
2213 // secondary pointer. | 2368 // secondary pointer. |
2214 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { | 2369 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { |
2215 base::TimeDelta two_finger_tap_timeout = kOneSecond; | 2370 base::TimeDelta two_finger_tap_timeout = kOneSecond; |
2216 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); | 2371 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2639 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, | 2794 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, |
2640 kFakeCoordY + GetTouchSlop() / 2); | 2795 kFakeCoordY + GetTouchSlop() / 2); |
2641 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2796 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2642 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | 2797 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); |
2643 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2798 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2644 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | 2799 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); |
2645 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | 2800 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); |
2646 } | 2801 } |
2647 | 2802 |
2648 } // namespace ui | 2803 } // namespace ui |
OLD | NEW |