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.
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/motion_event_test_utils.h"
16 #include "ui/gfx/geometry/point_f.h"
18 using base::TimeDelta
;
19 using base::TimeTicks
;
20 using ui::test::MockMotionEvent
;
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;
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
;
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;
51 gfx::RectF
BoundsForSingleMockTouchAtLocation(float x
, float y
) {
52 float diameter
= MockMotionEvent::TOUCH_MAJOR
;
53 return gfx::RectF(x
- diameter
/ 2, y
- diameter
/ 2, diameter
, diameter
);
58 class GestureProviderTest
: public testing::Test
, public GestureProviderClient
{
60 GestureProviderTest() {}
61 ~GestureProviderTest() override
{}
63 static MockMotionEvent
ObtainMotionEvent(base::TimeTicks event_time
,
64 MotionEvent::Action action
,
67 return MockMotionEvent(action
, event_time
, x
, y
);
70 static MockMotionEvent
ObtainMotionEvent(base::TimeTicks event_time
,
71 MotionEvent::Action action
,
76 return MockMotionEvent(action
, event_time
, x0
, y0
, x1
, y1
);
79 static MockMotionEvent
ObtainMotionEvent(base::TimeTicks event_time
,
80 MotionEvent::Action action
,
87 return MockMotionEvent(action
, event_time
, x0
, y0
, x1
, y1
, x2
, y2
);
90 static MockMotionEvent
ObtainMotionEvent(
91 base::TimeTicks event_time
,
92 MotionEvent::Action action
,
93 const std::vector
<gfx::PointF
>& positions
) {
94 switch (positions
.size()) {
96 return MockMotionEvent(
97 action
, event_time
, positions
[0].x(), positions
[0].y());
99 return MockMotionEvent(action
,
106 return MockMotionEvent(action
,
115 CHECK(false) << "MockMotionEvent only supports 1-3 pointers";
116 return MockMotionEvent();
120 static MockMotionEvent
ObtainMotionEvent(base::TimeTicks event_time
,
121 MotionEvent::Action action
) {
122 return ObtainMotionEvent(event_time
, action
, kFakeCoordX
, kFakeCoordY
);
126 void SetUp() override
{ SetUpWithConfig(GetDefaultConfig()); }
128 void TearDown() override
{
130 gesture_provider_
.reset();
133 // GestureProviderClient
134 void OnGestureEvent(const GestureEventData
& gesture
) override
{
135 if (gesture
.type() == ET_GESTURE_SCROLL_BEGIN
)
136 active_scroll_begin_event_
.reset(new GestureEventData(gesture
));
137 gestures_
.push_back(gesture
);
140 void SetUpWithConfig(const GestureProvider::Config
& config
) {
141 gesture_provider_
.reset(new GestureProvider(config
, this));
142 gesture_provider_
->SetMultiTouchZoomSupportEnabled(false);
145 void ResetGestureDetection() {
146 gesture_provider_
->ResetDetection();
150 bool CancelActiveTouchSequence() {
151 if (!gesture_provider_
->current_down_event())
153 return gesture_provider_
->OnTouchEvent(
154 *gesture_provider_
->current_down_event()->Cancel());
157 bool HasReceivedGesture(EventType type
) const {
158 for (size_t i
= 0; i
< gestures_
.size(); ++i
) {
159 if (gestures_
[i
].type() == type
)
165 const GestureEventData
& GetMostRecentGestureEvent() const {
166 EXPECT_FALSE(gestures_
.empty());
167 return gestures_
.back();
170 EventType
GetMostRecentGestureEventType() const {
171 EXPECT_FALSE(gestures_
.empty());
172 return gestures_
.back().type();
175 size_t GetReceivedGestureCount() const { return gestures_
.size(); }
177 const GestureEventData
& GetReceivedGesture(size_t index
) const {
178 EXPECT_LT(index
, GetReceivedGestureCount());
179 return gestures_
[index
];
182 const GestureEventData
* GetActiveScrollBeginEvent() const {
183 return active_scroll_begin_event_
? active_scroll_begin_event_
.get() : NULL
;
186 const GestureProvider::Config
& GetDefaultConfig() const {
187 static GestureProvider::Config sConfig
= CreateDefaultConfig();
191 float GetTouchSlop() const {
192 return GetDefaultConfig().gesture_detector_config
.touch_slop
;
195 float GetMinScalingSpan() const {
196 return GetDefaultConfig().scale_gesture_detector_config
.min_scaling_span
;
199 float GetMinSwipeVelocity() const {
200 return GetDefaultConfig().gesture_detector_config
.minimum_swipe_velocity
;
203 base::TimeDelta
GetLongPressTimeout() const {
204 return GetDefaultConfig().gesture_detector_config
.longpress_timeout
;
207 base::TimeDelta
GetShowPressTimeout() const {
208 return GetDefaultConfig().gesture_detector_config
.showpress_timeout
;
211 base::TimeDelta
GetDoubleTapTimeout() const {
212 return GetDefaultConfig().gesture_detector_config
.double_tap_timeout
;
215 base::TimeDelta
GetDoubleTapMinTime() const {
216 return GetDefaultConfig().gesture_detector_config
.double_tap_min_time
;
219 base::TimeDelta
GetValidDoubleTapDelay() const {
220 return (GetDoubleTapTimeout() + GetDoubleTapMinTime()) / 2;
223 void EnableBeginEndTypes() {
224 GestureProvider::Config config
= GetDefaultConfig();
225 config
.gesture_begin_end_types_enabled
= true;
226 SetUpWithConfig(config
);
230 GestureProvider::Config config
= GetDefaultConfig();
231 config
.gesture_detector_config
.swipe_enabled
= true;
232 SetUpWithConfig(config
);
235 void EnableTwoFingerTap(float max_distance_for_two_finger_tap
,
236 base::TimeDelta two_finger_tap_timeout
) {
237 GestureProvider::Config config
= GetDefaultConfig();
238 config
.gesture_detector_config
.two_finger_tap_enabled
= true;
239 config
.gesture_detector_config
.two_finger_tap_max_separation
=
240 max_distance_for_two_finger_tap
;
241 config
.gesture_detector_config
.two_finger_tap_timeout
=
242 two_finger_tap_timeout
;
243 SetUpWithConfig(config
);
246 void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta
) {
247 GestureProvider::Config config
= GetDefaultConfig();
248 config
.scale_gesture_detector_config
.min_pinch_update_span_delta
=
249 min_pinch_update_span_delta
;
250 SetUpWithConfig(config
);
253 void SetMinMaxGestureBoundsLength(float min_gesture_bound_length
,
254 float max_gesture_bound_length
) {
255 GestureProvider::Config config
= GetDefaultConfig();
256 config
.min_gesture_bounds_length
= min_gesture_bound_length
;
257 config
.max_gesture_bounds_length
= max_gesture_bound_length
;
258 SetUpWithConfig(config
);
261 void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout
,
262 base::TimeDelta longpress_timeout
) {
263 GestureProvider::Config config
= GetDefaultConfig();
264 config
.gesture_detector_config
.showpress_timeout
= showpress_timeout
;
265 config
.gesture_detector_config
.longpress_timeout
= longpress_timeout
;
266 SetUpWithConfig(config
);
269 bool HasDownEvent() const { return gesture_provider_
->current_down_event(); }
272 void CheckScrollEventSequenceForEndActionType(
273 MotionEvent::Action end_action_type
) {
274 base::TimeTicks event_time
= base::TimeTicks::Now();
275 const float scroll_to_x
= kFakeCoordX
+ 100;
276 const float scroll_to_y
= kFakeCoordY
+ 100;
277 int motion_event_id
= 3;
278 int motion_event_flags
= EF_SHIFT_DOWN
| EF_CAPS_LOCK_DOWN
;
280 MockMotionEvent event
=
281 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
282 event
.SetPrimaryPointerId(motion_event_id
);
283 event
.set_flags(motion_event_flags
);
285 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
286 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
288 event
= ObtainMotionEvent(event_time
+ kOneSecond
,
289 MotionEvent::ACTION_MOVE
,
292 event
.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER
);
293 event
.SetPrimaryPointerId(motion_event_id
);
294 event
.set_flags(motion_event_flags
);
296 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
297 EXPECT_TRUE(gesture_provider_
->IsScrollInProgress());
298 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
299 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
300 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
301 EXPECT_EQ(event
.GetToolType(0),
302 GetMostRecentGestureEvent().primary_tool_type
);
303 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
304 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x
, scroll_to_y
),
305 GetMostRecentGestureEvent().details
.bounding_box_f());
306 ASSERT_EQ(3U, GetReceivedGestureCount()) << "Only TapDown, "
307 "ScrollBegin and ScrollBy "
308 "should have been sent";
310 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN
, GetReceivedGesture(1).type());
311 EXPECT_EQ(motion_event_id
, GetReceivedGesture(1).motion_event_id
);
312 EXPECT_EQ(event_time
+ kOneSecond
, GetReceivedGesture(1).time
)
313 << "ScrollBegin should have the time of the ACTION_MOVE";
315 event
= ObtainMotionEvent(
316 event_time
+ kOneSecond
, end_action_type
, scroll_to_x
, scroll_to_y
);
317 event
.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER
);
318 event
.SetPrimaryPointerId(motion_event_id
);
320 gesture_provider_
->OnTouchEvent(event
);
321 EXPECT_FALSE(gesture_provider_
->IsScrollInProgress());
322 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END
));
323 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
324 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
325 EXPECT_EQ(event
.GetToolType(0),
326 GetMostRecentGestureEvent().primary_tool_type
);
327 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
328 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x
, scroll_to_y
),
329 GetMostRecentGestureEvent().details
.bounding_box_f());
332 void OneFingerSwipe(float vx
, float vy
) {
333 std::vector
<gfx::Vector2dF
> velocities
;
334 velocities
.push_back(gfx::Vector2dF(vx
, vy
));
335 MultiFingerSwipe(velocities
);
338 void TwoFingerSwipe(float vx0
, float vy0
, float vx1
, float vy1
) {
339 std::vector
<gfx::Vector2dF
> velocities
;
340 velocities
.push_back(gfx::Vector2dF(vx0
, vy0
));
341 velocities
.push_back(gfx::Vector2dF(vx1
, vy1
));
342 MultiFingerSwipe(velocities
);
345 void ThreeFingerSwipe(float vx0
,
351 std::vector
<gfx::Vector2dF
> velocities
;
352 velocities
.push_back(gfx::Vector2dF(vx0
, vy0
));
353 velocities
.push_back(gfx::Vector2dF(vx1
, vy1
));
354 velocities
.push_back(gfx::Vector2dF(vx2
, vy2
));
355 MultiFingerSwipe(velocities
);
358 void MultiFingerSwipe(std::vector
<gfx::Vector2dF
> velocities
) {
359 ASSERT_GT(velocities
.size(), 0U);
361 base::TimeTicks event_time
= base::TimeTicks::Now();
363 std::vector
<gfx::PointF
> positions(velocities
.size());
364 for (size_t i
= 0; i
< positions
.size(); ++i
)
365 positions
[i
] = gfx::PointF(kFakeCoordX
* (i
+ 1), kFakeCoordY
* (i
+ 1));
367 float dt
= kDeltaTimeForFlingSequences
.InSecondsF();
369 // Each pointer down should be a separate event.
370 for (size_t i
= 0; i
< positions
.size(); ++i
) {
371 const size_t pointer_count
= i
+ 1;
372 std::vector
<gfx::PointF
> event_positions(pointer_count
);
373 event_positions
.assign(positions
.begin(),
374 positions
.begin() + pointer_count
);
375 MockMotionEvent event
=
376 ObtainMotionEvent(event_time
,
377 pointer_count
> 1 ? MotionEvent::ACTION_POINTER_DOWN
378 : MotionEvent::ACTION_DOWN
,
380 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
383 for (size_t i
= 0; i
< positions
.size(); ++i
)
384 positions
[i
] += gfx::ScaleVector2d(velocities
[i
], dt
);
385 MockMotionEvent event
=
386 ObtainMotionEvent(event_time
+ kDeltaTimeForFlingSequences
,
387 MotionEvent::ACTION_MOVE
,
389 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
391 for (size_t i
= 0; i
< positions
.size(); ++i
)
392 positions
[i
] += gfx::ScaleVector2d(velocities
[i
], dt
);
393 event
= ObtainMotionEvent(event_time
+ 2 * kDeltaTimeForFlingSequences
,
394 MotionEvent::ACTION_MOVE
,
396 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
398 event
= ObtainMotionEvent(event_time
+ 2 * kDeltaTimeForFlingSequences
,
399 MotionEvent::ACTION_POINTER_UP
,
401 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
404 static void RunTasksAndWait(base::TimeDelta delay
) {
405 base::MessageLoop::current()->PostDelayedTask(
406 FROM_HERE
, base::MessageLoop::QuitClosure(), delay
);
407 base::MessageLoop::current()->Run();
410 std::vector
<GestureEventData
> gestures_
;
411 scoped_ptr
<GestureProvider
> gesture_provider_
;
412 scoped_ptr
<GestureEventData
> active_scroll_begin_event_
;
413 base::MessageLoopForUI message_loop_
;
416 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
417 TEST_F(GestureProviderTest
, GestureTap
) {
418 base::TimeTicks event_time
= base::TimeTicks::Now();
419 int motion_event_id
= 6;
420 int motion_event_flags
= EF_CONTROL_DOWN
| EF_ALT_DOWN
;
422 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
424 MockMotionEvent event
=
425 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
426 event
.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER
);
427 event
.SetPrimaryPointerId(motion_event_id
);
428 event
.set_flags(motion_event_flags
);
430 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
431 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
432 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
433 EXPECT_EQ(event
.GetToolType(0),
434 GetMostRecentGestureEvent().primary_tool_type
);
435 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
436 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
437 GetMostRecentGestureEvent().details
.bounding_box_f());
439 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
440 MotionEvent::ACTION_UP
);
441 event
.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER
);
442 event
.SetPrimaryPointerId(motion_event_id
);
443 event
.set_flags(motion_event_flags
);
445 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
446 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
447 // Ensure tap details have been set.
448 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.tap_count());
449 EXPECT_EQ(event
.GetToolType(0),
450 GetMostRecentGestureEvent().primary_tool_type
);
451 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
452 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
453 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
454 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
455 GetMostRecentGestureEvent().details
.bounding_box_f());
458 // Verify that a DOWN followed shortly by an UP will trigger
459 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
460 TEST_F(GestureProviderTest
, GestureTapWithDelay
) {
461 base::TimeTicks event_time
= base::TimeTicks::Now();
462 int motion_event_id
= 6;
463 int motion_event_flags
= EF_CONTROL_DOWN
| EF_ALT_DOWN
| EF_CAPS_LOCK_DOWN
;
465 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
467 MockMotionEvent event
=
468 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
469 event
.SetPrimaryPointerId(motion_event_id
);
470 event
.set_flags(motion_event_flags
);
472 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
473 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
474 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
475 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
476 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
477 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
478 GetMostRecentGestureEvent().details
.bounding_box_f());
480 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
481 MotionEvent::ACTION_UP
);
482 event
.SetPrimaryPointerId(motion_event_id
);
483 event
.set_flags(motion_event_flags
);
485 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
486 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
487 // Ensure tap details have been set.
488 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.tap_count());
489 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
490 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
491 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
492 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
493 GetMostRecentGestureEvent().details
.bounding_box_f());
494 EXPECT_EQ(event
.GetEventTime(), GetMostRecentGestureEvent().time
);
496 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP
));
497 RunTasksAndWait(GetDoubleTapTimeout());
498 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP
));
499 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
500 EXPECT_EQ(event
.GetEventTime(), GetMostRecentGestureEvent().time
);
503 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
504 TEST_F(GestureProviderTest
, GestureFlingAndCancelLongPress
) {
505 base::TimeTicks event_time
= TimeTicks::Now();
506 base::TimeDelta delta_time
= kDeltaTimeForFlingSequences
;
507 int motion_event_id
= 6;
508 int motion_event_flags
= EF_ALT_DOWN
;
510 MockMotionEvent event
=
511 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
512 event
.SetPrimaryPointerId(motion_event_id
);
513 event
.set_flags(motion_event_flags
);
515 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
516 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
517 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
518 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
519 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
521 event
= ObtainMotionEvent(event_time
+ delta_time
,
522 MotionEvent::ACTION_MOVE
,
525 event
.SetPrimaryPointerId(motion_event_id
);
526 event
.set_flags(motion_event_flags
);
527 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
529 event
= ObtainMotionEvent(event_time
+ delta_time
* 2,
530 MotionEvent::ACTION_UP
,
533 event
.SetPrimaryPointerId(motion_event_id
);
534 event
.set_flags(motion_event_flags
);
536 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
537 EXPECT_EQ(ET_SCROLL_FLING_START
, GetMostRecentGestureEventType());
538 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
539 EXPECT_EQ(motion_event_flags
, GetMostRecentGestureEvent().flags
);
540 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
541 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS
));
543 BoundsForSingleMockTouchAtLocation(kFakeCoordX
* 10, kFakeCoordY
* 10),
544 GetMostRecentGestureEvent().details
.bounding_box_f());
547 // Verify that for a normal scroll the following events are sent:
548 // - ET_GESTURE_SCROLL_BEGIN
549 // - ET_GESTURE_SCROLL_UPDATE
550 // - ET_GESTURE_SCROLL_END
551 TEST_F(GestureProviderTest
, ScrollEventActionUpSequence
) {
552 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP
);
555 // Verify that for a cancelled scroll the following events are sent:
556 // - ET_GESTURE_SCROLL_BEGIN
557 // - ET_GESTURE_SCROLL_UPDATE
558 // - ET_GESTURE_SCROLL_END
559 TEST_F(GestureProviderTest
, ScrollEventActionCancelSequence
) {
560 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL
);
563 // Verify that for a normal fling (fling after scroll) the following events are
565 // - ET_GESTURE_SCROLL_BEGIN
566 // - ET_SCROLL_FLING_START
567 TEST_F(GestureProviderTest
, FlingEventSequence
) {
568 base::TimeTicks event_time
= base::TimeTicks::Now();
569 base::TimeDelta delta_time
= kDeltaTimeForFlingSequences
;
570 int motion_event_id
= 6;
572 MockMotionEvent event
=
573 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
574 event
.SetPrimaryPointerId(motion_event_id
);
576 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
578 event
= ObtainMotionEvent(event_time
+ delta_time
,
579 MotionEvent::ACTION_MOVE
,
582 event
.SetPrimaryPointerId(motion_event_id
);
584 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
585 EXPECT_TRUE(gesture_provider_
->IsScrollInProgress());
586 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
587 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
588 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
589 ASSERT_EQ(3U, GetReceivedGestureCount());
590 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN
, GetReceivedGesture(1).type());
591 EXPECT_EQ(motion_event_id
, GetReceivedGesture(1).motion_event_id
);
593 // We don't want to take a dependency here on exactly how hints are calculated
594 // for a fling (eg. may depend on velocity), so just validate the direction.
595 int hint_x
= GetReceivedGesture(1).details
.scroll_x_hint();
596 int hint_y
= GetReceivedGesture(1).details
.scroll_y_hint();
597 EXPECT_TRUE(hint_x
> 0 && hint_y
> 0 && hint_x
> hint_y
)
598 << "ScrollBegin hint should be in positive X axis";
600 event
= ObtainMotionEvent(event_time
+ delta_time
* 2,
601 MotionEvent::ACTION_UP
,
604 event
.SetPrimaryPointerId(motion_event_id
);
606 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
607 EXPECT_FALSE(gesture_provider_
->IsScrollInProgress());
608 EXPECT_EQ(ET_SCROLL_FLING_START
, GetMostRecentGestureEventType());
609 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
610 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
611 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END
));
612 EXPECT_EQ(event_time
+ delta_time
* 2, GetMostRecentGestureEvent().time
)
613 << "FlingStart should have the time of the ACTION_UP";
616 TEST_F(GestureProviderTest
, GestureCancelledOnCancelEvent
) {
617 const base::TimeTicks event_time
= TimeTicks::Now();
619 MockMotionEvent event
=
620 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
621 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
622 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
624 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
626 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS
));
627 EXPECT_EQ(ET_GESTURE_LONG_PRESS
, GetMostRecentGestureEventType());
629 // A cancellation event may be triggered for a number of reasons, e.g.,
630 // from a context-menu-triggering long press resulting in loss of focus.
631 EXPECT_TRUE(CancelActiveTouchSequence());
632 EXPECT_FALSE(HasDownEvent());
634 // A final ACTION_UP should have no effect.
635 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
636 MotionEvent::ACTION_UP
);
637 EXPECT_FALSE(gesture_provider_
->OnTouchEvent(event
));
640 TEST_F(GestureProviderTest
, GestureCancelledOnDetectionReset
) {
641 const base::TimeTicks event_time
= TimeTicks::Now();
643 MockMotionEvent event
=
644 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
645 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
646 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
648 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
650 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS
));
651 EXPECT_EQ(ET_GESTURE_LONG_PRESS
, GetMostRecentGestureEventType());
653 ResetGestureDetection();
654 EXPECT_FALSE(HasDownEvent());
656 // A final ACTION_UP should have no effect.
657 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
658 MotionEvent::ACTION_UP
);
659 EXPECT_FALSE(gesture_provider_
->OnTouchEvent(event
));
662 TEST_F(GestureProviderTest
, NoTapAfterScrollBegins
) {
663 base::TimeTicks event_time
= base::TimeTicks::Now();
665 MockMotionEvent event
=
666 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
668 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
670 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
671 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
672 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
673 MotionEvent::ACTION_MOVE
,
676 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
677 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
679 event
= ObtainMotionEvent(event_time
+ kOneSecond
,
680 MotionEvent::ACTION_UP
,
683 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
684 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
685 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP
));
688 TEST_F(GestureProviderTest
, DoubleTap
) {
689 base::TimeTicks event_time
= base::TimeTicks::Now();
691 MockMotionEvent event
=
692 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
693 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
695 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
696 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
698 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
699 MotionEvent::ACTION_UP
,
702 gesture_provider_
->OnTouchEvent(event
);
703 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
704 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
706 event_time
+= GetValidDoubleTapDelay();
707 event
= ObtainMotionEvent(event_time
,
708 MotionEvent::ACTION_DOWN
,
711 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
712 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
713 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
715 // Moving a very small amount of distance should not trigger the double tap
717 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
718 MotionEvent::ACTION_MOVE
,
721 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
722 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
723 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
725 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
726 MotionEvent::ACTION_UP
,
729 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
731 const GestureEventData
& double_tap
= GetMostRecentGestureEvent();
732 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP
, double_tap
.type());
733 // Ensure tap details have been set.
734 EXPECT_EQ(10, double_tap
.details
.bounding_box().width());
735 EXPECT_EQ(10, double_tap
.details
.bounding_box().height());
736 EXPECT_EQ(1, double_tap
.details
.tap_count());
739 TEST_F(GestureProviderTest
, DoubleTapDragZoomBasic
) {
740 const base::TimeTicks down_time_1
= TimeTicks::Now();
741 const base::TimeTicks down_time_2
= down_time_1
+ GetValidDoubleTapDelay();
743 MockMotionEvent event
=
744 ObtainMotionEvent(down_time_1
, MotionEvent::ACTION_DOWN
);
745 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
747 event
= ObtainMotionEvent(down_time_1
+ kOneMicrosecond
,
748 MotionEvent::ACTION_UP
,
751 gesture_provider_
->OnTouchEvent(event
);
752 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
753 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
755 event
= ObtainMotionEvent(
756 down_time_2
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
757 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
758 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
759 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
761 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
,
762 MotionEvent::ACTION_MOVE
,
765 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
766 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
767 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN
, GetMostRecentGestureEventType());
768 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
+ 100),
769 GetMostRecentGestureEvent().details
.bounding_box_f());
771 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 2,
772 MotionEvent::ACTION_MOVE
,
775 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
776 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE
, GetMostRecentGestureEventType());
777 EXPECT_LT(1.f
, GetMostRecentGestureEvent().details
.scale());
778 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
+ 200),
779 GetMostRecentGestureEvent().details
.bounding_box_f());
781 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 3,
782 MotionEvent::ACTION_MOVE
,
785 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
786 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE
, GetMostRecentGestureEventType());
787 EXPECT_GT(1.f
, GetMostRecentGestureEvent().details
.scale());
788 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
+ 100),
789 GetMostRecentGestureEvent().details
.bounding_box_f());
791 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 4,
792 MotionEvent::ACTION_UP
,
795 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
796 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END
));
797 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
798 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
- 200),
799 GetMostRecentGestureEvent().details
.bounding_box_f());
802 // Generate a scroll gesture and verify that the resulting scroll motion event
803 // has both absolute and relative position information.
804 TEST_F(GestureProviderTest
, ScrollUpdateValues
) {
805 const float delta_x
= 16;
806 const float delta_y
= 84;
807 const float raw_offset_x
= 17.3f
;
808 const float raw_offset_y
= 13.7f
;
810 const base::TimeTicks event_time
= TimeTicks::Now();
812 MockMotionEvent event
=
813 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
814 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
816 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
817 // compare the relative and absolute coordinates.
818 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
819 MotionEvent::ACTION_MOVE
,
820 kFakeCoordX
- delta_x
/ 2,
821 kFakeCoordY
- delta_y
/ 2);
822 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
824 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
825 MotionEvent::ACTION_MOVE
,
826 kFakeCoordX
- delta_x
,
827 kFakeCoordY
- delta_y
);
828 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
829 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
831 // Make sure the reported gesture event has all the expected details.
832 ASSERT_LT(0U, GetReceivedGestureCount());
833 GestureEventData gesture
= GetMostRecentGestureEvent();
834 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, gesture
.type());
835 EXPECT_EQ(event_time
+ kOneMicrosecond
* 2, gesture
.time
);
836 EXPECT_EQ(kFakeCoordX
- delta_x
, gesture
.x
);
837 EXPECT_EQ(kFakeCoordY
- delta_y
, gesture
.y
);
838 EXPECT_EQ(kFakeCoordX
- delta_x
+ raw_offset_x
, gesture
.raw_x
);
839 EXPECT_EQ(kFakeCoordY
- delta_y
+ raw_offset_y
, gesture
.raw_y
);
840 EXPECT_EQ(1, gesture
.details
.touch_points());
842 // No horizontal delta because of snapping.
843 EXPECT_EQ(0, gesture
.details
.scroll_x());
844 EXPECT_EQ(-delta_y
/ 2, gesture
.details
.scroll_y());
847 // Verify that fractional scroll deltas are rounded as expected and that
848 // fractional scrolling doesn't break scroll snapping.
849 TEST_F(GestureProviderTest
, FractionalScroll
) {
850 const float delta_x
= 0.4f
;
851 const float delta_y
= 5.2f
;
853 const base::TimeTicks event_time
= TimeTicks::Now();
855 MockMotionEvent event
=
856 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
857 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
859 // Skip past the touch slop and move back.
860 event
= ObtainMotionEvent(event_time
,
861 MotionEvent::ACTION_MOVE
,
864 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
865 event
= ObtainMotionEvent(event_time
,
866 MotionEvent::ACTION_MOVE
);
867 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
869 // Now move up slowly, mostly vertically but with a (fractional) bit of
870 // horizontal motion.
871 for (int i
= 1; i
<= 10; i
++) {
872 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* i
,
873 MotionEvent::ACTION_MOVE
,
874 kFakeCoordX
+ delta_x
* i
,
875 kFakeCoordY
+ delta_y
* i
);
876 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
878 ASSERT_LT(0U, GetReceivedGestureCount());
879 GestureEventData gesture
= GetMostRecentGestureEvent();
880 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, gesture
.type());
881 EXPECT_EQ(event_time
+ kOneMicrosecond
* i
, gesture
.time
);
882 EXPECT_EQ(1, gesture
.details
.touch_points());
884 // Verify that the event co-ordinates are still the precise values we
886 EXPECT_EQ(kFakeCoordX
+ delta_x
* i
, gesture
.x
);
887 EXPECT_FLOAT_EQ(kFakeCoordY
+ delta_y
* i
, gesture
.y
);
889 // Verify that we're scrolling vertically by the expected amount
890 // (modulo rounding).
891 EXPECT_GE(gesture
.details
.scroll_y(), (int)delta_y
);
892 EXPECT_LE(gesture
.details
.scroll_y(), ((int)delta_y
) + 1);
894 // And that there has been no horizontal motion at all.
895 EXPECT_EQ(0, gesture
.details
.scroll_x());
899 // Generate a scroll gesture and verify that the resulting scroll begin event
900 // has the expected hint values.
901 TEST_F(GestureProviderTest
, ScrollBeginValues
) {
902 const float delta_x
= 13;
903 const float delta_y
= 89;
905 const base::TimeTicks event_time
= TimeTicks::Now();
907 MockMotionEvent event
=
908 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
909 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
911 // Move twice such that the first event isn't sufficient to start
912 // scrolling on it's own.
913 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
914 MotionEvent::ACTION_MOVE
,
917 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
918 EXPECT_FALSE(gesture_provider_
->IsScrollInProgress());
920 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
921 MotionEvent::ACTION_MOVE
,
922 kFakeCoordX
+ delta_x
,
923 kFakeCoordY
+ delta_y
);
924 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
925 EXPECT_TRUE(gesture_provider_
->IsScrollInProgress());
927 const GestureEventData
* scroll_begin_gesture
= GetActiveScrollBeginEvent();
928 ASSERT_TRUE(scroll_begin_gesture
);
929 EXPECT_EQ(delta_x
, scroll_begin_gesture
->details
.scroll_x_hint());
930 EXPECT_EQ(delta_y
, scroll_begin_gesture
->details
.scroll_y_hint());
933 TEST_F(GestureProviderTest
, LongPressAndTapCancelledWhenScrollBegins
) {
934 base::TimeTicks event_time
= base::TimeTicks::Now();
936 MockMotionEvent event
=
937 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
938 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
939 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
940 MotionEvent::ACTION_MOVE
,
943 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
944 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
945 MotionEvent::ACTION_MOVE
,
948 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
950 const base::TimeDelta long_press_timeout
=
951 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond
;
952 RunTasksAndWait(long_press_timeout
);
954 // No LONG_TAP as the LONG_PRESS timer is cancelled.
955 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS
));
956 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP
));
959 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
960 TEST_F(GestureProviderTest
, GestureLongTap
) {
961 base::TimeTicks event_time
= base::TimeTicks::Now();
963 MockMotionEvent event
=
964 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
965 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
967 const base::TimeDelta long_press_timeout
=
968 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond
;
969 RunTasksAndWait(long_press_timeout
);
971 EXPECT_EQ(ET_GESTURE_LONG_PRESS
, GetMostRecentGestureEventType());
972 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
973 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
974 GetMostRecentGestureEvent().details
.bounding_box_f());
976 event
= ObtainMotionEvent(event_time
+ kOneSecond
, MotionEvent::ACTION_UP
);
977 gesture_provider_
->OnTouchEvent(event
);
978 EXPECT_EQ(ET_GESTURE_LONG_TAP
, GetMostRecentGestureEventType());
979 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
980 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
981 GetMostRecentGestureEvent().details
.bounding_box_f());
984 TEST_F(GestureProviderTest
, GestureLongPressDoesNotPreventScrolling
) {
985 base::TimeTicks event_time
= base::TimeTicks::Now();
987 MockMotionEvent event
=
988 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
989 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
991 const base::TimeDelta long_press_timeout
=
992 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond
;
993 RunTasksAndWait(long_press_timeout
);
995 EXPECT_EQ(ET_GESTURE_LONG_PRESS
, GetMostRecentGestureEventType());
996 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
997 event
= ObtainMotionEvent(event_time
+ long_press_timeout
,
998 MotionEvent::ACTION_MOVE
,
1001 gesture_provider_
->OnTouchEvent(event
);
1003 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
1004 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1005 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1007 event
= ObtainMotionEvent(event_time
+ long_press_timeout
,
1008 MotionEvent::ACTION_UP
);
1009 gesture_provider_
->OnTouchEvent(event
);
1010 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP
));
1013 TEST_F(GestureProviderTest
, NoGestureLongPressDuringDoubleTap
) {
1014 base::TimeTicks event_time
= base::TimeTicks::Now();
1015 int motion_event_id
= 6;
1017 MockMotionEvent event
= ObtainMotionEvent(
1018 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1019 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1021 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1022 MotionEvent::ACTION_UP
,
1025 gesture_provider_
->OnTouchEvent(event
);
1026 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1027 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1029 event_time
+= GetValidDoubleTapDelay();
1030 event
= ObtainMotionEvent(event_time
,
1031 MotionEvent::ACTION_DOWN
,
1034 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1035 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1036 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1037 EXPECT_TRUE(gesture_provider_
->IsDoubleTapInProgress());
1039 const base::TimeDelta long_press_timeout
=
1040 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond
;
1041 RunTasksAndWait(long_press_timeout
);
1042 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS
));
1044 event
= ObtainMotionEvent(event_time
+ long_press_timeout
,
1045 MotionEvent::ACTION_MOVE
,
1048 event
.SetPrimaryPointerId(motion_event_id
);
1050 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1051 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN
, GetMostRecentGestureEventType());
1052 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
1053 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1054 EXPECT_TRUE(gesture_provider_
->IsDoubleTapInProgress());
1056 event
= ObtainMotionEvent(event_time
+ long_press_timeout
+ kOneMicrosecond
,
1057 MotionEvent::ACTION_UP
,
1060 event
.SetPrimaryPointerId(motion_event_id
);
1061 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1062 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
1063 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
1064 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1065 EXPECT_FALSE(gesture_provider_
->IsDoubleTapInProgress());
1068 // Verify that the touch slop region is removed from the first scroll delta to
1069 // avoid a jump when starting to scroll.
1070 TEST_F(GestureProviderTest
, TouchSlopRemovedFromScroll
) {
1071 const float touch_slop
= GetTouchSlop();
1072 const float scroll_delta
= 5;
1074 base::TimeTicks event_time
= base::TimeTicks::Now();
1076 MockMotionEvent event
=
1077 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1078 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1080 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1081 MotionEvent::ACTION_MOVE
,
1083 kFakeCoordY
+ touch_slop
+ scroll_delta
);
1084 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1086 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
1087 GestureEventData gesture
= GetMostRecentGestureEvent();
1088 EXPECT_EQ(0, gesture
.details
.scroll_x());
1089 EXPECT_EQ(scroll_delta
, gesture
.details
.scroll_y());
1090 EXPECT_EQ(1, gesture
.details
.touch_points());
1093 // Verify that movement within the touch slop region does not generate a scroll,
1094 // and that the slop region is correct even when using fractional coordinates.
1095 TEST_F(GestureProviderTest
, NoScrollWithinTouchSlop
) {
1096 const float touch_slop
= GetTouchSlop();
1097 const float scale_factor
= 2.5f
;
1098 const int touch_slop_pixels
= static_cast<int>(scale_factor
* touch_slop
);
1100 base::TimeTicks event_time
= base::TimeTicks::Now();
1102 MockMotionEvent event
=
1103 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1104 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1106 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1107 MotionEvent::ACTION_MOVE
,
1108 kFakeCoordX
+ touch_slop_pixels
/ scale_factor
,
1110 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1111 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1113 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1114 MotionEvent::ACTION_MOVE
,
1116 kFakeCoordY
+ touch_slop_pixels
/ scale_factor
);
1117 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1118 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1120 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1121 MotionEvent::ACTION_MOVE
,
1122 kFakeCoordX
- touch_slop_pixels
/ scale_factor
,
1124 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1125 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1127 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1128 MotionEvent::ACTION_MOVE
,
1130 kFakeCoordY
- touch_slop_pixels
/ scale_factor
);
1131 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1132 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1135 ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1136 MotionEvent::ACTION_MOVE
,
1138 kFakeCoordY
+ (touch_slop_pixels
+ 1.f
) / scale_factor
);
1139 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1140 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1143 TEST_F(GestureProviderTest
, NoDoubleTapWhenTooRapid
) {
1144 base::TimeTicks event_time
= base::TimeTicks::Now();
1146 MockMotionEvent event
=
1147 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1148 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1150 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1151 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1153 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1154 MotionEvent::ACTION_UP
,
1157 gesture_provider_
->OnTouchEvent(event
);
1158 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1159 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1161 // If the second tap follows the first in too short a time span, no double-tap
1163 event_time
+= (GetDoubleTapMinTime() / 2);
1164 event
= ObtainMotionEvent(event_time
,
1165 MotionEvent::ACTION_DOWN
,
1168 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1169 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1170 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1172 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1173 MotionEvent::ACTION_UP
,
1176 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1177 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1180 TEST_F(GestureProviderTest
, NoDoubleTapWhenExplicitlyDisabled
) {
1181 // Ensure that double-tap gestures can be disabled.
1182 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
1184 base::TimeTicks event_time
= base::TimeTicks::Now();
1185 MockMotionEvent event
= ObtainMotionEvent(
1186 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1187 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1188 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1190 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1191 MotionEvent::ACTION_UP
,
1194 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1195 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
1197 event_time
+= GetValidDoubleTapDelay();
1198 event
= ObtainMotionEvent(event_time
,
1199 MotionEvent::ACTION_DOWN
,
1202 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1203 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1205 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1206 MotionEvent::ACTION_UP
,
1209 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1210 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
1212 // Ensure that double-tap gestures can be interrupted.
1213 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
1215 event_time
= base::TimeTicks::Now();
1216 event
= ObtainMotionEvent(
1217 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1218 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1219 EXPECT_EQ(5U, GetReceivedGestureCount());
1221 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1222 MotionEvent::ACTION_UP
,
1225 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1226 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1228 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
1229 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
1231 // Ensure that double-tap gestures can be resumed.
1232 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
1234 event_time
+= GetValidDoubleTapDelay();
1235 event
= ObtainMotionEvent(event_time
,
1236 MotionEvent::ACTION_DOWN
,
1239 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1240 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1242 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1243 MotionEvent::ACTION_UP
,
1246 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1247 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1249 event_time
+= GetValidDoubleTapDelay();
1250 event
= ObtainMotionEvent(event_time
,
1251 MotionEvent::ACTION_DOWN
,
1254 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1255 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1257 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1258 MotionEvent::ACTION_UP
,
1261 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1262 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP
, GetMostRecentGestureEventType());
1265 TEST_F(GestureProviderTest
, NoDelayedTapWhenDoubleTapSupportToggled
) {
1266 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
1268 base::TimeTicks event_time
= base::TimeTicks::Now();
1269 MockMotionEvent event
= ObtainMotionEvent(
1270 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1271 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1272 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1273 EXPECT_EQ(1U, GetReceivedGestureCount());
1275 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1276 MotionEvent::ACTION_UP
,
1279 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1280 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1281 EXPECT_EQ(2U, GetReceivedGestureCount());
1283 // Disabling double-tap during the tap timeout should flush the delayed tap.
1284 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
1285 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
1286 EXPECT_EQ(3U, GetReceivedGestureCount());
1288 // No further timeout gestures should arrive.
1289 const base::TimeDelta long_press_timeout
=
1290 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond
;
1291 RunTasksAndWait(long_press_timeout
);
1292 EXPECT_EQ(3U, GetReceivedGestureCount());
1295 TEST_F(GestureProviderTest
, NoDoubleTapDragZoomWhenDisabledOnPlatform
) {
1296 const base::TimeTicks down_time_1
= TimeTicks::Now();
1297 const base::TimeTicks down_time_2
= down_time_1
+ GetValidDoubleTapDelay();
1299 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
1301 MockMotionEvent event
=
1302 ObtainMotionEvent(down_time_1
, MotionEvent::ACTION_DOWN
);
1303 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1305 event
= ObtainMotionEvent(down_time_1
+ kOneMicrosecond
,
1306 MotionEvent::ACTION_UP
,
1309 gesture_provider_
->OnTouchEvent(event
);
1311 event
= ObtainMotionEvent(
1312 down_time_2
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1313 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1315 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
,
1316 MotionEvent::ACTION_MOVE
,
1320 // The move should become a scroll, as doubletap drag zoom is disabled.
1321 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1322 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1323 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
1325 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 2,
1326 MotionEvent::ACTION_MOVE
,
1329 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1330 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
1331 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1332 EXPECT_EQ(down_time_2
+ kOneMicrosecond
* 2,
1333 GetMostRecentGestureEvent().time
);
1334 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE
));
1336 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 3,
1337 MotionEvent::ACTION_UP
,
1340 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1341 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END
));
1344 // Verify that double tap drag zoom feature is not invoked when the gesture
1345 // handler is told to disable double tap gesture detection.
1346 // The second tap sequence should be treated just as the first would be.
1347 TEST_F(GestureProviderTest
, NoDoubleTapDragZoomWhenDisabledOnPage
) {
1348 const base::TimeTicks down_time_1
= TimeTicks::Now();
1349 const base::TimeTicks down_time_2
= down_time_1
+ GetValidDoubleTapDelay();
1351 gesture_provider_
->SetDoubleTapSupportForPageEnabled(false);
1353 MockMotionEvent event
=
1354 ObtainMotionEvent(down_time_1
, MotionEvent::ACTION_DOWN
);
1355 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1357 event
= ObtainMotionEvent(down_time_1
+ kOneMicrosecond
,
1358 MotionEvent::ACTION_UP
,
1361 gesture_provider_
->OnTouchEvent(event
);
1363 event
= ObtainMotionEvent(
1364 down_time_2
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1365 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1367 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
,
1368 MotionEvent::ACTION_MOVE
,
1372 // The move should become a scroll, as double tap drag zoom is disabled.
1373 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1374 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1375 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
1377 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 2,
1378 MotionEvent::ACTION_MOVE
,
1381 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1382 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetMostRecentGestureEventType());
1383 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1384 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE
));
1386 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 3,
1387 MotionEvent::ACTION_UP
,
1390 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1391 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END
));
1394 // Verify that updating double tap support during a double tap drag zoom
1395 // disables double tap detection after the gesture has ended.
1396 TEST_F(GestureProviderTest
, FixedPageScaleDuringDoubleTapDragZoom
) {
1397 base::TimeTicks down_time_1
= TimeTicks::Now();
1398 base::TimeTicks down_time_2
= down_time_1
+ GetValidDoubleTapDelay();
1400 gesture_provider_
->SetDoubleTapSupportForPageEnabled(true);
1401 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
1403 // Start a double-tap drag gesture.
1404 MockMotionEvent event
=
1405 ObtainMotionEvent(down_time_1
, MotionEvent::ACTION_DOWN
);
1406 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1407 event
= ObtainMotionEvent(down_time_1
+ kOneMicrosecond
,
1408 MotionEvent::ACTION_UP
,
1411 gesture_provider_
->OnTouchEvent(event
);
1412 event
= ObtainMotionEvent(
1413 down_time_2
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1414 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1415 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
,
1416 MotionEvent::ACTION_MOVE
,
1419 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1420 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1421 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN
, GetMostRecentGestureEventType());
1422 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1424 // Simulate setting a fixed page scale (or a mobile viewport);
1425 // this should not disrupt the current double-tap gesture.
1426 gesture_provider_
->SetDoubleTapSupportForPageEnabled(false);
1428 // Double tap zoom updates should continue.
1429 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 2,
1430 MotionEvent::ACTION_MOVE
,
1433 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1434 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE
, GetMostRecentGestureEventType());
1435 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1436 EXPECT_LT(1.f
, GetMostRecentGestureEvent().details
.scale());
1437 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 3,
1438 MotionEvent::ACTION_UP
,
1441 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1442 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END
));
1443 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
1444 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1446 // The double-tap gesture has finished, but the page scale is fixed.
1447 // The same event sequence should not generate any double tap getsures.
1449 down_time_1
+= kOneMicrosecond
* 40;
1450 down_time_2
+= kOneMicrosecond
* 40;
1452 // Start a double-tap drag gesture.
1453 event
= ObtainMotionEvent(down_time_1
, MotionEvent::ACTION_DOWN
);
1454 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1455 event
= ObtainMotionEvent(down_time_1
+ kOneMicrosecond
,
1456 MotionEvent::ACTION_UP
,
1459 gesture_provider_
->OnTouchEvent(event
);
1460 event
= ObtainMotionEvent(
1461 down_time_2
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
1462 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1463 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
,
1464 MotionEvent::ACTION_MOVE
,
1467 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1468 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1469 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
1471 // Double tap zoom updates should not be sent.
1472 // Instead, the second tap drag becomes a scroll gesture sequence.
1473 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 2,
1474 MotionEvent::ACTION_MOVE
,
1477 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1478 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE
));
1479 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE
));
1480 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 3,
1481 MotionEvent::ACTION_UP
,
1484 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1485 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END
));
1488 // Verify that pinch zoom sends the proper event sequence.
1489 TEST_F(GestureProviderTest
, PinchZoom
) {
1490 base::TimeTicks event_time
= base::TimeTicks::Now();
1491 const float touch_slop
= GetTouchSlop();
1492 const float raw_offset_x
= 3.2f
;
1493 const float raw_offset_y
= 4.3f
;
1494 int motion_event_id
= 6;
1496 gesture_provider_
->SetDoubleTapSupportForPageEnabled(false);
1497 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
1498 gesture_provider_
->SetMultiTouchZoomSupportEnabled(true);
1500 int secondary_coord_x
= kFakeCoordX
+ 20 * touch_slop
;
1501 int secondary_coord_y
= kFakeCoordY
+ 20 * touch_slop
;
1503 MockMotionEvent event
=
1504 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1505 event
.SetPrimaryPointerId(motion_event_id
);
1506 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1507 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1508 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1509 EXPECT_EQ(kFakeCoordX
, GetMostRecentGestureEvent().x
);
1510 EXPECT_EQ(kFakeCoordY
, GetMostRecentGestureEvent().y
);
1511 EXPECT_EQ(kFakeCoordX
+ raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
1512 EXPECT_EQ(kFakeCoordY
+ raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
1513 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1514 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
1515 GetMostRecentGestureEvent().details
.bounding_box_f());
1517 // Toggling double-tap support should not take effect until the next sequence.
1518 gesture_provider_
->SetDoubleTapSupportForPageEnabled(true);
1520 event
= ObtainMotionEvent(event_time
,
1521 MotionEvent::ACTION_POINTER_DOWN
,
1526 event
.SetPrimaryPointerId(motion_event_id
);
1527 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1529 gesture_provider_
->OnTouchEvent(event
);
1530 EXPECT_EQ(1U, GetReceivedGestureCount());
1531 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1532 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX
, kFakeCoordY
),
1533 GetMostRecentGestureEvent().details
.bounding_box_f());
1535 secondary_coord_x
+= 5 * touch_slop
;
1536 secondary_coord_y
+= 5 * touch_slop
;
1537 event
= ObtainMotionEvent(event_time
,
1538 MotionEvent::ACTION_MOVE
,
1543 event
.SetPrimaryPointerId(motion_event_id
);
1544 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1546 // Toggling double-tap support should not take effect until the next sequence.
1547 gesture_provider_
->SetDoubleTapSupportForPageEnabled(false);
1549 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1550 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
1551 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1552 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
1553 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1554 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE
));
1556 EXPECT_EQ((kFakeCoordX
+ secondary_coord_x
) / 2, GetReceivedGesture(3).x
);
1557 EXPECT_EQ((kFakeCoordY
+ secondary_coord_y
) / 2, GetReceivedGesture(3).y
);
1558 EXPECT_EQ((kFakeCoordX
+ secondary_coord_x
) / 2 + raw_offset_x
,
1559 GetReceivedGesture(3).raw_x
);
1560 EXPECT_EQ((kFakeCoordY
+ secondary_coord_y
) / 2 + raw_offset_y
,
1561 GetReceivedGesture(3).raw_y
);
1564 gfx::RectF(kFakeCoordX
- kMockTouchRadius
, kFakeCoordY
- kMockTouchRadius
,
1565 secondary_coord_x
- kFakeCoordX
+ kMockTouchRadius
* 2,
1566 secondary_coord_y
- kFakeCoordY
+ kMockTouchRadius
* 2),
1567 GetMostRecentGestureEvent().details
.bounding_box_f());
1569 secondary_coord_x
+= 2 * touch_slop
;
1570 secondary_coord_y
+= 2 * touch_slop
;
1571 event
= ObtainMotionEvent(event_time
,
1572 MotionEvent::ACTION_MOVE
,
1577 event
.SetPrimaryPointerId(motion_event_id
);
1579 // Toggling double-tap support should not take effect until the next sequence.
1580 gesture_provider_
->SetDoubleTapSupportForPageEnabled(true);
1582 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1583 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
1584 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE
));
1585 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE
, GetMostRecentGestureEventType());
1586 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1587 EXPECT_LT(1.f
, GetMostRecentGestureEvent().details
.scale());
1589 gfx::RectF(kFakeCoordX
- kMockTouchRadius
, kFakeCoordY
- kMockTouchRadius
,
1590 secondary_coord_x
- kFakeCoordX
+ kMockTouchRadius
* 2,
1591 secondary_coord_y
- kFakeCoordY
+ kMockTouchRadius
* 2),
1592 GetMostRecentGestureEvent().details
.bounding_box_f());
1594 event
= ObtainMotionEvent(event_time
,
1595 MotionEvent::ACTION_POINTER_UP
,
1600 event
.SetPrimaryPointerId(motion_event_id
);
1602 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1603 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
1604 EXPECT_EQ(ET_GESTURE_PINCH_END
, GetMostRecentGestureEventType());
1605 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1606 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END
));
1608 gfx::RectF(kFakeCoordX
- kMockTouchRadius
, kFakeCoordY
- kMockTouchRadius
,
1609 secondary_coord_x
- kFakeCoordX
+ kMockTouchRadius
* 2,
1610 secondary_coord_y
- kFakeCoordY
+ kMockTouchRadius
* 2),
1611 GetMostRecentGestureEvent().details
.bounding_box_f());
1613 event
= ObtainMotionEvent(event_time
, MotionEvent::ACTION_UP
);
1614 gesture_provider_
->OnTouchEvent(event
);
1615 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
1616 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1618 gfx::RectF(kFakeCoordX
- kMockTouchRadius
, kFakeCoordY
- kMockTouchRadius
,
1619 kMockTouchRadius
* 2, kMockTouchRadius
* 2),
1620 GetMostRecentGestureEvent().details
.bounding_box_f());
1623 // Verify that no accidental pinching occurs if the touch size is large relative
1624 // to the min scaling span when the touch major value is used in scaling.
1625 TEST_F(GestureProviderTest
, NoPinchZoomWithFatFinger
) {
1626 base::TimeTicks event_time
= base::TimeTicks::Now();
1627 const float kFatFingerSize
= GetMinScalingSpan() * 3.f
;
1629 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
1630 gesture_provider_
->SetMultiTouchZoomSupportEnabled(true);
1632 MockMotionEvent event
=
1633 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1634 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1635 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1636 EXPECT_EQ(1U, GetReceivedGestureCount());
1638 event
= ObtainMotionEvent(event_time
+ kOneSecond
,
1639 MotionEvent::ACTION_MOVE
);
1640 event
.SetTouchMajor(0.1f
);
1641 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1642 EXPECT_EQ(1U, GetReceivedGestureCount());
1644 event
= ObtainMotionEvent(event_time
+ kOneSecond
* 2,
1645 MotionEvent::ACTION_MOVE
,
1648 event
.SetTouchMajor(1.f
);
1649 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1650 EXPECT_EQ(1U, GetReceivedGestureCount());
1652 event
= ObtainMotionEvent(event_time
+ kOneSecond
* 3,
1653 MotionEvent::ACTION_MOVE
);
1654 event
.SetTouchMajor(kFatFingerSize
* 3.5f
);
1655 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1656 EXPECT_EQ(1U, GetReceivedGestureCount());
1658 event
= ObtainMotionEvent(event_time
+ kOneSecond
* 4,
1659 MotionEvent::ACTION_MOVE
);
1660 event
.SetTouchMajor(kFatFingerSize
* 5.f
);
1661 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1662 EXPECT_EQ(1U, GetReceivedGestureCount());
1664 event
= ObtainMotionEvent(event_time
+ kOneSecond
* 4,
1665 MotionEvent::ACTION_MOVE
,
1667 kFakeCoordY
- 25.f
);
1668 event
.SetTouchMajor(kFatFingerSize
* 10.f
);
1669 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1670 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
1672 event
= ObtainMotionEvent(event_time
+ kOneSecond
* 4,
1673 MotionEvent::ACTION_MOVE
,
1674 kFakeCoordX
+ 100.f
,
1675 kFakeCoordY
- 50.f
);
1676 event
.SetTouchMajor(kFatFingerSize
* 5.f
);
1677 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1678 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
1681 // Verify that multi-finger swipe sends the proper event sequence.
1682 TEST_F(GestureProviderTest
, MultiFingerSwipe
) {
1684 gesture_provider_
->SetMultiTouchZoomSupportEnabled(false);
1685 const float min_swipe_velocity
= GetMinSwipeVelocity();
1687 // One finger - swipe right
1688 OneFingerSwipe(2 * min_swipe_velocity
, 0);
1689 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1690 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_right());
1691 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1692 ResetGestureDetection();
1694 // One finger - swipe left
1695 OneFingerSwipe(-2 * min_swipe_velocity
, 0);
1696 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1697 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_left());
1698 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1699 ResetGestureDetection();
1701 // One finger - swipe down
1702 OneFingerSwipe(0, 2 * min_swipe_velocity
);
1703 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1704 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_down());
1705 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1706 ResetGestureDetection();
1708 // One finger - swipe up
1709 OneFingerSwipe(0, -2 * min_swipe_velocity
);
1710 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1711 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_up());
1712 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1713 ResetGestureDetection();
1717 TwoFingerSwipe(min_swipe_velocity
* 2, 0, min_swipe_velocity
* 2, 0);
1718 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1719 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_right());
1720 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1721 ResetGestureDetection();
1724 TwoFingerSwipe(-min_swipe_velocity
* 2, 0, -min_swipe_velocity
* 2, 0);
1725 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1726 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_left());
1727 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1728 ResetGestureDetection();
1730 // No swipe with different touch directions.
1731 TwoFingerSwipe(min_swipe_velocity
* 2, 0, -min_swipe_velocity
* 2, 0);
1732 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1733 ResetGestureDetection();
1735 // No swipe without a dominant direction.
1736 TwoFingerSwipe(min_swipe_velocity
* 2,
1737 min_swipe_velocity
* 2,
1738 min_swipe_velocity
* 2,
1739 min_swipe_velocity
* 2);
1740 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1741 ResetGestureDetection();
1743 // Swipe down with non-zero velocities on both axes and dominant direction.
1744 TwoFingerSwipe(-min_swipe_velocity
,
1745 min_swipe_velocity
* 4,
1746 -min_swipe_velocity
,
1747 min_swipe_velocity
* 4);
1748 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1749 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_down());
1750 EXPECT_FALSE(GetMostRecentGestureEvent().details
.swipe_left());
1751 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1752 ResetGestureDetection();
1754 // Swipe up with non-zero velocities on both axes.
1755 TwoFingerSwipe(min_swipe_velocity
,
1756 -min_swipe_velocity
* 4,
1758 -min_swipe_velocity
* 4);
1759 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1760 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_up());
1761 EXPECT_FALSE(GetMostRecentGestureEvent().details
.swipe_right());
1762 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1763 ResetGestureDetection();
1765 // No swipe without sufficient velocity.
1766 TwoFingerSwipe(min_swipe_velocity
/ 2, 0, 0, 0);
1767 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1768 ResetGestureDetection();
1770 // Swipe up with one small and one medium velocity in slightly different but
1771 // not opposing directions.
1772 TwoFingerSwipe(min_swipe_velocity
/ 2,
1773 min_swipe_velocity
/ 2,
1775 min_swipe_velocity
* 2);
1776 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1777 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_down());
1778 EXPECT_FALSE(GetMostRecentGestureEvent().details
.swipe_right());
1779 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1780 ResetGestureDetection();
1782 // No swipe in orthogonal directions.
1783 TwoFingerSwipe(min_swipe_velocity
* 2, 0, 0, min_swipe_velocity
* 7);
1784 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1785 ResetGestureDetection();
1787 // Three finger swipe in same directions.
1788 ThreeFingerSwipe(min_swipe_velocity
* 2,
1790 min_swipe_velocity
* 3,
1792 min_swipe_velocity
* 4,
1794 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1795 EXPECT_TRUE(GetMostRecentGestureEvent().details
.swipe_right());
1796 EXPECT_EQ(3, GetMostRecentGestureEvent().details
.touch_points());
1797 ResetGestureDetection();
1799 // No three finger swipe in different directions.
1800 ThreeFingerSwipe(min_swipe_velocity
* 2,
1803 min_swipe_velocity
* 3,
1804 min_swipe_velocity
* 4,
1806 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE
));
1809 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1810 // so LONG_PRESS and LONG_TAP won't be triggered.
1811 TEST_F(GestureProviderTest
, GesturesCancelledAfterLongPressCausesLostFocus
) {
1812 base::TimeTicks event_time
= base::TimeTicks::Now();
1814 MockMotionEvent event
=
1815 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1816 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1818 const base::TimeDelta long_press_timeout
=
1819 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond
;
1820 RunTasksAndWait(long_press_timeout
);
1821 EXPECT_EQ(ET_GESTURE_LONG_PRESS
, GetMostRecentGestureEventType());
1822 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1824 EXPECT_TRUE(CancelActiveTouchSequence());
1825 EXPECT_FALSE(HasDownEvent());
1827 event
= ObtainMotionEvent(event_time
+ long_press_timeout
,
1828 MotionEvent::ACTION_UP
);
1829 gesture_provider_
->OnTouchEvent(event
);
1830 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP
));
1833 // Verify that inserting a touch cancel event will trigger proper touch and
1834 // gesture sequence cancellation.
1835 TEST_F(GestureProviderTest
, CancelActiveTouchSequence
) {
1836 base::TimeTicks event_time
= base::TimeTicks::Now();
1837 int motion_event_id
= 6;
1839 EXPECT_FALSE(CancelActiveTouchSequence());
1840 EXPECT_EQ(0U, GetReceivedGestureCount());
1842 MockMotionEvent event
=
1843 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
1844 event
.SetPrimaryPointerId(motion_event_id
);
1845 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1846 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1847 EXPECT_EQ(motion_event_id
, GetMostRecentGestureEvent().motion_event_id
);
1848 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1850 ASSERT_TRUE(CancelActiveTouchSequence());
1851 EXPECT_FALSE(HasDownEvent());
1853 // Subsequent MotionEvent's are dropped until ACTION_DOWN.
1854 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
,
1855 MotionEvent::ACTION_MOVE
);
1856 EXPECT_FALSE(gesture_provider_
->OnTouchEvent(event
));
1858 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 2,
1859 MotionEvent::ACTION_UP
);
1860 EXPECT_FALSE(gesture_provider_
->OnTouchEvent(event
));
1862 event
= ObtainMotionEvent(event_time
+ kOneMicrosecond
* 3,
1863 MotionEvent::ACTION_DOWN
);
1864 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1865 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1866 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1869 TEST_F(GestureProviderTest
, DoubleTapDragZoomCancelledOnSecondaryPointerDown
) {
1870 const base::TimeTicks down_time_1
= TimeTicks::Now();
1871 const base::TimeTicks down_time_2
= down_time_1
+ GetValidDoubleTapDelay();
1873 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
1875 MockMotionEvent event
=
1876 ObtainMotionEvent(down_time_1
, MotionEvent::ACTION_DOWN
);
1877 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1878 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1879 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1882 ObtainMotionEvent(down_time_1
+ kOneMicrosecond
, MotionEvent::ACTION_UP
);
1883 gesture_provider_
->OnTouchEvent(event
);
1884 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED
, GetMostRecentGestureEventType());
1885 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1887 event
= ObtainMotionEvent(down_time_2
, MotionEvent::ACTION_DOWN
);
1888 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1889 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1890 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1892 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
,
1893 MotionEvent::ACTION_MOVE
,
1896 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1897 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
1898 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN
, GetMostRecentGestureEventType());
1899 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1901 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 2,
1902 MotionEvent::ACTION_POINTER_DOWN
,
1907 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1908 EXPECT_EQ(ET_GESTURE_PINCH_END
, GetMostRecentGestureEventType());
1909 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1911 const size_t gesture_count
= GetReceivedGestureCount();
1912 event
= ObtainMotionEvent(down_time_2
+ kOneMicrosecond
* 3,
1913 MotionEvent::ACTION_POINTER_UP
,
1918 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1919 EXPECT_EQ(gesture_count
, GetReceivedGestureCount());
1921 event
= ObtainMotionEvent(down_time_2
+ kOneSecond
,
1922 MotionEvent::ACTION_UP
);
1923 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1924 EXPECT_EQ(gesture_count
+ 1, GetReceivedGestureCount());
1925 EXPECT_EQ(ET_GESTURE_SCROLL_END
, GetMostRecentGestureEventType());
1926 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1929 // Verify that gesture begin and gesture end events are dispatched correctly.
1930 TEST_F(GestureProviderTest
, GestureBeginAndEnd
) {
1931 EnableBeginEndTypes();
1932 base::TimeTicks event_time
= base::TimeTicks::Now();
1933 const float raw_offset_x
= 7.5f
;
1934 const float raw_offset_y
= 5.7f
;
1936 EXPECT_EQ(0U, GetReceivedGestureCount());
1937 MockMotionEvent event
=
1938 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
, 1, 1);
1939 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1940 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1941 EXPECT_EQ(ET_GESTURE_BEGIN
, GetReceivedGesture(0).type());
1942 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
1943 EXPECT_EQ(2U, GetReceivedGestureCount());
1944 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
1945 EXPECT_EQ(1, GetMostRecentGestureEvent().x
);
1946 EXPECT_EQ(1, GetMostRecentGestureEvent().y
);
1947 EXPECT_EQ(1 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
1948 EXPECT_EQ(1 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
1949 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius
, 1 - kMockTouchRadius
,
1950 kMockTouchRadius
* 2, kMockTouchRadius
* 2),
1951 GetMostRecentGestureEvent().details
.bounding_box_f());
1953 event
= ObtainMotionEvent(
1954 event_time
, MotionEvent::ACTION_POINTER_DOWN
, 1, 1, 2, 2);
1955 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1956 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1957 EXPECT_EQ(ET_GESTURE_BEGIN
, GetMostRecentGestureEventType());
1958 EXPECT_EQ(3U, GetReceivedGestureCount());
1959 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
1960 EXPECT_EQ(2, GetMostRecentGestureEvent().x
);
1961 EXPECT_EQ(2, GetMostRecentGestureEvent().y
);
1962 EXPECT_EQ(2 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
1963 EXPECT_EQ(2 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
1965 event
= ObtainMotionEvent(
1966 event_time
, MotionEvent::ACTION_POINTER_DOWN
, 1, 1, 2, 2, 3, 3);
1967 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1968 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1969 EXPECT_EQ(ET_GESTURE_BEGIN
, GetMostRecentGestureEventType());
1970 EXPECT_EQ(4U, GetReceivedGestureCount());
1971 EXPECT_EQ(3, GetMostRecentGestureEvent().details
.touch_points());
1972 EXPECT_EQ(3, GetMostRecentGestureEvent().x
);
1973 EXPECT_EQ(3, GetMostRecentGestureEvent().y
);
1974 EXPECT_EQ(3 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
1975 EXPECT_EQ(3 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
1977 event
= ObtainMotionEvent(
1978 event_time
, MotionEvent::ACTION_POINTER_UP
, 1, 1, 2, 2, 3, 3);
1979 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1980 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1981 EXPECT_EQ(ET_GESTURE_END
, GetMostRecentGestureEventType());
1982 EXPECT_EQ(5U, GetReceivedGestureCount());
1983 EXPECT_EQ(3, GetMostRecentGestureEvent().details
.touch_points());
1984 EXPECT_EQ(1, GetMostRecentGestureEvent().x
);
1985 EXPECT_EQ(1, GetMostRecentGestureEvent().y
);
1986 EXPECT_EQ(1 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
1987 EXPECT_EQ(1 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
1989 event
= ObtainMotionEvent(
1990 event_time
, MotionEvent::ACTION_POINTER_DOWN
, 2, 2, 3, 3, 4, 4);
1991 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
1992 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
1993 EXPECT_EQ(ET_GESTURE_BEGIN
, GetMostRecentGestureEventType());
1994 EXPECT_EQ(6U, GetReceivedGestureCount());
1995 EXPECT_EQ(3, GetMostRecentGestureEvent().details
.touch_points());
1996 EXPECT_EQ(4, GetMostRecentGestureEvent().x
);
1997 EXPECT_EQ(4, GetMostRecentGestureEvent().y
);
1998 EXPECT_EQ(4 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
1999 EXPECT_EQ(4 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
2001 event
= ObtainMotionEvent(
2002 event_time
, MotionEvent::ACTION_POINTER_UP
, 2, 2, 3, 3, 4, 4);
2003 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
2004 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2005 EXPECT_EQ(ET_GESTURE_END
, GetMostRecentGestureEventType());
2006 EXPECT_EQ(7U, GetReceivedGestureCount());
2007 EXPECT_EQ(3, GetMostRecentGestureEvent().details
.touch_points());
2008 EXPECT_EQ(2, GetMostRecentGestureEvent().x
);
2009 EXPECT_EQ(2, GetMostRecentGestureEvent().y
);
2010 EXPECT_EQ(2 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
2011 EXPECT_EQ(2 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
2014 ObtainMotionEvent(event_time
, MotionEvent::ACTION_POINTER_UP
, 3, 3, 4, 4);
2015 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
2016 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2017 EXPECT_EQ(ET_GESTURE_END
, GetMostRecentGestureEventType());
2018 EXPECT_EQ(8U, GetReceivedGestureCount());
2019 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
2020 EXPECT_EQ(3, GetMostRecentGestureEvent().x
);
2021 EXPECT_EQ(3, GetMostRecentGestureEvent().y
);
2022 EXPECT_EQ(3 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
2023 EXPECT_EQ(3 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
2026 event
= ObtainMotionEvent(event_time
, MotionEvent::ACTION_UP
, 4, 4);
2027 event
.SetRawOffset(raw_offset_x
, raw_offset_y
);
2028 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2029 EXPECT_EQ(ET_GESTURE_END
, GetMostRecentGestureEventType());
2030 EXPECT_EQ(9U, GetReceivedGestureCount());
2031 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2032 EXPECT_EQ(4, GetMostRecentGestureEvent().x
);
2033 EXPECT_EQ(4, GetMostRecentGestureEvent().y
);
2034 EXPECT_EQ(4 + raw_offset_x
, GetMostRecentGestureEvent().raw_x
);
2035 EXPECT_EQ(4 + raw_offset_y
, GetMostRecentGestureEvent().raw_y
);
2038 // Verify that gesture begin and gesture end events are dispatched correctly
2039 // when an ACTION_CANCEL is received.
2040 TEST_F(GestureProviderTest
, GestureBeginAndEndOnCancel
) {
2041 EnableBeginEndTypes();
2042 base::TimeTicks event_time
= base::TimeTicks::Now();
2044 EXPECT_EQ(0U, GetReceivedGestureCount());
2045 MockMotionEvent event
=
2046 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
, 1, 1);
2047 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2048 EXPECT_EQ(ET_GESTURE_BEGIN
, GetReceivedGesture(0).type());
2049 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2050 EXPECT_EQ(2U, GetReceivedGestureCount());
2051 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2052 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius
, 1 - kMockTouchRadius
,
2053 kMockTouchRadius
* 2, kMockTouchRadius
* 2),
2054 GetMostRecentGestureEvent().details
.bounding_box_f());
2055 EXPECT_EQ(1, GetMostRecentGestureEvent().x
);
2056 EXPECT_EQ(1, GetMostRecentGestureEvent().y
);
2058 event
= ObtainMotionEvent(
2059 event_time
, MotionEvent::ACTION_POINTER_DOWN
, 1, 1, 2, 2);
2060 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2061 EXPECT_EQ(ET_GESTURE_BEGIN
, GetMostRecentGestureEventType());
2062 EXPECT_EQ(3U, GetReceivedGestureCount());
2063 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
2064 EXPECT_EQ(2, GetMostRecentGestureEvent().x
);
2065 EXPECT_EQ(2, GetMostRecentGestureEvent().y
);
2067 event
= ObtainMotionEvent(
2068 event_time
, MotionEvent::ACTION_POINTER_DOWN
, 1, 1, 2, 2, 3, 3);
2069 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2070 EXPECT_EQ(ET_GESTURE_BEGIN
, GetMostRecentGestureEventType());
2071 EXPECT_EQ(4U, GetReceivedGestureCount());
2072 EXPECT_EQ(3, GetMostRecentGestureEvent().details
.touch_points());
2073 EXPECT_EQ(3, GetMostRecentGestureEvent().x
);
2074 EXPECT_EQ(3, GetMostRecentGestureEvent().y
);
2076 event
= ObtainMotionEvent(
2077 event_time
, MotionEvent::ACTION_CANCEL
, 1, 1, 2, 2, 3, 3);
2078 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2079 EXPECT_EQ(5U, GetReceivedGestureCount());
2080 EXPECT_EQ(3, GetReceivedGesture(4).details
.touch_points());
2081 EXPECT_EQ(ET_GESTURE_END
, GetReceivedGesture(4).type());
2082 EXPECT_EQ(1, GetMostRecentGestureEvent().x
);
2083 EXPECT_EQ(1, GetMostRecentGestureEvent().y
);
2085 event
= ObtainMotionEvent(
2086 event_time
, MotionEvent::ACTION_CANCEL
, 1, 1, 3, 3);
2087 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2088 EXPECT_EQ(6U, GetReceivedGestureCount());
2089 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
2090 EXPECT_EQ(ET_GESTURE_END
, GetMostRecentGestureEvent().type());
2091 EXPECT_EQ(1, GetMostRecentGestureEvent().x
);
2092 EXPECT_EQ(1, GetMostRecentGestureEvent().y
);
2094 event
= ObtainMotionEvent(
2095 event_time
, MotionEvent::ACTION_CANCEL
, 3, 3);
2096 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2097 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2098 EXPECT_EQ(ET_GESTURE_END
, GetMostRecentGestureEvent().type());
2099 EXPECT_EQ(3, GetMostRecentGestureEvent().x
);
2100 EXPECT_EQ(3, GetMostRecentGestureEvent().y
);
2103 // Test a simple two finger tap
2104 TEST_F(GestureProviderTest
, TwoFingerTap
) {
2105 // The time between ACTION_POINTER_DOWN and ACTION_POINTER_UP must be <= the
2106 // two finger tap delay.
2107 EnableTwoFingerTap(kMaxTwoFingerTapSeparation
, base::TimeDelta());
2108 const float scaled_touch_slop
= GetTouchSlop();
2110 base::TimeTicks event_time
= base::TimeTicks::Now();
2112 MockMotionEvent event
=
2113 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
, 0, 0);
2114 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2116 event
= ObtainMotionEvent(event_time
,
2117 MotionEvent::ACTION_MOVE
,
2119 scaled_touch_slop
/ 2);
2121 event
= ObtainMotionEvent(event_time
,
2122 MotionEvent::ACTION_POINTER_DOWN
,
2125 kMaxTwoFingerTapSeparation
/ 2,
2127 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2130 ObtainMotionEvent(event_time
,
2131 MotionEvent::ACTION_MOVE
,
2133 -scaled_touch_slop
/ 2,
2134 kMaxTwoFingerTapSeparation
/ 2 + scaled_touch_slop
/ 2,
2136 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2138 event
= ObtainMotionEvent(event_time
,
2139 MotionEvent::ACTION_POINTER_UP
,
2142 kMaxTwoFingerTapSeparation
,
2144 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2146 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetReceivedGesture(0).type());
2147 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN
, GetReceivedGesture(1).type());
2148 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetReceivedGesture(2).type());
2149 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP
, GetReceivedGesture(3).type());
2150 EXPECT_EQ(4U, GetReceivedGestureCount());
2152 EXPECT_EQ(kMockTouchRadius
* 2,
2153 GetReceivedGesture(3).details
.first_finger_width());
2154 EXPECT_EQ(kMockTouchRadius
* 2,
2155 GetReceivedGesture(3).details
.first_finger_height());
2158 // Test preventing a two finger tap via finger movement.
2159 TEST_F(GestureProviderTest
, TwoFingerTapCancelledByFingerMovement
) {
2160 EnableTwoFingerTap(kMaxTwoFingerTapSeparation
, base::TimeDelta());
2161 const float scaled_touch_slop
= GetTouchSlop();
2162 base::TimeTicks event_time
= base::TimeTicks::Now();
2164 MockMotionEvent event
= ObtainMotionEvent(
2165 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
2166 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2168 event
= ObtainMotionEvent(event_time
,
2169 MotionEvent::ACTION_POINTER_DOWN
,
2174 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2176 event
= ObtainMotionEvent(event_time
,
2177 MotionEvent::ACTION_MOVE
,
2180 kFakeCoordX
+ scaled_touch_slop
+ 0.1,
2182 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2184 event
= ObtainMotionEvent(event_time
,
2185 MotionEvent::ACTION_POINTER_UP
,
2190 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2192 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetReceivedGesture(0).type());
2193 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN
, GetReceivedGesture(1).type());
2194 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE
, GetReceivedGesture(2).type());
2195 EXPECT_FLOAT_EQ((scaled_touch_slop
+ 0.1) / 2,
2196 GetReceivedGesture(2).details
.scroll_x());
2197 EXPECT_EQ(0, GetReceivedGesture(2).details
.scroll_y());
2198 EXPECT_EQ(3U, GetReceivedGestureCount());
2201 // Test preventing a two finger tap by waiting too long before releasing the
2202 // secondary pointer.
2203 TEST_F(GestureProviderTest
, TwoFingerTapCancelledByDelay
) {
2204 base::TimeDelta two_finger_tap_timeout
= kOneSecond
;
2205 EnableTwoFingerTap(kMaxTwoFingerTapSeparation
, two_finger_tap_timeout
);
2206 base::TimeTicks event_time
= base::TimeTicks::Now();
2208 MockMotionEvent event
= ObtainMotionEvent(
2209 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
2210 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2212 event
= ObtainMotionEvent(event_time
,
2213 MotionEvent::ACTION_MOVE
,
2217 event
= ObtainMotionEvent(event_time
,
2218 MotionEvent::ACTION_POINTER_DOWN
,
2221 kFakeCoordX
+ kMaxTwoFingerTapSeparation
/ 2,
2223 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2225 event
= ObtainMotionEvent(event_time
+ kOneSecond
+ kOneMicrosecond
,
2226 MotionEvent::ACTION_POINTER_UP
,
2229 kFakeCoordX
+ kMaxTwoFingerTapSeparation
/ 2,
2231 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2233 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetReceivedGesture(0).type());
2234 EXPECT_EQ(1U, GetReceivedGestureCount());
2237 // Test preventing a two finger tap by pressing the secondary pointer too far
2239 TEST_F(GestureProviderTest
, TwoFingerTapCancelledByDistanceBetweenPointers
) {
2240 EnableTwoFingerTap(kMaxTwoFingerTapSeparation
, base::TimeDelta());
2241 base::TimeTicks event_time
= base::TimeTicks::Now();
2243 MockMotionEvent event
= ObtainMotionEvent(
2244 event_time
, MotionEvent::ACTION_DOWN
, kFakeCoordX
, kFakeCoordY
);
2245 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2247 event
= ObtainMotionEvent(event_time
,
2248 MotionEvent::ACTION_POINTER_DOWN
,
2251 kFakeCoordX
+ kMaxTwoFingerTapSeparation
,
2253 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2255 event
= ObtainMotionEvent(event_time
,
2256 MotionEvent::ACTION_POINTER_UP
,
2259 kFakeCoordX
+ kMaxTwoFingerTapSeparation
,
2261 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2263 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetReceivedGesture(0).type());
2264 EXPECT_EQ(1U, GetReceivedGestureCount());
2267 // Verify that pinch zoom only sends updates which exceed the
2268 // min_pinch_update_span_delta.
2269 TEST_F(GestureProviderTest
, PinchZoomWithThreshold
) {
2270 const float kMinPinchUpdateDistance
= 5;
2272 base::TimeTicks event_time
= base::TimeTicks::Now();
2273 const float touch_slop
= GetTouchSlop();
2275 SetMinPinchUpdateSpanDelta(kMinPinchUpdateDistance
);
2276 gesture_provider_
->SetDoubleTapSupportForPageEnabled(false);
2277 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(true);
2278 gesture_provider_
->SetMultiTouchZoomSupportEnabled(true);
2280 int secondary_coord_x
= kFakeCoordX
+ 20 * touch_slop
;
2281 int secondary_coord_y
= kFakeCoordY
+ 20 * touch_slop
;
2283 // First finger down.
2284 MockMotionEvent event
=
2285 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
2286 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2287 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2288 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2290 // Second finger down.
2291 event
= ObtainMotionEvent(event_time
,
2292 MotionEvent::ACTION_POINTER_DOWN
,
2298 gesture_provider_
->OnTouchEvent(event
);
2299 EXPECT_EQ(1U, GetReceivedGestureCount());
2300 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2302 // Move second finger.
2303 secondary_coord_x
+= 5 * touch_slop
;
2304 secondary_coord_y
+= 5 * touch_slop
;
2305 event
= ObtainMotionEvent(event_time
,
2306 MotionEvent::ACTION_MOVE
,
2312 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2313 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
2314 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN
));
2315 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE
));
2316 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN
));
2317 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE
));
2319 // Small move, shouldn't trigger pinch.
2320 event
= ObtainMotionEvent(event_time
,
2321 MotionEvent::ACTION_MOVE
,
2324 secondary_coord_x
+ kMinPinchUpdateDistance
,
2327 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2328 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE
));
2329 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
2331 // Small move, but combined with the previous move, should trigger pinch. We
2332 // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span
2333 // calculation factors in touch radius.
2334 const float kOvershootMinPinchUpdateDistance
= 3;
2335 event
= ObtainMotionEvent(event_time
,
2336 MotionEvent::ACTION_MOVE
,
2339 secondary_coord_x
+ kMinPinchUpdateDistance
+
2340 kOvershootMinPinchUpdateDistance
,
2343 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2344 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE
));
2345 EXPECT_EQ(2, GetMostRecentGestureEvent().details
.touch_points());
2348 // Verify that the min gesture bound setting is honored.
2349 TEST_F(GestureProviderTest
, MinGestureBoundsLength
) {
2350 const float kMinGestureBoundsLength
= 10.f
* kMockTouchRadius
;
2351 SetMinMaxGestureBoundsLength(kMinGestureBoundsLength
, 0.f
);
2352 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
2354 base::TimeTicks event_time
= base::TimeTicks::Now();
2355 MockMotionEvent event
=
2356 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
2357 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2359 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2360 EXPECT_EQ(kMinGestureBoundsLength
,
2361 GetMostRecentGestureEvent().details
.bounding_box_f().width());
2362 EXPECT_EQ(kMinGestureBoundsLength
,
2363 GetMostRecentGestureEvent().details
.bounding_box_f().height());
2366 ObtainMotionEvent(event_time
+ kOneMicrosecond
, MotionEvent::ACTION_UP
);
2367 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2368 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
2369 EXPECT_EQ(kMinGestureBoundsLength
,
2370 GetMostRecentGestureEvent().details
.bounding_box_f().width());
2371 EXPECT_EQ(kMinGestureBoundsLength
,
2372 GetMostRecentGestureEvent().details
.bounding_box_f().height());
2375 TEST_F(GestureProviderTest
, MaxGestureBoundsLength
) {
2376 const float kMaxGestureBoundsLength
= kMockTouchRadius
/ 10.f
;
2377 SetMinMaxGestureBoundsLength(0.f
, kMaxGestureBoundsLength
);
2378 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
2380 base::TimeTicks event_time
= base::TimeTicks::Now();
2381 MockMotionEvent event
=
2382 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
2383 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2385 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2386 EXPECT_EQ(kMaxGestureBoundsLength
,
2387 GetMostRecentGestureEvent().details
.bounding_box_f().width());
2388 EXPECT_EQ(kMaxGestureBoundsLength
,
2389 GetMostRecentGestureEvent().details
.bounding_box_f().height());
2392 ObtainMotionEvent(event_time
+ kOneMicrosecond
, MotionEvent::ACTION_UP
);
2393 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2394 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
2395 EXPECT_EQ(kMaxGestureBoundsLength
,
2396 GetMostRecentGestureEvent().details
.bounding_box_f().width());
2397 EXPECT_EQ(kMaxGestureBoundsLength
,
2398 GetMostRecentGestureEvent().details
.bounding_box_f().height());
2401 TEST_F(GestureProviderTest
, ZeroRadiusBoundingBox
) {
2402 base::TimeTicks event_time
= base::TimeTicks::Now();
2403 MockMotionEvent event
=
2404 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
, 10, 20);
2405 event
.SetTouchMajor(0);
2406 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2407 EXPECT_EQ(gfx::RectF(10, 20, 0, 0),
2408 GetMostRecentGestureEvent().details
.bounding_box_f());
2410 event
= ObtainMotionEvent(
2411 event_time
, MotionEvent::ACTION_POINTER_DOWN
, 10, 20, 110, 120);
2412 event
.SetTouchMajor(0);
2413 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2415 event
= ObtainMotionEvent(
2416 event_time
, MotionEvent::ACTION_MOVE
, 10, 20, 110, 150);
2417 event
.SetTouchMajor(0);
2418 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2420 EXPECT_EQ(gfx::RectF(10, 20, 100, 130),
2421 GetMostRecentGestureEvent().details
.bounding_box_f());
2424 // Verify that the min/max gesture bound settings are not applied to stylus
2425 // or mouse-derived MotionEvents.
2426 TEST_F(GestureProviderTest
, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse
) {
2427 const float kMinGestureBoundsLength
= 5.f
* kMockTouchRadius
;
2428 const float kMaxGestureBoundsLength
= 10.f
* kMockTouchRadius
;
2429 SetMinMaxGestureBoundsLength(kMinGestureBoundsLength
,
2430 kMaxGestureBoundsLength
);
2431 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
2433 base::TimeTicks event_time
= base::TimeTicks::Now();
2434 MockMotionEvent event
=
2435 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
2436 event
.SetTouchMajor(0);
2437 event
.SetToolType(0, MotionEvent::TOOL_TYPE_MOUSE
);
2438 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2440 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2441 EXPECT_EQ(MotionEvent::TOOL_TYPE_MOUSE
,
2442 GetMostRecentGestureEvent().primary_tool_type
);
2443 EXPECT_EQ(0.f
, GetMostRecentGestureEvent().details
.bounding_box_f().width());
2444 EXPECT_EQ(0.f
, GetMostRecentGestureEvent().details
.bounding_box_f().height());
2447 ObtainMotionEvent(event_time
+ kOneMicrosecond
, MotionEvent::ACTION_UP
);
2448 event
.SetTouchMajor(1);
2449 event
.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS
);
2450 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2451 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
2452 EXPECT_EQ(MotionEvent::TOOL_TYPE_STYLUS
,
2453 GetMostRecentGestureEvent().primary_tool_type
);
2454 EXPECT_EQ(0, GetMostRecentGestureEvent().details
.bounding_box_f().width());
2455 EXPECT_EQ(0, GetMostRecentGestureEvent().details
.bounding_box_f().height());
2457 event
= ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
);
2458 event
.SetTouchMajor(2.f
* kMaxGestureBoundsLength
);
2459 event
.SetToolType(0, MotionEvent::TOOL_TYPE_MOUSE
);
2460 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2461 EXPECT_EQ(MotionEvent::TOOL_TYPE_MOUSE
,
2462 GetMostRecentGestureEvent().primary_tool_type
);
2463 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2464 EXPECT_EQ(2.f
* kMaxGestureBoundsLength
,
2465 GetMostRecentGestureEvent().details
.bounding_box_f().width());
2466 EXPECT_EQ(2.f
* kMaxGestureBoundsLength
,
2467 GetMostRecentGestureEvent().details
.bounding_box_f().height());
2470 ObtainMotionEvent(event_time
+ kOneMicrosecond
, MotionEvent::ACTION_UP
);
2471 event
.SetTouchMajor(2.f
* kMaxGestureBoundsLength
);
2472 event
.SetToolType(0, MotionEvent::TOOL_TYPE_ERASER
);
2473 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2474 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
2475 EXPECT_EQ(MotionEvent::TOOL_TYPE_ERASER
,
2476 GetMostRecentGestureEvent().primary_tool_type
);
2477 EXPECT_EQ(2.f
* kMaxGestureBoundsLength
,
2478 GetMostRecentGestureEvent().details
.bounding_box_f().width());
2479 EXPECT_EQ(2.f
* kMaxGestureBoundsLength
,
2480 GetMostRecentGestureEvent().details
.bounding_box_f().height());
2483 // Test the bounding box for show press and tap gestures.
2484 TEST_F(GestureProviderTest
, BoundingBoxForShowPressAndTapGesture
) {
2485 base::TimeTicks event_time
= base::TimeTicks::Now();
2486 gesture_provider_
->SetDoubleTapSupportForPlatformEnabled(false);
2487 base::TimeDelta showpress_timeout
= kOneMicrosecond
;
2488 base::TimeDelta longpress_timeout
= kOneSecond
;
2489 SetShowPressAndLongPressTimeout(showpress_timeout
, longpress_timeout
);
2491 MockMotionEvent event
=
2492 ObtainMotionEvent(event_time
, MotionEvent::ACTION_DOWN
, 10, 10);
2493 event
.SetTouchMajor(10);
2495 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2496 EXPECT_EQ(ET_GESTURE_TAP_DOWN
, GetMostRecentGestureEventType());
2497 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2498 EXPECT_EQ(gfx::RectF(5, 5, 10, 10),
2499 GetMostRecentGestureEvent().details
.bounding_box_f());
2501 event
= ObtainMotionEvent(
2502 event_time
+ kOneMicrosecond
, MotionEvent::ACTION_MOVE
, 11, 9);
2503 event
.SetTouchMajor(20);
2504 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2505 event
= ObtainMotionEvent(
2506 event_time
+ kOneMicrosecond
, MotionEvent::ACTION_MOVE
, 8, 11);
2507 event
.SetTouchMajor(10);
2508 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2509 RunTasksAndWait(showpress_timeout
+ kOneMicrosecond
);
2510 EXPECT_EQ(ET_GESTURE_SHOW_PRESS
, GetMostRecentGestureEventType());
2511 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2512 GetMostRecentGestureEvent().details
.bounding_box_f());
2515 ObtainMotionEvent(event_time
+ kOneMicrosecond
, MotionEvent::ACTION_UP
);
2516 event
.SetTouchMajor(30);
2517 EXPECT_TRUE(gesture_provider_
->OnTouchEvent(event
));
2518 EXPECT_EQ(ET_GESTURE_TAP
, GetMostRecentGestureEventType());
2520 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.tap_count());
2521 EXPECT_EQ(1, GetMostRecentGestureEvent().details
.touch_points());
2522 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2523 GetMostRecentGestureEvent().details
.bounding_box_f());