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

Side by Side Diff: ui/aura/gestures/gesture_recognizer_unittest.cc

Issue 10831240: Remove TouchEvent interface, and rename TouchEventImpl to TouchEvent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge-tot Created 8 years, 4 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
« no previous file with comments | « ui/aura/event_filter_unittest.cc ('k') | ui/aura/root_window.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_vector.h" 5 #include "base/memory/scoped_vector.h"
6 #include "base/string_number_conversions.h" 6 #include "base/string_number_conversions.h"
7 #include "base/timer.h" 7 #include "base/timer.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "ui/aura/root_window.h" 9 #include "ui/aura/root_window.h"
10 #include "ui/aura/test/aura_test_base.h" 10 #include "ui/aura/test/aura_test_base.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 }; 209 };
210 210
211 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 211 class QueueTouchEventDelegate : public GestureEventConsumeDelegate {
212 public: 212 public:
213 explicit QueueTouchEventDelegate(RootWindow* root_window) 213 explicit QueueTouchEventDelegate(RootWindow* root_window)
214 : window_(NULL), 214 : window_(NULL),
215 root_window_(root_window) { 215 root_window_(root_window) {
216 } 216 }
217 virtual ~QueueTouchEventDelegate() {} 217 virtual ~QueueTouchEventDelegate() {}
218 218
219 virtual ui::TouchStatus OnTouchEvent(ui::TouchEventImpl* event) OVERRIDE { 219 virtual ui::TouchStatus OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
220 return event->type() == ui::ET_TOUCH_RELEASED ? 220 return event->type() == ui::ET_TOUCH_RELEASED ?
221 ui::TOUCH_STATUS_QUEUED_END : ui::TOUCH_STATUS_QUEUED; 221 ui::TOUCH_STATUS_QUEUED_END : ui::TOUCH_STATUS_QUEUED;
222 } 222 }
223 223
224 void ReceivedAck() { 224 void ReceivedAck() {
225 root_window_->AdvanceQueuedTouchEvent(window_, false); 225 root_window_->AdvanceQueuedTouchEvent(window_, false);
226 } 226 }
227 227
228 void ReceivedAckPreventDefaulted() { 228 void ReceivedAckPreventDefaulted() {
229 root_window_->AdvanceQueuedTouchEvent(window_, true); 229 root_window_->AdvanceQueuedTouchEvent(window_, true);
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 int num_steps, 371 int num_steps,
372 GestureEventConsumeDelegate* delegate) { 372 GestureEventConsumeDelegate* delegate) {
373 int x = x_start; 373 int x = x_start;
374 int y = y_start; 374 int y = y_start;
375 base::TimeDelta time = time_start; 375 base::TimeDelta time = time_start;
376 376
377 for (int i = 0; i < num_steps; i++) { 377 for (int i = 0; i < num_steps; i++) {
378 x += dx; 378 x += dx;
379 y += dy; 379 y += dy;
380 time = time + base::TimeDelta::FromMilliseconds(time_step); 380 time = time + base::TimeDelta::FromMilliseconds(time_step);
381 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 381 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y),
382 touch_id, time); 382 touch_id, time);
383 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 383 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
384 } 384 }
385 } 385 }
386 386
387 void SendScrollEvent(RootWindow* root_window, 387 void SendScrollEvent(RootWindow* root_window,
388 int x, 388 int x,
389 int y, 389 int y,
390 int touch_id, 390 int touch_id,
391 GestureEventConsumeDelegate* delegate) { 391 GestureEventConsumeDelegate* delegate) {
392 delegate->Reset(); 392 delegate->Reset();
393 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 393 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y),
394 touch_id, GetTime()); 394 touch_id, GetTime());
395 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 395 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
396 } 396 }
397 397
398 } // namespace 398 } // namespace
399 399
400 typedef AuraTestBase GestureRecognizerTest; 400 typedef AuraTestBase GestureRecognizerTest;
401 401
402 // Check that appropriate touch events generate tap gesture events. 402 // Check that appropriate touch events generate tap gesture events.
403 TEST_F(GestureRecognizerTest, GestureEventTap) { 403 TEST_F(GestureRecognizerTest, GestureEventTap) {
404 scoped_ptr<GestureEventConsumeDelegate> delegate( 404 scoped_ptr<GestureEventConsumeDelegate> delegate(
405 new GestureEventConsumeDelegate()); 405 new GestureEventConsumeDelegate());
406 const int kWindowWidth = 123; 406 const int kWindowWidth = 123;
407 const int kWindowHeight = 45; 407 const int kWindowHeight = 45;
408 const int kTouchId = 2; 408 const int kTouchId = 2;
409 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 409 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
410 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 410 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
411 delegate.get(), -1234, bounds, NULL)); 411 delegate.get(), -1234, bounds, NULL));
412 412
413 delegate->Reset(); 413 delegate->Reset();
414 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 414 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
415 kTouchId, GetTime()); 415 kTouchId, GetTime());
416 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 416 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
417 EXPECT_FALSE(delegate->tap()); 417 EXPECT_FALSE(delegate->tap());
418 EXPECT_TRUE(delegate->tap_down()); 418 EXPECT_TRUE(delegate->tap_down());
419 EXPECT_TRUE(delegate->begin()); 419 EXPECT_TRUE(delegate->begin());
420 EXPECT_FALSE(delegate->double_tap()); 420 EXPECT_FALSE(delegate->double_tap());
421 EXPECT_FALSE(delegate->scroll_begin()); 421 EXPECT_FALSE(delegate->scroll_begin());
422 EXPECT_FALSE(delegate->scroll_update()); 422 EXPECT_FALSE(delegate->scroll_update());
423 EXPECT_FALSE(delegate->scroll_end()); 423 EXPECT_FALSE(delegate->scroll_end());
424 EXPECT_FALSE(delegate->long_press()); 424 EXPECT_FALSE(delegate->long_press());
425 425
426 // Make sure there is enough delay before the touch is released so that it is 426 // Make sure there is enough delay before the touch is released so that it is
427 // recognized as a tap. 427 // recognized as a tap.
428 delegate->Reset(); 428 delegate->Reset();
429 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 429 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
430 kTouchId, press.time_stamp() + 430 kTouchId, press.time_stamp() +
431 base::TimeDelta::FromMilliseconds(50)); 431 base::TimeDelta::FromMilliseconds(50));
432 432
433 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 433 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
434 EXPECT_TRUE(delegate->tap()); 434 EXPECT_TRUE(delegate->tap());
435 EXPECT_FALSE(delegate->tap_down()); 435 EXPECT_FALSE(delegate->tap_down());
436 EXPECT_FALSE(delegate->begin()); 436 EXPECT_FALSE(delegate->begin());
437 EXPECT_TRUE(delegate->end()); 437 EXPECT_TRUE(delegate->end());
438 EXPECT_FALSE(delegate->double_tap()); 438 EXPECT_FALSE(delegate->double_tap());
439 EXPECT_FALSE(delegate->scroll_begin()); 439 EXPECT_FALSE(delegate->scroll_begin());
(...skipping 11 matching lines...) Expand all
451 const int kWindowWidth = 800; 451 const int kWindowWidth = 800;
452 const int kWindowHeight = 600; 452 const int kWindowHeight = 600;
453 const int kTouchId = 2; 453 const int kTouchId = 2;
454 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 454 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
455 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 455 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
456 delegate.get(), -1234, bounds, NULL)); 456 delegate.get(), -1234, bounds, NULL));
457 457
458 // Test with no ET_TOUCH_MOVED events. 458 // Test with no ET_TOUCH_MOVED events.
459 { 459 {
460 delegate->Reset(); 460 delegate->Reset();
461 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 461 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
462 kTouchId, GetTime()); 462 kTouchId, GetTime());
463 press.set_radius_x(5); 463 press.set_radius_x(5);
464 press.set_radius_y(12); 464 press.set_radius_y(12);
465 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 465 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
466 EXPECT_FALSE(delegate->tap()); 466 EXPECT_FALSE(delegate->tap());
467 EXPECT_TRUE(delegate->tap_down()); 467 EXPECT_TRUE(delegate->tap_down());
468 EXPECT_TRUE(delegate->begin()); 468 EXPECT_TRUE(delegate->begin());
469 EXPECT_FALSE(delegate->double_tap()); 469 EXPECT_FALSE(delegate->double_tap());
470 EXPECT_FALSE(delegate->scroll_begin()); 470 EXPECT_FALSE(delegate->scroll_begin());
471 EXPECT_FALSE(delegate->scroll_update()); 471 EXPECT_FALSE(delegate->scroll_update());
472 EXPECT_FALSE(delegate->scroll_end()); 472 EXPECT_FALSE(delegate->scroll_end());
473 EXPECT_FALSE(delegate->long_press()); 473 EXPECT_FALSE(delegate->long_press());
474 474
475 // Make sure there is enough delay before the touch is released so that it 475 // Make sure there is enough delay before the touch is released so that it
476 // is recognized as a tap. 476 // is recognized as a tap.
477 delegate->Reset(); 477 delegate->Reset();
478 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 478 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
479 kTouchId, press.time_stamp() + 479 kTouchId, press.time_stamp() +
480 base::TimeDelta::FromMilliseconds(50)); 480 base::TimeDelta::FromMilliseconds(50));
481 release.set_radius_x(5); 481 release.set_radius_x(5);
482 release.set_radius_y(12); 482 release.set_radius_y(12);
483 483
484 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 484 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
485 EXPECT_TRUE(delegate->tap()); 485 EXPECT_TRUE(delegate->tap());
486 EXPECT_FALSE(delegate->tap_down()); 486 EXPECT_FALSE(delegate->tap_down());
487 EXPECT_FALSE(delegate->begin()); 487 EXPECT_FALSE(delegate->begin());
488 EXPECT_TRUE(delegate->end()); 488 EXPECT_TRUE(delegate->end());
489 EXPECT_FALSE(delegate->double_tap()); 489 EXPECT_FALSE(delegate->double_tap());
490 EXPECT_FALSE(delegate->scroll_begin()); 490 EXPECT_FALSE(delegate->scroll_begin());
491 EXPECT_FALSE(delegate->scroll_update()); 491 EXPECT_FALSE(delegate->scroll_update());
492 EXPECT_FALSE(delegate->scroll_end()); 492 EXPECT_FALSE(delegate->scroll_end());
493 493
494 EXPECT_EQ(1, delegate->tap_count()); 494 EXPECT_EQ(1, delegate->tap_count());
495 gfx::Point actual_point(delegate->tap_location()); 495 gfx::Point actual_point(delegate->tap_location());
496 EXPECT_EQ(24, delegate->bounding_box().width()); 496 EXPECT_EQ(24, delegate->bounding_box().width());
497 EXPECT_EQ(24, delegate->bounding_box().height()); 497 EXPECT_EQ(24, delegate->bounding_box().height());
498 EXPECT_EQ(100, actual_point.x()); 498 EXPECT_EQ(100, actual_point.x());
499 EXPECT_EQ(200, actual_point.y()); 499 EXPECT_EQ(200, actual_point.y());
500 } 500 }
501 501
502 // Test with no ET_TOUCH_MOVED events but different touch points and radii. 502 // Test with no ET_TOUCH_MOVED events but different touch points and radii.
503 { 503 {
504 delegate->Reset(); 504 delegate->Reset();
505 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), 505 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290),
506 kTouchId, GetTime()); 506 kTouchId, GetTime());
507 press.set_radius_x(8); 507 press.set_radius_x(8);
508 press.set_radius_y(14); 508 press.set_radius_y(14);
509 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 509 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
510 EXPECT_FALSE(delegate->tap()); 510 EXPECT_FALSE(delegate->tap());
511 EXPECT_TRUE(delegate->tap_down()); 511 EXPECT_TRUE(delegate->tap_down());
512 EXPECT_TRUE(delegate->begin()); 512 EXPECT_TRUE(delegate->begin());
513 EXPECT_FALSE(delegate->double_tap()); 513 EXPECT_FALSE(delegate->double_tap());
514 EXPECT_FALSE(delegate->scroll_begin()); 514 EXPECT_FALSE(delegate->scroll_begin());
515 EXPECT_FALSE(delegate->scroll_update()); 515 EXPECT_FALSE(delegate->scroll_update());
516 EXPECT_FALSE(delegate->scroll_end()); 516 EXPECT_FALSE(delegate->scroll_end());
517 EXPECT_FALSE(delegate->long_press()); 517 EXPECT_FALSE(delegate->long_press());
518 518
519 delegate->Reset(); 519 delegate->Reset();
520 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(377, 291), 520 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(377, 291),
521 kTouchId, press.time_stamp() + 521 kTouchId, press.time_stamp() +
522 base::TimeDelta::FromMilliseconds(50)); 522 base::TimeDelta::FromMilliseconds(50));
523 release.set_radius_x(20); 523 release.set_radius_x(20);
524 release.set_radius_y(13); 524 release.set_radius_y(13);
525 525
526 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 526 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
527 EXPECT_TRUE(delegate->tap()); 527 EXPECT_TRUE(delegate->tap());
528 EXPECT_FALSE(delegate->tap_down()); 528 EXPECT_FALSE(delegate->tap_down());
529 EXPECT_FALSE(delegate->begin()); 529 EXPECT_FALSE(delegate->begin());
530 EXPECT_TRUE(delegate->end()); 530 EXPECT_TRUE(delegate->end());
531 EXPECT_FALSE(delegate->double_tap()); 531 EXPECT_FALSE(delegate->double_tap());
532 EXPECT_FALSE(delegate->scroll_begin()); 532 EXPECT_FALSE(delegate->scroll_begin());
533 EXPECT_FALSE(delegate->scroll_update()); 533 EXPECT_FALSE(delegate->scroll_update());
534 EXPECT_FALSE(delegate->scroll_end()); 534 EXPECT_FALSE(delegate->scroll_end());
535 535
536 EXPECT_EQ(1, delegate->tap_count()); 536 EXPECT_EQ(1, delegate->tap_count());
537 gfx::Point actual_point(delegate->tap_location()); 537 gfx::Point actual_point(delegate->tap_location());
538 EXPECT_EQ(46, delegate->bounding_box().width()); 538 EXPECT_EQ(46, delegate->bounding_box().width());
539 EXPECT_EQ(40, delegate->bounding_box().height()); 539 EXPECT_EQ(40, delegate->bounding_box().height());
540 EXPECT_EQ(373, actual_point.x()); 540 EXPECT_EQ(373, actual_point.x());
541 EXPECT_EQ(290, actual_point.y()); 541 EXPECT_EQ(290, actual_point.y());
542 } 542 }
543 543
544 // Test with a single ET_TOUCH_MOVED event. 544 // Test with a single ET_TOUCH_MOVED event.
545 { 545 {
546 delegate->Reset(); 546 delegate->Reset();
547 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), 547 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205),
548 kTouchId, GetTime()); 548 kTouchId, GetTime());
549 press.set_radius_x(6); 549 press.set_radius_x(6);
550 press.set_radius_y(10); 550 press.set_radius_y(10);
551 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 551 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
552 EXPECT_FALSE(delegate->tap()); 552 EXPECT_FALSE(delegate->tap());
553 EXPECT_TRUE(delegate->tap_down()); 553 EXPECT_TRUE(delegate->tap_down());
554 EXPECT_TRUE(delegate->begin()); 554 EXPECT_TRUE(delegate->begin());
555 EXPECT_FALSE(delegate->double_tap()); 555 EXPECT_FALSE(delegate->double_tap());
556 EXPECT_FALSE(delegate->scroll_begin()); 556 EXPECT_FALSE(delegate->scroll_begin());
557 EXPECT_FALSE(delegate->scroll_update()); 557 EXPECT_FALSE(delegate->scroll_update());
558 EXPECT_FALSE(delegate->scroll_end()); 558 EXPECT_FALSE(delegate->scroll_end());
559 EXPECT_FALSE(delegate->long_press()); 559 EXPECT_FALSE(delegate->long_press());
560 560
561 delegate->Reset(); 561 delegate->Reset();
562 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(52, 200), 562 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(52, 200),
563 kTouchId, press.time_stamp() + 563 kTouchId, press.time_stamp() +
564 base::TimeDelta::FromMilliseconds(50)); 564 base::TimeDelta::FromMilliseconds(50));
565 move.set_radius_x(8); 565 move.set_radius_x(8);
566 move.set_radius_y(12); 566 move.set_radius_y(12);
567 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 567 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
568 EXPECT_FALSE(delegate->tap()); 568 EXPECT_FALSE(delegate->tap());
569 EXPECT_FALSE(delegate->tap_down()); 569 EXPECT_FALSE(delegate->tap_down());
570 EXPECT_FALSE(delegate->begin()); 570 EXPECT_FALSE(delegate->begin());
571 EXPECT_FALSE(delegate->double_tap()); 571 EXPECT_FALSE(delegate->double_tap());
572 EXPECT_FALSE(delegate->scroll_begin()); 572 EXPECT_FALSE(delegate->scroll_begin());
573 EXPECT_FALSE(delegate->scroll_update()); 573 EXPECT_FALSE(delegate->scroll_update());
574 EXPECT_FALSE(delegate->scroll_end()); 574 EXPECT_FALSE(delegate->scroll_end());
575 EXPECT_FALSE(delegate->long_press()); 575 EXPECT_FALSE(delegate->long_press());
576 576
577 delegate->Reset(); 577 delegate->Reset();
578 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(50, 195), 578 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(50, 195),
579 kTouchId, press.time_stamp() + 579 kTouchId, press.time_stamp() +
580 base::TimeDelta::FromMilliseconds(50)); 580 base::TimeDelta::FromMilliseconds(50));
581 release.set_radius_x(4); 581 release.set_radius_x(4);
582 release.set_radius_y(8); 582 release.set_radius_y(8);
583 583
584 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 584 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
585 EXPECT_TRUE(delegate->tap()); 585 EXPECT_TRUE(delegate->tap());
586 EXPECT_FALSE(delegate->tap_down()); 586 EXPECT_FALSE(delegate->tap_down());
587 EXPECT_FALSE(delegate->begin()); 587 EXPECT_FALSE(delegate->begin());
588 EXPECT_TRUE(delegate->end()); 588 EXPECT_TRUE(delegate->end());
589 EXPECT_FALSE(delegate->double_tap()); 589 EXPECT_FALSE(delegate->double_tap());
590 EXPECT_FALSE(delegate->scroll_begin()); 590 EXPECT_FALSE(delegate->scroll_begin());
591 EXPECT_FALSE(delegate->scroll_update()); 591 EXPECT_FALSE(delegate->scroll_update());
592 EXPECT_FALSE(delegate->scroll_end()); 592 EXPECT_FALSE(delegate->scroll_end());
593 593
594 EXPECT_EQ(1, delegate->tap_count()); 594 EXPECT_EQ(1, delegate->tap_count());
595 gfx::Point actual_point(delegate->tap_location()); 595 gfx::Point actual_point(delegate->tap_location());
596 EXPECT_EQ(28, delegate->bounding_box().width()); 596 EXPECT_EQ(28, delegate->bounding_box().width());
597 EXPECT_EQ(28, delegate->bounding_box().height()); 597 EXPECT_EQ(28, delegate->bounding_box().height());
598 EXPECT_EQ(49, actual_point.x()); 598 EXPECT_EQ(49, actual_point.x());
599 EXPECT_EQ(200, actual_point.y()); 599 EXPECT_EQ(200, actual_point.y());
600 } 600 }
601 601
602 // Test with a few ET_TOUCH_MOVED events. 602 // Test with a few ET_TOUCH_MOVED events.
603 { 603 {
604 delegate->Reset(); 604 delegate->Reset();
605 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), 605 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150),
606 kTouchId, GetTime()); 606 kTouchId, GetTime());
607 press.set_radius_x(7); 607 press.set_radius_x(7);
608 press.set_radius_y(10); 608 press.set_radius_y(10);
609 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 609 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
610 EXPECT_FALSE(delegate->tap()); 610 EXPECT_FALSE(delegate->tap());
611 EXPECT_TRUE(delegate->tap_down()); 611 EXPECT_TRUE(delegate->tap_down());
612 EXPECT_TRUE(delegate->begin()); 612 EXPECT_TRUE(delegate->begin());
613 EXPECT_FALSE(delegate->double_tap()); 613 EXPECT_FALSE(delegate->double_tap());
614 EXPECT_FALSE(delegate->scroll_begin()); 614 EXPECT_FALSE(delegate->scroll_begin());
615 EXPECT_FALSE(delegate->scroll_update()); 615 EXPECT_FALSE(delegate->scroll_update());
616 EXPECT_FALSE(delegate->scroll_end()); 616 EXPECT_FALSE(delegate->scroll_end());
617 EXPECT_FALSE(delegate->long_press()); 617 EXPECT_FALSE(delegate->long_press());
618 618
619 delegate->Reset(); 619 delegate->Reset();
620 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(397, 155), 620 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(397, 155),
621 kTouchId, press.time_stamp() + 621 kTouchId, press.time_stamp() +
622 base::TimeDelta::FromMilliseconds(50)); 622 base::TimeDelta::FromMilliseconds(50));
623 move.set_radius_x(13); 623 move.set_radius_x(13);
624 move.set_radius_y(12); 624 move.set_radius_y(12);
625 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 625 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
626 EXPECT_FALSE(delegate->tap()); 626 EXPECT_FALSE(delegate->tap());
627 EXPECT_FALSE(delegate->tap_down()); 627 EXPECT_FALSE(delegate->tap_down());
628 EXPECT_FALSE(delegate->begin()); 628 EXPECT_FALSE(delegate->begin());
629 EXPECT_FALSE(delegate->double_tap()); 629 EXPECT_FALSE(delegate->double_tap());
630 EXPECT_FALSE(delegate->scroll_begin()); 630 EXPECT_FALSE(delegate->scroll_begin());
631 EXPECT_FALSE(delegate->scroll_update()); 631 EXPECT_FALSE(delegate->scroll_update());
632 EXPECT_FALSE(delegate->scroll_end()); 632 EXPECT_FALSE(delegate->scroll_end());
633 EXPECT_FALSE(delegate->long_press()); 633 EXPECT_FALSE(delegate->long_press());
634 634
635 delegate->Reset(); 635 delegate->Reset();
636 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(395, 148), 636 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(395, 148),
637 kTouchId, move.time_stamp() + 637 kTouchId, move.time_stamp() +
638 base::TimeDelta::FromMilliseconds(50)); 638 base::TimeDelta::FromMilliseconds(50));
639 move1.set_radius_x(16); 639 move1.set_radius_x(16);
640 move1.set_radius_y(16); 640 move1.set_radius_y(16);
641 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 641 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
642 EXPECT_FALSE(delegate->tap()); 642 EXPECT_FALSE(delegate->tap());
643 EXPECT_FALSE(delegate->tap_down()); 643 EXPECT_FALSE(delegate->tap_down());
644 EXPECT_FALSE(delegate->begin()); 644 EXPECT_FALSE(delegate->begin());
645 EXPECT_FALSE(delegate->double_tap()); 645 EXPECT_FALSE(delegate->double_tap());
646 EXPECT_FALSE(delegate->scroll_begin()); 646 EXPECT_FALSE(delegate->scroll_begin());
647 EXPECT_FALSE(delegate->scroll_update()); 647 EXPECT_FALSE(delegate->scroll_update());
648 EXPECT_FALSE(delegate->scroll_end()); 648 EXPECT_FALSE(delegate->scroll_end());
649 EXPECT_FALSE(delegate->long_press()); 649 EXPECT_FALSE(delegate->long_press());
650 650
651 delegate->Reset(); 651 delegate->Reset();
652 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150), 652 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150),
653 kTouchId, move1.time_stamp() + 653 kTouchId, move1.time_stamp() +
654 base::TimeDelta::FromMilliseconds(50)); 654 base::TimeDelta::FromMilliseconds(50));
655 move2.set_radius_x(14); 655 move2.set_radius_x(14);
656 move2.set_radius_y(10); 656 move2.set_radius_y(10);
657 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 657 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
658 EXPECT_FALSE(delegate->tap()); 658 EXPECT_FALSE(delegate->tap());
659 EXPECT_FALSE(delegate->tap_down()); 659 EXPECT_FALSE(delegate->tap_down());
660 EXPECT_FALSE(delegate->begin()); 660 EXPECT_FALSE(delegate->begin());
661 EXPECT_FALSE(delegate->double_tap()); 661 EXPECT_FALSE(delegate->double_tap());
662 EXPECT_FALSE(delegate->scroll_begin()); 662 EXPECT_FALSE(delegate->scroll_begin());
663 EXPECT_FALSE(delegate->scroll_update()); 663 EXPECT_FALSE(delegate->scroll_update());
664 EXPECT_FALSE(delegate->scroll_end()); 664 EXPECT_FALSE(delegate->scroll_end());
665 EXPECT_FALSE(delegate->long_press()); 665 EXPECT_FALSE(delegate->long_press());
666 666
667 delegate->Reset(); 667 delegate->Reset();
668 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149), 668 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149),
669 kTouchId, press.time_stamp() + 669 kTouchId, press.time_stamp() +
670 base::TimeDelta::FromMilliseconds(50)); 670 base::TimeDelta::FromMilliseconds(50));
671 release.set_radius_x(8); 671 release.set_radius_x(8);
672 release.set_radius_y(9); 672 release.set_radius_y(9);
673 673
674 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 674 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
675 EXPECT_TRUE(delegate->tap()); 675 EXPECT_TRUE(delegate->tap());
676 EXPECT_FALSE(delegate->tap_down()); 676 EXPECT_FALSE(delegate->tap_down());
677 EXPECT_FALSE(delegate->begin()); 677 EXPECT_FALSE(delegate->begin());
678 EXPECT_TRUE(delegate->end()); 678 EXPECT_TRUE(delegate->end());
(...skipping 16 matching lines...) Expand all
695 scoped_ptr<GestureEventConsumeDelegate> delegate( 695 scoped_ptr<GestureEventConsumeDelegate> delegate(
696 new GestureEventConsumeDelegate()); 696 new GestureEventConsumeDelegate());
697 const int kWindowWidth = 123; 697 const int kWindowWidth = 123;
698 const int kWindowHeight = 45; 698 const int kWindowHeight = 45;
699 const int kTouchId = 5; 699 const int kTouchId = 5;
700 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 700 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
701 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 701 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
702 delegate.get(), -1234, bounds, NULL)); 702 delegate.get(), -1234, bounds, NULL));
703 703
704 delegate->Reset(); 704 delegate->Reset();
705 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 705 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
706 kTouchId, GetTime()); 706 kTouchId, GetTime());
707 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 707 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
708 EXPECT_FALSE(delegate->tap()); 708 EXPECT_FALSE(delegate->tap());
709 EXPECT_TRUE(delegate->tap_down()); 709 EXPECT_TRUE(delegate->tap_down());
710 EXPECT_TRUE(delegate->begin()); 710 EXPECT_TRUE(delegate->begin());
711 EXPECT_FALSE(delegate->double_tap()); 711 EXPECT_FALSE(delegate->double_tap());
712 EXPECT_FALSE(delegate->scroll_begin()); 712 EXPECT_FALSE(delegate->scroll_begin());
713 EXPECT_FALSE(delegate->scroll_update()); 713 EXPECT_FALSE(delegate->scroll_update());
714 EXPECT_FALSE(delegate->scroll_end()); 714 EXPECT_FALSE(delegate->scroll_end());
715 715
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 EXPECT_FALSE(delegate->double_tap()); 754 EXPECT_FALSE(delegate->double_tap());
755 EXPECT_FALSE(delegate->scroll_begin()); 755 EXPECT_FALSE(delegate->scroll_begin());
756 EXPECT_TRUE(delegate->scroll_update()); 756 EXPECT_TRUE(delegate->scroll_update());
757 EXPECT_FALSE(delegate->scroll_end()); 757 EXPECT_FALSE(delegate->scroll_end());
758 EXPECT_EQ(30, delegate->scroll_x()); 758 EXPECT_EQ(30, delegate->scroll_x());
759 EXPECT_EQ(4, delegate->scroll_y()); 759 EXPECT_EQ(4, delegate->scroll_y());
760 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 760 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
761 761
762 // Release the touch. This should end the scroll. 762 // Release the touch. This should end the scroll.
763 delegate->Reset(); 763 delegate->Reset();
764 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 764 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
765 kTouchId, press.time_stamp() + 765 kTouchId, press.time_stamp() +
766 base::TimeDelta::FromMilliseconds(50)); 766 base::TimeDelta::FromMilliseconds(50));
767 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 767 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
768 EXPECT_FALSE(delegate->tap()); 768 EXPECT_FALSE(delegate->tap());
769 EXPECT_FALSE(delegate->tap_down()); 769 EXPECT_FALSE(delegate->tap_down());
770 EXPECT_FALSE(delegate->begin()); 770 EXPECT_FALSE(delegate->begin());
771 EXPECT_TRUE(delegate->end()); 771 EXPECT_TRUE(delegate->end());
772 EXPECT_FALSE(delegate->double_tap()); 772 EXPECT_FALSE(delegate->double_tap());
773 EXPECT_FALSE(delegate->scroll_begin()); 773 EXPECT_FALSE(delegate->scroll_begin());
774 EXPECT_FALSE(delegate->scroll_update()); 774 EXPECT_FALSE(delegate->scroll_update());
(...skipping 10 matching lines...) Expand all
785 const int kWindowWidth = 123; 785 const int kWindowWidth = 123;
786 const int kWindowHeight = 45; 786 const int kWindowHeight = 45;
787 const int kTouchId = 5; 787 const int kTouchId = 5;
788 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 788 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
789 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 789 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
790 delegate.get(), -1234, bounds, NULL)); 790 delegate.get(), -1234, bounds, NULL));
791 791
792 const int kPositionX = 101; 792 const int kPositionX = 101;
793 const int kPositionY = 201; 793 const int kPositionY = 201;
794 delegate->Reset(); 794 delegate->Reset();
795 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, 795 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
796 gfx::Point(kPositionX, kPositionY), 796 gfx::Point(kPositionX, kPositionY),
797 kTouchId, 797 kTouchId,
798 GetTime()); 798 GetTime());
799 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 799 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
800 EXPECT_EQ(gfx::Rect(kPositionX - radius, 800 EXPECT_EQ(gfx::Rect(kPositionX - radius,
801 kPositionY - radius, 801 kPositionY - radius,
802 radius * 2, 802 radius * 2,
803 radius * 2).ToString(), 803 radius * 2).ToString(),
804 delegate->bounding_box().ToString()); 804 delegate->bounding_box().ToString());
805 805
806 const int kScrollAmount = 50; 806 const int kScrollAmount = 50;
807 SendScrollEvents(root_window(), kPositionX, kPositionY, GetTime(), 807 SendScrollEvents(root_window(), kPositionX, kPositionY, GetTime(),
808 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); 808 1, 1, kTouchId, 1, kScrollAmount, delegate.get());
809 EXPECT_EQ(gfx::Point(1, 1).ToString(), 809 EXPECT_EQ(gfx::Point(1, 1).ToString(),
810 delegate->scroll_begin_position().ToString()); 810 delegate->scroll_begin_position().ToString());
811 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, 811 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius,
812 kPositionY + kScrollAmount - radius, 812 kPositionY + kScrollAmount - radius,
813 radius * 2, 813 radius * 2,
814 radius * 2).ToString(), 814 radius * 2).ToString(),
815 delegate->bounding_box().ToString()); 815 delegate->bounding_box().ToString());
816 816
817 // Release the touch. This should end the scroll. 817 // Release the touch. This should end the scroll.
818 delegate->Reset(); 818 delegate->Reset();
819 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, 819 ui::TouchEvent release(ui::ET_TOUCH_RELEASED,
820 gfx::Point(kPositionX, kPositionY), 820 gfx::Point(kPositionX, kPositionY),
821 kTouchId, press.time_stamp() + 821 kTouchId, press.time_stamp() +
822 base::TimeDelta::FromMilliseconds(50)); 822 base::TimeDelta::FromMilliseconds(50));
823 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 823 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
824 EXPECT_EQ(gfx::Rect(kPositionX - radius, 824 EXPECT_EQ(gfx::Rect(kPositionX - radius,
825 kPositionY - radius, 825 kPositionY - radius,
826 radius * 2, 826 radius * 2,
827 radius * 2).ToString(), 827 radius * 2).ToString(),
828 delegate->bounding_box().ToString()); 828 delegate->bounding_box().ToString());
829 } 829 }
830 ui::GestureConfiguration::set_default_radius(0); 830 ui::GestureConfiguration::set_default_radius(0);
831 } 831 }
832 832
833 // Check Scroll End Events report correct velocities 833 // Check Scroll End Events report correct velocities
834 // if the user was on a horizontal rail 834 // if the user was on a horizontal rail
835 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { 835 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) {
836 scoped_ptr<GestureEventConsumeDelegate> delegate( 836 scoped_ptr<GestureEventConsumeDelegate> delegate(
837 new GestureEventConsumeDelegate()); 837 new GestureEventConsumeDelegate());
838 const int kTouchId = 7; 838 const int kTouchId = 7;
839 gfx::Rect bounds(0, 0, 1000, 1000); 839 gfx::Rect bounds(0, 0, 1000, 1000);
840 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 840 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
841 delegate.get(), -1234, bounds, NULL)); 841 delegate.get(), -1234, bounds, NULL));
842 842
843 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 843 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
844 kTouchId, GetTime()); 844 kTouchId, GetTime());
845 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 845 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
846 846
847 // Move the touch-point horizontally enough that it is considered a 847 // Move the touch-point horizontally enough that it is considered a
848 // horizontal scroll. 848 // horizontal scroll.
849 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 849 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
850 EXPECT_EQ(0, delegate->scroll_y()); 850 EXPECT_EQ(0, delegate->scroll_y());
851 EXPECT_EQ(20, delegate->scroll_x()); 851 EXPECT_EQ(20, delegate->scroll_x());
852 852
853 // Get a high x velocity, while still staying on the rail 853 // Get a high x velocity, while still staying on the rail
854 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 854 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
855 100, 10, kTouchId, 1, 855 100, 10, kTouchId, 1,
856 ui::GestureConfiguration::points_buffered_for_velocity(), 856 ui::GestureConfiguration::points_buffered_for_velocity(),
857 delegate.get()); 857 delegate.get());
858 858
859 delegate->Reset(); 859 delegate->Reset();
860 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 860 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
861 kTouchId, GetTime()); 861 kTouchId, GetTime());
862 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 862 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
863 863
864 EXPECT_TRUE(delegate->fling()); 864 EXPECT_TRUE(delegate->fling());
865 EXPECT_FALSE(delegate->scroll_end()); 865 EXPECT_FALSE(delegate->scroll_end());
866 EXPECT_GT(delegate->velocity_x(), 0); 866 EXPECT_GT(delegate->velocity_x(), 0);
867 EXPECT_EQ(0, delegate->velocity_y()); 867 EXPECT_EQ(0, delegate->velocity_y());
868 } 868 }
869 869
870 // Check Scroll End Events report correct velocities 870 // Check Scroll End Events report correct velocities
871 // if the user was on a vertical rail 871 // if the user was on a vertical rail
872 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { 872 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) {
873 scoped_ptr<GestureEventConsumeDelegate> delegate( 873 scoped_ptr<GestureEventConsumeDelegate> delegate(
874 new GestureEventConsumeDelegate()); 874 new GestureEventConsumeDelegate());
875 const int kTouchId = 7; 875 const int kTouchId = 7;
876 gfx::Rect bounds(0, 0, 1000, 1000); 876 gfx::Rect bounds(0, 0, 1000, 1000);
877 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 877 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
878 delegate.get(), -1234, bounds, NULL)); 878 delegate.get(), -1234, bounds, NULL));
879 879
880 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 880 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
881 kTouchId, GetTime()); 881 kTouchId, GetTime());
882 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 882 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
883 883
884 // Move the touch-point vertically enough that it is considered a 884 // Move the touch-point vertically enough that it is considered a
885 // vertical scroll. 885 // vertical scroll.
886 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 886 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
887 EXPECT_EQ(20, delegate->scroll_y()); 887 EXPECT_EQ(20, delegate->scroll_y());
888 EXPECT_EQ(0, delegate->scroll_x()); 888 EXPECT_EQ(0, delegate->scroll_x());
889 889
890 // Get a high y velocity, while still staying on the rail 890 // Get a high y velocity, while still staying on the rail
891 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 891 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
892 10, 100, kTouchId, 1, 892 10, 100, kTouchId, 1,
893 ui::GestureConfiguration::points_buffered_for_velocity(), 893 ui::GestureConfiguration::points_buffered_for_velocity(),
894 delegate.get()); 894 delegate.get());
895 895
896 delegate->Reset(); 896 delegate->Reset();
897 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 897 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
898 kTouchId, GetTime()); 898 kTouchId, GetTime());
899 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 899 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
900 900
901 EXPECT_TRUE(delegate->fling()); 901 EXPECT_TRUE(delegate->fling());
902 EXPECT_FALSE(delegate->scroll_end()); 902 EXPECT_FALSE(delegate->scroll_end());
903 EXPECT_EQ(0, delegate->velocity_x()); 903 EXPECT_EQ(0, delegate->velocity_x());
904 EXPECT_GT(delegate->velocity_y(), 0); 904 EXPECT_GT(delegate->velocity_y(), 0);
905 } 905 }
906 906
907 // Check Scroll End Events reports zero velocities 907 // Check Scroll End Events reports zero velocities
908 // if the user is not on a rail 908 // if the user is not on a rail
909 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 909 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) {
910 scoped_ptr<GestureEventConsumeDelegate> delegate( 910 scoped_ptr<GestureEventConsumeDelegate> delegate(
911 new GestureEventConsumeDelegate()); 911 new GestureEventConsumeDelegate());
912 const int kTouchId = 7; 912 const int kTouchId = 7;
913 gfx::Rect bounds(0, 0, 1000, 1000); 913 gfx::Rect bounds(0, 0, 1000, 1000);
914 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 914 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
915 delegate.get(), -1234, bounds, NULL)); 915 delegate.get(), -1234, bounds, NULL));
916 916
917 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 917 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
918 kTouchId, GetTime()); 918 kTouchId, GetTime());
919 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 919 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
920 920
921 // Move the touch-point such that a non-rail scroll begins 921 // Move the touch-point such that a non-rail scroll begins
922 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); 922 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get());
923 EXPECT_EQ(20, delegate->scroll_y()); 923 EXPECT_EQ(20, delegate->scroll_y());
924 EXPECT_EQ(20, delegate->scroll_x()); 924 EXPECT_EQ(20, delegate->scroll_x());
925 925
926 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), 926 SendScrollEvents(root_window(), 1, 1, press.time_stamp(),
927 10, 100, kTouchId, 1, 927 10, 100, kTouchId, 1,
928 ui::GestureConfiguration::points_buffered_for_velocity(), 928 ui::GestureConfiguration::points_buffered_for_velocity(),
929 delegate.get()); 929 delegate.get());
930 930
931 delegate->Reset(); 931 delegate->Reset();
932 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 932 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
933 kTouchId, GetTime()); 933 kTouchId, GetTime());
934 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 934 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
935 935
936 EXPECT_TRUE(delegate->fling()); 936 EXPECT_TRUE(delegate->fling());
937 EXPECT_FALSE(delegate->scroll_end()); 937 EXPECT_FALSE(delegate->scroll_end());
938 EXPECT_GT(delegate->velocity_x(), 0); 938 EXPECT_GT(delegate->velocity_x(), 0);
939 EXPECT_GT(delegate->velocity_y(), 0); 939 EXPECT_GT(delegate->velocity_y(), 0);
940 } 940 }
941 941
942 // Check that appropriate touch events generate long press events 942 // Check that appropriate touch events generate long press events
(...skipping 10 matching lines...) Expand all
953 delegate->Reset(); 953 delegate->Reset();
954 954
955 TimerTestGestureRecognizer* gesture_recognizer = 955 TimerTestGestureRecognizer* gesture_recognizer =
956 new TimerTestGestureRecognizer(root_window()); 956 new TimerTestGestureRecognizer(root_window());
957 TimerTestGestureSequence* gesture_sequence = 957 TimerTestGestureSequence* gesture_sequence =
958 static_cast<TimerTestGestureSequence*>( 958 static_cast<TimerTestGestureSequence*>(
959 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 959 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
960 960
961 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 961 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
962 962
963 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 963 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
964 kTouchId, GetTime()); 964 kTouchId, GetTime());
965 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 965 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
966 EXPECT_TRUE(delegate->tap_down()); 966 EXPECT_TRUE(delegate->tap_down());
967 EXPECT_TRUE(delegate->begin()); 967 EXPECT_TRUE(delegate->begin());
968 968
969 // We haven't pressed long enough for a long press to occur 969 // We haven't pressed long enough for a long press to occur
970 EXPECT_FALSE(delegate->long_press()); 970 EXPECT_FALSE(delegate->long_press());
971 971
972 // Wait until the timer runs out 972 // Wait until the timer runs out
973 gesture_sequence->ForceTimeout(); 973 gesture_sequence->ForceTimeout();
974 EXPECT_TRUE(delegate->long_press()); 974 EXPECT_TRUE(delegate->long_press());
975 EXPECT_EQ(0, delegate->touch_id()); 975 EXPECT_EQ(0, delegate->touch_id());
976 976
977 delegate->Reset(); 977 delegate->Reset();
978 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 978 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
979 kTouchId, GetTime()); 979 kTouchId, GetTime());
980 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 980 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
981 EXPECT_FALSE(delegate->long_press()); 981 EXPECT_FALSE(delegate->long_press());
982 } 982 }
983 983
984 // Check that scrolling cancels a long press 984 // Check that scrolling cancels a long press
985 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 985 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) {
986 scoped_ptr<GestureEventConsumeDelegate> delegate( 986 scoped_ptr<GestureEventConsumeDelegate> delegate(
987 new GestureEventConsumeDelegate()); 987 new GestureEventConsumeDelegate());
988 const int kWindowWidth = 123; 988 const int kWindowWidth = 123;
989 const int kWindowHeight = 45; 989 const int kWindowHeight = 45;
990 const int kTouchId = 6; 990 const int kTouchId = 6;
991 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 991 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
992 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 992 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
993 delegate.get(), -1234, bounds, NULL)); 993 delegate.get(), -1234, bounds, NULL));
994 994
995 delegate->Reset(); 995 delegate->Reset();
996 996
997 TimerTestGestureRecognizer* gesture_recognizer = 997 TimerTestGestureRecognizer* gesture_recognizer =
998 new TimerTestGestureRecognizer(root_window()); 998 new TimerTestGestureRecognizer(root_window());
999 TimerTestGestureSequence* gesture_sequence = 999 TimerTestGestureSequence* gesture_sequence =
1000 static_cast<TimerTestGestureSequence*>( 1000 static_cast<TimerTestGestureSequence*>(
1001 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 1001 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
1002 1002
1003 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1003 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
1004 1004
1005 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1005 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1006 kTouchId, GetTime()); 1006 kTouchId, GetTime());
1007 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1007 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1008 EXPECT_TRUE(delegate->tap_down()); 1008 EXPECT_TRUE(delegate->tap_down());
1009 1009
1010 // We haven't pressed long enough for a long press to occur 1010 // We haven't pressed long enough for a long press to occur
1011 EXPECT_FALSE(delegate->long_press()); 1011 EXPECT_FALSE(delegate->long_press());
1012 1012
1013 // Scroll around, to cancel the long press 1013 // Scroll around, to cancel the long press
1014 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 1014 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
1015 // Wait until the timer runs out 1015 // Wait until the timer runs out
1016 gesture_sequence->ForceTimeout(); 1016 gesture_sequence->ForceTimeout();
1017 EXPECT_FALSE(delegate->long_press()); 1017 EXPECT_FALSE(delegate->long_press());
1018 1018
1019 delegate->Reset(); 1019 delegate->Reset();
1020 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1020 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1021 kTouchId, GetTime()); 1021 kTouchId, GetTime());
1022 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1022 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1023 EXPECT_FALSE(delegate->long_press()); 1023 EXPECT_FALSE(delegate->long_press());
1024 } 1024 }
1025 1025
1026 // Check that second tap cancels a long press 1026 // Check that second tap cancels a long press
1027 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1027 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) {
1028 scoped_ptr<GestureEventConsumeDelegate> delegate( 1028 scoped_ptr<GestureEventConsumeDelegate> delegate(
1029 new GestureEventConsumeDelegate()); 1029 new GestureEventConsumeDelegate());
1030 const int kWindowWidth = 300; 1030 const int kWindowWidth = 300;
1031 const int kWindowHeight = 400; 1031 const int kWindowHeight = 400;
1032 const int kTouchId1 = 8; 1032 const int kTouchId1 = 8;
1033 const int kTouchId2 = 2; 1033 const int kTouchId2 = 2;
1034 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1034 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1035 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1035 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1036 delegate.get(), -1234, bounds, NULL)); 1036 delegate.get(), -1234, bounds, NULL));
1037 1037
1038 TimerTestGestureRecognizer* gesture_recognizer = 1038 TimerTestGestureRecognizer* gesture_recognizer =
1039 new TimerTestGestureRecognizer(root_window()); 1039 new TimerTestGestureRecognizer(root_window());
1040 TimerTestGestureSequence* gesture_sequence = 1040 TimerTestGestureSequence* gesture_sequence =
1041 static_cast<TimerTestGestureSequence*>( 1041 static_cast<TimerTestGestureSequence*>(
1042 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 1042 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
1043 1043
1044 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1044 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
1045 1045
1046 delegate->Reset(); 1046 delegate->Reset();
1047 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1047 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1048 kTouchId1, GetTime()); 1048 kTouchId1, GetTime());
1049 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1049 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1050 EXPECT_TRUE(delegate->tap_down()); 1050 EXPECT_TRUE(delegate->tap_down());
1051 EXPECT_TRUE(delegate->begin()); 1051 EXPECT_TRUE(delegate->begin());
1052 1052
1053 // We haven't pressed long enough for a long press to occur 1053 // We haven't pressed long enough for a long press to occur
1054 EXPECT_FALSE(delegate->long_press()); 1054 EXPECT_FALSE(delegate->long_press());
1055 1055
1056 // Second tap, to cancel the long press 1056 // Second tap, to cancel the long press
1057 delegate->Reset(); 1057 delegate->Reset();
1058 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1058 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1059 kTouchId2, GetTime()); 1059 kTouchId2, GetTime());
1060 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1060 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1061 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1061 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1062 EXPECT_TRUE(delegate->begin()); 1062 EXPECT_TRUE(delegate->begin());
1063 1063
1064 // Wait until the timer runs out 1064 // Wait until the timer runs out
1065 gesture_sequence->ForceTimeout(); 1065 gesture_sequence->ForceTimeout();
1066 1066
1067 // No long press occurred 1067 // No long press occurred
1068 EXPECT_FALSE(delegate->long_press()); 1068 EXPECT_FALSE(delegate->long_press());
1069 1069
1070 delegate->Reset(); 1070 delegate->Reset();
1071 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1071 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1072 kTouchId1, GetTime()); 1072 kTouchId1, GetTime());
1073 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1073 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1074 EXPECT_FALSE(delegate->long_press()); 1074 EXPECT_FALSE(delegate->long_press());
1075 EXPECT_TRUE(delegate->two_finger_tap()); 1075 EXPECT_TRUE(delegate->two_finger_tap());
1076 } 1076 }
1077 1077
1078 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 1078 // Check that horizontal scroll gestures cause scrolls on horizontal rails.
1079 // Also tests that horizontal rails can be broken. 1079 // Also tests that horizontal rails can be broken.
1080 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 1080 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) {
1081 scoped_ptr<GestureEventConsumeDelegate> delegate( 1081 scoped_ptr<GestureEventConsumeDelegate> delegate(
1082 new GestureEventConsumeDelegate()); 1082 new GestureEventConsumeDelegate());
1083 const int kTouchId = 7; 1083 const int kTouchId = 7;
1084 gfx::Rect bounds(0, 0, 1000, 1000); 1084 gfx::Rect bounds(0, 0, 1000, 1000);
1085 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1085 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1086 delegate.get(), -1234, bounds, NULL)); 1086 delegate.get(), -1234, bounds, NULL));
1087 1087
1088 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1088 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1089 kTouchId, GetTime()); 1089 kTouchId, GetTime());
1090 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1090 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1091 1091
1092 // Move the touch-point horizontally enough that it is considered a 1092 // Move the touch-point horizontally enough that it is considered a
1093 // horizontal scroll. 1093 // horizontal scroll.
1094 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 1094 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get());
1095 EXPECT_EQ(0, delegate->scroll_y()); 1095 EXPECT_EQ(0, delegate->scroll_y());
1096 EXPECT_EQ(20, delegate->scroll_x()); 1096 EXPECT_EQ(20, delegate->scroll_x());
1097 1097
1098 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); 1098 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get());
(...skipping 21 matching lines...) Expand all
1120 // Check that vertical scroll gestures cause scrolls on vertical rails. 1120 // Check that vertical scroll gestures cause scrolls on vertical rails.
1121 // Also tests that vertical rails can be broken. 1121 // Also tests that vertical rails can be broken.
1122 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { 1122 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) {
1123 scoped_ptr<GestureEventConsumeDelegate> delegate( 1123 scoped_ptr<GestureEventConsumeDelegate> delegate(
1124 new GestureEventConsumeDelegate()); 1124 new GestureEventConsumeDelegate());
1125 const int kTouchId = 7; 1125 const int kTouchId = 7;
1126 gfx::Rect bounds(0, 0, 1000, 1000); 1126 gfx::Rect bounds(0, 0, 1000, 1000);
1127 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1127 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1128 delegate.get(), -1234, bounds, NULL)); 1128 delegate.get(), -1234, bounds, NULL));
1129 1129
1130 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1130 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0),
1131 kTouchId, GetTime()); 1131 kTouchId, GetTime());
1132 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1132 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1133 1133
1134 // Move the touch-point vertically enough that it is considered a 1134 // Move the touch-point vertically enough that it is considered a
1135 // vertical scroll. 1135 // vertical scroll.
1136 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 1136 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get());
1137 EXPECT_EQ(0, delegate->scroll_x()); 1137 EXPECT_EQ(0, delegate->scroll_x());
1138 EXPECT_EQ(20, delegate->scroll_y()); 1138 EXPECT_EQ(20, delegate->scroll_y());
1139 1139
1140 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); 1140 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get());
(...skipping 23 matching lines...) Expand all
1164 scoped_ptr<GestureEventConsumeDelegate> delegate( 1164 scoped_ptr<GestureEventConsumeDelegate> delegate(
1165 new GestureEventConsumeDelegate()); 1165 new GestureEventConsumeDelegate());
1166 const int kWindowWidth = 123; 1166 const int kWindowWidth = 123;
1167 const int kWindowHeight = 45; 1167 const int kWindowHeight = 45;
1168 const int kTouchId = 3; 1168 const int kTouchId = 3;
1169 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1169 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1170 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1170 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1171 delegate.get(), -1234, bounds, NULL)); 1171 delegate.get(), -1234, bounds, NULL));
1172 1172
1173 delegate->Reset(); 1173 delegate->Reset();
1174 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1174 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1175 kTouchId, GetTime()); 1175 kTouchId, GetTime());
1176 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1176 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1177 EXPECT_FALSE(delegate->tap()); 1177 EXPECT_FALSE(delegate->tap());
1178 EXPECT_TRUE(delegate->tap_down()); 1178 EXPECT_TRUE(delegate->tap_down());
1179 EXPECT_FALSE(delegate->double_tap()); 1179 EXPECT_FALSE(delegate->double_tap());
1180 EXPECT_FALSE(delegate->scroll_begin()); 1180 EXPECT_FALSE(delegate->scroll_begin());
1181 EXPECT_FALSE(delegate->scroll_update()); 1181 EXPECT_FALSE(delegate->scroll_update());
1182 EXPECT_FALSE(delegate->scroll_end()); 1182 EXPECT_FALSE(delegate->scroll_end());
1183 1183
1184 // Make sure there is enough delay before the touch is released so that it is 1184 // Make sure there is enough delay before the touch is released so that it is
1185 // recognized as a tap. 1185 // recognized as a tap.
1186 delegate->Reset(); 1186 delegate->Reset();
1187 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1187 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1188 kTouchId, press.time_stamp() + 1188 kTouchId, press.time_stamp() +
1189 base::TimeDelta::FromMilliseconds(50)); 1189 base::TimeDelta::FromMilliseconds(50));
1190 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1190 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1191 EXPECT_TRUE(delegate->tap()); 1191 EXPECT_TRUE(delegate->tap());
1192 EXPECT_FALSE(delegate->tap_down()); 1192 EXPECT_FALSE(delegate->tap_down());
1193 EXPECT_FALSE(delegate->double_tap()); 1193 EXPECT_FALSE(delegate->double_tap());
1194 EXPECT_FALSE(delegate->scroll_begin()); 1194 EXPECT_FALSE(delegate->scroll_begin());
1195 EXPECT_FALSE(delegate->scroll_update()); 1195 EXPECT_FALSE(delegate->scroll_update());
1196 EXPECT_FALSE(delegate->scroll_end()); 1196 EXPECT_FALSE(delegate->scroll_end());
1197 1197
1198 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger 1198 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger
1199 // a double-tap. 1199 // a double-tap.
1200 delegate->Reset(); 1200 delegate->Reset();
1201 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1201 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1202 kTouchId, release.time_stamp() + 1202 kTouchId, release.time_stamp() +
1203 base::TimeDelta::FromMilliseconds(1000)); 1203 base::TimeDelta::FromMilliseconds(1000));
1204 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1204 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1205 EXPECT_FALSE(delegate->tap()); 1205 EXPECT_FALSE(delegate->tap());
1206 EXPECT_TRUE(delegate->tap_down()); 1206 EXPECT_TRUE(delegate->tap_down());
1207 EXPECT_FALSE(delegate->double_tap()); 1207 EXPECT_FALSE(delegate->double_tap());
1208 EXPECT_FALSE(delegate->scroll_begin()); 1208 EXPECT_FALSE(delegate->scroll_begin());
1209 EXPECT_FALSE(delegate->scroll_update()); 1209 EXPECT_FALSE(delegate->scroll_update());
1210 EXPECT_FALSE(delegate->scroll_end()); 1210 EXPECT_FALSE(delegate->scroll_end());
1211 1211
1212 // Move the touch-point enough so that it is considered as a scroll. This 1212 // Move the touch-point enough so that it is considered as a scroll. This
1213 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1213 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1214 // The first movement is diagonal, to ensure that we have a free scroll, 1214 // The first movement is diagonal, to ensure that we have a free scroll,
1215 // and not a rail scroll. 1215 // and not a rail scroll.
1216 delegate->Reset(); 1216 delegate->Reset();
1217 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), 1217 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230),
1218 kTouchId, GetTime()); 1218 kTouchId, GetTime());
1219 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1219 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1220 EXPECT_FALSE(delegate->tap()); 1220 EXPECT_FALSE(delegate->tap());
1221 EXPECT_FALSE(delegate->tap_down()); 1221 EXPECT_FALSE(delegate->tap_down());
1222 EXPECT_FALSE(delegate->double_tap()); 1222 EXPECT_FALSE(delegate->double_tap());
1223 EXPECT_TRUE(delegate->scroll_begin()); 1223 EXPECT_TRUE(delegate->scroll_begin());
1224 EXPECT_TRUE(delegate->scroll_update()); 1224 EXPECT_TRUE(delegate->scroll_update());
1225 EXPECT_FALSE(delegate->scroll_end()); 1225 EXPECT_FALSE(delegate->scroll_end());
1226 EXPECT_EQ(29, delegate->scroll_x()); 1226 EXPECT_EQ(29, delegate->scroll_x());
1227 EXPECT_EQ(29, delegate->scroll_y()); 1227 EXPECT_EQ(29, delegate->scroll_y());
1228 1228
1229 // Move some more to generate a few more scroll updates. 1229 // Move some more to generate a few more scroll updates.
1230 delegate->Reset(); 1230 delegate->Reset();
1231 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), 1231 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211),
1232 kTouchId, GetTime()); 1232 kTouchId, GetTime());
1233 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 1233 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
1234 EXPECT_FALSE(delegate->tap()); 1234 EXPECT_FALSE(delegate->tap());
1235 EXPECT_FALSE(delegate->tap_down()); 1235 EXPECT_FALSE(delegate->tap_down());
1236 EXPECT_FALSE(delegate->double_tap()); 1236 EXPECT_FALSE(delegate->double_tap());
1237 EXPECT_FALSE(delegate->scroll_begin()); 1237 EXPECT_FALSE(delegate->scroll_begin());
1238 EXPECT_TRUE(delegate->scroll_update()); 1238 EXPECT_TRUE(delegate->scroll_update());
1239 EXPECT_FALSE(delegate->scroll_end()); 1239 EXPECT_FALSE(delegate->scroll_end());
1240 EXPECT_EQ(-20, delegate->scroll_x()); 1240 EXPECT_EQ(-20, delegate->scroll_x());
1241 EXPECT_EQ(-19, delegate->scroll_y()); 1241 EXPECT_EQ(-19, delegate->scroll_y());
1242 1242
1243 delegate->Reset(); 1243 delegate->Reset();
1244 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), 1244 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215),
1245 kTouchId, GetTime()); 1245 kTouchId, GetTime());
1246 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1246 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1247 EXPECT_FALSE(delegate->tap()); 1247 EXPECT_FALSE(delegate->tap());
1248 EXPECT_FALSE(delegate->tap_down()); 1248 EXPECT_FALSE(delegate->tap_down());
1249 EXPECT_FALSE(delegate->double_tap()); 1249 EXPECT_FALSE(delegate->double_tap());
1250 EXPECT_FALSE(delegate->scroll_begin()); 1250 EXPECT_FALSE(delegate->scroll_begin());
1251 EXPECT_TRUE(delegate->scroll_update()); 1251 EXPECT_TRUE(delegate->scroll_update());
1252 EXPECT_FALSE(delegate->scroll_end()); 1252 EXPECT_FALSE(delegate->scroll_end());
1253 EXPECT_EQ(30, delegate->scroll_x()); 1253 EXPECT_EQ(30, delegate->scroll_x());
1254 EXPECT_EQ(4, delegate->scroll_y()); 1254 EXPECT_EQ(4, delegate->scroll_y());
1255 1255
1256 // Release the touch. This should end the scroll. 1256 // Release the touch. This should end the scroll.
1257 delegate->Reset(); 1257 delegate->Reset();
1258 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1258 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1259 kTouchId, GetTime()); 1259 kTouchId, GetTime());
1260 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1260 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1261 EXPECT_FALSE(delegate->tap()); 1261 EXPECT_FALSE(delegate->tap());
1262 EXPECT_FALSE(delegate->tap_down()); 1262 EXPECT_FALSE(delegate->tap_down());
1263 EXPECT_FALSE(delegate->double_tap()); 1263 EXPECT_FALSE(delegate->double_tap());
1264 EXPECT_FALSE(delegate->scroll_begin()); 1264 EXPECT_FALSE(delegate->scroll_begin());
1265 EXPECT_FALSE(delegate->scroll_update()); 1265 EXPECT_FALSE(delegate->scroll_update());
1266 EXPECT_TRUE(delegate->scroll_end()); 1266 EXPECT_TRUE(delegate->scroll_end());
1267 } 1267 }
1268 1268
1269 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { 1269 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) {
1270 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1270 scoped_ptr<QueueTouchEventDelegate> queued_delegate(
1271 new QueueTouchEventDelegate(root_window())); 1271 new QueueTouchEventDelegate(root_window()));
1272 const int kWindowWidth = 123; 1272 const int kWindowWidth = 123;
1273 const int kWindowHeight = 45; 1273 const int kWindowHeight = 45;
1274 const int kTouchId1 = 6; 1274 const int kTouchId1 = 6;
1275 const int kTouchId2 = 4; 1275 const int kTouchId2 = 4;
1276 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1276 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1277 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1277 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate(
1278 queued_delegate.get(), -1234, bounds, NULL)); 1278 queued_delegate.get(), -1234, bounds, NULL));
1279 1279
1280 queued_delegate->set_window(queue.get()); 1280 queued_delegate->set_window(queue.get());
1281 1281
1282 // Touch down on the window. This should not generate any gesture event. 1282 // Touch down on the window. This should not generate any gesture event.
1283 queued_delegate->Reset(); 1283 queued_delegate->Reset();
1284 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1284 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1285 kTouchId1, GetTime()); 1285 kTouchId1, GetTime());
1286 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1286 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1287 EXPECT_FALSE(queued_delegate->tap()); 1287 EXPECT_FALSE(queued_delegate->tap());
1288 EXPECT_FALSE(queued_delegate->tap_down()); 1288 EXPECT_FALSE(queued_delegate->tap_down());
1289 EXPECT_FALSE(queued_delegate->begin()); 1289 EXPECT_FALSE(queued_delegate->begin());
1290 EXPECT_FALSE(queued_delegate->double_tap()); 1290 EXPECT_FALSE(queued_delegate->double_tap());
1291 EXPECT_FALSE(queued_delegate->scroll_begin()); 1291 EXPECT_FALSE(queued_delegate->scroll_begin());
1292 EXPECT_FALSE(queued_delegate->scroll_update()); 1292 EXPECT_FALSE(queued_delegate->scroll_update());
1293 EXPECT_FALSE(queued_delegate->scroll_end()); 1293 EXPECT_FALSE(queued_delegate->scroll_end());
1294 1294
1295 // Introduce some delay before the touch is released so that it is recognized 1295 // Introduce some delay before the touch is released so that it is recognized
1296 // as a tap. However, this still should not create any gesture events. 1296 // as a tap. However, this still should not create any gesture events.
1297 queued_delegate->Reset(); 1297 queued_delegate->Reset();
1298 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1298 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1299 kTouchId1, press.time_stamp() + 1299 kTouchId1, press.time_stamp() +
1300 base::TimeDelta::FromMilliseconds(50)); 1300 base::TimeDelta::FromMilliseconds(50));
1301 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1301 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1302 EXPECT_FALSE(queued_delegate->tap()); 1302 EXPECT_FALSE(queued_delegate->tap());
1303 EXPECT_FALSE(queued_delegate->tap_down()); 1303 EXPECT_FALSE(queued_delegate->tap_down());
1304 EXPECT_FALSE(queued_delegate->begin()); 1304 EXPECT_FALSE(queued_delegate->begin());
1305 EXPECT_FALSE(queued_delegate->end()); 1305 EXPECT_FALSE(queued_delegate->end());
1306 EXPECT_FALSE(queued_delegate->double_tap()); 1306 EXPECT_FALSE(queued_delegate->double_tap());
1307 EXPECT_FALSE(queued_delegate->scroll_begin()); 1307 EXPECT_FALSE(queued_delegate->scroll_begin());
1308 EXPECT_FALSE(queued_delegate->scroll_update()); 1308 EXPECT_FALSE(queued_delegate->scroll_update());
1309 EXPECT_FALSE(queued_delegate->scroll_end()); 1309 EXPECT_FALSE(queued_delegate->scroll_end());
1310 1310
1311 // Create another window, and place a touch-down on it. This should create a 1311 // Create another window, and place a touch-down on it. This should create a
1312 // tap-down gesture. 1312 // tap-down gesture.
1313 scoped_ptr<GestureEventConsumeDelegate> delegate( 1313 scoped_ptr<GestureEventConsumeDelegate> delegate(
1314 new GestureEventConsumeDelegate()); 1314 new GestureEventConsumeDelegate());
1315 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1315 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1316 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL)); 1316 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL));
1317 delegate->Reset(); 1317 delegate->Reset();
1318 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 1318 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20),
1319 kTouchId2, GetTime()); 1319 kTouchId2, GetTime());
1320 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1320 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1321 EXPECT_FALSE(delegate->tap()); 1321 EXPECT_FALSE(delegate->tap());
1322 EXPECT_TRUE(delegate->tap_down()); 1322 EXPECT_TRUE(delegate->tap_down());
1323 EXPECT_FALSE(queued_delegate->begin()); 1323 EXPECT_FALSE(queued_delegate->begin());
1324 EXPECT_FALSE(queued_delegate->end()); 1324 EXPECT_FALSE(queued_delegate->end());
1325 EXPECT_FALSE(delegate->double_tap()); 1325 EXPECT_FALSE(delegate->double_tap());
1326 EXPECT_FALSE(delegate->scroll_begin()); 1326 EXPECT_FALSE(delegate->scroll_begin());
1327 EXPECT_FALSE(delegate->scroll_update()); 1327 EXPECT_FALSE(delegate->scroll_update());
1328 EXPECT_FALSE(delegate->scroll_end()); 1328 EXPECT_FALSE(delegate->scroll_end());
1329 1329
1330 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 1330 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20),
1331 kTouchId2, GetTime()); 1331 kTouchId2, GetTime());
1332 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 1332 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
1333 1333
1334 // Process the first queued event. 1334 // Process the first queued event.
1335 queued_delegate->Reset(); 1335 queued_delegate->Reset();
1336 queued_delegate->ReceivedAck(); 1336 queued_delegate->ReceivedAck();
1337 EXPECT_FALSE(queued_delegate->tap()); 1337 EXPECT_FALSE(queued_delegate->tap());
1338 EXPECT_TRUE(queued_delegate->tap_down()); 1338 EXPECT_TRUE(queued_delegate->tap_down());
1339 EXPECT_TRUE(queued_delegate->begin()); 1339 EXPECT_TRUE(queued_delegate->begin());
1340 EXPECT_FALSE(queued_delegate->end()); 1340 EXPECT_FALSE(queued_delegate->end());
(...skipping 10 matching lines...) Expand all
1351 EXPECT_FALSE(queued_delegate->begin()); 1351 EXPECT_FALSE(queued_delegate->begin());
1352 EXPECT_TRUE(queued_delegate->end()); 1352 EXPECT_TRUE(queued_delegate->end());
1353 EXPECT_FALSE(queued_delegate->double_tap()); 1353 EXPECT_FALSE(queued_delegate->double_tap());
1354 EXPECT_FALSE(queued_delegate->scroll_begin()); 1354 EXPECT_FALSE(queued_delegate->scroll_begin());
1355 EXPECT_FALSE(queued_delegate->scroll_update()); 1355 EXPECT_FALSE(queued_delegate->scroll_update());
1356 EXPECT_FALSE(queued_delegate->scroll_end()); 1356 EXPECT_FALSE(queued_delegate->scroll_end());
1357 1357
1358 // Start all over. Press on the first window, then press again on the second 1358 // Start all over. Press on the first window, then press again on the second
1359 // window. The second press should still go to the first window. 1359 // window. The second press should still go to the first window.
1360 queued_delegate->Reset(); 1360 queued_delegate->Reset();
1361 ui::TouchEventImpl press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1361 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1362 kTouchId1, GetTime()); 1362 kTouchId1, GetTime());
1363 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 1363 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3);
1364 EXPECT_FALSE(queued_delegate->tap()); 1364 EXPECT_FALSE(queued_delegate->tap());
1365 EXPECT_FALSE(queued_delegate->tap_down()); 1365 EXPECT_FALSE(queued_delegate->tap_down());
1366 EXPECT_FALSE(queued_delegate->begin()); 1366 EXPECT_FALSE(queued_delegate->begin());
1367 EXPECT_FALSE(queued_delegate->end()); 1367 EXPECT_FALSE(queued_delegate->end());
1368 EXPECT_FALSE(queued_delegate->begin()); 1368 EXPECT_FALSE(queued_delegate->begin());
1369 EXPECT_FALSE(queued_delegate->end()); 1369 EXPECT_FALSE(queued_delegate->end());
1370 EXPECT_FALSE(queued_delegate->double_tap()); 1370 EXPECT_FALSE(queued_delegate->double_tap());
1371 EXPECT_FALSE(queued_delegate->scroll_begin()); 1371 EXPECT_FALSE(queued_delegate->scroll_begin());
1372 EXPECT_FALSE(queued_delegate->scroll_update()); 1372 EXPECT_FALSE(queued_delegate->scroll_update());
1373 EXPECT_FALSE(queued_delegate->scroll_end()); 1373 EXPECT_FALSE(queued_delegate->scroll_end());
1374 1374
1375 queued_delegate->Reset(); 1375 queued_delegate->Reset();
1376 delegate->Reset(); 1376 delegate->Reset();
1377 ui::TouchEventImpl press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203), 1377 ui::TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203),
1378 kTouchId2, GetTime()); 1378 kTouchId2, GetTime());
1379 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press4); 1379 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press4);
1380 EXPECT_FALSE(delegate->tap()); 1380 EXPECT_FALSE(delegate->tap());
1381 EXPECT_FALSE(delegate->tap_down()); 1381 EXPECT_FALSE(delegate->tap_down());
1382 EXPECT_FALSE(delegate->begin()); 1382 EXPECT_FALSE(delegate->begin());
1383 EXPECT_FALSE(delegate->end()); 1383 EXPECT_FALSE(delegate->end());
1384 EXPECT_FALSE(delegate->double_tap()); 1384 EXPECT_FALSE(delegate->double_tap());
1385 EXPECT_FALSE(delegate->scroll_begin()); 1385 EXPECT_FALSE(delegate->scroll_begin());
1386 EXPECT_FALSE(delegate->scroll_update()); 1386 EXPECT_FALSE(delegate->scroll_update());
1387 EXPECT_FALSE(delegate->scroll_end()); 1387 EXPECT_FALSE(delegate->scroll_end());
1388 EXPECT_FALSE(queued_delegate->tap()); 1388 EXPECT_FALSE(queued_delegate->tap());
1389 EXPECT_FALSE(queued_delegate->tap_down()); 1389 EXPECT_FALSE(queued_delegate->tap_down());
1390 EXPECT_FALSE(queued_delegate->begin()); 1390 EXPECT_FALSE(queued_delegate->begin());
1391 EXPECT_FALSE(queued_delegate->end()); 1391 EXPECT_FALSE(queued_delegate->end());
1392 EXPECT_FALSE(queued_delegate->double_tap()); 1392 EXPECT_FALSE(queued_delegate->double_tap());
1393 EXPECT_FALSE(queued_delegate->scroll_begin()); 1393 EXPECT_FALSE(queued_delegate->scroll_begin());
1394 EXPECT_FALSE(queued_delegate->scroll_update()); 1394 EXPECT_FALSE(queued_delegate->scroll_update());
1395 EXPECT_FALSE(queued_delegate->scroll_end()); 1395 EXPECT_FALSE(queued_delegate->scroll_end());
1396 1396
1397 // Move the second touch-point enough so that it is considered a pinch. This 1397 // Move the second touch-point enough so that it is considered a pinch. This
1398 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. 1398 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures.
1399 queued_delegate->Reset(); 1399 queued_delegate->Reset();
1400 delegate->Reset(); 1400 delegate->Reset();
1401 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); 1401 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click();
1402 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203), 1402 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203),
1403 kTouchId2, GetTime()); 1403 kTouchId2, GetTime());
1404 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1404 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1405 EXPECT_FALSE(delegate->tap()); 1405 EXPECT_FALSE(delegate->tap());
1406 EXPECT_FALSE(delegate->tap_down()); 1406 EXPECT_FALSE(delegate->tap_down());
1407 EXPECT_FALSE(delegate->begin()); 1407 EXPECT_FALSE(delegate->begin());
1408 EXPECT_FALSE(delegate->double_tap()); 1408 EXPECT_FALSE(delegate->double_tap());
1409 EXPECT_FALSE(delegate->scroll_begin()); 1409 EXPECT_FALSE(delegate->scroll_begin());
1410 EXPECT_FALSE(delegate->scroll_update()); 1410 EXPECT_FALSE(delegate->scroll_update());
1411 EXPECT_FALSE(delegate->scroll_end()); 1411 EXPECT_FALSE(delegate->scroll_end());
1412 EXPECT_FALSE(queued_delegate->tap()); 1412 EXPECT_FALSE(queued_delegate->tap());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1465 const int kWindowHeight = 400; 1465 const int kWindowHeight = 400;
1466 const int kTouchId1 = 5; 1466 const int kTouchId1 = 5;
1467 const int kTouchId2 = 3; 1467 const int kTouchId2 = 3;
1468 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1468 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1469 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1469 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1470 delegate.get(), -1234, bounds, NULL)); 1470 delegate.get(), -1234, bounds, NULL));
1471 1471
1472 aura::RootWindow* root = root_window(); 1472 aura::RootWindow* root = root_window();
1473 1473
1474 delegate->Reset(); 1474 delegate->Reset();
1475 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1475 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1476 kTouchId1, GetTime()); 1476 kTouchId1, GetTime());
1477 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1477 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1478 EXPECT_FALSE(delegate->tap()); 1478 EXPECT_FALSE(delegate->tap());
1479 EXPECT_TRUE(delegate->tap_down()); 1479 EXPECT_TRUE(delegate->tap_down());
1480 EXPECT_FALSE(delegate->double_tap()); 1480 EXPECT_FALSE(delegate->double_tap());
1481 EXPECT_FALSE(delegate->scroll_begin()); 1481 EXPECT_FALSE(delegate->scroll_begin());
1482 EXPECT_FALSE(delegate->scroll_update()); 1482 EXPECT_FALSE(delegate->scroll_update());
1483 EXPECT_FALSE(delegate->scroll_end()); 1483 EXPECT_FALSE(delegate->scroll_end());
1484 1484
1485 // Move the touch-point enough so that it is considered as a scroll. This 1485 // Move the touch-point enough so that it is considered as a scroll. This
1486 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1486 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures.
1487 delegate->Reset(); 1487 delegate->Reset();
1488 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301), 1488 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301),
1489 kTouchId1, GetTime()); 1489 kTouchId1, GetTime());
1490 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1490 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1491 EXPECT_FALSE(delegate->tap()); 1491 EXPECT_FALSE(delegate->tap());
1492 EXPECT_FALSE(delegate->tap_down()); 1492 EXPECT_FALSE(delegate->tap_down());
1493 EXPECT_FALSE(delegate->double_tap()); 1493 EXPECT_FALSE(delegate->double_tap());
1494 EXPECT_TRUE(delegate->scroll_begin()); 1494 EXPECT_TRUE(delegate->scroll_begin());
1495 EXPECT_TRUE(delegate->scroll_update()); 1495 EXPECT_TRUE(delegate->scroll_update());
1496 EXPECT_FALSE(delegate->scroll_end()); 1496 EXPECT_FALSE(delegate->scroll_end());
1497 1497
1498 // Press the second finger. It should cause pinch-begin. Note that we will not 1498 // Press the second finger. It should cause pinch-begin. Note that we will not
1499 // transition to two finger tap here because the touch points are far enough. 1499 // transition to two finger tap here because the touch points are far enough.
1500 delegate->Reset(); 1500 delegate->Reset();
1501 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1501 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1502 kTouchId2, GetTime()); 1502 kTouchId2, GetTime());
1503 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1503 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1504 EXPECT_FALSE(delegate->tap()); 1504 EXPECT_FALSE(delegate->tap());
1505 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1505 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1506 EXPECT_FALSE(delegate->double_tap()); 1506 EXPECT_FALSE(delegate->double_tap());
1507 EXPECT_FALSE(delegate->scroll_begin()); 1507 EXPECT_FALSE(delegate->scroll_begin());
1508 EXPECT_FALSE(delegate->scroll_update()); 1508 EXPECT_FALSE(delegate->scroll_update());
1509 EXPECT_FALSE(delegate->scroll_end()); 1509 EXPECT_FALSE(delegate->scroll_end());
1510 EXPECT_TRUE(delegate->pinch_begin()); 1510 EXPECT_TRUE(delegate->pinch_begin());
1511 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(), 1511 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(),
1512 delegate->bounding_box().ToString()); 1512 delegate->bounding_box().ToString());
1513 1513
1514 // Move the first finger. 1514 // Move the first finger.
1515 delegate->Reset(); 1515 delegate->Reset();
1516 ui::TouchEventImpl move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), 1516 ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201),
1517 kTouchId1, GetTime()); 1517 kTouchId1, GetTime());
1518 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 1518 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3);
1519 EXPECT_FALSE(delegate->tap()); 1519 EXPECT_FALSE(delegate->tap());
1520 EXPECT_FALSE(delegate->tap_down()); 1520 EXPECT_FALSE(delegate->tap_down());
1521 EXPECT_FALSE(delegate->double_tap()); 1521 EXPECT_FALSE(delegate->double_tap());
1522 EXPECT_FALSE(delegate->scroll_begin()); 1522 EXPECT_FALSE(delegate->scroll_begin());
1523 EXPECT_FALSE(delegate->scroll_update()); 1523 EXPECT_FALSE(delegate->scroll_update());
1524 EXPECT_FALSE(delegate->scroll_end()); 1524 EXPECT_FALSE(delegate->scroll_end());
1525 EXPECT_FALSE(delegate->pinch_begin()); 1525 EXPECT_FALSE(delegate->pinch_begin());
1526 EXPECT_TRUE(delegate->pinch_update()); 1526 EXPECT_TRUE(delegate->pinch_update());
1527 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(), 1527 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(),
1528 delegate->bounding_box().ToString()); 1528 delegate->bounding_box().ToString());
1529 1529
1530 // Now move the second finger. 1530 // Now move the second finger.
1531 delegate->Reset(); 1531 delegate->Reset();
1532 ui::TouchEventImpl move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1532 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15),
1533 kTouchId2, GetTime()); 1533 kTouchId2, GetTime());
1534 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 1534 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4);
1535 EXPECT_FALSE(delegate->tap()); 1535 EXPECT_FALSE(delegate->tap());
1536 EXPECT_FALSE(delegate->tap_down()); 1536 EXPECT_FALSE(delegate->tap_down());
1537 EXPECT_FALSE(delegate->double_tap()); 1537 EXPECT_FALSE(delegate->double_tap());
1538 EXPECT_FALSE(delegate->scroll_begin()); 1538 EXPECT_FALSE(delegate->scroll_begin());
1539 EXPECT_FALSE(delegate->scroll_update()); 1539 EXPECT_FALSE(delegate->scroll_update());
1540 EXPECT_FALSE(delegate->scroll_end()); 1540 EXPECT_FALSE(delegate->scroll_end());
1541 EXPECT_FALSE(delegate->pinch_begin()); 1541 EXPECT_FALSE(delegate->pinch_begin());
1542 EXPECT_TRUE(delegate->pinch_update()); 1542 EXPECT_TRUE(delegate->pinch_update());
1543 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(), 1543 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(),
1544 delegate->bounding_box().ToString()); 1544 delegate->bounding_box().ToString());
1545 1545
1546 // Release the first finger. This should end pinch. 1546 // Release the first finger. This should end pinch.
1547 delegate->Reset(); 1547 delegate->Reset();
1548 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1548 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1549 kTouchId1, press.time_stamp() + 1549 kTouchId1, press.time_stamp() +
1550 base::TimeDelta::FromMilliseconds(50)); 1550 base::TimeDelta::FromMilliseconds(50));
1551 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1551 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1552 EXPECT_FALSE(delegate->tap()); 1552 EXPECT_FALSE(delegate->tap());
1553 EXPECT_FALSE(delegate->tap_down()); 1553 EXPECT_FALSE(delegate->tap_down());
1554 EXPECT_FALSE(delegate->double_tap()); 1554 EXPECT_FALSE(delegate->double_tap());
1555 EXPECT_FALSE(delegate->scroll_begin()); 1555 EXPECT_FALSE(delegate->scroll_begin());
1556 EXPECT_FALSE(delegate->scroll_update()); 1556 EXPECT_FALSE(delegate->scroll_update());
1557 EXPECT_FALSE(delegate->scroll_end()); 1557 EXPECT_FALSE(delegate->scroll_end());
1558 EXPECT_TRUE(delegate->pinch_end()); 1558 EXPECT_TRUE(delegate->pinch_end());
1559 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), 1559 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1560 delegate->bounding_box().ToString()); 1560 delegate->bounding_box().ToString());
1561 1561
1562 // Move the second finger. This should still generate a scroll. 1562 // Move the second finger. This should still generate a scroll.
1563 delegate->Reset(); 1563 delegate->Reset();
1564 ui::TouchEventImpl move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1564 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
1565 kTouchId2, GetTime()); 1565 kTouchId2, GetTime());
1566 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); 1566 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5);
1567 EXPECT_FALSE(delegate->tap()); 1567 EXPECT_FALSE(delegate->tap());
1568 EXPECT_FALSE(delegate->tap_down()); 1568 EXPECT_FALSE(delegate->tap_down());
1569 EXPECT_FALSE(delegate->double_tap()); 1569 EXPECT_FALSE(delegate->double_tap());
1570 EXPECT_FALSE(delegate->scroll_begin()); 1570 EXPECT_FALSE(delegate->scroll_begin());
1571 EXPECT_TRUE(delegate->scroll_update()); 1571 EXPECT_TRUE(delegate->scroll_update());
1572 EXPECT_FALSE(delegate->scroll_end()); 1572 EXPECT_FALSE(delegate->scroll_end());
1573 EXPECT_FALSE(delegate->pinch_begin()); 1573 EXPECT_FALSE(delegate->pinch_begin());
1574 EXPECT_FALSE(delegate->pinch_update()); 1574 EXPECT_FALSE(delegate->pinch_update());
1575 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1575 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1576 } 1576 }
1577 1577
1578 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { 1578 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) {
1579 scoped_ptr<GestureEventConsumeDelegate> delegate( 1579 scoped_ptr<GestureEventConsumeDelegate> delegate(
1580 new GestureEventConsumeDelegate()); 1580 new GestureEventConsumeDelegate());
1581 const int kWindowWidth = 300; 1581 const int kWindowWidth = 300;
1582 const int kWindowHeight = 400; 1582 const int kWindowHeight = 400;
1583 const int kTouchId1 = 5; 1583 const int kTouchId1 = 5;
1584 const int kTouchId2 = 3; 1584 const int kTouchId2 = 3;
1585 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1585 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1586 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1586 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1587 delegate.get(), -1234, bounds, NULL)); 1587 delegate.get(), -1234, bounds, NULL));
1588 1588
1589 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 1589 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
1590 kTouchId1, GetTime()); 1590 kTouchId1, GetTime());
1591 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1591 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1592 delegate->Reset(); 1592 delegate->Reset();
1593 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1593 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1594 kTouchId2, GetTime()); 1594 kTouchId2, GetTime());
1595 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1595 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1596 // Since the touch points are far enough we will go to pinch rather than two 1596 // Since the touch points are far enough we will go to pinch rather than two
1597 // finger tap. 1597 // finger tap.
1598 EXPECT_TRUE(delegate->pinch_begin()); 1598 EXPECT_TRUE(delegate->pinch_begin());
1599 1599
1600 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 1600 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
1601 EXPECT_TRUE(delegate->pinch_update()); 1601 EXPECT_TRUE(delegate->pinch_update());
1602 1602
1603 // Pinch has started, now release the second finger 1603 // Pinch has started, now release the second finger
1604 delegate->Reset(); 1604 delegate->Reset();
1605 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1605 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1606 kTouchId1, GetTime()); 1606 kTouchId1, GetTime());
1607 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1607 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1608 EXPECT_TRUE(delegate->pinch_end()); 1608 EXPECT_TRUE(delegate->pinch_end());
1609 1609
1610 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get()); 1610 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get());
1611 EXPECT_TRUE(delegate->scroll_update()); 1611 EXPECT_TRUE(delegate->scroll_update());
1612 1612
1613 // Pinch again 1613 // Pinch again
1614 delegate->Reset(); 1614 delegate->Reset();
1615 ui::TouchEventImpl press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1615 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1616 kTouchId1, GetTime()); 1616 kTouchId1, GetTime());
1617 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 1617 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3);
1618 // Now the touch points are close. So we will go into two finger tap. 1618 // Now the touch points are close. So we will go into two finger tap.
1619 // Move the touch-point enough to break two-finger-tap and enter pinch. 1619 // Move the touch-point enough to break two-finger-tap and enter pinch.
1620 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202), 1620 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202),
1621 kTouchId1, GetTime()); 1621 kTouchId1, GetTime());
1622 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1622 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1623 EXPECT_TRUE(delegate->pinch_begin()); 1623 EXPECT_TRUE(delegate->pinch_begin());
1624 1624
1625 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 1625 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
1626 EXPECT_TRUE(delegate->pinch_update()); 1626 EXPECT_TRUE(delegate->pinch_update());
1627 } 1627 }
1628 1628
1629 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { 1629 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) {
1630 scoped_ptr<GestureEventConsumeDelegate> delegate( 1630 scoped_ptr<GestureEventConsumeDelegate> delegate(
1631 new GestureEventConsumeDelegate()); 1631 new GestureEventConsumeDelegate());
1632 const int kWindowWidth = 300; 1632 const int kWindowWidth = 300;
1633 const int kWindowHeight = 400; 1633 const int kWindowHeight = 400;
1634 const int kTouchId1 = 3; 1634 const int kTouchId1 = 3;
1635 const int kTouchId2 = 5; 1635 const int kTouchId2 = 5;
1636 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1636 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight);
1637 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1637 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1638 delegate.get(), -1234, bounds, NULL)); 1638 delegate.get(), -1234, bounds, NULL));
1639 1639
1640 aura::RootWindow* root = root_window(); 1640 aura::RootWindow* root = root_window();
1641 1641
1642 delegate->Reset(); 1642 delegate->Reset();
1643 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 1643 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301),
1644 kTouchId1, GetTime()); 1644 kTouchId1, GetTime());
1645 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1645 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1646 EXPECT_FALSE(delegate->tap()); 1646 EXPECT_FALSE(delegate->tap());
1647 EXPECT_TRUE(delegate->tap_down()); 1647 EXPECT_TRUE(delegate->tap_down());
1648 EXPECT_FALSE(delegate->double_tap()); 1648 EXPECT_FALSE(delegate->double_tap());
1649 EXPECT_FALSE(delegate->scroll_begin()); 1649 EXPECT_FALSE(delegate->scroll_begin());
1650 EXPECT_FALSE(delegate->scroll_update()); 1650 EXPECT_FALSE(delegate->scroll_update());
1651 EXPECT_FALSE(delegate->scroll_end()); 1651 EXPECT_FALSE(delegate->scroll_end());
1652 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1652 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1653 1653
1654 // Press the second finger far enough to break two finger tap. It should 1654 // Press the second finger far enough to break two finger tap. It should
1655 // instead cause a scroll-begin and pinch-begin. 1655 // instead cause a scroll-begin and pinch-begin.
1656 delegate->Reset(); 1656 delegate->Reset();
1657 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1657 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
1658 kTouchId2, GetTime()); 1658 kTouchId2, GetTime());
1659 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1659 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1660 EXPECT_FALSE(delegate->tap()); 1660 EXPECT_FALSE(delegate->tap());
1661 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1661 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1662 EXPECT_FALSE(delegate->double_tap()); 1662 EXPECT_FALSE(delegate->double_tap());
1663 EXPECT_TRUE(delegate->scroll_begin()); 1663 EXPECT_TRUE(delegate->scroll_begin());
1664 EXPECT_FALSE(delegate->scroll_update()); 1664 EXPECT_FALSE(delegate->scroll_update());
1665 EXPECT_FALSE(delegate->scroll_end()); 1665 EXPECT_FALSE(delegate->scroll_end());
1666 EXPECT_TRUE(delegate->pinch_begin()); 1666 EXPECT_TRUE(delegate->pinch_begin());
1667 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(), 1667 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(),
1668 delegate->bounding_box().ToString()); 1668 delegate->bounding_box().ToString());
1669 1669
1670 // Move the first finger. 1670 // Move the first finger.
1671 delegate->Reset(); 1671 delegate->Reset();
1672 ui::TouchEventImpl move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), 1672 ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201),
1673 kTouchId1, GetTime()); 1673 kTouchId1, GetTime());
1674 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 1674 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3);
1675 EXPECT_FALSE(delegate->tap()); 1675 EXPECT_FALSE(delegate->tap());
1676 EXPECT_FALSE(delegate->tap_down()); 1676 EXPECT_FALSE(delegate->tap_down());
1677 EXPECT_FALSE(delegate->double_tap()); 1677 EXPECT_FALSE(delegate->double_tap());
1678 EXPECT_FALSE(delegate->scroll_begin()); 1678 EXPECT_FALSE(delegate->scroll_begin());
1679 EXPECT_FALSE(delegate->scroll_update()); 1679 EXPECT_FALSE(delegate->scroll_update());
1680 EXPECT_FALSE(delegate->scroll_end()); 1680 EXPECT_FALSE(delegate->scroll_end());
1681 EXPECT_FALSE(delegate->pinch_begin()); 1681 EXPECT_FALSE(delegate->pinch_begin());
1682 EXPECT_TRUE(delegate->pinch_update()); 1682 EXPECT_TRUE(delegate->pinch_update());
1683 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(), 1683 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(),
1684 delegate->bounding_box().ToString()); 1684 delegate->bounding_box().ToString());
1685 1685
1686 // Now move the second finger. 1686 // Now move the second finger.
1687 delegate->Reset(); 1687 delegate->Reset();
1688 ui::TouchEventImpl move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1688 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15),
1689 kTouchId2, GetTime()); 1689 kTouchId2, GetTime());
1690 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 1690 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4);
1691 EXPECT_FALSE(delegate->tap()); 1691 EXPECT_FALSE(delegate->tap());
1692 EXPECT_FALSE(delegate->tap_down()); 1692 EXPECT_FALSE(delegate->tap_down());
1693 EXPECT_FALSE(delegate->double_tap()); 1693 EXPECT_FALSE(delegate->double_tap());
1694 EXPECT_FALSE(delegate->scroll_begin()); 1694 EXPECT_FALSE(delegate->scroll_begin());
1695 EXPECT_FALSE(delegate->scroll_update()); 1695 EXPECT_FALSE(delegate->scroll_update());
1696 EXPECT_FALSE(delegate->scroll_end()); 1696 EXPECT_FALSE(delegate->scroll_end());
1697 EXPECT_FALSE(delegate->pinch_begin()); 1697 EXPECT_FALSE(delegate->pinch_begin());
1698 EXPECT_TRUE(delegate->pinch_update()); 1698 EXPECT_TRUE(delegate->pinch_update());
1699 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(), 1699 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(),
1700 delegate->bounding_box().ToString()); 1700 delegate->bounding_box().ToString());
1701 1701
1702 // Release the first finger. This should end pinch. 1702 // Release the first finger. This should end pinch.
1703 delegate->Reset(); 1703 delegate->Reset();
1704 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1704 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1705 kTouchId1, press.time_stamp() + 1705 kTouchId1, press.time_stamp() +
1706 base::TimeDelta::FromMilliseconds(50)); 1706 base::TimeDelta::FromMilliseconds(50));
1707 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1707 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1708 EXPECT_FALSE(delegate->tap()); 1708 EXPECT_FALSE(delegate->tap());
1709 EXPECT_FALSE(delegate->tap_down()); 1709 EXPECT_FALSE(delegate->tap_down());
1710 EXPECT_FALSE(delegate->double_tap()); 1710 EXPECT_FALSE(delegate->double_tap());
1711 EXPECT_FALSE(delegate->scroll_begin()); 1711 EXPECT_FALSE(delegate->scroll_begin());
1712 EXPECT_FALSE(delegate->scroll_update()); 1712 EXPECT_FALSE(delegate->scroll_update());
1713 EXPECT_FALSE(delegate->scroll_end()); 1713 EXPECT_FALSE(delegate->scroll_end());
1714 EXPECT_TRUE(delegate->pinch_end()); 1714 EXPECT_TRUE(delegate->pinch_end());
1715 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), 1715 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(),
1716 delegate->bounding_box().ToString()); 1716 delegate->bounding_box().ToString());
1717 1717
1718 // Move the second finger. This should still generate a scroll. 1718 // Move the second finger. This should still generate a scroll.
1719 delegate->Reset(); 1719 delegate->Reset();
1720 ui::TouchEventImpl move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1720 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10),
1721 kTouchId2, GetTime()); 1721 kTouchId2, GetTime());
1722 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); 1722 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5);
1723 EXPECT_FALSE(delegate->tap()); 1723 EXPECT_FALSE(delegate->tap());
1724 EXPECT_FALSE(delegate->tap_down()); 1724 EXPECT_FALSE(delegate->tap_down());
1725 EXPECT_FALSE(delegate->double_tap()); 1725 EXPECT_FALSE(delegate->double_tap());
1726 EXPECT_FALSE(delegate->scroll_begin()); 1726 EXPECT_FALSE(delegate->scroll_begin());
1727 EXPECT_TRUE(delegate->scroll_update()); 1727 EXPECT_TRUE(delegate->scroll_update());
1728 EXPECT_FALSE(delegate->scroll_end()); 1728 EXPECT_FALSE(delegate->scroll_end());
1729 EXPECT_FALSE(delegate->pinch_begin()); 1729 EXPECT_FALSE(delegate->pinch_begin());
1730 EXPECT_FALSE(delegate->pinch_update()); 1730 EXPECT_FALSE(delegate->pinch_update());
1731 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1731 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
1732 } 1732 }
1733 1733
1734 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 1734 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) {
1735 scoped_ptr<GestureEventConsumeDelegate> delegate( 1735 scoped_ptr<GestureEventConsumeDelegate> delegate(
1736 new GestureEventConsumeDelegate()); 1736 new GestureEventConsumeDelegate());
1737 1737
1738 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1738 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1739 6, GetTime()); 1739 6, GetTime());
1740 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1740 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1741 EXPECT_FALSE(delegate->tap()); 1741 EXPECT_FALSE(delegate->tap());
1742 EXPECT_FALSE(delegate->tap_down()); 1742 EXPECT_FALSE(delegate->tap_down());
1743 } 1743 }
1744 1744
1745 // Check that a touch is locked to the window of the closest current touch 1745 // Check that a touch is locked to the window of the closest current touch
1746 // within max_separation_for_gesture_touches_in_pixels 1746 // within max_separation_for_gesture_touches_in_pixels
1747 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { 1747 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) {
1748 ui::GestureRecognizer* gesture_recognizer = 1748 ui::GestureRecognizer* gesture_recognizer =
(...skipping 17 matching lines...) Expand all
1766 1766
1767 scoped_array<aura::Window*> windows(new aura::Window*[kNumWindows]); 1767 scoped_array<aura::Window*> windows(new aura::Window*[kNumWindows]);
1768 1768
1769 // Instantiate windows with |window_bounds| and touch each window at 1769 // Instantiate windows with |window_bounds| and touch each window at
1770 // its origin. 1770 // its origin.
1771 for (int i = 0; i < kNumWindows; ++i) { 1771 for (int i = 0; i < kNumWindows; ++i) {
1772 delegates[i] = new GestureEventConsumeDelegate(); 1772 delegates[i] = new GestureEventConsumeDelegate();
1773 windows[i] = CreateTestWindowWithDelegate( 1773 windows[i] = CreateTestWindowWithDelegate(
1774 delegates[i], i, *window_bounds[i], NULL); 1774 delegates[i], i, *window_bounds[i], NULL);
1775 windows[i]->set_id(i); 1775 windows[i]->set_id(i);
1776 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, window_bounds[i]->origin(), 1776 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i]->origin(),
1777 i, GetTime()); 1777 i, GetTime());
1778 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1778 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1779 } 1779 }
1780 1780
1781 // Touches should now be associated with the closest touch within 1781 // Touches should now be associated with the closest touch within
1782 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels 1782 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels
1783 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); 1783 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11));
1784 EXPECT_EQ("0", WindowIDAsString(target)); 1784 EXPECT_EQ("0", WindowIDAsString(target));
1785 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); 1785 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11));
1786 EXPECT_EQ("1", WindowIDAsString(target)); 1786 EXPECT_EQ("1", WindowIDAsString(target));
1787 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); 1787 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511));
1788 EXPECT_EQ("2", WindowIDAsString(target)); 1788 EXPECT_EQ("2", WindowIDAsString(target));
1789 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); 1789 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511));
1790 EXPECT_EQ("3", WindowIDAsString(target)); 1790 EXPECT_EQ("3", WindowIDAsString(target));
1791 1791
1792 // Add a touch in the middle associated with windows[2] 1792 // Add a touch in the middle associated with windows[2]
1793 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), 1793 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500),
1794 kNumWindows, GetTime()); 1794 kNumWindows, GetTime());
1795 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1795 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1796 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), 1796 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250),
1797 kNumWindows, GetTime()); 1797 kNumWindows, GetTime());
1798 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1798 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move);
1799 1799
1800 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); 1800 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250));
1801 EXPECT_EQ("2", WindowIDAsString(target)); 1801 EXPECT_EQ("2", WindowIDAsString(target));
1802 1802
1803 // Make sure that ties are broken by distance to a current touch 1803 // Make sure that ties are broken by distance to a current touch
1804 // Closer to the point in the bottom right. 1804 // Closer to the point in the bottom right.
1805 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); 1805 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380));
1806 EXPECT_EQ("3", WindowIDAsString(target)); 1806 EXPECT_EQ("3", WindowIDAsString(target));
1807 1807
1808 // This touch is closer to the point in the middle 1808 // This touch is closer to the point in the middle
1809 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); 1809 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300));
1810 EXPECT_EQ("2", WindowIDAsString(target)); 1810 EXPECT_EQ("2", WindowIDAsString(target));
1811 1811
1812 // A touch too far from other touches won't be locked to anything 1812 // A touch too far from other touches won't be locked to anything
1813 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 1813 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000));
1814 EXPECT_TRUE(target == NULL); 1814 EXPECT_TRUE(target == NULL);
1815 1815
1816 // Move a touch associated with windows[2] to 1000, 1000 1816 // Move a touch associated with windows[2] to 1000, 1000
1817 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), 1817 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000),
1818 kNumWindows, GetTime()); 1818 kNumWindows, GetTime());
1819 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1819 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1820 1820
1821 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 1821 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000));
1822 EXPECT_EQ("2", WindowIDAsString(target)); 1822 EXPECT_EQ("2", WindowIDAsString(target));
1823 } 1823 }
1824 1824
1825 // Check that touch events outside the root window are still handled 1825 // Check that touch events outside the root window are still handled
1826 // by the root window's gesture sequence. 1826 // by the root window's gesture sequence.
1827 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 1827 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) {
1828 TestGestureRecognizer* gesture_recognizer = 1828 TestGestureRecognizer* gesture_recognizer =
1829 new TestGestureRecognizer(root_window()); 1829 new TestGestureRecognizer(root_window());
1830 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1830 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
1831 1831
1832 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 1832 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds(
1833 gfx::Rect(-100, -100, 2000, 2000), NULL)); 1833 gfx::Rect(-100, -100, 2000, 2000), NULL));
1834 1834
1835 ui::GestureSequence* window_gesture_sequence = 1835 ui::GestureSequence* window_gesture_sequence =
1836 gesture_recognizer->GetGestureSequenceForTesting(window.get()); 1836 gesture_recognizer->GetGestureSequenceForTesting(window.get());
1837 1837
1838 ui::GestureSequence* root_window_gesture_sequence = 1838 ui::GestureSequence* root_window_gesture_sequence =
1839 gesture_recognizer->GetGestureSequenceForTesting(root_window()); 1839 gesture_recognizer->GetGestureSequenceForTesting(root_window());
1840 1840
1841 gfx::Point pos1(-10, -10); 1841 gfx::Point pos1(-10, -10);
1842 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, pos1, 0, GetTime()); 1842 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, GetTime());
1843 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1843 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1844 1844
1845 gfx::Point pos2(1000, 1000); 1845 gfx::Point pos2(1000, 1000);
1846 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, pos2, 1, GetTime()); 1846 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, GetTime());
1847 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1847 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1848 1848
1849 // As these presses were outside the root window, they should be 1849 // As these presses were outside the root window, they should be
1850 // associated with the root window. 1850 // associated with the root window.
1851 EXPECT_EQ(0, window_gesture_sequence->point_count()); 1851 EXPECT_EQ(0, window_gesture_sequence->point_count());
1852 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); 1852 EXPECT_EQ(2, root_window_gesture_sequence->point_count());
1853 } 1853 }
1854 1854
1855 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { 1855 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) {
1856 scoped_ptr<QueueTouchEventDelegate> delegate( 1856 scoped_ptr<QueueTouchEventDelegate> delegate(
1857 new QueueTouchEventDelegate(root_window())); 1857 new QueueTouchEventDelegate(root_window()));
1858 const int kTouchId = 2; 1858 const int kTouchId = 2;
1859 gfx::Rect bounds(100, 200, 100, 100); 1859 gfx::Rect bounds(100, 200, 100, 100);
1860 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1860 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1861 delegate.get(), -1234, bounds, NULL)); 1861 delegate.get(), -1234, bounds, NULL));
1862 delegate->set_window(window.get()); 1862 delegate->set_window(window.get());
1863 1863
1864 delegate->Reset(); 1864 delegate->Reset();
1865 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1865 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1866 kTouchId, GetTime()); 1866 kTouchId, GetTime());
1867 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1867 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1868 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1868 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1869 kTouchId, press.time_stamp() + 1869 kTouchId, press.time_stamp() +
1870 base::TimeDelta::FromMilliseconds(50)); 1870 base::TimeDelta::FromMilliseconds(50));
1871 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1871 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
1872 1872
1873 delegate->Reset(); 1873 delegate->Reset();
1874 delegate->ReceivedAck(); 1874 delegate->ReceivedAck();
1875 EXPECT_TRUE(delegate->tap_down()); 1875 EXPECT_TRUE(delegate->tap_down());
1876 delegate->Reset(); 1876 delegate->Reset();
1877 delegate->ReceivedAckPreventDefaulted(); 1877 delegate->ReceivedAckPreventDefaulted();
1878 EXPECT_FALSE(delegate->tap()); 1878 EXPECT_FALSE(delegate->tap());
(...skipping 29 matching lines...) Expand all
1908 new GestureEventConsumeDelegate()); 1908 new GestureEventConsumeDelegate());
1909 const int kWindowWidth = 123; 1909 const int kWindowWidth = 123;
1910 const int kWindowHeight = 45; 1910 const int kWindowHeight = 45;
1911 const int kTouchId1 = 2; 1911 const int kTouchId1 = 2;
1912 const int kTouchId2 = 3; 1912 const int kTouchId2 = 3;
1913 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1913 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
1914 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1914 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
1915 delegate.get(), -1234, bounds, NULL)); 1915 delegate.get(), -1234, bounds, NULL));
1916 1916
1917 delegate->Reset(); 1917 delegate->Reset();
1918 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1918 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
1919 kTouchId1, GetTime()); 1919 kTouchId1, GetTime());
1920 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1920 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
1921 EXPECT_FALSE(delegate->tap()); 1921 EXPECT_FALSE(delegate->tap());
1922 EXPECT_TRUE(delegate->tap_down()); 1922 EXPECT_TRUE(delegate->tap_down());
1923 EXPECT_FALSE(delegate->double_tap()); 1923 EXPECT_FALSE(delegate->double_tap());
1924 EXPECT_FALSE(delegate->scroll_begin()); 1924 EXPECT_FALSE(delegate->scroll_begin());
1925 EXPECT_FALSE(delegate->scroll_update()); 1925 EXPECT_FALSE(delegate->scroll_update());
1926 EXPECT_FALSE(delegate->scroll_end()); 1926 EXPECT_FALSE(delegate->scroll_end());
1927 EXPECT_FALSE(delegate->long_press()); 1927 EXPECT_FALSE(delegate->long_press());
1928 EXPECT_FALSE(delegate->two_finger_tap()); 1928 EXPECT_FALSE(delegate->two_finger_tap());
1929 1929
1930 delegate->Reset(); 1930 delegate->Reset();
1931 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 1931 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
1932 kTouchId2, GetTime()); 1932 kTouchId2, GetTime());
1933 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1933 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
1934 EXPECT_FALSE(delegate->tap()); 1934 EXPECT_FALSE(delegate->tap());
1935 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1935 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
1936 EXPECT_FALSE(delegate->double_tap()); 1936 EXPECT_FALSE(delegate->double_tap());
1937 EXPECT_FALSE(delegate->scroll_begin()); 1937 EXPECT_FALSE(delegate->scroll_begin());
1938 EXPECT_FALSE(delegate->scroll_update()); 1938 EXPECT_FALSE(delegate->scroll_update());
1939 EXPECT_FALSE(delegate->scroll_end()); 1939 EXPECT_FALSE(delegate->scroll_end());
1940 EXPECT_FALSE(delegate->long_press()); 1940 EXPECT_FALSE(delegate->long_press());
1941 EXPECT_FALSE(delegate->two_finger_tap()); 1941 EXPECT_FALSE(delegate->two_finger_tap());
1942 1942
1943 // Little bit of touch move should not affect our state. 1943 // Little bit of touch move should not affect our state.
1944 delegate->Reset(); 1944 delegate->Reset();
1945 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202), 1945 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202),
1946 kTouchId1, GetTime()); 1946 kTouchId1, GetTime());
1947 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 1947 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
1948 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202), 1948 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202),
1949 kTouchId2, GetTime()); 1949 kTouchId2, GetTime());
1950 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1950 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
1951 EXPECT_FALSE(delegate->tap()); 1951 EXPECT_FALSE(delegate->tap());
1952 EXPECT_FALSE(delegate->tap_down()); 1952 EXPECT_FALSE(delegate->tap_down());
1953 EXPECT_FALSE(delegate->double_tap()); 1953 EXPECT_FALSE(delegate->double_tap());
1954 EXPECT_FALSE(delegate->scroll_begin()); 1954 EXPECT_FALSE(delegate->scroll_begin());
1955 EXPECT_FALSE(delegate->scroll_update()); 1955 EXPECT_FALSE(delegate->scroll_update());
1956 EXPECT_FALSE(delegate->scroll_end()); 1956 EXPECT_FALSE(delegate->scroll_end());
1957 EXPECT_FALSE(delegate->long_press()); 1957 EXPECT_FALSE(delegate->long_press());
1958 EXPECT_FALSE(delegate->two_finger_tap()); 1958 EXPECT_FALSE(delegate->two_finger_tap());
1959 1959
1960 // Make sure there is enough delay before the touch is released so that it is 1960 // Make sure there is enough delay before the touch is released so that it is
1961 // recognized as a tap. 1961 // recognized as a tap.
1962 delegate->Reset(); 1962 delegate->Reset();
1963 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1963 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
1964 kTouchId1, press1.time_stamp() + 1964 kTouchId1, press1.time_stamp() +
1965 base::TimeDelta::FromMilliseconds(50)); 1965 base::TimeDelta::FromMilliseconds(50));
1966 1966
1967 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1967 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
1968 EXPECT_FALSE(delegate->tap()); 1968 EXPECT_FALSE(delegate->tap());
1969 EXPECT_FALSE(delegate->tap_down()); 1969 EXPECT_FALSE(delegate->tap_down());
1970 EXPECT_FALSE(delegate->double_tap()); 1970 EXPECT_FALSE(delegate->double_tap());
1971 EXPECT_FALSE(delegate->scroll_begin()); 1971 EXPECT_FALSE(delegate->scroll_begin());
1972 EXPECT_FALSE(delegate->scroll_update()); 1972 EXPECT_FALSE(delegate->scroll_update());
1973 EXPECT_FALSE(delegate->scroll_end()); 1973 EXPECT_FALSE(delegate->scroll_end());
1974 EXPECT_TRUE(delegate->two_finger_tap()); 1974 EXPECT_TRUE(delegate->two_finger_tap());
1975 1975
1976 // Lift second finger. 1976 // Lift second finger.
1977 // Make sure there is enough delay before the touch is released so that it is 1977 // Make sure there is enough delay before the touch is released so that it is
1978 // recognized as a tap. 1978 // recognized as a tap.
1979 delegate->Reset(); 1979 delegate->Reset();
1980 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 1980 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
1981 kTouchId2, press2.time_stamp() + 1981 kTouchId2, press2.time_stamp() +
1982 base::TimeDelta::FromMilliseconds(50)); 1982 base::TimeDelta::FromMilliseconds(50));
1983 1983
1984 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 1984 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
1985 EXPECT_FALSE(delegate->tap()); 1985 EXPECT_FALSE(delegate->tap());
1986 EXPECT_FALSE(delegate->tap_down()); 1986 EXPECT_FALSE(delegate->tap_down());
1987 EXPECT_FALSE(delegate->double_tap()); 1987 EXPECT_FALSE(delegate->double_tap());
1988 EXPECT_FALSE(delegate->scroll_begin()); 1988 EXPECT_FALSE(delegate->scroll_begin());
1989 EXPECT_FALSE(delegate->scroll_update()); 1989 EXPECT_FALSE(delegate->scroll_update());
1990 EXPECT_TRUE(delegate->scroll_end()); 1990 EXPECT_TRUE(delegate->scroll_end());
1991 EXPECT_FALSE(delegate->two_finger_tap()); 1991 EXPECT_FALSE(delegate->two_finger_tap());
1992 } 1992 }
1993 1993
1994 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { 1994 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) {
1995 scoped_ptr<GestureEventConsumeDelegate> delegate( 1995 scoped_ptr<GestureEventConsumeDelegate> delegate(
1996 new GestureEventConsumeDelegate()); 1996 new GestureEventConsumeDelegate());
1997 const int kWindowWidth = 123; 1997 const int kWindowWidth = 123;
1998 const int kWindowHeight = 45; 1998 const int kWindowHeight = 45;
1999 const int kTouchId1 = 2; 1999 const int kTouchId1 = 2;
2000 const int kTouchId2 = 3; 2000 const int kTouchId2 = 3;
2001 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2001 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2002 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2002 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2003 delegate.get(), -1234, bounds, NULL)); 2003 delegate.get(), -1234, bounds, NULL));
2004 2004
2005 delegate->Reset(); 2005 delegate->Reset();
2006 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2006 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2007 kTouchId1, GetTime()); 2007 kTouchId1, GetTime());
2008 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2008 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2009 2009
2010 delegate->Reset(); 2010 delegate->Reset();
2011 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2011 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2012 kTouchId2, GetTime()); 2012 kTouchId2, GetTime());
2013 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2013 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2014 2014
2015 // Send release event after sufficient delay so that two finger time expires. 2015 // Send release event after sufficient delay so that two finger time expires.
2016 delegate->Reset(); 2016 delegate->Reset();
2017 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2017 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2018 kTouchId1, press1.time_stamp() + 2018 kTouchId1, press1.time_stamp() +
2019 base::TimeDelta::FromMilliseconds(1000)); 2019 base::TimeDelta::FromMilliseconds(1000));
2020 2020
2021 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2021 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2022 EXPECT_FALSE(delegate->two_finger_tap()); 2022 EXPECT_FALSE(delegate->two_finger_tap());
2023 2023
2024 // Lift second finger. 2024 // Lift second finger.
2025 // Make sure there is enough delay before the touch is released so that it is 2025 // Make sure there is enough delay before the touch is released so that it is
2026 // recognized as a tap. 2026 // recognized as a tap.
2027 delegate->Reset(); 2027 delegate->Reset();
2028 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2028 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201),
2029 kTouchId2, press2.time_stamp() + 2029 kTouchId2, press2.time_stamp() +
2030 base::TimeDelta::FromMilliseconds(50)); 2030 base::TimeDelta::FromMilliseconds(50));
2031 2031
2032 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2032 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2033 EXPECT_FALSE(delegate->two_finger_tap()); 2033 EXPECT_FALSE(delegate->two_finger_tap());
2034 } 2034 }
2035 2035
2036 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2036 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) {
2037 scoped_ptr<GestureEventConsumeDelegate> delegate( 2037 scoped_ptr<GestureEventConsumeDelegate> delegate(
2038 new GestureEventConsumeDelegate()); 2038 new GestureEventConsumeDelegate());
2039 const int kWindowWidth = 123; 2039 const int kWindowWidth = 123;
2040 const int kWindowHeight = 45; 2040 const int kWindowHeight = 45;
2041 const int kTouchId1 = 2; 2041 const int kTouchId1 = 2;
2042 const int kTouchId2 = 3; 2042 const int kTouchId2 = 3;
2043 2043
2044 // Test moving first finger 2044 // Test moving first finger
2045 { 2045 {
2046 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2046 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2047 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2047 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2048 delegate.get(), -1234, bounds, NULL)); 2048 delegate.get(), -1234, bounds, NULL));
2049 2049
2050 delegate->Reset(); 2050 delegate->Reset();
2051 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2051 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2052 kTouchId1, GetTime()); 2052 kTouchId1, GetTime());
2053 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2053 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2054 2054
2055 delegate->Reset(); 2055 delegate->Reset();
2056 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2056 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2057 kTouchId2, GetTime()); 2057 kTouchId2, GetTime());
2058 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2058 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2059 2059
2060 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 2060 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get());
2061 EXPECT_FALSE(delegate->two_finger_tap()); 2061 EXPECT_FALSE(delegate->two_finger_tap());
2062 EXPECT_TRUE(delegate->pinch_begin()); 2062 EXPECT_TRUE(delegate->pinch_begin());
2063 2063
2064 // Make sure there is enough delay before the touch is released so that it 2064 // Make sure there is enough delay before the touch is released so that it
2065 // is recognized as a tap. 2065 // is recognized as a tap.
2066 delegate->Reset(); 2066 delegate->Reset();
2067 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2067 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2068 kTouchId2, press1.time_stamp() + 2068 kTouchId2, press1.time_stamp() +
2069 base::TimeDelta::FromMilliseconds(50)); 2069 base::TimeDelta::FromMilliseconds(50));
2070 2070
2071 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2071 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2072 EXPECT_FALSE(delegate->two_finger_tap()); 2072 EXPECT_FALSE(delegate->two_finger_tap());
2073 EXPECT_TRUE(delegate->pinch_end()); 2073 EXPECT_TRUE(delegate->pinch_end());
2074 } 2074 }
2075 2075
2076 // Test moving second finger 2076 // Test moving second finger
2077 { 2077 {
2078 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2078 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2079 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2079 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2080 delegate.get(), -1234, bounds, NULL)); 2080 delegate.get(), -1234, bounds, NULL));
2081 2081
2082 delegate->Reset(); 2082 delegate->Reset();
2083 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2083 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2084 kTouchId1, GetTime()); 2084 kTouchId1, GetTime());
2085 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2085 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2086 2086
2087 delegate->Reset(); 2087 delegate->Reset();
2088 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2088 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2089 kTouchId2, GetTime()); 2089 kTouchId2, GetTime());
2090 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2090 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2091 2091
2092 SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get()); 2092 SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get());
2093 EXPECT_FALSE(delegate->two_finger_tap()); 2093 EXPECT_FALSE(delegate->two_finger_tap());
2094 EXPECT_TRUE(delegate->pinch_begin()); 2094 EXPECT_TRUE(delegate->pinch_begin());
2095 2095
2096 // Make sure there is enough delay before the touch is released so that it 2096 // Make sure there is enough delay before the touch is released so that it
2097 // is recognized as a tap. 2097 // is recognized as a tap.
2098 delegate->Reset(); 2098 delegate->Reset();
2099 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2099 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2100 kTouchId1, press1.time_stamp() + 2100 kTouchId1, press1.time_stamp() +
2101 base::TimeDelta::FromMilliseconds(50)); 2101 base::TimeDelta::FromMilliseconds(50));
2102 2102
2103 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2103 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2104 EXPECT_FALSE(delegate->two_finger_tap()); 2104 EXPECT_FALSE(delegate->two_finger_tap());
2105 EXPECT_TRUE(delegate->pinch_end()); 2105 EXPECT_TRUE(delegate->pinch_end());
2106 } 2106 }
2107 } 2107 }
2108 2108
2109 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { 2109 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) {
2110 scoped_ptr<GestureEventConsumeDelegate> delegate( 2110 scoped_ptr<GestureEventConsumeDelegate> delegate(
2111 new GestureEventConsumeDelegate()); 2111 new GestureEventConsumeDelegate());
2112 const int kWindowWidth = 123; 2112 const int kWindowWidth = 123;
2113 const int kWindowHeight = 45; 2113 const int kWindowHeight = 45;
2114 const int kTouchId1 = 2; 2114 const int kTouchId1 = 2;
2115 const int kTouchId2 = 3; 2115 const int kTouchId2 = 3;
2116 2116
2117 // Test canceling first finger. 2117 // Test canceling first finger.
2118 { 2118 {
2119 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2119 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2120 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2120 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2121 delegate.get(), -1234, bounds, NULL)); 2121 delegate.get(), -1234, bounds, NULL));
2122 2122
2123 delegate->Reset(); 2123 delegate->Reset();
2124 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2124 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2125 kTouchId1, GetTime()); 2125 kTouchId1, GetTime());
2126 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2126 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2127 2127
2128 delegate->Reset(); 2128 delegate->Reset();
2129 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2129 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2130 kTouchId2, GetTime()); 2130 kTouchId2, GetTime());
2131 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2131 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2132 2132
2133 delegate->Reset(); 2133 delegate->Reset();
2134 ui::TouchEventImpl cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), 2134 ui::TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201),
2135 kTouchId1, GetTime()); 2135 kTouchId1, GetTime());
2136 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); 2136 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel);
2137 EXPECT_FALSE(delegate->two_finger_tap()); 2137 EXPECT_FALSE(delegate->two_finger_tap());
2138 2138
2139 // Make sure there is enough delay before the touch is released so that it 2139 // Make sure there is enough delay before the touch is released so that it
2140 // is recognized as a tap. 2140 // is recognized as a tap.
2141 delegate->Reset(); 2141 delegate->Reset();
2142 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2142 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2143 kTouchId2, press1.time_stamp() + 2143 kTouchId2, press1.time_stamp() +
2144 base::TimeDelta::FromMilliseconds(50)); 2144 base::TimeDelta::FromMilliseconds(50));
2145 2145
2146 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2146 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2147 EXPECT_FALSE(delegate->two_finger_tap()); 2147 EXPECT_FALSE(delegate->two_finger_tap());
2148 } 2148 }
2149 2149
2150 // Test canceling second finger 2150 // Test canceling second finger
2151 { 2151 {
2152 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2152 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2153 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2153 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2154 delegate.get(), -1234, bounds, NULL)); 2154 delegate.get(), -1234, bounds, NULL));
2155 2155
2156 delegate->Reset(); 2156 delegate->Reset();
2157 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2157 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2158 kTouchId1, GetTime()); 2158 kTouchId1, GetTime());
2159 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2159 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2160 2160
2161 delegate->Reset(); 2161 delegate->Reset();
2162 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2162 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201),
2163 kTouchId2, GetTime()); 2163 kTouchId2, GetTime());
2164 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2164 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2165 2165
2166 delegate->Reset(); 2166 delegate->Reset();
2167 ui::TouchEventImpl cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), 2167 ui::TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201),
2168 kTouchId2, GetTime()); 2168 kTouchId2, GetTime());
2169 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); 2169 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel);
2170 EXPECT_FALSE(delegate->two_finger_tap()); 2170 EXPECT_FALSE(delegate->two_finger_tap());
2171 2171
2172 // Make sure there is enough delay before the touch is released so that it 2172 // Make sure there is enough delay before the touch is released so that it
2173 // is recognized as a tap. 2173 // is recognized as a tap.
2174 delegate->Reset(); 2174 delegate->Reset();
2175 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2175 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2176 kTouchId1, press1.time_stamp() + 2176 kTouchId1, press1.time_stamp() +
2177 base::TimeDelta::FromMilliseconds(50)); 2177 base::TimeDelta::FromMilliseconds(50));
2178 2178
2179 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2179 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2180 EXPECT_FALSE(delegate->two_finger_tap()); 2180 EXPECT_FALSE(delegate->two_finger_tap());
2181 } 2181 }
2182 } 2182 }
2183 2183
2184 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { 2184 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) {
2185 scoped_ptr<GestureEventConsumeDelegate> delegate( 2185 scoped_ptr<GestureEventConsumeDelegate> delegate(
2186 new GestureEventConsumeDelegate()); 2186 new GestureEventConsumeDelegate());
2187 const int kWindowWidth = 523; 2187 const int kWindowWidth = 523;
2188 const int kWindowHeight = 45; 2188 const int kWindowHeight = 45;
2189 const int kTouchId1 = 2; 2189 const int kTouchId1 = 2;
2190 const int kTouchId2 = 3; 2190 const int kTouchId2 = 3;
2191 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2191 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2192 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2192 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2193 delegate.get(), -1234, bounds, NULL)); 2193 delegate.get(), -1234, bounds, NULL));
2194 2194
2195 delegate->Reset(); 2195 delegate->Reset();
2196 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2196 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2197 kTouchId1, GetTime()); 2197 kTouchId1, GetTime());
2198 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2198 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2199 EXPECT_FALSE(delegate->tap()); 2199 EXPECT_FALSE(delegate->tap());
2200 EXPECT_TRUE(delegate->tap_down()); 2200 EXPECT_TRUE(delegate->tap_down());
2201 EXPECT_FALSE(delegate->double_tap()); 2201 EXPECT_FALSE(delegate->double_tap());
2202 EXPECT_FALSE(delegate->scroll_begin()); 2202 EXPECT_FALSE(delegate->scroll_begin());
2203 EXPECT_FALSE(delegate->scroll_update()); 2203 EXPECT_FALSE(delegate->scroll_update());
2204 EXPECT_FALSE(delegate->scroll_end()); 2204 EXPECT_FALSE(delegate->scroll_end());
2205 EXPECT_FALSE(delegate->long_press()); 2205 EXPECT_FALSE(delegate->long_press());
2206 EXPECT_FALSE(delegate->two_finger_tap()); 2206 EXPECT_FALSE(delegate->two_finger_tap());
2207 2207
2208 delegate->Reset(); 2208 delegate->Reset();
2209 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201), 2209 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201),
2210 kTouchId2, GetTime()); 2210 kTouchId2, GetTime());
2211 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2211 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2212 EXPECT_FALSE(delegate->tap()); 2212 EXPECT_FALSE(delegate->tap());
2213 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 2213 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap.
2214 EXPECT_FALSE(delegate->double_tap()); 2214 EXPECT_FALSE(delegate->double_tap());
2215 EXPECT_TRUE(delegate->scroll_begin()); 2215 EXPECT_TRUE(delegate->scroll_begin());
2216 EXPECT_FALSE(delegate->scroll_update()); 2216 EXPECT_FALSE(delegate->scroll_update());
2217 EXPECT_FALSE(delegate->scroll_end()); 2217 EXPECT_FALSE(delegate->scroll_end());
2218 EXPECT_FALSE(delegate->long_press()); 2218 EXPECT_FALSE(delegate->long_press());
2219 EXPECT_FALSE(delegate->two_finger_tap()); 2219 EXPECT_FALSE(delegate->two_finger_tap());
2220 EXPECT_TRUE(delegate->pinch_begin()); 2220 EXPECT_TRUE(delegate->pinch_begin());
2221 } 2221 }
2222 2222
2223 // Verifies if a window is the target of multiple touch-ids and we hide the 2223 // Verifies if a window is the target of multiple touch-ids and we hide the
2224 // window everything is cleaned up correctly. 2224 // window everything is cleaned up correctly.
2225 TEST_F(GestureRecognizerTest, FlushAllOnHide) { 2225 TEST_F(GestureRecognizerTest, FlushAllOnHide) {
2226 scoped_ptr<GestureEventConsumeDelegate> delegate( 2226 scoped_ptr<GestureEventConsumeDelegate> delegate(
2227 new GestureEventConsumeDelegate()); 2227 new GestureEventConsumeDelegate());
2228 gfx::Rect bounds(0, 0, 200, 200); 2228 gfx::Rect bounds(0, 0, 200, 200);
2229 scoped_ptr<aura::Window> window( 2229 scoped_ptr<aura::Window> window(
2230 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL)); 2230 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL));
2231 const int kTouchId1 = 8; 2231 const int kTouchId1 = 8;
2232 const int kTouchId2 = 2; 2232 const int kTouchId2 = 2;
2233 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2233 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10),
2234 kTouchId1, GetTime()); 2234 kTouchId1, GetTime());
2235 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2235 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2236 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2236 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20),
2237 kTouchId2, GetTime()); 2237 kTouchId2, GetTime());
2238 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2238 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2239 window->Hide(); 2239 window->Hide();
2240 EXPECT_EQ(NULL, 2240 EXPECT_EQ(NULL,
2241 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1)); 2241 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1));
2242 EXPECT_EQ(NULL, 2242 EXPECT_EQ(NULL,
2243 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2)); 2243 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2));
2244 } 2244 }
2245 2245
2246 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { 2246 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) {
2247 scoped_ptr<QueueTouchEventDelegate> delegate( 2247 scoped_ptr<QueueTouchEventDelegate> delegate(
2248 new QueueTouchEventDelegate(root_window())); 2248 new QueueTouchEventDelegate(root_window()));
2249 const int kTouchId = 2; 2249 const int kTouchId = 2;
2250 gfx::Rect bounds(100, 200, 100, 100); 2250 gfx::Rect bounds(100, 200, 100, 100);
2251 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2251 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2252 delegate.get(), -1234, bounds, NULL)); 2252 delegate.get(), -1234, bounds, NULL));
2253 delegate->set_window(window.get()); 2253 delegate->set_window(window.get());
2254 2254
2255 TimerTestGestureRecognizer* gesture_recognizer = 2255 TimerTestGestureRecognizer* gesture_recognizer =
2256 new TimerTestGestureRecognizer(root_window()); 2256 new TimerTestGestureRecognizer(root_window());
2257 TimerTestGestureSequence* gesture_sequence = 2257 TimerTestGestureSequence* gesture_sequence =
2258 static_cast<TimerTestGestureSequence*>( 2258 static_cast<TimerTestGestureSequence*>(
2259 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 2259 gesture_recognizer->GetGestureSequenceForTesting(window.get()));
2260 2260
2261 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2261 root_window()->SetGestureRecognizerForTesting(gesture_recognizer);
2262 2262
2263 delegate->Reset(); 2263 delegate->Reset();
2264 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2264 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2265 kTouchId, GetTime()); 2265 kTouchId, GetTime());
2266 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2266 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
2267 // Scroll around, to cancel the long press 2267 // Scroll around, to cancel the long press
2268 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 2268 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get());
2269 2269
2270 delegate->Reset(); 2270 delegate->Reset();
2271 delegate->ReceivedAck(); 2271 delegate->ReceivedAck();
2272 EXPECT_TRUE(delegate->tap_down()); 2272 EXPECT_TRUE(delegate->tap_down());
2273 EXPECT_TRUE(gesture_sequence->IsTimerRunning()); 2273 EXPECT_TRUE(gesture_sequence->IsTimerRunning());
2274 2274
2275 delegate->Reset(); 2275 delegate->Reset();
2276 delegate->ReceivedAckPreventDefaulted(); 2276 delegate->ReceivedAckPreventDefaulted();
2277 EXPECT_FALSE(gesture_sequence->IsTimerRunning()); 2277 EXPECT_FALSE(gesture_sequence->IsTimerRunning());
2278 gesture_sequence->ForceTimeout(); 2278 gesture_sequence->ForceTimeout();
2279 EXPECT_FALSE(delegate->long_press()); 2279 EXPECT_FALSE(delegate->long_press());
2280 } 2280 }
2281 2281
2282 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events. 2282 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events.
2283 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate { 2283 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate {
2284 public: 2284 public:
2285 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {} 2285 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {}
2286 virtual ~ConsumesTouchMovesDelegate() {} 2286 virtual ~ConsumesTouchMovesDelegate() {}
2287 2287
2288 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; } 2288 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; }
2289 2289
2290 private: 2290 private:
2291 virtual ui::TouchStatus OnTouchEvent(ui::TouchEventImpl* touch) OVERRIDE { 2291 virtual ui::TouchStatus OnTouchEvent(ui::TouchEvent* touch) OVERRIDE {
2292 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED) 2292 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED)
2293 return ui::TOUCH_STATUS_CONTINUE; 2293 return ui::TOUCH_STATUS_CONTINUE;
2294 return GestureEventConsumeDelegate::OnTouchEvent(touch); 2294 return GestureEventConsumeDelegate::OnTouchEvent(touch);
2295 } 2295 }
2296 2296
2297 bool consume_touch_move_; 2297 bool consume_touch_move_;
2298 2298
2299 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 2299 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate);
2300 }; 2300 };
2301 2301
2302 // Same as GestureEventScroll, but tests the different behaviour for consumed 2302 // Same as GestureEventScroll, but tests the different behaviour for consumed
2303 // touch-move events before and after scroll has started. 2303 // touch-move events before and after scroll has started.
2304 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) { 2304 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) {
2305 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 2305 scoped_ptr<ConsumesTouchMovesDelegate> delegate(
2306 new ConsumesTouchMovesDelegate()); 2306 new ConsumesTouchMovesDelegate());
2307 const int kWindowWidth = 123; 2307 const int kWindowWidth = 123;
2308 const int kWindowHeight = 45; 2308 const int kWindowHeight = 45;
2309 const int kTouchId = 5; 2309 const int kTouchId = 5;
2310 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2310 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2311 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2311 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2312 delegate.get(), -1234, bounds, NULL)); 2312 delegate.get(), -1234, bounds, NULL));
2313 2313
2314 delegate->Reset(); 2314 delegate->Reset();
2315 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2315 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2316 kTouchId, GetTime()); 2316 kTouchId, GetTime());
2317 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2317 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
2318 EXPECT_FALSE(delegate->tap()); 2318 EXPECT_FALSE(delegate->tap());
2319 EXPECT_TRUE(delegate->tap_down()); 2319 EXPECT_TRUE(delegate->tap_down());
2320 EXPECT_TRUE(delegate->begin()); 2320 EXPECT_TRUE(delegate->begin());
2321 EXPECT_FALSE(delegate->double_tap()); 2321 EXPECT_FALSE(delegate->double_tap());
2322 EXPECT_FALSE(delegate->scroll_begin()); 2322 EXPECT_FALSE(delegate->scroll_begin());
2323 EXPECT_FALSE(delegate->scroll_update()); 2323 EXPECT_FALSE(delegate->scroll_update());
2324 EXPECT_FALSE(delegate->scroll_end()); 2324 EXPECT_FALSE(delegate->scroll_end());
2325 2325
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
2373 EXPECT_FALSE(delegate->begin()); 2373 EXPECT_FALSE(delegate->begin());
2374 EXPECT_FALSE(delegate->double_tap()); 2374 EXPECT_FALSE(delegate->double_tap());
2375 EXPECT_FALSE(delegate->scroll_begin()); 2375 EXPECT_FALSE(delegate->scroll_begin());
2376 EXPECT_TRUE(delegate->scroll_update()); 2376 EXPECT_TRUE(delegate->scroll_update());
2377 EXPECT_FALSE(delegate->scroll_end()); 2377 EXPECT_FALSE(delegate->scroll_end());
2378 EXPECT_EQ(30, delegate->scroll_x()); 2378 EXPECT_EQ(30, delegate->scroll_x());
2379 EXPECT_EQ(4, delegate->scroll_y()); 2379 EXPECT_EQ(4, delegate->scroll_y());
2380 2380
2381 // Release the touch. This should end the scroll. 2381 // Release the touch. This should end the scroll.
2382 delegate->Reset(); 2382 delegate->Reset();
2383 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2383 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2384 kTouchId, press.time_stamp() + 2384 kTouchId, press.time_stamp() +
2385 base::TimeDelta::FromMilliseconds(50)); 2385 base::TimeDelta::FromMilliseconds(50));
2386 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2386 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release);
2387 EXPECT_FALSE(delegate->tap()); 2387 EXPECT_FALSE(delegate->tap());
2388 EXPECT_FALSE(delegate->tap_down()); 2388 EXPECT_FALSE(delegate->tap_down());
2389 EXPECT_FALSE(delegate->begin()); 2389 EXPECT_FALSE(delegate->begin());
2390 EXPECT_TRUE(delegate->end()); 2390 EXPECT_TRUE(delegate->end());
2391 EXPECT_FALSE(delegate->double_tap()); 2391 EXPECT_FALSE(delegate->double_tap());
2392 EXPECT_FALSE(delegate->scroll_begin()); 2392 EXPECT_FALSE(delegate->scroll_begin());
2393 EXPECT_FALSE(delegate->scroll_update()); 2393 EXPECT_FALSE(delegate->scroll_update());
2394 EXPECT_TRUE(delegate->scroll_end()); 2394 EXPECT_TRUE(delegate->scroll_end());
2395 } 2395 }
2396 2396
2397 // Check that appropriate touch events generate double tap gesture events. 2397 // Check that appropriate touch events generate double tap gesture events.
2398 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) { 2398 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) {
2399 scoped_ptr<GestureEventConsumeDelegate> delegate( 2399 scoped_ptr<GestureEventConsumeDelegate> delegate(
2400 new GestureEventConsumeDelegate()); 2400 new GestureEventConsumeDelegate());
2401 const int kWindowWidth = 123; 2401 const int kWindowWidth = 123;
2402 const int kWindowHeight = 45; 2402 const int kWindowHeight = 45;
2403 const int kTouchId = 2; 2403 const int kTouchId = 2;
2404 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2404 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2405 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2405 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2406 delegate.get(), -1234, bounds, NULL)); 2406 delegate.get(), -1234, bounds, NULL));
2407 2407
2408 // First tap (tested in GestureEventTap) 2408 // First tap (tested in GestureEventTap)
2409 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201), 2409 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201),
2410 kTouchId, GetTime()); 2410 kTouchId, GetTime());
2411 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2411 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2412 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201), 2412 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201),
2413 kTouchId, press1.time_stamp() + 2413 kTouchId, press1.time_stamp() +
2414 base::TimeDelta::FromMilliseconds(50)); 2414 base::TimeDelta::FromMilliseconds(50));
2415 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2415 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2416 delegate->Reset(); 2416 delegate->Reset();
2417 2417
2418 // Second tap 2418 // Second tap
2419 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 203), 2419 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 203),
2420 kTouchId, release1.time_stamp() + 2420 kTouchId, release1.time_stamp() +
2421 base::TimeDelta::FromMilliseconds(200)); 2421 base::TimeDelta::FromMilliseconds(200));
2422 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2422 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2423 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206), 2423 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206),
2424 kTouchId, press2.time_stamp() + 2424 kTouchId, press2.time_stamp() +
2425 base::TimeDelta::FromMilliseconds(50)); 2425 base::TimeDelta::FromMilliseconds(50));
2426 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2426 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2427 2427
2428 EXPECT_TRUE(delegate->tap()); 2428 EXPECT_TRUE(delegate->tap());
2429 EXPECT_TRUE(delegate->tap_down()); 2429 EXPECT_TRUE(delegate->tap_down());
2430 EXPECT_TRUE(delegate->begin()); 2430 EXPECT_TRUE(delegate->begin());
2431 EXPECT_TRUE(delegate->end()); 2431 EXPECT_TRUE(delegate->end());
2432 EXPECT_TRUE(delegate->double_tap()); 2432 EXPECT_TRUE(delegate->double_tap());
2433 EXPECT_FALSE(delegate->scroll_begin()); 2433 EXPECT_FALSE(delegate->scroll_begin());
2434 EXPECT_FALSE(delegate->scroll_update()); 2434 EXPECT_FALSE(delegate->scroll_update());
2435 EXPECT_FALSE(delegate->scroll_end()); 2435 EXPECT_FALSE(delegate->scroll_end());
2436 2436
2437 EXPECT_EQ(2, delegate->tap_count()); 2437 EXPECT_EQ(2, delegate->tap_count());
2438 } 2438 }
2439 2439
2440 // Check that we don't get a double tap when the two taps are far apart. 2440 // Check that we don't get a double tap when the two taps are far apart.
2441 TEST_F(GestureRecognizerTest, TwoTapsFarApart) { 2441 TEST_F(GestureRecognizerTest, TwoTapsFarApart) {
2442 scoped_ptr<GestureEventConsumeDelegate> delegate( 2442 scoped_ptr<GestureEventConsumeDelegate> delegate(
2443 new GestureEventConsumeDelegate()); 2443 new GestureEventConsumeDelegate());
2444 const int kWindowWidth = 123; 2444 const int kWindowWidth = 123;
2445 const int kWindowHeight = 45; 2445 const int kWindowHeight = 45;
2446 const int kTouchId = 2; 2446 const int kTouchId = 2;
2447 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2447 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2448 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2448 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2449 delegate.get(), -1234, bounds, NULL)); 2449 delegate.get(), -1234, bounds, NULL));
2450 2450
2451 // First tap (tested in GestureEventTap) 2451 // First tap (tested in GestureEventTap)
2452 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2452 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2453 kTouchId, GetTime()); 2453 kTouchId, GetTime());
2454 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2454 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2455 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2455 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2456 kTouchId, press1.time_stamp() + 2456 kTouchId, press1.time_stamp() +
2457 base::TimeDelta::FromMilliseconds(50)); 2457 base::TimeDelta::FromMilliseconds(50));
2458 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2458 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2459 delegate->Reset(); 2459 delegate->Reset();
2460 2460
2461 // Second tap, close in time but far in distance 2461 // Second tap, close in time but far in distance
2462 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), 2462 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201),
2463 kTouchId, release1.time_stamp() + 2463 kTouchId, release1.time_stamp() +
2464 base::TimeDelta::FromMilliseconds(200)); 2464 base::TimeDelta::FromMilliseconds(200));
2465 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2465 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2466 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(201, 201), 2466 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(201, 201),
2467 kTouchId, press2.time_stamp() + 2467 kTouchId, press2.time_stamp() +
2468 base::TimeDelta::FromMilliseconds(50)); 2468 base::TimeDelta::FromMilliseconds(50));
2469 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2469 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2470 2470
2471 EXPECT_TRUE(delegate->tap()); 2471 EXPECT_TRUE(delegate->tap());
2472 EXPECT_TRUE(delegate->tap_down()); 2472 EXPECT_TRUE(delegate->tap_down());
2473 EXPECT_TRUE(delegate->begin()); 2473 EXPECT_TRUE(delegate->begin());
2474 EXPECT_TRUE(delegate->end()); 2474 EXPECT_TRUE(delegate->end());
2475 EXPECT_FALSE(delegate->double_tap()); 2475 EXPECT_FALSE(delegate->double_tap());
2476 EXPECT_FALSE(delegate->scroll_begin()); 2476 EXPECT_FALSE(delegate->scroll_begin());
2477 EXPECT_FALSE(delegate->scroll_update()); 2477 EXPECT_FALSE(delegate->scroll_update());
2478 EXPECT_FALSE(delegate->scroll_end()); 2478 EXPECT_FALSE(delegate->scroll_end());
2479 2479
2480 EXPECT_EQ(1, delegate->tap_count()); 2480 EXPECT_EQ(1, delegate->tap_count());
2481 } 2481 }
2482 2482
2483 // Check that we don't get a double tap when the two taps have a long enough 2483 // Check that we don't get a double tap when the two taps have a long enough
2484 // delay in between. 2484 // delay in between.
2485 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) { 2485 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
2486 scoped_ptr<GestureEventConsumeDelegate> delegate( 2486 scoped_ptr<GestureEventConsumeDelegate> delegate(
2487 new GestureEventConsumeDelegate()); 2487 new GestureEventConsumeDelegate());
2488 const int kWindowWidth = 123; 2488 const int kWindowWidth = 123;
2489 const int kWindowHeight = 45; 2489 const int kWindowHeight = 45;
2490 const int kTouchId = 2; 2490 const int kTouchId = 2;
2491 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2491 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2492 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2492 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2493 delegate.get(), -1234, bounds, NULL)); 2493 delegate.get(), -1234, bounds, NULL));
2494 2494
2495 // First tap (tested in GestureEventTap) 2495 // First tap (tested in GestureEventTap)
2496 ui::TouchEventImpl press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2496 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2497 kTouchId, GetTime()); 2497 kTouchId, GetTime());
2498 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2498 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2499 ui::TouchEventImpl release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2499 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2500 kTouchId, press1.time_stamp() + 2500 kTouchId, press1.time_stamp() +
2501 base::TimeDelta::FromMilliseconds(50)); 2501 base::TimeDelta::FromMilliseconds(50));
2502 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2502 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1);
2503 delegate->Reset(); 2503 delegate->Reset();
2504 2504
2505 // Second tap, close in distance but after some delay 2505 // Second tap, close in distance but after some delay
2506 ui::TouchEventImpl press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2506 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
2507 kTouchId, release1.time_stamp() + 2507 kTouchId, release1.time_stamp() +
2508 base::TimeDelta::FromMilliseconds(2000)); 2508 base::TimeDelta::FromMilliseconds(2000));
2509 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2509 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2510 ui::TouchEventImpl release2(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2510 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201),
2511 kTouchId, press2.time_stamp() + 2511 kTouchId, press2.time_stamp() +
2512 base::TimeDelta::FromMilliseconds(50)); 2512 base::TimeDelta::FromMilliseconds(50));
2513 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2513 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2);
2514 2514
2515 EXPECT_TRUE(delegate->tap()); 2515 EXPECT_TRUE(delegate->tap());
2516 EXPECT_TRUE(delegate->tap_down()); 2516 EXPECT_TRUE(delegate->tap_down());
2517 EXPECT_TRUE(delegate->begin()); 2517 EXPECT_TRUE(delegate->begin());
2518 EXPECT_TRUE(delegate->end()); 2518 EXPECT_TRUE(delegate->end());
2519 EXPECT_FALSE(delegate->double_tap()); 2519 EXPECT_FALSE(delegate->double_tap());
2520 EXPECT_FALSE(delegate->scroll_begin()); 2520 EXPECT_FALSE(delegate->scroll_begin());
2521 EXPECT_FALSE(delegate->scroll_update()); 2521 EXPECT_FALSE(delegate->scroll_update());
2522 EXPECT_FALSE(delegate->scroll_end()); 2522 EXPECT_FALSE(delegate->scroll_end());
2523 2523
2524 EXPECT_EQ(1, delegate->tap_count()); 2524 EXPECT_EQ(1, delegate->tap_count());
2525 } 2525 }
2526 2526
2527 // Checks that if the bounding-box of a gesture changes because of change in 2527 // Checks that if the bounding-box of a gesture changes because of change in
2528 // radius of a touch-point, and not because of change in position, then there 2528 // radius of a touch-point, and not because of change in position, then there
2529 // are not gesture events from that. 2529 // are not gesture events from that.
2530 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) { 2530 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
2531 scoped_ptr<GestureEventConsumeDelegate> delegate( 2531 scoped_ptr<GestureEventConsumeDelegate> delegate(
2532 new GestureEventConsumeDelegate()); 2532 new GestureEventConsumeDelegate());
2533 const int kWindowWidth = 234; 2533 const int kWindowWidth = 234;
2534 const int kWindowHeight = 345; 2534 const int kWindowHeight = 345;
2535 const int kTouchId = 5, kTouchId2 = 7; 2535 const int kTouchId = 5, kTouchId2 = 7;
2536 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2536 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
2537 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2537 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
2538 delegate.get(), -1234, bounds, NULL)); 2538 delegate.get(), -1234, bounds, NULL));
2539 2539
2540 ui::TouchEventImpl press1( 2540 ui::TouchEvent press1(
2541 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, GetTime()); 2541 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, GetTime());
2542 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2542 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
2543 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2543 EXPECT_TRUE(delegate->bounding_box().IsEmpty());
2544 2544
2545 delegate->Reset(); 2545 delegate->Reset();
2546 2546
2547 ui::TouchEventImpl press2( 2547 ui::TouchEvent press2(
2548 ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), kTouchId2, 2548 ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), kTouchId2,
2549 press1.time_stamp() + base::TimeDelta::FromMilliseconds(400)); 2549 press1.time_stamp() + base::TimeDelta::FromMilliseconds(400));
2550 press2.set_radius_x(5); 2550 press2.set_radius_x(5);
2551 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2551 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
2552 EXPECT_FALSE(delegate->pinch_begin()); 2552 EXPECT_FALSE(delegate->pinch_begin());
2553 2553
2554 delegate->Reset(); 2554 delegate->Reset();
2555 2555
2556 ui::TouchEventImpl move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId, 2556 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId,
2557 press1.time_stamp() + base::TimeDelta::FromMilliseconds(40)); 2557 press1.time_stamp() + base::TimeDelta::FromMilliseconds(40));
2558 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 2558 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
2559 EXPECT_TRUE(delegate->pinch_begin()); 2559 EXPECT_TRUE(delegate->pinch_begin());
2560 EXPECT_EQ(gfx::Rect(141, 196, 65, 10).ToString(), 2560 EXPECT_EQ(gfx::Rect(141, 196, 65, 10).ToString(),
2561 delegate->bounding_box().ToString()); 2561 delegate->bounding_box().ToString());
2562 2562
2563 delegate->Reset(); 2563 delegate->Reset();
2564 2564
2565 // The position doesn't move, but the radius changes. 2565 // The position doesn't move, but the radius changes.
2566 ui::TouchEventImpl move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId, 2566 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId,
2567 press2.time_stamp() + base::TimeDelta::FromMilliseconds(40)); 2567 press2.time_stamp() + base::TimeDelta::FromMilliseconds(40));
2568 move2.set_radius_x(50); 2568 move2.set_radius_x(50);
2569 move2.set_radius_y(60); 2569 move2.set_radius_y(60);
2570 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2570 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
2571 EXPECT_FALSE(delegate->tap()); 2571 EXPECT_FALSE(delegate->tap());
2572 EXPECT_FALSE(delegate->scroll_update()); 2572 EXPECT_FALSE(delegate->scroll_update());
2573 EXPECT_FALSE(delegate->pinch_update()); 2573 EXPECT_FALSE(delegate->pinch_update());
2574 2574
2575 delegate->Reset(); 2575 delegate->Reset();
2576 } 2576 }
2577 2577
2578 } // namespace test 2578 } // namespace test
2579 } // namespace aura 2579 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/event_filter_unittest.cc ('k') | ui/aura/root_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698