Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
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/gesture_detection/gesture_event_params.h"
12 #include "ui/events/gesture_detection/gesture_provider.h"
13 #include "ui/events/gesture_detection/mock_motion_event.h"
14 #include "ui/events/gesture_detection/motion_event.h"
15 #include "ui/gfx/geometry/point_f.h"
16
17 using base::TimeDelta;
18 using base::TimeTicks;
19
20 namespace ui {
21 namespace {
22
23 const float kFakeCoordX = 42.f;
24 const float kFakeCoordY = 24.f;
25 const TimeDelta kOneSecond = TimeDelta::FromSeconds(1);
26 const TimeDelta kFiveMilliseconds = TimeDelta::FromMilliseconds(5);
27
28 } // namespace
29
30 class GestureProviderTest : public testing::Test, public GestureProviderClient {
31 public:
32 GestureProviderTest() {}
33 virtual ~GestureProviderTest() {}
34
35 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
36 MotionEvent::Action action,
37 float x,
38 float y) {
39 return MockMotionEvent(action, event_time, x, y);
40 }
41
42 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
43 MotionEvent::Action action,
44 float x0,
45 float y0,
46 float x1,
47 float y1) {
48 return MockMotionEvent(action, event_time, x0, y0, x1, y1);
49 }
50
51 static MockMotionEvent ObtainMotionEvent(base::TimeTicks event_time,
52 MotionEvent::Action action) {
53 return ObtainMotionEvent(event_time, action, kFakeCoordX, kFakeCoordY);
54 }
55
56 // Test
57 virtual void SetUp() OVERRIDE {
58 gesture_provider_.reset(new GestureProvider(GetDefaultConfig(), this));
59 gesture_provider_->UpdateMultiTouchSupport(false);
60 }
61
62 virtual void TearDown() OVERRIDE {
63 gestures_.clear();
64 gesture_provider_.reset();
65 }
66
67 // GestureProviderClient
68 virtual void OnGestureEvent(const GestureEventParams& gesture) OVERRIDE {
69 if (gesture.type == GESTURE_SCROLL_BEGIN)
70 active_scroll_begin_event_.reset(new GestureEventParams(gesture));
71 gestures_.push_back(gesture);
72 }
73
74 bool HasReceivedGesture(GestureEventType type) const {
75 for (size_t i = 0; i < gestures_.size(); ++i) {
76 if (gestures_[i].type == type)
77 return true;
78 }
79 return false;
80 }
81
82 const GestureEventParams& GetMostRecentGestureEvent() const {
83 EXPECT_FALSE(gestures_.empty());
84 return gestures_.back();
85 }
86
87 const GestureEventType GetMostRecentGestureEventType() const {
88 EXPECT_FALSE(gestures_.empty());
89 return gestures_.back().type;
90 }
91
92 size_t GetReceivedGestureCount() const { return gestures_.size(); }
93
94 const GestureEventParams& GetReceivedGesture(size_t index) const {
95 EXPECT_LT(index, GetReceivedGestureCount());
96 return gestures_[index];
97 }
98
99 const GestureEventParams* GetActiveScrollBeginEvent() const {
100 return active_scroll_begin_event_ ? active_scroll_begin_event_.get() : NULL;
101 }
102
103 const GestureProvider::Config& GetDefaultConfig() const {
104 static GestureProvider::Config sConfig;
105 return sConfig;
106 }
107
108 int GetTouchSlop() const {
109 return GetDefaultConfig().gesture_detector_config.scaled_touch_slop;
110 }
111
112 base::TimeDelta GetLongPressTimeout() const {
113 return GetDefaultConfig().gesture_detector_config.longpress_timeout;
114 }
115
116 base::TimeDelta GetShowPressTimeout() const {
117 return GetDefaultConfig().gesture_detector_config.tap_timeout;
118 }
119
120 protected:
121 void CheckScrollEventSequenceForendActionType(
122 MotionEvent::Action end_action_type) {
123 base::TimeTicks event_time = base::TimeTicks::Now();
124 const int scroll_to_x = kFakeCoordX + 100;
125 const int scroll_to_y = kFakeCoordY + 100;
126
127 MockMotionEvent event =
128 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
129
130 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
131
132 event = ObtainMotionEvent(event_time + kOneSecond,
133 MotionEvent::ACTION_MOVE,
134 scroll_to_x,
135 scroll_to_y);
136 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
137 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
138 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
139 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
140 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, "
141 "ScrollBegin and ScrollBy "
142 "should have been sent";
143
144 EXPECT_EQ(GESTURE_TAP_CANCEL, GetReceivedGesture(1).type);
145 EXPECT_EQ(GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type);
146 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time)
147 << "ScrollBegin should have the time of the ACTION_MOVE";
148
149 event = ObtainMotionEvent(
150 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
151 gesture_provider_->OnTouchEvent(event);
152 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
153 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_END));
154 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType());
155 }
156
157 static void Wait(base::TimeDelta delay) {
158 base::MessageLoop::current()->PostDelayedTask(
159 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
160 base::MessageLoop::current()->Run();
161 }
162
163 std::vector<GestureEventParams> gestures_;
164 scoped_ptr<GestureProvider> gesture_provider_;
165 scoped_ptr<GestureEventParams> active_scroll_begin_event_;
166 base::MessageLoopForUI message_loop_;
167 };
168
169 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
170 TEST_F(GestureProviderTest, GestureSingleTap) {
171 base::TimeTicks event_time = base::TimeTicks::Now();
172
173 gesture_provider_->UpdateDoubleTapSupportForPlatform(false);
174
175 MockMotionEvent event =
176 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
177 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
178 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
179
180 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
181 MotionEvent::ACTION_UP);
182 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
183 EXPECT_EQ(GESTURE_SINGLE_TAP_CONFIRMED, GetMostRecentGestureEventType());
184 }
185
186 // Verify that a DOWN followed shortly by an UP will trigger
187 // a GESTURE_SINGLE_TAP_UNCONFIRMED event if double-tap is enabled.
188 TEST_F(GestureProviderTest, GestureSingleTapWithDelay) {
189 base::TimeTicks event_time = base::TimeTicks::Now();
190
191 gesture_provider_->UpdateDoubleTapSupportForPlatform(true);
192
193 MockMotionEvent event =
194 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
195 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
196 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
197
198 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
199 MotionEvent::ACTION_UP);
200 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
201 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
202 EXPECT_FALSE(HasReceivedGesture(GESTURE_SINGLE_TAP_CONFIRMED));
203 }
204
205
206 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
207 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
208 base::TimeTicks event_time = TimeTicks::Now();
209
210 MockMotionEvent event =
211 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
212
213 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
214 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
215
216 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
217 MotionEvent::ACTION_MOVE,
218 kFakeCoordX * 10,
219 kFakeCoordY * 10);
220 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
221
222 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
223 MotionEvent::ACTION_UP,
224 kFakeCoordX * 10,
225 kFakeCoordY * 10);
226 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
227 EXPECT_EQ(GESTURE_FLING_START, GetMostRecentGestureEventType());
228 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_PRESS));
229 }
230
231 // Verify that for a normal scroll the following events are sent:
232 // - GESTURE_SCROLL_BEGIN
233 // - GESTURE_SCROLL_UPDATE
234 // - GESTURE_SCROLL_END
235 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
236 CheckScrollEventSequenceForendActionType(MotionEvent::ACTION_UP);
237 }
238
239 // Verify that for a cancelled scroll the following events are sent:
240 // - GESTURE_SCROLL_BEGIN
241 // - GESTURE_SCROLL_UPDATE
242 // - GESTURE_SCROLL_END
243 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
244 CheckScrollEventSequenceForendActionType(MotionEvent::ACTION_CANCEL);
245 }
246
247 // Verify that for a normal fling (fling after scroll) the following events are
248 // sent:
249 // - GESTURE_SCROLL_BEGIN
250 // - GESTURE_FLING_START
251 TEST_F(GestureProviderTest, FlingEventSequence) {
252 base::TimeTicks event_time = base::TimeTicks::Now();
253
254 MockMotionEvent event =
255 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
256
257 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
258
259 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
260 MotionEvent::ACTION_MOVE,
261 kFakeCoordX * 5,
262 kFakeCoordY * 5);
263 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
264 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
265 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
266 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
267 ASSERT_EQ(4U, GetReceivedGestureCount());
268 ASSERT_EQ(GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type);
269
270 // We don't want to take a dependency here on exactly how hints are calculated
271 // for a fling (eg. may depend on velocity), so just validate the direction.
272 int hint_x = GetReceivedGesture(2).data.scroll_begin.delta_x_hint;
273 int hint_y = GetReceivedGesture(2).data.scroll_begin.delta_y_hint;
274 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
275 << "ScrollBegin hint should be in positive X axis";
276
277 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3,
278 MotionEvent::ACTION_UP,
279 kFakeCoordX * 10,
280 kFakeCoordY * 10);
281 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
282 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
283 EXPECT_EQ(GESTURE_FLING_START, GetMostRecentGestureEventType());
284 EXPECT_FALSE(HasReceivedGesture(GESTURE_SCROLL_END));
285 EXPECT_EQ(event_time + kFiveMilliseconds * 3,
286 GetMostRecentGestureEvent().time)
287 << "FlingStart should have the time of the ACTION_UP";
288 }
289
290 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) {
291 const base::TimeTicks event_time = TimeTicks::Now();
292
293 MockMotionEvent event =
294 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
295 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
296 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
297
298 Wait(GetShowPressTimeout() + kFiveMilliseconds);
299 EXPECT_EQ(GESTURE_SHOW_PRESS, GetMostRecentGestureEventType());
300
301 Wait(GetLongPressTimeout() + kFiveMilliseconds);
302 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
303
304 // The long press triggers window focus loss by opening a context menu
305 gesture_provider_->CancelActiveTouchSequence();
306 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
307 }
308
309 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) {
310 base::TimeTicks event_time = base::TimeTicks::Now();
311
312 MockMotionEvent event =
313 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
314
315 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
316
317 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
318 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
319 MotionEvent::ACTION_MOVE,
320 kFakeCoordX + 50,
321 kFakeCoordY + 50);
322 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
323
324 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
325 EXPECT_TRUE(HasReceivedGesture(GESTURE_TAP_CANCEL));
326
327 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
328 MotionEvent::ACTION_UP,
329 kFakeCoordX + 100,
330 kFakeCoordY + 100);
331 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
332 EXPECT_EQ(GESTURE_FLING_START, GetMostRecentGestureEventType());
333 EXPECT_FALSE(HasReceivedGesture(GESTURE_SCROLL_END));
334 }
335
336 TEST_F(GestureProviderTest, DoubleTap) {
337 base::TimeTicks event_time = base::TimeTicks::Now();
338
339 MockMotionEvent event =
340 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
341 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
342
343 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
344
345 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
346 MotionEvent::ACTION_UP,
347 kFakeCoordX,
348 kFakeCoordY);
349 gesture_provider_->OnTouchEvent(event);
350 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
351
352 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
353 MotionEvent::ACTION_DOWN,
354 kFakeCoordX,
355 kFakeCoordY);
356 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
357 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
358
359 // Moving a very small amount of distance should not trigger the double tap
360 // drag zoom mode.
361 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3,
362 MotionEvent::ACTION_MOVE,
363 kFakeCoordX,
364 kFakeCoordY + 1);
365 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
366 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
367
368 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3,
369 MotionEvent::ACTION_UP,
370 kFakeCoordX,
371 kFakeCoordY + 1);
372 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
373 EXPECT_EQ(GESTURE_DOUBLE_TAP, GetMostRecentGestureEventType());
374 }
375
376 TEST_F(GestureProviderTest, DoubleTapDragZoom) {
377 const base::TimeTicks down_time_1 = TimeTicks::Now();
378 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20;
379
380 MockMotionEvent event =
381 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
382 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
383
384 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds,
385 MotionEvent::ACTION_UP,
386 kFakeCoordX,
387 kFakeCoordY);
388 gesture_provider_->OnTouchEvent(event);
389 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
390
391 event = ObtainMotionEvent(
392 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
393 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
394 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
395
396 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds,
397 MotionEvent::ACTION_MOVE,
398 kFakeCoordX,
399 kFakeCoordY + 100);
400 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
401 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
402 const GestureEventParams* scroll_begin_gesture = GetActiveScrollBeginEvent();
403 ASSERT_TRUE(!!scroll_begin_gesture);
404 EXPECT_EQ(0, scroll_begin_gesture->data.scroll_begin.delta_x_hint);
405 EXPECT_EQ(100, scroll_begin_gesture->data.scroll_begin.delta_y_hint);
406 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
407
408 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2,
409 MotionEvent::ACTION_MOVE,
410 kFakeCoordX,
411 kFakeCoordY + 200);
412 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
413 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE));
414 EXPECT_EQ(GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
415
416 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3,
417 MotionEvent::ACTION_UP,
418 kFakeCoordX,
419 kFakeCoordY + 200);
420 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
421 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_END));
422 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType());
423 }
424
425 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
426 const base::TimeTicks down_time_1 = TimeTicks::Now();
427 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20;
428
429 MockMotionEvent event =
430 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
431 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
432 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
433
434 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds,
435 MotionEvent::ACTION_UP);
436 gesture_provider_->OnTouchEvent(event);
437 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
438
439 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN);
440 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
441 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
442 EXPECT_TRUE(HasReceivedGesture(GESTURE_TAP_CANCEL));
443
444 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 10,
445 MotionEvent::ACTION_MOVE,
446 kFakeCoordX,
447 kFakeCoordY - 30);
448 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
449 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
450 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
451
452 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 20,
453 MotionEvent::ACTION_POINTER_DOWN,
454 kFakeCoordX,
455 kFakeCoordY - 30,
456 kFakeCoordX + 50,
457 kFakeCoordY + 50);
458 gesture_provider_->OnTouchEvent(event);
459 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_END));
460 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType());
461 const size_t gesture_count = GetReceivedGestureCount();
462
463 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 30,
464 MotionEvent::ACTION_POINTER_UP,
465 kFakeCoordX,
466 kFakeCoordY - 30,
467 kFakeCoordX + 50,
468 kFakeCoordY + 50);
469 gesture_provider_->OnTouchEvent(event);
470 EXPECT_EQ(gesture_count, GetReceivedGestureCount());
471 }
472
473 // Generate a scroll gesture and verify that the resulting scroll motion event
474 // has both absolute and relative position information.
475 TEST_F(GestureProviderTest, ScrollUpdateValues) {
476 const int delta_x = 16;
477 const int delta_y = 84;
478
479 const base::TimeTicks event_time = TimeTicks::Now();
480
481 MockMotionEvent event =
482 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
483 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
484
485 // Move twice so that we get two GESTURE_SCROLL_UPDATE events and can compare
486 // the relative and absolute coordinates.
487 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
488 MotionEvent::ACTION_MOVE,
489 kFakeCoordX - delta_x / 2,
490 kFakeCoordY - delta_y / 2);
491 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
492
493 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
494 MotionEvent::ACTION_MOVE,
495 kFakeCoordX - delta_x,
496 kFakeCoordY - delta_y);
497 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
498
499 // Make sure the reported gesture event has all the expected data.
500 ASSERT_LT(0U, GetReceivedGestureCount());
501 GestureEventParams gesture = GetMostRecentGestureEvent();
502 EXPECT_EQ(GESTURE_SCROLL_UPDATE, gesture.type);
503 EXPECT_EQ(event_time + kFiveMilliseconds * 2, gesture.time);
504 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
505 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
506
507 // No horizontal delta because of snapping.
508 EXPECT_EQ(0, gesture.data.scroll_update.delta_x);
509 EXPECT_EQ(-delta_y / 2, gesture.data.scroll_update.delta_y);
510 }
511
512 // Generate a scroll gesture and verify that the resulting scroll begin event
513 // has the expected hint values.
514 TEST_F(GestureProviderTest, ScrollBeginValues) {
515 const int delta_x = 13;
516 const int delta_y = 89;
517
518 const base::TimeTicks event_time = TimeTicks::Now();
519
520 MockMotionEvent event =
521 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
522 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
523
524 // Move twice such that the first event isn't sufficient to start
525 // scrolling on it's own.
526 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
527 MotionEvent::ACTION_MOVE,
528 kFakeCoordX + 2,
529 kFakeCoordY + 1);
530 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
531 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
532
533 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
534 MotionEvent::ACTION_MOVE,
535 kFakeCoordX + delta_x,
536 kFakeCoordY + delta_y);
537 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
538 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
539
540 const GestureEventParams* scroll_begin_gesture = GetActiveScrollBeginEvent();
541 ASSERT_TRUE(!!scroll_begin_gesture);
542 EXPECT_EQ(delta_x, scroll_begin_gesture->data.scroll_begin.delta_x_hint);
543 EXPECT_EQ(delta_y, scroll_begin_gesture->data.scroll_begin.delta_y_hint);
544 }
545
546 TEST_F(GestureProviderTest, LongPressAndTapCancelledWhenScrollBegins) {
547 base::TimeTicks event_time = base::TimeTicks::Now();
548
549 MockMotionEvent event =
550 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
551 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
552 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
553 MotionEvent::ACTION_MOVE,
554 kFakeCoordX * 5,
555 kFakeCoordY * 5);
556 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
557 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
558 MotionEvent::ACTION_MOVE,
559 kFakeCoordX * 10,
560 kFakeCoordY * 10);
561 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
562
563 const base::TimeDelta long_press_timeout =
564 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2;
565 Wait(long_press_timeout);
566
567 // No LONG_TAP as the LONG_PRESS timer is cancelled.
568 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_PRESS));
569 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP));
570 }
571
572 // Verify that LONG_TAP is triggered after LONG_PRESS followed by an UP.
573 TEST_F(GestureProviderTest, GestureLongTap) {
574 base::TimeTicks event_time = base::TimeTicks::Now();
575
576 MockMotionEvent event =
577 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
578 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
579
580 const base::TimeDelta long_press_timeout =
581 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2;
582 Wait(long_press_timeout);
583
584 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
585
586 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP);
587 gesture_provider_->OnTouchEvent(event);
588 EXPECT_EQ(GESTURE_LONG_TAP, GetMostRecentGestureEventType());
589 }
590
591 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
592 base::TimeTicks event_time = base::TimeTicks::Now();
593
594 MockMotionEvent event =
595 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
596 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
597
598 const base::TimeDelta long_press_timeout =
599 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2;
600 Wait(long_press_timeout);
601
602 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
603 event = ObtainMotionEvent(event_time + long_press_timeout,
604 MotionEvent::ACTION_MOVE,
605 kFakeCoordX + 100,
606 kFakeCoordY + 100);
607 gesture_provider_->OnTouchEvent(event);
608
609 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
610 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
611 EXPECT_TRUE(HasReceivedGesture(GESTURE_TAP_CANCEL));
612
613 event = ObtainMotionEvent(event_time + long_press_timeout,
614 MotionEvent::ACTION_UP);
615 gesture_provider_->OnTouchEvent(event);
616 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP));
617 }
618
619 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
620 base::TimeTicks event_time = base::TimeTicks::Now();
621
622 MockMotionEvent event = ObtainMotionEvent(
623 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
624 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
625
626 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
627 MotionEvent::ACTION_UP,
628 kFakeCoordX,
629 kFakeCoordY);
630 gesture_provider_->OnTouchEvent(event);
631 EXPECT_EQ(GESTURE_SINGLE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
632
633 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
634 MotionEvent::ACTION_DOWN,
635 kFakeCoordX,
636 kFakeCoordY);
637 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
638 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
639 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
640
641 const base::TimeDelta long_press_timeout =
642 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2;
643 Wait(long_press_timeout);
644 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_PRESS));
645
646 event = ObtainMotionEvent(event_time + long_press_timeout,
647 MotionEvent::ACTION_MOVE,
648 kFakeCoordX + 20,
649 kFakeCoordY + 20);
650 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
651 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
652 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
653
654 event = ObtainMotionEvent(event_time + long_press_timeout + kFiveMilliseconds,
655 MotionEvent::ACTION_UP,
656 kFakeCoordX,
657 kFakeCoordY + 1);
658 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
659 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType());
660 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
661 }
662
663 // Verify that the touch slop region is removed from the first scroll delta to
664 // avoid a jump when starting to scroll.
665 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
666 const int scaled_touch_slop = GetTouchSlop();
667 const int scroll_delta = 5;
668
669 base::TimeTicks event_time = base::TimeTicks::Now();
670
671 MockMotionEvent event =
672 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
673 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
674
675 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
676 MotionEvent::ACTION_MOVE,
677 kFakeCoordX,
678 kFakeCoordY + scaled_touch_slop + scroll_delta);
679 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
680
681 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
682 GestureEventParams gesture = GetMostRecentGestureEvent();
683 EXPECT_EQ(0, gesture.data.scroll_update.delta_x);
684 EXPECT_EQ(scroll_delta, gesture.data.scroll_update.delta_y);
685 }
686
687 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
688 gesture_provider_->UpdateDoubleTapSupportForPlatform(false);
689
690 base::TimeTicks event_time = base::TimeTicks::Now();
691 MockMotionEvent event = ObtainMotionEvent(
692 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
693 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
694 EXPECT_EQ(1U, GetReceivedGestureCount());
695 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
696
697 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
698 MotionEvent::ACTION_UP,
699 kFakeCoordX,
700 kFakeCoordY);
701 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
702 EXPECT_EQ(GESTURE_SINGLE_TAP_CONFIRMED, GetMostRecentGestureEventType());
703
704 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
705 MotionEvent::ACTION_DOWN,
706 kFakeCoordX,
707 kFakeCoordY);
708 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
709 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
710
711 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3,
712 MotionEvent::ACTION_UP,
713 kFakeCoordX,
714 kFakeCoordY);
715 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
716 EXPECT_EQ(GESTURE_SINGLE_TAP_CONFIRMED, GetMostRecentGestureEventType());
717 }
718
719 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
720 const base::TimeTicks down_time_1 = TimeTicks::Now();
721 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20;
722
723 gesture_provider_->UpdateDoubleTapSupportForPlatform(false);
724
725 MockMotionEvent event =
726 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
727 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
728
729 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds,
730 MotionEvent::ACTION_UP,
731 kFakeCoordX,
732 kFakeCoordY);
733 gesture_provider_->OnTouchEvent(event);
734
735 event = ObtainMotionEvent(
736 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
737 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
738
739 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds,
740 MotionEvent::ACTION_MOVE,
741 kFakeCoordX,
742 kFakeCoordY + 100);
743
744 // The move should become a scroll, as doubletap drag zoom is disabled.
745 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
746 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
747 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_BEGIN));
748
749 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2,
750 MotionEvent::ACTION_MOVE,
751 kFakeCoordX,
752 kFakeCoordY + 200);
753 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
754 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
755 EXPECT_EQ(down_time_2 + kFiveMilliseconds * 2,
756 GetMostRecentGestureEvent().time);
757 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_UPDATE));
758
759 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3,
760 MotionEvent::ACTION_UP,
761 kFakeCoordX,
762 kFakeCoordY + 200);
763 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
764 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_END));
765 }
766
767 // Verify that double tap drag zoom feature is not invoked when the gesture
768 // handler is told to disable double tap gesture detection.
769 // The second tap sequence should be treated just as the first would be.
770 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPage) {
771 const base::TimeTicks down_time_1 = TimeTicks::Now();
772 const base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20;
773
774 gesture_provider_->UpdateDoubleTapSupportForPage(false);
775
776 MockMotionEvent event =
777 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
778 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
779
780 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds,
781 MotionEvent::ACTION_UP,
782 kFakeCoordX,
783 kFakeCoordY);
784 gesture_provider_->OnTouchEvent(event);
785
786 event = ObtainMotionEvent(
787 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
788 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
789
790 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds,
791 MotionEvent::ACTION_MOVE,
792 kFakeCoordX,
793 kFakeCoordY + 100);
794
795 // The move should become a scroll, as double tap drag zoom is disabled.
796 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
797 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
798 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_BEGIN));
799
800 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2,
801 MotionEvent::ACTION_MOVE,
802 kFakeCoordX,
803 kFakeCoordY + 200);
804 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
805 EXPECT_EQ(GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
806 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_UPDATE));
807
808 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3,
809 MotionEvent::ACTION_UP,
810 kFakeCoordX,
811 kFakeCoordY + 200);
812 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
813 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_END));
814 }
815
816 // Verify that updating double tap support during a double tap drag zoom
817 // disables double tap detection after the gesture has ended.
818 TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
819 base::TimeTicks down_time_1 = TimeTicks::Now();
820 base::TimeTicks down_time_2 = down_time_1 + kFiveMilliseconds * 20;
821
822 // Start a double-tap drag gesture.
823 MockMotionEvent event =
824 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
825 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
826 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds,
827 MotionEvent::ACTION_UP,
828 kFakeCoordX,
829 kFakeCoordY);
830 gesture_provider_->OnTouchEvent(event);
831 event = ObtainMotionEvent(
832 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
833 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
834 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds,
835 MotionEvent::ACTION_MOVE,
836 kFakeCoordX,
837 kFakeCoordY + 100);
838 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
839 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
840 EXPECT_EQ(GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
841
842 // Simulate setting a fixed page scale (or a mobile viewport);
843 // this should not disrupt the current double-tap gesture.
844 gesture_provider_->UpdateDoubleTapSupportForPage(false);
845
846 // Double tap zoom updates should continue.
847 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2,
848 MotionEvent::ACTION_MOVE,
849 kFakeCoordX,
850 kFakeCoordY + 200);
851 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
852 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE));
853 EXPECT_EQ(GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
854 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3,
855 MotionEvent::ACTION_UP,
856 kFakeCoordX,
857 kFakeCoordY + 200);
858 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
859 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_END));
860 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType());
861
862 // The double-tap gesture has finished, but the page scale is fixed.
863 // The same event sequence should not generate any double tap getsures.
864 gestures_.clear();
865 down_time_1 += kFiveMilliseconds * 40;
866 down_time_2 += kFiveMilliseconds * 40;
867
868 // Start a double-tap drag gesture.
869 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
870 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
871 event = ObtainMotionEvent(down_time_1 + kFiveMilliseconds,
872 MotionEvent::ACTION_UP,
873 kFakeCoordX,
874 kFakeCoordY);
875 gesture_provider_->OnTouchEvent(event);
876 event = ObtainMotionEvent(
877 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
878 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
879 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds,
880 MotionEvent::ACTION_MOVE,
881 kFakeCoordX,
882 kFakeCoordY + 100);
883 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
884 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
885 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_BEGIN));
886
887 // Double tap zoom updates should not be sent.
888 // Instead, the second tap drag becomes a scroll gesture sequence.
889 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 2,
890 MotionEvent::ACTION_MOVE,
891 kFakeCoordX,
892 kFakeCoordY + 200);
893 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
894 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE));
895 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_UPDATE));
896 event = ObtainMotionEvent(down_time_2 + kFiveMilliseconds * 3,
897 MotionEvent::ACTION_UP,
898 kFakeCoordX,
899 kFakeCoordY + 200);
900 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
901 EXPECT_FALSE(HasReceivedGesture(GESTURE_PINCH_END));
902 }
903
904 // Verify that pinch zoom sends the proper event sequence.
905 TEST_F(GestureProviderTest, PinchZoom) {
906 base::TimeTicks event_time = base::TimeTicks::Now();
907 const int scaled_touch_slop = GetTouchSlop();
908
909 gesture_provider_->UpdateMultiTouchSupport(true);
910
911 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop;
912 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop;
913
914 MockMotionEvent event =
915 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
916 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
917 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
918
919 event = ObtainMotionEvent(event_time,
920 MotionEvent::ACTION_POINTER_DOWN,
921 kFakeCoordX,
922 kFakeCoordY,
923 secondary_coord_x,
924 secondary_coord_y);
925 gesture_provider_->OnTouchEvent(event);
926 EXPECT_EQ(1U, GetReceivedGestureCount());
927
928 secondary_coord_x += 5 * scaled_touch_slop;
929 secondary_coord_y += 5 * scaled_touch_slop;
930
931 event = ObtainMotionEvent(event_time,
932 MotionEvent::ACTION_MOVE,
933 kFakeCoordX,
934 kFakeCoordY,
935 secondary_coord_x,
936 secondary_coord_y);
937
938 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
939 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_BEGIN));
940 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_BEGIN));
941 EXPECT_TRUE(HasReceivedGesture(GESTURE_PINCH_UPDATE));
942 EXPECT_TRUE(HasReceivedGesture(GESTURE_SCROLL_UPDATE));
943
944 event = ObtainMotionEvent(event_time,
945 MotionEvent::ACTION_POINTER_UP,
946 kFakeCoordX,
947 kFakeCoordY,
948 secondary_coord_x,
949 secondary_coord_y);
950
951 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
952 EXPECT_EQ(GESTURE_PINCH_END, GetMostRecentGestureEventType());
953 EXPECT_FALSE(HasReceivedGesture(GESTURE_SCROLL_END));
954
955 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
956 gesture_provider_->OnTouchEvent(event);
957 EXPECT_EQ(GESTURE_SCROLL_END, GetMostRecentGestureEventType());
958 }
959
960 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
961 // so LONG_PRESS and LONG_TAP won't be triggered.
962 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
963 base::TimeTicks event_time = base::TimeTicks::Now();
964
965 MockMotionEvent event =
966 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
967 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
968
969 const base::TimeDelta long_press_timeout =
970 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2;
971 Wait(long_press_timeout);
972 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
973
974 gesture_provider_->CancelActiveTouchSequence();
975 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
976
977 event = ObtainMotionEvent(event_time + long_press_timeout,
978 MotionEvent::ACTION_UP);
979 gesture_provider_->OnTouchEvent(event);
980 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP));
981 }
982
983 // Verify that ignoring the remaining touch sequence triggers proper touch and
984 // gesture cancellation.
985 TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
986 base::TimeTicks event_time = base::TimeTicks::Now();
987
988 gesture_provider_->CancelActiveTouchSequence();
989 EXPECT_EQ(0U, GetReceivedGestureCount());
990
991 MockMotionEvent event =
992 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
993 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
994 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
995
996 gesture_provider_->CancelActiveTouchSequence();
997 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType());
998
999 // Subsequent MotionEvent's are dropped until ACTION_DOWN.
1000 event = ObtainMotionEvent(event_time + kFiveMilliseconds,
1001 MotionEvent::ACTION_MOVE);
1002 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1003
1004 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2,
1005 MotionEvent::ACTION_UP);
1006 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1007
1008 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3,
1009 MotionEvent::ACTION_DOWN);
1010 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1011 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1012 }
1013
1014 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698