base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_provider_unittest.cc
blob8f73a4a916b970806581194874949322420294d1
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;
22 namespace ui {
23 namespace {
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;
48 return sConfig;
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);
56 } // namespace
58 class GestureProviderTest : public testing::Test, public GestureProviderClient {
59 public:
60 GestureProviderTest() {}
61 ~GestureProviderTest() override {}
63 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
64 MotionEvent::Action action,
65 float x,
66 float y) {
67 return MockMotionEvent(action, event_time, x, y);
70 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
71 MotionEvent::Action action,
72 float x0,
73 float y0,
74 float x1,
75 float y1) {
76 return MockMotionEvent(action, event_time, x0, y0, x1, y1);
79 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
80 MotionEvent::Action action,
81 float x0,
82 float y0,
83 float x1,
84 float y1,
85 float x2,
86 float y2) {
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()) {
95 case 1:
96 return MockMotionEvent(
97 action, event_time, positions[0].x(), positions[0].y());
98 case 2:
99 return MockMotionEvent(action,
100 event_time,
101 positions[0].x(),
102 positions[0].y(),
103 positions[1].x(),
104 positions[1].y());
105 case 3:
106 return MockMotionEvent(action,
107 event_time,
108 positions[0].x(),
109 positions[0].y(),
110 positions[1].x(),
111 positions[1].y(),
112 positions[2].x(),
113 positions[2].y());
114 default:
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);
125 // Test
126 void SetUp() override { SetUpWithConfig(GetDefaultConfig()); }
128 void TearDown() override {
129 gestures_.clear();
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();
147 gestures_.clear();
150 bool CancelActiveTouchSequence() {
151 if (!gesture_provider_->current_down_event())
152 return false;
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)
160 return true;
162 return false;
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();
188 return sConfig;
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);
229 void EnableSwipe() {
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(); }
271 protected:
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 = 0;
278 int motion_event_flags = EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN;
280 MockMotionEvent event =
281 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
282 event.set_id(++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,
290 scroll_to_x,
291 scroll_to_y);
292 event.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER);
293 event.set_id(++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());
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.set_id(++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());
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,
346 float vy0,
347 float vx1,
348 float vy1,
349 float vx2,
350 float vy2) {
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,
379 event_positions);
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,
388 positions);
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,
395 positions);
396 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
398 event = ObtainMotionEvent(event_time + 2 * kDeltaTimeForFlingSequences,
399 MotionEvent::ACTION_POINTER_UP,
400 positions);
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 = 0;
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.set_id(++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());
439 event = ObtainMotionEvent(event_time + kOneMicrosecond,
440 MotionEvent::ACTION_UP);
441 event.SetToolType(0, MotionEvent::TOOL_TYPE_FINGER);
442 event.set_id(++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());
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 = 0;
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.set_id(++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());
480 event = ObtainMotionEvent(event_time + kOneMicrosecond,
481 MotionEvent::ACTION_UP);
482 event.set_id(++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());
495 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
496 RunTasksAndWait(GetDoubleTapTimeout());
497 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP));
500 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
501 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
502 base::TimeTicks event_time = TimeTicks::Now();
503 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
504 int motion_event_id = 0;
505 int motion_event_flags = EF_ALT_DOWN;
507 MockMotionEvent event =
508 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
509 event.set_id(++motion_event_id);
510 event.set_flags(motion_event_flags);
512 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
513 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
514 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
515 EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
516 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
518 event = ObtainMotionEvent(event_time + delta_time,
519 MotionEvent::ACTION_MOVE,
520 kFakeCoordX * 10,
521 kFakeCoordY * 10);
522 event.set_id(++motion_event_id);
523 event.set_flags(motion_event_flags);
524 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
526 event = ObtainMotionEvent(event_time + delta_time * 2,
527 MotionEvent::ACTION_UP,
528 kFakeCoordX * 10,
529 kFakeCoordY * 10);
530 event.set_id(++motion_event_id);
531 event.set_flags(motion_event_flags);
533 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
534 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
535 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
536 EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
537 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
538 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
539 EXPECT_EQ(
540 BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 10),
541 GetMostRecentGestureEvent().details.bounding_box());
544 // Verify that for a normal scroll the following events are sent:
545 // - ET_GESTURE_SCROLL_BEGIN
546 // - ET_GESTURE_SCROLL_UPDATE
547 // - ET_GESTURE_SCROLL_END
548 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
549 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP);
552 // Verify that for a cancelled scroll the following events are sent:
553 // - ET_GESTURE_SCROLL_BEGIN
554 // - ET_GESTURE_SCROLL_UPDATE
555 // - ET_GESTURE_SCROLL_END
556 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
557 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL);
560 // Verify that for a normal fling (fling after scroll) the following events are
561 // sent:
562 // - ET_GESTURE_SCROLL_BEGIN
563 // - ET_SCROLL_FLING_START
564 TEST_F(GestureProviderTest, FlingEventSequence) {
565 base::TimeTicks event_time = base::TimeTicks::Now();
566 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
567 int motion_event_id = 0;
569 MockMotionEvent event =
570 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
571 event.set_id(++motion_event_id);
573 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
575 event = ObtainMotionEvent(event_time + delta_time,
576 MotionEvent::ACTION_MOVE,
577 kFakeCoordX * 5,
578 kFakeCoordY * 5);
579 event.set_id(++motion_event_id);
581 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
582 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
583 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
584 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
585 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
586 ASSERT_EQ(3U, GetReceivedGestureCount());
587 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
588 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
590 // We don't want to take a dependency here on exactly how hints are calculated
591 // for a fling (eg. may depend on velocity), so just validate the direction.
592 int hint_x = GetReceivedGesture(1).details.scroll_x_hint();
593 int hint_y = GetReceivedGesture(1).details.scroll_y_hint();
594 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
595 << "ScrollBegin hint should be in positive X axis";
597 event = ObtainMotionEvent(event_time + delta_time * 2,
598 MotionEvent::ACTION_UP,
599 kFakeCoordX * 10,
600 kFakeCoordY * 10);
601 event.set_id(++motion_event_id);
603 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
604 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
605 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
606 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
607 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
608 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
609 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
610 << "FlingStart should have the time of the ACTION_UP";
613 TEST_F(GestureProviderTest, GestureCancelledOnCancelEvent) {
614 const base::TimeTicks event_time = TimeTicks::Now();
616 MockMotionEvent event =
617 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
618 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
619 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
621 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
622 kOneMicrosecond);
623 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
624 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
626 // A cancellation event may be triggered for a number of reasons, e.g.,
627 // from a context-menu-triggering long press resulting in loss of focus.
628 EXPECT_TRUE(CancelActiveTouchSequence());
629 EXPECT_FALSE(HasDownEvent());
631 // A final ACTION_UP should have no effect.
632 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
633 MotionEvent::ACTION_UP);
634 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
637 TEST_F(GestureProviderTest, GestureCancelledOnDetectionReset) {
638 const base::TimeTicks event_time = TimeTicks::Now();
640 MockMotionEvent event =
641 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
642 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
643 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
645 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
646 kOneMicrosecond);
647 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
648 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
650 ResetGestureDetection();
651 EXPECT_FALSE(HasDownEvent());
653 // A final ACTION_UP should have no effect.
654 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
655 MotionEvent::ACTION_UP);
656 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
659 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) {
660 base::TimeTicks event_time = base::TimeTicks::Now();
662 MockMotionEvent event =
663 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
665 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
667 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
668 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
669 event = ObtainMotionEvent(event_time + kOneMicrosecond,
670 MotionEvent::ACTION_MOVE,
671 kFakeCoordX + 50,
672 kFakeCoordY + 50);
673 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
674 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
676 event = ObtainMotionEvent(event_time + kOneSecond,
677 MotionEvent::ACTION_UP,
678 kFakeCoordX + 50,
679 kFakeCoordY + 50);
680 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
681 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
682 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
685 TEST_F(GestureProviderTest, DoubleTap) {
686 base::TimeTicks event_time = base::TimeTicks::Now();
688 MockMotionEvent event =
689 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
690 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
692 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
693 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
695 event = ObtainMotionEvent(event_time + kOneMicrosecond,
696 MotionEvent::ACTION_UP,
697 kFakeCoordX,
698 kFakeCoordY);
699 gesture_provider_->OnTouchEvent(event);
700 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
701 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
703 event_time += GetValidDoubleTapDelay();
704 event = ObtainMotionEvent(event_time,
705 MotionEvent::ACTION_DOWN,
706 kFakeCoordX,
707 kFakeCoordY);
708 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
709 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
710 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
712 // Moving a very small amount of distance should not trigger the double tap
713 // drag zoom mode.
714 event = ObtainMotionEvent(event_time + kOneMicrosecond,
715 MotionEvent::ACTION_MOVE,
716 kFakeCoordX,
717 kFakeCoordY + 1);
718 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
719 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
720 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
722 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
723 MotionEvent::ACTION_UP,
724 kFakeCoordX,
725 kFakeCoordY + 1);
726 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
728 const GestureEventData& double_tap = GetMostRecentGestureEvent();
729 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type());
730 // Ensure tap details have been set.
731 EXPECT_EQ(10, double_tap.details.bounding_box().width());
732 EXPECT_EQ(10, double_tap.details.bounding_box().height());
733 EXPECT_EQ(1, double_tap.details.tap_count());
736 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
737 const base::TimeTicks down_time_1 = TimeTicks::Now();
738 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
740 MockMotionEvent event =
741 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
742 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
744 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
745 MotionEvent::ACTION_UP,
746 kFakeCoordX,
747 kFakeCoordY);
748 gesture_provider_->OnTouchEvent(event);
749 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
750 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
752 event = ObtainMotionEvent(
753 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
754 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
755 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
756 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
758 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
759 MotionEvent::ACTION_MOVE,
760 kFakeCoordX,
761 kFakeCoordY + 100);
762 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
763 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
764 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
765 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
766 GetMostRecentGestureEvent().details.bounding_box());
768 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
769 MotionEvent::ACTION_MOVE,
770 kFakeCoordX,
771 kFakeCoordY + 200);
772 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
773 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
774 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
775 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 200),
776 GetMostRecentGestureEvent().details.bounding_box());
778 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
779 MotionEvent::ACTION_MOVE,
780 kFakeCoordX,
781 kFakeCoordY + 100);
782 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
783 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
784 EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale());
785 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
786 GetMostRecentGestureEvent().details.bounding_box());
788 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 4,
789 MotionEvent::ACTION_UP,
790 kFakeCoordX,
791 kFakeCoordY - 200);
792 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
793 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
794 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
795 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200),
796 GetMostRecentGestureEvent().details.bounding_box());
799 // Generate a scroll gesture and verify that the resulting scroll motion event
800 // has both absolute and relative position information.
801 TEST_F(GestureProviderTest, ScrollUpdateValues) {
802 const float delta_x = 16;
803 const float delta_y = 84;
804 const float raw_offset_x = 17.3f;
805 const float raw_offset_y = 13.7f;
807 const base::TimeTicks event_time = TimeTicks::Now();
809 MockMotionEvent event =
810 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
811 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
813 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
814 // compare the relative and absolute coordinates.
815 event = ObtainMotionEvent(event_time + kOneMicrosecond,
816 MotionEvent::ACTION_MOVE,
817 kFakeCoordX - delta_x / 2,
818 kFakeCoordY - delta_y / 2);
819 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
821 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
822 MotionEvent::ACTION_MOVE,
823 kFakeCoordX - delta_x,
824 kFakeCoordY - delta_y);
825 event.SetRawOffset(raw_offset_x, raw_offset_y);
826 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
828 // Make sure the reported gesture event has all the expected details.
829 ASSERT_LT(0U, GetReceivedGestureCount());
830 GestureEventData gesture = GetMostRecentGestureEvent();
831 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
832 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
833 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
834 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
835 EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x);
836 EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y);
837 EXPECT_EQ(1, gesture.details.touch_points());
839 // No horizontal delta because of snapping.
840 EXPECT_EQ(0, gesture.details.scroll_x());
841 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
844 // Verify that fractional scroll deltas are rounded as expected and that
845 // fractional scrolling doesn't break scroll snapping.
846 TEST_F(GestureProviderTest, FractionalScroll) {
847 const float delta_x = 0.4f;
848 const float delta_y = 5.2f;
850 const base::TimeTicks event_time = TimeTicks::Now();
852 MockMotionEvent event =
853 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
854 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
856 // Skip past the touch slop and move back.
857 event = ObtainMotionEvent(event_time,
858 MotionEvent::ACTION_MOVE,
859 kFakeCoordX,
860 kFakeCoordY + 100);
861 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
862 event = ObtainMotionEvent(event_time,
863 MotionEvent::ACTION_MOVE);
864 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
866 // Now move up slowly, mostly vertically but with a (fractional) bit of
867 // horizontal motion.
868 for(int i = 1; i <= 10; i++) {
869 event = ObtainMotionEvent(event_time + kOneMicrosecond * i,
870 MotionEvent::ACTION_MOVE,
871 kFakeCoordX + delta_x * i,
872 kFakeCoordY + delta_y * i);
873 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
875 ASSERT_LT(0U, GetReceivedGestureCount());
876 GestureEventData gesture = GetMostRecentGestureEvent();
877 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
878 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
879 EXPECT_EQ(1, gesture.details.touch_points());
881 // Verify that the event co-ordinates are still the precise values we
882 // supplied.
883 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
884 EXPECT_FLOAT_EQ(kFakeCoordY + delta_y * i, gesture.y);
886 // Verify that we're scrolling vertically by the expected amount
887 // (modulo rounding).
888 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y);
889 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1);
891 // And that there has been no horizontal motion at all.
892 EXPECT_EQ(0, gesture.details.scroll_x());
896 // Generate a scroll gesture and verify that the resulting scroll begin event
897 // has the expected hint values.
898 TEST_F(GestureProviderTest, ScrollBeginValues) {
899 const float delta_x = 13;
900 const float delta_y = 89;
902 const base::TimeTicks event_time = TimeTicks::Now();
904 MockMotionEvent event =
905 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
906 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
908 // Move twice such that the first event isn't sufficient to start
909 // scrolling on it's own.
910 event = ObtainMotionEvent(event_time + kOneMicrosecond,
911 MotionEvent::ACTION_MOVE,
912 kFakeCoordX + 2,
913 kFakeCoordY + 1);
914 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
915 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
917 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
918 MotionEvent::ACTION_MOVE,
919 kFakeCoordX + delta_x,
920 kFakeCoordY + delta_y);
921 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
922 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
924 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
925 ASSERT_TRUE(!!scroll_begin_gesture);
926 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint());
927 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint());
930 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
931 base::TimeTicks event_time = base::TimeTicks::Now();
933 MockMotionEvent event =
934 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
935 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
936 event = ObtainMotionEvent(event_time + kOneMicrosecond,
937 MotionEvent::ACTION_MOVE,
938 kFakeCoordX * 5,
939 kFakeCoordY * 5);
940 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
941 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
942 MotionEvent::ACTION_MOVE,
943 kFakeCoordX * 10,
944 kFakeCoordY * 10);
945 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
947 const base::TimeDelta long_press_timeout =
948 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
949 RunTasksAndWait(long_press_timeout);
951 // No LONG_TAP as the LONG_PRESS timer is cancelled.
952 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
953 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
956 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
957 TEST_F(GestureProviderTest, GestureLongTap) {
958 base::TimeTicks event_time = base::TimeTicks::Now();
960 MockMotionEvent event =
961 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
962 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
964 const base::TimeDelta long_press_timeout =
965 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
966 RunTasksAndWait(long_press_timeout);
968 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
969 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
970 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
971 GetMostRecentGestureEvent().details.bounding_box());
973 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP);
974 gesture_provider_->OnTouchEvent(event);
975 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType());
976 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
977 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
978 GetMostRecentGestureEvent().details.bounding_box());
981 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
982 base::TimeTicks event_time = base::TimeTicks::Now();
984 MockMotionEvent event =
985 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
986 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
988 const base::TimeDelta long_press_timeout =
989 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
990 RunTasksAndWait(long_press_timeout);
992 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
993 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
994 event = ObtainMotionEvent(event_time + long_press_timeout,
995 MotionEvent::ACTION_MOVE,
996 kFakeCoordX + 100,
997 kFakeCoordY + 100);
998 gesture_provider_->OnTouchEvent(event);
1000 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1001 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1002 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1004 event = ObtainMotionEvent(event_time + long_press_timeout,
1005 MotionEvent::ACTION_UP);
1006 gesture_provider_->OnTouchEvent(event);
1007 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
1010 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
1011 base::TimeTicks event_time = base::TimeTicks::Now();
1012 int motion_event_id = 0;
1014 MockMotionEvent event = ObtainMotionEvent(
1015 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1016 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1018 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1019 MotionEvent::ACTION_UP,
1020 kFakeCoordX,
1021 kFakeCoordY);
1022 gesture_provider_->OnTouchEvent(event);
1023 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1024 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1026 event_time += GetValidDoubleTapDelay();
1027 event = ObtainMotionEvent(event_time,
1028 MotionEvent::ACTION_DOWN,
1029 kFakeCoordX,
1030 kFakeCoordY);
1031 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1032 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1033 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1034 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
1036 const base::TimeDelta long_press_timeout =
1037 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1038 RunTasksAndWait(long_press_timeout);
1039 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
1041 event = ObtainMotionEvent(event_time + long_press_timeout,
1042 MotionEvent::ACTION_MOVE,
1043 kFakeCoordX + 20,
1044 kFakeCoordY + 20);
1045 event.set_id(++motion_event_id);
1047 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1048 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1049 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1050 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1051 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
1053 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
1054 MotionEvent::ACTION_UP,
1055 kFakeCoordX,
1056 kFakeCoordY + 1);
1057 event.set_id(++motion_event_id);
1058 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1059 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1060 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1061 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1062 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
1065 // Verify that the touch slop region is removed from the first scroll delta to
1066 // avoid a jump when starting to scroll.
1067 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
1068 const float touch_slop = GetTouchSlop();
1069 const float scroll_delta = 5;
1071 base::TimeTicks event_time = base::TimeTicks::Now();
1073 MockMotionEvent event =
1074 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1075 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1077 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1078 MotionEvent::ACTION_MOVE,
1079 kFakeCoordX,
1080 kFakeCoordY + touch_slop + scroll_delta);
1081 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1083 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1084 GestureEventData gesture = GetMostRecentGestureEvent();
1085 EXPECT_EQ(0, gesture.details.scroll_x());
1086 EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
1087 EXPECT_EQ(1, gesture.details.touch_points());
1090 // Verify that movement within the touch slop region does not generate a scroll,
1091 // and that the slop region is correct even when using fractional coordinates.
1092 TEST_F(GestureProviderTest, NoScrollWithinTouchSlop) {
1093 const float touch_slop = GetTouchSlop();
1094 const float scale_factor = 2.5f;
1095 const int touch_slop_pixels = static_cast<int>(scale_factor * touch_slop);
1097 base::TimeTicks event_time = base::TimeTicks::Now();
1099 MockMotionEvent event =
1100 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1101 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1103 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1104 MotionEvent::ACTION_MOVE,
1105 kFakeCoordX + touch_slop_pixels / scale_factor,
1106 kFakeCoordY);
1107 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1108 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1110 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1111 MotionEvent::ACTION_MOVE,
1112 kFakeCoordX,
1113 kFakeCoordY + touch_slop_pixels / scale_factor);
1114 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1115 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1117 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1118 MotionEvent::ACTION_MOVE,
1119 kFakeCoordX - touch_slop_pixels / scale_factor,
1120 kFakeCoordY);
1121 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1122 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1124 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1125 MotionEvent::ACTION_MOVE,
1126 kFakeCoordX,
1127 kFakeCoordY - touch_slop_pixels / scale_factor);
1128 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1129 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1131 event =
1132 ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1133 MotionEvent::ACTION_MOVE,
1134 kFakeCoordX,
1135 kFakeCoordY + (touch_slop_pixels + 1.f) / scale_factor);
1136 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1137 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1140 TEST_F(GestureProviderTest, NoDoubleTapWhenTooRapid) {
1141 base::TimeTicks event_time = base::TimeTicks::Now();
1143 MockMotionEvent event =
1144 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1145 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1147 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1148 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1150 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1151 MotionEvent::ACTION_UP,
1152 kFakeCoordX,
1153 kFakeCoordY);
1154 gesture_provider_->OnTouchEvent(event);
1155 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1156 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1158 // If the second tap follows the first in too short a time span, no double-tap
1159 // will occur.
1160 event_time += (GetDoubleTapMinTime() / 2);
1161 event = ObtainMotionEvent(event_time,
1162 MotionEvent::ACTION_DOWN,
1163 kFakeCoordX,
1164 kFakeCoordY);
1165 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1166 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1167 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1169 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1170 MotionEvent::ACTION_UP,
1171 kFakeCoordX,
1172 kFakeCoordY);
1173 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1174 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1177 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
1178 // Ensure that double-tap gestures can be disabled.
1179 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1181 base::TimeTicks event_time = base::TimeTicks::Now();
1182 MockMotionEvent event = ObtainMotionEvent(
1183 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1184 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1185 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1187 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1188 MotionEvent::ACTION_UP,
1189 kFakeCoordX,
1190 kFakeCoordY);
1191 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1192 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1194 event_time += GetValidDoubleTapDelay();
1195 event = ObtainMotionEvent(event_time,
1196 MotionEvent::ACTION_DOWN,
1197 kFakeCoordX,
1198 kFakeCoordY);
1199 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1200 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1202 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1203 MotionEvent::ACTION_UP,
1204 kFakeCoordX,
1205 kFakeCoordY);
1206 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1207 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1209 // Ensure that double-tap gestures can be interrupted.
1210 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1212 event_time = base::TimeTicks::Now();
1213 event = ObtainMotionEvent(
1214 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1215 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1216 EXPECT_EQ(5U, GetReceivedGestureCount());
1218 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1219 MotionEvent::ACTION_UP,
1220 kFakeCoordX,
1221 kFakeCoordY);
1222 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1223 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1225 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1226 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1228 // Ensure that double-tap gestures can be resumed.
1229 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1231 event_time += GetValidDoubleTapDelay();
1232 event = ObtainMotionEvent(event_time,
1233 MotionEvent::ACTION_DOWN,
1234 kFakeCoordX,
1235 kFakeCoordY);
1236 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1237 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1239 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1240 MotionEvent::ACTION_UP,
1241 kFakeCoordX,
1242 kFakeCoordY);
1243 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1244 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1246 event_time += GetValidDoubleTapDelay();
1247 event = ObtainMotionEvent(event_time,
1248 MotionEvent::ACTION_DOWN,
1249 kFakeCoordX,
1250 kFakeCoordY);
1251 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1252 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1254 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1255 MotionEvent::ACTION_UP,
1256 kFakeCoordX,
1257 kFakeCoordY);
1258 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1259 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
1262 TEST_F(GestureProviderTest, NoDelayedTapWhenDoubleTapSupportToggled) {
1263 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1265 base::TimeTicks event_time = base::TimeTicks::Now();
1266 MockMotionEvent event = ObtainMotionEvent(
1267 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1268 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1269 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1270 EXPECT_EQ(1U, GetReceivedGestureCount());
1272 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1273 MotionEvent::ACTION_UP,
1274 kFakeCoordX,
1275 kFakeCoordY);
1276 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1277 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1278 EXPECT_EQ(2U, GetReceivedGestureCount());
1280 // Disabling double-tap during the tap timeout should flush the delayed tap.
1281 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1282 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1283 EXPECT_EQ(3U, GetReceivedGestureCount());
1285 // No further timeout gestures should arrive.
1286 const base::TimeDelta long_press_timeout =
1287 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1288 RunTasksAndWait(long_press_timeout);
1289 EXPECT_EQ(3U, GetReceivedGestureCount());
1292 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
1293 const base::TimeTicks down_time_1 = TimeTicks::Now();
1294 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1296 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1298 MockMotionEvent event =
1299 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1300 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1302 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1303 MotionEvent::ACTION_UP,
1304 kFakeCoordX,
1305 kFakeCoordY);
1306 gesture_provider_->OnTouchEvent(event);
1308 event = ObtainMotionEvent(
1309 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1310 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1312 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1313 MotionEvent::ACTION_MOVE,
1314 kFakeCoordX,
1315 kFakeCoordY + 100);
1317 // The move should become a scroll, as doubletap drag zoom is disabled.
1318 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1319 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1320 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1322 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1323 MotionEvent::ACTION_MOVE,
1324 kFakeCoordX,
1325 kFakeCoordY + 200);
1326 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1327 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1328 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1329 EXPECT_EQ(down_time_2 + kOneMicrosecond * 2,
1330 GetMostRecentGestureEvent().time);
1331 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1333 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1334 MotionEvent::ACTION_UP,
1335 kFakeCoordX,
1336 kFakeCoordY + 200);
1337 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1338 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1341 // Verify that double tap drag zoom feature is not invoked when the gesture
1342 // handler is told to disable double tap gesture detection.
1343 // The second tap sequence should be treated just as the first would be.
1344 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) {
1345 const base::TimeTicks down_time_1 = TimeTicks::Now();
1346 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1348 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1350 MockMotionEvent event =
1351 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1352 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1354 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1355 MotionEvent::ACTION_UP,
1356 kFakeCoordX,
1357 kFakeCoordY);
1358 gesture_provider_->OnTouchEvent(event);
1360 event = ObtainMotionEvent(
1361 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1362 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1364 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1365 MotionEvent::ACTION_MOVE,
1366 kFakeCoordX,
1367 kFakeCoordY + 100);
1369 // The move should become a scroll, as double tap drag zoom is disabled.
1370 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1371 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1372 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1374 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1375 MotionEvent::ACTION_MOVE,
1376 kFakeCoordX,
1377 kFakeCoordY + 200);
1378 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1379 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1380 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1381 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1383 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1384 MotionEvent::ACTION_UP,
1385 kFakeCoordX,
1386 kFakeCoordY + 200);
1387 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1388 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1391 // Verify that updating double tap support during a double tap drag zoom
1392 // disables double tap detection after the gesture has ended.
1393 TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
1394 base::TimeTicks down_time_1 = TimeTicks::Now();
1395 base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1397 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1398 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1400 // Start a double-tap drag gesture.
1401 MockMotionEvent event =
1402 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1403 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1404 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1405 MotionEvent::ACTION_UP,
1406 kFakeCoordX,
1407 kFakeCoordY);
1408 gesture_provider_->OnTouchEvent(event);
1409 event = ObtainMotionEvent(
1410 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1411 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1412 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1413 MotionEvent::ACTION_MOVE,
1414 kFakeCoordX,
1415 kFakeCoordY + 100);
1416 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1417 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1418 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1419 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1421 // Simulate setting a fixed page scale (or a mobile viewport);
1422 // this should not disrupt the current double-tap gesture.
1423 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1425 // Double tap zoom updates should continue.
1426 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1427 MotionEvent::ACTION_MOVE,
1428 kFakeCoordX,
1429 kFakeCoordY + 200);
1430 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1431 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1432 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1433 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
1434 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1435 MotionEvent::ACTION_UP,
1436 kFakeCoordX,
1437 kFakeCoordY + 200);
1438 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1439 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1440 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1441 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1443 // The double-tap gesture has finished, but the page scale is fixed.
1444 // The same event sequence should not generate any double tap getsures.
1445 gestures_.clear();
1446 down_time_1 += kOneMicrosecond * 40;
1447 down_time_2 += kOneMicrosecond * 40;
1449 // Start a double-tap drag gesture.
1450 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1451 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1452 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1453 MotionEvent::ACTION_UP,
1454 kFakeCoordX,
1455 kFakeCoordY);
1456 gesture_provider_->OnTouchEvent(event);
1457 event = ObtainMotionEvent(
1458 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1459 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1460 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1461 MotionEvent::ACTION_MOVE,
1462 kFakeCoordX,
1463 kFakeCoordY + 100);
1464 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1465 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1466 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1468 // Double tap zoom updates should not be sent.
1469 // Instead, the second tap drag becomes a scroll gesture sequence.
1470 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1471 MotionEvent::ACTION_MOVE,
1472 kFakeCoordX,
1473 kFakeCoordY + 200);
1474 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1475 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1476 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1477 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1478 MotionEvent::ACTION_UP,
1479 kFakeCoordX,
1480 kFakeCoordY + 200);
1481 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1482 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1485 // Verify that pinch zoom sends the proper event sequence.
1486 TEST_F(GestureProviderTest, PinchZoom) {
1487 base::TimeTicks event_time = base::TimeTicks::Now();
1488 const float touch_slop = GetTouchSlop();
1489 const float raw_offset_x = 3.2f;
1490 const float raw_offset_y = 4.3f;
1491 int motion_event_id = 0;
1493 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1494 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1495 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1497 int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
1498 int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
1500 MockMotionEvent event =
1501 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1502 event.set_id(++motion_event_id);
1503 event.SetRawOffset(raw_offset_x, raw_offset_y);
1504 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1505 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1506 EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
1507 EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
1508 EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1509 EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1510 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1511 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
1512 GetMostRecentGestureEvent().details.bounding_box());
1514 // Toggling double-tap support should not take effect until the next sequence.
1515 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1517 event = ObtainMotionEvent(event_time,
1518 MotionEvent::ACTION_POINTER_DOWN,
1519 kFakeCoordX,
1520 kFakeCoordY,
1521 secondary_coord_x,
1522 secondary_coord_y);
1523 event.set_id(++motion_event_id);
1524 event.SetRawOffset(raw_offset_x, raw_offset_y);
1526 gesture_provider_->OnTouchEvent(event);
1527 EXPECT_EQ(1U, GetReceivedGestureCount());
1528 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1529 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
1530 GetMostRecentGestureEvent().details.bounding_box());
1532 secondary_coord_x += 5 * touch_slop;
1533 secondary_coord_y += 5 * touch_slop;
1534 event = ObtainMotionEvent(event_time,
1535 MotionEvent::ACTION_MOVE,
1536 kFakeCoordX,
1537 kFakeCoordY,
1538 secondary_coord_x,
1539 secondary_coord_y);
1540 event.set_id(++motion_event_id);
1541 event.SetRawOffset(raw_offset_x, raw_offset_y);
1543 // Toggling double-tap support should not take effect until the next sequence.
1544 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1546 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1547 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1548 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1549 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1550 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1551 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1553 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
1554 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
1555 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x,
1556 GetReceivedGesture(3).raw_x);
1557 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y,
1558 GetReceivedGesture(3).raw_y);
1560 EXPECT_EQ(
1561 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1562 kFakeCoordY - kMockTouchRadius,
1563 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1564 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1565 GetMostRecentGestureEvent().details.bounding_box());
1567 secondary_coord_x += 2 * touch_slop;
1568 secondary_coord_y += 2 * touch_slop;
1569 event = ObtainMotionEvent(event_time,
1570 MotionEvent::ACTION_MOVE,
1571 kFakeCoordX,
1572 kFakeCoordY,
1573 secondary_coord_x,
1574 secondary_coord_y);
1575 event.set_id(++motion_event_id);
1577 // Toggling double-tap support should not take effect until the next sequence.
1578 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1580 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1581 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1582 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1583 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1584 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1585 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
1586 EXPECT_EQ(
1587 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1588 kFakeCoordY - kMockTouchRadius,
1589 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1590 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1591 GetMostRecentGestureEvent().details.bounding_box());
1593 event = ObtainMotionEvent(event_time,
1594 MotionEvent::ACTION_POINTER_UP,
1595 kFakeCoordX,
1596 kFakeCoordY,
1597 secondary_coord_x,
1598 secondary_coord_y);
1599 event.set_id(++motion_event_id);
1601 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1602 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1603 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1604 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1605 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
1606 EXPECT_EQ(
1607 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1608 kFakeCoordY - kMockTouchRadius,
1609 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1610 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1611 GetMostRecentGestureEvent().details.bounding_box());
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());
1617 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
1618 kFakeCoordY - kMockTouchRadius,
1619 kMockTouchRadius * 2,
1620 kMockTouchRadius * 2),
1621 GetMostRecentGestureEvent().details.bounding_box());
1624 // Verify that no accidental pinching occurs if the touch size is large relative
1625 // to the min scaling span when the touch major value is used in scaling.
1626 TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) {
1627 base::TimeTicks event_time = base::TimeTicks::Now();
1628 const float kFatFingerSize = GetMinScalingSpan() * 3.f;
1630 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1631 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1633 MockMotionEvent event =
1634 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1635 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1636 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1637 EXPECT_EQ(1U, GetReceivedGestureCount());
1639 event = ObtainMotionEvent(event_time + kOneSecond,
1640 MotionEvent::ACTION_MOVE);
1641 event.SetTouchMajor(0.1f);
1642 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1643 EXPECT_EQ(1U, GetReceivedGestureCount());
1645 event = ObtainMotionEvent(event_time + kOneSecond * 2,
1646 MotionEvent::ACTION_MOVE,
1647 kFakeCoordX + 1.f,
1648 kFakeCoordY);
1649 event.SetTouchMajor(1.f);
1650 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1651 EXPECT_EQ(1U, GetReceivedGestureCount());
1653 event = ObtainMotionEvent(event_time + kOneSecond * 3,
1654 MotionEvent::ACTION_MOVE);
1655 event.SetTouchMajor(kFatFingerSize * 3.5f);
1656 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1657 EXPECT_EQ(1U, GetReceivedGestureCount());
1659 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1660 MotionEvent::ACTION_MOVE);
1661 event.SetTouchMajor(kFatFingerSize * 5.f);
1662 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1663 EXPECT_EQ(1U, GetReceivedGestureCount());
1665 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1666 MotionEvent::ACTION_MOVE,
1667 kFakeCoordX + 50.f,
1668 kFakeCoordY - 25.f);
1669 event.SetTouchMajor(kFatFingerSize * 10.f);
1670 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1671 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1673 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1674 MotionEvent::ACTION_MOVE,
1675 kFakeCoordX + 100.f,
1676 kFakeCoordY - 50.f);
1677 event.SetTouchMajor(kFatFingerSize * 5.f);
1678 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1679 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1682 // Verify that multi-finger swipe sends the proper event sequence.
1683 TEST_F(GestureProviderTest, MultiFingerSwipe) {
1684 EnableSwipe();
1685 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
1686 const float min_swipe_velocity = GetMinSwipeVelocity();
1688 // One finger - swipe right
1689 OneFingerSwipe(2 * min_swipe_velocity, 0);
1690 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1691 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1692 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1693 ResetGestureDetection();
1695 // One finger - swipe left
1696 OneFingerSwipe(-2 * min_swipe_velocity, 0);
1697 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1698 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1699 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1700 ResetGestureDetection();
1702 // One finger - swipe down
1703 OneFingerSwipe(0, 2 * min_swipe_velocity);
1704 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1705 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1706 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1707 ResetGestureDetection();
1709 // One finger - swipe up
1710 OneFingerSwipe(0, -2 * min_swipe_velocity);
1711 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1712 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1713 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1714 ResetGestureDetection();
1716 // Two fingers
1717 // Swipe right.
1718 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0);
1719 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1720 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1721 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1722 ResetGestureDetection();
1724 // Swipe left.
1725 TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
1726 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1727 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1728 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1729 ResetGestureDetection();
1731 // No swipe with different touch directions.
1732 TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
1733 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1734 ResetGestureDetection();
1736 // No swipe without a dominant direction.
1737 TwoFingerSwipe(min_swipe_velocity * 2,
1738 min_swipe_velocity * 2,
1739 min_swipe_velocity * 2,
1740 min_swipe_velocity * 2);
1741 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1742 ResetGestureDetection();
1744 // Swipe down with non-zero velocities on both axes and dominant direction.
1745 TwoFingerSwipe(-min_swipe_velocity,
1746 min_swipe_velocity * 4,
1747 -min_swipe_velocity,
1748 min_swipe_velocity * 4);
1749 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1750 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1751 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left());
1752 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1753 ResetGestureDetection();
1755 // Swipe up with non-zero velocities on both axes.
1756 TwoFingerSwipe(min_swipe_velocity,
1757 -min_swipe_velocity * 4,
1758 min_swipe_velocity,
1759 -min_swipe_velocity * 4);
1760 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1761 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1762 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1763 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1764 ResetGestureDetection();
1766 // No swipe without sufficient velocity.
1767 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0);
1768 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1769 ResetGestureDetection();
1771 // Swipe up with one small and one medium velocity in slightly different but
1772 // not opposing directions.
1773 TwoFingerSwipe(min_swipe_velocity / 2,
1774 min_swipe_velocity / 2,
1776 min_swipe_velocity * 2);
1777 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1778 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1779 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1780 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1781 ResetGestureDetection();
1783 // No swipe in orthogonal directions.
1784 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7);
1785 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1786 ResetGestureDetection();
1788 // Three finger swipe in same directions.
1789 ThreeFingerSwipe(min_swipe_velocity * 2,
1791 min_swipe_velocity * 3,
1793 min_swipe_velocity * 4,
1795 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1796 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1797 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1798 ResetGestureDetection();
1800 // No three finger swipe in different directions.
1801 ThreeFingerSwipe(min_swipe_velocity * 2,
1804 min_swipe_velocity * 3,
1805 min_swipe_velocity * 4,
1807 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1810 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1811 // so LONG_PRESS and LONG_TAP won't be triggered.
1812 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
1813 base::TimeTicks event_time = base::TimeTicks::Now();
1815 MockMotionEvent event =
1816 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1817 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1819 const base::TimeDelta long_press_timeout =
1820 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1821 RunTasksAndWait(long_press_timeout);
1822 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
1823 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1825 EXPECT_TRUE(CancelActiveTouchSequence());
1826 EXPECT_FALSE(HasDownEvent());
1828 event = ObtainMotionEvent(event_time + long_press_timeout,
1829 MotionEvent::ACTION_UP);
1830 gesture_provider_->OnTouchEvent(event);
1831 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
1834 // Verify that inserting a touch cancel event will trigger proper touch and
1835 // gesture sequence cancellation.
1836 TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
1837 base::TimeTicks event_time = base::TimeTicks::Now();
1838 int motion_event_id = 0;
1840 EXPECT_FALSE(CancelActiveTouchSequence());
1841 EXPECT_EQ(0U, GetReceivedGestureCount());
1843 MockMotionEvent event =
1844 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1845 event.set_id(++motion_event_id);
1846 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1847 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1848 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1849 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1851 ASSERT_TRUE(CancelActiveTouchSequence());
1852 EXPECT_FALSE(HasDownEvent());
1854 // Subsequent MotionEvent's are dropped until ACTION_DOWN.
1855 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1856 MotionEvent::ACTION_MOVE);
1857 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1859 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1860 MotionEvent::ACTION_UP);
1861 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1863 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
1864 MotionEvent::ACTION_DOWN);
1865 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1866 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1867 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1870 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
1871 const base::TimeTicks down_time_1 = TimeTicks::Now();
1872 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1874 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1876 MockMotionEvent event =
1877 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1878 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1879 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1880 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1882 event =
1883 ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::ACTION_UP);
1884 gesture_provider_->OnTouchEvent(event);
1885 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1886 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1888 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN);
1889 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1890 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1891 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1893 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1894 MotionEvent::ACTION_MOVE,
1895 kFakeCoordX,
1896 kFakeCoordY - 30);
1897 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1898 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1899 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1900 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1902 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1903 MotionEvent::ACTION_POINTER_DOWN,
1904 kFakeCoordX,
1905 kFakeCoordY - 30,
1906 kFakeCoordX + 50,
1907 kFakeCoordY + 50);
1908 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1909 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1910 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1912 const size_t gesture_count = GetReceivedGestureCount();
1913 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1914 MotionEvent::ACTION_POINTER_UP,
1915 kFakeCoordX,
1916 kFakeCoordY - 30,
1917 kFakeCoordX + 50,
1918 kFakeCoordY + 50);
1919 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1920 EXPECT_EQ(gesture_count, GetReceivedGestureCount());
1922 event = ObtainMotionEvent(down_time_2 + kOneSecond,
1923 MotionEvent::ACTION_UP);
1924 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1925 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount());
1926 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1927 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1930 // Verify that gesture begin and gesture end events are dispatched correctly.
1931 TEST_F(GestureProviderTest, GestureBeginAndEnd) {
1932 EnableBeginEndTypes();
1933 base::TimeTicks event_time = base::TimeTicks::Now();
1934 const float raw_offset_x = 7.5f;
1935 const float raw_offset_y = 5.7f;
1937 EXPECT_EQ(0U, GetReceivedGestureCount());
1938 MockMotionEvent event =
1939 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
1940 event.SetRawOffset(raw_offset_x, raw_offset_y);
1941 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1942 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
1943 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1944 EXPECT_EQ(2U, GetReceivedGestureCount());
1945 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1946 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1947 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1948 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1949 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1950 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
1951 1 - kMockTouchRadius,
1952 kMockTouchRadius * 2,
1953 kMockTouchRadius * 2),
1954 GetMostRecentGestureEvent().details.bounding_box());
1956 event = ObtainMotionEvent(
1957 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
1958 event.SetRawOffset(raw_offset_x, raw_offset_y);
1959 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1960 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1961 EXPECT_EQ(3U, GetReceivedGestureCount());
1962 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1963 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
1964 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
1965 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1966 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1968 event = ObtainMotionEvent(
1969 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
1970 event.SetRawOffset(raw_offset_x, raw_offset_y);
1971 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1972 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1973 EXPECT_EQ(4U, GetReceivedGestureCount());
1974 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1975 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
1976 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
1977 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1978 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1980 event = ObtainMotionEvent(
1981 event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3);
1982 event.SetRawOffset(raw_offset_x, raw_offset_y);
1983 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1984 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1985 EXPECT_EQ(5U, GetReceivedGestureCount());
1986 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1987 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1988 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1989 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1990 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1992 event = ObtainMotionEvent(
1993 event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4);
1994 event.SetRawOffset(raw_offset_x, raw_offset_y);
1995 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1996 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1997 EXPECT_EQ(6U, GetReceivedGestureCount());
1998 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1999 EXPECT_EQ(4, GetMostRecentGestureEvent().x);
2000 EXPECT_EQ(4, GetMostRecentGestureEvent().y);
2001 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2002 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2004 event = ObtainMotionEvent(
2005 event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4);
2006 event.SetRawOffset(raw_offset_x, raw_offset_y);
2007 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2008 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
2009 EXPECT_EQ(7U, GetReceivedGestureCount());
2010 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
2011 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
2012 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
2013 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2014 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2016 event =
2017 ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4);
2018 event.SetRawOffset(raw_offset_x, raw_offset_y);
2019 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2020 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
2021 EXPECT_EQ(8U, GetReceivedGestureCount());
2022 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2023 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
2024 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
2025 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2026 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2029 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4);
2030 event.SetRawOffset(raw_offset_x, raw_offset_y);
2031 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2032 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
2033 EXPECT_EQ(9U, GetReceivedGestureCount());
2034 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2035 EXPECT_EQ(4, GetMostRecentGestureEvent().x);
2036 EXPECT_EQ(4, GetMostRecentGestureEvent().y);
2037 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2038 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2041 // Verify that gesture begin and gesture end events are dispatched correctly
2042 // when an ACTION_CANCEL is received.
2043 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
2044 EnableBeginEndTypes();
2045 base::TimeTicks event_time = base::TimeTicks::Now();
2047 EXPECT_EQ(0U, GetReceivedGestureCount());
2048 MockMotionEvent event =
2049 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
2050 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2051 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
2052 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2053 EXPECT_EQ(2U, GetReceivedGestureCount());
2054 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2055 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
2056 1 - kMockTouchRadius,
2057 kMockTouchRadius * 2,
2058 kMockTouchRadius * 2),
2059 GetMostRecentGestureEvent().details.bounding_box());
2060 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
2061 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
2063 event = ObtainMotionEvent(
2064 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
2065 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2066 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
2067 EXPECT_EQ(3U, GetReceivedGestureCount());
2068 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2069 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
2070 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
2072 event = ObtainMotionEvent(
2073 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
2074 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2075 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
2076 EXPECT_EQ(4U, GetReceivedGestureCount());
2077 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
2078 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
2079 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
2081 event = ObtainMotionEvent(
2082 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 2, 2, 3, 3);
2083 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2084 EXPECT_EQ(5U, GetReceivedGestureCount());
2085 EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points());
2086 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).type());
2087 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
2088 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
2090 event = ObtainMotionEvent(
2091 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 3, 3);
2092 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2093 EXPECT_EQ(6U, GetReceivedGestureCount());
2094 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2095 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
2096 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
2097 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
2099 event = ObtainMotionEvent(
2100 event_time, MotionEvent::ACTION_CANCEL, 3, 3);
2101 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2102 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2103 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
2104 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
2105 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
2108 // Test a simple two finger tap
2109 TEST_F(GestureProviderTest, TwoFingerTap) {
2110 // The time between ACTION_POINTER_DOWN and ACTION_POINTER_UP must be <= the
2111 // two finger tap delay.
2112 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2113 const float scaled_touch_slop = GetTouchSlop();
2115 base::TimeTicks event_time = base::TimeTicks::Now();
2117 MockMotionEvent event =
2118 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0);
2119 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2121 event = ObtainMotionEvent(event_time,
2122 MotionEvent::ACTION_MOVE,
2124 scaled_touch_slop / 2);
2126 event = ObtainMotionEvent(event_time,
2127 MotionEvent::ACTION_POINTER_DOWN,
2130 kMaxTwoFingerTapSeparation / 2,
2132 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2134 event =
2135 ObtainMotionEvent(event_time,
2136 MotionEvent::ACTION_MOVE,
2138 -scaled_touch_slop / 2,
2139 kMaxTwoFingerTapSeparation / 2 + scaled_touch_slop / 2,
2141 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2143 event = ObtainMotionEvent(event_time,
2144 MotionEvent::ACTION_POINTER_UP,
2147 kMaxTwoFingerTapSeparation,
2149 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2151 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2152 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
2153 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(2).type());
2154 EXPECT_EQ(3U, GetReceivedGestureCount());
2156 EXPECT_EQ(kMockTouchRadius * 2,
2157 GetReceivedGesture(2).details.first_finger_width());
2158 EXPECT_EQ(kMockTouchRadius * 2,
2159 GetReceivedGesture(2).details.first_finger_height());
2162 // Test preventing a two finger tap via finger movement.
2163 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) {
2164 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2165 const float scaled_touch_slop = GetTouchSlop();
2166 base::TimeTicks event_time = base::TimeTicks::Now();
2168 MockMotionEvent event = ObtainMotionEvent(
2169 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
2170 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2172 event = ObtainMotionEvent(event_time,
2173 MotionEvent::ACTION_POINTER_DOWN,
2174 kFakeCoordX,
2175 kFakeCoordY,
2176 kFakeCoordX,
2177 kFakeCoordY);
2178 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2180 event = ObtainMotionEvent(event_time,
2181 MotionEvent::ACTION_MOVE,
2182 kFakeCoordX,
2183 kFakeCoordY,
2184 kFakeCoordX + scaled_touch_slop + 0.1,
2185 kFakeCoordY);
2186 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2188 event = ObtainMotionEvent(event_time,
2189 MotionEvent::ACTION_POINTER_UP,
2190 kFakeCoordX,
2191 kFakeCoordY,
2192 kFakeCoordX,
2193 kFakeCoordY);
2194 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2196 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2197 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
2198 EXPECT_EQ(2U, 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,
2214 kFakeCoordX,
2215 kFakeCoordY);
2217 event = ObtainMotionEvent(event_time,
2218 MotionEvent::ACTION_POINTER_DOWN,
2219 kFakeCoordX,
2220 kFakeCoordY,
2221 kFakeCoordX + kMaxTwoFingerTapSeparation / 2,
2222 kFakeCoordY);
2223 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2225 event = ObtainMotionEvent(event_time + kOneSecond + kOneMicrosecond,
2226 MotionEvent::ACTION_POINTER_UP,
2227 kFakeCoordX,
2228 kFakeCoordY,
2229 kFakeCoordX + kMaxTwoFingerTapSeparation / 2,
2230 kFakeCoordY);
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
2238 // from the first
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,
2249 kFakeCoordX,
2250 kFakeCoordY,
2251 kFakeCoordX + kMaxTwoFingerTapSeparation,
2252 kFakeCoordY);
2253 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2255 event = ObtainMotionEvent(event_time,
2256 MotionEvent::ACTION_POINTER_UP,
2257 kFakeCoordX,
2258 kFakeCoordY,
2259 kFakeCoordX + kMaxTwoFingerTapSeparation,
2260 kFakeCoordY);
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,
2293 kFakeCoordX,
2294 kFakeCoordY,
2295 secondary_coord_x,
2296 secondary_coord_y);
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,
2307 kFakeCoordX,
2308 kFakeCoordY,
2309 secondary_coord_x,
2310 secondary_coord_y);
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,
2322 kFakeCoordX,
2323 kFakeCoordY,
2324 secondary_coord_x + kMinPinchUpdateDistance,
2325 secondary_coord_y);
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,
2337 kFakeCoordX,
2338 kFakeCoordY,
2339 secondary_coord_x + kMinPinchUpdateDistance +
2340 kOvershootMinPinchUpdateDistance,
2341 secondary_coord_y);
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());
2365 event =
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());
2391 event =
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());
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());
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());
2446 event =
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());
2469 event =
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());
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());
2514 event =
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());
2526 } // namespace ui