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

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

Issue 298823006: [Aura] Reduce frequency of PinchUpdate events. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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 | Annotate | Revision Log
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 "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
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 SetMinPinchUpdateDistance(float min_pinch_update_distance) {
221 GestureProvider::Config config = GetDefaultConfig();
222 config.scale_gesture_detector_config.min_pinch_update_distance =
223 min_pinch_update_distance;
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
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_distance.
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 int motion_event_id = 0;
1928
1929 SetMinPinchUpdateDistance(kMinPinchUpdateDistance);
1930 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1931 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1932 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1933
1934 int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
1935 int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
1936
1937 // First finger down.
1938 MockMotionEvent event =
1939 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1940 event.SetId(++motion_event_id);
1941 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1942 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1943 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1944
1945 // Second finger down.
1946 event = ObtainMotionEvent(event_time,
1947 MotionEvent::ACTION_POINTER_DOWN,
1948 kFakeCoordX,
1949 kFakeCoordY,
1950 secondary_coord_x,
1951 secondary_coord_y);
1952 event.SetId(++motion_event_id);
jdduke (slow) 2014/05/21 19:30:37 Nit: Let's remove all of the touch id assignment a
tdresser 2014/05/22 12:31:44 Done.
1953
1954 gesture_provider_->OnTouchEvent(event);
1955 EXPECT_EQ(1U, GetReceivedGestureCount());
1956 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1957
1958 // Move second finger.
1959 secondary_coord_x += 5 * touch_slop;
1960 secondary_coord_y += 5 * touch_slop;
1961 event = ObtainMotionEvent(event_time,
1962 MotionEvent::ACTION_MOVE,
1963 kFakeCoordX,
1964 kFakeCoordY,
1965 secondary_coord_x,
1966 secondary_coord_y);
1967 event.SetId(++motion_event_id);
1968
1969 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1970 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1971 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1972 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1973 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1974 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1975 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1976
1977 // Small move, shouldn't trigger pinch.
1978 event = ObtainMotionEvent(event_time,
1979 MotionEvent::ACTION_MOVE,
1980 kFakeCoordX,
1981 kFakeCoordY,
1982 secondary_coord_x + kMinPinchUpdateDistance,
1983 secondary_coord_y);
1984 event.SetId(++motion_event_id);
1985
1986 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1987 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1988 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1989
1990 // Small move, but combined with the previous move, should trigger pinch. We
1991 // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span
1992 // calculation factors in touch radius.
1993 const float kOvershootMinPinchUpdateDistance = 3;
jdduke (slow) 2014/05/21 19:30:37 Hmm, where do you get 3 from?
tdresser 2014/05/22 12:31:44 It comes from the way that touch radius factors in
1994 event = ObtainMotionEvent(event_time,
1995 MotionEvent::ACTION_MOVE,
1996 kFakeCoordX,
1997 kFakeCoordY,
1998 secondary_coord_x + kMinPinchUpdateDistance +
1999 kOvershootMinPinchUpdateDistance,
2000 secondary_coord_y);
2001 event.SetId(++motion_event_id);
2002
2003 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2004 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
2005 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
2006 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2007 }
2008
1913 } // namespace ui 2009 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698