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/mock_motion_event.h"
15 #include "ui/events/gesture_detection/motion_event.h"
16 #include "ui/gfx/geometry/point_f.h"
18 using base::TimeDelta;
19 using base::TimeTicks;
24 const float kFakeCoordX = 42.f;
25 const float kFakeCoordY = 24.f;
26 const TimeDelta kOneSecond = TimeDelta::FromSeconds(1);
27 const TimeDelta kOneMicrosecond = TimeDelta::FromMicroseconds(1);
28 const TimeDelta kDeltaTimeForFlingSequences = TimeDelta::FromMilliseconds(5);
30 GestureProvider::Config CreateDefaultConfig() {
31 GestureProvider::Config sConfig;
32 // The longpress timeout is non-zero only to indicate ordering with respect to
33 // the showpress timeout.
34 sConfig.gesture_detector_config.showpress_timeout = base::TimeDelta();
35 sConfig.gesture_detector_config.longpress_timeout = kOneMicrosecond;
37 // A valid doubletap timeout should always be non-zero. The value is used not
38 // only to trigger the timeout that confirms the tap event, but also to gate
39 // whether the second tap is in fact a double-tap (using a strict inequality
40 // between times for the first up and the second down events). We use 4
41 // microseconds simply to allow several intermediate events to occur before
42 // the second tap at microsecond intervals.
43 sConfig.gesture_detector_config.double_tap_timeout = kOneMicrosecond * 4;
49 class GestureProviderTest : public testing::Test, public GestureProviderClient {
51 GestureProviderTest() {}
52 virtual ~GestureProviderTest() {}
54 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
55 MotionEvent::Action action,
58 return MockMotionEvent(action, event_time, x, y);
61 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
62 MotionEvent::Action action,
67 return MockMotionEvent(action, event_time, x0, y0, x1, y1);
70 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
71 MotionEvent::Action action) {
72 return ObtainMotionEvent(event_time, action, kFakeCoordX, kFakeCoordY);
76 virtual void SetUp() OVERRIDE {
77 gesture_provider_.reset(new GestureProvider(GetDefaultConfig(), this));
78 gesture_provider_->SetMultiTouchSupportEnabled(false);
81 virtual void TearDown() OVERRIDE {
83 gesture_provider_.reset();
86 // GestureProviderClient
87 virtual void OnGestureEvent(const GestureEventData& gesture) OVERRIDE {
88 if (gesture.type == ET_GESTURE_SCROLL_BEGIN)
89 active_scroll_begin_event_.reset(new GestureEventData(gesture));
90 gestures_.push_back(gesture);
93 bool CancelActiveTouchSequence() {
94 if (!gesture_provider_->current_down_event())
96 return gesture_provider_->OnTouchEvent(
97 *gesture_provider_->current_down_event()->Cancel());
100 bool HasReceivedGesture(EventType type) const {
101 for (size_t i = 0; i < gestures_.size(); ++i) {
102 if (gestures_[i].type == type)
108 const GestureEventData& GetMostRecentGestureEvent() const {
109 EXPECT_FALSE(gestures_.empty());
110 return gestures_.back();
113 const EventType GetMostRecentGestureEventType() const {
114 EXPECT_FALSE(gestures_.empty());
115 return gestures_.back().type;
118 size_t GetReceivedGestureCount() const { return gestures_.size(); }
120 const GestureEventData& GetReceivedGesture(size_t index) const {
121 EXPECT_LT(index, GetReceivedGestureCount());
122 return gestures_[index];
125 const GestureEventData* GetActiveScrollBeginEvent() const {
126 return active_scroll_begin_event_ ? active_scroll_begin_event_.get() : NULL;
129 const GestureProvider::Config& GetDefaultConfig() const {
130 static GestureProvider::Config sConfig = CreateDefaultConfig();
134 int GetTouchSlop() const {
135 return GetDefaultConfig().gesture_detector_config.scaled_touch_slop;
138 base::TimeDelta GetLongPressTimeout() const {
139 return GetDefaultConfig().gesture_detector_config.longpress_timeout;
142 base::TimeDelta GetShowPressTimeout() const {
143 return GetDefaultConfig().gesture_detector_config.showpress_timeout;
147 void CheckScrollEventSequenceForEndActionType(
148 MotionEvent::Action end_action_type) {
149 base::TimeTicks event_time = base::TimeTicks::Now();
150 const int scroll_to_x = kFakeCoordX + 100;
151 const int scroll_to_y = kFakeCoordY + 100;
153 MockMotionEvent event =
154 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
156 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
158 event = ObtainMotionEvent(event_time + kOneSecond,
159 MotionEvent::ACTION_MOVE,
162 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
163 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
164 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
165 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
166 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, "
167 "ScrollBegin and ScrollBy "
168 "should have been sent";
170 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(1).type);
171 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type);
172 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time)
173 << "ScrollBegin should have the time of the ACTION_MOVE";
175 event = ObtainMotionEvent(
176 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
177 gesture_provider_->OnTouchEvent(event);
178 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
179 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
180 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
183 static void RunTasksAndWait(base::TimeDelta delay) {
184 base::MessageLoop::current()->PostDelayedTask(
185 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
186 base::MessageLoop::current()->Run();
189 std::vector<GestureEventData> gestures_;
190 scoped_ptr<GestureProvider> gesture_provider_;
191 scoped_ptr<GestureEventData> active_scroll_begin_event_;
192 base::MessageLoopForUI message_loop_;
195 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
196 TEST_F(GestureProviderTest, GestureTapTap) {
197 base::TimeTicks event_time = base::TimeTicks::Now();
199 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
201 MockMotionEvent event =
202 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
203 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
204 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
206 event = ObtainMotionEvent(event_time + kOneMicrosecond,
207 MotionEvent::ACTION_UP);
208 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
209 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
210 // Ensure tap details have been set.
211 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width());
212 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height());
213 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
216 // Verify that a DOWN followed shortly by an UP will trigger
217 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
218 TEST_F(GestureProviderTest, GestureTapTapWithDelay) {
219 base::TimeTicks event_time = base::TimeTicks::Now();
221 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
223 MockMotionEvent event =
224 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
225 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
226 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
228 event = ObtainMotionEvent(event_time + kOneMicrosecond,
229 MotionEvent::ACTION_UP);
230 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
231 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
232 // Ensure tap details have been set.
233 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width());
234 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height());
235 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
237 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
240 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
241 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
242 base::TimeTicks event_time = TimeTicks::Now();
243 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
245 MockMotionEvent event =
246 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
248 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
249 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
251 event = ObtainMotionEvent(event_time + delta_time,
252 MotionEvent::ACTION_MOVE,
255 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
257 event = ObtainMotionEvent(event_time + delta_time * 2,
258 MotionEvent::ACTION_UP,
261 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
262 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
263 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
266 // Verify that for a normal scroll the following events are sent:
267 // - ET_GESTURE_SCROLL_BEGIN
268 // - ET_GESTURE_SCROLL_UPDATE
269 // - ET_GESTURE_SCROLL_END
270 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
271 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP);
274 // Verify that for a cancelled scroll the following events are sent:
275 // - ET_GESTURE_SCROLL_BEGIN
276 // - ET_GESTURE_SCROLL_UPDATE
277 // - ET_GESTURE_SCROLL_END
278 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
279 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL);
282 // Verify that for a normal fling (fling after scroll) the following events are
284 // - ET_GESTURE_SCROLL_BEGIN
285 // - ET_SCROLL_FLING_START
286 TEST_F(GestureProviderTest, FlingEventSequence) {
287 base::TimeTicks event_time = base::TimeTicks::Now();
288 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
290 MockMotionEvent event =
291 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
293 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
295 event = ObtainMotionEvent(event_time + delta_time,
296 MotionEvent::ACTION_MOVE,
299 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
300 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
301 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
302 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
303 ASSERT_EQ(4U, GetReceivedGestureCount());
304 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type);
306 // We don't want to take a dependency here on exactly how hints are calculated
307 // for a fling (eg. may depend on velocity), so just validate the direction.
308 int hint_x = GetReceivedGesture(2).details.scroll_x_hint();
309 int hint_y = GetReceivedGesture(2).details.scroll_y_hint();
310 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
311 << "ScrollBegin hint should be in positive X axis";
313 event = ObtainMotionEvent(event_time + delta_time * 2,
314 MotionEvent::ACTION_UP,
317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
318 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
319 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
320 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
321 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
322 << "FlingStart should have the time of the ACTION_UP";
325 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) {
326 const base::TimeTicks event_time = TimeTicks::Now();
328 MockMotionEvent event =
329 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
330 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
331 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
333 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
335 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
336 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
338 // The long press triggers window focus loss by opening a context menu
339 EXPECT_TRUE(CancelActiveTouchSequence());
340 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
343 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) {
344 base::TimeTicks event_time = base::TimeTicks::Now();
346 MockMotionEvent event =
347 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
349 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
351 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
352 event = ObtainMotionEvent(event_time + kOneMicrosecond,
353 MotionEvent::ACTION_MOVE,
356 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
358 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
359 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL));
362 TEST_F(GestureProviderTest, DoubleTap) {
363 base::TimeTicks event_time = base::TimeTicks::Now();
365 MockMotionEvent event =
366 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
367 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
369 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
371 event = ObtainMotionEvent(event_time + kOneMicrosecond,
372 MotionEvent::ACTION_UP,
375 gesture_provider_->OnTouchEvent(event);
376 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
378 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
379 MotionEvent::ACTION_DOWN,
382 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
383 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
385 // Moving a very small amount of distance should not trigger the double tap
387 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
388 MotionEvent::ACTION_MOVE,
391 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
392 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
394 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
395 MotionEvent::ACTION_UP,
398 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
400 const GestureEventData& double_tap = GetMostRecentGestureEvent();
401 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type);
402 // Ensure tap details have been set.
403 EXPECT_EQ(10, double_tap.details.bounding_box().width());
404 EXPECT_EQ(10, double_tap.details.bounding_box().height());
405 EXPECT_EQ(1, double_tap.details.tap_count());
408 TEST_F(GestureProviderTest, DoubleTapDragZoom) {
409 const base::TimeTicks down_time_1 = TimeTicks::Now();
410 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
412 MockMotionEvent event =
413 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
414 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
416 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
417 MotionEvent::ACTION_UP,
420 gesture_provider_->OnTouchEvent(event);
421 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
423 event = ObtainMotionEvent(
424 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
425 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
426 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
428 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
429 MotionEvent::ACTION_MOVE,
432 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
433 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
434 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
435 ASSERT_TRUE(!!scroll_begin_gesture);
436 EXPECT_EQ(0, scroll_begin_gesture->details.scroll_x_hint());
437 EXPECT_EQ(100, scroll_begin_gesture->details.scroll_y_hint());
438 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
440 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
441 MotionEvent::ACTION_MOVE,
444 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
445 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
446 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
448 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
449 MotionEvent::ACTION_UP,
452 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
453 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
454 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
457 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
458 const base::TimeTicks down_time_1 = TimeTicks::Now();
459 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
461 MockMotionEvent event =
462 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
463 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
464 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
466 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
467 MotionEvent::ACTION_UP);
468 gesture_provider_->OnTouchEvent(event);
469 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
471 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN);
472 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
473 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
474 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL));
476 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
477 MotionEvent::ACTION_MOVE,
480 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
481 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
482 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
484 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
485 MotionEvent::ACTION_POINTER_DOWN,
490 gesture_provider_->OnTouchEvent(event);
491 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
492 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
493 const size_t gesture_count = GetReceivedGestureCount();
495 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
496 MotionEvent::ACTION_POINTER_UP,
501 gesture_provider_->OnTouchEvent(event);
502 EXPECT_EQ(gesture_count, GetReceivedGestureCount());
505 // Generate a scroll gesture and verify that the resulting scroll motion event
506 // has both absolute and relative position information.
507 TEST_F(GestureProviderTest, ScrollUpdateValues) {
508 const int delta_x = 16;
509 const int delta_y = 84;
511 const base::TimeTicks event_time = TimeTicks::Now();
513 MockMotionEvent event =
514 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
515 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
517 // Move twice so that we get two ET_GESTURE_SCROLL_UPDATE events and can
518 // compare the relative and absolute coordinates.
519 event = ObtainMotionEvent(event_time + kOneMicrosecond,
520 MotionEvent::ACTION_MOVE,
521 kFakeCoordX - delta_x / 2,
522 kFakeCoordY - delta_y / 2);
523 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
525 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
526 MotionEvent::ACTION_MOVE,
527 kFakeCoordX - delta_x,
528 kFakeCoordY - delta_y);
529 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
531 // Make sure the reported gesture event has all the expected details.
532 ASSERT_LT(0U, GetReceivedGestureCount());
533 GestureEventData gesture = GetMostRecentGestureEvent();
534 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type);
535 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
536 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
537 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
539 // No horizontal delta because of snapping.
540 EXPECT_EQ(0, gesture.details.scroll_x());
541 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
544 // Verify that fractional scroll deltas are rounded as expected and that
545 // fractional scrolling doesn't break scroll snapping.
546 TEST_F(GestureProviderTest, FractionalScroll) {
547 const float delta_x = 0.4f;
548 const float delta_y = 5.2f;
550 const base::TimeTicks event_time = TimeTicks::Now();
552 MockMotionEvent event =
553 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
554 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
556 // Skip past the touch slop and move back.
557 event = ObtainMotionEvent(event_time,
558 MotionEvent::ACTION_MOVE,
561 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
562 event = ObtainMotionEvent(event_time,
563 MotionEvent::ACTION_MOVE);
564 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
566 // Now move up slowly, mostly vertically but with a (fractional) bit of
567 // horizontal motion.
568 for(int i = 1; i <= 10; i++) {
569 event = ObtainMotionEvent(event_time + kOneMicrosecond * i,
570 MotionEvent::ACTION_MOVE,
571 kFakeCoordX + delta_x * i,
572 kFakeCoordY + delta_y * i);
573 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
575 ASSERT_LT(0U, GetReceivedGestureCount());
576 GestureEventData gesture = GetMostRecentGestureEvent();
577 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type);
578 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
580 // Verify that the event co-ordinates are still the precise values we
582 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
583 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y);
585 // Verify that we're scrolling vertically by the expected amount
586 // (modulo rounding).
587 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y);
588 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1);
590 // And that there has been no horizontal motion at all.
591 EXPECT_EQ(0, gesture.details.scroll_x());
595 // Generate a scroll gesture and verify that the resulting scroll begin event
596 // has the expected hint values.
597 TEST_F(GestureProviderTest, ScrollBeginValues) {
598 const int delta_x = 13;
599 const int delta_y = 89;
601 const base::TimeTicks event_time = TimeTicks::Now();
603 MockMotionEvent event =
604 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
605 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
607 // Move twice such that the first event isn't sufficient to start
608 // scrolling on it's own.
609 event = ObtainMotionEvent(event_time + kOneMicrosecond,
610 MotionEvent::ACTION_MOVE,
613 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
614 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
616 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
617 MotionEvent::ACTION_MOVE,
618 kFakeCoordX + delta_x,
619 kFakeCoordY + delta_y);
620 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
621 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
623 const GestureEventData* scroll_begin_gesture = GetActiveScrollBeginEvent();
624 ASSERT_TRUE(!!scroll_begin_gesture);
625 EXPECT_EQ(delta_x, scroll_begin_gesture->details.scroll_x_hint());
626 EXPECT_EQ(delta_y, scroll_begin_gesture->details.scroll_y_hint());
629 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
630 base::TimeTicks event_time = base::TimeTicks::Now();
632 MockMotionEvent event =
633 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
634 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
635 event = ObtainMotionEvent(event_time + kOneMicrosecond,
636 MotionEvent::ACTION_MOVE,
639 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
640 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
641 MotionEvent::ACTION_MOVE,
644 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
646 const base::TimeDelta long_press_timeout =
647 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
648 RunTasksAndWait(long_press_timeout);
650 // No LONG_TAP as the LONG_PRESS timer is cancelled.
651 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
652 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
655 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
656 TEST_F(GestureProviderTest, GestureLongTap) {
657 base::TimeTicks event_time = base::TimeTicks::Now();
659 MockMotionEvent event =
660 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
661 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
663 const base::TimeDelta long_press_timeout =
664 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
665 RunTasksAndWait(long_press_timeout);
667 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
669 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP);
670 gesture_provider_->OnTouchEvent(event);
671 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType());
674 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
675 base::TimeTicks event_time = base::TimeTicks::Now();
677 MockMotionEvent event =
678 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
679 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
681 const base::TimeDelta long_press_timeout =
682 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
683 RunTasksAndWait(long_press_timeout);
685 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
686 event = ObtainMotionEvent(event_time + long_press_timeout,
687 MotionEvent::ACTION_MOVE,
690 gesture_provider_->OnTouchEvent(event);
692 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
693 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
694 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL));
696 event = ObtainMotionEvent(event_time + long_press_timeout,
697 MotionEvent::ACTION_UP);
698 gesture_provider_->OnTouchEvent(event);
699 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
702 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
703 base::TimeTicks event_time = base::TimeTicks::Now();
705 MockMotionEvent event = ObtainMotionEvent(
706 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
707 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
709 event = ObtainMotionEvent(event_time + kOneMicrosecond,
710 MotionEvent::ACTION_UP,
713 gesture_provider_->OnTouchEvent(event);
714 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
716 event = ObtainMotionEvent(event_time + kOneMicrosecond,
717 MotionEvent::ACTION_DOWN,
720 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
721 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
722 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
724 const base::TimeDelta long_press_timeout =
725 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
726 RunTasksAndWait(long_press_timeout);
727 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
729 event = ObtainMotionEvent(event_time + long_press_timeout,
730 MotionEvent::ACTION_MOVE,
733 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
734 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
735 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
737 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
738 MotionEvent::ACTION_UP,
741 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
742 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
743 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
746 // Verify that the touch slop region is removed from the first scroll delta to
747 // avoid a jump when starting to scroll.
748 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
749 const int scaled_touch_slop = GetTouchSlop();
750 const int scroll_delta = 5;
752 base::TimeTicks event_time = base::TimeTicks::Now();
754 MockMotionEvent event =
755 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
756 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
758 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
759 MotionEvent::ACTION_MOVE,
761 kFakeCoordY + scaled_touch_slop + scroll_delta);
762 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
764 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
765 GestureEventData gesture = GetMostRecentGestureEvent();
766 EXPECT_EQ(0, gesture.details.scroll_x());
767 EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
770 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
771 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
773 base::TimeTicks event_time = base::TimeTicks::Now();
774 MockMotionEvent event = ObtainMotionEvent(
775 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
776 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
777 EXPECT_EQ(1U, GetReceivedGestureCount());
778 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
780 event = ObtainMotionEvent(event_time + kOneMicrosecond,
781 MotionEvent::ACTION_UP,
784 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
785 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
787 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
788 MotionEvent::ACTION_DOWN,
791 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
792 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
794 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
795 MotionEvent::ACTION_UP,
798 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
799 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
802 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
803 const base::TimeTicks down_time_1 = TimeTicks::Now();
804 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
806 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
808 MockMotionEvent event =
809 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
810 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
812 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
813 MotionEvent::ACTION_UP,
816 gesture_provider_->OnTouchEvent(event);
818 event = ObtainMotionEvent(
819 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
820 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
822 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
823 MotionEvent::ACTION_MOVE,
827 // The move should become a scroll, as doubletap drag zoom is disabled.
828 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
829 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
830 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
832 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
833 MotionEvent::ACTION_MOVE,
836 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
837 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
838 EXPECT_EQ(down_time_2 + kOneMicrosecond * 2,
839 GetMostRecentGestureEvent().time);
840 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
842 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
843 MotionEvent::ACTION_UP,
846 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
847 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
850 // Verify that double tap drag zoom feature is not invoked when the gesture
851 // handler is told to disable double tap gesture detection.
852 // The second tap sequence should be treated just as the first would be.
853 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) {
854 const base::TimeTicks down_time_1 = TimeTicks::Now();
855 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
857 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
859 MockMotionEvent event =
860 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
861 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
863 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
864 MotionEvent::ACTION_UP,
867 gesture_provider_->OnTouchEvent(event);
869 event = ObtainMotionEvent(
870 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
871 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
873 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
874 MotionEvent::ACTION_MOVE,
878 // The move should become a scroll, as double tap drag zoom is disabled.
879 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
880 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
881 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
883 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
884 MotionEvent::ACTION_MOVE,
887 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
888 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
889 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
891 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
892 MotionEvent::ACTION_UP,
895 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
896 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
899 // Verify that updating double tap support during a double tap drag zoom
900 // disables double tap detection after the gesture has ended.
901 TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
902 base::TimeTicks down_time_1 = TimeTicks::Now();
903 base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
905 // Start a double-tap drag gesture.
906 MockMotionEvent event =
907 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
908 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
909 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
910 MotionEvent::ACTION_UP,
913 gesture_provider_->OnTouchEvent(event);
914 event = ObtainMotionEvent(
915 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
916 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
917 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
918 MotionEvent::ACTION_MOVE,
921 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
922 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
923 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
925 // Simulate setting a fixed page scale (or a mobile viewport);
926 // this should not disrupt the current double-tap gesture.
927 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
929 // Double tap zoom updates should continue.
930 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
931 MotionEvent::ACTION_MOVE,
934 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
935 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
936 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
937 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
938 MotionEvent::ACTION_UP,
941 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
942 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
943 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
945 // The double-tap gesture has finished, but the page scale is fixed.
946 // The same event sequence should not generate any double tap getsures.
948 down_time_1 += kOneMicrosecond * 40;
949 down_time_2 += kOneMicrosecond * 40;
951 // Start a double-tap drag gesture.
952 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
953 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
954 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
955 MotionEvent::ACTION_UP,
958 gesture_provider_->OnTouchEvent(event);
959 event = ObtainMotionEvent(
960 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
961 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
962 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
963 MotionEvent::ACTION_MOVE,
966 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
967 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
968 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
970 // Double tap zoom updates should not be sent.
971 // Instead, the second tap drag becomes a scroll gesture sequence.
972 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
973 MotionEvent::ACTION_MOVE,
976 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
977 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
978 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
979 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
980 MotionEvent::ACTION_UP,
983 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
984 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
987 // Verify that pinch zoom sends the proper event sequence.
988 TEST_F(GestureProviderTest, PinchZoom) {
989 base::TimeTicks event_time = base::TimeTicks::Now();
990 const int scaled_touch_slop = GetTouchSlop();
992 gesture_provider_->SetMultiTouchSupportEnabled(true);
994 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop;
995 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop;
997 MockMotionEvent event =
998 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
999 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1000 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1002 event = ObtainMotionEvent(event_time,
1003 MotionEvent::ACTION_POINTER_DOWN,
1008 gesture_provider_->OnTouchEvent(event);
1009 EXPECT_EQ(1U, GetReceivedGestureCount());
1011 secondary_coord_x += 5 * scaled_touch_slop;
1012 secondary_coord_y += 5 * scaled_touch_slop;
1014 event = ObtainMotionEvent(event_time,
1015 MotionEvent::ACTION_MOVE,
1021 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1022 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1023 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1024 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1025 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1027 event = ObtainMotionEvent(event_time,
1028 MotionEvent::ACTION_POINTER_UP,
1034 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1035 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1036 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
1038 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
1039 gesture_provider_->OnTouchEvent(event);
1040 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1043 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1044 // so LONG_PRESS and LONG_TAP won't be triggered.
1045 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
1046 base::TimeTicks event_time = base::TimeTicks::Now();
1048 MockMotionEvent event =
1049 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1050 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1052 const base::TimeDelta long_press_timeout =
1053 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1054 RunTasksAndWait(long_press_timeout);
1055 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
1057 EXPECT_TRUE(CancelActiveTouchSequence());
1058 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
1060 event = ObtainMotionEvent(event_time + long_press_timeout,
1061 MotionEvent::ACTION_UP);
1062 gesture_provider_->OnTouchEvent(event);
1063 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
1066 // Verify that inserting a touch cancel event will trigger proper touch and
1067 // gesture sequence cancellation.
1068 TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
1069 base::TimeTicks event_time = base::TimeTicks::Now();
1071 EXPECT_FALSE(CancelActiveTouchSequence());
1072 EXPECT_EQ(0U, GetReceivedGestureCount());
1074 MockMotionEvent event =
1075 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1076 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1077 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1079 ASSERT_TRUE(CancelActiveTouchSequence());
1080 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
1082 // Subsequent MotionEvent's are dropped until ACTION_DOWN.
1083 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1084 MotionEvent::ACTION_MOVE);
1085 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1087 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1088 MotionEvent::ACTION_UP);
1089 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1091 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
1092 MotionEvent::ACTION_DOWN);
1093 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1094 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());