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

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

Issue 227743007: ui::GestureProvider gives GestureEventData the number of touch points. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jdduke final nits. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 event = ObtainMotionEvent( 189 event = ObtainMotionEvent(
190 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); 190 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
191 event.SetId(++motion_event_id); 191 event.SetId(++motion_event_id);
192 192
193 gesture_provider_->OnTouchEvent(event); 193 gesture_provider_->OnTouchEvent(event);
194 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 194 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
195 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 195 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
196 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 196 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
197 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 197 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
198 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
198 } 199 }
199 200
200 static void RunTasksAndWait(base::TimeDelta delay) { 201 static void RunTasksAndWait(base::TimeDelta delay) {
201 base::MessageLoop::current()->PostDelayedTask( 202 base::MessageLoop::current()->PostDelayedTask(
202 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 203 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
203 base::MessageLoop::current()->Run(); 204 base::MessageLoop::current()->Run();
204 } 205 }
205 206
206 std::vector<GestureEventData> gestures_; 207 std::vector<GestureEventData> gestures_;
207 scoped_ptr<GestureProvider> gesture_provider_; 208 scoped_ptr<GestureProvider> gesture_provider_;
208 scoped_ptr<GestureEventData> active_scroll_begin_event_; 209 scoped_ptr<GestureEventData> active_scroll_begin_event_;
209 base::MessageLoopForUI message_loop_; 210 base::MessageLoopForUI message_loop_;
210 }; 211 };
211 212
212 // Verify that a DOWN followed shortly by an UP will trigger a single tap. 213 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
213 TEST_F(GestureProviderTest, GestureTapTap) { 214 TEST_F(GestureProviderTest, GestureTapTap) {
214 base::TimeTicks event_time = base::TimeTicks::Now(); 215 base::TimeTicks event_time = base::TimeTicks::Now();
215 int motion_event_id = 0; 216 int motion_event_id = 0;
216 217
217 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 218 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
218 219
219 MockMotionEvent event = 220 MockMotionEvent event =
220 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 221 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
221 event.SetId(++motion_event_id); 222 event.SetId(++motion_event_id);
222 223
223 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 224 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
224 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 225 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
226 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
225 227
226 event = ObtainMotionEvent(event_time + kOneMicrosecond, 228 event = ObtainMotionEvent(event_time + kOneMicrosecond,
227 MotionEvent::ACTION_UP); 229 MotionEvent::ACTION_UP);
228 event.SetId(++motion_event_id); 230 event.SetId(++motion_event_id);
229 231
230 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 232 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
231 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 233 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
232 // Ensure tap details have been set. 234 // Ensure tap details have been set.
233 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); 235 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width());
234 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); 236 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height());
235 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 237 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
236 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 238 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
239 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
237 } 240 }
238 241
239 // Verify that a DOWN followed shortly by an UP will trigger 242 // Verify that a DOWN followed shortly by an UP will trigger
240 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled. 243 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
241 TEST_F(GestureProviderTest, GestureTapTapWithDelay) { 244 TEST_F(GestureProviderTest, GestureTapTapWithDelay) {
242 base::TimeTicks event_time = base::TimeTicks::Now(); 245 base::TimeTicks event_time = base::TimeTicks::Now();
243 int motion_event_id = 0; 246 int motion_event_id = 0;
244 247
245 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 248 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
246 249
247 MockMotionEvent event = 250 MockMotionEvent event =
248 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 251 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
249 event.SetId(++motion_event_id); 252 event.SetId(++motion_event_id);
250 253
251 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 254 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
252 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 255 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
253 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 256 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
257 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
254 258
255 event = ObtainMotionEvent(event_time + kOneMicrosecond, 259 event = ObtainMotionEvent(event_time + kOneMicrosecond,
256 MotionEvent::ACTION_UP); 260 MotionEvent::ACTION_UP);
257 event.SetId(++motion_event_id); 261 event.SetId(++motion_event_id);
258 262
259 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 263 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
260 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 264 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
261 // Ensure tap details have been set. 265 // Ensure tap details have been set.
262 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); 266 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width());
263 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); 267 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height());
264 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 268 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
265 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 269 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
270 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
266 271
267 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP)); 272 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
268 } 273 }
269 274
270 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). 275 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
271 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) { 276 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
272 base::TimeTicks event_time = TimeTicks::Now(); 277 base::TimeTicks event_time = TimeTicks::Now();
273 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; 278 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
274 int motion_event_id = 0; 279 int motion_event_id = 0;
275 280
276 MockMotionEvent event = 281 MockMotionEvent event =
277 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 282 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
278 event.SetId(++motion_event_id); 283 event.SetId(++motion_event_id);
279 284
280 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 285 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
281 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 286 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
282 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 287 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
288 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
283 289
284 event = ObtainMotionEvent(event_time + delta_time, 290 event = ObtainMotionEvent(event_time + delta_time,
285 MotionEvent::ACTION_MOVE, 291 MotionEvent::ACTION_MOVE,
286 kFakeCoordX * 10, 292 kFakeCoordX * 10,
287 kFakeCoordY * 10); 293 kFakeCoordY * 10);
288 event.SetId(++motion_event_id); 294 event.SetId(++motion_event_id);
289 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 295 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
290 296
291 event = ObtainMotionEvent(event_time + delta_time * 2, 297 event = ObtainMotionEvent(event_time + delta_time * 2,
292 MotionEvent::ACTION_UP, 298 MotionEvent::ACTION_UP,
293 kFakeCoordX * 10, 299 kFakeCoordX * 10,
294 kFakeCoordY * 10); 300 kFakeCoordY * 10);
295 event.SetId(++motion_event_id); 301 event.SetId(++motion_event_id);
296 302
297 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 303 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
298 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 304 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
299 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 305 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
306 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
300 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 307 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
301 } 308 }
302 309
303 // Verify that for a normal scroll the following events are sent: 310 // Verify that for a normal scroll the following events are sent:
304 // - ET_GESTURE_SCROLL_BEGIN 311 // - ET_GESTURE_SCROLL_BEGIN
305 // - ET_GESTURE_SCROLL_UPDATE 312 // - ET_GESTURE_SCROLL_UPDATE
306 // - ET_GESTURE_SCROLL_END 313 // - ET_GESTURE_SCROLL_END
307 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { 314 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
308 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP); 315 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP);
309 } 316 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 event = ObtainMotionEvent(event_time + delta_time * 2, 363 event = ObtainMotionEvent(event_time + delta_time * 2,
357 MotionEvent::ACTION_UP, 364 MotionEvent::ACTION_UP,
358 kFakeCoordX * 10, 365 kFakeCoordX * 10,
359 kFakeCoordY * 10); 366 kFakeCoordY * 10);
360 event.SetId(++motion_event_id); 367 event.SetId(++motion_event_id);
361 368
362 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 369 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
363 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 370 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
364 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 371 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
365 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 372 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
373 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
366 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 374 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
367 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) 375 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
368 << "FlingStart should have the time of the ACTION_UP"; 376 << "FlingStart should have the time of the ACTION_UP";
369 } 377 }
370 378
371 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) { 379 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) {
372 const base::TimeTicks event_time = TimeTicks::Now(); 380 const base::TimeTicks event_time = TimeTicks::Now();
373 381
374 MockMotionEvent event = 382 MockMotionEvent event =
375 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 383 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
(...skipping 17 matching lines...) Expand all
393 401
394 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) { 402 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) {
395 base::TimeTicks event_time = base::TimeTicks::Now(); 403 base::TimeTicks event_time = base::TimeTicks::Now();
396 404
397 MockMotionEvent event = 405 MockMotionEvent event =
398 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 406 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
399 407
400 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 408 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
401 409
402 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 410 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
411 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
403 event = ObtainMotionEvent(event_time + kOneMicrosecond, 412 event = ObtainMotionEvent(event_time + kOneMicrosecond,
404 MotionEvent::ACTION_MOVE, 413 MotionEvent::ACTION_MOVE,
405 kFakeCoordX + 50, 414 kFakeCoordX + 50,
406 kFakeCoordY + 50); 415 kFakeCoordY + 50);
407 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 416 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
408 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 417 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
409 418
410 event = ObtainMotionEvent(event_time + kOneSecond, 419 event = ObtainMotionEvent(event_time + kOneSecond,
411 MotionEvent::ACTION_UP, 420 MotionEvent::ACTION_UP,
412 kFakeCoordX + 50, 421 kFakeCoordX + 50,
413 kFakeCoordY + 50); 422 kFakeCoordY + 50);
414 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 423 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
415 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 424 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
416 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 425 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
417 } 426 }
418 427
419 TEST_F(GestureProviderTest, DoubleTap) { 428 TEST_F(GestureProviderTest, DoubleTap) {
420 base::TimeTicks event_time = base::TimeTicks::Now(); 429 base::TimeTicks event_time = base::TimeTicks::Now();
421 430
422 MockMotionEvent event = 431 MockMotionEvent event =
423 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 432 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
424 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 433 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
425 434
426 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 435 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
436 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
427 437
428 event = ObtainMotionEvent(event_time + kOneMicrosecond, 438 event = ObtainMotionEvent(event_time + kOneMicrosecond,
429 MotionEvent::ACTION_UP, 439 MotionEvent::ACTION_UP,
430 kFakeCoordX, 440 kFakeCoordX,
431 kFakeCoordY); 441 kFakeCoordY);
432 gesture_provider_->OnTouchEvent(event); 442 gesture_provider_->OnTouchEvent(event);
433 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 443 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
444 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
434 445
435 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 446 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
436 MotionEvent::ACTION_DOWN, 447 MotionEvent::ACTION_DOWN,
437 kFakeCoordX, 448 kFakeCoordX,
438 kFakeCoordY); 449 kFakeCoordY);
439 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 450 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
440 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 451 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
452 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
441 453
442 // Moving a very small amount of distance should not trigger the double tap 454 // Moving a very small amount of distance should not trigger the double tap
443 // drag zoom mode. 455 // drag zoom mode.
444 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 456 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
445 MotionEvent::ACTION_MOVE, 457 MotionEvent::ACTION_MOVE,
446 kFakeCoordX, 458 kFakeCoordX,
447 kFakeCoordY + 1); 459 kFakeCoordY + 1);
448 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 460 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
449 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 461 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
462 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
450 463
451 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 464 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
452 MotionEvent::ACTION_UP, 465 MotionEvent::ACTION_UP,
453 kFakeCoordX, 466 kFakeCoordX,
454 kFakeCoordY + 1); 467 kFakeCoordY + 1);
455 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 468 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
456 469
457 const GestureEventData& double_tap = GetMostRecentGestureEvent(); 470 const GestureEventData& double_tap = GetMostRecentGestureEvent();
458 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); 471 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type);
459 // Ensure tap details have been set. 472 // Ensure tap details have been set.
460 EXPECT_EQ(10, double_tap.details.bounding_box().width()); 473 EXPECT_EQ(10, double_tap.details.bounding_box().width());
461 EXPECT_EQ(10, double_tap.details.bounding_box().height()); 474 EXPECT_EQ(10, double_tap.details.bounding_box().height());
462 EXPECT_EQ(1, double_tap.details.tap_count()); 475 EXPECT_EQ(1, double_tap.details.tap_count());
463 } 476 }
464 477
465 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { 478 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
466 const base::TimeTicks down_time_1 = TimeTicks::Now(); 479 const base::TimeTicks down_time_1 = TimeTicks::Now();
467 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; 480 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
468 481
469 MockMotionEvent event = 482 MockMotionEvent event =
470 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 483 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
471 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 484 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
472 485
473 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, 486 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond,
474 MotionEvent::ACTION_UP, 487 MotionEvent::ACTION_UP,
475 kFakeCoordX, 488 kFakeCoordX,
476 kFakeCoordY); 489 kFakeCoordY);
477 gesture_provider_->OnTouchEvent(event); 490 gesture_provider_->OnTouchEvent(event);
478 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 491 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
492 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
479 493
480 event = ObtainMotionEvent( 494 event = ObtainMotionEvent(
481 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 495 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
482 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 496 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
483 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 497 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
498 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
484 499
485 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 500 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
486 MotionEvent::ACTION_MOVE, 501 MotionEvent::ACTION_MOVE,
487 kFakeCoordX, 502 kFakeCoordX,
488 kFakeCoordY + 100); 503 kFakeCoordY + 100);
489 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 504 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
490 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 505 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
491 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 506 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
492 507
493 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 508 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 kFakeCoordY - delta_y); 556 kFakeCoordY - delta_y);
542 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 557 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
543 558
544 // Make sure the reported gesture event has all the expected details. 559 // Make sure the reported gesture event has all the expected details.
545 ASSERT_LT(0U, GetReceivedGestureCount()); 560 ASSERT_LT(0U, GetReceivedGestureCount());
546 GestureEventData gesture = GetMostRecentGestureEvent(); 561 GestureEventData gesture = GetMostRecentGestureEvent();
547 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); 562 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type);
548 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); 563 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
549 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); 564 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
550 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); 565 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
566 EXPECT_EQ(1, gesture.details.touch_points());
551 567
552 // No horizontal delta because of snapping. 568 // No horizontal delta because of snapping.
553 EXPECT_EQ(0, gesture.details.scroll_x()); 569 EXPECT_EQ(0, gesture.details.scroll_x());
554 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); 570 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
555 } 571 }
556 572
557 // Verify that fractional scroll deltas are rounded as expected and that 573 // Verify that fractional scroll deltas are rounded as expected and that
558 // fractional scrolling doesn't break scroll snapping. 574 // fractional scrolling doesn't break scroll snapping.
559 TEST_F(GestureProviderTest, FractionalScroll) { 575 TEST_F(GestureProviderTest, FractionalScroll) {
560 const float delta_x = 0.4f; 576 const float delta_x = 0.4f;
(...skipping 21 matching lines...) Expand all
582 event = ObtainMotionEvent(event_time + kOneMicrosecond * i, 598 event = ObtainMotionEvent(event_time + kOneMicrosecond * i,
583 MotionEvent::ACTION_MOVE, 599 MotionEvent::ACTION_MOVE,
584 kFakeCoordX + delta_x * i, 600 kFakeCoordX + delta_x * i,
585 kFakeCoordY + delta_y * i); 601 kFakeCoordY + delta_y * i);
586 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 602 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
587 603
588 ASSERT_LT(0U, GetReceivedGestureCount()); 604 ASSERT_LT(0U, GetReceivedGestureCount());
589 GestureEventData gesture = GetMostRecentGestureEvent(); 605 GestureEventData gesture = GetMostRecentGestureEvent();
590 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); 606 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type);
591 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time); 607 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
608 EXPECT_EQ(1, gesture.details.touch_points());
592 609
593 // Verify that the event co-ordinates are still the precise values we 610 // Verify that the event co-ordinates are still the precise values we
594 // supplied. 611 // supplied.
595 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); 612 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
596 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y); 613 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y);
597 614
598 // Verify that we're scrolling vertically by the expected amount 615 // Verify that we're scrolling vertically by the expected amount
599 // (modulo rounding). 616 // (modulo rounding).
600 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y); 617 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y);
601 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1); 618 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1);
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 688
672 MockMotionEvent event = 689 MockMotionEvent event =
673 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 690 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
674 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 691 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
675 692
676 const base::TimeDelta long_press_timeout = 693 const base::TimeDelta long_press_timeout =
677 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 694 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
678 RunTasksAndWait(long_press_timeout); 695 RunTasksAndWait(long_press_timeout);
679 696
680 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 697 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
698 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
681 699
682 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP); 700 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP);
683 gesture_provider_->OnTouchEvent(event); 701 gesture_provider_->OnTouchEvent(event);
684 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType()); 702 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType());
703 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
685 } 704 }
686 705
687 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) { 706 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) {
688 base::TimeTicks event_time = base::TimeTicks::Now(); 707 base::TimeTicks event_time = base::TimeTicks::Now();
689 708
690 MockMotionEvent event = 709 MockMotionEvent event =
691 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 710 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
692 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 711 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
693 712
694 const base::TimeDelta long_press_timeout = 713 const base::TimeDelta long_press_timeout =
695 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 714 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
696 RunTasksAndWait(long_press_timeout); 715 RunTasksAndWait(long_press_timeout);
697 716
698 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 717 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
718 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
699 event = ObtainMotionEvent(event_time + long_press_timeout, 719 event = ObtainMotionEvent(event_time + long_press_timeout,
700 MotionEvent::ACTION_MOVE, 720 MotionEvent::ACTION_MOVE,
701 kFakeCoordX + 100, 721 kFakeCoordX + 100,
702 kFakeCoordY + 100); 722 kFakeCoordY + 100);
703 gesture_provider_->OnTouchEvent(event); 723 gesture_provider_->OnTouchEvent(event);
704 724
705 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 725 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
726 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
706 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 727 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
707 728
708 event = ObtainMotionEvent(event_time + long_press_timeout, 729 event = ObtainMotionEvent(event_time + long_press_timeout,
709 MotionEvent::ACTION_UP); 730 MotionEvent::ACTION_UP);
710 gesture_provider_->OnTouchEvent(event); 731 gesture_provider_->OnTouchEvent(event);
711 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 732 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
712 } 733 }
713 734
714 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { 735 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
715 base::TimeTicks event_time = base::TimeTicks::Now(); 736 base::TimeTicks event_time = base::TimeTicks::Now();
716 int motion_event_id = 0; 737 int motion_event_id = 0;
717 738
718 MockMotionEvent event = ObtainMotionEvent( 739 MockMotionEvent event = ObtainMotionEvent(
719 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 740 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
720 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 741 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
721 742
722 event = ObtainMotionEvent(event_time + kOneMicrosecond, 743 event = ObtainMotionEvent(event_time + kOneMicrosecond,
723 MotionEvent::ACTION_UP, 744 MotionEvent::ACTION_UP,
724 kFakeCoordX, 745 kFakeCoordX,
725 kFakeCoordY); 746 kFakeCoordY);
726 gesture_provider_->OnTouchEvent(event); 747 gesture_provider_->OnTouchEvent(event);
727 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 748 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
749 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
728 750
729 event = ObtainMotionEvent(event_time + kOneMicrosecond, 751 event = ObtainMotionEvent(event_time + kOneMicrosecond,
730 MotionEvent::ACTION_DOWN, 752 MotionEvent::ACTION_DOWN,
731 kFakeCoordX, 753 kFakeCoordX,
732 kFakeCoordY); 754 kFakeCoordY);
733 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 755 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
734 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 756 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
757 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
735 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); 758 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
736 759
737 const base::TimeDelta long_press_timeout = 760 const base::TimeDelta long_press_timeout =
738 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 761 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
739 RunTasksAndWait(long_press_timeout); 762 RunTasksAndWait(long_press_timeout);
740 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 763 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
741 764
742 event = ObtainMotionEvent(event_time + long_press_timeout, 765 event = ObtainMotionEvent(event_time + long_press_timeout,
743 MotionEvent::ACTION_MOVE, 766 MotionEvent::ACTION_MOVE,
744 kFakeCoordX + 20, 767 kFakeCoordX + 20,
745 kFakeCoordY + 20); 768 kFakeCoordY + 20);
746 event.SetId(++motion_event_id); 769 event.SetId(++motion_event_id);
747 770
748 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 771 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
749 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 772 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
750 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 773 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
774 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
751 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); 775 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
752 776
753 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond, 777 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
754 MotionEvent::ACTION_UP, 778 MotionEvent::ACTION_UP,
755 kFakeCoordX, 779 kFakeCoordX,
756 kFakeCoordY + 1); 780 kFakeCoordY + 1);
757 event.SetId(++motion_event_id); 781 event.SetId(++motion_event_id);
758 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 782 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
759 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 783 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
760 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 784 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
785 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
761 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress()); 786 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
762 } 787 }
763 788
764 // Verify that the touch slop region is removed from the first scroll delta to 789 // Verify that the touch slop region is removed from the first scroll delta to
765 // avoid a jump when starting to scroll. 790 // avoid a jump when starting to scroll.
766 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { 791 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
767 const int scaled_touch_slop = GetTouchSlop(); 792 const int scaled_touch_slop = GetTouchSlop();
768 const int scroll_delta = 5; 793 const int scroll_delta = 5;
769 794
770 base::TimeTicks event_time = base::TimeTicks::Now(); 795 base::TimeTicks event_time = base::TimeTicks::Now();
771 796
772 MockMotionEvent event = 797 MockMotionEvent event =
773 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 798 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
774 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 799 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
775 800
776 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 801 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
777 MotionEvent::ACTION_MOVE, 802 MotionEvent::ACTION_MOVE,
778 kFakeCoordX, 803 kFakeCoordX,
779 kFakeCoordY + scaled_touch_slop + scroll_delta); 804 kFakeCoordY + scaled_touch_slop + scroll_delta);
780 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 805 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
781 806
782 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 807 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
783 GestureEventData gesture = GetMostRecentGestureEvent(); 808 GestureEventData gesture = GetMostRecentGestureEvent();
784 EXPECT_EQ(0, gesture.details.scroll_x()); 809 EXPECT_EQ(0, gesture.details.scroll_x());
785 EXPECT_EQ(scroll_delta, gesture.details.scroll_y()); 810 EXPECT_EQ(scroll_delta, gesture.details.scroll_y());
811 EXPECT_EQ(1, gesture.details.touch_points());
786 } 812 }
787 813
788 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) { 814 TEST_F(GestureProviderTest, NoDoubleTapWhenExplicitlyDisabled) {
789 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 815 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
790 816
791 base::TimeTicks event_time = base::TimeTicks::Now(); 817 base::TimeTicks event_time = base::TimeTicks::Now();
792 MockMotionEvent event = ObtainMotionEvent( 818 MockMotionEvent event = ObtainMotionEvent(
793 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 819 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
794 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 820 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
795 EXPECT_EQ(1U, GetReceivedGestureCount()); 821 EXPECT_EQ(1U, GetReceivedGestureCount());
796 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 822 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
823 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
797 824
798 event = ObtainMotionEvent(event_time + kOneMicrosecond, 825 event = ObtainMotionEvent(event_time + kOneMicrosecond,
799 MotionEvent::ACTION_UP, 826 MotionEvent::ACTION_UP,
800 kFakeCoordX, 827 kFakeCoordX,
801 kFakeCoordY); 828 kFakeCoordY);
802 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 829 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
803 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 830 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
831 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
804 832
805 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 833 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
806 MotionEvent::ACTION_DOWN, 834 MotionEvent::ACTION_DOWN,
807 kFakeCoordX, 835 kFakeCoordX,
808 kFakeCoordY); 836 kFakeCoordY);
809 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 837 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
810 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 838 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
839 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
811 840
812 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 841 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
813 MotionEvent::ACTION_UP, 842 MotionEvent::ACTION_UP,
814 kFakeCoordX, 843 kFakeCoordX,
815 kFakeCoordY); 844 kFakeCoordY);
816 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 845 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
817 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 846 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
847 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
818 } 848 }
819 849
820 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) { 850 TEST_F(GestureProviderTest, NoDoubleTapDragZoomWhenDisabledOnPlatform) {
821 const base::TimeTicks down_time_1 = TimeTicks::Now(); 851 const base::TimeTicks down_time_1 = TimeTicks::Now();
822 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; 852 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
823 853
824 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 854 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
825 855
826 MockMotionEvent event = 856 MockMotionEvent event =
827 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 857 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
(...skipping 18 matching lines...) Expand all
846 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 876 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
847 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 877 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
848 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 878 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
849 879
850 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 880 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
851 MotionEvent::ACTION_MOVE, 881 MotionEvent::ACTION_MOVE,
852 kFakeCoordX, 882 kFakeCoordX,
853 kFakeCoordY + 200); 883 kFakeCoordY + 200);
854 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 884 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
855 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 885 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
886 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
856 EXPECT_EQ(down_time_2 + kOneMicrosecond * 2, 887 EXPECT_EQ(down_time_2 + kOneMicrosecond * 2,
857 GetMostRecentGestureEvent().time); 888 GetMostRecentGestureEvent().time);
858 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 889 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
859 890
860 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 891 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
861 MotionEvent::ACTION_UP, 892 MotionEvent::ACTION_UP,
862 kFakeCoordX, 893 kFakeCoordX,
863 kFakeCoordY + 200); 894 kFakeCoordY + 200);
864 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 895 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
865 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 896 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
897 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 928 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
898 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 929 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
899 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 930 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
900 931
901 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 932 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
902 MotionEvent::ACTION_MOVE, 933 MotionEvent::ACTION_MOVE,
903 kFakeCoordX, 934 kFakeCoordX,
904 kFakeCoordY + 200); 935 kFakeCoordY + 200);
905 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 936 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
906 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 937 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
938 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
907 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 939 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
908 940
909 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 941 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
910 MotionEvent::ACTION_UP, 942 MotionEvent::ACTION_UP,
911 kFakeCoordX, 943 kFakeCoordX,
912 kFakeCoordY + 200); 944 kFakeCoordY + 200);
913 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 945 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
914 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 946 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
915 } 947 }
916 948
(...skipping 18 matching lines...) Expand all
935 event = ObtainMotionEvent( 967 event = ObtainMotionEvent(
936 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 968 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
937 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 969 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
938 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 970 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
939 MotionEvent::ACTION_MOVE, 971 MotionEvent::ACTION_MOVE,
940 kFakeCoordX, 972 kFakeCoordX,
941 kFakeCoordY + 100); 973 kFakeCoordY + 100);
942 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 974 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
943 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 975 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
944 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 976 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
977 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
945 978
946 // Simulate setting a fixed page scale (or a mobile viewport); 979 // Simulate setting a fixed page scale (or a mobile viewport);
947 // this should not disrupt the current double-tap gesture. 980 // this should not disrupt the current double-tap gesture.
948 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 981 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
949 982
950 // Double tap zoom updates should continue. 983 // Double tap zoom updates should continue.
951 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 984 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
952 MotionEvent::ACTION_MOVE, 985 MotionEvent::ACTION_MOVE,
953 kFakeCoordX, 986 kFakeCoordX,
954 kFakeCoordY + 200); 987 kFakeCoordY + 200);
955 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 988 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
956 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); 989 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
990 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
957 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); 991 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
958 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 992 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
959 MotionEvent::ACTION_UP, 993 MotionEvent::ACTION_UP,
960 kFakeCoordX, 994 kFakeCoordX,
961 kFakeCoordY + 200); 995 kFakeCoordY + 200);
962 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 996 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
963 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 997 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_END));
964 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 998 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
999 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
965 1000
966 // The double-tap gesture has finished, but the page scale is fixed. 1001 // The double-tap gesture has finished, but the page scale is fixed.
967 // The same event sequence should not generate any double tap getsures. 1002 // The same event sequence should not generate any double tap getsures.
968 gestures_.clear(); 1003 gestures_.clear();
969 down_time_1 += kOneMicrosecond * 40; 1004 down_time_1 += kOneMicrosecond * 40;
970 down_time_2 += kOneMicrosecond * 40; 1005 down_time_2 += kOneMicrosecond * 40;
971 1006
972 // Start a double-tap drag gesture. 1007 // Start a double-tap drag gesture.
973 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1008 event = ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
974 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1009 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 gesture_provider_->SetMultiTouchSupportEnabled(true); 1051 gesture_provider_->SetMultiTouchSupportEnabled(true);
1017 1052
1018 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; 1053 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop;
1019 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; 1054 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop;
1020 1055
1021 MockMotionEvent event = 1056 MockMotionEvent event =
1022 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1057 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1023 event.SetId(++motion_event_id); 1058 event.SetId(++motion_event_id);
1024 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1059 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1025 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1060 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1061 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1026 1062
1027 // Toggling double-tap support should not take effect until the next sequence. 1063 // Toggling double-tap support should not take effect until the next sequence.
1028 gesture_provider_->SetDoubleTapSupportForPageEnabled(true); 1064 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1029 1065
1030 event = ObtainMotionEvent(event_time, 1066 event = ObtainMotionEvent(event_time,
1031 MotionEvent::ACTION_POINTER_DOWN, 1067 MotionEvent::ACTION_POINTER_DOWN,
1032 kFakeCoordX, 1068 kFakeCoordX,
1033 kFakeCoordY, 1069 kFakeCoordY,
1034 secondary_coord_x, 1070 secondary_coord_x,
1035 secondary_coord_y); 1071 secondary_coord_y);
1036 event.SetId(++motion_event_id); 1072 event.SetId(++motion_event_id);
1037 1073
1038 gesture_provider_->OnTouchEvent(event); 1074 gesture_provider_->OnTouchEvent(event);
1039 EXPECT_EQ(1U, GetReceivedGestureCount()); 1075 EXPECT_EQ(1U, GetReceivedGestureCount());
1076 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1040 1077
1041 secondary_coord_x += 5 * scaled_touch_slop; 1078 secondary_coord_x += 5 * scaled_touch_slop;
1042 secondary_coord_y += 5 * scaled_touch_slop; 1079 secondary_coord_y += 5 * scaled_touch_slop;
1043 event = ObtainMotionEvent(event_time, 1080 event = ObtainMotionEvent(event_time,
1044 MotionEvent::ACTION_MOVE, 1081 MotionEvent::ACTION_MOVE,
1045 kFakeCoordX, 1082 kFakeCoordX,
1046 kFakeCoordY, 1083 kFakeCoordY,
1047 secondary_coord_x, 1084 secondary_coord_x,
1048 secondary_coord_y); 1085 secondary_coord_y);
1049 event.SetId(++motion_event_id); 1086 event.SetId(++motion_event_id);
1050 1087
1051 // Toggling double-tap support should not take effect until the next sequence. 1088 // Toggling double-tap support should not take effect until the next sequence.
1052 gesture_provider_->SetDoubleTapSupportForPageEnabled(false); 1089 gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
1053 1090
1054 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1091 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1055 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1092 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1093 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1056 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1094 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1057 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1095 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1058 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1096 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1059 1097
1060 secondary_coord_x += 2 * scaled_touch_slop; 1098 secondary_coord_x += 2 * scaled_touch_slop;
1061 secondary_coord_y += 2 * scaled_touch_slop; 1099 secondary_coord_y += 2 * scaled_touch_slop;
1062 event = ObtainMotionEvent(event_time, 1100 event = ObtainMotionEvent(event_time,
1063 MotionEvent::ACTION_MOVE, 1101 MotionEvent::ACTION_MOVE,
1064 kFakeCoordX, 1102 kFakeCoordX,
1065 kFakeCoordY, 1103 kFakeCoordY,
1066 secondary_coord_x, 1104 secondary_coord_x,
1067 secondary_coord_y); 1105 secondary_coord_y);
1068 event.SetId(++motion_event_id); 1106 event.SetId(++motion_event_id);
1069 1107
1070 // Toggling double-tap support should not take effect until the next sequence. 1108 // Toggling double-tap support should not take effect until the next sequence.
1071 gesture_provider_->SetDoubleTapSupportForPageEnabled(true); 1109 gesture_provider_->SetDoubleTapSupportForPageEnabled(true);
1072 1110
1073 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1111 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1074 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1112 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1075 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1113 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1076 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType()); 1114 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1115 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1077 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale()); 1116 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
1078 1117
1079 event = ObtainMotionEvent(event_time, 1118 event = ObtainMotionEvent(event_time,
1080 MotionEvent::ACTION_POINTER_UP, 1119 MotionEvent::ACTION_POINTER_UP,
1081 kFakeCoordX, 1120 kFakeCoordX,
1082 kFakeCoordY, 1121 kFakeCoordY,
1083 secondary_coord_x, 1122 secondary_coord_x,
1084 secondary_coord_y); 1123 secondary_coord_y);
1085 event.SetId(++motion_event_id); 1124 event.SetId(++motion_event_id);
1086 1125
1087 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1126 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1088 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1127 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1089 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType()); 1128 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1129 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1090 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 1130 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
1091 1131
1092 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); 1132 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
1093 gesture_provider_->OnTouchEvent(event); 1133 gesture_provider_->OnTouchEvent(event);
1094 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1134 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1135 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1095 } 1136 }
1096 1137
1097 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins 1138 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1098 // so LONG_PRESS and LONG_TAP won't be triggered. 1139 // so LONG_PRESS and LONG_TAP won't be triggered.
1099 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) { 1140 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
1100 base::TimeTicks event_time = base::TimeTicks::Now(); 1141 base::TimeTicks event_time = base::TimeTicks::Now();
1101 1142
1102 MockMotionEvent event = 1143 MockMotionEvent event =
1103 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1144 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1104 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1145 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1105 1146
1106 const base::TimeDelta long_press_timeout = 1147 const base::TimeDelta long_press_timeout =
1107 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 1148 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
1108 RunTasksAndWait(long_press_timeout); 1149 RunTasksAndWait(long_press_timeout);
1109 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 1150 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
1151 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1110 1152
1111 EXPECT_TRUE(CancelActiveTouchSequence()); 1153 EXPECT_TRUE(CancelActiveTouchSequence());
1112 EXPECT_FALSE(HasDownEvent()); 1154 EXPECT_FALSE(HasDownEvent());
1113 1155
1114 event = ObtainMotionEvent(event_time + long_press_timeout, 1156 event = ObtainMotionEvent(event_time + long_press_timeout,
1115 MotionEvent::ACTION_UP); 1157 MotionEvent::ACTION_UP);
1116 gesture_provider_->OnTouchEvent(event); 1158 gesture_provider_->OnTouchEvent(event);
1117 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 1159 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
1118 } 1160 }
1119 1161
1120 // Verify that inserting a touch cancel event will trigger proper touch and 1162 // Verify that inserting a touch cancel event will trigger proper touch and
1121 // gesture sequence cancellation. 1163 // gesture sequence cancellation.
1122 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { 1164 TEST_F(GestureProviderTest, CancelActiveTouchSequence) {
1123 base::TimeTicks event_time = base::TimeTicks::Now(); 1165 base::TimeTicks event_time = base::TimeTicks::Now();
1124 int motion_event_id = 0; 1166 int motion_event_id = 0;
1125 1167
1126 EXPECT_FALSE(CancelActiveTouchSequence()); 1168 EXPECT_FALSE(CancelActiveTouchSequence());
1127 EXPECT_EQ(0U, GetReceivedGestureCount()); 1169 EXPECT_EQ(0U, GetReceivedGestureCount());
1128 1170
1129 MockMotionEvent event = 1171 MockMotionEvent event =
1130 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1172 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1131 event.SetId(++motion_event_id); 1173 event.SetId(++motion_event_id);
1132 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1174 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1133 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1175 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1134 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 1176 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1177 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1135 1178
1136 ASSERT_TRUE(CancelActiveTouchSequence()); 1179 ASSERT_TRUE(CancelActiveTouchSequence());
1137 EXPECT_FALSE(HasDownEvent()); 1180 EXPECT_FALSE(HasDownEvent());
1138 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
1139 1181
1140 // Subsequent MotionEvent's are dropped until ACTION_DOWN. 1182 // Subsequent MotionEvent's are dropped until ACTION_DOWN.
1141 event = ObtainMotionEvent(event_time + kOneMicrosecond, 1183 event = ObtainMotionEvent(event_time + kOneMicrosecond,
1142 MotionEvent::ACTION_MOVE); 1184 MotionEvent::ACTION_MOVE);
1143 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 1185 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1144 1186
1145 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 1187 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
1146 MotionEvent::ACTION_UP); 1188 MotionEvent::ACTION_UP);
1147 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 1189 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1148 1190
1149 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 1191 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
1150 MotionEvent::ACTION_DOWN); 1192 MotionEvent::ACTION_DOWN);
1151 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1193 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1152 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1194 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1195 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1153 } 1196 }
1154 1197
1155 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) { 1198 TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
1156 const base::TimeTicks down_time_1 = TimeTicks::Now(); 1199 const base::TimeTicks down_time_1 = TimeTicks::Now();
1157 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; 1200 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
1158 1201
1159 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 1202 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
1160 1203
1161 MockMotionEvent event = 1204 MockMotionEvent event =
1162 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); 1205 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN);
1163 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1206 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1164 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1207 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1208 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1165 1209
1166 event = 1210 event =
1167 ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::ACTION_UP); 1211 ObtainMotionEvent(down_time_1 + kOneMicrosecond, MotionEvent::ACTION_UP);
1168 gesture_provider_->OnTouchEvent(event); 1212 gesture_provider_->OnTouchEvent(event);
1169 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 1213 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
1214 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1170 1215
1171 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN); 1216 event = ObtainMotionEvent(down_time_2, MotionEvent::ACTION_DOWN);
1172 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1217 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1173 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1218 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1219 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1174 1220
1175 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, 1221 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond,
1176 MotionEvent::ACTION_MOVE, 1222 MotionEvent::ACTION_MOVE,
1177 kFakeCoordX, 1223 kFakeCoordX,
1178 kFakeCoordY - 30); 1224 kFakeCoordY - 30);
1179 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1225 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1180 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1226 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1181 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 1227 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
1228 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1182 1229
1183 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, 1230 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2,
1184 MotionEvent::ACTION_POINTER_DOWN, 1231 MotionEvent::ACTION_POINTER_DOWN,
1185 kFakeCoordX, 1232 kFakeCoordX,
1186 kFakeCoordY - 30, 1233 kFakeCoordY - 30,
1187 kFakeCoordX + 50, 1234 kFakeCoordX + 50,
1188 kFakeCoordY + 50); 1235 kFakeCoordY + 50);
1189 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1236 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1190 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType()); 1237 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1238 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1191 1239
1192 const size_t gesture_count = GetReceivedGestureCount(); 1240 const size_t gesture_count = GetReceivedGestureCount();
1193 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3, 1241 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 3,
1194 MotionEvent::ACTION_POINTER_UP, 1242 MotionEvent::ACTION_POINTER_UP,
1195 kFakeCoordX, 1243 kFakeCoordX,
1196 kFakeCoordY - 30, 1244 kFakeCoordY - 30,
1197 kFakeCoordX + 50, 1245 kFakeCoordX + 50,
1198 kFakeCoordY + 50); 1246 kFakeCoordY + 50);
1199 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1247 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1200 EXPECT_EQ(gesture_count, GetReceivedGestureCount()); 1248 EXPECT_EQ(gesture_count, GetReceivedGestureCount());
1201 1249
1202 event = ObtainMotionEvent(down_time_2 + kOneSecond, 1250 event = ObtainMotionEvent(down_time_2 + kOneSecond,
1203 MotionEvent::ACTION_UP); 1251 MotionEvent::ACTION_UP);
1204 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1252 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1205 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount()); 1253 EXPECT_EQ(gesture_count + 1, GetReceivedGestureCount());
1206 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1254 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1255 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1207 } 1256 }
1208 1257
1209 // Verify that gesture begin and gesture end events are dispatched correctly. 1258 // Verify that gesture begin and gesture end events are dispatched correctly.
1210 TEST_F(GestureProviderTest, GestureBeginAndEnd) { 1259 TEST_F(GestureProviderTest, GestureBeginAndEnd) {
1211 SetBeginEndTypesEnabled(true); 1260 SetBeginEndTypesEnabled(true);
1212 base::TimeTicks event_time = base::TimeTicks::Now(); 1261 base::TimeTicks event_time = base::TimeTicks::Now();
1213 1262
1214 EXPECT_EQ(0U, GetReceivedGestureCount()); 1263 EXPECT_EQ(0U, GetReceivedGestureCount());
1215 MockMotionEvent event = 1264 MockMotionEvent event =
1216 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1265 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1266 event.pointer_count = 1;
1217 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1267 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1218 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); 1268 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type);
1219 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1269 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1220 EXPECT_EQ(2U, GetReceivedGestureCount()); 1270 EXPECT_EQ(2U, GetReceivedGestureCount());
1271 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1221 1272
1222 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); 1273 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN);
1274 event.pointer_count = 2;
1223 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1275 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1224 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1276 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1225 EXPECT_EQ(3U, GetReceivedGestureCount()); 1277 EXPECT_EQ(3U, GetReceivedGestureCount());
1278 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1226 1279
1227 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); 1280 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN);
1281 event.pointer_count = 3;
1228 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1282 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1229 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1283 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1230 EXPECT_EQ(4U, GetReceivedGestureCount()); 1284 EXPECT_EQ(4U, GetReceivedGestureCount());
1285 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1231 1286
1232 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); 1287 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP);
1288 event.pointer_count = 2;
1233 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1289 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1234 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1290 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1235 EXPECT_EQ(5U, GetReceivedGestureCount()); 1291 EXPECT_EQ(5U, GetReceivedGestureCount());
1292 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1236 1293
1237 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); 1294 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN);
1295 event.pointer_count = 3;
1238 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1296 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1239 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); 1297 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
1240 EXPECT_EQ(6U, GetReceivedGestureCount()); 1298 EXPECT_EQ(6U, GetReceivedGestureCount());
1299 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1241 1300
1242 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); 1301 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP);
1302 event.pointer_count = 2;
1243 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1303 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1244 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1304 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1245 EXPECT_EQ(7U, GetReceivedGestureCount()); 1305 EXPECT_EQ(7U, GetReceivedGestureCount());
1306 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1246 1307
1247 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); 1308 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP);
1309 event.pointer_count = 1;
1248 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1310 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1249 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1311 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1250 EXPECT_EQ(8U, GetReceivedGestureCount()); 1312 EXPECT_EQ(8U, GetReceivedGestureCount());
1313 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1251 1314
1252 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); 1315 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
1316 event.pointer_count = 1;
1253 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1254 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1318 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1255 EXPECT_EQ(9U, GetReceivedGestureCount()); 1319 EXPECT_EQ(9U, GetReceivedGestureCount());
1320 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1256 1321
1257 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1322 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1323 event.pointer_count = 1;
1258 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1324 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1259 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(9).type); 1325 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(9).type);
1260 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1326 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1261 EXPECT_EQ(11U, GetReceivedGestureCount()); 1327 EXPECT_EQ(11U, GetReceivedGestureCount());
1328 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1262 1329
1263 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL); 1330 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL);
1331 event.pointer_count = 1;
1264 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1332 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1265 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1333 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1266 EXPECT_EQ(12U, GetReceivedGestureCount()); 1334 EXPECT_EQ(12U, GetReceivedGestureCount());
1267 1335 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1268
1269 } 1336 }
1270 1337
1271 } // namespace ui 1338 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | ui/events/gesture_detection/touch_disposition_gesture_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698