Chromium Code Reviews| Index: ui/events/gesture_detection/gesture_provider_unittest.cc |
| diff --git a/ui/events/gesture_detection/gesture_provider_unittest.cc b/ui/events/gesture_detection/gesture_provider_unittest.cc |
| index 6ec8a5bc7f2cd93b658f2bb74b2c8c63325cfd1a..01128a317ffb5df03ad905064c59195c961038e7 100644 |
| --- a/ui/events/gesture_detection/gesture_provider_unittest.cc |
| +++ b/ui/events/gesture_detection/gesture_provider_unittest.cc |
| @@ -131,8 +131,8 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient { |
| return sConfig; |
| } |
| - int GetTouchSlop() const { |
| - return GetDefaultConfig().gesture_detector_config.scaled_touch_slop; |
| + float GetTouchSlop() const { |
| + return GetDefaultConfig().gesture_detector_config.touch_slop; |
| } |
| base::TimeDelta GetLongPressTimeout() const { |
| @@ -154,8 +154,8 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient { |
| void CheckScrollEventSequenceForEndActionType( |
| MotionEvent::Action end_action_type) { |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| - const int scroll_to_x = kFakeCoordX + 100; |
| - const int scroll_to_y = kFakeCoordY + 100; |
| + const float scroll_to_x = kFakeCoordX + 100; |
| + const float scroll_to_y = kFakeCoordY + 100; |
| int motion_event_id = 0; |
| MockMotionEvent event = |
| @@ -507,8 +507,8 @@ TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { |
| // Generate a scroll gesture and verify that the resulting scroll motion event |
| // has both absolute and relative position information. |
| TEST_F(GestureProviderTest, ScrollUpdateValues) { |
| - const int delta_x = 16; |
| - const int delta_y = 84; |
| + const float delta_x = 16; |
| + const float delta_y = 84; |
| const base::TimeTicks event_time = TimeTicks::Now(); |
| @@ -597,8 +597,8 @@ TEST_F(GestureProviderTest, FractionalScroll) { |
| // Generate a scroll gesture and verify that the resulting scroll begin event |
| // has the expected hint values. |
| TEST_F(GestureProviderTest, ScrollBeginValues) { |
| - const int delta_x = 13; |
| - const int delta_y = 89; |
| + const float delta_x = 13; |
| + const float delta_y = 89; |
| const base::TimeTicks event_time = TimeTicks::Now(); |
| @@ -754,8 +754,8 @@ TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { |
| // Verify that the touch slop region is removed from the first scroll delta to |
| // avoid a jump when starting to scroll. |
| TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { |
| - const int scaled_touch_slop = GetTouchSlop(); |
| - const int scroll_delta = 5; |
| + const float touch_slop = GetTouchSlop(); |
| + const float scroll_delta = 5; |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| @@ -766,7 +766,7 @@ TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { |
| event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| MotionEvent::ACTION_MOVE, |
| kFakeCoordX, |
| - kFakeCoordY + scaled_touch_slop + scroll_delta); |
| + kFakeCoordY + touch_slop + scroll_delta); |
| EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); |
| @@ -775,6 +775,56 @@ TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { |
| EXPECT_EQ(scroll_delta, gesture.details.scroll_y()); |
| } |
| +// Verify that movement with the touch slop region does not generate a scroll, |
|
tdresser
2014/04/09 14:00:01
with -> within
jdduke (slow)
2014/04/10 22:04:53
Done.
|
| +// and that the slop region is correct even when using fractional coordinates. |
| +TEST_F(GestureProviderTest, NoScrollWithinTouchSlop) { |
| + const float touch_slop = GetTouchSlop(); |
| + const float scale_factor = 2.5f; |
| + const int touch_slop_pixels = static_cast<int>(scale_factor * touch_slop); |
| + |
| + base::TimeTicks event_time = base::TimeTicks::Now(); |
| + |
| + MockMotionEvent event = |
| + ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| + |
| + event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| + MotionEvent::ACTION_MOVE, |
| + kFakeCoordX + touch_slop_pixels / scale_factor, |
| + kFakeCoordY); |
| + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| + EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| + |
| + event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| + MotionEvent::ACTION_MOVE, |
| + kFakeCoordX, |
| + kFakeCoordY + touch_slop_pixels / scale_factor); |
| + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| + EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| + |
| + event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| + MotionEvent::ACTION_MOVE, |
| + kFakeCoordX - touch_slop_pixels / scale_factor, |
| + kFakeCoordY); |
| + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| + EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| + |
| + event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| + MotionEvent::ACTION_MOVE, |
| + kFakeCoordX, |
| + kFakeCoordY - touch_slop_pixels / scale_factor); |
| + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| + EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| + |
| + event = |
| + ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| + MotionEvent::ACTION_MOVE, |
| + kFakeCoordX, |
| + kFakeCoordY + (touch_slop_pixels + 1.f) / scale_factor); |
| + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| + EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| +} |
| + |
| TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) { |
| gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); |
| @@ -995,13 +1045,13 @@ TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) { |
| // Verify that pinch zoom sends the proper event sequence. |
| TEST_F(GestureProviderTest, PinchZoom) { |
| base::TimeTicks event_time = base::TimeTicks::Now(); |
| - const int scaled_touch_slop = GetTouchSlop(); |
| + const float touch_slop = GetTouchSlop(); |
| int motion_event_id = 0; |
| gesture_provider_->SetMultiTouchSupportEnabled(true); |
| - int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; |
| - int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; |
| + int secondary_coord_x = kFakeCoordX + 20 * touch_slop; |
| + int secondary_coord_y = kFakeCoordY + 20 * touch_slop; |
| MockMotionEvent event = |
| ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| @@ -1020,8 +1070,8 @@ TEST_F(GestureProviderTest, PinchZoom) { |
| gesture_provider_->OnTouchEvent(event); |
| EXPECT_EQ(1U, GetReceivedGestureCount()); |
| - secondary_coord_x += 5 * scaled_touch_slop; |
| - secondary_coord_y += 5 * scaled_touch_slop; |
| + secondary_coord_x += 5 * touch_slop; |
| + secondary_coord_y += 5 * touch_slop; |
| event = ObtainMotionEvent(event_time, |
| MotionEvent::ACTION_MOVE, |
| kFakeCoordX, |
| @@ -1036,8 +1086,8 @@ TEST_F(GestureProviderTest, PinchZoom) { |
| EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
| EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); |
| - secondary_coord_x += 2 * scaled_touch_slop; |
| - secondary_coord_y += 2 * scaled_touch_slop; |
| + secondary_coord_x += 2 * touch_slop; |
| + secondary_coord_y += 2 * touch_slop; |
| event = ObtainMotionEvent(event_time, |
| MotionEvent::ACTION_MOVE, |
| kFakeCoordX, |