| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/logging.h" | 6 #include "base/logging.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 398 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 399 | 399 |
| 400 const GestureEventData& double_tap = GetMostRecentGestureEvent(); | 400 const GestureEventData& double_tap = GetMostRecentGestureEvent(); |
| 401 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); | 401 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); |
| 402 // Ensure tap details have been set. | 402 // Ensure tap details have been set. |
| 403 EXPECT_EQ(10, double_tap.details.bounding_box().width()); | 403 EXPECT_EQ(10, double_tap.details.bounding_box().width()); |
| 404 EXPECT_EQ(10, double_tap.details.bounding_box().height()); | 404 EXPECT_EQ(10, double_tap.details.bounding_box().height()); |
| 405 EXPECT_EQ(1, double_tap.details.tap_count()); | 405 EXPECT_EQ(1, double_tap.details.tap_count()); |
| 406 } | 406 } |
| 407 | 407 |
| 408 TEST_F(GestureProviderTest, DoubleTapDragZoom) { | 408 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { |
| 409 const base::TimeTicks down_time_1 = TimeTicks::Now(); | 409 const base::TimeTicks down_time_1 = TimeTicks::Now(); |
| 410 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; | 410 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; |
| 411 | 411 |
| 412 MockMotionEvent event = | 412 MockMotionEvent event = |
| 413 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | 413 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); |
| 414 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 414 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 415 | 415 |
| 416 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, | 416 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, |
| 417 MotionEvent::ACTION_UP, | 417 MotionEvent::ACTION_UP, |
| 418 kFakeCoordX, | 418 kFakeCoordX, |
| 419 kFakeCoordY); | 419 kFakeCoordY); |
| 420 gesture_provider_->OnTouchEvent(event); | 420 gesture_provider_->OnTouchEvent(event); |
| 421 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | 421 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); |
| 422 | 422 |
| 423 event = ObtainMotionEvent( | 423 event = ObtainMotionEvent( |
| 424 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | 424 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); |
| 425 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 425 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 426 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 426 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 427 | 427 |
| 428 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, | 428 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, |
| 429 MotionEvent::ACTION_MOVE, | 429 MotionEvent::ACTION_MOVE, |
| 430 kFakeCoordX, | 430 kFakeCoordX, |
| 431 kFakeCoordY + 100); | 431 kFakeCoordY + 100); |
| 432 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 432 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 433 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | 433 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| 434 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent(); | 434 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); |
| 435 ASSERT_TRUE(!!scroll_begin_gesture); | |
| 436 EXPECT_EQ(0, scroll_begin_gesture->details.scroll_x_hint()); | |
| 437 EXPECT_EQ(100, scroll_begin_gesture->details.scroll_y_hint()); | |
| 438 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | |
| 439 | 435 |
| 440 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, | 436 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, |
| 441 MotionEvent::ACTION_MOVE, | 437 MotionEvent::ACTION_MOVE, |
| 442 kFakeCoordX, | 438 kFakeCoordX, |
| 443 kFakeCoordY + 200); | 439 kFakeCoordY + 200); |
| 444 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 440 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 445 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); | 441 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); |
| 446 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); | 442 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); |
| 447 | 443 |
| 448 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, | 444 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, |
| 445 MotionEvent::ACTION_MOVE, |
| 446 kFakeCoordX, |
| 447 kFakeCoordY + 100); |
| 448 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 449 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); |
| 450 EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale()); |
| 451 |
| 452 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 4, |
| 449 MotionEvent::ACTION_UP, | 453 MotionEvent::ACTION_UP, |
| 450 kFakeCoordX, | 454 kFakeCoordX, |
| 451 kFakeCoordY + 200); | 455 kFakeCoordY - 200); |
| 452 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 456 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 453 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); | 457 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); |
| 454 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | 458 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); |
| 455 } | 459 } |
| 456 | 460 |
| 457 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) { | |
| 458 const base::TimeTicks down_time_1 = TimeTicks::Now(); | |
| 459 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; | |
| 460 | |
| 461 MockMotionEvent event = | |
| 462 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | |
| 463 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 464 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 465 | |
| 466 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, | |
| 467 MotionEvent::ACTION_UP); | |
| 468 gesture_provider_->OnTouchEvent(event); | |
| 469 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | |
| 470 | |
| 471 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN); | |
| 472 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 473 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
| 474 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL)); | |
| 475 | |
| 476 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, | |
| 477 MotionEvent::ACTION_MOVE, | |
| 478 kFakeCoordX, | |
| 479 kFakeCoordY - 30); | |
| 480 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 481 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | |
| 482 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | |
| 483 | |
| 484 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, | |
| 485 MotionEvent::ACTION_POINTER_DOWN, | |
| 486 kFakeCoordX, | |
| 487 kFakeCoordY - 30, | |
| 488 kFakeCoordX + 50, | |
| 489 kFakeCoordY + 50); | |
| 490 gesture_provider_->OnTouchEvent(event); | |
| 491 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); | |
| 492 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | |
| 493 const size_t gesture_count = GetReceivedGestureCount(); | |
| 494 | |
| 495 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, | |
| 496 MotionEvent::ACTION_POINTER_UP, | |
| 497 kFakeCoordX, | |
| 498 kFakeCoordY - 30, | |
| 499 kFakeCoordX + 50, | |
| 500 kFakeCoordY + 50); | |
| 501 gesture_provider_->OnTouchEvent(event); | |
| 502 EXPECT_EQ(gesture_count, GetReceivedGestureCount()); | |
| 503 } | |
| 504 | |
| 505 // Generate a scroll gesture and verify that the resulting scroll motion event | 461 // Generate a scroll gesture and verify that the resulting scroll motion event |
| 506 // has both absolute and relative position information. | 462 // has both absolute and relative position information. |
| 507 TEST_F(GestureProviderTest, ScrollUpdateValues) { | 463 TEST_F(GestureProviderTest, ScrollUpdateValues) { |
| 508 const int delta_x = 16; | 464 const int delta_x = 16; |
| 509 const int delta_y = 84; | 465 const int delta_y = 84; |
| 510 | 466 |
| 511 const base::TimeTicks event_time = TimeTicks::Now(); | 467 const base::TimeTicks event_time = TimeTicks::Now(); |
| 512 | 468 |
| 513 MockMotionEvent event = | 469 MockMotionEvent event = |
| 514 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 470 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 // Simulate setting a fixed page scale (or a mobile viewport); | 881 // Simulate setting a fixed page scale (or a mobile viewport); |
| 926 // this should not disrupt the current double-tap gesture. | 882 // this should not disrupt the current double-tap gesture. |
| 927 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); | 883 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); |
| 928 | 884 |
| 929 // Double tap zoom updates should continue. | 885 // Double tap zoom updates should continue. |
| 930 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, | 886 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, |
| 931 MotionEvent::ACTION_MOVE, | 887 MotionEvent::ACTION_MOVE, |
| 932 kFakeCoordX, | 888 kFakeCoordX, |
| 933 kFakeCoordY + 200); | 889 kFakeCoordY + 200); |
| 934 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 890 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 935 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); | |
| 936 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); | 891 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); |
| 892 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); |
| 937 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, | 893 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, |
| 938 MotionEvent::ACTION_UP, | 894 MotionEvent::ACTION_UP, |
| 939 kFakeCoordX, | 895 kFakeCoordX, |
| 940 kFakeCoordY + 200); | 896 kFakeCoordY + 200); |
| 941 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 897 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 942 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); | 898 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); |
| 943 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | 899 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); |
| 944 | 900 |
| 945 // The double-tap gesture has finished, but the page scale is fixed. | 901 // The double-tap gesture has finished, but the page scale is fixed. |
| 946 // The same event sequence should not generate any double tap getsures. | 902 // The same event sequence should not generate any double tap getsures. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 MotionEvent::ACTION_POINTER_DOWN, | 959 MotionEvent::ACTION_POINTER_DOWN, |
| 1004 kFakeCoordX, | 960 kFakeCoordX, |
| 1005 kFakeCoordY, | 961 kFakeCoordY, |
| 1006 secondary_coord_x, | 962 secondary_coord_x, |
| 1007 secondary_coord_y); | 963 secondary_coord_y); |
| 1008 gesture_provider_->OnTouchEvent(event); | 964 gesture_provider_->OnTouchEvent(event); |
| 1009 EXPECT_EQ(1U, GetReceivedGestureCount()); | 965 EXPECT_EQ(1U, GetReceivedGestureCount()); |
| 1010 | 966 |
| 1011 secondary_coord_x += 5 * scaled_touch_slop; | 967 secondary_coord_x += 5 * scaled_touch_slop; |
| 1012 secondary_coord_y += 5 * scaled_touch_slop; | 968 secondary_coord_y += 5 * scaled_touch_slop; |
| 1013 | |
| 1014 event = ObtainMotionEvent(event_time, | 969 event = ObtainMotionEvent(event_time, |
| 1015 MotionEvent::ACTION_MOVE, | 970 MotionEvent::ACTION_MOVE, |
| 1016 kFakeCoordX, | 971 kFakeCoordX, |
| 1017 kFakeCoordY, | 972 kFakeCoordY, |
| 1018 secondary_coord_x, | 973 secondary_coord_x, |
| 1019 secondary_coord_y); | 974 secondary_coord_y); |
| 1020 | |
| 1021 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 975 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1022 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); | 976 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); |
| 1023 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | 977 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| 1024 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); | |
| 1025 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); | 978 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); |
| 1026 | 979 |
| 980 secondary_coord_x += 2 * scaled_touch_slop; |
| 981 secondary_coord_y += 2 * scaled_touch_slop; |
| 982 event = ObtainMotionEvent(event_time, |
| 983 MotionEvent::ACTION_MOVE, |
| 984 kFakeCoordX, |
| 985 kFakeCoordY, |
| 986 secondary_coord_x, |
| 987 secondary_coord_y); |
| 988 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 989 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); |
| 990 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); |
| 991 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); |
| 992 |
| 1027 event = ObtainMotionEvent(event_time, | 993 event = ObtainMotionEvent(event_time, |
| 1028 MotionEvent::ACTION_POINTER_UP, | 994 MotionEvent::ACTION_POINTER_UP, |
| 1029 kFakeCoordX, | 995 kFakeCoordX, |
| 1030 kFakeCoordY, | 996 kFakeCoordY, |
| 1031 secondary_coord_x, | 997 secondary_coord_x, |
| 1032 secondary_coord_y); | 998 secondary_coord_y); |
| 1033 | 999 |
| 1034 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1000 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1035 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType()); | 1001 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType()); |
| 1036 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); | 1002 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1088 MotionEvent::ACTION_UP); | 1054 MotionEvent::ACTION_UP); |
| 1089 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | 1055 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); |
| 1090 | 1056 |
| 1091 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, | 1057 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, |
| 1092 MotionEvent::ACTION_DOWN); | 1058 MotionEvent::ACTION_DOWN); |
| 1093 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1059 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1094 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1060 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1095 } | 1061 } |
| 1096 | 1062 |
| 1097 } // namespace ui | 1063 } // namespace ui |
| OLD | NEW |