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 78a84b94ae9c5cc07953c5b1464055996bc2294e..8d4badd1aa46fde6897ea3e338e148bacc6ef5ff 100644 |
--- a/ui/events/gesture_detection/gesture_provider_unittest.cc |
+++ b/ui/events/gesture_detection/gesture_provider_unittest.cc |
@@ -217,6 +217,13 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient { |
SetUpWithConfig(config); |
} |
+ void SetMinPinchUpdateDistance(float min_pinch_update_distance) { |
+ GestureProvider::Config config = GetDefaultConfig(); |
+ config.scale_gesture_detector_config.min_pinch_update_distance = |
+ min_pinch_update_distance; |
+ SetUpWithConfig(config); |
+ } |
+ |
bool HasDownEvent() const { return gesture_provider_->current_down_event(); } |
protected: |
@@ -1910,4 +1917,93 @@ TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) { |
EXPECT_EQ(1U, GetReceivedGestureCount()); |
} |
+// Verify that pinch zoom only sends updates which exceed the |
+// min_pinch_update_distance. |
+TEST_F(GestureProviderTest, PinchZoomWithThreshold) { |
+ const float kMinPinchUpdateDistance = 5; |
+ |
+ base::TimeTicks event_time = base::TimeTicks::Now(); |
+ const float touch_slop = GetTouchSlop(); |
+ int motion_event_id = 0; |
+ |
+ SetMinPinchUpdateDistance(kMinPinchUpdateDistance); |
+ gesture_provider_->SetDoubleTapSupportForPageEnabled(false); |
+ gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); |
+ gesture_provider_->SetMultiTouchZoomSupportEnabled(true); |
+ |
+ int secondary_coord_x = kFakeCoordX + 20 * touch_slop; |
+ int secondary_coord_y = kFakeCoordY + 20 * touch_slop; |
+ |
+ // First finger down. |
+ MockMotionEvent event = |
+ ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
+ event.SetId(++motion_event_id); |
+ EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
+ EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
+ EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
+ |
+ // Second finger down. |
+ event = ObtainMotionEvent(event_time, |
+ MotionEvent::ACTION_POINTER_DOWN, |
+ kFakeCoordX, |
+ kFakeCoordY, |
+ secondary_coord_x, |
+ secondary_coord_y); |
+ event.SetId(++motion_event_id); |
jdduke (slow)
2014/05/21 19:30:37
Nit: Let's remove all of the touch id assignment a
tdresser
2014/05/22 12:31:44
Done.
|
+ |
+ gesture_provider_->OnTouchEvent(event); |
+ EXPECT_EQ(1U, GetReceivedGestureCount()); |
+ EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
+ |
+ // Move second finger. |
+ secondary_coord_x += 5 * touch_slop; |
+ secondary_coord_y += 5 * touch_slop; |
+ event = ObtainMotionEvent(event_time, |
+ MotionEvent::ACTION_MOVE, |
+ kFakeCoordX, |
+ kFakeCoordY, |
+ secondary_coord_x, |
+ secondary_coord_y); |
+ event.SetId(++motion_event_id); |
+ |
+ EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
+ EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
+ EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); |
+ EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); |
+ EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); |
+ EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
+ EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); |
+ |
+ // Small move, shouldn't trigger pinch. |
+ event = ObtainMotionEvent(event_time, |
+ MotionEvent::ACTION_MOVE, |
+ kFakeCoordX, |
+ kFakeCoordY, |
+ secondary_coord_x + kMinPinchUpdateDistance, |
+ secondary_coord_y); |
+ event.SetId(++motion_event_id); |
+ |
+ EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
+ EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); |
+ EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); |
+ |
+ // Small move, but combined with the previous move, should trigger pinch. We |
+ // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span |
+ // calculation factors in touch radius. |
+ const float kOvershootMinPinchUpdateDistance = 3; |
jdduke (slow)
2014/05/21 19:30:37
Hmm, where do you get 3 from?
tdresser
2014/05/22 12:31:44
It comes from the way that touch radius factors in
|
+ event = ObtainMotionEvent(event_time, |
+ MotionEvent::ACTION_MOVE, |
+ kFakeCoordX, |
+ kFakeCoordY, |
+ secondary_coord_x + kMinPinchUpdateDistance + |
+ kOvershootMinPinchUpdateDistance, |
+ secondary_coord_y); |
+ event.SetId(++motion_event_id); |
+ |
+ EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
+ EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
+ EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); |
+ EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); |
+} |
+ |
} // namespace ui |