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 3 // found in the LICENSE file. 4 5 #include "base/basictypes.h" 6 #include "base/logging.h" 7 #include "base/memory/scoped_ptr.h" 8 #include "base/message_loop/message_loop.h" 9 #include "base/time/time.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "ui/events/event_constants.h" 12 #include "ui/events/gesture_detection/gesture_event_data.h" 13 #include "ui/events/gesture_detection/gesture_provider.h" 14 #include "ui/events/gesture_detection/motion_event.h" 15 #include "ui/events/test/mock_motion_event.h" 16 #include "ui/gfx/geometry/point_f.h" 17 18 using base::TimeDelta; 19 using base::TimeTicks; 20 using ui::test::MockMotionEvent; 21 22 namespace ui { 23 namespace { 24 25 const float kFakeCoordX = 42.f; 26 const float kFakeCoordY = 24.f; 27 const TimeDelta kOneSecond = TimeDelta::FromSeconds(1); 28 const TimeDelta kOneMicrosecond = TimeDelta::FromMicroseconds(1); 29 const TimeDelta kDeltaTimeForFlingSequences = TimeDelta::FromMilliseconds(5); 30 const float kMockTouchRadius = MockMotionEvent::TOUCH_MAJOR / 2; 31 const float kMaxTwoFingerTapSeparation = 300; 32 33 GestureProvider::Config CreateDefaultConfig() { 34 GestureProvider::Config sConfig; 35 // The longpress timeout is non-zero only to indicate ordering with respect to 36 // the showpress timeout. 37 sConfig.gesture_detector_config.showpress_timeout = base::TimeDelta(); 38 sConfig.gesture_detector_config.longpress_timeout = kOneMicrosecond; 39 40 // A valid doubletap timeout should always be non-zero. The value is used not 41 // only to trigger the timeout that confirms the tap event, but also to gate 42 // whether the second tap is in fact a double-tap (using a strict inequality 43 // between times for the first up and the second down events). We use 4 44 // microseconds simply to allow several intermediate events to occur before 45 // the second tap at microsecond intervals. 46 sConfig.gesture_detector_config.double_tap_timeout = kOneMicrosecond * 4; 47 sConfig.gesture_detector_config.double_tap_min_time = kOneMicrosecond * 2; 48 49 sConfig.scale_gesture_detector_config.gesture_detector_config = 50 sConfig.gesture_detector_config; 51 return sConfig; 52 } 53 54 gfx::RectF BoundsForSingleMockTouchAtLocation(float x, float y) { 55 float diameter = MockMotionEvent::TOUCH_MAJOR; 56 return gfx::RectF(x - diameter / 2, y - diameter / 2, diameter, diameter); 57 } 58 59 } // namespace 60 61 class GestureProviderTest : public testing::Test, public GestureProviderClient { 62 public: 63 GestureProviderTest() {} 64 virtual ~GestureProviderTest() {} 65 66 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, 67 MotionEvent::Action action, 68 float x, 69 float y) { 70 return MockMotionEvent(action, event_time, x, y); 71 } 72 73 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, 74 MotionEvent::Action action, 75 float x0, 76 float y0, 77 float x1, 78 float y1) { 79 return MockMotionEvent(action, event_time, x0, y0, x1, y1); 80 } 81 82 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, 83 MotionEvent::Action action, 84 float x0, 85 float y0, 86 float x1, 87 float y1, 88 float x2, 89 float y2) { 90 return MockMotionEvent(action, event_time, x0, y0, x1, y1, x2, y2); 91 } 92 93 static MockMotionEvent ObtainMotionEvent( 94 base::TimeTicks event_time, 95 MotionEvent::Action action, 96 const std::vector<gfx::PointF>& positions) { 97 switch (positions.size()) { 98 case 1: 99 return MockMotionEvent( 100 action, event_time, positions[0].x(), positions[0].y()); 101 case 2: 102 return MockMotionEvent(action, 103 event_time, 104 positions[0].x(), 105 positions[0].y(), 106 positions[1].x(), 107 positions[1].y()); 108 case 3: 109 return MockMotionEvent(action, 110 event_time, 111 positions[0].x(), 112 positions[0].y(), 113 positions[1].x(), 114 positions[1].y(), 115 positions[2].x(), 116 positions[2].y()); 117 default: 118 CHECK(false) << "MockMotionEvent only supports 1-3 pointers"; 119 return MockMotionEvent(); 120 } 121 } 122 123 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time, 124 MotionEvent::Action action) { 125 return ObtainMotionEvent(event_time, action, kFakeCoordX, kFakeCoordY); 126 } 127 128 // Test 129 virtual void SetUp() OVERRIDE { SetUpWithConfig(GetDefaultConfig()); } 130 131 virtual void TearDown() OVERRIDE { 132 gestures_.clear(); 133 gesture_provider_.reset(); 134 } 135 136 // GestureProviderClient 137 virtual void OnGestureEvent(const GestureEventData& gesture) OVERRIDE { 138 if (gesture.type() == ET_GESTURE_SCROLL_BEGIN) 139 active_scroll_begin_event_.reset(new GestureEventData(gesture)); 140 gestures_.push_back(gesture); 141 } 142 143 void SetUpWithConfig(const GestureProvider::Config& config) { 144 gesture_provider_.reset(new GestureProvider(config, this)); 145 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 146 } 147 148 void ResetGestureDetection() { 149 CancelActiveTouchSequence(); 150 gestures_.clear(); 151 } 152 bool CancelActiveTouchSequence() { 153 if (!gesture_provider_->current_down_event()) 154 return false; 155 return gesture_provider_->OnTouchEvent( 156 *gesture_provider_->current_down_event()->Cancel()); 157 } 158 159 bool HasReceivedGesture(EventType type) const { 160 for (size_t i = 0; i < gestures_.size(); ++i) { 161 if (gestures_[i].type() == type) 162 return true; 163 } 164 return false; 165 } 166 167 const GestureEventData& GetMostRecentGestureEvent() const { 168 EXPECT_FALSE(gestures_.empty()); 169 return gestures_.back(); 170 } 171 172 EventType GetMostRecentGestureEventType() const { 173 EXPECT_FALSE(gestures_.empty()); 174 return gestures_.back().type(); 175 } 176 177 size_t GetReceivedGestureCount() const { return gestures_.size(); } 178 179 const GestureEventData& GetReceivedGesture(size_t index) const { 180 EXPECT_LT(index, GetReceivedGestureCount()); 181 return gestures_[index]; 182 } 183 184 const GestureEventData* GetActiveScrollBeginEvent() const { 185 return active_scroll_begin_event_ ? active_scroll_begin_event_.get() : NULL; 186 } 187 188 const GestureProvider::Config& GetDefaultConfig() const { 189 static GestureProvider::Config sConfig = CreateDefaultConfig(); 190 return sConfig; 191 } 192 193 float GetTouchSlop() const { 194 return GetDefaultConfig().gesture_detector_config.touch_slop; 195 } 196 197 float GetMinScalingSpan() const { 198 return GetDefaultConfig().scale_gesture_detector_config.min_scaling_span; 199 } 200 201 float GetMinSwipeVelocity() const { 202 return GetDefaultConfig().gesture_detector_config.minimum_swipe_velocity; 203 } 204 205 base::TimeDelta GetLongPressTimeout() const { 206 return GetDefaultConfig().gesture_detector_config.longpress_timeout; 207 } 208 209 base::TimeDelta GetShowPressTimeout() const { 210 return GetDefaultConfig().gesture_detector_config.showpress_timeout; 211 } 212 213 base::TimeDelta GetDoubleTapTimeout() const { 214 return GetDefaultConfig().gesture_detector_config.double_tap_timeout; 215 } 216 217 base::TimeDelta GetDoubleTapMinTime() const { 218 return GetDefaultConfig().gesture_detector_config.double_tap_min_time; 219 } 220 221 base::TimeDelta GetValidDoubleTapDelay() const { 222 return (GetDoubleTapTimeout() + GetDoubleTapMinTime()) / 2; 223 } 224 225 void EnableBeginEndTypes() { 226 GestureProvider::Config config = GetDefaultConfig(); 227 config.gesture_begin_end_types_enabled = true; 228 SetUpWithConfig(config); 229 } 230 231 void EnableSwipe() { 232 GestureProvider::Config config = GetDefaultConfig(); 233 config.gesture_detector_config.swipe_enabled = true; 234 SetUpWithConfig(config); 235 } 236 237 void EnableTwoFingerTap(float max_distance_for_two_finger_tap, 238 base::TimeDelta two_finger_tap_timeout) { 239 GestureProvider::Config config = GetDefaultConfig(); 240 config.gesture_detector_config.two_finger_tap_enabled = true; 241 config.gesture_detector_config.two_finger_tap_max_separation = 242 max_distance_for_two_finger_tap; 243 config.gesture_detector_config.two_finger_tap_timeout = 244 two_finger_tap_timeout; 245 SetUpWithConfig(config); 246 } 247 248 void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta) { 249 GestureProvider::Config config = GetDefaultConfig(); 250 config.scale_gesture_detector_config.min_pinch_update_span_delta = 251 min_pinch_update_span_delta; 252 SetUpWithConfig(config); 253 } 254 255 void SetMinGestureBoundsLength(float min_gesture_bound_length) { 256 GestureProvider::Config config = GetDefaultConfig(); 257 config.min_gesture_bounds_length = min_gesture_bound_length; 258 SetUpWithConfig(config); 259 } 260 261 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } 262 263 protected: 264 void CheckScrollEventSequenceForEndActionType( 265 MotionEvent::Action end_action_type) { 266 base::TimeTicks event_time = base::TimeTicks::Now(); 267 const float scroll_to_x = kFakeCoordX + 100; 268 const float scroll_to_y = kFakeCoordY + 100; 269 int motion_event_id = 0; 270 271 MockMotionEvent event = 272 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 273 event.SetId(++motion_event_id); 274 275 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 276 277 event = ObtainMotionEvent(event_time + kOneSecond, 278 MotionEvent::ACTION_MOVE, 279 scroll_to_x, 280 scroll_to_y); 281 event.SetId(++motion_event_id); 282 283 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 284 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 285 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 286 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 287 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 288 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y), 289 GetMostRecentGestureEvent().details.bounding_box()); 290 ASSERT_EQ(3U, GetReceivedGestureCount()) << "Only TapDown, " 291 "ScrollBegin and ScrollBy " 292 "should have been sent"; 293 294 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); 295 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id); 296 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(1).time) 297 << "ScrollBegin should have the time of the ACTION_MOVE"; 298 299 event = ObtainMotionEvent( 300 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); 301 event.SetId(++motion_event_id); 302 303 gesture_provider_->OnTouchEvent(event); 304 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 305 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 306 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 307 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 308 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 309 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y), 310 GetMostRecentGestureEvent().details.bounding_box()); 311 } 312 313 void OneFingerSwipe(float vx, float vy) { 314 std::vector<gfx::Vector2dF> velocities; 315 velocities.push_back(gfx::Vector2dF(vx, vy)); 316 MultiFingerSwipe(velocities); 317 } 318 319 void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) { 320 std::vector<gfx::Vector2dF> velocities; 321 velocities.push_back(gfx::Vector2dF(vx0, vy0)); 322 velocities.push_back(gfx::Vector2dF(vx1, vy1)); 323 MultiFingerSwipe(velocities); 324 } 325 326 void ThreeFingerSwipe(float vx0, 327 float vy0, 328 float vx1, 329 float vy1, 330 float vx2, 331 float vy2) { 332 std::vector<gfx::Vector2dF> velocities; 333 velocities.push_back(gfx::Vector2dF(vx0, vy0)); 334 velocities.push_back(gfx::Vector2dF(vx1, vy1)); 335 velocities.push_back(gfx::Vector2dF(vx2, vy2)); 336 MultiFingerSwipe(velocities); 337 } 338 339 void MultiFingerSwipe(std::vector<gfx::Vector2dF> velocities) { 340 ASSERT_GT(velocities.size(), 0U); 341 342 base::TimeTicks event_time = base::TimeTicks::Now(); 343 344 std::vector<gfx::PointF> positions(velocities.size()); 345 for (size_t i = 0; i < positions.size(); ++i) 346 positions[i] = gfx::PointF(kFakeCoordX * (i + 1), kFakeCoordY * (i + 1)); 347 348 float dt = kDeltaTimeForFlingSequences.InSecondsF(); 349 350 // Each pointer down should be a separate event. 351 for (size_t i = 0; i < positions.size(); ++i) { 352 const size_t pointer_count = i + 1; 353 std::vector<gfx::PointF> event_positions(pointer_count); 354 event_positions.assign(positions.begin(), 355 positions.begin() + pointer_count); 356 MockMotionEvent event = 357 ObtainMotionEvent(event_time, 358 pointer_count > 1 ? MotionEvent::ACTION_POINTER_DOWN 359 : MotionEvent::ACTION_DOWN, 360 event_positions); 361 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 362 } 363 364 for (size_t i = 0; i < positions.size(); ++i) 365 positions[i] += gfx::ScaleVector2d(velocities[i], dt); 366 MockMotionEvent event = 367 ObtainMotionEvent(event_time + kDeltaTimeForFlingSequences, 368 MotionEvent::ACTION_MOVE, 369 positions); 370 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 371 372 for (size_t i = 0; i < positions.size(); ++i) 373 positions[i] += gfx::ScaleVector2d(velocities[i], dt); 374 event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences, 375 MotionEvent::ACTION_MOVE, 376 positions); 377 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 378 379 event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences, 380 MotionEvent::ACTION_POINTER_UP, 381 positions); 382 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 383 } 384 385 static void RunTasksAndWait(base::TimeDelta delay) { 386 base::MessageLoop::current()->PostDelayedTask( 387 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 388 base::MessageLoop::current()->Run(); 389 } 390 391 std::vector<GestureEventData> gestures_; 392 scoped_ptr<GestureProvider> gesture_provider_; 393 scoped_ptr<GestureEventData> active_scroll_begin_event_; 394 base::MessageLoopForUI message_loop_; 395 }; 396 397 // Verify that a DOWN followed shortly by an UP will trigger a single tap. 398 TEST_F(GestureProviderTest, GestureTap) { 399 base::TimeTicks event_time = base::TimeTicks::Now(); 400 int motion_event_id = 0; 401 402 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 403 404 MockMotionEvent event = 405 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 406 event.SetId(++motion_event_id); 407 408 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 409 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 410 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 411 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 412 GetMostRecentGestureEvent().details.bounding_box()); 413 414 event = ObtainMotionEvent(event_time + kOneMicrosecond, 415 MotionEvent::ACTION_UP); 416 event.SetId(++motion_event_id); 417 418 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 419 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 420 // Ensure tap details have been set. 421 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 422 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 423 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 424 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 425 GetMostRecentGestureEvent().details.bounding_box()); 426 } 427 428 // Verify that a DOWN followed shortly by an UP will trigger 429 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled. 430 TEST_F(GestureProviderTest, GestureTapWithDelay) { 431 base::TimeTicks event_time = base::TimeTicks::Now(); 432 int motion_event_id = 0; 433 434 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 435 436 MockMotionEvent event = 437 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 438 event.SetId(++motion_event_id); 439 440 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 441 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 442 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 443 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 444 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 445 GetMostRecentGestureEvent().details.bounding_box()); 446 447 event = ObtainMotionEvent(event_time + kOneMicrosecond, 448 MotionEvent::ACTION_UP); 449 event.SetId(++motion_event_id); 450 451 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 452 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 453 // Ensure tap details have been set. 454 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 455 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 456 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 457 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 458 GetMostRecentGestureEvent().details.bounding_box()); 459 460 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP)); 461 RunTasksAndWait(GetDoubleTapTimeout()); 462 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP)); 463 } 464 465 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). 466 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) { 467 base::TimeTicks event_time = TimeTicks::Now(); 468 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; 469 int motion_event_id = 0; 470 471 MockMotionEvent event = 472 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 473 event.SetId(++motion_event_id); 474 475 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 476 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 477 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 478 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 479 480 event = ObtainMotionEvent(event_time + delta_time, 481 MotionEvent::ACTION_MOVE, 482 kFakeCoordX * 10, 483 kFakeCoordY * 10); 484 event.SetId(++motion_event_id); 485 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 486 487 event = ObtainMotionEvent(event_time + delta_time * 2, 488 MotionEvent::ACTION_UP, 489 kFakeCoordX * 10, 490 kFakeCoordY * 10); 491 event.SetId(++motion_event_id); 492 493 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 494 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 495 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 496 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 497 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 498 EXPECT_EQ( 499 BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 10), 500 GetMostRecentGestureEvent().details.bounding_box()); 501 } 502 503 // Verify that for a normal scroll the following events are sent: 504 // - ET_GESTURE_SCROLL_BEGIN 505 // - ET_GESTURE_SCROLL_UPDATE 506 // - ET_GESTURE_SCROLL_END 507 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { 508 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP); 509 } 510 511 // Verify that for a cancelled scroll the following events are sent: 512 // - ET_GESTURE_SCROLL_BEGIN 513 // - ET_GESTURE_SCROLL_UPDATE 514 // - ET_GESTURE_SCROLL_END 515 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) { 516 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL); 517 } 518 519 // Verify that for a normal fling (fling after scroll) the following events are 520 // sent: 521 // - ET_GESTURE_SCROLL_BEGIN 522 // - ET_SCROLL_FLING_START 523 TEST_F(GestureProviderTest, FlingEventSequence) { 524 base::TimeTicks event_time = base::TimeTicks::Now(); 525 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; 526 int motion_event_id = 0; 527 528 MockMotionEvent event = 529 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 530 event.SetId(++motion_event_id); 531 532 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 533 534 event = ObtainMotionEvent(event_time + delta_time, 535 MotionEvent::ACTION_MOVE, 536 kFakeCoordX * 5, 537 kFakeCoordY * 5); 538 event.SetId(++motion_event_id); 539 540 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 541 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 542 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 543 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 544 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 545 ASSERT_EQ(3U, GetReceivedGestureCount()); 546 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); 547 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id); 548 549 // We don't want to take a dependency here on exactly how hints are calculated 550 // for a fling (eg. may depend on velocity), so just validate the direction. 551 int hint_x = GetReceivedGesture(1).details.scroll_x_hint(); 552 int hint_y = GetReceivedGesture(1).details.scroll_y_hint(); 553 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) 554 << "ScrollBegin hint should be in positive X axis"; 555 556 event = ObtainMotionEvent(event_time + delta_time * 2, 557 MotionEvent::ACTION_UP, 558 kFakeCoordX * 10, 559 kFakeCoordY * 10); 560 event.SetId(++motion_event_id); 561 562 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 563 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 564 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 565 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 566 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 567 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 568 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) 569 << "FlingStart should have the time of the ACTION_UP"; 570 } 571 572 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) { 573 const base::TimeTicks event_time = TimeTicks::Now(); 574 575 MockMotionEvent event = 576 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 577 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 578 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 579 580 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + 581 kOneMicrosecond); 582 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); 583 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 584 585 // The long press triggers window focus loss by opening a context menu. 586 EXPECT_TRUE(CancelActiveTouchSequence()); 587 EXPECT_FALSE(HasDownEvent()); 588 589 // A final ACTION_UP should have no effect. 590 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 591 MotionEvent::ACTION_UP); 592 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 593 } 594 595 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) { 596 base::TimeTicks event_time = base::TimeTicks::Now(); 597 598 MockMotionEvent event = 599 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 600 601 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 602 603 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 604 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 605 event = ObtainMotionEvent(event_time + kOneMicrosecond, 606 MotionEvent::ACTION_MOVE, 607 kFakeCoordX + 50, 608 kFakeCoordY + 50); 609 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 610 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 611 612 event = ObtainMotionEvent(event_time + kOneSecond, 613 MotionEvent::ACTION_UP, 614 kFakeCoordX + 50, 615 kFakeCoordY + 50); 616 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 617 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 618 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 619 } 620 621 TEST_F(GestureProviderTest, DoubleTap) { 622 base::TimeTicks event_time = base::TimeTicks::Now(); 623 624 MockMotionEvent event = 625 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 626 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 627 628 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 629 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 630 631 event = ObtainMotionEvent(event_time + kOneMicrosecond, 632 MotionEvent::ACTION_UP, 633 kFakeCoordX, 634 kFakeCoordY); 635 gesture_provider_->OnTouchEvent(event); 636 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 637 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 638 639 event_time += GetValidDoubleTapDelay(); 640 event = ObtainMotionEvent(event_time, 641 MotionEvent::ACTION_DOWN, 642 kFakeCoordX, 643 kFakeCoordY); 644 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 645 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 646 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 647 648 // Moving a very small amount of distance should not trigger the double tap 649 // drag zoom mode. 650 event = ObtainMotionEvent(event_time + kOneMicrosecond, 651 MotionEvent::ACTION_MOVE, 652 kFakeCoordX, 653 kFakeCoordY + 1); 654 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 655 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 656 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 657 658 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 659 MotionEvent::ACTION_UP, 660 kFakeCoordX, 661 kFakeCoordY + 1); 662 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 663 664 const GestureEventData& double_tap = GetMostRecentGestureEvent(); 665 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type()); 666 // Ensure tap details have been set. 667 EXPECT_EQ(10, double_tap.details.bounding_box().width()); 668 EXPECT_EQ(10, double_tap.details.bounding_box().height()); 669 EXPECT_EQ(1, double_tap.details.tap_count()); 670 } 671 672 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { 673 const base::TimeTicks down_time_1 = TimeTicks::Now(); 674 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay(); 675 676 MockMotionEvent event = 677 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 678 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 679 680 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, 681 MotionEvent::ACTION_UP, 682 kFakeCoordX, 683 kFakeCoordY); 684 gesture_provider_->OnTouchEvent(event); 685 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 686 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 687 688 event = ObtainMotionEvent( 689 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 690 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 691 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 692 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 693 694 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 695 MotionEvent::ACTION_MOVE, 696 kFakeCoordX, 697 kFakeCoordY + 100); 698 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 699 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 700 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 701 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100), 702 GetMostRecentGestureEvent().details.bounding_box()); 703 704 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 705 MotionEvent::ACTION_MOVE, 706 kFakeCoordX, 707 kFakeCoordY + 200); 708 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 709 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); 710 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); 711 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 200), 712 GetMostRecentGestureEvent().details.bounding_box()); 713 714 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 715 MotionEvent::ACTION_MOVE, 716 kFakeCoordX, 717 kFakeCoordY + 100); 718 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 719 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); 720 EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale()); 721 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100), 722 GetMostRecentGestureEvent().details.bounding_box()); 723 724 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 4, 725 MotionEvent::ACTION_UP, 726 kFakeCoordX, 727 kFakeCoordY - 200); 728 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 729 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 730 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 731 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200), 732 GetMostRecentGestureEvent().details.bounding_box()); 733 } 734 735 // Generate a scroll gesture and verify that the resulting scroll motion event 736 // has both absolute and relative position information. 737 TEST_F(GestureProviderTest, ScrollUpdateValues) { 738 const float delta_x = 16; 739 const float delta_y = 84; 740 const float raw_offset_x = 17.3f; 741 const float raw_offset_y = 13.7f; 742 743 const base::TimeTicks event_time = TimeTicks::Now(); 744 745 MockMotionEvent event = 746 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 747 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 748 749 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can 750 // compare the relative and absolute coordinates. 751 event = ObtainMotionEvent(event_time + kOneMicrosecond, 752 MotionEvent::ACTION_MOVE, 753 kFakeCoordX - delta_x / 2, 754 kFakeCoordY - delta_y / 2); 755 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 756 757 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 758 MotionEvent::ACTION_MOVE, 759 kFakeCoordX - delta_x, 760 kFakeCoordY - delta_y); 761 event.SetRawOffset(raw_offset_x, raw_offset_y); 762 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 763 764 // Make sure the reported gesture event has all the expected details. 765 ASSERT_LT(0U, GetReceivedGestureCount()); 766 GestureEventData gesture = GetMostRecentGestureEvent(); 767 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type()); 768 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); 769 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); 770 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); 771 EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x); 772 EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y); 773 EXPECT_EQ(1, gesture.details.touch_points()); 774 775 // No horizontal delta because of snapping. 776 EXPECT_EQ(0, gesture.details.scroll_x()); 777 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); 778 } 779 780 // Verify that fractional scroll deltas are rounded as expected and that 781 // fractional scrolling doesn't break scroll snapping. 782 TEST_F(GestureProviderTest, FractionalScroll) { 783 const float delta_x = 0.4f; 784 const float delta_y = 5.2f; 785 786 const base::TimeTicks event_time = TimeTicks::Now(); 787 788 MockMotionEvent event = 789 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 790 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 791 792 // Skip past the touch slop and move back. 793 event = ObtainMotionEvent(event_time, 794 MotionEvent::ACTION_MOVE, 795 kFakeCoordX, 796 kFakeCoordY + 100); 797 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 798 event = ObtainMotionEvent(event_time, 799 MotionEvent::ACTION_MOVE); 800 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 801 802 // Now move up slowly, mostly vertically but with a (fractional) bit of 803 // horizontal motion. 804 for(int i = 1; i <= 10; i++) { 805 event = ObtainMotionEvent(event_time + kOneMicrosecond * i, 806 MotionEvent::ACTION_MOVE, 807 kFakeCoordX + delta_x * i, 808 kFakeCoordY + delta_y * i); 809 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 810 811 ASSERT_LT(0U, GetReceivedGestureCount()); 812 GestureEventData gesture = GetMostRecentGestureEvent(); 813 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type()); 814 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time); 815 EXPECT_EQ(1, gesture.details.touch_points()); 816 817 // Verify that the event co-ordinates are still the precise values we 818 // supplied. 819 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); 820 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y); 821 822 // Verify that we're scrolling vertically by the expected amount 823 // (modulo rounding). 824 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y); 825 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1); 826 827 // And that there has been no horizontal motion at all. 828 EXPECT_EQ(0, gesture.details.scroll_x()); 829 } 830 } 831 832 // Generate a scroll gesture and verify that the resulting scroll begin event 833 // has the expected hint values. 834 TEST_F(GestureProviderTest, ScrollBeginValues) { 835 const float delta_x = 13; 836 const float delta_y = 89; 837 838 const base::TimeTicks event_time = TimeTicks::Now(); 839 840 MockMotionEvent event = 841 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 842 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 843 844 // Move twice such that the first event isn't sufficient to start 845 // scrolling on it's own. 846 event = ObtainMotionEvent(event_time + kOneMicrosecond, 847 MotionEvent::ACTION_MOVE, 848 kFakeCoordX + 2, 849 kFakeCoordY + 1); 850 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 851 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 852 853 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 854 MotionEvent::ACTION_MOVE, 855 kFakeCoordX + delta_x, 856 kFakeCoordY + delta_y); 857 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 858 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 859 860 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); 861 ASSERT_TRUE(!!scroll_begin_gesture); 862 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint()); 863 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint()); 864 } 865 866 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) { 867 base::TimeTicks event_time = base::TimeTicks::Now(); 868 869 MockMotionEvent event = 870 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 871 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 872 event = ObtainMotionEvent(event_time + kOneMicrosecond, 873 MotionEvent::ACTION_MOVE, 874 kFakeCoordX * 5, 875 kFakeCoordY * 5); 876 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 877 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 878 MotionEvent::ACTION_MOVE, 879 kFakeCoordX * 10, 880 kFakeCoordY * 10); 881 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 882 883 const base::TimeDelta long_press_timeout = 884 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 885 RunTasksAndWait(long_press_timeout); 886 887 // No LONG_TAP as the LONG_PRESS timer is cancelled. 888 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 889 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 890 } 891 892 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP. 893 TEST_F(GestureProviderTest, GestureLongTap) { 894 base::TimeTicks event_time = base::TimeTicks::Now(); 895 896 MockMotionEvent event = 897 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 898 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 899 900 const base::TimeDelta long_press_timeout = 901 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 902 RunTasksAndWait(long_press_timeout); 903 904 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 905 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 906 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 907 GetMostRecentGestureEvent().details.bounding_box()); 908 909 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP); 910 gesture_provider_->OnTouchEvent(event); 911 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType()); 912 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 913 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 914 GetMostRecentGestureEvent().details.bounding_box()); 915 } 916 917 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) { 918 base::TimeTicks event_time = base::TimeTicks::Now(); 919 920 MockMotionEvent event = 921 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 922 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 923 924 const base::TimeDelta long_press_timeout = 925 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 926 RunTasksAndWait(long_press_timeout); 927 928 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 929 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 930 event = ObtainMotionEvent(event_time + long_press_timeout, 931 MotionEvent::ACTION_MOVE, 932 kFakeCoordX + 100, 933 kFakeCoordY + 100); 934 gesture_provider_->OnTouchEvent(event); 935 936 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 937 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 938 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 939 940 event = ObtainMotionEvent(event_time + long_press_timeout, 941 MotionEvent::ACTION_UP); 942 gesture_provider_->OnTouchEvent(event); 943 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 944 } 945 946 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { 947 base::TimeTicks event_time = base::TimeTicks::Now(); 948 int motion_event_id = 0; 949 950 MockMotionEvent event = ObtainMotionEvent( 951 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 952 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 953 954 event = ObtainMotionEvent(event_time + kOneMicrosecond, 955 MotionEvent::ACTION_UP, 956 kFakeCoordX, 957 kFakeCoordY); 958 gesture_provider_->OnTouchEvent(event); 959 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 960 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 961 962 event_time += GetValidDoubleTapDelay(); 963 event = ObtainMotionEvent(event_time, 964 MotionEvent::ACTION_DOWN, 965 kFakeCoordX, 966 kFakeCoordY); 967 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 968 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 969 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 970 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); 971 972 const base::TimeDelta long_press_timeout = 973 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 974 RunTasksAndWait(long_press_timeout); 975 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 976 977 event = ObtainMotionEvent(event_time + long_press_timeout, 978 MotionEvent::ACTION_MOVE, 979 kFakeCoordX + 20, 980 kFakeCoordY + 20); 981 event.SetId(++motion_event_id); 982 983 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 984 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 985 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 986 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 987 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); 988 989 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond, 990 MotionEvent::ACTION_UP, 991 kFakeCoordX, 992 kFakeCoordY + 1); 993 event.SetId(++motion_event_id); 994 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 995 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 996 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 997 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 998 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress()); 999 } 1000 1001 // Verify that the touch slop region is removed from the first scroll delta to 1002 // avoid a jump when starting to scroll. 1003 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { 1004 const float touch_slop = GetTouchSlop(); 1005 const float scroll_delta = 5; 1006 1007 base::TimeTicks event_time = base::TimeTicks::Now(); 1008 1009 MockMotionEvent event = 1010 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1011 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1012 1013 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1014 MotionEvent::ACTION_MOVE, 1015 kFakeCoordX, 1016 kFakeCoordY + touch_slop + scroll_delta); 1017 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1018 1019 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 1020 GestureEventData gesture = GetMostRecentGestureEvent(); 1021 EXPECT_EQ(0, gesture.details.scroll_x()); 1022 EXPECT_EQ(scroll_delta, gesture.details.scroll_y()); 1023 EXPECT_EQ(1, gesture.details.touch_points()); 1024 } 1025 1026 // Verify that movement within the touch slop region does not generate a scroll, 1027 // and that the slop region is correct even when using fractional coordinates. 1028 TEST_F(GestureProviderTest, NoScrollWithinTouchSlop) { 1029 const float touch_slop = GetTouchSlop(); 1030 const float scale_factor = 2.5f; 1031 const int touch_slop_pixels = static_cast<int>(scale_factor * touch_slop); 1032 1033 base::TimeTicks event_time = base::TimeTicks::Now(); 1034 1035 MockMotionEvent event = 1036 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1037 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1038 1039 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1040 MotionEvent::ACTION_MOVE, 1041 kFakeCoordX + touch_slop_pixels / scale_factor, 1042 kFakeCoordY); 1043 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1044 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1045 1046 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1047 MotionEvent::ACTION_MOVE, 1048 kFakeCoordX, 1049 kFakeCoordY + touch_slop_pixels / scale_factor); 1050 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1051 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1052 1053 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1054 MotionEvent::ACTION_MOVE, 1055 kFakeCoordX - touch_slop_pixels / scale_factor, 1056 kFakeCoordY); 1057 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1058 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1059 1060 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1061 MotionEvent::ACTION_MOVE, 1062 kFakeCoordX, 1063 kFakeCoordY - touch_slop_pixels / scale_factor); 1064 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1065 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1066 1067 event = 1068 ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1069 MotionEvent::ACTION_MOVE, 1070 kFakeCoordX, 1071 kFakeCoordY + (touch_slop_pixels + 1.f) / scale_factor); 1072 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1073 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1074 } 1075 1076 TEST_F(GestureProviderTest, NoDoubleTapWhenTooRapid) { 1077 base::TimeTicks event_time = base::TimeTicks::Now(); 1078 1079 MockMotionEvent event = 1080 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1081 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1082 1083 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1084 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1085 1086 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1087 MotionEvent::ACTION_UP, 1088 kFakeCoordX, 1089 kFakeCoordY); 1090 gesture_provider_->OnTouchEvent(event); 1091 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1092 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1093 1094 // If the second tap follows the first in too short a time span, no double-tap 1095 // will occur. 1096 event_time += (GetDoubleTapMinTime() / 2); 1097 event = ObtainMotionEvent(event_time, 1098 MotionEvent::ACTION_DOWN, 1099 kFakeCoordX, 1100 kFakeCoordY); 1101 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1102 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1103 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1104 1105 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1106 MotionEvent::ACTION_UP, 1107 kFakeCoordX, 1108 kFakeCoordY); 1109 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1110 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1111 } 1112 1113 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) { 1114 // Ensure that double-tap gestures can be disabled. 1115 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1116 1117 base::TimeTicks event_time = base::TimeTicks::Now(); 1118 MockMotionEvent event = ObtainMotionEvent( 1119 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1120 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1121 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1122 1123 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1124 MotionEvent::ACTION_UP, 1125 kFakeCoordX, 1126 kFakeCoordY); 1127 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1128 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 1129 1130 event_time += GetValidDoubleTapDelay(); 1131 event = ObtainMotionEvent(event_time, 1132 MotionEvent::ACTION_DOWN, 1133 kFakeCoordX, 1134 kFakeCoordY); 1135 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1136 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1137 1138 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1139 MotionEvent::ACTION_UP, 1140 kFakeCoordX, 1141 kFakeCoordY); 1142 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1143 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 1144 1145 // Ensure that double-tap gestures can be interrupted. 1146 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1147 1148 event_time = base::TimeTicks::Now(); 1149 event = ObtainMotionEvent( 1150 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1151 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1152 EXPECT_EQ(5U, GetReceivedGestureCount()); 1153 1154 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1155 MotionEvent::ACTION_UP, 1156 kFakeCoordX, 1157 kFakeCoordY); 1158 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1159 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1160 1161 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1162 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 1163 1164 // Ensure that double-tap gestures can be resumed. 1165 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1166 1167 event_time += GetValidDoubleTapDelay(); 1168 event = ObtainMotionEvent(event_time, 1169 MotionEvent::ACTION_DOWN, 1170 kFakeCoordX, 1171 kFakeCoordY); 1172 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1173 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1174 1175 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1176 MotionEvent::ACTION_UP, 1177 kFakeCoordX, 1178 kFakeCoordY); 1179 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1180 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1181 1182 event_time += GetValidDoubleTapDelay(); 1183 event = ObtainMotionEvent(event_time, 1184 MotionEvent::ACTION_DOWN, 1185 kFakeCoordX, 1186 kFakeCoordY); 1187 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1188 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1189 1190 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1191 MotionEvent::ACTION_UP, 1192 kFakeCoordX, 1193 kFakeCoordY); 1194 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1195 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType()); 1196 } 1197 1198 TEST_F(GestureProviderTest, NoDelayedTapWhenDoubleTapSupportToggled) { 1199 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1200 1201 base::TimeTicks event_time = base::TimeTicks::Now(); 1202 MockMotionEvent event = ObtainMotionEvent( 1203 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1204 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1205 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1206 EXPECT_EQ(1U, GetReceivedGestureCount()); 1207 1208 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1209 MotionEvent::ACTION_UP, 1210 kFakeCoordX, 1211 kFakeCoordY); 1212 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1213 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1214 EXPECT_EQ(2U, GetReceivedGestureCount()); 1215 1216 // Disabling double-tap during the tap timeout should flush the delayed tap. 1217 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1218 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 1219 EXPECT_EQ(3U, GetReceivedGestureCount()); 1220 1221 // No further timeout gestures should arrive. 1222 const base::TimeDelta long_press_timeout = 1223 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 1224 RunTasksAndWait(long_press_timeout); 1225 EXPECT_EQ(3U, GetReceivedGestureCount()); 1226 } 1227 1228 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) { 1229 const base::TimeTicks down_time_1 = TimeTicks::Now(); 1230 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay(); 1231 1232 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1233 1234 MockMotionEvent event = 1235 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1236 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1237 1238 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, 1239 MotionEvent::ACTION_UP, 1240 kFakeCoordX, 1241 kFakeCoordY); 1242 gesture_provider_->OnTouchEvent(event); 1243 1244 event = ObtainMotionEvent( 1245 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1246 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1247 1248 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 1249 MotionEvent::ACTION_MOVE, 1250 kFakeCoordX, 1251 kFakeCoordY + 100); 1252 1253 // The move should become a scroll, as doubletap drag zoom is disabled. 1254 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1255 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1256 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1257 1258 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 1259 MotionEvent::ACTION_MOVE, 1260 kFakeCoordX, 1261 kFakeCoordY + 200); 1262 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1263 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 1264 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1265 EXPECT_EQ(down_time_2 + kOneMicrosecond * 2, 1266 GetMostRecentGestureEvent().time); 1267 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 1268 1269 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 1270 MotionEvent::ACTION_UP, 1271 kFakeCoordX, 1272 kFakeCoordY + 200); 1273 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1274 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 1275 } 1276 1277 // Verify that double tap drag zoom feature is not invoked when the gesture 1278 // handler is told to disable double tap gesture detection. 1279 // The second tap sequence should be treated just as the first would be. 1280 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) { 1281 const base::TimeTicks down_time_1 = TimeTicks::Now(); 1282 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay(); 1283 1284 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1285 1286 MockMotionEvent event = 1287 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1288 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1289 1290 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, 1291 MotionEvent::ACTION_UP, 1292 kFakeCoordX, 1293 kFakeCoordY); 1294 gesture_provider_->OnTouchEvent(event); 1295 1296 event = ObtainMotionEvent( 1297 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1298 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1299 1300 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 1301 MotionEvent::ACTION_MOVE, 1302 kFakeCoordX, 1303 kFakeCoordY + 100); 1304 1305 // The move should become a scroll, as double tap drag zoom is disabled. 1306 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1307 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1308 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1309 1310 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 1311 MotionEvent::ACTION_MOVE, 1312 kFakeCoordX, 1313 kFakeCoordY + 200); 1314 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1315 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 1316 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1317 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 1318 1319 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 1320 MotionEvent::ACTION_UP, 1321 kFakeCoordX, 1322 kFakeCoordY + 200); 1323 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1324 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 1325 } 1326 1327 // Verify that updating double tap support during a double tap drag zoom 1328 // disables double tap detection after the gesture has ended. 1329 TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) { 1330 base::TimeTicks down_time_1 = TimeTicks::Now(); 1331 base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay(); 1332 1333 gesture_provider_->SetDoubleTapSupportForPageEnabled(true); 1334 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1335 1336 // Start a double-tap drag gesture. 1337 MockMotionEvent event = 1338 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1339 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1340 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, 1341 MotionEvent::ACTION_UP, 1342 kFakeCoordX, 1343 kFakeCoordY); 1344 gesture_provider_->OnTouchEvent(event); 1345 event = ObtainMotionEvent( 1346 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1347 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1348 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 1349 MotionEvent::ACTION_MOVE, 1350 kFakeCoordX, 1351 kFakeCoordY + 100); 1352 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1353 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1354 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 1355 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1356 1357 // Simulate setting a fixed page scale (or a mobile viewport); 1358 // this should not disrupt the current double-tap gesture. 1359 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1360 1361 // Double tap zoom updates should continue. 1362 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 1363 MotionEvent::ACTION_MOVE, 1364 kFakeCoordX, 1365 kFakeCoordY + 200); 1366 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1367 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); 1368 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1369 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); 1370 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 1371 MotionEvent::ACTION_UP, 1372 kFakeCoordX, 1373 kFakeCoordY + 200); 1374 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1375 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 1376 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1377 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1378 1379 // The double-tap gesture has finished, but the page scale is fixed. 1380 // The same event sequence should not generate any double tap getsures. 1381 gestures_.clear(); 1382 down_time_1 += kOneMicrosecond * 40; 1383 down_time_2 += kOneMicrosecond * 40; 1384 1385 // Start a double-tap drag gesture. 1386 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1387 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1388 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, 1389 MotionEvent::ACTION_UP, 1390 kFakeCoordX, 1391 kFakeCoordY); 1392 gesture_provider_->OnTouchEvent(event); 1393 event = ObtainMotionEvent( 1394 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 1395 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1396 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 1397 MotionEvent::ACTION_MOVE, 1398 kFakeCoordX, 1399 kFakeCoordY + 100); 1400 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1401 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1402 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1403 1404 // Double tap zoom updates should not be sent. 1405 // Instead, the second tap drag becomes a scroll gesture sequence. 1406 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 1407 MotionEvent::ACTION_MOVE, 1408 kFakeCoordX, 1409 kFakeCoordY + 200); 1410 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1411 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1412 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 1413 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 1414 MotionEvent::ACTION_UP, 1415 kFakeCoordX, 1416 kFakeCoordY + 200); 1417 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1418 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 1419 } 1420 1421 // Verify that pinch zoom sends the proper event sequence. 1422 TEST_F(GestureProviderTest, PinchZoom) { 1423 base::TimeTicks event_time = base::TimeTicks::Now(); 1424 const float touch_slop = GetTouchSlop(); 1425 const float raw_offset_x = 3.2f; 1426 const float raw_offset_y = 4.3f; 1427 int motion_event_id = 0; 1428 1429 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1430 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1431 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); 1432 1433 int secondary_coord_x = kFakeCoordX + 20 * touch_slop; 1434 int secondary_coord_y = kFakeCoordY + 20 * touch_slop; 1435 1436 MockMotionEvent event = 1437 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1438 event.SetId(++motion_event_id); 1439 event.SetRawOffset(raw_offset_x, raw_offset_y); 1440 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1441 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1442 EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x); 1443 EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y); 1444 EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1445 EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1446 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1447 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 1448 GetMostRecentGestureEvent().details.bounding_box()); 1449 1450 // Toggling double-tap support should not take effect until the next sequence. 1451 gesture_provider_->SetDoubleTapSupportForPageEnabled(true); 1452 1453 event = ObtainMotionEvent(event_time, 1454 MotionEvent::ACTION_POINTER_DOWN, 1455 kFakeCoordX, 1456 kFakeCoordY, 1457 secondary_coord_x, 1458 secondary_coord_y); 1459 event.SetId(++motion_event_id); 1460 event.SetRawOffset(raw_offset_x, raw_offset_y); 1461 1462 gesture_provider_->OnTouchEvent(event); 1463 EXPECT_EQ(1U, GetReceivedGestureCount()); 1464 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1465 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 1466 GetMostRecentGestureEvent().details.bounding_box()); 1467 1468 secondary_coord_x += 5 * touch_slop; 1469 secondary_coord_y += 5 * touch_slop; 1470 event = ObtainMotionEvent(event_time, 1471 MotionEvent::ACTION_MOVE, 1472 kFakeCoordX, 1473 kFakeCoordY, 1474 secondary_coord_x, 1475 secondary_coord_y); 1476 event.SetId(++motion_event_id); 1477 event.SetRawOffset(raw_offset_x, raw_offset_y); 1478 1479 // Toggling double-tap support should not take effect until the next sequence. 1480 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1481 1482 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1483 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1484 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1485 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1486 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1487 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1488 1489 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x); 1490 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y); 1491 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x, 1492 GetReceivedGesture(3).raw_x); 1493 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y, 1494 GetReceivedGesture(3).raw_y); 1495 1496 EXPECT_EQ( 1497 gfx::RectF(kFakeCoordX - kMockTouchRadius, 1498 kFakeCoordY - kMockTouchRadius, 1499 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2, 1500 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2), 1501 GetMostRecentGestureEvent().details.bounding_box()); 1502 1503 secondary_coord_x += 2 * touch_slop; 1504 secondary_coord_y += 2 * touch_slop; 1505 event = ObtainMotionEvent(event_time, 1506 MotionEvent::ACTION_MOVE, 1507 kFakeCoordX, 1508 kFakeCoordY, 1509 secondary_coord_x, 1510 secondary_coord_y); 1511 event.SetId(++motion_event_id); 1512 1513 // Toggling double-tap support should not take effect until the next sequence. 1514 gesture_provider_->SetDoubleTapSupportForPageEnabled(true); 1515 1516 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1517 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1518 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1519 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); 1520 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1521 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); 1522 EXPECT_EQ( 1523 gfx::RectF(kFakeCoordX - kMockTouchRadius, 1524 kFakeCoordY - kMockTouchRadius, 1525 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2, 1526 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2), 1527 GetMostRecentGestureEvent().details.bounding_box()); 1528 1529 event = ObtainMotionEvent(event_time, 1530 MotionEvent::ACTION_POINTER_UP, 1531 kFakeCoordX, 1532 kFakeCoordY, 1533 secondary_coord_x, 1534 secondary_coord_y); 1535 event.SetId(++motion_event_id); 1536 1537 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1538 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1539 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType()); 1540 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1541 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 1542 EXPECT_EQ( 1543 gfx::RectF(kFakeCoordX - kMockTouchRadius, 1544 kFakeCoordY - kMockTouchRadius, 1545 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2, 1546 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2), 1547 GetMostRecentGestureEvent().details.bounding_box()); 1548 1549 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); 1550 gesture_provider_->OnTouchEvent(event); 1551 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1552 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1553 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius, 1554 kFakeCoordY - kMockTouchRadius, 1555 kMockTouchRadius * 2, 1556 kMockTouchRadius * 2), 1557 GetMostRecentGestureEvent().details.bounding_box()); 1558 } 1559 1560 // Verify that no accidental pinching occurs if the touch size is large relative 1561 // to the min scaling span. 1562 TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) { 1563 base::TimeTicks event_time = base::TimeTicks::Now(); 1564 const float kFatFingerSize = GetMinScalingSpan() * 3.f; 1565 1566 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1567 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); 1568 1569 MockMotionEvent event = 1570 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1571 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1572 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1573 EXPECT_EQ(1U, GetReceivedGestureCount()); 1574 1575 event = ObtainMotionEvent(event_time + kOneSecond, 1576 MotionEvent::ACTION_MOVE); 1577 event.SetTouchMajor(0.1f); 1578 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1579 EXPECT_EQ(1U, GetReceivedGestureCount()); 1580 1581 event = ObtainMotionEvent(event_time + kOneSecond * 2, 1582 MotionEvent::ACTION_MOVE, 1583 kFakeCoordX + 1.f, 1584 kFakeCoordY); 1585 event.SetTouchMajor(1.f); 1586 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1587 EXPECT_EQ(1U, GetReceivedGestureCount()); 1588 1589 event = ObtainMotionEvent(event_time + kOneSecond * 3, 1590 MotionEvent::ACTION_MOVE); 1591 event.SetTouchMajor(kFatFingerSize * 3.5f); 1592 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1593 EXPECT_EQ(1U, GetReceivedGestureCount()); 1594 1595 event = ObtainMotionEvent(event_time + kOneSecond * 4, 1596 MotionEvent::ACTION_MOVE); 1597 event.SetTouchMajor(kFatFingerSize * 5.f); 1598 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1599 EXPECT_EQ(1U, GetReceivedGestureCount()); 1600 } 1601 1602 // Verify that multi-finger swipe sends the proper event sequence. 1603 TEST_F(GestureProviderTest, MultiFingerSwipe) { 1604 EnableSwipe(); 1605 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 1606 const float min_swipe_velocity = GetMinSwipeVelocity(); 1607 1608 // One finger - swipe right 1609 OneFingerSwipe(2 * min_swipe_velocity, 0); 1610 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1611 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1612 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1613 ResetGestureDetection(); 1614 1615 // One finger - swipe left 1616 OneFingerSwipe(-2 * min_swipe_velocity, 0); 1617 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1618 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left()); 1619 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1620 ResetGestureDetection(); 1621 1622 // One finger - swipe down 1623 OneFingerSwipe(0, 2 * min_swipe_velocity); 1624 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1625 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1626 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1627 ResetGestureDetection(); 1628 1629 // One finger - swipe up 1630 OneFingerSwipe(0, -2 * min_swipe_velocity); 1631 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1632 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up()); 1633 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1634 ResetGestureDetection(); 1635 1636 // Two fingers 1637 // Swipe right. 1638 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0); 1639 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1640 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1641 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1642 ResetGestureDetection(); 1643 1644 // Swipe left. 1645 TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0); 1646 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1647 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left()); 1648 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1649 ResetGestureDetection(); 1650 1651 // No swipe with different touch directions. 1652 TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0); 1653 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1654 ResetGestureDetection(); 1655 1656 // No swipe without a dominant direction. 1657 TwoFingerSwipe(min_swipe_velocity * 2, 1658 min_swipe_velocity * 2, 1659 min_swipe_velocity * 2, 1660 min_swipe_velocity * 2); 1661 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1662 ResetGestureDetection(); 1663 1664 // Swipe down with non-zero velocities on both axes and dominant direction. 1665 TwoFingerSwipe(-min_swipe_velocity, 1666 min_swipe_velocity * 4, 1667 -min_swipe_velocity, 1668 min_swipe_velocity * 4); 1669 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1670 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1671 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left()); 1672 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1673 ResetGestureDetection(); 1674 1675 // Swipe up with non-zero velocities on both axes. 1676 TwoFingerSwipe(min_swipe_velocity, 1677 -min_swipe_velocity * 4, 1678 min_swipe_velocity, 1679 -min_swipe_velocity * 4); 1680 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1681 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up()); 1682 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right()); 1683 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1684 ResetGestureDetection(); 1685 1686 // No swipe without sufficient velocity. 1687 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0); 1688 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1689 ResetGestureDetection(); 1690 1691 // Swipe up with one small and one medium velocity in slightly different but 1692 // not opposing directions. 1693 TwoFingerSwipe(min_swipe_velocity / 2, 1694 min_swipe_velocity / 2, 1695 0, 1696 min_swipe_velocity * 2); 1697 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1698 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1699 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right()); 1700 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1701 ResetGestureDetection(); 1702 1703 // No swipe in orthogonal directions. 1704 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7); 1705 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1706 ResetGestureDetection(); 1707 1708 // Three finger swipe in same directions. 1709 ThreeFingerSwipe(min_swipe_velocity * 2, 1710 0, 1711 min_swipe_velocity * 3, 1712 0, 1713 min_swipe_velocity * 4, 1714 0); 1715 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1716 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1717 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1718 ResetGestureDetection(); 1719 1720 // No three finger swipe in different directions. 1721 ThreeFingerSwipe(min_swipe_velocity * 2, 1722 0, 1723 0, 1724 min_swipe_velocity * 3, 1725 min_swipe_velocity * 4, 1726 0); 1727 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE)); 1728 } 1729 1730 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins 1731 // so LONG_PRESS and LONG_TAP won't be triggered. 1732 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) { 1733 base::TimeTicks event_time = base::TimeTicks::Now(); 1734 1735 MockMotionEvent event = 1736 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1737 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1738 1739 const base::TimeDelta long_press_timeout = 1740 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 1741 RunTasksAndWait(long_press_timeout); 1742 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 1743 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1744 1745 EXPECT_TRUE(CancelActiveTouchSequence()); 1746 EXPECT_FALSE(HasDownEvent()); 1747 1748 event = ObtainMotionEvent(event_time + long_press_timeout, 1749 MotionEvent::ACTION_UP); 1750 gesture_provider_->OnTouchEvent(event); 1751 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 1752 } 1753 1754 // Verify that inserting a touch cancel event will trigger proper touch and 1755 // gesture sequence cancellation. 1756 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { 1757 base::TimeTicks event_time = base::TimeTicks::Now(); 1758 int motion_event_id = 0; 1759 1760 EXPECT_FALSE(CancelActiveTouchSequence()); 1761 EXPECT_EQ(0U, GetReceivedGestureCount()); 1762 1763 MockMotionEvent event = 1764 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1765 event.SetId(++motion_event_id); 1766 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1767 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1768 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1769 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1770 1771 ASSERT_TRUE(CancelActiveTouchSequence()); 1772 EXPECT_FALSE(HasDownEvent()); 1773 1774 // Subsequent MotionEvent's are dropped until ACTION_DOWN. 1775 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1776 MotionEvent::ACTION_MOVE); 1777 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 1778 1779 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1780 MotionEvent::ACTION_UP); 1781 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 1782 1783 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 1784 MotionEvent::ACTION_DOWN); 1785 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1786 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1787 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1788 } 1789 1790 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) { 1791 const base::TimeTicks down_time_1 = TimeTicks::Now(); 1792 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay(); 1793 1794 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1795 1796 MockMotionEvent event = 1797 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1798 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1799 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1800 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1801 1802 event = 1803 ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::ACTION_UP); 1804 gesture_provider_->OnTouchEvent(event); 1805 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1806 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1807 1808 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN); 1809 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1810 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1811 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1812 1813 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 1814 MotionEvent::ACTION_MOVE, 1815 kFakeCoordX, 1816 kFakeCoordY - 30); 1817 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1818 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1819 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 1820 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1821 1822 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 1823 MotionEvent::ACTION_POINTER_DOWN, 1824 kFakeCoordX, 1825 kFakeCoordY - 30, 1826 kFakeCoordX + 50, 1827 kFakeCoordY + 50); 1828 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1829 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType()); 1830 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1831 1832 const size_t gesture_count = GetReceivedGestureCount(); 1833 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 1834 MotionEvent::ACTION_POINTER_UP, 1835 kFakeCoordX, 1836 kFakeCoordY - 30, 1837 kFakeCoordX + 50, 1838 kFakeCoordY + 50); 1839 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1840 EXPECT_EQ(gesture_count, GetReceivedGestureCount()); 1841 1842 event = ObtainMotionEvent(down_time_2 + kOneSecond, 1843 MotionEvent::ACTION_UP); 1844 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1845 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount()); 1846 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1847 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1848 } 1849 1850 // Verify that gesture begin and gesture end events are dispatched correctly. 1851 TEST_F(GestureProviderTest, GestureBeginAndEnd) { 1852 EnableBeginEndTypes(); 1853 base::TimeTicks event_time = base::TimeTicks::Now(); 1854 const float raw_offset_x = 7.5f; 1855 const float raw_offset_y = 5.7f; 1856 1857 EXPECT_EQ(0U, GetReceivedGestureCount()); 1858 MockMotionEvent event = 1859 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1); 1860 event.pointer_count = 1; 1861 event.SetRawOffset(raw_offset_x, raw_offset_y); 1862 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1863 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type()); 1864 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1865 EXPECT_EQ(2U, GetReceivedGestureCount()); 1866 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1867 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1868 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1869 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1870 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1871 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1872 1 - kMockTouchRadius, 1873 kMockTouchRadius * 2, 1874 kMockTouchRadius * 2), 1875 GetMostRecentGestureEvent().details.bounding_box()); 1876 1877 event = ObtainMotionEvent( 1878 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2); 1879 event.pointer_count = 2; 1880 event.SetRawOffset(raw_offset_x, raw_offset_y); 1881 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1882 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1883 EXPECT_EQ(3U, GetReceivedGestureCount()); 1884 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1885 EXPECT_EQ(2, GetMostRecentGestureEvent().x); 1886 EXPECT_EQ(2, GetMostRecentGestureEvent().y); 1887 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1888 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1889 1890 event = ObtainMotionEvent( 1891 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3); 1892 event.pointer_count = 3; 1893 event.SetRawOffset(raw_offset_x, raw_offset_y); 1894 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1895 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1896 EXPECT_EQ(4U, GetReceivedGestureCount()); 1897 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1898 EXPECT_EQ(3, GetMostRecentGestureEvent().x); 1899 EXPECT_EQ(3, GetMostRecentGestureEvent().y); 1900 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1901 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1902 1903 event = ObtainMotionEvent( 1904 event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3); 1905 event.pointer_count = 2; 1906 event.SetRawOffset(raw_offset_x, raw_offset_y); 1907 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1908 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1909 EXPECT_EQ(5U, GetReceivedGestureCount()); 1910 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1911 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1912 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1913 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1914 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1915 1916 event = ObtainMotionEvent( 1917 event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4); 1918 event.SetRawOffset(raw_offset_x, raw_offset_y); 1919 event.pointer_count = 3; 1920 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1921 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1922 EXPECT_EQ(6U, GetReceivedGestureCount()); 1923 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1924 EXPECT_EQ(4, GetMostRecentGestureEvent().x); 1925 EXPECT_EQ(4, GetMostRecentGestureEvent().y); 1926 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1927 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1928 1929 event = ObtainMotionEvent( 1930 event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4); 1931 event.pointer_count = 2; 1932 event.SetRawOffset(raw_offset_x, raw_offset_y); 1933 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1934 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1935 EXPECT_EQ(7U, GetReceivedGestureCount()); 1936 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1937 EXPECT_EQ(2, GetMostRecentGestureEvent().x); 1938 EXPECT_EQ(2, GetMostRecentGestureEvent().y); 1939 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1940 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1941 1942 event = 1943 ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4); 1944 event.pointer_count = 1; 1945 event.SetRawOffset(raw_offset_x, raw_offset_y); 1946 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1947 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1948 EXPECT_EQ(8U, GetReceivedGestureCount()); 1949 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1950 EXPECT_EQ(3, GetMostRecentGestureEvent().x); 1951 EXPECT_EQ(3, GetMostRecentGestureEvent().y); 1952 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1953 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1954 1955 1956 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4); 1957 event.pointer_count = 1; 1958 event.SetRawOffset(raw_offset_x, raw_offset_y); 1959 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1960 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1961 EXPECT_EQ(9U, GetReceivedGestureCount()); 1962 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1963 EXPECT_EQ(4, GetMostRecentGestureEvent().x); 1964 EXPECT_EQ(4, GetMostRecentGestureEvent().y); 1965 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x); 1966 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y); 1967 } 1968 1969 // Verify that gesture begin and gesture end events are dispatched correctly 1970 // when an ACTION_CANCEL is received. 1971 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) { 1972 EnableBeginEndTypes(); 1973 base::TimeTicks event_time = base::TimeTicks::Now(); 1974 1975 EXPECT_EQ(0U, GetReceivedGestureCount()); 1976 MockMotionEvent event = 1977 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1); 1978 event.pointer_count = 1; 1979 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1980 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type()); 1981 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1982 EXPECT_EQ(2U, GetReceivedGestureCount()); 1983 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1984 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1985 1 - kMockTouchRadius, 1986 kMockTouchRadius * 2, 1987 kMockTouchRadius * 2), 1988 GetMostRecentGestureEvent().details.bounding_box()); 1989 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1990 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1991 1992 event = ObtainMotionEvent( 1993 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2); 1994 event.pointer_count = 2; 1995 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1996 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1997 EXPECT_EQ(3U, GetReceivedGestureCount()); 1998 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1999 EXPECT_EQ(2, GetMostRecentGestureEvent().x); 2000 EXPECT_EQ(2, GetMostRecentGestureEvent().y); 2001 2002 2003 event = ObtainMotionEvent( 2004 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3); 2005 event.pointer_count = 3; 2006 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2007 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 2008 EXPECT_EQ(4U, GetReceivedGestureCount()); 2009 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 2010 EXPECT_EQ(3, GetMostRecentGestureEvent().x); 2011 EXPECT_EQ(3, GetMostRecentGestureEvent().y); 2012 2013 event = ObtainMotionEvent( 2014 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 2, 2, 3, 3); 2015 event.pointer_count = 3; 2016 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2017 EXPECT_EQ(7U, GetReceivedGestureCount()); 2018 EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points()); 2019 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).type()); 2020 EXPECT_EQ(2, GetReceivedGesture(5).details.touch_points()); 2021 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(5).type()); 2022 EXPECT_EQ(1, GetReceivedGesture(6).details.touch_points()); 2023 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(6).type()); 2024 EXPECT_EQ(1, GetReceivedGesture(4).x); 2025 EXPECT_EQ(1, GetReceivedGesture(4).y); 2026 EXPECT_EQ(2, GetReceivedGesture(5).x); 2027 EXPECT_EQ(2, GetReceivedGesture(5).y); 2028 EXPECT_EQ(3, GetReceivedGesture(6).x); 2029 EXPECT_EQ(3, GetReceivedGesture(6).y); 2030 } 2031 2032 // Test a simple two finger tap 2033 TEST_F(GestureProviderTest, TwoFingerTap) { 2034 // The time between ACTION_POINTER_DOWN and ACTION_POINTER_UP must be <= the 2035 // two finger tap delay. 2036 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); 2037 const float scaled_touch_slop = GetTouchSlop(); 2038 2039 base::TimeTicks event_time = base::TimeTicks::Now(); 2040 2041 MockMotionEvent event = 2042 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0); 2043 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2044 2045 event = ObtainMotionEvent(event_time, 2046 MotionEvent::ACTION_MOVE, 2047 0, 2048 scaled_touch_slop / 2); 2049 2050 event = ObtainMotionEvent(event_time, 2051 MotionEvent::ACTION_POINTER_DOWN, 2052 0, 2053 0, 2054 kMaxTwoFingerTapSeparation / 2, 2055 0); 2056 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2057 2058 event = 2059 ObtainMotionEvent(event_time, 2060 MotionEvent::ACTION_MOVE, 2061 0, 2062 -scaled_touch_slop / 2, 2063 kMaxTwoFingerTapSeparation / 2 + scaled_touch_slop / 2, 2064 0); 2065 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2066 2067 event = ObtainMotionEvent(event_time, 2068 MotionEvent::ACTION_POINTER_UP, 2069 0, 2070 0, 2071 kMaxTwoFingerTapSeparation, 2072 0); 2073 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2074 2075 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); 2076 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); 2077 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(2).type()); 2078 EXPECT_EQ(3U, GetReceivedGestureCount()); 2079 2080 EXPECT_EQ(kMockTouchRadius * 2, 2081 GetReceivedGesture(2).details.first_finger_width()); 2082 EXPECT_EQ(kMockTouchRadius * 2, 2083 GetReceivedGesture(2).details.first_finger_height()); 2084 } 2085 2086 // Test preventing a two finger tap via finger movement. 2087 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { 2088 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); 2089 const float scaled_touch_slop = GetTouchSlop(); 2090 base::TimeTicks event_time = base::TimeTicks::Now(); 2091 2092 MockMotionEvent event = ObtainMotionEvent( 2093 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 2094 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2095 2096 event = ObtainMotionEvent(event_time, 2097 MotionEvent::ACTION_POINTER_DOWN, 2098 kFakeCoordX, 2099 kFakeCoordY, 2100 kFakeCoordX, 2101 kFakeCoordY); 2102 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2103 2104 event = ObtainMotionEvent(event_time, 2105 MotionEvent::ACTION_MOVE, 2106 kFakeCoordX, 2107 kFakeCoordY, 2108 kFakeCoordX + scaled_touch_slop + 0.1, 2109 kFakeCoordY); 2110 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2111 2112 event = ObtainMotionEvent(event_time, 2113 MotionEvent::ACTION_POINTER_UP, 2114 kFakeCoordX, 2115 kFakeCoordY, 2116 kFakeCoordX, 2117 kFakeCoordY); 2118 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2119 2120 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); 2121 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type()); 2122 EXPECT_EQ(2U, GetReceivedGestureCount()); 2123 } 2124 2125 // Test preventing a two finger tap by waiting too long before releasing the 2126 // secondary pointer. 2127 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { 2128 base::TimeDelta two_finger_tap_timeout = kOneSecond; 2129 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); 2130 base::TimeTicks event_time = base::TimeTicks::Now(); 2131 2132 MockMotionEvent event = ObtainMotionEvent( 2133 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 2134 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2135 2136 event = ObtainMotionEvent(event_time, 2137 MotionEvent::ACTION_MOVE, 2138 kFakeCoordX, 2139 kFakeCoordY); 2140 2141 event = ObtainMotionEvent(event_time, 2142 MotionEvent::ACTION_POINTER_DOWN, 2143 kFakeCoordX, 2144 kFakeCoordY, 2145 kFakeCoordX + kMaxTwoFingerTapSeparation / 2, 2146 kFakeCoordY); 2147 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2148 2149 event = ObtainMotionEvent(event_time + kOneSecond + kOneMicrosecond, 2150 MotionEvent::ACTION_POINTER_UP, 2151 kFakeCoordX, 2152 kFakeCoordY, 2153 kFakeCoordX + kMaxTwoFingerTapSeparation / 2, 2154 kFakeCoordY); 2155 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2156 2157 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); 2158 EXPECT_EQ(1U, GetReceivedGestureCount()); 2159 } 2160 2161 // Test preventing a two finger tap by pressing the secondary pointer too far 2162 // from the first 2163 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) { 2164 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); 2165 base::TimeTicks event_time = base::TimeTicks::Now(); 2166 2167 MockMotionEvent event = ObtainMotionEvent( 2168 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 2169 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2170 2171 event = ObtainMotionEvent(event_time, 2172 MotionEvent::ACTION_POINTER_DOWN, 2173 kFakeCoordX, 2174 kFakeCoordY, 2175 kFakeCoordX + kMaxTwoFingerTapSeparation, 2176 kFakeCoordY); 2177 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2178 2179 event = ObtainMotionEvent(event_time, 2180 MotionEvent::ACTION_POINTER_UP, 2181 kFakeCoordX, 2182 kFakeCoordY, 2183 kFakeCoordX + kMaxTwoFingerTapSeparation, 2184 kFakeCoordY); 2185 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2186 2187 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type()); 2188 EXPECT_EQ(1U, GetReceivedGestureCount()); 2189 } 2190 2191 // Verify that pinch zoom only sends updates which exceed the 2192 // min_pinch_update_span_delta. 2193 TEST_F(GestureProviderTest, PinchZoomWithThreshold) { 2194 const float kMinPinchUpdateDistance = 5; 2195 2196 base::TimeTicks event_time = base::TimeTicks::Now(); 2197 const float touch_slop = GetTouchSlop(); 2198 2199 SetMinPinchUpdateSpanDelta(kMinPinchUpdateDistance); 2200 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 2201 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 2202 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); 2203 2204 int secondary_coord_x = kFakeCoordX + 20 * touch_slop; 2205 int secondary_coord_y = kFakeCoordY + 20 * touch_slop; 2206 2207 // First finger down. 2208 MockMotionEvent event = 2209 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 2210 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2211 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 2212 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 2213 2214 // Second finger down. 2215 event = ObtainMotionEvent(event_time, 2216 MotionEvent::ACTION_POINTER_DOWN, 2217 kFakeCoordX, 2218 kFakeCoordY, 2219 secondary_coord_x, 2220 secondary_coord_y); 2221 2222 gesture_provider_->OnTouchEvent(event); 2223 EXPECT_EQ(1U, GetReceivedGestureCount()); 2224 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 2225 2226 // Move second finger. 2227 secondary_coord_x += 5 * touch_slop; 2228 secondary_coord_y += 5 * touch_slop; 2229 event = ObtainMotionEvent(event_time, 2230 MotionEvent::ACTION_MOVE, 2231 kFakeCoordX, 2232 kFakeCoordY, 2233 secondary_coord_x, 2234 secondary_coord_y); 2235 2236 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2237 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 2238 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 2239 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 2240 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 2241 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 2242 2243 // Small move, shouldn't trigger pinch. 2244 event = ObtainMotionEvent(event_time, 2245 MotionEvent::ACTION_MOVE, 2246 kFakeCoordX, 2247 kFakeCoordY, 2248 secondary_coord_x + kMinPinchUpdateDistance, 2249 secondary_coord_y); 2250 2251 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2252 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 2253 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 2254 2255 // Small move, but combined with the previous move, should trigger pinch. We 2256 // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span 2257 // calculation factors in touch radius. 2258 const float kOvershootMinPinchUpdateDistance = 3; 2259 event = ObtainMotionEvent(event_time, 2260 MotionEvent::ACTION_MOVE, 2261 kFakeCoordX, 2262 kFakeCoordY, 2263 secondary_coord_x + kMinPinchUpdateDistance + 2264 kOvershootMinPinchUpdateDistance, 2265 secondary_coord_y); 2266 2267 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2268 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 2269 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 2270 } 2271 2272 // Verify that the min gesture bound setting is honored. 2273 TEST_F(GestureProviderTest, MinGestureBoundsLength) { 2274 const float kMinGestureBoundsLength = 10.f * kMockTouchRadius; 2275 SetMinGestureBoundsLength(kMinGestureBoundsLength); 2276 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 2277 2278 base::TimeTicks event_time = base::TimeTicks::Now(); 2279 MockMotionEvent event = 2280 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 2281 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2282 2283 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 2284 EXPECT_EQ(kMinGestureBoundsLength, 2285 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2286 EXPECT_EQ(kMinGestureBoundsLength, 2287 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2288 2289 event = 2290 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP); 2291 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2292 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2293 EXPECT_EQ(kMinGestureBoundsLength, 2294 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2295 EXPECT_EQ(kMinGestureBoundsLength, 2296 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2297 } 2298 2299 } // namespace ui 2300