Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_provider_unittest.cc
blob1f8d2d8182c005554a74f2c7e830e53bca017ad0
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());
494 EXPECT_EQ(event.GetEventTime(), GetMostRecentGestureEvent().time);
496 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
497 RunTasksAndWait(GetDoubleTapTimeout());
498 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP));
499 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
500 EXPECT_EQ(event.GetEventTime(), GetMostRecentGestureEvent().time);
503 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
504 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
505 base::TimeTicks event_time = TimeTicks::Now();
506 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
507 int motion_event_id = 0;
508 int motion_event_flags = EF_ALT_DOWN;
510 MockMotionEvent event =
511 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
512 event.set_id(++motion_event_id);
513 event.set_flags(motion_event_flags);
515 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
516 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
517 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
518 EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
519 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
521 event = ObtainMotionEvent(event_time + delta_time,
522 MotionEvent::ACTION_MOVE,
523 kFakeCoordX * 10,
524 kFakeCoordY * 10);
525 event.set_id(++motion_event_id);
526 event.set_flags(motion_event_flags);
527 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
529 event = ObtainMotionEvent(event_time + delta_time * 2,
530 MotionEvent::ACTION_UP,
531 kFakeCoordX * 10,
532 kFakeCoordY * 10);
533 event.set_id(++motion_event_id);
534 event.set_flags(motion_event_flags);
536 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
537 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
538 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
539 EXPECT_EQ(motion_event_flags, GetMostRecentGestureEvent().flags);
540 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
541 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
542 EXPECT_EQ(
543 BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 10),
544 GetMostRecentGestureEvent().details.bounding_box());
547 // Verify that for a normal scroll the following events are sent:
548 // - ET_GESTURE_SCROLL_BEGIN
549 // - ET_GESTURE_SCROLL_UPDATE
550 // - ET_GESTURE_SCROLL_END
551 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
552 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP);
555 // Verify that for a cancelled scroll the following events are sent:
556 // - ET_GESTURE_SCROLL_BEGIN
557 // - ET_GESTURE_SCROLL_UPDATE
558 // - ET_GESTURE_SCROLL_END
559 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
560 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL);
563 // Verify that for a normal fling (fling after scroll) the following events are
564 // sent:
565 // - ET_GESTURE_SCROLL_BEGIN
566 // - ET_SCROLL_FLING_START
567 TEST_F(GestureProviderTest, FlingEventSequence) {
568 base::TimeTicks event_time = base::TimeTicks::Now();
569 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
570 int motion_event_id = 0;
572 MockMotionEvent event =
573 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
574 event.set_id(++motion_event_id);
576 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
578 event = ObtainMotionEvent(event_time + delta_time,
579 MotionEvent::ACTION_MOVE,
580 kFakeCoordX * 5,
581 kFakeCoordY * 5);
582 event.set_id(++motion_event_id);
584 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
585 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
586 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
587 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
588 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
589 ASSERT_EQ(3U, GetReceivedGestureCount());
590 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
591 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
593 // We don't want to take a dependency here on exactly how hints are calculated
594 // for a fling (eg. may depend on velocity), so just validate the direction.
595 int hint_x = GetReceivedGesture(1).details.scroll_x_hint();
596 int hint_y = GetReceivedGesture(1).details.scroll_y_hint();
597 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
598 << "ScrollBegin hint should be in positive X axis";
600 event = ObtainMotionEvent(event_time + delta_time * 2,
601 MotionEvent::ACTION_UP,
602 kFakeCoordX * 10,
603 kFakeCoordY * 10);
604 event.set_id(++motion_event_id);
606 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
607 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
608 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
609 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
610 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
611 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
612 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
613 << "FlingStart should have the time of the ACTION_UP";
616 TEST_F(GestureProviderTest, GestureCancelledOnCancelEvent) {
617 const base::TimeTicks event_time = TimeTicks::Now();
619 MockMotionEvent event =
620 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
621 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
622 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
624 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
625 kOneMicrosecond);
626 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
627 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
629 // A cancellation event may be triggered for a number of reasons, e.g.,
630 // from a context-menu-triggering long press resulting in loss of focus.
631 EXPECT_TRUE(CancelActiveTouchSequence());
632 EXPECT_FALSE(HasDownEvent());
634 // A final ACTION_UP should have no effect.
635 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
636 MotionEvent::ACTION_UP);
637 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
640 TEST_F(GestureProviderTest, GestureCancelledOnDetectionReset) {
641 const base::TimeTicks event_time = TimeTicks::Now();
643 MockMotionEvent event =
644 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
645 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
646 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
648 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
649 kOneMicrosecond);
650 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
651 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
653 ResetGestureDetection();
654 EXPECT_FALSE(HasDownEvent());
656 // A final ACTION_UP should have no effect.
657 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
658 MotionEvent::ACTION_UP);
659 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
662 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) {
663 base::TimeTicks event_time = base::TimeTicks::Now();
665 MockMotionEvent event =
666 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
668 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
670 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
671 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
672 event = ObtainMotionEvent(event_time + kOneMicrosecond,
673 MotionEvent::ACTION_MOVE,
674 kFakeCoordX + 50,
675 kFakeCoordY + 50);
676 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
677 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
679 event = ObtainMotionEvent(event_time + kOneSecond,
680 MotionEvent::ACTION_UP,
681 kFakeCoordX + 50,
682 kFakeCoordY + 50);
683 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
684 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
685 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
688 TEST_F(GestureProviderTest, DoubleTap) {
689 base::TimeTicks event_time = base::TimeTicks::Now();
691 MockMotionEvent event =
692 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
693 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
695 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
696 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
698 event = ObtainMotionEvent(event_time + kOneMicrosecond,
699 MotionEvent::ACTION_UP,
700 kFakeCoordX,
701 kFakeCoordY);
702 gesture_provider_->OnTouchEvent(event);
703 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
704 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
706 event_time += GetValidDoubleTapDelay();
707 event = ObtainMotionEvent(event_time,
708 MotionEvent::ACTION_DOWN,
709 kFakeCoordX,
710 kFakeCoordY);
711 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
712 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
713 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
715 // Moving a very small amount of distance should not trigger the double tap
716 // drag zoom mode.
717 event = ObtainMotionEvent(event_time + kOneMicrosecond,
718 MotionEvent::ACTION_MOVE,
719 kFakeCoordX,
720 kFakeCoordY + 1);
721 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
722 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
723 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
725 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
726 MotionEvent::ACTION_UP,
727 kFakeCoordX,
728 kFakeCoordY + 1);
729 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
731 const GestureEventData& double_tap = GetMostRecentGestureEvent();
732 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type());
733 // Ensure tap details have been set.
734 EXPECT_EQ(10, double_tap.details.bounding_box().width());
735 EXPECT_EQ(10, double_tap.details.bounding_box().height());
736 EXPECT_EQ(1, double_tap.details.tap_count());
739 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
740 const base::TimeTicks down_time_1 = TimeTicks::Now();
741 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
743 MockMotionEvent event =
744 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
745 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
747 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
748 MotionEvent::ACTION_UP,
749 kFakeCoordX,
750 kFakeCoordY);
751 gesture_provider_->OnTouchEvent(event);
752 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
753 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
755 event = ObtainMotionEvent(
756 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
757 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
758 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
759 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
761 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
762 MotionEvent::ACTION_MOVE,
763 kFakeCoordX,
764 kFakeCoordY + 100);
765 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
766 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
767 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
768 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
769 GetMostRecentGestureEvent().details.bounding_box());
771 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
772 MotionEvent::ACTION_MOVE,
773 kFakeCoordX,
774 kFakeCoordY + 200);
775 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
776 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
777 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
778 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 200),
779 GetMostRecentGestureEvent().details.bounding_box());
781 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
782 MotionEvent::ACTION_MOVE,
783 kFakeCoordX,
784 kFakeCoordY + 100);
785 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
786 ASSERT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
787 EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale());
788 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY + 100),
789 GetMostRecentGestureEvent().details.bounding_box());
791 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 4,
792 MotionEvent::ACTION_UP,
793 kFakeCoordX,
794 kFakeCoordY - 200);
795 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
796 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
797 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
798 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY - 200),
799 GetMostRecentGestureEvent().details.bounding_box());
802 // Generate a scroll gesture and verify that the resulting scroll motion event
803 // has both absolute and relative position information.
804 TEST_F(GestureProviderTest, ScrollUpdateValues) {
805 const float delta_x = 16;
806 const float delta_y = 84;
807 const float raw_offset_x = 17.3f;
808 const float raw_offset_y = 13.7f;
810 const base::TimeTicks event_time = TimeTicks::Now();
812 MockMotionEvent event =
813 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
814 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
816 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
817 // compare the relative and absolute coordinates.
818 event = ObtainMotionEvent(event_time + kOneMicrosecond,
819 MotionEvent::ACTION_MOVE,
820 kFakeCoordX - delta_x / 2,
821 kFakeCoordY - delta_y / 2);
822 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
824 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
825 MotionEvent::ACTION_MOVE,
826 kFakeCoordX - delta_x,
827 kFakeCoordY - delta_y);
828 event.SetRawOffset(raw_offset_x, raw_offset_y);
829 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
831 // Make sure the reported gesture event has all the expected details.
832 ASSERT_LT(0U, GetReceivedGestureCount());
833 GestureEventData gesture = GetMostRecentGestureEvent();
834 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
835 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
836 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
837 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
838 EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x);
839 EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y);
840 EXPECT_EQ(1, gesture.details.touch_points());
842 // No horizontal delta because of snapping.
843 EXPECT_EQ(0, gesture.details.scroll_x());
844 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
847 // Verify that fractional scroll deltas are rounded as expected and that
848 // fractional scrolling doesn't break scroll snapping.
849 TEST_F(GestureProviderTest, FractionalScroll) {
850 const float delta_x = 0.4f;
851 const float delta_y = 5.2f;
853 const base::TimeTicks event_time = TimeTicks::Now();
855 MockMotionEvent event =
856 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
857 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
859 // Skip past the touch slop and move back.
860 event = ObtainMotionEvent(event_time,
861 MotionEvent::ACTION_MOVE,
862 kFakeCoordX,
863 kFakeCoordY + 100);
864 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
865 event = ObtainMotionEvent(event_time,
866 MotionEvent::ACTION_MOVE);
867 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
869 // Now move up slowly, mostly vertically but with a (fractional) bit of
870 // horizontal motion.
871 for(int i = 1; i <= 10; i++) {
872 event = ObtainMotionEvent(event_time + kOneMicrosecond * i,
873 MotionEvent::ACTION_MOVE,
874 kFakeCoordX + delta_x * i,
875 kFakeCoordY + delta_y * i);
876 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
878 ASSERT_LT(0U, GetReceivedGestureCount());
879 GestureEventData gesture = GetMostRecentGestureEvent();
880 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
881 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
882 EXPECT_EQ(1, gesture.details.touch_points());
884 // Verify that the event co-ordinates are still the precise values we
885 // supplied.
886 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
887 EXPECT_FLOAT_EQ(kFakeCoordY + delta_y * i, gesture.y);
889 // Verify that we're scrolling vertically by the expected amount
890 // (modulo rounding).
891 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y);
892 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1);
894 // And that there has been no horizontal motion at all.
895 EXPECT_EQ(0, gesture.details.scroll_x());
899 // Generate a scroll gesture and verify that the resulting scroll begin event
900 // has the expected hint values.
901 TEST_F(GestureProviderTest, ScrollBeginValues) {
902 const float delta_x = 13;
903 const float delta_y = 89;
905 const base::TimeTicks event_time = TimeTicks::Now();
907 MockMotionEvent event =
908 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
909 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
911 // Move twice such that the first event isn't sufficient to start
912 // scrolling on it's own.
913 event = ObtainMotionEvent(event_time + kOneMicrosecond,
914 MotionEvent::ACTION_MOVE,
915 kFakeCoordX + 2,
916 kFakeCoordY + 1);
917 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
918 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
920 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
921 MotionEvent::ACTION_MOVE,
922 kFakeCoordX + delta_x,
923 kFakeCoordY + delta_y);
924 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
925 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
927 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
928 ASSERT_TRUE(!!scroll_begin_gesture);
929 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint());
930 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint());
933 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
934 base::TimeTicks event_time = base::TimeTicks::Now();
936 MockMotionEvent event =
937 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
938 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
939 event = ObtainMotionEvent(event_time + kOneMicrosecond,
940 MotionEvent::ACTION_MOVE,
941 kFakeCoordX * 5,
942 kFakeCoordY * 5);
943 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
944 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
945 MotionEvent::ACTION_MOVE,
946 kFakeCoordX * 10,
947 kFakeCoordY * 10);
948 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
950 const base::TimeDelta long_press_timeout =
951 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
952 RunTasksAndWait(long_press_timeout);
954 // No LONG_TAP as the LONG_PRESS timer is cancelled.
955 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
956 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
959 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
960 TEST_F(GestureProviderTest, GestureLongTap) {
961 base::TimeTicks event_time = base::TimeTicks::Now();
963 MockMotionEvent event =
964 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
965 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
967 const base::TimeDelta long_press_timeout =
968 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
969 RunTasksAndWait(long_press_timeout);
971 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
972 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
973 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
974 GetMostRecentGestureEvent().details.bounding_box());
976 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP);
977 gesture_provider_->OnTouchEvent(event);
978 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType());
979 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
980 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
981 GetMostRecentGestureEvent().details.bounding_box());
984 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
985 base::TimeTicks event_time = base::TimeTicks::Now();
987 MockMotionEvent event =
988 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
989 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
991 const base::TimeDelta long_press_timeout =
992 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
993 RunTasksAndWait(long_press_timeout);
995 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
996 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
997 event = ObtainMotionEvent(event_time + long_press_timeout,
998 MotionEvent::ACTION_MOVE,
999 kFakeCoordX + 100,
1000 kFakeCoordY + 100);
1001 gesture_provider_->OnTouchEvent(event);
1003 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1004 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1005 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1007 event = ObtainMotionEvent(event_time + long_press_timeout,
1008 MotionEvent::ACTION_UP);
1009 gesture_provider_->OnTouchEvent(event);
1010 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
1013 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
1014 base::TimeTicks event_time = base::TimeTicks::Now();
1015 int motion_event_id = 0;
1017 MockMotionEvent event = ObtainMotionEvent(
1018 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1019 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1021 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1022 MotionEvent::ACTION_UP,
1023 kFakeCoordX,
1024 kFakeCoordY);
1025 gesture_provider_->OnTouchEvent(event);
1026 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1027 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1029 event_time += GetValidDoubleTapDelay();
1030 event = ObtainMotionEvent(event_time,
1031 MotionEvent::ACTION_DOWN,
1032 kFakeCoordX,
1033 kFakeCoordY);
1034 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1035 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1036 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1037 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
1039 const base::TimeDelta long_press_timeout =
1040 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1041 RunTasksAndWait(long_press_timeout);
1042 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
1044 event = ObtainMotionEvent(event_time + long_press_timeout,
1045 MotionEvent::ACTION_MOVE,
1046 kFakeCoordX + 20,
1047 kFakeCoordY + 20);
1048 event.set_id(++motion_event_id);
1050 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1051 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1052 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1053 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1054 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
1056 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
1057 MotionEvent::ACTION_UP,
1058 kFakeCoordX,
1059 kFakeCoordY + 1);
1060 event.set_id(++motion_event_id);
1061 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1062 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1063 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1064 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1065 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
1068 // Verify that the touch slop region is removed from the first scroll delta to
1069 // avoid a jump when starting to scroll.
1070 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
1071 const float touch_slop = GetTouchSlop();
1072 const float scroll_delta = 5;
1074 base::TimeTicks event_time = base::TimeTicks::Now();
1076 MockMotionEvent event =
1077 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1078 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1080 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1081 MotionEvent::ACTION_MOVE,
1082 kFakeCoordX,
1083 kFakeCoordY + touch_slop + scroll_delta);
1084 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1086 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1087 GestureEventData gesture = GetMostRecentGestureEvent();
1088 EXPECT_EQ(0, gesture.details.scroll_x());
1089 EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
1090 EXPECT_EQ(1, gesture.details.touch_points());
1093 // Verify that movement within the touch slop region does not generate a scroll,
1094 // and that the slop region is correct even when using fractional coordinates.
1095 TEST_F(GestureProviderTest, NoScrollWithinTouchSlop) {
1096 const float touch_slop = GetTouchSlop();
1097 const float scale_factor = 2.5f;
1098 const int touch_slop_pixels = static_cast<int>(scale_factor * touch_slop);
1100 base::TimeTicks event_time = base::TimeTicks::Now();
1102 MockMotionEvent event =
1103 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1104 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1106 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1107 MotionEvent::ACTION_MOVE,
1108 kFakeCoordX + touch_slop_pixels / scale_factor,
1109 kFakeCoordY);
1110 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1111 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1113 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1114 MotionEvent::ACTION_MOVE,
1115 kFakeCoordX,
1116 kFakeCoordY + touch_slop_pixels / scale_factor);
1117 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1118 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1120 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1121 MotionEvent::ACTION_MOVE,
1122 kFakeCoordX - touch_slop_pixels / scale_factor,
1123 kFakeCoordY);
1124 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1125 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1127 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1128 MotionEvent::ACTION_MOVE,
1129 kFakeCoordX,
1130 kFakeCoordY - touch_slop_pixels / scale_factor);
1131 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1132 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1134 event =
1135 ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1136 MotionEvent::ACTION_MOVE,
1137 kFakeCoordX,
1138 kFakeCoordY + (touch_slop_pixels + 1.f) / scale_factor);
1139 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1140 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1143 TEST_F(GestureProviderTest, NoDoubleTapWhenTooRapid) {
1144 base::TimeTicks event_time = base::TimeTicks::Now();
1146 MockMotionEvent event =
1147 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1148 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1150 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1151 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1153 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1154 MotionEvent::ACTION_UP,
1155 kFakeCoordX,
1156 kFakeCoordY);
1157 gesture_provider_->OnTouchEvent(event);
1158 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1159 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1161 // If the second tap follows the first in too short a time span, no double-tap
1162 // will occur.
1163 event_time += (GetDoubleTapMinTime() / 2);
1164 event = ObtainMotionEvent(event_time,
1165 MotionEvent::ACTION_DOWN,
1166 kFakeCoordX,
1167 kFakeCoordY);
1168 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1169 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1170 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1172 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1173 MotionEvent::ACTION_UP,
1174 kFakeCoordX,
1175 kFakeCoordY);
1176 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1177 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1180 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
1181 // Ensure that double-tap gestures can be disabled.
1182 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1184 base::TimeTicks event_time = base::TimeTicks::Now();
1185 MockMotionEvent event = ObtainMotionEvent(
1186 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1187 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1188 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1190 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1191 MotionEvent::ACTION_UP,
1192 kFakeCoordX,
1193 kFakeCoordY);
1194 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1195 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1197 event_time += GetValidDoubleTapDelay();
1198 event = ObtainMotionEvent(event_time,
1199 MotionEvent::ACTION_DOWN,
1200 kFakeCoordX,
1201 kFakeCoordY);
1202 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1203 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1205 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1206 MotionEvent::ACTION_UP,
1207 kFakeCoordX,
1208 kFakeCoordY);
1209 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1210 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1212 // Ensure that double-tap gestures can be interrupted.
1213 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1215 event_time = base::TimeTicks::Now();
1216 event = ObtainMotionEvent(
1217 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1218 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1219 EXPECT_EQ(5U, GetReceivedGestureCount());
1221 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1222 MotionEvent::ACTION_UP,
1223 kFakeCoordX,
1224 kFakeCoordY);
1225 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1226 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1228 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1229 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1231 // Ensure that double-tap gestures can be resumed.
1232 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1234 event_time += GetValidDoubleTapDelay();
1235 event = ObtainMotionEvent(event_time,
1236 MotionEvent::ACTION_DOWN,
1237 kFakeCoordX,
1238 kFakeCoordY);
1239 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1240 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1242 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1243 MotionEvent::ACTION_UP,
1244 kFakeCoordX,
1245 kFakeCoordY);
1246 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1247 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1249 event_time += GetValidDoubleTapDelay();
1250 event = ObtainMotionEvent(event_time,
1251 MotionEvent::ACTION_DOWN,
1252 kFakeCoordX,
1253 kFakeCoordY);
1254 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1255 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1257 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1258 MotionEvent::ACTION_UP,
1259 kFakeCoordX,
1260 kFakeCoordY);
1261 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1262 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
1265 TEST_F(GestureProviderTest, NoDelayedTapWhenDoubleTapSupportToggled) {
1266 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1268 base::TimeTicks event_time = base::TimeTicks::Now();
1269 MockMotionEvent event = ObtainMotionEvent(
1270 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1271 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1272 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1273 EXPECT_EQ(1U, GetReceivedGestureCount());
1275 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1276 MotionEvent::ACTION_UP,
1277 kFakeCoordX,
1278 kFakeCoordY);
1279 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1280 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1281 EXPECT_EQ(2U, GetReceivedGestureCount());
1283 // Disabling double-tap during the tap timeout should flush the delayed tap.
1284 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1285 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
1286 EXPECT_EQ(3U, GetReceivedGestureCount());
1288 // No further timeout gestures should arrive.
1289 const base::TimeDelta long_press_timeout =
1290 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1291 RunTasksAndWait(long_press_timeout);
1292 EXPECT_EQ(3U, GetReceivedGestureCount());
1295 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
1296 const base::TimeTicks down_time_1 = TimeTicks::Now();
1297 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1299 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1301 MockMotionEvent event =
1302 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1303 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1305 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1306 MotionEvent::ACTION_UP,
1307 kFakeCoordX,
1308 kFakeCoordY);
1309 gesture_provider_->OnTouchEvent(event);
1311 event = ObtainMotionEvent(
1312 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1313 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1315 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1316 MotionEvent::ACTION_MOVE,
1317 kFakeCoordX,
1318 kFakeCoordY + 100);
1320 // The move should become a scroll, as doubletap drag zoom is disabled.
1321 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1322 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1323 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1325 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1326 MotionEvent::ACTION_MOVE,
1327 kFakeCoordX,
1328 kFakeCoordY + 200);
1329 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1330 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1331 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1332 EXPECT_EQ(down_time_2 + kOneMicrosecond * 2,
1333 GetMostRecentGestureEvent().time);
1334 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1336 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1337 MotionEvent::ACTION_UP,
1338 kFakeCoordX,
1339 kFakeCoordY + 200);
1340 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1341 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1344 // Verify that double tap drag zoom feature is not invoked when the gesture
1345 // handler is told to disable double tap gesture detection.
1346 // The second tap sequence should be treated just as the first would be.
1347 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) {
1348 const base::TimeTicks down_time_1 = TimeTicks::Now();
1349 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1351 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1353 MockMotionEvent event =
1354 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1355 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1357 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1358 MotionEvent::ACTION_UP,
1359 kFakeCoordX,
1360 kFakeCoordY);
1361 gesture_provider_->OnTouchEvent(event);
1363 event = ObtainMotionEvent(
1364 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1365 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1367 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1368 MotionEvent::ACTION_MOVE,
1369 kFakeCoordX,
1370 kFakeCoordY + 100);
1372 // The move should become a scroll, as double tap drag zoom is disabled.
1373 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1374 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1375 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1377 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1378 MotionEvent::ACTION_MOVE,
1379 kFakeCoordX,
1380 kFakeCoordY + 200);
1381 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1382 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
1383 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1384 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1386 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1387 MotionEvent::ACTION_UP,
1388 kFakeCoordX,
1389 kFakeCoordY + 200);
1390 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1391 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1394 // Verify that updating double tap support during a double tap drag zoom
1395 // disables double tap detection after the gesture has ended.
1396 TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
1397 base::TimeTicks down_time_1 = TimeTicks::Now();
1398 base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1400 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1401 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1403 // Start a double-tap drag gesture.
1404 MockMotionEvent event =
1405 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1406 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1407 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1408 MotionEvent::ACTION_UP,
1409 kFakeCoordX,
1410 kFakeCoordY);
1411 gesture_provider_->OnTouchEvent(event);
1412 event = ObtainMotionEvent(
1413 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1414 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1415 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1416 MotionEvent::ACTION_MOVE,
1417 kFakeCoordX,
1418 kFakeCoordY + 100);
1419 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1420 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1421 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1422 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1424 // Simulate setting a fixed page scale (or a mobile viewport);
1425 // this should not disrupt the current double-tap gesture.
1426 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1428 // Double tap zoom updates should continue.
1429 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1430 MotionEvent::ACTION_MOVE,
1431 kFakeCoordX,
1432 kFakeCoordY + 200);
1433 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1434 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1435 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1436 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
1437 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1438 MotionEvent::ACTION_UP,
1439 kFakeCoordX,
1440 kFakeCoordY + 200);
1441 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1442 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1443 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1444 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1446 // The double-tap gesture has finished, but the page scale is fixed.
1447 // The same event sequence should not generate any double tap getsures.
1448 gestures_.clear();
1449 down_time_1 += kOneMicrosecond * 40;
1450 down_time_2 += kOneMicrosecond * 40;
1452 // Start a double-tap drag gesture.
1453 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1454 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1455 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
1456 MotionEvent::ACTION_UP,
1457 kFakeCoordX,
1458 kFakeCoordY);
1459 gesture_provider_->OnTouchEvent(event);
1460 event = ObtainMotionEvent(
1461 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
1462 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1463 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1464 MotionEvent::ACTION_MOVE,
1465 kFakeCoordX,
1466 kFakeCoordY + 100);
1467 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1468 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1469 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1471 // Double tap zoom updates should not be sent.
1472 // Instead, the second tap drag becomes a scroll gesture sequence.
1473 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1474 MotionEvent::ACTION_MOVE,
1475 kFakeCoordX,
1476 kFakeCoordY + 200);
1477 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1478 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1479 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1480 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1481 MotionEvent::ACTION_UP,
1482 kFakeCoordX,
1483 kFakeCoordY + 200);
1484 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1485 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
1488 // Verify that pinch zoom sends the proper event sequence.
1489 TEST_F(GestureProviderTest, PinchZoom) {
1490 base::TimeTicks event_time = base::TimeTicks::Now();
1491 const float touch_slop = GetTouchSlop();
1492 const float raw_offset_x = 3.2f;
1493 const float raw_offset_y = 4.3f;
1494 int motion_event_id = 0;
1496 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1497 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1498 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1500 int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
1501 int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
1503 MockMotionEvent event =
1504 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1505 event.set_id(++motion_event_id);
1506 event.SetRawOffset(raw_offset_x, raw_offset_y);
1507 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1508 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1509 EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
1510 EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
1511 EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1512 EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1513 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1514 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
1515 GetMostRecentGestureEvent().details.bounding_box());
1517 // Toggling double-tap support should not take effect until the next sequence.
1518 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1520 event = ObtainMotionEvent(event_time,
1521 MotionEvent::ACTION_POINTER_DOWN,
1522 kFakeCoordX,
1523 kFakeCoordY,
1524 secondary_coord_x,
1525 secondary_coord_y);
1526 event.set_id(++motion_event_id);
1527 event.SetRawOffset(raw_offset_x, raw_offset_y);
1529 gesture_provider_->OnTouchEvent(event);
1530 EXPECT_EQ(1U, GetReceivedGestureCount());
1531 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1532 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
1533 GetMostRecentGestureEvent().details.bounding_box());
1535 secondary_coord_x += 5 * touch_slop;
1536 secondary_coord_y += 5 * touch_slop;
1537 event = ObtainMotionEvent(event_time,
1538 MotionEvent::ACTION_MOVE,
1539 kFakeCoordX,
1540 kFakeCoordY,
1541 secondary_coord_x,
1542 secondary_coord_y);
1543 event.set_id(++motion_event_id);
1544 event.SetRawOffset(raw_offset_x, raw_offset_y);
1546 // Toggling double-tap support should not take effect until the next sequence.
1547 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1549 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1550 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1551 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1552 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1553 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1554 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1556 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
1557 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
1558 EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x,
1559 GetReceivedGesture(3).raw_x);
1560 EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y,
1561 GetReceivedGesture(3).raw_y);
1563 EXPECT_EQ(
1564 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1565 kFakeCoordY - kMockTouchRadius,
1566 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1567 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1568 GetMostRecentGestureEvent().details.bounding_box());
1570 secondary_coord_x += 2 * touch_slop;
1571 secondary_coord_y += 2 * touch_slop;
1572 event = ObtainMotionEvent(event_time,
1573 MotionEvent::ACTION_MOVE,
1574 kFakeCoordX,
1575 kFakeCoordY,
1576 secondary_coord_x,
1577 secondary_coord_y);
1578 event.set_id(++motion_event_id);
1580 // Toggling double-tap support should not take effect until the next sequence.
1581 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1583 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1584 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1585 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1586 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1587 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1588 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
1589 EXPECT_EQ(
1590 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1591 kFakeCoordY - kMockTouchRadius,
1592 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1593 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1594 GetMostRecentGestureEvent().details.bounding_box());
1596 event = ObtainMotionEvent(event_time,
1597 MotionEvent::ACTION_POINTER_UP,
1598 kFakeCoordX,
1599 kFakeCoordY,
1600 secondary_coord_x,
1601 secondary_coord_y);
1602 event.set_id(++motion_event_id);
1604 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1605 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1606 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1607 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1608 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
1609 EXPECT_EQ(
1610 gfx::RectF(kFakeCoordX - kMockTouchRadius,
1611 kFakeCoordY - kMockTouchRadius,
1612 secondary_coord_x - kFakeCoordX + kMockTouchRadius * 2,
1613 secondary_coord_y - kFakeCoordY + kMockTouchRadius * 2),
1614 GetMostRecentGestureEvent().details.bounding_box());
1616 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
1617 gesture_provider_->OnTouchEvent(event);
1618 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1619 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1620 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
1621 kFakeCoordY - kMockTouchRadius,
1622 kMockTouchRadius * 2,
1623 kMockTouchRadius * 2),
1624 GetMostRecentGestureEvent().details.bounding_box());
1627 // Verify that no accidental pinching occurs if the touch size is large relative
1628 // to the min scaling span when the touch major value is used in scaling.
1629 TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) {
1630 base::TimeTicks event_time = base::TimeTicks::Now();
1631 const float kFatFingerSize = GetMinScalingSpan() * 3.f;
1633 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1634 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1636 MockMotionEvent event =
1637 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1638 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1639 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1640 EXPECT_EQ(1U, GetReceivedGestureCount());
1642 event = ObtainMotionEvent(event_time + kOneSecond,
1643 MotionEvent::ACTION_MOVE);
1644 event.SetTouchMajor(0.1f);
1645 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1646 EXPECT_EQ(1U, GetReceivedGestureCount());
1648 event = ObtainMotionEvent(event_time + kOneSecond * 2,
1649 MotionEvent::ACTION_MOVE,
1650 kFakeCoordX + 1.f,
1651 kFakeCoordY);
1652 event.SetTouchMajor(1.f);
1653 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1654 EXPECT_EQ(1U, GetReceivedGestureCount());
1656 event = ObtainMotionEvent(event_time + kOneSecond * 3,
1657 MotionEvent::ACTION_MOVE);
1658 event.SetTouchMajor(kFatFingerSize * 3.5f);
1659 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1660 EXPECT_EQ(1U, GetReceivedGestureCount());
1662 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1663 MotionEvent::ACTION_MOVE);
1664 event.SetTouchMajor(kFatFingerSize * 5.f);
1665 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1666 EXPECT_EQ(1U, GetReceivedGestureCount());
1668 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1669 MotionEvent::ACTION_MOVE,
1670 kFakeCoordX + 50.f,
1671 kFakeCoordY - 25.f);
1672 event.SetTouchMajor(kFatFingerSize * 10.f);
1673 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1674 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1676 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1677 MotionEvent::ACTION_MOVE,
1678 kFakeCoordX + 100.f,
1679 kFakeCoordY - 50.f);
1680 event.SetTouchMajor(kFatFingerSize * 5.f);
1681 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1682 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1685 // Verify that multi-finger swipe sends the proper event sequence.
1686 TEST_F(GestureProviderTest, MultiFingerSwipe) {
1687 EnableSwipe();
1688 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
1689 const float min_swipe_velocity = GetMinSwipeVelocity();
1691 // One finger - swipe right
1692 OneFingerSwipe(2 * min_swipe_velocity, 0);
1693 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1694 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1695 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1696 ResetGestureDetection();
1698 // One finger - swipe left
1699 OneFingerSwipe(-2 * min_swipe_velocity, 0);
1700 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1701 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1702 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1703 ResetGestureDetection();
1705 // One finger - swipe down
1706 OneFingerSwipe(0, 2 * min_swipe_velocity);
1707 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1708 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1709 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1710 ResetGestureDetection();
1712 // One finger - swipe up
1713 OneFingerSwipe(0, -2 * min_swipe_velocity);
1714 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1715 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1716 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1717 ResetGestureDetection();
1719 // Two fingers
1720 // Swipe right.
1721 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0);
1722 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1723 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1724 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1725 ResetGestureDetection();
1727 // Swipe left.
1728 TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
1729 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1730 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1731 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1732 ResetGestureDetection();
1734 // No swipe with different touch directions.
1735 TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
1736 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1737 ResetGestureDetection();
1739 // No swipe without a dominant direction.
1740 TwoFingerSwipe(min_swipe_velocity * 2,
1741 min_swipe_velocity * 2,
1742 min_swipe_velocity * 2,
1743 min_swipe_velocity * 2);
1744 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1745 ResetGestureDetection();
1747 // Swipe down with non-zero velocities on both axes and dominant direction.
1748 TwoFingerSwipe(-min_swipe_velocity,
1749 min_swipe_velocity * 4,
1750 -min_swipe_velocity,
1751 min_swipe_velocity * 4);
1752 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1753 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1754 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left());
1755 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1756 ResetGestureDetection();
1758 // Swipe up with non-zero velocities on both axes.
1759 TwoFingerSwipe(min_swipe_velocity,
1760 -min_swipe_velocity * 4,
1761 min_swipe_velocity,
1762 -min_swipe_velocity * 4);
1763 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1764 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1765 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1766 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1767 ResetGestureDetection();
1769 // No swipe without sufficient velocity.
1770 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0);
1771 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1772 ResetGestureDetection();
1774 // Swipe up with one small and one medium velocity in slightly different but
1775 // not opposing directions.
1776 TwoFingerSwipe(min_swipe_velocity / 2,
1777 min_swipe_velocity / 2,
1779 min_swipe_velocity * 2);
1780 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1781 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1782 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1783 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1784 ResetGestureDetection();
1786 // No swipe in orthogonal directions.
1787 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7);
1788 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1789 ResetGestureDetection();
1791 // Three finger swipe in same directions.
1792 ThreeFingerSwipe(min_swipe_velocity * 2,
1794 min_swipe_velocity * 3,
1796 min_swipe_velocity * 4,
1798 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1799 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1800 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1801 ResetGestureDetection();
1803 // No three finger swipe in different directions.
1804 ThreeFingerSwipe(min_swipe_velocity * 2,
1807 min_swipe_velocity * 3,
1808 min_swipe_velocity * 4,
1810 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1813 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1814 // so LONG_PRESS and LONG_TAP won't be triggered.
1815 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
1816 base::TimeTicks event_time = base::TimeTicks::Now();
1818 MockMotionEvent event =
1819 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1820 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1822 const base::TimeDelta long_press_timeout =
1823 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1824 RunTasksAndWait(long_press_timeout);
1825 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
1826 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1828 EXPECT_TRUE(CancelActiveTouchSequence());
1829 EXPECT_FALSE(HasDownEvent());
1831 event = ObtainMotionEvent(event_time + long_press_timeout,
1832 MotionEvent::ACTION_UP);
1833 gesture_provider_->OnTouchEvent(event);
1834 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
1837 // Verify that inserting a touch cancel event will trigger proper touch and
1838 // gesture sequence cancellation.
1839 TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
1840 base::TimeTicks event_time = base::TimeTicks::Now();
1841 int motion_event_id = 0;
1843 EXPECT_FALSE(CancelActiveTouchSequence());
1844 EXPECT_EQ(0U, GetReceivedGestureCount());
1846 MockMotionEvent event =
1847 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1848 event.set_id(++motion_event_id);
1849 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1850 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1851 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1852 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1854 ASSERT_TRUE(CancelActiveTouchSequence());
1855 EXPECT_FALSE(HasDownEvent());
1857 // Subsequent MotionEvent's are dropped until ACTION_DOWN.
1858 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1859 MotionEvent::ACTION_MOVE);
1860 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1862 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1863 MotionEvent::ACTION_UP);
1864 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1866 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
1867 MotionEvent::ACTION_DOWN);
1868 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1869 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1870 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1873 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
1874 const base::TimeTicks down_time_1 = TimeTicks::Now();
1875 const base::TimeTicks down_time_2 = down_time_1 + GetValidDoubleTapDelay();
1877 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1879 MockMotionEvent event =
1880 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1881 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1882 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1883 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1885 event =
1886 ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::ACTION_UP);
1887 gesture_provider_->OnTouchEvent(event);
1888 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1889 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1891 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN);
1892 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1893 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1894 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1896 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1897 MotionEvent::ACTION_MOVE,
1898 kFakeCoordX,
1899 kFakeCoordY - 30);
1900 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1901 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1902 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1903 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1905 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1906 MotionEvent::ACTION_POINTER_DOWN,
1907 kFakeCoordX,
1908 kFakeCoordY - 30,
1909 kFakeCoordX + 50,
1910 kFakeCoordY + 50);
1911 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1912 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1913 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1915 const size_t gesture_count = GetReceivedGestureCount();
1916 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1917 MotionEvent::ACTION_POINTER_UP,
1918 kFakeCoordX,
1919 kFakeCoordY - 30,
1920 kFakeCoordX + 50,
1921 kFakeCoordY + 50);
1922 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1923 EXPECT_EQ(gesture_count, GetReceivedGestureCount());
1925 event = ObtainMotionEvent(down_time_2 + kOneSecond,
1926 MotionEvent::ACTION_UP);
1927 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1928 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount());
1929 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1930 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1933 // Verify that gesture begin and gesture end events are dispatched correctly.
1934 TEST_F(GestureProviderTest, GestureBeginAndEnd) {
1935 EnableBeginEndTypes();
1936 base::TimeTicks event_time = base::TimeTicks::Now();
1937 const float raw_offset_x = 7.5f;
1938 const float raw_offset_y = 5.7f;
1940 EXPECT_EQ(0U, GetReceivedGestureCount());
1941 MockMotionEvent event =
1942 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
1943 event.SetRawOffset(raw_offset_x, raw_offset_y);
1944 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1945 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
1946 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1947 EXPECT_EQ(2U, GetReceivedGestureCount());
1948 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1949 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1950 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1951 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1952 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1953 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
1954 1 - kMockTouchRadius,
1955 kMockTouchRadius * 2,
1956 kMockTouchRadius * 2),
1957 GetMostRecentGestureEvent().details.bounding_box());
1959 event = ObtainMotionEvent(
1960 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
1961 event.SetRawOffset(raw_offset_x, raw_offset_y);
1962 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1963 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1964 EXPECT_EQ(3U, GetReceivedGestureCount());
1965 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1966 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
1967 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
1968 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1969 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1971 event = ObtainMotionEvent(
1972 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
1973 event.SetRawOffset(raw_offset_x, raw_offset_y);
1974 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1975 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1976 EXPECT_EQ(4U, GetReceivedGestureCount());
1977 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1978 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
1979 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
1980 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1981 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1983 event = ObtainMotionEvent(
1984 event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3);
1985 event.SetRawOffset(raw_offset_x, raw_offset_y);
1986 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1987 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1988 EXPECT_EQ(5U, GetReceivedGestureCount());
1989 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1990 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1991 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1992 EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
1993 EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
1995 event = ObtainMotionEvent(
1996 event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4);
1997 event.SetRawOffset(raw_offset_x, raw_offset_y);
1998 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1999 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
2000 EXPECT_EQ(6U, GetReceivedGestureCount());
2001 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
2002 EXPECT_EQ(4, GetMostRecentGestureEvent().x);
2003 EXPECT_EQ(4, GetMostRecentGestureEvent().y);
2004 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2005 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2007 event = ObtainMotionEvent(
2008 event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4);
2009 event.SetRawOffset(raw_offset_x, raw_offset_y);
2010 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2011 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
2012 EXPECT_EQ(7U, GetReceivedGestureCount());
2013 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
2014 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
2015 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
2016 EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2017 EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2019 event =
2020 ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4);
2021 event.SetRawOffset(raw_offset_x, raw_offset_y);
2022 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2023 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
2024 EXPECT_EQ(8U, GetReceivedGestureCount());
2025 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2026 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
2027 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
2028 EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2029 EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2032 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4);
2033 event.SetRawOffset(raw_offset_x, raw_offset_y);
2034 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2035 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
2036 EXPECT_EQ(9U, GetReceivedGestureCount());
2037 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2038 EXPECT_EQ(4, GetMostRecentGestureEvent().x);
2039 EXPECT_EQ(4, GetMostRecentGestureEvent().y);
2040 EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
2041 EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
2044 // Verify that gesture begin and gesture end events are dispatched correctly
2045 // when an ACTION_CANCEL is received.
2046 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
2047 EnableBeginEndTypes();
2048 base::TimeTicks event_time = base::TimeTicks::Now();
2050 EXPECT_EQ(0U, GetReceivedGestureCount());
2051 MockMotionEvent event =
2052 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
2053 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2054 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
2055 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2056 EXPECT_EQ(2U, GetReceivedGestureCount());
2057 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2058 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
2059 1 - kMockTouchRadius,
2060 kMockTouchRadius * 2,
2061 kMockTouchRadius * 2),
2062 GetMostRecentGestureEvent().details.bounding_box());
2063 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
2064 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
2066 event = ObtainMotionEvent(
2067 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
2068 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2069 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
2070 EXPECT_EQ(3U, GetReceivedGestureCount());
2071 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2072 EXPECT_EQ(2, GetMostRecentGestureEvent().x);
2073 EXPECT_EQ(2, GetMostRecentGestureEvent().y);
2075 event = ObtainMotionEvent(
2076 event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
2077 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2078 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
2079 EXPECT_EQ(4U, GetReceivedGestureCount());
2080 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
2081 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
2082 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
2084 event = ObtainMotionEvent(
2085 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 2, 2, 3, 3);
2086 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2087 EXPECT_EQ(5U, GetReceivedGestureCount());
2088 EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points());
2089 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).type());
2090 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
2091 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
2093 event = ObtainMotionEvent(
2094 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 3, 3);
2095 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2096 EXPECT_EQ(6U, GetReceivedGestureCount());
2097 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2098 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
2099 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
2100 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
2102 event = ObtainMotionEvent(
2103 event_time, MotionEvent::ACTION_CANCEL, 3, 3);
2104 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2105 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2106 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEvent().type());
2107 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
2108 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
2111 // Test a simple two finger tap
2112 TEST_F(GestureProviderTest, TwoFingerTap) {
2113 // The time between ACTION_POINTER_DOWN and ACTION_POINTER_UP must be <= the
2114 // two finger tap delay.
2115 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2116 const float scaled_touch_slop = GetTouchSlop();
2118 base::TimeTicks event_time = base::TimeTicks::Now();
2120 MockMotionEvent event =
2121 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 0, 0);
2122 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2124 event = ObtainMotionEvent(event_time,
2125 MotionEvent::ACTION_MOVE,
2127 scaled_touch_slop / 2);
2129 event = ObtainMotionEvent(event_time,
2130 MotionEvent::ACTION_POINTER_DOWN,
2133 kMaxTwoFingerTapSeparation / 2,
2135 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2137 event =
2138 ObtainMotionEvent(event_time,
2139 MotionEvent::ACTION_MOVE,
2141 -scaled_touch_slop / 2,
2142 kMaxTwoFingerTapSeparation / 2 + scaled_touch_slop / 2,
2144 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2146 event = ObtainMotionEvent(event_time,
2147 MotionEvent::ACTION_POINTER_UP,
2150 kMaxTwoFingerTapSeparation,
2152 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2154 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2155 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
2156 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(2).type());
2157 EXPECT_EQ(3U, GetReceivedGestureCount());
2159 EXPECT_EQ(kMockTouchRadius * 2,
2160 GetReceivedGesture(2).details.first_finger_width());
2161 EXPECT_EQ(kMockTouchRadius * 2,
2162 GetReceivedGesture(2).details.first_finger_height());
2165 // Test preventing a two finger tap via finger movement.
2166 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) {
2167 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2168 const float scaled_touch_slop = GetTouchSlop();
2169 base::TimeTicks event_time = base::TimeTicks::Now();
2171 MockMotionEvent event = ObtainMotionEvent(
2172 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
2173 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2175 event = ObtainMotionEvent(event_time,
2176 MotionEvent::ACTION_POINTER_DOWN,
2177 kFakeCoordX,
2178 kFakeCoordY,
2179 kFakeCoordX,
2180 kFakeCoordY);
2181 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2183 event = ObtainMotionEvent(event_time,
2184 MotionEvent::ACTION_MOVE,
2185 kFakeCoordX,
2186 kFakeCoordY,
2187 kFakeCoordX + scaled_touch_slop + 0.1,
2188 kFakeCoordY);
2189 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2191 event = ObtainMotionEvent(event_time,
2192 MotionEvent::ACTION_POINTER_UP,
2193 kFakeCoordX,
2194 kFakeCoordY,
2195 kFakeCoordX,
2196 kFakeCoordY);
2197 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2199 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2200 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
2201 EXPECT_EQ(2U, GetReceivedGestureCount());
2204 // Test preventing a two finger tap by waiting too long before releasing the
2205 // secondary pointer.
2206 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) {
2207 base::TimeDelta two_finger_tap_timeout = kOneSecond;
2208 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout);
2209 base::TimeTicks event_time = base::TimeTicks::Now();
2211 MockMotionEvent event = ObtainMotionEvent(
2212 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
2213 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2215 event = ObtainMotionEvent(event_time,
2216 MotionEvent::ACTION_MOVE,
2217 kFakeCoordX,
2218 kFakeCoordY);
2220 event = ObtainMotionEvent(event_time,
2221 MotionEvent::ACTION_POINTER_DOWN,
2222 kFakeCoordX,
2223 kFakeCoordY,
2224 kFakeCoordX + kMaxTwoFingerTapSeparation / 2,
2225 kFakeCoordY);
2226 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2228 event = ObtainMotionEvent(event_time + kOneSecond + kOneMicrosecond,
2229 MotionEvent::ACTION_POINTER_UP,
2230 kFakeCoordX,
2231 kFakeCoordY,
2232 kFakeCoordX + kMaxTwoFingerTapSeparation / 2,
2233 kFakeCoordY);
2234 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2236 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2237 EXPECT_EQ(1U, GetReceivedGestureCount());
2240 // Test preventing a two finger tap by pressing the secondary pointer too far
2241 // from the first
2242 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) {
2243 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2244 base::TimeTicks event_time = base::TimeTicks::Now();
2246 MockMotionEvent event = ObtainMotionEvent(
2247 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
2248 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2250 event = ObtainMotionEvent(event_time,
2251 MotionEvent::ACTION_POINTER_DOWN,
2252 kFakeCoordX,
2253 kFakeCoordY,
2254 kFakeCoordX + kMaxTwoFingerTapSeparation,
2255 kFakeCoordY);
2256 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2258 event = ObtainMotionEvent(event_time,
2259 MotionEvent::ACTION_POINTER_UP,
2260 kFakeCoordX,
2261 kFakeCoordY,
2262 kFakeCoordX + kMaxTwoFingerTapSeparation,
2263 kFakeCoordY);
2264 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2266 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2267 EXPECT_EQ(1U, GetReceivedGestureCount());
2270 // Verify that pinch zoom only sends updates which exceed the
2271 // min_pinch_update_span_delta.
2272 TEST_F(GestureProviderTest, PinchZoomWithThreshold) {
2273 const float kMinPinchUpdateDistance = 5;
2275 base::TimeTicks event_time = base::TimeTicks::Now();
2276 const float touch_slop = GetTouchSlop();
2278 SetMinPinchUpdateSpanDelta(kMinPinchUpdateDistance);
2279 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
2280 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
2281 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
2283 int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
2284 int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
2286 // First finger down.
2287 MockMotionEvent event =
2288 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2289 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2290 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2291 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2293 // Second finger down.
2294 event = ObtainMotionEvent(event_time,
2295 MotionEvent::ACTION_POINTER_DOWN,
2296 kFakeCoordX,
2297 kFakeCoordY,
2298 secondary_coord_x,
2299 secondary_coord_y);
2301 gesture_provider_->OnTouchEvent(event);
2302 EXPECT_EQ(1U, GetReceivedGestureCount());
2303 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2305 // Move second finger.
2306 secondary_coord_x += 5 * touch_slop;
2307 secondary_coord_y += 5 * touch_slop;
2308 event = ObtainMotionEvent(event_time,
2309 MotionEvent::ACTION_MOVE,
2310 kFakeCoordX,
2311 kFakeCoordY,
2312 secondary_coord_x,
2313 secondary_coord_y);
2315 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2316 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2317 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
2318 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
2319 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
2320 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
2322 // Small move, shouldn't trigger pinch.
2323 event = ObtainMotionEvent(event_time,
2324 MotionEvent::ACTION_MOVE,
2325 kFakeCoordX,
2326 kFakeCoordY,
2327 secondary_coord_x + kMinPinchUpdateDistance,
2328 secondary_coord_y);
2330 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2331 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
2332 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2334 // Small move, but combined with the previous move, should trigger pinch. We
2335 // need to overshoot kMinPinchUpdateDistance by a fair bit, as the span
2336 // calculation factors in touch radius.
2337 const float kOvershootMinPinchUpdateDistance = 3;
2338 event = ObtainMotionEvent(event_time,
2339 MotionEvent::ACTION_MOVE,
2340 kFakeCoordX,
2341 kFakeCoordY,
2342 secondary_coord_x + kMinPinchUpdateDistance +
2343 kOvershootMinPinchUpdateDistance,
2344 secondary_coord_y);
2346 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2347 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
2348 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2351 // Verify that the min gesture bound setting is honored.
2352 TEST_F(GestureProviderTest, MinGestureBoundsLength) {
2353 const float kMinGestureBoundsLength = 10.f * kMockTouchRadius;
2354 SetMinMaxGestureBoundsLength(kMinGestureBoundsLength, 0.f);
2355 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2357 base::TimeTicks event_time = base::TimeTicks::Now();
2358 MockMotionEvent event =
2359 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2360 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2362 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2363 EXPECT_EQ(kMinGestureBoundsLength,
2364 GetMostRecentGestureEvent().details.bounding_box_f().width());
2365 EXPECT_EQ(kMinGestureBoundsLength,
2366 GetMostRecentGestureEvent().details.bounding_box_f().height());
2368 event =
2369 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2370 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2371 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2372 EXPECT_EQ(kMinGestureBoundsLength,
2373 GetMostRecentGestureEvent().details.bounding_box_f().width());
2374 EXPECT_EQ(kMinGestureBoundsLength,
2375 GetMostRecentGestureEvent().details.bounding_box_f().height());
2378 TEST_F(GestureProviderTest, MaxGestureBoundsLength) {
2379 const float kMaxGestureBoundsLength = kMockTouchRadius / 10.f;
2380 SetMinMaxGestureBoundsLength(0.f, kMaxGestureBoundsLength);
2381 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2383 base::TimeTicks event_time = base::TimeTicks::Now();
2384 MockMotionEvent event =
2385 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2386 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2388 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2389 EXPECT_EQ(kMaxGestureBoundsLength,
2390 GetMostRecentGestureEvent().details.bounding_box_f().width());
2391 EXPECT_EQ(kMaxGestureBoundsLength,
2392 GetMostRecentGestureEvent().details.bounding_box_f().height());
2394 event =
2395 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2396 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2397 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2398 EXPECT_EQ(kMaxGestureBoundsLength,
2399 GetMostRecentGestureEvent().details.bounding_box_f().width());
2400 EXPECT_EQ(kMaxGestureBoundsLength,
2401 GetMostRecentGestureEvent().details.bounding_box_f().height());
2404 TEST_F(GestureProviderTest, ZeroRadiusBoundingBox) {
2405 base::TimeTicks event_time = base::TimeTicks::Now();
2406 MockMotionEvent event =
2407 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 10, 20);
2408 event.SetTouchMajor(0);
2409 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2410 EXPECT_EQ(gfx::RectF(10, 20, 0, 0),
2411 GetMostRecentGestureEvent().details.bounding_box());
2413 event = ObtainMotionEvent(
2414 event_time, MotionEvent::ACTION_POINTER_DOWN, 10, 20, 110, 120);
2415 event.SetTouchMajor(0);
2416 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2418 event = ObtainMotionEvent(
2419 event_time, MotionEvent::ACTION_MOVE, 10, 20, 110, 150);
2420 event.SetTouchMajor(0);
2421 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2423 EXPECT_EQ(gfx::RectF(10, 20, 100, 130),
2424 GetMostRecentGestureEvent().details.bounding_box());
2427 // Verify that the min/max gesture bound settings are not applied to stylus
2428 // or mouse-derived MotionEvents.
2429 TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) {
2430 const float kMinGestureBoundsLength = 5.f * kMockTouchRadius;
2431 const float kMaxGestureBoundsLength = 10.f * kMockTouchRadius;
2432 SetMinMaxGestureBoundsLength(kMinGestureBoundsLength,
2433 kMaxGestureBoundsLength);
2434 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2436 base::TimeTicks event_time = base::TimeTicks::Now();
2437 MockMotionEvent event =
2438 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2439 event.SetTouchMajor(0);
2440 event.SetToolType(0, MotionEvent::TOOL_TYPE_MOUSE);
2441 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2443 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2444 EXPECT_EQ(MotionEvent::TOOL_TYPE_MOUSE,
2445 GetMostRecentGestureEvent().primary_tool_type);
2446 EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().width());
2447 EXPECT_EQ(0.f, GetMostRecentGestureEvent().details.bounding_box_f().height());
2449 event =
2450 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2451 event.SetTouchMajor(1);
2452 event.SetToolType(0, MotionEvent::TOOL_TYPE_STYLUS);
2453 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2454 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2455 EXPECT_EQ(MotionEvent::TOOL_TYPE_STYLUS,
2456 GetMostRecentGestureEvent().primary_tool_type);
2457 EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().width());
2458 EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().height());
2460 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2461 event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
2462 event.SetToolType(0, MotionEvent::TOOL_TYPE_MOUSE);
2463 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2464 EXPECT_EQ(MotionEvent::TOOL_TYPE_MOUSE,
2465 GetMostRecentGestureEvent().primary_tool_type);
2466 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2467 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2468 GetMostRecentGestureEvent().details.bounding_box_f().width());
2469 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2470 GetMostRecentGestureEvent().details.bounding_box_f().height());
2472 event =
2473 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2474 event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
2475 event.SetToolType(0, MotionEvent::TOOL_TYPE_ERASER);
2476 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2477 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2478 EXPECT_EQ(MotionEvent::TOOL_TYPE_ERASER,
2479 GetMostRecentGestureEvent().primary_tool_type);
2480 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2481 GetMostRecentGestureEvent().details.bounding_box_f().width());
2482 EXPECT_EQ(2.f * kMaxGestureBoundsLength,
2483 GetMostRecentGestureEvent().details.bounding_box_f().height());
2486 // Test the bounding box for show press and tap gestures.
2487 TEST_F(GestureProviderTest, BoundingBoxForShowPressAndTapGesture) {
2488 base::TimeTicks event_time = base::TimeTicks::Now();
2489 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2490 base::TimeDelta showpress_timeout = kOneMicrosecond;
2491 base::TimeDelta longpress_timeout = kOneSecond;
2492 SetShowPressAndLongPressTimeout(showpress_timeout, longpress_timeout);
2494 MockMotionEvent event =
2495 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 10, 10);
2496 event.SetTouchMajor(10);
2498 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2499 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2500 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2501 EXPECT_EQ(gfx::RectF(5, 5, 10, 10),
2502 GetMostRecentGestureEvent().details.bounding_box());
2504 event = ObtainMotionEvent(
2505 event_time + kOneMicrosecond, MotionEvent::ACTION_MOVE, 11, 9);
2506 event.SetTouchMajor(20);
2507 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2508 event = ObtainMotionEvent(
2509 event_time + kOneMicrosecond, MotionEvent::ACTION_MOVE, 8, 11);
2510 event.SetTouchMajor(10);
2511 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2512 RunTasksAndWait(showpress_timeout + kOneMicrosecond);
2513 EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetMostRecentGestureEventType());
2514 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2515 GetMostRecentGestureEvent().details.bounding_box());
2517 event =
2518 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2519 event.SetTouchMajor(30);
2520 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2521 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2523 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2524 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2525 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2526 GetMostRecentGestureEvent().details.bounding_box());
2529 } // namespace ui