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

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

Issue 223673006: Support GestureBegin and GestureEnd in ui::GestureProvider (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 23 matching lines...) Expand all
34 sConfig.gesture_detector_config.showpress_timeout = base::TimeDelta(); 34 sConfig.gesture_detector_config.showpress_timeout = base::TimeDelta();
35 sConfig.gesture_detector_config.longpress_timeout = kOneMicrosecond; 35 sConfig.gesture_detector_config.longpress_timeout = kOneMicrosecond;
36 36
37 // A valid doubletap timeout should always be non-zero. The value is used not 37 // A valid doubletap timeout should always be non-zero. The value is used not
38 // only to trigger the timeout that confirms the tap event, but also to gate 38 // only to trigger the timeout that confirms the tap event, but also to gate
39 // whether the second tap is in fact a double-tap (using a strict inequality 39 // whether the second tap is in fact a double-tap (using a strict inequality
40 // between times for the first up and the second down events). We use 4 40 // between times for the first up and the second down events). We use 4
41 // microseconds simply to allow several intermediate events to occur before 41 // microseconds simply to allow several intermediate events to occur before
42 // the second tap at microsecond intervals. 42 // the second tap at microsecond intervals.
43 sConfig.gesture_detector_config.double_tap_timeout = kOneMicrosecond * 4; 43 sConfig.gesture_detector_config.double_tap_timeout = kOneMicrosecond * 4;
44 sConfig.send_aura_specific_gestures = true;
jdduke (slow) 2014/04/03 20:17:16 I'd prefer if this default'ed to false, and we had
tdresser 2014/04/03 21:14:41 Done.
44 return sConfig; 45 return sConfig;
45 } 46 }
46 47
47 } // namespace 48 } // namespace
48 49
49 class GestureProviderTest : public testing::Test, public GestureProviderClient { 50 class GestureProviderTest : public testing::Test, public GestureProviderClient {
50 public: 51 public:
51 GestureProviderTest() {} 52 GestureProviderTest() {}
52 virtual ~GestureProviderTest() {} 53 virtual ~GestureProviderTest() {}
53 54
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 155 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
155 156
156 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 157 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
157 158
158 event = ObtainMotionEvent(event_time + kOneSecond, 159 event = ObtainMotionEvent(event_time + kOneSecond,
159 MotionEvent::ACTION_MOVE, 160 MotionEvent::ACTION_MOVE,
160 scroll_to_x, 161 scroll_to_x,
161 scroll_to_y); 162 scroll_to_y);
162 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 163 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
163 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 164 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
164 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 165 ASSERT_EQ(5U, GetReceivedGestureCount())
165 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 166 << "Only GestureBegin, TapDown, TapCancel, ScrollBegin and ScrollBy "
166 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, " 167 << "should have been sent.";
167 "ScrollBegin and ScrollBy " 168 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
168 "should have been sent"; 169 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(1).type);
169 170 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(2).type);
170 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(1).type); 171 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(3).type);
171 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); 172 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(3).time)
172 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time)
173 << "ScrollBegin should have the time of the ACTION_MOVE"; 173 << "ScrollBegin should have the time of the ACTION_MOVE";
174 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(4).type);
174 175
175 event = ObtainMotionEvent( 176 event = ObtainMotionEvent(
176 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); 177 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
177 gesture_provider_->OnTouchEvent(event); 178 gesture_provider_->OnTouchEvent(event);
178 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 179 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
179 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 180 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
180 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 181 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
181 } 182 }
182 183
183 static void RunTasksAndWait(base::TimeDelta delay) { 184 static void RunTasksAndWait(base::TimeDelta delay) {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 292 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
292 293
293 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 294 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
294 295
295 event = ObtainMotionEvent(event_time + delta_time, 296 event = ObtainMotionEvent(event_time + delta_time,
296 MotionEvent::ACTION_MOVE, 297 MotionEvent::ACTION_MOVE,
297 kFakeCoordX * 5, 298 kFakeCoordX * 5,
298 kFakeCoordY * 5); 299 kFakeCoordY * 5);
299 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 300 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
300 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 301 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
301 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 302 ASSERT_EQ(5U, GetReceivedGestureCount());
302 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 303 ASSERT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
303 ASSERT_EQ(4U, GetReceivedGestureCount()); 304 ASSERT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(1).type);
304 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); 305 ASSERT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(2).type);
306 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(3).type);
307 ASSERT_EQ(ET_GESTURE_SCROLL_UPDATE, GetReceivedGesture(4).type);
305 308
306 // We don't want to take a dependency here on exactly how hints are calculated 309 // We don't want to take a dependency here on exactly how hints are calculated
307 // for a fling (eg. may depend on velocity), so just validate the direction. 310 // for a fling (eg. may depend on velocity), so just validate the direction.
308 int hint_x = GetReceivedGesture(2).details.scroll_x_hint(); 311 int hint_x = GetReceivedGesture(3).details.scroll_x_hint();
309 int hint_y = GetReceivedGesture(2).details.scroll_y_hint(); 312 int hint_y = GetReceivedGesture(3).details.scroll_y_hint();
310 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) 313 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
311 << "ScrollBegin hint should be in positive X axis"; 314 << "ScrollBegin hint should be in positive X axis";
312 315
313 event = ObtainMotionEvent(event_time + delta_time * 2, 316 event = ObtainMotionEvent(event_time + delta_time * 2,
314 MotionEvent::ACTION_UP, 317 MotionEvent::ACTION_UP,
315 kFakeCoordX * 10, 318 kFakeCoordX * 10,
316 kFakeCoordY * 10); 319 kFakeCoordY * 10);
317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 320 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
318 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 321 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
319 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 322 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 495 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
493 const size_t gesture_count = GetReceivedGestureCount(); 496 const size_t gesture_count = GetReceivedGestureCount();
494 497
495 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 498 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
496 MotionEvent::ACTION_POINTER_UP, 499 MotionEvent::ACTION_POINTER_UP,
497 kFakeCoordX, 500 kFakeCoordX,
498 kFakeCoordY - 30, 501 kFakeCoordY - 30,
499 kFakeCoordX + 50, 502 kFakeCoordX + 50,
500 kFakeCoordY + 50); 503 kFakeCoordY + 50);
501 gesture_provider_->OnTouchEvent(event); 504 gesture_provider_->OnTouchEvent(event);
502 EXPECT_EQ(gesture_count, GetReceivedGestureCount()); 505 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
506 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount());
503 } 507 }
504 508
505 // Generate a scroll gesture and verify that the resulting scroll motion event 509 // Generate a scroll gesture and verify that the resulting scroll motion event
506 // has both absolute and relative position information. 510 // has both absolute and relative position information.
507 TEST_F(GestureProviderTest, ScrollUpdateValues) { 511 TEST_F(GestureProviderTest, ScrollUpdateValues) {
508 const int delta_x = 16; 512 const int delta_x = 16;
509 const int delta_y = 84; 513 const int delta_y = 84;
510 514
511 const base::TimeTicks event_time = TimeTicks::Now(); 515 const base::TimeTicks event_time = TimeTicks::Now();
512 516
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 EXPECT_EQ(scroll_delta, gesture.details.scroll_y()); 771 EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
768 } 772 }
769 773
770 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) { 774 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
771 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 775 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
772 776
773 base::TimeTicks event_time = base::TimeTicks::Now(); 777 base::TimeTicks event_time = base::TimeTicks::Now();
774 MockMotionEvent event = ObtainMotionEvent( 778 MockMotionEvent event = ObtainMotionEvent(
775 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 779 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
776 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 780 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
777 EXPECT_EQ(1U, GetReceivedGestureCount()); 781 EXPECT_EQ(2U, GetReceivedGestureCount());
778 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 782 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
783 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
779 784
780 event = ObtainMotionEvent(event_time + kOneMicrosecond, 785 event = ObtainMotionEvent(event_time + kOneMicrosecond,
781 MotionEvent::ACTION_UP, 786 MotionEvent::ACTION_UP,
782 kFakeCoordX, 787 kFakeCoordX,
783 kFakeCoordY); 788 kFakeCoordY);
784 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 789 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
785 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 790 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
786 791
787 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 792 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
788 MotionEvent::ACTION_DOWN, 793 MotionEvent::ACTION_DOWN,
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
991 996
992 gesture_provider_->SetMultiTouchSupportEnabled(true); 997 gesture_provider_->SetMultiTouchSupportEnabled(true);
993 998
994 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; 999 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop;
995 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; 1000 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop;
996 1001
997 MockMotionEvent event = 1002 MockMotionEvent event =
998 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1003 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
999 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1004 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1000 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1005 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1006 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
1001 1007
1002 event = ObtainMotionEvent(event_time, 1008 event = ObtainMotionEvent(event_time,
1003 MotionEvent::ACTION_POINTER_DOWN, 1009 MotionEvent::ACTION_POINTER_DOWN,
1004 kFakeCoordX, 1010 kFakeCoordX,
1005 kFakeCoordY, 1011 kFakeCoordY,
1006 secondary_coord_x, 1012 secondary_coord_x,
1007 secondary_coord_y); 1013 secondary_coord_y);
1008 gesture_provider_->OnTouchEvent(event); 1014 gesture_provider_->OnTouchEvent(event);
1009 EXPECT_EQ(1U, GetReceivedGestureCount()); 1015 EXPECT_EQ(3U, GetReceivedGestureCount());
1016 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(2).type);
1010 1017
1011 secondary_coord_x += 5 * scaled_touch_slop; 1018 secondary_coord_x += 5 * scaled_touch_slop;
1012 secondary_coord_y += 5 * scaled_touch_slop; 1019 secondary_coord_y += 5 * scaled_touch_slop;
1013 1020
1014 event = ObtainMotionEvent(event_time, 1021 event = ObtainMotionEvent(event_time,
1015 MotionEvent::ACTION_MOVE, 1022 MotionEvent::ACTION_MOVE,
1016 kFakeCoordX, 1023 kFakeCoordX,
1017 kFakeCoordY, 1024 kFakeCoordY,
1018 secondary_coord_x, 1025 secondary_coord_x,
1019 secondary_coord_y); 1026 secondary_coord_y);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 MotionEvent::ACTION_UP); 1095 MotionEvent::ACTION_UP);
1089 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 1096 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1090 1097
1091 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 1098 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
1092 MotionEvent::ACTION_DOWN); 1099 MotionEvent::ACTION_DOWN);
1093 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1100 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1094 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1101 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1095 } 1102 }
1096 1103
1097 } // namespace ui 1104 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698