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

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

Issue 289373009: Support tap_count in ui::GestureProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small cleanup. 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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 171
172 const GestureProvider::Config& GetDefaultConfig() const { 172 const GestureProvider::Config& GetDefaultConfig() const {
173 static GestureProvider::Config sConfig = CreateDefaultConfig(); 173 static GestureProvider::Config sConfig = CreateDefaultConfig();
174 return sConfig; 174 return sConfig;
175 } 175 }
176 176
177 float GetTouchSlop() const { 177 float GetTouchSlop() const {
178 return GetDefaultConfig().gesture_detector_config.touch_slop; 178 return GetDefaultConfig().gesture_detector_config.touch_slop;
179 } 179 }
180 180
181 float GetDoubleTapSlop() const {
182 return GetDefaultConfig().gesture_detector_config.double_tap_slop;
183 }
184
181 float GetMinSwipeVelocity() const { 185 float GetMinSwipeVelocity() const {
182 return GetDefaultConfig().gesture_detector_config.minimum_swipe_velocity; 186 return GetDefaultConfig().gesture_detector_config.minimum_swipe_velocity;
183 } 187 }
184 188
185 base::TimeDelta GetLongPressTimeout() const { 189 base::TimeDelta GetLongPressTimeout() const {
186 return GetDefaultConfig().gesture_detector_config.longpress_timeout; 190 return GetDefaultConfig().gesture_detector_config.longpress_timeout;
187 } 191 }
188 192
189 base::TimeDelta GetShowPressTimeout() const { 193 base::TimeDelta GetShowPressTimeout() const {
190 return GetDefaultConfig().gesture_detector_config.showpress_timeout; 194 return GetDefaultConfig().gesture_detector_config.showpress_timeout;
(...skipping 1712 matching lines...) Expand 10 before | Expand all | Expand 10 after
1903 kFakeCoordX, 1907 kFakeCoordX,
1904 kFakeCoordY, 1908 kFakeCoordY,
1905 kFakeCoordX + kMaxTwoFingerTapSeparation, 1909 kFakeCoordX + kMaxTwoFingerTapSeparation,
1906 kFakeCoordY); 1910 kFakeCoordY);
1907 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1911 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1908 1912
1909 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); 1913 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type);
1910 EXPECT_EQ(1U, GetReceivedGestureCount()); 1914 EXPECT_EQ(1U, GetReceivedGestureCount());
1911 } 1915 }
1912 1916
1917 TEST_F(GestureProviderTest, TripleTap) {
1918 const float slop = GetDoubleTapSlop();
1919 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1920 base::TimeTicks event_time = base::TimeTicks::Now();
1921
1922 // First Tap.
1923 MockMotionEvent event =
1924 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1925 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1926
1927 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1928 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1929
1930 event_time += kOneMicrosecond;
1931 event = ObtainMotionEvent(
1932 event_time, MotionEvent::ACTION_UP, kFakeCoordX, kFakeCoordY);
1933 gesture_provider_->OnTouchEvent(event);
1934 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1935 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1936 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
1937
1938 // Second Tap.
1939 event_time += kOneMicrosecond;
1940 event = ObtainMotionEvent(
1941 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX + slop, kFakeCoordY);
1942 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1943 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1944 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1945
1946 event_time += kOneMicrosecond;
1947 event = ObtainMotionEvent(
1948 event_time, MotionEvent::ACTION_UP, kFakeCoordX + slop, kFakeCoordY);
1949 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1950
1951 const GestureEventData& second_tap = GetMostRecentGestureEvent();
1952 EXPECT_EQ(ET_GESTURE_TAP, second_tap.type);
1953 // Ensure tap details have been set.
1954 EXPECT_EQ(10, second_tap.details.bounding_box().width());
1955 EXPECT_EQ(10, second_tap.details.bounding_box().height());
1956 EXPECT_EQ(2, second_tap.details.tap_count());
1957
1958 // Third, Fourth and Fifth Taps. Taps after the third should still get a
1959 // tap_count of 3, as 3 is the maximum.
1960 for (int i = 0; i < 3; ++i) {
1961 event_time += kOneMicrosecond;
1962 // We keep tapping inside the previous tap's slop region.
1963 event = ObtainMotionEvent(event_time,
1964 MotionEvent::ACTION_DOWN,
1965 kFakeCoordX + slop * (2 + i),
1966 kFakeCoordY);
1967 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1968 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1969 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1970
1971 event_time += kOneMicrosecond;
1972 event = ObtainMotionEvent(event_time,
1973 MotionEvent::ACTION_UP,
1974 kFakeCoordX + slop * (2 + i),
1975 kFakeCoordY);
1976 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1977
1978 const GestureEventData& third_tap = GetMostRecentGestureEvent();
1979 EXPECT_EQ(ET_GESTURE_TAP, third_tap.type);
1980 // Ensure tap details have been set.
1981 EXPECT_EQ(10, third_tap.details.bounding_box().width());
1982 EXPECT_EQ(10, third_tap.details.bounding_box().height());
1983 EXPECT_EQ(3, third_tap.details.tap_count());
1984 }
1985
1986 // Tap outside of the slop area. This should reset the |tap_count| to 1.
1987 event_time += kOneMicrosecond;
1988 event = ObtainMotionEvent(event_time,
1989 MotionEvent::ACTION_DOWN,
1990 kFakeCoordX,
1991 kFakeCoordY);
1992 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1993 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1994 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1995
1996 event_time += kOneMicrosecond;
1997 event = ObtainMotionEvent(event_time,
1998 MotionEvent::ACTION_UP,
1999 kFakeCoordX,
2000 kFakeCoordY);
2001 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2002
2003 const GestureEventData& final_tap = GetMostRecentGestureEvent();
2004 EXPECT_EQ(ET_GESTURE_TAP, final_tap.type);
2005 // Ensure tap details have been set.
2006 EXPECT_EQ(10, final_tap.details.bounding_box().width());
2007 EXPECT_EQ(10, final_tap.details.bounding_box().height());
2008 EXPECT_EQ(1, final_tap.details.tap_count());
2009 }
2010
1913 } // namespace ui 2011 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698