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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 base::TimeDelta two_finger_tap_timeout) { | 210 base::TimeDelta two_finger_tap_timeout) { |
211 GestureProvider::Config config = GetDefaultConfig(); | 211 GestureProvider::Config config = GetDefaultConfig(); |
212 config.gesture_detector_config.two_finger_tap_enabled = true; | 212 config.gesture_detector_config.two_finger_tap_enabled = true; |
213 config.gesture_detector_config.two_finger_tap_max_separation = | 213 config.gesture_detector_config.two_finger_tap_max_separation = |
214 max_distance_for_two_finger_tap; | 214 max_distance_for_two_finger_tap; |
215 config.gesture_detector_config.two_finger_tap_timeout = | 215 config.gesture_detector_config.two_finger_tap_timeout = |
216 two_finger_tap_timeout; | 216 two_finger_tap_timeout; |
217 SetUpWithConfig(config); | 217 SetUpWithConfig(config); |
218 } | 218 } |
219 | 219 |
| 220 void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta) { |
| 221 GestureProvider::Config config = GetDefaultConfig(); |
| 222 config.scale_gesture_detector_config.min_pinch_update_span_delta = |
| 223 min_pinch_update_span_delta; |
| 224 SetUpWithConfig(config); |
| 225 } |
| 226 |
220 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } | 227 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } |
221 | 228 |
222 protected: | 229 protected: |
223 void CheckScrollEventSequenceForEndActionType( | 230 void CheckScrollEventSequenceForEndActionType( |
224 MotionEvent::Action end_action_type) { | 231 MotionEvent::Action end_action_type) { |
225 base::TimeTicks event_time = base::TimeTicks::Now(); | 232 base::TimeTicks event_time = base::TimeTicks::Now(); |
226 const float scroll_to_x = kFakeCoordX + 100; | 233 const float scroll_to_x = kFakeCoordX + 100; |
227 const float scroll_to_y = kFakeCoordY + 100; | 234 const float scroll_to_y = kFakeCoordY + 100; |
228 int motion_event_id = 0; | 235 int motion_event_id = 0; |
229 | 236 |
(...skipping 1673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1903 kFakeCoordX, | 1910 kFakeCoordX, |
1904 kFakeCoordY, | 1911 kFakeCoordY, |
1905 kFakeCoordX + kMaxTwoFingerTapSeparation, | 1912 kFakeCoordX + kMaxTwoFingerTapSeparation, |
1906 kFakeCoordY); | 1913 kFakeCoordY); |
1907 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1914 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1908 | 1915 |
1909 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); | 1916 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); |
1910 EXPECT_EQ(1U, GetReceivedGestureCount()); | 1917 EXPECT_EQ(1U, GetReceivedGestureCount()); |
1911 } | 1918 } |
1912 | 1919 |
| 1920 // Verify that pinch zoom only sends updates which exceed the |
| 1921 // min_pinch_update_span_delta. |
| 1922 TEST_F(GestureProviderTest, PinchZoomWithThreshold) { |
| 1923 const float kMinPinchUpdateDistance = 5; |
| 1924 |
| 1925 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 1926 const float touch_slop = GetTouchSlop(); |
| 1927 |
| 1928 SetMinPinchUpdateSpanDelta(kMinPinchUpdateDistance); |
| 1929 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); |
| 1930 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); |
| 1931 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); |
| 1932 |
| 1933 int secondary_coord_x = kFakeCoordX + 20 * touch_slop; |
| 1934 int secondary_coord_y = kFakeCoordY + 20 * touch_slop; |
| 1935 |
| 1936 // First finger down. |
| 1937 MockMotionEvent event = |
| 1938 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 1939 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1940 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1941 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
| 1942 |
| 1943 // Second finger down. |
| 1944 event = ObtainMotionEvent(event_time, |
| 1945 MotionEvent::ACTION_POINTER_DOWN, |
| 1946 kFakeCoordX, |
| 1947 kFakeCoordY, |
| 1948 secondary_coord_x, |
| 1949 secondary_coord_y); |
| 1950 |
| 1951 gesture_provider_->OnTouchEvent(event); |
| 1952 EXPECT_EQ(1U, GetReceivedGestureCount()); |
| 1953 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
| 1954 |
| 1955 // Move second finger. |
| 1956 secondary_coord_x += 5 * touch_slop; |
| 1957 secondary_coord_y += 5 * touch_slop; |
| 1958 event = ObtainMotionEvent(event_time, |
| 1959 MotionEvent::ACTION_MOVE, |
| 1960 kFakeCoordX, |
| 1961 kFakeCoordY, |
| 1962 secondary_coord_x, |
| 1963 secondary_coord_y); |
| 1964 |
| 1965 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1966 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); |
| 1967 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); |
| 1968 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); |
| 1969 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| 1970 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); |
| 1971 |
| 1972 // Small move, shouldn't trigger pinch. |
| 1973 event = ObtainMotionEvent(event_time, |
| 1974 MotionEvent::ACTION_MOVE, |
| 1975 kFakeCoordX, |
| 1976 kFakeCoordY, |
| 1977 secondary_coord_x + kMinPinchUpdateDistance, |
| 1978 secondary_coord_y); |
| 1979 |
| 1980 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1981 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); |
| 1982 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); |
| 1983 |
| 1984 // Small move, but combined with the previous move, should trigger pinch. We |
| 1985 // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span |
| 1986 // calculation factors in touch radius. |
| 1987 const float kOvershootMinPinchUpdateDistance = 3; |
| 1988 event = ObtainMotionEvent(event_time, |
| 1989 MotionEvent::ACTION_MOVE, |
| 1990 kFakeCoordX, |
| 1991 kFakeCoordY, |
| 1992 secondary_coord_x + kMinPinchUpdateDistance + |
| 1993 kOvershootMinPinchUpdateDistance, |
| 1994 secondary_coord_y); |
| 1995 |
| 1996 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1997 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); |
| 1998 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); |
| 1999 } |
| 2000 |
1913 } // namespace ui | 2001 } // namespace ui |
OLD | NEW |