Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 2058723003: Slop region check for multi-finger scroll (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 927 matching lines...) Expand 10 before | Expand all | Expand 10 after
938 kFakeCoordY + delta_y); 938 kFakeCoordY + delta_y);
939 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 939 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
940 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 940 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
941 941
942 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); 942 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
943 ASSERT_TRUE(scroll_begin_gesture); 943 ASSERT_TRUE(scroll_begin_gesture);
944 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); 944 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint());
945 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); 945 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint());
946 } 946 }
947 947
948 // Verify that slop regions are checked for one and two finger scrolls,
949 // three-finger tap doesn't exist, no slop region check is needed for
950 // three-finger scrolls.
951 TEST_F(GestureProviderTest, SlopRegionCheckOnScroll) {
tdresser 2016/06/28 15:24:19 Can we split this into three tests, one per number
sahel 2016/06/29 16:26:19 Done.
952 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
953 const float scaled_touch_slop = GetTouchSlop();
954
955 base::TimeTicks event_time = base::TimeTicks::Now();
956
957
958
tdresser 2016/06/28 15:24:19 This is a bit more whitespace than we'd usually us
sahel 2016/06/29 16:26:19 Done.
959 // Scrolls with one pointer down.
960 MockMotionEvent event =
961 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0);
962 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
963
964 // Moves within slop region.
965 event = ObtainMotionEvent(event_time,
966 MotionEvent::ACTION_MOVE,
967 0,
968 scaled_touch_slop / 2);
969 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
970
971 // Exceeds slop region.
972 event = ObtainMotionEvent(event_time,
973 MotionEvent::ACTION_MOVE,
974 0,
975 2 * scaled_touch_slop);
976 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
977
978 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP,
979 0, 2 * scaled_touch_slop);
980 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
981
982
983
984 // Scrolls with two pointers down.
985 event_time += kOneSecond;
986 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0);
987 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
988
989 event = ObtainMotionEvent(event_time,
990 MotionEvent::ACTION_POINTER_DOWN,
991 0,
992 0,
993 kMaxTwoFingerTapSeparation / 2,
994 0);
995 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
996
997 // Moves within slop region: two-finger tap.
998 event = ObtainMotionEvent(event_time,
999 MotionEvent::ACTION_MOVE,
1000 0,
1001 scaled_touch_slop / 2,
1002 kMaxTwoFingerTapSeparation / 2,
1003 0);
1004 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1005
1006 event = ObtainMotionEvent(event_time,
1007 MotionEvent::ACTION_POINTER_UP,
1008 0,
1009 scaled_touch_slop / 2,
1010 kMaxTwoFingerTapSeparation / 2,
1011 0);
1012 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1013
1014 // Exceeds slop region: scroll.
1015 event = ObtainMotionEvent(event_time,
1016 MotionEvent::ACTION_POINTER_DOWN,
1017 0,
1018 scaled_touch_slop / 2,
1019 kMaxTwoFingerTapSeparation / 2,
1020 0);
1021 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1022
1023 event = ObtainMotionEvent(event_time,
1024 MotionEvent::ACTION_MOVE,
1025 0,
1026 scaled_touch_slop / 2,
1027 kMaxTwoFingerTapSeparation / 2,
1028 2 * scaled_touch_slop);
1029 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1030
1031 event = ObtainMotionEvent(event_time,
1032 MotionEvent::ACTION_POINTER_UP,
1033 0,
1034 scaled_touch_slop / 2,
1035 kMaxTwoFingerTapSeparation / 2,
1036 2 * scaled_touch_slop);
1037 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1038
1039 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP,
1040 0, scaled_touch_slop / 2);
1041 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1042
1043
1044
1045 // Scrolls with three pointers down.
1046 event_time += kOneSecond;
1047 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0);
1048 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1049
1050 event = ObtainMotionEvent(event_time,
1051 MotionEvent::ACTION_POINTER_DOWN,
1052 0,
1053 0,
1054 kMaxTwoFingerTapSeparation / 2,
1055 0);
1056 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1057
1058 event = ObtainMotionEvent(event_time,
1059 MotionEvent::ACTION_POINTER_DOWN,
1060 0,
1061 0,
1062 kMaxTwoFingerTapSeparation / 2,
1063 0,
1064 2 * kMaxTwoFingerTapSeparation,
1065 0);
1066 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1067
1068 // Moves within slop region, three-finger scroll always happens
1069 event = ObtainMotionEvent(event_time,
1070 MotionEvent::ACTION_MOVE,
1071 0,
1072 scaled_touch_slop / 2,
1073 kMaxTwoFingerTapSeparation / 2,
1074 0,
1075 2 * kMaxTwoFingerTapSeparation,
1076 0);
1077 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1078
1079
1080
1081 // One finger scroll
tdresser 2016/06/28 15:24:19 Missing periods.
1082 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
1083 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
1084 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
1085 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(3).type());
1086
1087 // Two-finger scroll
1088 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(4).type());
1089 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(5).type());
1090 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(6).type());
1091 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(7).type());
1092 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetReceivedGesture(8).type());
1093
1094 // Three-finger scroll
1095 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(9).type());
1096 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(10).type());
1097 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(11).type());
1098
1099 EXPECT_EQ(12U, GetReceivedGestureCount());
1100
1101 }
1102
948 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { 1103 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
949 base::TimeTicks event_time = base::TimeTicks::Now(); 1104 base::TimeTicks event_time = base::TimeTicks::Now();
950 1105
951 MockMotionEvent event = 1106 MockMotionEvent event =
952 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1107 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
953 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1108 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
954 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1109 event = ObtainMotionEvent(event_time + kOneMicrosecond,
955 MotionEvent::ACTION_MOVE, 1110 MotionEvent::ACTION_MOVE,
956 kFakeCoordX * 5, 1111 kFakeCoordX * 5,
957 kFakeCoordY * 5); 1112 kFakeCoordY * 5);
(...skipping 1194 matching lines...) Expand 10 before | Expand all | Expand 10 after
2152 2307
2153 event = ObtainMotionEvent(event_time, 2308 event = ObtainMotionEvent(event_time,
2154 MotionEvent::ACTION_POINTER_UP, 2309 MotionEvent::ACTION_POINTER_UP,
2155 0, 2310 0,
2156 0, 2311 0,
2157 kMaxTwoFingerTapSeparation, 2312 kMaxTwoFingerTapSeparation,
2158 0); 2313 0);
2159 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2314 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2160 2315
2161 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); 2316 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2162 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); 2317 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(1).type());
2163 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); 2318 EXPECT_EQ(2U, GetReceivedGestureCount());
2164 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(3).type());
2165 EXPECT_EQ(4U, GetReceivedGestureCount());
2166
2167 EXPECT_EQ(kMockTouchRadius * 2, 2319 EXPECT_EQ(kMockTouchRadius * 2,
2168 GetReceivedGesture(3).details.first_finger_width()); 2320 GetReceivedGesture(1).details.first_finger_width());
2169 EXPECT_EQ(kMockTouchRadius * 2, 2321 EXPECT_EQ(kMockTouchRadius * 2,
2170 GetReceivedGesture(3).details.first_finger_height()); 2322 GetReceivedGesture(1).details.first_finger_height());
2171 } 2323 }
2172 2324
2173 // Test preventing a two finger tap via finger movement. 2325 // Test preventing a two finger tap via finger movement.
2174 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { 2326 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) {
2175 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); 2327 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2176 const float scaled_touch_slop = GetTouchSlop(); 2328 const float scaled_touch_slop = GetTouchSlop();
2177 base::TimeTicks event_time = base::TimeTicks::Now(); 2329 base::TimeTicks event_time = base::TimeTicks::Now();
2178 2330
2179 MockMotionEvent event = ObtainMotionEvent( 2331 MockMotionEvent event = ObtainMotionEvent(
2180 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 2332 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
2181 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2333 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2182 2334
2183 event = ObtainMotionEvent(event_time, 2335 event = ObtainMotionEvent(event_time,
2184 MotionEvent::ACTION_POINTER_DOWN, 2336 MotionEvent::ACTION_POINTER_DOWN,
2185 kFakeCoordX, 2337 kFakeCoordX,
2186 kFakeCoordY, 2338 kFakeCoordY,
2187 kFakeCoordX, 2339 kFakeCoordX,
2188 kFakeCoordY); 2340 kFakeCoordY);
2189 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2341 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2190 2342
2191 event = ObtainMotionEvent(event_time, 2343 event = ObtainMotionEvent(event_time,
2192 MotionEvent::ACTION_MOVE, 2344 MotionEvent::ACTION_MOVE,
2193 kFakeCoordX, 2345 kFakeCoordX,
2194 kFakeCoordY, 2346 kFakeCoordY,
2195 kFakeCoordX + scaled_touch_slop + 0.1, 2347 kFakeCoordX + 2 * scaled_touch_slop + 2,
2196 kFakeCoordY); 2348 kFakeCoordY);
2197 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2349 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2198 2350
2199 event = ObtainMotionEvent(event_time, 2351 event = ObtainMotionEvent(event_time,
2200 MotionEvent::ACTION_POINTER_UP, 2352 MotionEvent::ACTION_POINTER_UP,
2201 kFakeCoordX, 2353 kFakeCoordX,
2202 kFakeCoordY, 2354 kFakeCoordY,
2203 kFakeCoordX, 2355 kFakeCoordX,
2204 kFakeCoordY); 2356 kFakeCoordY);
2205 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2357 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2206 2358
2207 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); 2359 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2208 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); 2360 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
2209 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type()); 2361 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(2).type());
2210 EXPECT_FLOAT_EQ((scaled_touch_slop + 0.1) / 2, 2362 // d_x = 2 * scaled_touch_slop + 2,
2363 // d_focus_x = scaled_touch_slop + 1,
2364 // touch_slop / event.GetPointerCount() is deducted from first scroll,
2365 // scroll_x = scaled_touch_slop + 1 - scaled_touch_slop / 2
2366 EXPECT_FLOAT_EQ(scaled_touch_slop / 2 + 1,
2211 GetReceivedGesture(2).details.scroll_x()); 2367 GetReceivedGesture(2).details.scroll_x());
2212 EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y()); 2368 EXPECT_EQ(0, GetReceivedGesture(2).details.scroll_y());
2213 EXPECT_EQ(3U, GetReceivedGestureCount()); 2369 EXPECT_EQ(3U, GetReceivedGestureCount());
2214 } 2370 }
2215 2371
2216 // Test preventing a two finger tap by waiting too long before releasing the 2372 // Test preventing a two finger tap by waiting too long before releasing the
2217 // secondary pointer. 2373 // secondary pointer.
2218 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { 2374 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) {
2219 base::TimeDelta two_finger_tap_timeout = kOneSecond; 2375 base::TimeDelta two_finger_tap_timeout = kOneSecond;
2220 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); 2376 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout);
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
2643 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, 2799 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX,
2644 kFakeCoordY + GetTouchSlop() / 2); 2800 kFakeCoordY + GetTouchSlop() / 2);
2645 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2801 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2646 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); 2802 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2647 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2803 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2648 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2804 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2649 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 2805 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2650 } 2806 }
2651 2807
2652 } // namespace ui 2808 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698