OLD | NEW |
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/event.h" | 9 #include "ui/aura/event.h" |
10 #include "ui/aura/root_window.h" | 10 #include "ui/aura/root_window.h" |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 int x = x_start; | 365 int x = x_start; |
366 int y = y_start; | 366 int y = y_start; |
367 base::TimeDelta time = time_start; | 367 base::TimeDelta time = time_start; |
368 | 368 |
369 for (int i = 0; i < num_steps; i++) { | 369 for (int i = 0; i < num_steps; i++) { |
370 x += dx; | 370 x += dx; |
371 y += dy; | 371 y += dy; |
372 time = time + base::TimeDelta::FromMilliseconds(time_step); | 372 time = time + base::TimeDelta::FromMilliseconds(time_step); |
373 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), | 373 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), |
374 touch_id, time); | 374 touch_id, time); |
375 root_window->DispatchTouchEvent(&move); | 375 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
376 } | 376 } |
377 } | 377 } |
378 | 378 |
379 void SendScrollEvent(RootWindow* root_window, | 379 void SendScrollEvent(RootWindow* root_window, |
380 int x, | 380 int x, |
381 int y, | 381 int y, |
382 int touch_id, | 382 int touch_id, |
383 GestureEventConsumeDelegate* delegate) { | 383 GestureEventConsumeDelegate* delegate) { |
384 delegate->Reset(); | 384 delegate->Reset(); |
385 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), | 385 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), |
386 touch_id, GetTime()); | 386 touch_id, GetTime()); |
387 root_window->DispatchTouchEvent(&move); | 387 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
388 } | 388 } |
389 | 389 |
390 } // namespace | 390 } // namespace |
391 | 391 |
392 typedef AuraTestBase GestureRecognizerTest; | 392 typedef AuraTestBase GestureRecognizerTest; |
393 | 393 |
394 // Check that appropriate touch events generate tap gesture events. | 394 // Check that appropriate touch events generate tap gesture events. |
395 TEST_F(GestureRecognizerTest, GestureEventTap) { | 395 TEST_F(GestureRecognizerTest, GestureEventTap) { |
396 scoped_ptr<GestureEventConsumeDelegate> delegate( | 396 scoped_ptr<GestureEventConsumeDelegate> delegate( |
397 new GestureEventConsumeDelegate()); | 397 new GestureEventConsumeDelegate()); |
398 const int kWindowWidth = 123; | 398 const int kWindowWidth = 123; |
399 const int kWindowHeight = 45; | 399 const int kWindowHeight = 45; |
400 const int kTouchId = 2; | 400 const int kTouchId = 2; |
401 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 401 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
402 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 402 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
403 delegate.get(), -1234, bounds, NULL)); | 403 delegate.get(), -1234, bounds, NULL)); |
404 | 404 |
405 delegate->Reset(); | 405 delegate->Reset(); |
406 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 406 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
407 kTouchId, GetTime()); | 407 kTouchId, GetTime()); |
408 root_window()->DispatchTouchEvent(&press); | 408 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
409 EXPECT_FALSE(delegate->tap()); | 409 EXPECT_FALSE(delegate->tap()); |
410 EXPECT_TRUE(delegate->tap_down()); | 410 EXPECT_TRUE(delegate->tap_down()); |
411 EXPECT_TRUE(delegate->begin()); | 411 EXPECT_TRUE(delegate->begin()); |
412 EXPECT_FALSE(delegate->double_tap()); | 412 EXPECT_FALSE(delegate->double_tap()); |
413 EXPECT_FALSE(delegate->scroll_begin()); | 413 EXPECT_FALSE(delegate->scroll_begin()); |
414 EXPECT_FALSE(delegate->scroll_update()); | 414 EXPECT_FALSE(delegate->scroll_update()); |
415 EXPECT_FALSE(delegate->scroll_end()); | 415 EXPECT_FALSE(delegate->scroll_end()); |
416 EXPECT_FALSE(delegate->long_press()); | 416 EXPECT_FALSE(delegate->long_press()); |
417 | 417 |
418 // Make sure there is enough delay before the touch is released so that it is | 418 // Make sure there is enough delay before the touch is released so that it is |
419 // recognized as a tap. | 419 // recognized as a tap. |
420 delegate->Reset(); | 420 delegate->Reset(); |
421 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 421 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
422 kTouchId, press.time_stamp() + | 422 kTouchId, press.time_stamp() + |
423 base::TimeDelta::FromMilliseconds(50)); | 423 base::TimeDelta::FromMilliseconds(50)); |
424 | 424 |
425 root_window()->DispatchTouchEvent(&release); | 425 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
426 EXPECT_TRUE(delegate->tap()); | 426 EXPECT_TRUE(delegate->tap()); |
427 EXPECT_FALSE(delegate->tap_down()); | 427 EXPECT_FALSE(delegate->tap_down()); |
428 EXPECT_FALSE(delegate->begin()); | 428 EXPECT_FALSE(delegate->begin()); |
429 EXPECT_TRUE(delegate->end()); | 429 EXPECT_TRUE(delegate->end()); |
430 EXPECT_FALSE(delegate->double_tap()); | 430 EXPECT_FALSE(delegate->double_tap()); |
431 EXPECT_FALSE(delegate->scroll_begin()); | 431 EXPECT_FALSE(delegate->scroll_begin()); |
432 EXPECT_FALSE(delegate->scroll_update()); | 432 EXPECT_FALSE(delegate->scroll_update()); |
433 EXPECT_FALSE(delegate->scroll_end()); | 433 EXPECT_FALSE(delegate->scroll_end()); |
434 } | 434 } |
435 | 435 |
436 // Check that appropriate touch events generate tap gesture events | 436 // Check that appropriate touch events generate tap gesture events |
437 // when information about the touch radii are provided. | 437 // when information about the touch radii are provided. |
438 TEST_F(GestureRecognizerTest, GestureEventTapRegion) { | 438 TEST_F(GestureRecognizerTest, GestureEventTapRegion) { |
439 scoped_ptr<GestureEventConsumeDelegate> delegate( | 439 scoped_ptr<GestureEventConsumeDelegate> delegate( |
440 new GestureEventConsumeDelegate()); | 440 new GestureEventConsumeDelegate()); |
441 const int kWindowWidth = 800; | 441 const int kWindowWidth = 800; |
442 const int kWindowHeight = 600; | 442 const int kWindowHeight = 600; |
443 const int kTouchId = 2; | 443 const int kTouchId = 2; |
444 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); | 444 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); |
445 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 445 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
446 delegate.get(), -1234, bounds, NULL)); | 446 delegate.get(), -1234, bounds, NULL)); |
447 | 447 |
448 // Test with no ET_TOUCH_MOVED events. | 448 // Test with no ET_TOUCH_MOVED events. |
449 { | 449 { |
450 delegate->Reset(); | 450 delegate->Reset(); |
451 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 451 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
452 kTouchId, GetTime()); | 452 kTouchId, GetTime()); |
453 press.set_radius_x(5); | 453 press.set_radius_x(5); |
454 press.set_radius_y(12); | 454 press.set_radius_y(12); |
455 root_window()->DispatchTouchEvent(&press); | 455 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
456 EXPECT_FALSE(delegate->tap()); | 456 EXPECT_FALSE(delegate->tap()); |
457 EXPECT_TRUE(delegate->tap_down()); | 457 EXPECT_TRUE(delegate->tap_down()); |
458 EXPECT_TRUE(delegate->begin()); | 458 EXPECT_TRUE(delegate->begin()); |
459 EXPECT_FALSE(delegate->double_tap()); | 459 EXPECT_FALSE(delegate->double_tap()); |
460 EXPECT_FALSE(delegate->scroll_begin()); | 460 EXPECT_FALSE(delegate->scroll_begin()); |
461 EXPECT_FALSE(delegate->scroll_update()); | 461 EXPECT_FALSE(delegate->scroll_update()); |
462 EXPECT_FALSE(delegate->scroll_end()); | 462 EXPECT_FALSE(delegate->scroll_end()); |
463 EXPECT_FALSE(delegate->long_press()); | 463 EXPECT_FALSE(delegate->long_press()); |
464 | 464 |
465 // Make sure there is enough delay before the touch is released so that it | 465 // Make sure there is enough delay before the touch is released so that it |
466 // is recognized as a tap. | 466 // is recognized as a tap. |
467 delegate->Reset(); | 467 delegate->Reset(); |
468 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 468 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
469 kTouchId, press.time_stamp() + | 469 kTouchId, press.time_stamp() + |
470 base::TimeDelta::FromMilliseconds(50)); | 470 base::TimeDelta::FromMilliseconds(50)); |
471 release.set_radius_x(5); | 471 release.set_radius_x(5); |
472 release.set_radius_y(12); | 472 release.set_radius_y(12); |
473 | 473 |
474 root_window()->DispatchTouchEvent(&release); | 474 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
475 EXPECT_TRUE(delegate->tap()); | 475 EXPECT_TRUE(delegate->tap()); |
476 EXPECT_FALSE(delegate->tap_down()); | 476 EXPECT_FALSE(delegate->tap_down()); |
477 EXPECT_FALSE(delegate->begin()); | 477 EXPECT_FALSE(delegate->begin()); |
478 EXPECT_TRUE(delegate->end()); | 478 EXPECT_TRUE(delegate->end()); |
479 EXPECT_FALSE(delegate->double_tap()); | 479 EXPECT_FALSE(delegate->double_tap()); |
480 EXPECT_FALSE(delegate->scroll_begin()); | 480 EXPECT_FALSE(delegate->scroll_begin()); |
481 EXPECT_FALSE(delegate->scroll_update()); | 481 EXPECT_FALSE(delegate->scroll_update()); |
482 EXPECT_FALSE(delegate->scroll_end()); | 482 EXPECT_FALSE(delegate->scroll_end()); |
483 | 483 |
484 gfx::Point actual_point(delegate->tap_location()); | 484 gfx::Point actual_point(delegate->tap_location()); |
485 EXPECT_EQ(24, delegate->bounding_box().width()); | 485 EXPECT_EQ(24, delegate->bounding_box().width()); |
486 EXPECT_EQ(24, delegate->bounding_box().height()); | 486 EXPECT_EQ(24, delegate->bounding_box().height()); |
487 EXPECT_EQ(100, actual_point.x()); | 487 EXPECT_EQ(100, actual_point.x()); |
488 EXPECT_EQ(200, actual_point.y()); | 488 EXPECT_EQ(200, actual_point.y()); |
489 } | 489 } |
490 | 490 |
491 // Test with no ET_TOUCH_MOVED events but different touch points and radii. | 491 // Test with no ET_TOUCH_MOVED events but different touch points and radii. |
492 { | 492 { |
493 delegate->Reset(); | 493 delegate->Reset(); |
494 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), | 494 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), |
495 kTouchId, GetTime()); | 495 kTouchId, GetTime()); |
496 press.set_radius_x(8); | 496 press.set_radius_x(8); |
497 press.set_radius_y(14); | 497 press.set_radius_y(14); |
498 root_window()->DispatchTouchEvent(&press); | 498 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
499 EXPECT_FALSE(delegate->tap()); | 499 EXPECT_FALSE(delegate->tap()); |
500 EXPECT_TRUE(delegate->tap_down()); | 500 EXPECT_TRUE(delegate->tap_down()); |
501 EXPECT_TRUE(delegate->begin()); | 501 EXPECT_TRUE(delegate->begin()); |
502 EXPECT_FALSE(delegate->double_tap()); | 502 EXPECT_FALSE(delegate->double_tap()); |
503 EXPECT_FALSE(delegate->scroll_begin()); | 503 EXPECT_FALSE(delegate->scroll_begin()); |
504 EXPECT_FALSE(delegate->scroll_update()); | 504 EXPECT_FALSE(delegate->scroll_update()); |
505 EXPECT_FALSE(delegate->scroll_end()); | 505 EXPECT_FALSE(delegate->scroll_end()); |
506 EXPECT_FALSE(delegate->long_press()); | 506 EXPECT_FALSE(delegate->long_press()); |
507 | 507 |
508 delegate->Reset(); | 508 delegate->Reset(); |
509 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(377, 291), | 509 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(377, 291), |
510 kTouchId, press.time_stamp() + | 510 kTouchId, press.time_stamp() + |
511 base::TimeDelta::FromMilliseconds(50)); | 511 base::TimeDelta::FromMilliseconds(50)); |
512 release.set_radius_x(20); | 512 release.set_radius_x(20); |
513 release.set_radius_y(13); | 513 release.set_radius_y(13); |
514 | 514 |
515 root_window()->DispatchTouchEvent(&release); | 515 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
516 EXPECT_TRUE(delegate->tap()); | 516 EXPECT_TRUE(delegate->tap()); |
517 EXPECT_FALSE(delegate->tap_down()); | 517 EXPECT_FALSE(delegate->tap_down()); |
518 EXPECT_FALSE(delegate->begin()); | 518 EXPECT_FALSE(delegate->begin()); |
519 EXPECT_TRUE(delegate->end()); | 519 EXPECT_TRUE(delegate->end()); |
520 EXPECT_FALSE(delegate->double_tap()); | 520 EXPECT_FALSE(delegate->double_tap()); |
521 EXPECT_FALSE(delegate->scroll_begin()); | 521 EXPECT_FALSE(delegate->scroll_begin()); |
522 EXPECT_FALSE(delegate->scroll_update()); | 522 EXPECT_FALSE(delegate->scroll_update()); |
523 EXPECT_FALSE(delegate->scroll_end()); | 523 EXPECT_FALSE(delegate->scroll_end()); |
524 | 524 |
525 gfx::Point actual_point(delegate->tap_location()); | 525 gfx::Point actual_point(delegate->tap_location()); |
526 EXPECT_EQ(46, delegate->bounding_box().width()); | 526 EXPECT_EQ(46, delegate->bounding_box().width()); |
527 EXPECT_EQ(40, delegate->bounding_box().height()); | 527 EXPECT_EQ(40, delegate->bounding_box().height()); |
528 EXPECT_EQ(373, actual_point.x()); | 528 EXPECT_EQ(373, actual_point.x()); |
529 EXPECT_EQ(290, actual_point.y()); | 529 EXPECT_EQ(290, actual_point.y()); |
530 } | 530 } |
531 | 531 |
532 // Test with a single ET_TOUCH_MOVED event. | 532 // Test with a single ET_TOUCH_MOVED event. |
533 { | 533 { |
534 delegate->Reset(); | 534 delegate->Reset(); |
535 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), | 535 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), |
536 kTouchId, GetTime()); | 536 kTouchId, GetTime()); |
537 press.set_radius_x(6); | 537 press.set_radius_x(6); |
538 press.set_radius_y(10); | 538 press.set_radius_y(10); |
539 root_window()->DispatchTouchEvent(&press); | 539 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
540 EXPECT_FALSE(delegate->tap()); | 540 EXPECT_FALSE(delegate->tap()); |
541 EXPECT_TRUE(delegate->tap_down()); | 541 EXPECT_TRUE(delegate->tap_down()); |
542 EXPECT_TRUE(delegate->begin()); | 542 EXPECT_TRUE(delegate->begin()); |
543 EXPECT_FALSE(delegate->double_tap()); | 543 EXPECT_FALSE(delegate->double_tap()); |
544 EXPECT_FALSE(delegate->scroll_begin()); | 544 EXPECT_FALSE(delegate->scroll_begin()); |
545 EXPECT_FALSE(delegate->scroll_update()); | 545 EXPECT_FALSE(delegate->scroll_update()); |
546 EXPECT_FALSE(delegate->scroll_end()); | 546 EXPECT_FALSE(delegate->scroll_end()); |
547 EXPECT_FALSE(delegate->long_press()); | 547 EXPECT_FALSE(delegate->long_press()); |
548 | 548 |
549 delegate->Reset(); | 549 delegate->Reset(); |
550 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(52, 200), | 550 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(52, 200), |
551 kTouchId, press.time_stamp() + | 551 kTouchId, press.time_stamp() + |
552 base::TimeDelta::FromMilliseconds(50)); | 552 base::TimeDelta::FromMilliseconds(50)); |
553 move.set_radius_x(8); | 553 move.set_radius_x(8); |
554 move.set_radius_y(12); | 554 move.set_radius_y(12); |
555 root_window()->DispatchTouchEvent(&move); | 555 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
556 EXPECT_FALSE(delegate->tap()); | 556 EXPECT_FALSE(delegate->tap()); |
557 EXPECT_FALSE(delegate->tap_down()); | 557 EXPECT_FALSE(delegate->tap_down()); |
558 EXPECT_FALSE(delegate->begin()); | 558 EXPECT_FALSE(delegate->begin()); |
559 EXPECT_FALSE(delegate->double_tap()); | 559 EXPECT_FALSE(delegate->double_tap()); |
560 EXPECT_FALSE(delegate->scroll_begin()); | 560 EXPECT_FALSE(delegate->scroll_begin()); |
561 EXPECT_FALSE(delegate->scroll_update()); | 561 EXPECT_FALSE(delegate->scroll_update()); |
562 EXPECT_FALSE(delegate->scroll_end()); | 562 EXPECT_FALSE(delegate->scroll_end()); |
563 EXPECT_FALSE(delegate->long_press()); | 563 EXPECT_FALSE(delegate->long_press()); |
564 | 564 |
565 delegate->Reset(); | 565 delegate->Reset(); |
566 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(50, 195), | 566 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(50, 195), |
567 kTouchId, press.time_stamp() + | 567 kTouchId, press.time_stamp() + |
568 base::TimeDelta::FromMilliseconds(50)); | 568 base::TimeDelta::FromMilliseconds(50)); |
569 release.set_radius_x(4); | 569 release.set_radius_x(4); |
570 release.set_radius_y(8); | 570 release.set_radius_y(8); |
571 | 571 |
572 root_window()->DispatchTouchEvent(&release); | 572 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
573 EXPECT_TRUE(delegate->tap()); | 573 EXPECT_TRUE(delegate->tap()); |
574 EXPECT_FALSE(delegate->tap_down()); | 574 EXPECT_FALSE(delegate->tap_down()); |
575 EXPECT_FALSE(delegate->begin()); | 575 EXPECT_FALSE(delegate->begin()); |
576 EXPECT_TRUE(delegate->end()); | 576 EXPECT_TRUE(delegate->end()); |
577 EXPECT_FALSE(delegate->double_tap()); | 577 EXPECT_FALSE(delegate->double_tap()); |
578 EXPECT_FALSE(delegate->scroll_begin()); | 578 EXPECT_FALSE(delegate->scroll_begin()); |
579 EXPECT_FALSE(delegate->scroll_update()); | 579 EXPECT_FALSE(delegate->scroll_update()); |
580 EXPECT_FALSE(delegate->scroll_end()); | 580 EXPECT_FALSE(delegate->scroll_end()); |
581 | 581 |
582 gfx::Point actual_point(delegate->tap_location()); | 582 gfx::Point actual_point(delegate->tap_location()); |
583 EXPECT_EQ(28, delegate->bounding_box().width()); | 583 EXPECT_EQ(28, delegate->bounding_box().width()); |
584 EXPECT_EQ(28, delegate->bounding_box().height()); | 584 EXPECT_EQ(28, delegate->bounding_box().height()); |
585 EXPECT_EQ(49, actual_point.x()); | 585 EXPECT_EQ(49, actual_point.x()); |
586 EXPECT_EQ(200, actual_point.y()); | 586 EXPECT_EQ(200, actual_point.y()); |
587 } | 587 } |
588 | 588 |
589 // Test with a few ET_TOUCH_MOVED events. | 589 // Test with a few ET_TOUCH_MOVED events. |
590 { | 590 { |
591 delegate->Reset(); | 591 delegate->Reset(); |
592 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), | 592 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), |
593 kTouchId, GetTime()); | 593 kTouchId, GetTime()); |
594 press.set_radius_x(7); | 594 press.set_radius_x(7); |
595 press.set_radius_y(10); | 595 press.set_radius_y(10); |
596 root_window()->DispatchTouchEvent(&press); | 596 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
597 EXPECT_FALSE(delegate->tap()); | 597 EXPECT_FALSE(delegate->tap()); |
598 EXPECT_TRUE(delegate->tap_down()); | 598 EXPECT_TRUE(delegate->tap_down()); |
599 EXPECT_TRUE(delegate->begin()); | 599 EXPECT_TRUE(delegate->begin()); |
600 EXPECT_FALSE(delegate->double_tap()); | 600 EXPECT_FALSE(delegate->double_tap()); |
601 EXPECT_FALSE(delegate->scroll_begin()); | 601 EXPECT_FALSE(delegate->scroll_begin()); |
602 EXPECT_FALSE(delegate->scroll_update()); | 602 EXPECT_FALSE(delegate->scroll_update()); |
603 EXPECT_FALSE(delegate->scroll_end()); | 603 EXPECT_FALSE(delegate->scroll_end()); |
604 EXPECT_FALSE(delegate->long_press()); | 604 EXPECT_FALSE(delegate->long_press()); |
605 | 605 |
606 delegate->Reset(); | 606 delegate->Reset(); |
607 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(397, 155), | 607 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(397, 155), |
608 kTouchId, press.time_stamp() + | 608 kTouchId, press.time_stamp() + |
609 base::TimeDelta::FromMilliseconds(50)); | 609 base::TimeDelta::FromMilliseconds(50)); |
610 move.set_radius_x(13); | 610 move.set_radius_x(13); |
611 move.set_radius_y(12); | 611 move.set_radius_y(12); |
612 root_window()->DispatchTouchEvent(&move); | 612 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
613 EXPECT_FALSE(delegate->tap()); | 613 EXPECT_FALSE(delegate->tap()); |
614 EXPECT_FALSE(delegate->tap_down()); | 614 EXPECT_FALSE(delegate->tap_down()); |
615 EXPECT_FALSE(delegate->begin()); | 615 EXPECT_FALSE(delegate->begin()); |
616 EXPECT_FALSE(delegate->double_tap()); | 616 EXPECT_FALSE(delegate->double_tap()); |
617 EXPECT_FALSE(delegate->scroll_begin()); | 617 EXPECT_FALSE(delegate->scroll_begin()); |
618 EXPECT_FALSE(delegate->scroll_update()); | 618 EXPECT_FALSE(delegate->scroll_update()); |
619 EXPECT_FALSE(delegate->scroll_end()); | 619 EXPECT_FALSE(delegate->scroll_end()); |
620 EXPECT_FALSE(delegate->long_press()); | 620 EXPECT_FALSE(delegate->long_press()); |
621 | 621 |
622 delegate->Reset(); | 622 delegate->Reset(); |
623 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(395, 148), | 623 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(395, 148), |
624 kTouchId, move.time_stamp() + | 624 kTouchId, move.time_stamp() + |
625 base::TimeDelta::FromMilliseconds(50)); | 625 base::TimeDelta::FromMilliseconds(50)); |
626 move1.set_radius_x(16); | 626 move1.set_radius_x(16); |
627 move1.set_radius_y(16); | 627 move1.set_radius_y(16); |
628 root_window()->DispatchTouchEvent(&move1); | 628 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); |
629 EXPECT_FALSE(delegate->tap()); | 629 EXPECT_FALSE(delegate->tap()); |
630 EXPECT_FALSE(delegate->tap_down()); | 630 EXPECT_FALSE(delegate->tap_down()); |
631 EXPECT_FALSE(delegate->begin()); | 631 EXPECT_FALSE(delegate->begin()); |
632 EXPECT_FALSE(delegate->double_tap()); | 632 EXPECT_FALSE(delegate->double_tap()); |
633 EXPECT_FALSE(delegate->scroll_begin()); | 633 EXPECT_FALSE(delegate->scroll_begin()); |
634 EXPECT_FALSE(delegate->scroll_update()); | 634 EXPECT_FALSE(delegate->scroll_update()); |
635 EXPECT_FALSE(delegate->scroll_end()); | 635 EXPECT_FALSE(delegate->scroll_end()); |
636 EXPECT_FALSE(delegate->long_press()); | 636 EXPECT_FALSE(delegate->long_press()); |
637 | 637 |
638 delegate->Reset(); | 638 delegate->Reset(); |
639 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150), | 639 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150), |
640 kTouchId, move1.time_stamp() + | 640 kTouchId, move1.time_stamp() + |
641 base::TimeDelta::FromMilliseconds(50)); | 641 base::TimeDelta::FromMilliseconds(50)); |
642 move2.set_radius_x(14); | 642 move2.set_radius_x(14); |
643 move2.set_radius_y(10); | 643 move2.set_radius_y(10); |
644 root_window()->DispatchTouchEvent(&move2); | 644 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
645 EXPECT_FALSE(delegate->tap()); | 645 EXPECT_FALSE(delegate->tap()); |
646 EXPECT_FALSE(delegate->tap_down()); | 646 EXPECT_FALSE(delegate->tap_down()); |
647 EXPECT_FALSE(delegate->begin()); | 647 EXPECT_FALSE(delegate->begin()); |
648 EXPECT_FALSE(delegate->double_tap()); | 648 EXPECT_FALSE(delegate->double_tap()); |
649 EXPECT_FALSE(delegate->scroll_begin()); | 649 EXPECT_FALSE(delegate->scroll_begin()); |
650 EXPECT_FALSE(delegate->scroll_update()); | 650 EXPECT_FALSE(delegate->scroll_update()); |
651 EXPECT_FALSE(delegate->scroll_end()); | 651 EXPECT_FALSE(delegate->scroll_end()); |
652 EXPECT_FALSE(delegate->long_press()); | 652 EXPECT_FALSE(delegate->long_press()); |
653 | 653 |
654 delegate->Reset(); | 654 delegate->Reset(); |
655 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149), | 655 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149), |
656 kTouchId, press.time_stamp() + | 656 kTouchId, press.time_stamp() + |
657 base::TimeDelta::FromMilliseconds(50)); | 657 base::TimeDelta::FromMilliseconds(50)); |
658 release.set_radius_x(8); | 658 release.set_radius_x(8); |
659 release.set_radius_y(9); | 659 release.set_radius_y(9); |
660 | 660 |
661 root_window()->DispatchTouchEvent(&release); | 661 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
662 EXPECT_TRUE(delegate->tap()); | 662 EXPECT_TRUE(delegate->tap()); |
663 EXPECT_FALSE(delegate->tap_down()); | 663 EXPECT_FALSE(delegate->tap_down()); |
664 EXPECT_FALSE(delegate->begin()); | 664 EXPECT_FALSE(delegate->begin()); |
665 EXPECT_TRUE(delegate->end()); | 665 EXPECT_TRUE(delegate->end()); |
666 EXPECT_FALSE(delegate->double_tap()); | 666 EXPECT_FALSE(delegate->double_tap()); |
667 EXPECT_FALSE(delegate->scroll_begin()); | 667 EXPECT_FALSE(delegate->scroll_begin()); |
668 EXPECT_FALSE(delegate->scroll_update()); | 668 EXPECT_FALSE(delegate->scroll_update()); |
669 EXPECT_FALSE(delegate->scroll_end()); | 669 EXPECT_FALSE(delegate->scroll_end()); |
670 | 670 |
671 gfx::Point actual_point(delegate->tap_location()); | 671 gfx::Point actual_point(delegate->tap_location()); |
(...skipping 11 matching lines...) Expand all Loading... |
683 const int kWindowWidth = 123; | 683 const int kWindowWidth = 123; |
684 const int kWindowHeight = 45; | 684 const int kWindowHeight = 45; |
685 const int kTouchId = 5; | 685 const int kTouchId = 5; |
686 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 686 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
687 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 687 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
688 delegate.get(), -1234, bounds, NULL)); | 688 delegate.get(), -1234, bounds, NULL)); |
689 | 689 |
690 delegate->Reset(); | 690 delegate->Reset(); |
691 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 691 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
692 kTouchId, GetTime()); | 692 kTouchId, GetTime()); |
693 root_window()->DispatchTouchEvent(&press); | 693 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
694 EXPECT_FALSE(delegate->tap()); | 694 EXPECT_FALSE(delegate->tap()); |
695 EXPECT_TRUE(delegate->tap_down()); | 695 EXPECT_TRUE(delegate->tap_down()); |
696 EXPECT_TRUE(delegate->begin()); | 696 EXPECT_TRUE(delegate->begin()); |
697 EXPECT_FALSE(delegate->double_tap()); | 697 EXPECT_FALSE(delegate->double_tap()); |
698 EXPECT_FALSE(delegate->scroll_begin()); | 698 EXPECT_FALSE(delegate->scroll_begin()); |
699 EXPECT_FALSE(delegate->scroll_update()); | 699 EXPECT_FALSE(delegate->scroll_update()); |
700 EXPECT_FALSE(delegate->scroll_end()); | 700 EXPECT_FALSE(delegate->scroll_end()); |
701 | 701 |
702 // Move the touch-point enough so that it is considered as a scroll. This | 702 // Move the touch-point enough so that it is considered as a scroll. This |
703 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. | 703 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
743 EXPECT_FALSE(delegate->scroll_end()); | 743 EXPECT_FALSE(delegate->scroll_end()); |
744 EXPECT_EQ(30, delegate->scroll_x()); | 744 EXPECT_EQ(30, delegate->scroll_x()); |
745 EXPECT_EQ(4, delegate->scroll_y()); | 745 EXPECT_EQ(4, delegate->scroll_y()); |
746 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 746 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
747 | 747 |
748 // Release the touch. This should end the scroll. | 748 // Release the touch. This should end the scroll. |
749 delegate->Reset(); | 749 delegate->Reset(); |
750 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 750 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
751 kTouchId, press.time_stamp() + | 751 kTouchId, press.time_stamp() + |
752 base::TimeDelta::FromMilliseconds(50)); | 752 base::TimeDelta::FromMilliseconds(50)); |
753 root_window()->DispatchTouchEvent(&release); | 753 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
754 EXPECT_FALSE(delegate->tap()); | 754 EXPECT_FALSE(delegate->tap()); |
755 EXPECT_FALSE(delegate->tap_down()); | 755 EXPECT_FALSE(delegate->tap_down()); |
756 EXPECT_FALSE(delegate->begin()); | 756 EXPECT_FALSE(delegate->begin()); |
757 EXPECT_TRUE(delegate->end()); | 757 EXPECT_TRUE(delegate->end()); |
758 EXPECT_FALSE(delegate->double_tap()); | 758 EXPECT_FALSE(delegate->double_tap()); |
759 EXPECT_FALSE(delegate->scroll_begin()); | 759 EXPECT_FALSE(delegate->scroll_begin()); |
760 EXPECT_FALSE(delegate->scroll_update()); | 760 EXPECT_FALSE(delegate->scroll_update()); |
761 EXPECT_TRUE(delegate->scroll_end()); | 761 EXPECT_TRUE(delegate->scroll_end()); |
762 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 762 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
763 } | 763 } |
764 | 764 |
765 // Check that the bounding box during a scroll event is correct. | 765 // Check that the bounding box during a scroll event is correct. |
766 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { | 766 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { |
767 for (int radius = 1; radius <= 10; ++radius) { | 767 for (int radius = 1; radius <= 10; ++radius) { |
768 ui::GestureConfiguration::set_default_radius(radius); | 768 ui::GestureConfiguration::set_default_radius(radius); |
769 scoped_ptr<GestureEventConsumeDelegate> delegate( | 769 scoped_ptr<GestureEventConsumeDelegate> delegate( |
770 new GestureEventConsumeDelegate()); | 770 new GestureEventConsumeDelegate()); |
771 const int kWindowWidth = 123; | 771 const int kWindowWidth = 123; |
772 const int kWindowHeight = 45; | 772 const int kWindowHeight = 45; |
773 const int kTouchId = 5; | 773 const int kTouchId = 5; |
774 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 774 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
775 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 775 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
776 delegate.get(), -1234, bounds, NULL)); | 776 delegate.get(), -1234, bounds, NULL)); |
777 | 777 |
778 const int kPositionX = 101; | 778 const int kPositionX = 101; |
779 const int kPositionY = 201; | 779 const int kPositionY = 201; |
780 delegate->Reset(); | 780 delegate->Reset(); |
781 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(kPositionX, kPositionY), | 781 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(kPositionX, kPositionY), |
782 kTouchId, GetTime()); | 782 kTouchId, GetTime()); |
783 root_window()->DispatchTouchEvent(&press); | 783 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
784 EXPECT_EQ(gfx::Rect(kPositionX - radius, | 784 EXPECT_EQ(gfx::Rect(kPositionX - radius, |
785 kPositionY - radius, | 785 kPositionY - radius, |
786 radius * 2, | 786 radius * 2, |
787 radius * 2).ToString(), | 787 radius * 2).ToString(), |
788 delegate->bounding_box().ToString()); | 788 delegate->bounding_box().ToString()); |
789 | 789 |
790 const int kScrollAmount = 50; | 790 const int kScrollAmount = 50; |
791 SendScrollEvents(root_window(), kPositionX, kPositionY, GetTime(), | 791 SendScrollEvents(root_window(), kPositionX, kPositionY, GetTime(), |
792 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); | 792 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); |
793 EXPECT_EQ(gfx::Point(1, 1).ToString(), | 793 EXPECT_EQ(gfx::Point(1, 1).ToString(), |
794 delegate->scroll_begin_position().ToString()); | 794 delegate->scroll_begin_position().ToString()); |
795 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, | 795 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, |
796 kPositionY + kScrollAmount - radius, | 796 kPositionY + kScrollAmount - radius, |
797 radius * 2, | 797 radius * 2, |
798 radius * 2).ToString(), | 798 radius * 2).ToString(), |
799 delegate->bounding_box().ToString()); | 799 delegate->bounding_box().ToString()); |
800 | 800 |
801 // Release the touch. This should end the scroll. | 801 // Release the touch. This should end the scroll. |
802 delegate->Reset(); | 802 delegate->Reset(); |
803 TouchEvent release(ui::ET_TOUCH_RELEASED, | 803 TouchEvent release(ui::ET_TOUCH_RELEASED, |
804 gfx::Point(kPositionX, kPositionY), | 804 gfx::Point(kPositionX, kPositionY), |
805 kTouchId, press.time_stamp() + | 805 kTouchId, press.time_stamp() + |
806 base::TimeDelta::FromMilliseconds(50)); | 806 base::TimeDelta::FromMilliseconds(50)); |
807 root_window()->DispatchTouchEvent(&release); | 807 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
808 EXPECT_EQ(gfx::Rect(kPositionX - radius, | 808 EXPECT_EQ(gfx::Rect(kPositionX - radius, |
809 kPositionY - radius, | 809 kPositionY - radius, |
810 radius * 2, | 810 radius * 2, |
811 radius * 2).ToString(), | 811 radius * 2).ToString(), |
812 delegate->bounding_box().ToString()); | 812 delegate->bounding_box().ToString()); |
813 } | 813 } |
814 ui::GestureConfiguration::set_default_radius(0); | 814 ui::GestureConfiguration::set_default_radius(0); |
815 } | 815 } |
816 | 816 |
817 // Check Scroll End Events report correct velocities | 817 // Check Scroll End Events report correct velocities |
818 // if the user was on a horizontal rail | 818 // if the user was on a horizontal rail |
819 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { | 819 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { |
820 scoped_ptr<GestureEventConsumeDelegate> delegate( | 820 scoped_ptr<GestureEventConsumeDelegate> delegate( |
821 new GestureEventConsumeDelegate()); | 821 new GestureEventConsumeDelegate()); |
822 const int kTouchId = 7; | 822 const int kTouchId = 7; |
823 gfx::Rect bounds(0, 0, 1000, 1000); | 823 gfx::Rect bounds(0, 0, 1000, 1000); |
824 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 824 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
825 delegate.get(), -1234, bounds, NULL)); | 825 delegate.get(), -1234, bounds, NULL)); |
826 | 826 |
827 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 827 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
828 kTouchId, GetTime()); | 828 kTouchId, GetTime()); |
829 root_window()->DispatchTouchEvent(&press); | 829 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
830 | 830 |
831 // Move the touch-point horizontally enough that it is considered a | 831 // Move the touch-point horizontally enough that it is considered a |
832 // horizontal scroll. | 832 // horizontal scroll. |
833 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); | 833 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); |
834 EXPECT_EQ(0, delegate->scroll_y()); | 834 EXPECT_EQ(0, delegate->scroll_y()); |
835 EXPECT_EQ(20, delegate->scroll_x()); | 835 EXPECT_EQ(20, delegate->scroll_x()); |
836 | 836 |
837 // Get a high x velocity, while still staying on the rail | 837 // Get a high x velocity, while still staying on the rail |
838 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 838 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
839 100, 10, kTouchId, 1, | 839 100, 10, kTouchId, 1, |
840 ui::GestureConfiguration::points_buffered_for_velocity(), | 840 ui::GestureConfiguration::points_buffered_for_velocity(), |
841 delegate.get()); | 841 delegate.get()); |
842 | 842 |
843 delegate->Reset(); | 843 delegate->Reset(); |
844 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 844 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
845 kTouchId, GetTime()); | 845 kTouchId, GetTime()); |
846 root_window()->DispatchTouchEvent(&release); | 846 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
847 | 847 |
848 EXPECT_TRUE(delegate->scroll_end()); | 848 EXPECT_TRUE(delegate->scroll_end()); |
849 EXPECT_EQ(0, delegate->velocity_x()); | 849 EXPECT_EQ(0, delegate->velocity_x()); |
850 EXPECT_EQ(0, delegate->velocity_y()); | 850 EXPECT_EQ(0, delegate->velocity_y()); |
851 } | 851 } |
852 | 852 |
853 // Check Scroll End Events report correct velocities | 853 // Check Scroll End Events report correct velocities |
854 // if the user was on a vertical rail | 854 // if the user was on a vertical rail |
855 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { | 855 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { |
856 scoped_ptr<GestureEventConsumeDelegate> delegate( | 856 scoped_ptr<GestureEventConsumeDelegate> delegate( |
857 new GestureEventConsumeDelegate()); | 857 new GestureEventConsumeDelegate()); |
858 const int kTouchId = 7; | 858 const int kTouchId = 7; |
859 gfx::Rect bounds(0, 0, 1000, 1000); | 859 gfx::Rect bounds(0, 0, 1000, 1000); |
860 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 860 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
861 delegate.get(), -1234, bounds, NULL)); | 861 delegate.get(), -1234, bounds, NULL)); |
862 | 862 |
863 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 863 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
864 kTouchId, GetTime()); | 864 kTouchId, GetTime()); |
865 root_window()->DispatchTouchEvent(&press); | 865 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
866 | 866 |
867 // Move the touch-point vertically enough that it is considered a | 867 // Move the touch-point vertically enough that it is considered a |
868 // vertical scroll. | 868 // vertical scroll. |
869 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); | 869 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); |
870 EXPECT_EQ(20, delegate->scroll_y()); | 870 EXPECT_EQ(20, delegate->scroll_y()); |
871 EXPECT_EQ(0, delegate->scroll_x()); | 871 EXPECT_EQ(0, delegate->scroll_x()); |
872 | 872 |
873 // Get a high y velocity, while still staying on the rail | 873 // Get a high y velocity, while still staying on the rail |
874 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 874 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
875 10, 100, kTouchId, 1, | 875 10, 100, kTouchId, 1, |
876 ui::GestureConfiguration::points_buffered_for_velocity(), | 876 ui::GestureConfiguration::points_buffered_for_velocity(), |
877 delegate.get()); | 877 delegate.get()); |
878 | 878 |
879 delegate->Reset(); | 879 delegate->Reset(); |
880 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 880 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
881 kTouchId, GetTime()); | 881 kTouchId, GetTime()); |
882 root_window()->DispatchTouchEvent(&release); | 882 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
883 | 883 |
884 EXPECT_TRUE(delegate->scroll_end()); | 884 EXPECT_TRUE(delegate->scroll_end()); |
885 EXPECT_EQ(0, delegate->velocity_x()); | 885 EXPECT_EQ(0, delegate->velocity_x()); |
886 EXPECT_EQ(0, delegate->velocity_y()); | 886 EXPECT_EQ(0, delegate->velocity_y()); |
887 } | 887 } |
888 | 888 |
889 // Check Scroll End Events reports zero velocities | 889 // Check Scroll End Events reports zero velocities |
890 // if the user is not on a rail | 890 // if the user is not on a rail |
891 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { | 891 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { |
892 scoped_ptr<GestureEventConsumeDelegate> delegate( | 892 scoped_ptr<GestureEventConsumeDelegate> delegate( |
893 new GestureEventConsumeDelegate()); | 893 new GestureEventConsumeDelegate()); |
894 const int kTouchId = 7; | 894 const int kTouchId = 7; |
895 gfx::Rect bounds(0, 0, 1000, 1000); | 895 gfx::Rect bounds(0, 0, 1000, 1000); |
896 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 896 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
897 delegate.get(), -1234, bounds, NULL)); | 897 delegate.get(), -1234, bounds, NULL)); |
898 | 898 |
899 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 899 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
900 kTouchId, GetTime()); | 900 kTouchId, GetTime()); |
901 root_window()->DispatchTouchEvent(&press); | 901 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
902 | 902 |
903 // Move the touch-point such that a non-rail scroll begins | 903 // Move the touch-point such that a non-rail scroll begins |
904 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); | 904 SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); |
905 EXPECT_EQ(20, delegate->scroll_y()); | 905 EXPECT_EQ(20, delegate->scroll_y()); |
906 EXPECT_EQ(20, delegate->scroll_x()); | 906 EXPECT_EQ(20, delegate->scroll_x()); |
907 | 907 |
908 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), | 908 SendScrollEvents(root_window(), 1, 1, press.time_stamp(), |
909 10, 100, kTouchId, 1, | 909 10, 100, kTouchId, 1, |
910 ui::GestureConfiguration::points_buffered_for_velocity(), | 910 ui::GestureConfiguration::points_buffered_for_velocity(), |
911 delegate.get()); | 911 delegate.get()); |
912 | 912 |
913 delegate->Reset(); | 913 delegate->Reset(); |
914 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 914 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
915 kTouchId, GetTime()); | 915 kTouchId, GetTime()); |
916 root_window()->DispatchTouchEvent(&release); | 916 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
917 | 917 |
918 EXPECT_TRUE(delegate->scroll_end()); | 918 EXPECT_TRUE(delegate->scroll_end()); |
919 EXPECT_EQ(0, delegate->velocity_x()); | 919 EXPECT_EQ(0, delegate->velocity_x()); |
920 EXPECT_EQ(0, delegate->velocity_y()); | 920 EXPECT_EQ(0, delegate->velocity_y()); |
921 } | 921 } |
922 | 922 |
923 // Check that appropriate touch events generate long press events | 923 // Check that appropriate touch events generate long press events |
924 TEST_F(GestureRecognizerTest, GestureEventLongPress) { | 924 TEST_F(GestureRecognizerTest, GestureEventLongPress) { |
925 scoped_ptr<GestureEventConsumeDelegate> delegate( | 925 scoped_ptr<GestureEventConsumeDelegate> delegate( |
926 new GestureEventConsumeDelegate()); | 926 new GestureEventConsumeDelegate()); |
927 const int kWindowWidth = 123; | 927 const int kWindowWidth = 123; |
928 const int kWindowHeight = 45; | 928 const int kWindowHeight = 45; |
929 const int kTouchId = 2; | 929 const int kTouchId = 2; |
930 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 930 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
931 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 931 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
932 delegate.get(), -1234, bounds, NULL)); | 932 delegate.get(), -1234, bounds, NULL)); |
933 | 933 |
934 delegate->Reset(); | 934 delegate->Reset(); |
935 | 935 |
936 TimerTestGestureRecognizer* gesture_recognizer = | 936 TimerTestGestureRecognizer* gesture_recognizer = |
937 new TimerTestGestureRecognizer(root_window()); | 937 new TimerTestGestureRecognizer(root_window()); |
938 TimerTestGestureSequence* gesture_sequence = | 938 TimerTestGestureSequence* gesture_sequence = |
939 static_cast<TimerTestGestureSequence*>( | 939 static_cast<TimerTestGestureSequence*>( |
940 gesture_recognizer->GetGestureSequenceForTesting(window.get())); | 940 gesture_recognizer->GetGestureSequenceForTesting(window.get())); |
941 | 941 |
942 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); | 942 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); |
943 | 943 |
944 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 944 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
945 kTouchId, GetTime()); | 945 kTouchId, GetTime()); |
946 root_window()->DispatchTouchEvent(&press1); | 946 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
947 EXPECT_TRUE(delegate->tap_down()); | 947 EXPECT_TRUE(delegate->tap_down()); |
948 EXPECT_TRUE(delegate->begin()); | 948 EXPECT_TRUE(delegate->begin()); |
949 | 949 |
950 // We haven't pressed long enough for a long press to occur | 950 // We haven't pressed long enough for a long press to occur |
951 EXPECT_FALSE(delegate->long_press()); | 951 EXPECT_FALSE(delegate->long_press()); |
952 | 952 |
953 // Wait until the timer runs out | 953 // Wait until the timer runs out |
954 gesture_sequence->ForceTimeout(); | 954 gesture_sequence->ForceTimeout(); |
955 EXPECT_TRUE(delegate->long_press()); | 955 EXPECT_TRUE(delegate->long_press()); |
956 EXPECT_EQ(0, delegate->touch_id()); | 956 EXPECT_EQ(0, delegate->touch_id()); |
957 | 957 |
958 delegate->Reset(); | 958 delegate->Reset(); |
959 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 959 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
960 kTouchId, GetTime()); | 960 kTouchId, GetTime()); |
961 root_window()->DispatchTouchEvent(&release1); | 961 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
962 EXPECT_FALSE(delegate->long_press()); | 962 EXPECT_FALSE(delegate->long_press()); |
963 } | 963 } |
964 | 964 |
965 // Check that scrolling cancels a long press | 965 // Check that scrolling cancels a long press |
966 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { | 966 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { |
967 scoped_ptr<GestureEventConsumeDelegate> delegate( | 967 scoped_ptr<GestureEventConsumeDelegate> delegate( |
968 new GestureEventConsumeDelegate()); | 968 new GestureEventConsumeDelegate()); |
969 const int kWindowWidth = 123; | 969 const int kWindowWidth = 123; |
970 const int kWindowHeight = 45; | 970 const int kWindowHeight = 45; |
971 const int kTouchId = 6; | 971 const int kTouchId = 6; |
972 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 972 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
973 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 973 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
974 delegate.get(), -1234, bounds, NULL)); | 974 delegate.get(), -1234, bounds, NULL)); |
975 | 975 |
976 delegate->Reset(); | 976 delegate->Reset(); |
977 | 977 |
978 TimerTestGestureRecognizer* gesture_recognizer = | 978 TimerTestGestureRecognizer* gesture_recognizer = |
979 new TimerTestGestureRecognizer(root_window()); | 979 new TimerTestGestureRecognizer(root_window()); |
980 TimerTestGestureSequence* gesture_sequence = | 980 TimerTestGestureSequence* gesture_sequence = |
981 static_cast<TimerTestGestureSequence*>( | 981 static_cast<TimerTestGestureSequence*>( |
982 gesture_recognizer->GetGestureSequenceForTesting(window.get())); | 982 gesture_recognizer->GetGestureSequenceForTesting(window.get())); |
983 | 983 |
984 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); | 984 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); |
985 | 985 |
986 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 986 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
987 kTouchId, GetTime()); | 987 kTouchId, GetTime()); |
988 root_window()->DispatchTouchEvent(&press1); | 988 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
989 EXPECT_TRUE(delegate->tap_down()); | 989 EXPECT_TRUE(delegate->tap_down()); |
990 | 990 |
991 // We haven't pressed long enough for a long press to occur | 991 // We haven't pressed long enough for a long press to occur |
992 EXPECT_FALSE(delegate->long_press()); | 992 EXPECT_FALSE(delegate->long_press()); |
993 | 993 |
994 // Scroll around, to cancel the long press | 994 // Scroll around, to cancel the long press |
995 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); | 995 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); |
996 // Wait until the timer runs out | 996 // Wait until the timer runs out |
997 gesture_sequence->ForceTimeout(); | 997 gesture_sequence->ForceTimeout(); |
998 EXPECT_FALSE(delegate->long_press()); | 998 EXPECT_FALSE(delegate->long_press()); |
999 | 999 |
1000 delegate->Reset(); | 1000 delegate->Reset(); |
1001 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1001 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1002 kTouchId, GetTime()); | 1002 kTouchId, GetTime()); |
1003 root_window()->DispatchTouchEvent(&release1); | 1003 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
1004 EXPECT_FALSE(delegate->long_press()); | 1004 EXPECT_FALSE(delegate->long_press()); |
1005 } | 1005 } |
1006 | 1006 |
1007 // Check that second tap cancels a long press | 1007 // Check that second tap cancels a long press |
1008 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { | 1008 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { |
1009 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1009 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1010 new GestureEventConsumeDelegate()); | 1010 new GestureEventConsumeDelegate()); |
1011 const int kWindowWidth = 300; | 1011 const int kWindowWidth = 300; |
1012 const int kWindowHeight = 400; | 1012 const int kWindowHeight = 400; |
1013 const int kTouchId1 = 8; | 1013 const int kTouchId1 = 8; |
1014 const int kTouchId2 = 2; | 1014 const int kTouchId2 = 2; |
1015 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); | 1015 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); |
1016 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1016 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1017 delegate.get(), -1234, bounds, NULL)); | 1017 delegate.get(), -1234, bounds, NULL)); |
1018 | 1018 |
1019 TimerTestGestureRecognizer* gesture_recognizer = | 1019 TimerTestGestureRecognizer* gesture_recognizer = |
1020 new TimerTestGestureRecognizer(root_window()); | 1020 new TimerTestGestureRecognizer(root_window()); |
1021 TimerTestGestureSequence* gesture_sequence = | 1021 TimerTestGestureSequence* gesture_sequence = |
1022 static_cast<TimerTestGestureSequence*>( | 1022 static_cast<TimerTestGestureSequence*>( |
1023 gesture_recognizer->GetGestureSequenceForTesting(window.get())); | 1023 gesture_recognizer->GetGestureSequenceForTesting(window.get())); |
1024 | 1024 |
1025 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); | 1025 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); |
1026 | 1026 |
1027 delegate->Reset(); | 1027 delegate->Reset(); |
1028 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1028 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1029 kTouchId1, GetTime()); | 1029 kTouchId1, GetTime()); |
1030 root_window()->DispatchTouchEvent(&press); | 1030 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1031 EXPECT_TRUE(delegate->tap_down()); | 1031 EXPECT_TRUE(delegate->tap_down()); |
1032 EXPECT_TRUE(delegate->begin()); | 1032 EXPECT_TRUE(delegate->begin()); |
1033 | 1033 |
1034 // We haven't pressed long enough for a long press to occur | 1034 // We haven't pressed long enough for a long press to occur |
1035 EXPECT_FALSE(delegate->long_press()); | 1035 EXPECT_FALSE(delegate->long_press()); |
1036 | 1036 |
1037 // Second tap, to cancel the long press | 1037 // Second tap, to cancel the long press |
1038 delegate->Reset(); | 1038 delegate->Reset(); |
1039 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), | 1039 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), |
1040 kTouchId2, GetTime()); | 1040 kTouchId2, GetTime()); |
1041 root_window()->DispatchTouchEvent(&press2); | 1041 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1042 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. | 1042 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. |
1043 EXPECT_TRUE(delegate->begin()); | 1043 EXPECT_TRUE(delegate->begin()); |
1044 | 1044 |
1045 // Wait until the timer runs out | 1045 // Wait until the timer runs out |
1046 gesture_sequence->ForceTimeout(); | 1046 gesture_sequence->ForceTimeout(); |
1047 | 1047 |
1048 // No long press occurred | 1048 // No long press occurred |
1049 EXPECT_FALSE(delegate->long_press()); | 1049 EXPECT_FALSE(delegate->long_press()); |
1050 | 1050 |
1051 delegate->Reset(); | 1051 delegate->Reset(); |
1052 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1052 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1053 kTouchId1, GetTime()); | 1053 kTouchId1, GetTime()); |
1054 root_window()->DispatchTouchEvent(&release1); | 1054 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
1055 EXPECT_FALSE(delegate->long_press()); | 1055 EXPECT_FALSE(delegate->long_press()); |
1056 EXPECT_TRUE(delegate->two_finger_tap()); | 1056 EXPECT_TRUE(delegate->two_finger_tap()); |
1057 } | 1057 } |
1058 | 1058 |
1059 // Check that horizontal scroll gestures cause scrolls on horizontal rails. | 1059 // Check that horizontal scroll gestures cause scrolls on horizontal rails. |
1060 // Also tests that horizontal rails can be broken. | 1060 // Also tests that horizontal rails can be broken. |
1061 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { | 1061 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { |
1062 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1062 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1063 new GestureEventConsumeDelegate()); | 1063 new GestureEventConsumeDelegate()); |
1064 const int kTouchId = 7; | 1064 const int kTouchId = 7; |
1065 gfx::Rect bounds(0, 0, 1000, 1000); | 1065 gfx::Rect bounds(0, 0, 1000, 1000); |
1066 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1066 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1067 delegate.get(), -1234, bounds, NULL)); | 1067 delegate.get(), -1234, bounds, NULL)); |
1068 | 1068 |
1069 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 1069 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
1070 kTouchId, GetTime()); | 1070 kTouchId, GetTime()); |
1071 root_window()->DispatchTouchEvent(&press); | 1071 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1072 | 1072 |
1073 // Move the touch-point horizontally enough that it is considered a | 1073 // Move the touch-point horizontally enough that it is considered a |
1074 // horizontal scroll. | 1074 // horizontal scroll. |
1075 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); | 1075 SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); |
1076 EXPECT_EQ(0, delegate->scroll_y()); | 1076 EXPECT_EQ(0, delegate->scroll_y()); |
1077 EXPECT_EQ(20, delegate->scroll_x()); | 1077 EXPECT_EQ(20, delegate->scroll_x()); |
1078 | 1078 |
1079 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); | 1079 SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); |
1080 EXPECT_TRUE(delegate->scroll_update()); | 1080 EXPECT_TRUE(delegate->scroll_update()); |
1081 EXPECT_EQ(5, delegate->scroll_x()); | 1081 EXPECT_EQ(5, delegate->scroll_x()); |
(...skipping 21 matching lines...) Expand all Loading... |
1103 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { | 1103 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { |
1104 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1104 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1105 new GestureEventConsumeDelegate()); | 1105 new GestureEventConsumeDelegate()); |
1106 const int kTouchId = 7; | 1106 const int kTouchId = 7; |
1107 gfx::Rect bounds(0, 0, 1000, 1000); | 1107 gfx::Rect bounds(0, 0, 1000, 1000); |
1108 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1108 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1109 delegate.get(), -1234, bounds, NULL)); | 1109 delegate.get(), -1234, bounds, NULL)); |
1110 | 1110 |
1111 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), | 1111 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), |
1112 kTouchId, GetTime()); | 1112 kTouchId, GetTime()); |
1113 root_window()->DispatchTouchEvent(&press); | 1113 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1114 | 1114 |
1115 // Move the touch-point vertically enough that it is considered a | 1115 // Move the touch-point vertically enough that it is considered a |
1116 // vertical scroll. | 1116 // vertical scroll. |
1117 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); | 1117 SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); |
1118 EXPECT_EQ(0, delegate->scroll_x()); | 1118 EXPECT_EQ(0, delegate->scroll_x()); |
1119 EXPECT_EQ(20, delegate->scroll_y()); | 1119 EXPECT_EQ(20, delegate->scroll_y()); |
1120 | 1120 |
1121 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); | 1121 SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); |
1122 EXPECT_TRUE(delegate->scroll_update()); | 1122 EXPECT_TRUE(delegate->scroll_update()); |
1123 EXPECT_EQ(5, delegate->scroll_y()); | 1123 EXPECT_EQ(5, delegate->scroll_y()); |
(...skipping 23 matching lines...) Expand all Loading... |
1147 const int kWindowWidth = 123; | 1147 const int kWindowWidth = 123; |
1148 const int kWindowHeight = 45; | 1148 const int kWindowHeight = 45; |
1149 const int kTouchId = 3; | 1149 const int kTouchId = 3; |
1150 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1150 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1151 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1151 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1152 delegate.get(), -1234, bounds, NULL)); | 1152 delegate.get(), -1234, bounds, NULL)); |
1153 | 1153 |
1154 delegate->Reset(); | 1154 delegate->Reset(); |
1155 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1155 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1156 kTouchId, GetTime()); | 1156 kTouchId, GetTime()); |
1157 root_window()->DispatchTouchEvent(&press); | 1157 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1158 EXPECT_FALSE(delegate->tap()); | 1158 EXPECT_FALSE(delegate->tap()); |
1159 EXPECT_TRUE(delegate->tap_down()); | 1159 EXPECT_TRUE(delegate->tap_down()); |
1160 EXPECT_FALSE(delegate->double_tap()); | 1160 EXPECT_FALSE(delegate->double_tap()); |
1161 EXPECT_FALSE(delegate->scroll_begin()); | 1161 EXPECT_FALSE(delegate->scroll_begin()); |
1162 EXPECT_FALSE(delegate->scroll_update()); | 1162 EXPECT_FALSE(delegate->scroll_update()); |
1163 EXPECT_FALSE(delegate->scroll_end()); | 1163 EXPECT_FALSE(delegate->scroll_end()); |
1164 | 1164 |
1165 // Make sure there is enough delay before the touch is released so that it is | 1165 // Make sure there is enough delay before the touch is released so that it is |
1166 // recognized as a tap. | 1166 // recognized as a tap. |
1167 delegate->Reset(); | 1167 delegate->Reset(); |
1168 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1168 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1169 kTouchId, press.time_stamp() + | 1169 kTouchId, press.time_stamp() + |
1170 base::TimeDelta::FromMilliseconds(50)); | 1170 base::TimeDelta::FromMilliseconds(50)); |
1171 root_window()->DispatchTouchEvent(&release); | 1171 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
1172 EXPECT_TRUE(delegate->tap()); | 1172 EXPECT_TRUE(delegate->tap()); |
1173 EXPECT_FALSE(delegate->tap_down()); | 1173 EXPECT_FALSE(delegate->tap_down()); |
1174 EXPECT_FALSE(delegate->double_tap()); | 1174 EXPECT_FALSE(delegate->double_tap()); |
1175 EXPECT_FALSE(delegate->scroll_begin()); | 1175 EXPECT_FALSE(delegate->scroll_begin()); |
1176 EXPECT_FALSE(delegate->scroll_update()); | 1176 EXPECT_FALSE(delegate->scroll_update()); |
1177 EXPECT_FALSE(delegate->scroll_end()); | 1177 EXPECT_FALSE(delegate->scroll_end()); |
1178 | 1178 |
1179 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger | 1179 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger |
1180 // a double-tap. | 1180 // a double-tap. |
1181 delegate->Reset(); | 1181 delegate->Reset(); |
1182 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1182 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1183 kTouchId, release.time_stamp() + | 1183 kTouchId, release.time_stamp() + |
1184 base::TimeDelta::FromMilliseconds(1000)); | 1184 base::TimeDelta::FromMilliseconds(1000)); |
1185 root_window()->DispatchTouchEvent(&press1); | 1185 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
1186 EXPECT_FALSE(delegate->tap()); | 1186 EXPECT_FALSE(delegate->tap()); |
1187 EXPECT_TRUE(delegate->tap_down()); | 1187 EXPECT_TRUE(delegate->tap_down()); |
1188 EXPECT_FALSE(delegate->double_tap()); | 1188 EXPECT_FALSE(delegate->double_tap()); |
1189 EXPECT_FALSE(delegate->scroll_begin()); | 1189 EXPECT_FALSE(delegate->scroll_begin()); |
1190 EXPECT_FALSE(delegate->scroll_update()); | 1190 EXPECT_FALSE(delegate->scroll_update()); |
1191 EXPECT_FALSE(delegate->scroll_end()); | 1191 EXPECT_FALSE(delegate->scroll_end()); |
1192 | 1192 |
1193 // Move the touch-point enough so that it is considered as a scroll. This | 1193 // Move the touch-point enough so that it is considered as a scroll. This |
1194 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. | 1194 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. |
1195 // The first movement is diagonal, to ensure that we have a free scroll, | 1195 // The first movement is diagonal, to ensure that we have a free scroll, |
1196 // and not a rail scroll. | 1196 // and not a rail scroll. |
1197 delegate->Reset(); | 1197 delegate->Reset(); |
1198 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), | 1198 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), |
1199 kTouchId, GetTime()); | 1199 kTouchId, GetTime()); |
1200 root_window()->DispatchTouchEvent(&move); | 1200 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
1201 EXPECT_FALSE(delegate->tap()); | 1201 EXPECT_FALSE(delegate->tap()); |
1202 EXPECT_FALSE(delegate->tap_down()); | 1202 EXPECT_FALSE(delegate->tap_down()); |
1203 EXPECT_FALSE(delegate->double_tap()); | 1203 EXPECT_FALSE(delegate->double_tap()); |
1204 EXPECT_TRUE(delegate->scroll_begin()); | 1204 EXPECT_TRUE(delegate->scroll_begin()); |
1205 EXPECT_TRUE(delegate->scroll_update()); | 1205 EXPECT_TRUE(delegate->scroll_update()); |
1206 EXPECT_FALSE(delegate->scroll_end()); | 1206 EXPECT_FALSE(delegate->scroll_end()); |
1207 EXPECT_EQ(29, delegate->scroll_x()); | 1207 EXPECT_EQ(29, delegate->scroll_x()); |
1208 EXPECT_EQ(29, delegate->scroll_y()); | 1208 EXPECT_EQ(29, delegate->scroll_y()); |
1209 | 1209 |
1210 // Move some more to generate a few more scroll updates. | 1210 // Move some more to generate a few more scroll updates. |
1211 delegate->Reset(); | 1211 delegate->Reset(); |
1212 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), | 1212 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), |
1213 kTouchId, GetTime()); | 1213 kTouchId, GetTime()); |
1214 root_window()->DispatchTouchEvent(&move1); | 1214 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); |
1215 EXPECT_FALSE(delegate->tap()); | 1215 EXPECT_FALSE(delegate->tap()); |
1216 EXPECT_FALSE(delegate->tap_down()); | 1216 EXPECT_FALSE(delegate->tap_down()); |
1217 EXPECT_FALSE(delegate->double_tap()); | 1217 EXPECT_FALSE(delegate->double_tap()); |
1218 EXPECT_FALSE(delegate->scroll_begin()); | 1218 EXPECT_FALSE(delegate->scroll_begin()); |
1219 EXPECT_TRUE(delegate->scroll_update()); | 1219 EXPECT_TRUE(delegate->scroll_update()); |
1220 EXPECT_FALSE(delegate->scroll_end()); | 1220 EXPECT_FALSE(delegate->scroll_end()); |
1221 EXPECT_EQ(-20, delegate->scroll_x()); | 1221 EXPECT_EQ(-20, delegate->scroll_x()); |
1222 EXPECT_EQ(-19, delegate->scroll_y()); | 1222 EXPECT_EQ(-19, delegate->scroll_y()); |
1223 | 1223 |
1224 delegate->Reset(); | 1224 delegate->Reset(); |
1225 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), | 1225 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), |
1226 kTouchId, GetTime()); | 1226 kTouchId, GetTime()); |
1227 root_window()->DispatchTouchEvent(&move2); | 1227 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
1228 EXPECT_FALSE(delegate->tap()); | 1228 EXPECT_FALSE(delegate->tap()); |
1229 EXPECT_FALSE(delegate->tap_down()); | 1229 EXPECT_FALSE(delegate->tap_down()); |
1230 EXPECT_FALSE(delegate->double_tap()); | 1230 EXPECT_FALSE(delegate->double_tap()); |
1231 EXPECT_FALSE(delegate->scroll_begin()); | 1231 EXPECT_FALSE(delegate->scroll_begin()); |
1232 EXPECT_TRUE(delegate->scroll_update()); | 1232 EXPECT_TRUE(delegate->scroll_update()); |
1233 EXPECT_FALSE(delegate->scroll_end()); | 1233 EXPECT_FALSE(delegate->scroll_end()); |
1234 EXPECT_EQ(30, delegate->scroll_x()); | 1234 EXPECT_EQ(30, delegate->scroll_x()); |
1235 EXPECT_EQ(4, delegate->scroll_y()); | 1235 EXPECT_EQ(4, delegate->scroll_y()); |
1236 | 1236 |
1237 // Release the touch. This should end the scroll. | 1237 // Release the touch. This should end the scroll. |
1238 delegate->Reset(); | 1238 delegate->Reset(); |
1239 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1239 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1240 kTouchId, GetTime()); | 1240 kTouchId, GetTime()); |
1241 root_window()->DispatchTouchEvent(&release1); | 1241 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
1242 EXPECT_FALSE(delegate->tap()); | 1242 EXPECT_FALSE(delegate->tap()); |
1243 EXPECT_FALSE(delegate->tap_down()); | 1243 EXPECT_FALSE(delegate->tap_down()); |
1244 EXPECT_FALSE(delegate->double_tap()); | 1244 EXPECT_FALSE(delegate->double_tap()); |
1245 EXPECT_FALSE(delegate->scroll_begin()); | 1245 EXPECT_FALSE(delegate->scroll_begin()); |
1246 EXPECT_FALSE(delegate->scroll_update()); | 1246 EXPECT_FALSE(delegate->scroll_update()); |
1247 EXPECT_TRUE(delegate->scroll_end()); | 1247 EXPECT_TRUE(delegate->scroll_end()); |
1248 } | 1248 } |
1249 | 1249 |
1250 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { | 1250 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { |
1251 scoped_ptr<QueueTouchEventDelegate> queued_delegate( | 1251 scoped_ptr<QueueTouchEventDelegate> queued_delegate( |
1252 new QueueTouchEventDelegate(root_window())); | 1252 new QueueTouchEventDelegate(root_window())); |
1253 const int kWindowWidth = 123; | 1253 const int kWindowWidth = 123; |
1254 const int kWindowHeight = 45; | 1254 const int kWindowHeight = 45; |
1255 const int kTouchId1 = 6; | 1255 const int kTouchId1 = 6; |
1256 const int kTouchId2 = 4; | 1256 const int kTouchId2 = 4; |
1257 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1257 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1258 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( | 1258 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( |
1259 queued_delegate.get(), -1234, bounds, NULL)); | 1259 queued_delegate.get(), -1234, bounds, NULL)); |
1260 | 1260 |
1261 queued_delegate->set_window(queue.get()); | 1261 queued_delegate->set_window(queue.get()); |
1262 | 1262 |
1263 // Touch down on the window. This should not generate any gesture event. | 1263 // Touch down on the window. This should not generate any gesture event. |
1264 queued_delegate->Reset(); | 1264 queued_delegate->Reset(); |
1265 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1265 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1266 kTouchId1, GetTime()); | 1266 kTouchId1, GetTime()); |
1267 root_window()->DispatchTouchEvent(&press); | 1267 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1268 EXPECT_FALSE(queued_delegate->tap()); | 1268 EXPECT_FALSE(queued_delegate->tap()); |
1269 EXPECT_FALSE(queued_delegate->tap_down()); | 1269 EXPECT_FALSE(queued_delegate->tap_down()); |
1270 EXPECT_FALSE(queued_delegate->begin()); | 1270 EXPECT_FALSE(queued_delegate->begin()); |
1271 EXPECT_FALSE(queued_delegate->double_tap()); | 1271 EXPECT_FALSE(queued_delegate->double_tap()); |
1272 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1272 EXPECT_FALSE(queued_delegate->scroll_begin()); |
1273 EXPECT_FALSE(queued_delegate->scroll_update()); | 1273 EXPECT_FALSE(queued_delegate->scroll_update()); |
1274 EXPECT_FALSE(queued_delegate->scroll_end()); | 1274 EXPECT_FALSE(queued_delegate->scroll_end()); |
1275 | 1275 |
1276 // Introduce some delay before the touch is released so that it is recognized | 1276 // Introduce some delay before the touch is released so that it is recognized |
1277 // as a tap. However, this still should not create any gesture events. | 1277 // as a tap. However, this still should not create any gesture events. |
1278 queued_delegate->Reset(); | 1278 queued_delegate->Reset(); |
1279 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1279 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1280 kTouchId1, press.time_stamp() + | 1280 kTouchId1, press.time_stamp() + |
1281 base::TimeDelta::FromMilliseconds(50)); | 1281 base::TimeDelta::FromMilliseconds(50)); |
1282 root_window()->DispatchTouchEvent(&release); | 1282 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
1283 EXPECT_FALSE(queued_delegate->tap()); | 1283 EXPECT_FALSE(queued_delegate->tap()); |
1284 EXPECT_FALSE(queued_delegate->tap_down()); | 1284 EXPECT_FALSE(queued_delegate->tap_down()); |
1285 EXPECT_FALSE(queued_delegate->begin()); | 1285 EXPECT_FALSE(queued_delegate->begin()); |
1286 EXPECT_FALSE(queued_delegate->end()); | 1286 EXPECT_FALSE(queued_delegate->end()); |
1287 EXPECT_FALSE(queued_delegate->double_tap()); | 1287 EXPECT_FALSE(queued_delegate->double_tap()); |
1288 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1288 EXPECT_FALSE(queued_delegate->scroll_begin()); |
1289 EXPECT_FALSE(queued_delegate->scroll_update()); | 1289 EXPECT_FALSE(queued_delegate->scroll_update()); |
1290 EXPECT_FALSE(queued_delegate->scroll_end()); | 1290 EXPECT_FALSE(queued_delegate->scroll_end()); |
1291 | 1291 |
1292 // Create another window, and place a touch-down on it. This should create a | 1292 // Create another window, and place a touch-down on it. This should create a |
1293 // tap-down gesture. | 1293 // tap-down gesture. |
1294 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1294 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1295 new GestureEventConsumeDelegate()); | 1295 new GestureEventConsumeDelegate()); |
1296 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1296 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1297 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL)); | 1297 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), NULL)); |
1298 delegate->Reset(); | 1298 delegate->Reset(); |
1299 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), | 1299 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), |
1300 kTouchId2, GetTime()); | 1300 kTouchId2, GetTime()); |
1301 root_window()->DispatchTouchEvent(&press2); | 1301 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1302 EXPECT_FALSE(delegate->tap()); | 1302 EXPECT_FALSE(delegate->tap()); |
1303 EXPECT_TRUE(delegate->tap_down()); | 1303 EXPECT_TRUE(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(delegate->double_tap()); | 1306 EXPECT_FALSE(delegate->double_tap()); |
1307 EXPECT_FALSE(delegate->scroll_begin()); | 1307 EXPECT_FALSE(delegate->scroll_begin()); |
1308 EXPECT_FALSE(delegate->scroll_update()); | 1308 EXPECT_FALSE(delegate->scroll_update()); |
1309 EXPECT_FALSE(delegate->scroll_end()); | 1309 EXPECT_FALSE(delegate->scroll_end()); |
1310 | 1310 |
1311 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), | 1311 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), |
1312 kTouchId2, GetTime()); | 1312 kTouchId2, GetTime()); |
1313 root_window()->DispatchTouchEvent(&release2); | 1313 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); |
1314 | 1314 |
1315 // Process the first queued event. | 1315 // Process the first queued event. |
1316 queued_delegate->Reset(); | 1316 queued_delegate->Reset(); |
1317 queued_delegate->ReceivedAck(); | 1317 queued_delegate->ReceivedAck(); |
1318 EXPECT_FALSE(queued_delegate->tap()); | 1318 EXPECT_FALSE(queued_delegate->tap()); |
1319 EXPECT_TRUE(queued_delegate->tap_down()); | 1319 EXPECT_TRUE(queued_delegate->tap_down()); |
1320 EXPECT_TRUE(queued_delegate->begin()); | 1320 EXPECT_TRUE(queued_delegate->begin()); |
1321 EXPECT_FALSE(queued_delegate->end()); | 1321 EXPECT_FALSE(queued_delegate->end()); |
1322 EXPECT_FALSE(queued_delegate->double_tap()); | 1322 EXPECT_FALSE(queued_delegate->double_tap()); |
1323 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1323 EXPECT_FALSE(queued_delegate->scroll_begin()); |
(...skipping 10 matching lines...) Expand all Loading... |
1334 EXPECT_FALSE(queued_delegate->double_tap()); | 1334 EXPECT_FALSE(queued_delegate->double_tap()); |
1335 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1335 EXPECT_FALSE(queued_delegate->scroll_begin()); |
1336 EXPECT_FALSE(queued_delegate->scroll_update()); | 1336 EXPECT_FALSE(queued_delegate->scroll_update()); |
1337 EXPECT_FALSE(queued_delegate->scroll_end()); | 1337 EXPECT_FALSE(queued_delegate->scroll_end()); |
1338 | 1338 |
1339 // Start all over. Press on the first window, then press again on the second | 1339 // Start all over. Press on the first window, then press again on the second |
1340 // window. The second press should still go to the first window. | 1340 // window. The second press should still go to the first window. |
1341 queued_delegate->Reset(); | 1341 queued_delegate->Reset(); |
1342 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1342 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1343 kTouchId1, GetTime()); | 1343 kTouchId1, GetTime()); |
1344 root_window()->DispatchTouchEvent(&press3); | 1344 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); |
1345 EXPECT_FALSE(queued_delegate->tap()); | 1345 EXPECT_FALSE(queued_delegate->tap()); |
1346 EXPECT_FALSE(queued_delegate->tap_down()); | 1346 EXPECT_FALSE(queued_delegate->tap_down()); |
1347 EXPECT_FALSE(queued_delegate->begin()); | 1347 EXPECT_FALSE(queued_delegate->begin()); |
1348 EXPECT_FALSE(queued_delegate->end()); | 1348 EXPECT_FALSE(queued_delegate->end()); |
1349 EXPECT_FALSE(queued_delegate->begin()); | 1349 EXPECT_FALSE(queued_delegate->begin()); |
1350 EXPECT_FALSE(queued_delegate->end()); | 1350 EXPECT_FALSE(queued_delegate->end()); |
1351 EXPECT_FALSE(queued_delegate->double_tap()); | 1351 EXPECT_FALSE(queued_delegate->double_tap()); |
1352 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1352 EXPECT_FALSE(queued_delegate->scroll_begin()); |
1353 EXPECT_FALSE(queued_delegate->scroll_update()); | 1353 EXPECT_FALSE(queued_delegate->scroll_update()); |
1354 EXPECT_FALSE(queued_delegate->scroll_end()); | 1354 EXPECT_FALSE(queued_delegate->scroll_end()); |
1355 | 1355 |
1356 queued_delegate->Reset(); | 1356 queued_delegate->Reset(); |
1357 delegate->Reset(); | 1357 delegate->Reset(); |
1358 TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203), | 1358 TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203), |
1359 kTouchId2, GetTime()); | 1359 kTouchId2, GetTime()); |
1360 root_window()->DispatchTouchEvent(&press4); | 1360 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press4); |
1361 EXPECT_FALSE(delegate->tap()); | 1361 EXPECT_FALSE(delegate->tap()); |
1362 EXPECT_FALSE(delegate->tap_down()); | 1362 EXPECT_FALSE(delegate->tap_down()); |
1363 EXPECT_FALSE(delegate->begin()); | 1363 EXPECT_FALSE(delegate->begin()); |
1364 EXPECT_FALSE(delegate->end()); | 1364 EXPECT_FALSE(delegate->end()); |
1365 EXPECT_FALSE(delegate->double_tap()); | 1365 EXPECT_FALSE(delegate->double_tap()); |
1366 EXPECT_FALSE(delegate->scroll_begin()); | 1366 EXPECT_FALSE(delegate->scroll_begin()); |
1367 EXPECT_FALSE(delegate->scroll_update()); | 1367 EXPECT_FALSE(delegate->scroll_update()); |
1368 EXPECT_FALSE(delegate->scroll_end()); | 1368 EXPECT_FALSE(delegate->scroll_end()); |
1369 EXPECT_FALSE(queued_delegate->tap()); | 1369 EXPECT_FALSE(queued_delegate->tap()); |
1370 EXPECT_FALSE(queued_delegate->tap_down()); | 1370 EXPECT_FALSE(queued_delegate->tap_down()); |
1371 EXPECT_FALSE(queued_delegate->begin()); | 1371 EXPECT_FALSE(queued_delegate->begin()); |
1372 EXPECT_FALSE(queued_delegate->end()); | 1372 EXPECT_FALSE(queued_delegate->end()); |
1373 EXPECT_FALSE(queued_delegate->double_tap()); | 1373 EXPECT_FALSE(queued_delegate->double_tap()); |
1374 EXPECT_FALSE(queued_delegate->scroll_begin()); | 1374 EXPECT_FALSE(queued_delegate->scroll_begin()); |
1375 EXPECT_FALSE(queued_delegate->scroll_update()); | 1375 EXPECT_FALSE(queued_delegate->scroll_update()); |
1376 EXPECT_FALSE(queued_delegate->scroll_end()); | 1376 EXPECT_FALSE(queued_delegate->scroll_end()); |
1377 | 1377 |
1378 // Move the second touch-point enough so that it is considered a pinch. This | 1378 // Move the second touch-point enough so that it is considered a pinch. This |
1379 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. | 1379 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. |
1380 queued_delegate->Reset(); | 1380 queued_delegate->Reset(); |
1381 delegate->Reset(); | 1381 delegate->Reset(); |
1382 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); | 1382 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); |
1383 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203), | 1383 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203), |
1384 kTouchId2, GetTime()); | 1384 kTouchId2, GetTime()); |
1385 root_window()->DispatchTouchEvent(&move); | 1385 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
1386 EXPECT_FALSE(delegate->tap()); | 1386 EXPECT_FALSE(delegate->tap()); |
1387 EXPECT_FALSE(delegate->tap_down()); | 1387 EXPECT_FALSE(delegate->tap_down()); |
1388 EXPECT_FALSE(delegate->begin()); | 1388 EXPECT_FALSE(delegate->begin()); |
1389 EXPECT_FALSE(delegate->double_tap()); | 1389 EXPECT_FALSE(delegate->double_tap()); |
1390 EXPECT_FALSE(delegate->scroll_begin()); | 1390 EXPECT_FALSE(delegate->scroll_begin()); |
1391 EXPECT_FALSE(delegate->scroll_update()); | 1391 EXPECT_FALSE(delegate->scroll_update()); |
1392 EXPECT_FALSE(delegate->scroll_end()); | 1392 EXPECT_FALSE(delegate->scroll_end()); |
1393 EXPECT_FALSE(queued_delegate->tap()); | 1393 EXPECT_FALSE(queued_delegate->tap()); |
1394 EXPECT_FALSE(queued_delegate->tap_down()); | 1394 EXPECT_FALSE(queued_delegate->tap_down()); |
1395 EXPECT_FALSE(queued_delegate->begin()); | 1395 EXPECT_FALSE(queued_delegate->begin()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 const int kTouchId2 = 3; | 1448 const int kTouchId2 = 3; |
1449 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); | 1449 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); |
1450 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1450 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1451 delegate.get(), -1234, bounds, NULL)); | 1451 delegate.get(), -1234, bounds, NULL)); |
1452 | 1452 |
1453 aura::RootWindow* root = root_window(); | 1453 aura::RootWindow* root = root_window(); |
1454 | 1454 |
1455 delegate->Reset(); | 1455 delegate->Reset(); |
1456 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1456 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1457 kTouchId1, GetTime()); | 1457 kTouchId1, GetTime()); |
1458 root->DispatchTouchEvent(&press); | 1458 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1459 EXPECT_FALSE(delegate->tap()); | 1459 EXPECT_FALSE(delegate->tap()); |
1460 EXPECT_TRUE(delegate->tap_down()); | 1460 EXPECT_TRUE(delegate->tap_down()); |
1461 EXPECT_FALSE(delegate->double_tap()); | 1461 EXPECT_FALSE(delegate->double_tap()); |
1462 EXPECT_FALSE(delegate->scroll_begin()); | 1462 EXPECT_FALSE(delegate->scroll_begin()); |
1463 EXPECT_FALSE(delegate->scroll_update()); | 1463 EXPECT_FALSE(delegate->scroll_update()); |
1464 EXPECT_FALSE(delegate->scroll_end()); | 1464 EXPECT_FALSE(delegate->scroll_end()); |
1465 | 1465 |
1466 // Move the touch-point enough so that it is considered as a scroll. This | 1466 // Move the touch-point enough so that it is considered as a scroll. This |
1467 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. | 1467 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. |
1468 delegate->Reset(); | 1468 delegate->Reset(); |
1469 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301), | 1469 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301), |
1470 kTouchId1, GetTime()); | 1470 kTouchId1, GetTime()); |
1471 root->DispatchTouchEvent(&move); | 1471 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
1472 EXPECT_FALSE(delegate->tap()); | 1472 EXPECT_FALSE(delegate->tap()); |
1473 EXPECT_FALSE(delegate->tap_down()); | 1473 EXPECT_FALSE(delegate->tap_down()); |
1474 EXPECT_FALSE(delegate->double_tap()); | 1474 EXPECT_FALSE(delegate->double_tap()); |
1475 EXPECT_TRUE(delegate->scroll_begin()); | 1475 EXPECT_TRUE(delegate->scroll_begin()); |
1476 EXPECT_TRUE(delegate->scroll_update()); | 1476 EXPECT_TRUE(delegate->scroll_update()); |
1477 EXPECT_FALSE(delegate->scroll_end()); | 1477 EXPECT_FALSE(delegate->scroll_end()); |
1478 | 1478 |
1479 // Press the second finger. It should cause pinch-begin. Note that we will not | 1479 // Press the second finger. It should cause pinch-begin. Note that we will not |
1480 // transition to two finger tap here because the touch points are far enough. | 1480 // transition to two finger tap here because the touch points are far enough. |
1481 delegate->Reset(); | 1481 delegate->Reset(); |
1482 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), | 1482 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), |
1483 kTouchId2, GetTime()); | 1483 kTouchId2, GetTime()); |
1484 root->DispatchTouchEvent(&press2); | 1484 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1485 EXPECT_FALSE(delegate->tap()); | 1485 EXPECT_FALSE(delegate->tap()); |
1486 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. | 1486 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. |
1487 EXPECT_FALSE(delegate->double_tap()); | 1487 EXPECT_FALSE(delegate->double_tap()); |
1488 EXPECT_FALSE(delegate->scroll_begin()); | 1488 EXPECT_FALSE(delegate->scroll_begin()); |
1489 EXPECT_FALSE(delegate->scroll_update()); | 1489 EXPECT_FALSE(delegate->scroll_update()); |
1490 EXPECT_FALSE(delegate->scroll_end()); | 1490 EXPECT_FALSE(delegate->scroll_end()); |
1491 EXPECT_TRUE(delegate->pinch_begin()); | 1491 EXPECT_TRUE(delegate->pinch_begin()); |
1492 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(), | 1492 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(), |
1493 delegate->bounding_box().ToString()); | 1493 delegate->bounding_box().ToString()); |
1494 | 1494 |
1495 // Move the first finger. | 1495 // Move the first finger. |
1496 delegate->Reset(); | 1496 delegate->Reset(); |
1497 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), | 1497 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), |
1498 kTouchId1, GetTime()); | 1498 kTouchId1, GetTime()); |
1499 root->DispatchTouchEvent(&move3); | 1499 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); |
1500 EXPECT_FALSE(delegate->tap()); | 1500 EXPECT_FALSE(delegate->tap()); |
1501 EXPECT_FALSE(delegate->tap_down()); | 1501 EXPECT_FALSE(delegate->tap_down()); |
1502 EXPECT_FALSE(delegate->double_tap()); | 1502 EXPECT_FALSE(delegate->double_tap()); |
1503 EXPECT_FALSE(delegate->scroll_begin()); | 1503 EXPECT_FALSE(delegate->scroll_begin()); |
1504 EXPECT_FALSE(delegate->scroll_update()); | 1504 EXPECT_FALSE(delegate->scroll_update()); |
1505 EXPECT_FALSE(delegate->scroll_end()); | 1505 EXPECT_FALSE(delegate->scroll_end()); |
1506 EXPECT_FALSE(delegate->pinch_begin()); | 1506 EXPECT_FALSE(delegate->pinch_begin()); |
1507 EXPECT_TRUE(delegate->pinch_update()); | 1507 EXPECT_TRUE(delegate->pinch_update()); |
1508 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(), | 1508 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(), |
1509 delegate->bounding_box().ToString()); | 1509 delegate->bounding_box().ToString()); |
1510 | 1510 |
1511 // Now move the second finger. | 1511 // Now move the second finger. |
1512 delegate->Reset(); | 1512 delegate->Reset(); |
1513 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), | 1513 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), |
1514 kTouchId2, GetTime()); | 1514 kTouchId2, GetTime()); |
1515 root->DispatchTouchEvent(&move4); | 1515 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); |
1516 EXPECT_FALSE(delegate->tap()); | 1516 EXPECT_FALSE(delegate->tap()); |
1517 EXPECT_FALSE(delegate->tap_down()); | 1517 EXPECT_FALSE(delegate->tap_down()); |
1518 EXPECT_FALSE(delegate->double_tap()); | 1518 EXPECT_FALSE(delegate->double_tap()); |
1519 EXPECT_FALSE(delegate->scroll_begin()); | 1519 EXPECT_FALSE(delegate->scroll_begin()); |
1520 EXPECT_FALSE(delegate->scroll_update()); | 1520 EXPECT_FALSE(delegate->scroll_update()); |
1521 EXPECT_FALSE(delegate->scroll_end()); | 1521 EXPECT_FALSE(delegate->scroll_end()); |
1522 EXPECT_FALSE(delegate->pinch_begin()); | 1522 EXPECT_FALSE(delegate->pinch_begin()); |
1523 EXPECT_TRUE(delegate->pinch_update()); | 1523 EXPECT_TRUE(delegate->pinch_update()); |
1524 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(), | 1524 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(), |
1525 delegate->bounding_box().ToString()); | 1525 delegate->bounding_box().ToString()); |
1526 | 1526 |
1527 // Release the first finger. This should end pinch. | 1527 // Release the first finger. This should end pinch. |
1528 delegate->Reset(); | 1528 delegate->Reset(); |
1529 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1529 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1530 kTouchId1, press.time_stamp() + | 1530 kTouchId1, press.time_stamp() + |
1531 base::TimeDelta::FromMilliseconds(50)); | 1531 base::TimeDelta::FromMilliseconds(50)); |
1532 root->DispatchTouchEvent(&release); | 1532 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
1533 EXPECT_FALSE(delegate->tap()); | 1533 EXPECT_FALSE(delegate->tap()); |
1534 EXPECT_FALSE(delegate->tap_down()); | 1534 EXPECT_FALSE(delegate->tap_down()); |
1535 EXPECT_FALSE(delegate->double_tap()); | 1535 EXPECT_FALSE(delegate->double_tap()); |
1536 EXPECT_FALSE(delegate->scroll_begin()); | 1536 EXPECT_FALSE(delegate->scroll_begin()); |
1537 EXPECT_FALSE(delegate->scroll_update()); | 1537 EXPECT_FALSE(delegate->scroll_update()); |
1538 EXPECT_FALSE(delegate->scroll_end()); | 1538 EXPECT_FALSE(delegate->scroll_end()); |
1539 EXPECT_TRUE(delegate->pinch_end()); | 1539 EXPECT_TRUE(delegate->pinch_end()); |
1540 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), | 1540 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), |
1541 delegate->bounding_box().ToString()); | 1541 delegate->bounding_box().ToString()); |
1542 | 1542 |
1543 // Move the second finger. This should still generate a scroll. | 1543 // Move the second finger. This should still generate a scroll. |
1544 delegate->Reset(); | 1544 delegate->Reset(); |
1545 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), | 1545 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), |
1546 kTouchId2, GetTime()); | 1546 kTouchId2, GetTime()); |
1547 root->DispatchTouchEvent(&move5); | 1547 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); |
1548 EXPECT_FALSE(delegate->tap()); | 1548 EXPECT_FALSE(delegate->tap()); |
1549 EXPECT_FALSE(delegate->tap_down()); | 1549 EXPECT_FALSE(delegate->tap_down()); |
1550 EXPECT_FALSE(delegate->double_tap()); | 1550 EXPECT_FALSE(delegate->double_tap()); |
1551 EXPECT_FALSE(delegate->scroll_begin()); | 1551 EXPECT_FALSE(delegate->scroll_begin()); |
1552 EXPECT_TRUE(delegate->scroll_update()); | 1552 EXPECT_TRUE(delegate->scroll_update()); |
1553 EXPECT_FALSE(delegate->scroll_end()); | 1553 EXPECT_FALSE(delegate->scroll_end()); |
1554 EXPECT_FALSE(delegate->pinch_begin()); | 1554 EXPECT_FALSE(delegate->pinch_begin()); |
1555 EXPECT_FALSE(delegate->pinch_update()); | 1555 EXPECT_FALSE(delegate->pinch_update()); |
1556 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 1556 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
1557 } | 1557 } |
1558 | 1558 |
1559 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { | 1559 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { |
1560 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1560 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1561 new GestureEventConsumeDelegate()); | 1561 new GestureEventConsumeDelegate()); |
1562 const int kWindowWidth = 300; | 1562 const int kWindowWidth = 300; |
1563 const int kWindowHeight = 400; | 1563 const int kWindowHeight = 400; |
1564 const int kTouchId1 = 5; | 1564 const int kTouchId1 = 5; |
1565 const int kTouchId2 = 3; | 1565 const int kTouchId2 = 3; |
1566 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); | 1566 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); |
1567 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1567 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1568 delegate.get(), -1234, bounds, NULL)); | 1568 delegate.get(), -1234, bounds, NULL)); |
1569 | 1569 |
1570 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), | 1570 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), |
1571 kTouchId1, GetTime()); | 1571 kTouchId1, GetTime()); |
1572 root_window()->DispatchTouchEvent(&press); | 1572 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1573 delegate->Reset(); | 1573 delegate->Reset(); |
1574 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), | 1574 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), |
1575 kTouchId2, GetTime()); | 1575 kTouchId2, GetTime()); |
1576 root_window()->DispatchTouchEvent(&press2); | 1576 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1577 // Since the touch points are far enough we will go to pinch rather than two | 1577 // Since the touch points are far enough we will go to pinch rather than two |
1578 // finger tap. | 1578 // finger tap. |
1579 EXPECT_TRUE(delegate->pinch_begin()); | 1579 EXPECT_TRUE(delegate->pinch_begin()); |
1580 | 1580 |
1581 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); | 1581 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); |
1582 EXPECT_TRUE(delegate->pinch_update()); | 1582 EXPECT_TRUE(delegate->pinch_update()); |
1583 | 1583 |
1584 // Pinch has started, now release the second finger | 1584 // Pinch has started, now release the second finger |
1585 delegate->Reset(); | 1585 delegate->Reset(); |
1586 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1586 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1587 kTouchId1, GetTime()); | 1587 kTouchId1, GetTime()); |
1588 root_window()->DispatchTouchEvent(&release); | 1588 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
1589 EXPECT_TRUE(delegate->pinch_end()); | 1589 EXPECT_TRUE(delegate->pinch_end()); |
1590 | 1590 |
1591 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get()); | 1591 SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get()); |
1592 EXPECT_TRUE(delegate->scroll_update()); | 1592 EXPECT_TRUE(delegate->scroll_update()); |
1593 | 1593 |
1594 // Pinch again | 1594 // Pinch again |
1595 delegate->Reset(); | 1595 delegate->Reset(); |
1596 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), | 1596 TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), |
1597 kTouchId1, GetTime()); | 1597 kTouchId1, GetTime()); |
1598 root_window()->DispatchTouchEvent(&press3); | 1598 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); |
1599 // Now the touch points are close. So we will go into two finger tap. | 1599 // Now the touch points are close. So we will go into two finger tap. |
1600 // Move the touch-point enough to break two-finger-tap and enter pinch. | 1600 // Move the touch-point enough to break two-finger-tap and enter pinch. |
1601 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202), | 1601 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202), |
1602 kTouchId1, GetTime()); | 1602 kTouchId1, GetTime()); |
1603 root_window()->DispatchTouchEvent(&move2); | 1603 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
1604 EXPECT_TRUE(delegate->pinch_begin()); | 1604 EXPECT_TRUE(delegate->pinch_begin()); |
1605 | 1605 |
1606 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); | 1606 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); |
1607 EXPECT_TRUE(delegate->pinch_update()); | 1607 EXPECT_TRUE(delegate->pinch_update()); |
1608 } | 1608 } |
1609 | 1609 |
1610 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { | 1610 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { |
1611 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1611 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1612 new GestureEventConsumeDelegate()); | 1612 new GestureEventConsumeDelegate()); |
1613 const int kWindowWidth = 300; | 1613 const int kWindowWidth = 300; |
1614 const int kWindowHeight = 400; | 1614 const int kWindowHeight = 400; |
1615 const int kTouchId1 = 3; | 1615 const int kTouchId1 = 3; |
1616 const int kTouchId2 = 5; | 1616 const int kTouchId2 = 5; |
1617 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); | 1617 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); |
1618 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1618 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1619 delegate.get(), -1234, bounds, NULL)); | 1619 delegate.get(), -1234, bounds, NULL)); |
1620 | 1620 |
1621 aura::RootWindow* root = root_window(); | 1621 aura::RootWindow* root = root_window(); |
1622 | 1622 |
1623 delegate->Reset(); | 1623 delegate->Reset(); |
1624 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), | 1624 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), |
1625 kTouchId1, GetTime()); | 1625 kTouchId1, GetTime()); |
1626 root->DispatchTouchEvent(&press); | 1626 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1627 EXPECT_FALSE(delegate->tap()); | 1627 EXPECT_FALSE(delegate->tap()); |
1628 EXPECT_TRUE(delegate->tap_down()); | 1628 EXPECT_TRUE(delegate->tap_down()); |
1629 EXPECT_FALSE(delegate->double_tap()); | 1629 EXPECT_FALSE(delegate->double_tap()); |
1630 EXPECT_FALSE(delegate->scroll_begin()); | 1630 EXPECT_FALSE(delegate->scroll_begin()); |
1631 EXPECT_FALSE(delegate->scroll_update()); | 1631 EXPECT_FALSE(delegate->scroll_update()); |
1632 EXPECT_FALSE(delegate->scroll_end()); | 1632 EXPECT_FALSE(delegate->scroll_end()); |
1633 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 1633 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
1634 | 1634 |
1635 // Press the second finger far enough to break two finger tap. It should | 1635 // Press the second finger far enough to break two finger tap. It should |
1636 // instead cause a scroll-begin and pinch-begin. | 1636 // instead cause a scroll-begin and pinch-begin. |
1637 delegate->Reset(); | 1637 delegate->Reset(); |
1638 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), | 1638 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), |
1639 kTouchId2, GetTime()); | 1639 kTouchId2, GetTime()); |
1640 root->DispatchTouchEvent(&press2); | 1640 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1641 EXPECT_FALSE(delegate->tap()); | 1641 EXPECT_FALSE(delegate->tap()); |
1642 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. | 1642 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. |
1643 EXPECT_FALSE(delegate->double_tap()); | 1643 EXPECT_FALSE(delegate->double_tap()); |
1644 EXPECT_TRUE(delegate->scroll_begin()); | 1644 EXPECT_TRUE(delegate->scroll_begin()); |
1645 EXPECT_FALSE(delegate->scroll_update()); | 1645 EXPECT_FALSE(delegate->scroll_update()); |
1646 EXPECT_FALSE(delegate->scroll_end()); | 1646 EXPECT_FALSE(delegate->scroll_end()); |
1647 EXPECT_TRUE(delegate->pinch_begin()); | 1647 EXPECT_TRUE(delegate->pinch_begin()); |
1648 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(), | 1648 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(), |
1649 delegate->bounding_box().ToString()); | 1649 delegate->bounding_box().ToString()); |
1650 | 1650 |
1651 // Move the first finger. | 1651 // Move the first finger. |
1652 delegate->Reset(); | 1652 delegate->Reset(); |
1653 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), | 1653 TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), |
1654 kTouchId1, GetTime()); | 1654 kTouchId1, GetTime()); |
1655 root->DispatchTouchEvent(&move3); | 1655 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); |
1656 EXPECT_FALSE(delegate->tap()); | 1656 EXPECT_FALSE(delegate->tap()); |
1657 EXPECT_FALSE(delegate->tap_down()); | 1657 EXPECT_FALSE(delegate->tap_down()); |
1658 EXPECT_FALSE(delegate->double_tap()); | 1658 EXPECT_FALSE(delegate->double_tap()); |
1659 EXPECT_FALSE(delegate->scroll_begin()); | 1659 EXPECT_FALSE(delegate->scroll_begin()); |
1660 EXPECT_FALSE(delegate->scroll_update()); | 1660 EXPECT_FALSE(delegate->scroll_update()); |
1661 EXPECT_FALSE(delegate->scroll_end()); | 1661 EXPECT_FALSE(delegate->scroll_end()); |
1662 EXPECT_FALSE(delegate->pinch_begin()); | 1662 EXPECT_FALSE(delegate->pinch_begin()); |
1663 EXPECT_TRUE(delegate->pinch_update()); | 1663 EXPECT_TRUE(delegate->pinch_update()); |
1664 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(), | 1664 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(), |
1665 delegate->bounding_box().ToString()); | 1665 delegate->bounding_box().ToString()); |
1666 | 1666 |
1667 // Now move the second finger. | 1667 // Now move the second finger. |
1668 delegate->Reset(); | 1668 delegate->Reset(); |
1669 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), | 1669 TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), |
1670 kTouchId2, GetTime()); | 1670 kTouchId2, GetTime()); |
1671 root->DispatchTouchEvent(&move4); | 1671 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); |
1672 EXPECT_FALSE(delegate->tap()); | 1672 EXPECT_FALSE(delegate->tap()); |
1673 EXPECT_FALSE(delegate->tap_down()); | 1673 EXPECT_FALSE(delegate->tap_down()); |
1674 EXPECT_FALSE(delegate->double_tap()); | 1674 EXPECT_FALSE(delegate->double_tap()); |
1675 EXPECT_FALSE(delegate->scroll_begin()); | 1675 EXPECT_FALSE(delegate->scroll_begin()); |
1676 EXPECT_FALSE(delegate->scroll_update()); | 1676 EXPECT_FALSE(delegate->scroll_update()); |
1677 EXPECT_FALSE(delegate->scroll_end()); | 1677 EXPECT_FALSE(delegate->scroll_end()); |
1678 EXPECT_FALSE(delegate->pinch_begin()); | 1678 EXPECT_FALSE(delegate->pinch_begin()); |
1679 EXPECT_TRUE(delegate->pinch_update()); | 1679 EXPECT_TRUE(delegate->pinch_update()); |
1680 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(), | 1680 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(), |
1681 delegate->bounding_box().ToString()); | 1681 delegate->bounding_box().ToString()); |
1682 | 1682 |
1683 // Release the first finger. This should end pinch. | 1683 // Release the first finger. This should end pinch. |
1684 delegate->Reset(); | 1684 delegate->Reset(); |
1685 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1685 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1686 kTouchId1, press.time_stamp() + | 1686 kTouchId1, press.time_stamp() + |
1687 base::TimeDelta::FromMilliseconds(50)); | 1687 base::TimeDelta::FromMilliseconds(50)); |
1688 root->DispatchTouchEvent(&release); | 1688 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
1689 EXPECT_FALSE(delegate->tap()); | 1689 EXPECT_FALSE(delegate->tap()); |
1690 EXPECT_FALSE(delegate->tap_down()); | 1690 EXPECT_FALSE(delegate->tap_down()); |
1691 EXPECT_FALSE(delegate->double_tap()); | 1691 EXPECT_FALSE(delegate->double_tap()); |
1692 EXPECT_FALSE(delegate->scroll_begin()); | 1692 EXPECT_FALSE(delegate->scroll_begin()); |
1693 EXPECT_FALSE(delegate->scroll_update()); | 1693 EXPECT_FALSE(delegate->scroll_update()); |
1694 EXPECT_FALSE(delegate->scroll_end()); | 1694 EXPECT_FALSE(delegate->scroll_end()); |
1695 EXPECT_TRUE(delegate->pinch_end()); | 1695 EXPECT_TRUE(delegate->pinch_end()); |
1696 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), | 1696 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), |
1697 delegate->bounding_box().ToString()); | 1697 delegate->bounding_box().ToString()); |
1698 | 1698 |
1699 // Move the second finger. This should still generate a scroll. | 1699 // Move the second finger. This should still generate a scroll. |
1700 delegate->Reset(); | 1700 delegate->Reset(); |
1701 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), | 1701 TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), |
1702 kTouchId2, GetTime()); | 1702 kTouchId2, GetTime()); |
1703 root->DispatchTouchEvent(&move5); | 1703 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); |
1704 EXPECT_FALSE(delegate->tap()); | 1704 EXPECT_FALSE(delegate->tap()); |
1705 EXPECT_FALSE(delegate->tap_down()); | 1705 EXPECT_FALSE(delegate->tap_down()); |
1706 EXPECT_FALSE(delegate->double_tap()); | 1706 EXPECT_FALSE(delegate->double_tap()); |
1707 EXPECT_FALSE(delegate->scroll_begin()); | 1707 EXPECT_FALSE(delegate->scroll_begin()); |
1708 EXPECT_TRUE(delegate->scroll_update()); | 1708 EXPECT_TRUE(delegate->scroll_update()); |
1709 EXPECT_FALSE(delegate->scroll_end()); | 1709 EXPECT_FALSE(delegate->scroll_end()); |
1710 EXPECT_FALSE(delegate->pinch_begin()); | 1710 EXPECT_FALSE(delegate->pinch_begin()); |
1711 EXPECT_FALSE(delegate->pinch_update()); | 1711 EXPECT_FALSE(delegate->pinch_update()); |
1712 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); | 1712 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); |
1713 } | 1713 } |
1714 | 1714 |
1715 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { | 1715 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { |
1716 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1716 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1717 new GestureEventConsumeDelegate()); | 1717 new GestureEventConsumeDelegate()); |
1718 | 1718 |
1719 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1719 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1720 6, GetTime()); | 1720 6, GetTime()); |
1721 root_window()->DispatchTouchEvent(&release1); | 1721 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
1722 EXPECT_FALSE(delegate->tap()); | 1722 EXPECT_FALSE(delegate->tap()); |
1723 EXPECT_FALSE(delegate->tap_down()); | 1723 EXPECT_FALSE(delegate->tap_down()); |
1724 } | 1724 } |
1725 | 1725 |
1726 // Check that a touch is locked to the window of the closest current touch | 1726 // Check that a touch is locked to the window of the closest current touch |
1727 // within max_separation_for_gesture_touches_in_pixels | 1727 // within max_separation_for_gesture_touches_in_pixels |
1728 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { | 1728 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { |
1729 ui::GestureRecognizer* gesture_recognizer = | 1729 ui::GestureRecognizer* gesture_recognizer = |
1730 new ui::GestureRecognizerImpl(root_window()); | 1730 new ui::GestureRecognizerImpl(root_window()); |
1731 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); | 1731 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); |
(...skipping 17 matching lines...) Expand all Loading... |
1749 | 1749 |
1750 // Instantiate windows with |window_bounds| and touch each window at | 1750 // Instantiate windows with |window_bounds| and touch each window at |
1751 // its origin. | 1751 // its origin. |
1752 for (int i = 0; i < kNumWindows; ++i) { | 1752 for (int i = 0; i < kNumWindows; ++i) { |
1753 delegates[i] = new GestureEventConsumeDelegate(); | 1753 delegates[i] = new GestureEventConsumeDelegate(); |
1754 windows[i] = CreateTestWindowWithDelegate( | 1754 windows[i] = CreateTestWindowWithDelegate( |
1755 delegates[i], i, *window_bounds[i], NULL); | 1755 delegates[i], i, *window_bounds[i], NULL); |
1756 windows[i]->set_id(i); | 1756 windows[i]->set_id(i); |
1757 TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i]->origin(), | 1757 TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i]->origin(), |
1758 i, GetTime()); | 1758 i, GetTime()); |
1759 root_window()->DispatchTouchEvent(&press); | 1759 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1760 } | 1760 } |
1761 | 1761 |
1762 // Touches should now be associated with the closest touch within | 1762 // Touches should now be associated with the closest touch within |
1763 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels | 1763 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels |
1764 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); | 1764 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); |
1765 EXPECT_EQ("0", WindowIDAsString(target)); | 1765 EXPECT_EQ("0", WindowIDAsString(target)); |
1766 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); | 1766 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); |
1767 EXPECT_EQ("1", WindowIDAsString(target)); | 1767 EXPECT_EQ("1", WindowIDAsString(target)); |
1768 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); | 1768 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); |
1769 EXPECT_EQ("2", WindowIDAsString(target)); | 1769 EXPECT_EQ("2", WindowIDAsString(target)); |
1770 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); | 1770 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); |
1771 EXPECT_EQ("3", WindowIDAsString(target)); | 1771 EXPECT_EQ("3", WindowIDAsString(target)); |
1772 | 1772 |
1773 // Add a touch in the middle associated with windows[2] | 1773 // Add a touch in the middle associated with windows[2] |
1774 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), | 1774 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), |
1775 kNumWindows, GetTime()); | 1775 kNumWindows, GetTime()); |
1776 root_window()->DispatchTouchEvent(&press); | 1776 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1777 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), | 1777 TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), |
1778 kNumWindows, GetTime()); | 1778 kNumWindows, GetTime()); |
1779 root_window()->DispatchTouchEvent(&move); | 1779 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); |
1780 | 1780 |
1781 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); | 1781 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); |
1782 EXPECT_EQ("2", WindowIDAsString(target)); | 1782 EXPECT_EQ("2", WindowIDAsString(target)); |
1783 | 1783 |
1784 // Make sure that ties are broken by distance to a current touch | 1784 // Make sure that ties are broken by distance to a current touch |
1785 // Closer to the point in the bottom right. | 1785 // Closer to the point in the bottom right. |
1786 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); | 1786 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); |
1787 EXPECT_EQ("3", WindowIDAsString(target)); | 1787 EXPECT_EQ("3", WindowIDAsString(target)); |
1788 | 1788 |
1789 // This touch is closer to the point in the middle | 1789 // This touch is closer to the point in the middle |
1790 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); | 1790 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); |
1791 EXPECT_EQ("2", WindowIDAsString(target)); | 1791 EXPECT_EQ("2", WindowIDAsString(target)); |
1792 | 1792 |
1793 // A touch too far from other touches won't be locked to anything | 1793 // A touch too far from other touches won't be locked to anything |
1794 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); | 1794 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); |
1795 EXPECT_TRUE(target == NULL); | 1795 EXPECT_TRUE(target == NULL); |
1796 | 1796 |
1797 // Move a touch associated with windows[2] to 1000, 1000 | 1797 // Move a touch associated with windows[2] to 1000, 1000 |
1798 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), | 1798 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), |
1799 kNumWindows, GetTime()); | 1799 kNumWindows, GetTime()); |
1800 root_window()->DispatchTouchEvent(&move2); | 1800 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
1801 | 1801 |
1802 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); | 1802 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); |
1803 EXPECT_EQ("2", WindowIDAsString(target)); | 1803 EXPECT_EQ("2", WindowIDAsString(target)); |
1804 } | 1804 } |
1805 | 1805 |
1806 // Check that touch events outside the root window are still handled | 1806 // Check that touch events outside the root window are still handled |
1807 // by the root window's gesture sequence. | 1807 // by the root window's gesture sequence. |
1808 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { | 1808 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { |
1809 TestGestureRecognizer* gesture_recognizer = | 1809 TestGestureRecognizer* gesture_recognizer = |
1810 new TestGestureRecognizer(root_window()); | 1810 new TestGestureRecognizer(root_window()); |
1811 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); | 1811 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); |
1812 | 1812 |
1813 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( | 1813 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( |
1814 gfx::Rect(-100, -100, 2000, 2000), NULL)); | 1814 gfx::Rect(-100, -100, 2000, 2000), NULL)); |
1815 | 1815 |
1816 ui::GestureSequence* window_gesture_sequence = | 1816 ui::GestureSequence* window_gesture_sequence = |
1817 gesture_recognizer->GetGestureSequenceForTesting(window.get()); | 1817 gesture_recognizer->GetGestureSequenceForTesting(window.get()); |
1818 | 1818 |
1819 ui::GestureSequence* root_window_gesture_sequence = | 1819 ui::GestureSequence* root_window_gesture_sequence = |
1820 gesture_recognizer->GetGestureSequenceForTesting(root_window()); | 1820 gesture_recognizer->GetGestureSequenceForTesting(root_window()); |
1821 | 1821 |
1822 gfx::Point pos1(-10, -10); | 1822 gfx::Point pos1(-10, -10); |
1823 TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, GetTime()); | 1823 TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, GetTime()); |
1824 root_window()->DispatchTouchEvent(&press1); | 1824 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
1825 | 1825 |
1826 gfx::Point pos2(1000, 1000); | 1826 gfx::Point pos2(1000, 1000); |
1827 TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, GetTime()); | 1827 TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, GetTime()); |
1828 root_window()->DispatchTouchEvent(&press2); | 1828 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1829 | 1829 |
1830 // As these presses were outside the root window, they should be | 1830 // As these presses were outside the root window, they should be |
1831 // associated with the root window. | 1831 // associated with the root window. |
1832 EXPECT_EQ(0, window_gesture_sequence->point_count()); | 1832 EXPECT_EQ(0, window_gesture_sequence->point_count()); |
1833 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); | 1833 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); |
1834 } | 1834 } |
1835 | 1835 |
1836 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { | 1836 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { |
1837 scoped_ptr<QueueTouchEventDelegate> delegate( | 1837 scoped_ptr<QueueTouchEventDelegate> delegate( |
1838 new QueueTouchEventDelegate(root_window())); | 1838 new QueueTouchEventDelegate(root_window())); |
1839 const int kTouchId = 2; | 1839 const int kTouchId = 2; |
1840 gfx::Rect bounds(100, 200, 100, 100); | 1840 gfx::Rect bounds(100, 200, 100, 100); |
1841 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1841 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1842 delegate.get(), -1234, bounds, NULL)); | 1842 delegate.get(), -1234, bounds, NULL)); |
1843 delegate->set_window(window.get()); | 1843 delegate->set_window(window.get()); |
1844 | 1844 |
1845 delegate->Reset(); | 1845 delegate->Reset(); |
1846 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1846 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1847 kTouchId, GetTime()); | 1847 kTouchId, GetTime()); |
1848 root_window()->DispatchTouchEvent(&press); | 1848 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1849 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1849 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1850 kTouchId, press.time_stamp() + | 1850 kTouchId, press.time_stamp() + |
1851 base::TimeDelta::FromMilliseconds(50)); | 1851 base::TimeDelta::FromMilliseconds(50)); |
1852 root_window()->DispatchTouchEvent(&release); | 1852 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
1853 | 1853 |
1854 delegate->Reset(); | 1854 delegate->Reset(); |
1855 delegate->ReceivedAck(); | 1855 delegate->ReceivedAck(); |
1856 EXPECT_TRUE(delegate->tap_down()); | 1856 EXPECT_TRUE(delegate->tap_down()); |
1857 delegate->Reset(); | 1857 delegate->Reset(); |
1858 delegate->ReceivedAckPreventDefaulted(); | 1858 delegate->ReceivedAckPreventDefaulted(); |
1859 EXPECT_FALSE(delegate->tap()); | 1859 EXPECT_FALSE(delegate->tap()); |
1860 } | 1860 } |
1861 | 1861 |
1862 TEST_F(GestureRecognizerTest, CaptureSendsTapUp) { | 1862 TEST_F(GestureRecognizerTest, CaptureSendsTapUp) { |
(...skipping 28 matching lines...) Expand all Loading... |
1891 const int kWindowHeight = 45; | 1891 const int kWindowHeight = 45; |
1892 const int kTouchId1 = 2; | 1892 const int kTouchId1 = 2; |
1893 const int kTouchId2 = 3; | 1893 const int kTouchId2 = 3; |
1894 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1894 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1895 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1895 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1896 delegate.get(), -1234, bounds, NULL)); | 1896 delegate.get(), -1234, bounds, NULL)); |
1897 | 1897 |
1898 delegate->Reset(); | 1898 delegate->Reset(); |
1899 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1899 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1900 kTouchId1, GetTime()); | 1900 kTouchId1, GetTime()); |
1901 root_window()->DispatchTouchEvent(&press1); | 1901 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
1902 EXPECT_FALSE(delegate->tap()); | 1902 EXPECT_FALSE(delegate->tap()); |
1903 EXPECT_TRUE(delegate->tap_down()); | 1903 EXPECT_TRUE(delegate->tap_down()); |
1904 EXPECT_FALSE(delegate->double_tap()); | 1904 EXPECT_FALSE(delegate->double_tap()); |
1905 EXPECT_FALSE(delegate->scroll_begin()); | 1905 EXPECT_FALSE(delegate->scroll_begin()); |
1906 EXPECT_FALSE(delegate->scroll_update()); | 1906 EXPECT_FALSE(delegate->scroll_update()); |
1907 EXPECT_FALSE(delegate->scroll_end()); | 1907 EXPECT_FALSE(delegate->scroll_end()); |
1908 EXPECT_FALSE(delegate->long_press()); | 1908 EXPECT_FALSE(delegate->long_press()); |
1909 EXPECT_FALSE(delegate->two_finger_tap()); | 1909 EXPECT_FALSE(delegate->two_finger_tap()); |
1910 | 1910 |
1911 delegate->Reset(); | 1911 delegate->Reset(); |
1912 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), | 1912 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), |
1913 kTouchId2, GetTime()); | 1913 kTouchId2, GetTime()); |
1914 root_window()->DispatchTouchEvent(&press2); | 1914 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1915 EXPECT_FALSE(delegate->tap()); | 1915 EXPECT_FALSE(delegate->tap()); |
1916 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. | 1916 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. |
1917 EXPECT_FALSE(delegate->double_tap()); | 1917 EXPECT_FALSE(delegate->double_tap()); |
1918 EXPECT_FALSE(delegate->scroll_begin()); | 1918 EXPECT_FALSE(delegate->scroll_begin()); |
1919 EXPECT_FALSE(delegate->scroll_update()); | 1919 EXPECT_FALSE(delegate->scroll_update()); |
1920 EXPECT_FALSE(delegate->scroll_end()); | 1920 EXPECT_FALSE(delegate->scroll_end()); |
1921 EXPECT_FALSE(delegate->long_press()); | 1921 EXPECT_FALSE(delegate->long_press()); |
1922 EXPECT_FALSE(delegate->two_finger_tap()); | 1922 EXPECT_FALSE(delegate->two_finger_tap()); |
1923 | 1923 |
1924 // Little bit of touch move should not affect our state. | 1924 // Little bit of touch move should not affect our state. |
1925 delegate->Reset(); | 1925 delegate->Reset(); |
1926 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202), | 1926 TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202), |
1927 kTouchId1, GetTime()); | 1927 kTouchId1, GetTime()); |
1928 root_window()->DispatchTouchEvent(&move1); | 1928 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); |
1929 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202), | 1929 TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202), |
1930 kTouchId2, GetTime()); | 1930 kTouchId2, GetTime()); |
1931 root_window()->DispatchTouchEvent(&move2); | 1931 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); |
1932 EXPECT_FALSE(delegate->tap()); | 1932 EXPECT_FALSE(delegate->tap()); |
1933 EXPECT_FALSE(delegate->tap_down()); | 1933 EXPECT_FALSE(delegate->tap_down()); |
1934 EXPECT_FALSE(delegate->double_tap()); | 1934 EXPECT_FALSE(delegate->double_tap()); |
1935 EXPECT_FALSE(delegate->scroll_begin()); | 1935 EXPECT_FALSE(delegate->scroll_begin()); |
1936 EXPECT_FALSE(delegate->scroll_update()); | 1936 EXPECT_FALSE(delegate->scroll_update()); |
1937 EXPECT_FALSE(delegate->scroll_end()); | 1937 EXPECT_FALSE(delegate->scroll_end()); |
1938 EXPECT_FALSE(delegate->long_press()); | 1938 EXPECT_FALSE(delegate->long_press()); |
1939 EXPECT_FALSE(delegate->two_finger_tap()); | 1939 EXPECT_FALSE(delegate->two_finger_tap()); |
1940 | 1940 |
1941 // Make sure there is enough delay before the touch is released so that it is | 1941 // Make sure there is enough delay before the touch is released so that it is |
1942 // recognized as a tap. | 1942 // recognized as a tap. |
1943 delegate->Reset(); | 1943 delegate->Reset(); |
1944 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1944 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1945 kTouchId1, press1.time_stamp() + | 1945 kTouchId1, press1.time_stamp() + |
1946 base::TimeDelta::FromMilliseconds(50)); | 1946 base::TimeDelta::FromMilliseconds(50)); |
1947 | 1947 |
1948 root_window()->DispatchTouchEvent(&release1); | 1948 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
1949 EXPECT_FALSE(delegate->tap()); | 1949 EXPECT_FALSE(delegate->tap()); |
1950 EXPECT_FALSE(delegate->tap_down()); | 1950 EXPECT_FALSE(delegate->tap_down()); |
1951 EXPECT_FALSE(delegate->double_tap()); | 1951 EXPECT_FALSE(delegate->double_tap()); |
1952 EXPECT_FALSE(delegate->scroll_begin()); | 1952 EXPECT_FALSE(delegate->scroll_begin()); |
1953 EXPECT_FALSE(delegate->scroll_update()); | 1953 EXPECT_FALSE(delegate->scroll_update()); |
1954 EXPECT_FALSE(delegate->scroll_end()); | 1954 EXPECT_FALSE(delegate->scroll_end()); |
1955 EXPECT_TRUE(delegate->two_finger_tap()); | 1955 EXPECT_TRUE(delegate->two_finger_tap()); |
1956 | 1956 |
1957 // Lift second finger. | 1957 // Lift second finger. |
1958 // Make sure there is enough delay before the touch is released so that it is | 1958 // Make sure there is enough delay before the touch is released so that it is |
1959 // recognized as a tap. | 1959 // recognized as a tap. |
1960 delegate->Reset(); | 1960 delegate->Reset(); |
1961 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), | 1961 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), |
1962 kTouchId2, press2.time_stamp() + | 1962 kTouchId2, press2.time_stamp() + |
1963 base::TimeDelta::FromMilliseconds(50)); | 1963 base::TimeDelta::FromMilliseconds(50)); |
1964 | 1964 |
1965 root_window()->DispatchTouchEvent(&release2); | 1965 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); |
1966 EXPECT_FALSE(delegate->tap()); | 1966 EXPECT_FALSE(delegate->tap()); |
1967 EXPECT_FALSE(delegate->tap_down()); | 1967 EXPECT_FALSE(delegate->tap_down()); |
1968 EXPECT_FALSE(delegate->double_tap()); | 1968 EXPECT_FALSE(delegate->double_tap()); |
1969 EXPECT_FALSE(delegate->scroll_begin()); | 1969 EXPECT_FALSE(delegate->scroll_begin()); |
1970 EXPECT_FALSE(delegate->scroll_update()); | 1970 EXPECT_FALSE(delegate->scroll_update()); |
1971 EXPECT_TRUE(delegate->scroll_end()); | 1971 EXPECT_TRUE(delegate->scroll_end()); |
1972 EXPECT_FALSE(delegate->two_finger_tap()); | 1972 EXPECT_FALSE(delegate->two_finger_tap()); |
1973 } | 1973 } |
1974 | 1974 |
1975 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { | 1975 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { |
1976 scoped_ptr<GestureEventConsumeDelegate> delegate( | 1976 scoped_ptr<GestureEventConsumeDelegate> delegate( |
1977 new GestureEventConsumeDelegate()); | 1977 new GestureEventConsumeDelegate()); |
1978 const int kWindowWidth = 123; | 1978 const int kWindowWidth = 123; |
1979 const int kWindowHeight = 45; | 1979 const int kWindowHeight = 45; |
1980 const int kTouchId1 = 2; | 1980 const int kTouchId1 = 2; |
1981 const int kTouchId2 = 3; | 1981 const int kTouchId2 = 3; |
1982 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 1982 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
1983 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 1983 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
1984 delegate.get(), -1234, bounds, NULL)); | 1984 delegate.get(), -1234, bounds, NULL)); |
1985 | 1985 |
1986 delegate->Reset(); | 1986 delegate->Reset(); |
1987 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 1987 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
1988 kTouchId1, GetTime()); | 1988 kTouchId1, GetTime()); |
1989 root_window()->DispatchTouchEvent(&press1); | 1989 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
1990 | 1990 |
1991 delegate->Reset(); | 1991 delegate->Reset(); |
1992 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), | 1992 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), |
1993 kTouchId2, GetTime()); | 1993 kTouchId2, GetTime()); |
1994 root_window()->DispatchTouchEvent(&press2); | 1994 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
1995 | 1995 |
1996 // Send release event after sufficient delay so that two finger time expires. | 1996 // Send release event after sufficient delay so that two finger time expires. |
1997 delegate->Reset(); | 1997 delegate->Reset(); |
1998 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 1998 TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
1999 kTouchId1, press1.time_stamp() + | 1999 kTouchId1, press1.time_stamp() + |
2000 base::TimeDelta::FromMilliseconds(1000)); | 2000 base::TimeDelta::FromMilliseconds(1000)); |
2001 | 2001 |
2002 root_window()->DispatchTouchEvent(&release1); | 2002 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); |
2003 EXPECT_FALSE(delegate->two_finger_tap()); | 2003 EXPECT_FALSE(delegate->two_finger_tap()); |
2004 | 2004 |
2005 // Lift second finger. | 2005 // Lift second finger. |
2006 // Make sure there is enough delay before the touch is released so that it is | 2006 // Make sure there is enough delay before the touch is released so that it is |
2007 // recognized as a tap. | 2007 // recognized as a tap. |
2008 delegate->Reset(); | 2008 delegate->Reset(); |
2009 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), | 2009 TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), |
2010 kTouchId2, press2.time_stamp() + | 2010 kTouchId2, press2.time_stamp() + |
2011 base::TimeDelta::FromMilliseconds(50)); | 2011 base::TimeDelta::FromMilliseconds(50)); |
2012 | 2012 |
2013 root_window()->DispatchTouchEvent(&release2); | 2013 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); |
2014 EXPECT_FALSE(delegate->two_finger_tap()); | 2014 EXPECT_FALSE(delegate->two_finger_tap()); |
2015 } | 2015 } |
2016 | 2016 |
2017 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { | 2017 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { |
2018 scoped_ptr<GestureEventConsumeDelegate> delegate( | 2018 scoped_ptr<GestureEventConsumeDelegate> delegate( |
2019 new GestureEventConsumeDelegate()); | 2019 new GestureEventConsumeDelegate()); |
2020 const int kWindowWidth = 123; | 2020 const int kWindowWidth = 123; |
2021 const int kWindowHeight = 45; | 2021 const int kWindowHeight = 45; |
2022 const int kTouchId1 = 2; | 2022 const int kTouchId1 = 2; |
2023 const int kTouchId2 = 3; | 2023 const int kTouchId2 = 3; |
2024 | 2024 |
2025 // Test moving first finger | 2025 // Test moving first finger |
2026 { | 2026 { |
2027 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2027 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2028 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2028 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2029 delegate.get(), -1234, bounds, NULL)); | 2029 delegate.get(), -1234, bounds, NULL)); |
2030 | 2030 |
2031 delegate->Reset(); | 2031 delegate->Reset(); |
2032 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2032 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2033 kTouchId1, GetTime()); | 2033 kTouchId1, GetTime()); |
2034 root_window()->DispatchTouchEvent(&press1); | 2034 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
2035 | 2035 |
2036 delegate->Reset(); | 2036 delegate->Reset(); |
2037 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), | 2037 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), |
2038 kTouchId2, GetTime()); | 2038 kTouchId2, GetTime()); |
2039 root_window()->DispatchTouchEvent(&press2); | 2039 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2040 | 2040 |
2041 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); | 2041 SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); |
2042 EXPECT_FALSE(delegate->two_finger_tap()); | 2042 EXPECT_FALSE(delegate->two_finger_tap()); |
2043 EXPECT_TRUE(delegate->pinch_begin()); | 2043 EXPECT_TRUE(delegate->pinch_begin()); |
2044 | 2044 |
2045 // Make sure there is enough delay before the touch is released so that it | 2045 // Make sure there is enough delay before the touch is released so that it |
2046 // is recognized as a tap. | 2046 // is recognized as a tap. |
2047 delegate->Reset(); | 2047 delegate->Reset(); |
2048 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 2048 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
2049 kTouchId2, press1.time_stamp() + | 2049 kTouchId2, press1.time_stamp() + |
2050 base::TimeDelta::FromMilliseconds(50)); | 2050 base::TimeDelta::FromMilliseconds(50)); |
2051 | 2051 |
2052 root_window()->DispatchTouchEvent(&release); | 2052 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
2053 EXPECT_FALSE(delegate->two_finger_tap()); | 2053 EXPECT_FALSE(delegate->two_finger_tap()); |
2054 EXPECT_TRUE(delegate->pinch_end()); | 2054 EXPECT_TRUE(delegate->pinch_end()); |
2055 } | 2055 } |
2056 | 2056 |
2057 // Test moving second finger | 2057 // Test moving second finger |
2058 { | 2058 { |
2059 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2059 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2060 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2060 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2061 delegate.get(), -1234, bounds, NULL)); | 2061 delegate.get(), -1234, bounds, NULL)); |
2062 | 2062 |
2063 delegate->Reset(); | 2063 delegate->Reset(); |
2064 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2064 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2065 kTouchId1, GetTime()); | 2065 kTouchId1, GetTime()); |
2066 root_window()->DispatchTouchEvent(&press1); | 2066 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
2067 | 2067 |
2068 delegate->Reset(); | 2068 delegate->Reset(); |
2069 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), | 2069 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), |
2070 kTouchId2, GetTime()); | 2070 kTouchId2, GetTime()); |
2071 root_window()->DispatchTouchEvent(&press2); | 2071 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2072 | 2072 |
2073 SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get()); | 2073 SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get()); |
2074 EXPECT_FALSE(delegate->two_finger_tap()); | 2074 EXPECT_FALSE(delegate->two_finger_tap()); |
2075 EXPECT_TRUE(delegate->pinch_begin()); | 2075 EXPECT_TRUE(delegate->pinch_begin()); |
2076 | 2076 |
2077 // Make sure there is enough delay before the touch is released so that it | 2077 // Make sure there is enough delay before the touch is released so that it |
2078 // is recognized as a tap. | 2078 // is recognized as a tap. |
2079 delegate->Reset(); | 2079 delegate->Reset(); |
2080 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 2080 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
2081 kTouchId1, press1.time_stamp() + | 2081 kTouchId1, press1.time_stamp() + |
2082 base::TimeDelta::FromMilliseconds(50)); | 2082 base::TimeDelta::FromMilliseconds(50)); |
2083 | 2083 |
2084 root_window()->DispatchTouchEvent(&release); | 2084 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
2085 EXPECT_FALSE(delegate->two_finger_tap()); | 2085 EXPECT_FALSE(delegate->two_finger_tap()); |
2086 EXPECT_TRUE(delegate->pinch_end()); | 2086 EXPECT_TRUE(delegate->pinch_end()); |
2087 } | 2087 } |
2088 } | 2088 } |
2089 | 2089 |
2090 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { | 2090 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { |
2091 scoped_ptr<GestureEventConsumeDelegate> delegate( | 2091 scoped_ptr<GestureEventConsumeDelegate> delegate( |
2092 new GestureEventConsumeDelegate()); | 2092 new GestureEventConsumeDelegate()); |
2093 const int kWindowWidth = 123; | 2093 const int kWindowWidth = 123; |
2094 const int kWindowHeight = 45; | 2094 const int kWindowHeight = 45; |
2095 const int kTouchId1 = 2; | 2095 const int kTouchId1 = 2; |
2096 const int kTouchId2 = 3; | 2096 const int kTouchId2 = 3; |
2097 | 2097 |
2098 // Test canceling first finger. | 2098 // Test canceling first finger. |
2099 { | 2099 { |
2100 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2100 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2101 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2101 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2102 delegate.get(), -1234, bounds, NULL)); | 2102 delegate.get(), -1234, bounds, NULL)); |
2103 | 2103 |
2104 delegate->Reset(); | 2104 delegate->Reset(); |
2105 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2105 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2106 kTouchId1, GetTime()); | 2106 kTouchId1, GetTime()); |
2107 root_window()->DispatchTouchEvent(&press1); | 2107 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
2108 | 2108 |
2109 delegate->Reset(); | 2109 delegate->Reset(); |
2110 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), | 2110 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), |
2111 kTouchId2, GetTime()); | 2111 kTouchId2, GetTime()); |
2112 root_window()->DispatchTouchEvent(&press2); | 2112 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2113 | 2113 |
2114 delegate->Reset(); | 2114 delegate->Reset(); |
2115 TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), | 2115 TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), |
2116 kTouchId1, GetTime()); | 2116 kTouchId1, GetTime()); |
2117 root_window()->DispatchTouchEvent(&cancel); | 2117 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); |
2118 EXPECT_FALSE(delegate->two_finger_tap()); | 2118 EXPECT_FALSE(delegate->two_finger_tap()); |
2119 | 2119 |
2120 // Make sure there is enough delay before the touch is released so that it | 2120 // Make sure there is enough delay before the touch is released so that it |
2121 // is recognized as a tap. | 2121 // is recognized as a tap. |
2122 delegate->Reset(); | 2122 delegate->Reset(); |
2123 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 2123 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
2124 kTouchId2, press1.time_stamp() + | 2124 kTouchId2, press1.time_stamp() + |
2125 base::TimeDelta::FromMilliseconds(50)); | 2125 base::TimeDelta::FromMilliseconds(50)); |
2126 | 2126 |
2127 root_window()->DispatchTouchEvent(&release); | 2127 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
2128 EXPECT_FALSE(delegate->two_finger_tap()); | 2128 EXPECT_FALSE(delegate->two_finger_tap()); |
2129 } | 2129 } |
2130 | 2130 |
2131 // Test canceling second finger | 2131 // Test canceling second finger |
2132 { | 2132 { |
2133 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2133 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2134 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2134 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2135 delegate.get(), -1234, bounds, NULL)); | 2135 delegate.get(), -1234, bounds, NULL)); |
2136 | 2136 |
2137 delegate->Reset(); | 2137 delegate->Reset(); |
2138 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2138 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2139 kTouchId1, GetTime()); | 2139 kTouchId1, GetTime()); |
2140 root_window()->DispatchTouchEvent(&press1); | 2140 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
2141 | 2141 |
2142 delegate->Reset(); | 2142 delegate->Reset(); |
2143 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), | 2143 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), |
2144 kTouchId2, GetTime()); | 2144 kTouchId2, GetTime()); |
2145 root_window()->DispatchTouchEvent(&press2); | 2145 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2146 | 2146 |
2147 delegate->Reset(); | 2147 delegate->Reset(); |
2148 TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), | 2148 TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), |
2149 kTouchId2, GetTime()); | 2149 kTouchId2, GetTime()); |
2150 root_window()->DispatchTouchEvent(&cancel); | 2150 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); |
2151 EXPECT_FALSE(delegate->two_finger_tap()); | 2151 EXPECT_FALSE(delegate->two_finger_tap()); |
2152 | 2152 |
2153 // Make sure there is enough delay before the touch is released so that it | 2153 // Make sure there is enough delay before the touch is released so that it |
2154 // is recognized as a tap. | 2154 // is recognized as a tap. |
2155 delegate->Reset(); | 2155 delegate->Reset(); |
2156 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 2156 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
2157 kTouchId1, press1.time_stamp() + | 2157 kTouchId1, press1.time_stamp() + |
2158 base::TimeDelta::FromMilliseconds(50)); | 2158 base::TimeDelta::FromMilliseconds(50)); |
2159 | 2159 |
2160 root_window()->DispatchTouchEvent(&release); | 2160 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
2161 EXPECT_FALSE(delegate->two_finger_tap()); | 2161 EXPECT_FALSE(delegate->two_finger_tap()); |
2162 } | 2162 } |
2163 } | 2163 } |
2164 | 2164 |
2165 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { | 2165 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { |
2166 scoped_ptr<GestureEventConsumeDelegate> delegate( | 2166 scoped_ptr<GestureEventConsumeDelegate> delegate( |
2167 new GestureEventConsumeDelegate()); | 2167 new GestureEventConsumeDelegate()); |
2168 const int kWindowWidth = 523; | 2168 const int kWindowWidth = 523; |
2169 const int kWindowHeight = 45; | 2169 const int kWindowHeight = 45; |
2170 const int kTouchId1 = 2; | 2170 const int kTouchId1 = 2; |
2171 const int kTouchId2 = 3; | 2171 const int kTouchId2 = 3; |
2172 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2172 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2173 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2173 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2174 delegate.get(), -1234, bounds, NULL)); | 2174 delegate.get(), -1234, bounds, NULL)); |
2175 | 2175 |
2176 delegate->Reset(); | 2176 delegate->Reset(); |
2177 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2177 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2178 kTouchId1, GetTime()); | 2178 kTouchId1, GetTime()); |
2179 root_window()->DispatchTouchEvent(&press1); | 2179 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
2180 EXPECT_FALSE(delegate->tap()); | 2180 EXPECT_FALSE(delegate->tap()); |
2181 EXPECT_TRUE(delegate->tap_down()); | 2181 EXPECT_TRUE(delegate->tap_down()); |
2182 EXPECT_FALSE(delegate->double_tap()); | 2182 EXPECT_FALSE(delegate->double_tap()); |
2183 EXPECT_FALSE(delegate->scroll_begin()); | 2183 EXPECT_FALSE(delegate->scroll_begin()); |
2184 EXPECT_FALSE(delegate->scroll_update()); | 2184 EXPECT_FALSE(delegate->scroll_update()); |
2185 EXPECT_FALSE(delegate->scroll_end()); | 2185 EXPECT_FALSE(delegate->scroll_end()); |
2186 EXPECT_FALSE(delegate->long_press()); | 2186 EXPECT_FALSE(delegate->long_press()); |
2187 EXPECT_FALSE(delegate->two_finger_tap()); | 2187 EXPECT_FALSE(delegate->two_finger_tap()); |
2188 | 2188 |
2189 delegate->Reset(); | 2189 delegate->Reset(); |
2190 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201), | 2190 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201), |
2191 kTouchId2, GetTime()); | 2191 kTouchId2, GetTime()); |
2192 root_window()->DispatchTouchEvent(&press2); | 2192 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2193 EXPECT_FALSE(delegate->tap()); | 2193 EXPECT_FALSE(delegate->tap()); |
2194 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. | 2194 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. |
2195 EXPECT_FALSE(delegate->double_tap()); | 2195 EXPECT_FALSE(delegate->double_tap()); |
2196 EXPECT_TRUE(delegate->scroll_begin()); | 2196 EXPECT_TRUE(delegate->scroll_begin()); |
2197 EXPECT_FALSE(delegate->scroll_update()); | 2197 EXPECT_FALSE(delegate->scroll_update()); |
2198 EXPECT_FALSE(delegate->scroll_end()); | 2198 EXPECT_FALSE(delegate->scroll_end()); |
2199 EXPECT_FALSE(delegate->long_press()); | 2199 EXPECT_FALSE(delegate->long_press()); |
2200 EXPECT_FALSE(delegate->two_finger_tap()); | 2200 EXPECT_FALSE(delegate->two_finger_tap()); |
2201 EXPECT_TRUE(delegate->pinch_begin()); | 2201 EXPECT_TRUE(delegate->pinch_begin()); |
2202 } | 2202 } |
2203 | 2203 |
2204 // Verifies if a window is the target of multiple touch-ids and we hide the | 2204 // Verifies if a window is the target of multiple touch-ids and we hide the |
2205 // window everything is cleaned up correctly. | 2205 // window everything is cleaned up correctly. |
2206 TEST_F(GestureRecognizerTest, FlushAllOnHide) { | 2206 TEST_F(GestureRecognizerTest, FlushAllOnHide) { |
2207 scoped_ptr<GestureEventConsumeDelegate> delegate( | 2207 scoped_ptr<GestureEventConsumeDelegate> delegate( |
2208 new GestureEventConsumeDelegate()); | 2208 new GestureEventConsumeDelegate()); |
2209 gfx::Rect bounds(0, 0, 200, 200); | 2209 gfx::Rect bounds(0, 0, 200, 200); |
2210 scoped_ptr<aura::Window> window( | 2210 scoped_ptr<aura::Window> window( |
2211 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL)); | 2211 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, NULL)); |
2212 const int kTouchId1 = 8; | 2212 const int kTouchId1 = 8; |
2213 const int kTouchId2 = 2; | 2213 const int kTouchId2 = 2; |
2214 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), | 2214 TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), |
2215 kTouchId1, GetTime()); | 2215 kTouchId1, GetTime()); |
2216 root_window()->DispatchTouchEvent(&press1); | 2216 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); |
2217 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), | 2217 TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), |
2218 kTouchId2, GetTime()); | 2218 kTouchId2, GetTime()); |
2219 root_window()->DispatchTouchEvent(&press2); | 2219 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); |
2220 window->Hide(); | 2220 window->Hide(); |
2221 EXPECT_EQ(NULL, | 2221 EXPECT_EQ(NULL, |
2222 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1)); | 2222 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1)); |
2223 EXPECT_EQ(NULL, | 2223 EXPECT_EQ(NULL, |
2224 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2)); | 2224 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2)); |
2225 } | 2225 } |
2226 | 2226 |
2227 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { | 2227 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { |
2228 scoped_ptr<QueueTouchEventDelegate> delegate( | 2228 scoped_ptr<QueueTouchEventDelegate> delegate( |
2229 new QueueTouchEventDelegate(root_window())); | 2229 new QueueTouchEventDelegate(root_window())); |
2230 const int kTouchId = 2; | 2230 const int kTouchId = 2; |
2231 gfx::Rect bounds(100, 200, 100, 100); | 2231 gfx::Rect bounds(100, 200, 100, 100); |
2232 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2232 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2233 delegate.get(), -1234, bounds, NULL)); | 2233 delegate.get(), -1234, bounds, NULL)); |
2234 delegate->set_window(window.get()); | 2234 delegate->set_window(window.get()); |
2235 | 2235 |
2236 TimerTestGestureRecognizer* gesture_recognizer = | 2236 TimerTestGestureRecognizer* gesture_recognizer = |
2237 new TimerTestGestureRecognizer(root_window()); | 2237 new TimerTestGestureRecognizer(root_window()); |
2238 TimerTestGestureSequence* gesture_sequence = | 2238 TimerTestGestureSequence* gesture_sequence = |
2239 static_cast<TimerTestGestureSequence*>( | 2239 static_cast<TimerTestGestureSequence*>( |
2240 gesture_recognizer->GetGestureSequenceForTesting(window.get())); | 2240 gesture_recognizer->GetGestureSequenceForTesting(window.get())); |
2241 | 2241 |
2242 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); | 2242 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); |
2243 | 2243 |
2244 delegate->Reset(); | 2244 delegate->Reset(); |
2245 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2245 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2246 kTouchId, GetTime()); | 2246 kTouchId, GetTime()); |
2247 root_window()->DispatchTouchEvent(&press); | 2247 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
2248 // Scroll around, to cancel the long press | 2248 // Scroll around, to cancel the long press |
2249 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); | 2249 SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); |
2250 | 2250 |
2251 delegate->Reset(); | 2251 delegate->Reset(); |
2252 delegate->ReceivedAck(); | 2252 delegate->ReceivedAck(); |
2253 EXPECT_TRUE(delegate->tap_down()); | 2253 EXPECT_TRUE(delegate->tap_down()); |
2254 EXPECT_TRUE(gesture_sequence->IsTimerRunning()); | 2254 EXPECT_TRUE(gesture_sequence->IsTimerRunning()); |
2255 | 2255 |
2256 delegate->Reset(); | 2256 delegate->Reset(); |
2257 delegate->ReceivedAckPreventDefaulted(); | 2257 delegate->ReceivedAckPreventDefaulted(); |
(...skipping 30 matching lines...) Expand all Loading... |
2288 const int kWindowWidth = 123; | 2288 const int kWindowWidth = 123; |
2289 const int kWindowHeight = 45; | 2289 const int kWindowHeight = 45; |
2290 const int kTouchId = 5; | 2290 const int kTouchId = 5; |
2291 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); | 2291 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); |
2292 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 2292 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
2293 delegate.get(), -1234, bounds, NULL)); | 2293 delegate.get(), -1234, bounds, NULL)); |
2294 | 2294 |
2295 delegate->Reset(); | 2295 delegate->Reset(); |
2296 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 2296 TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), |
2297 kTouchId, GetTime()); | 2297 kTouchId, GetTime()); |
2298 root_window()->DispatchTouchEvent(&press); | 2298 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
2299 EXPECT_FALSE(delegate->tap()); | 2299 EXPECT_FALSE(delegate->tap()); |
2300 EXPECT_TRUE(delegate->tap_down()); | 2300 EXPECT_TRUE(delegate->tap_down()); |
2301 EXPECT_TRUE(delegate->begin()); | 2301 EXPECT_TRUE(delegate->begin()); |
2302 EXPECT_FALSE(delegate->double_tap()); | 2302 EXPECT_FALSE(delegate->double_tap()); |
2303 EXPECT_FALSE(delegate->scroll_begin()); | 2303 EXPECT_FALSE(delegate->scroll_begin()); |
2304 EXPECT_FALSE(delegate->scroll_update()); | 2304 EXPECT_FALSE(delegate->scroll_update()); |
2305 EXPECT_FALSE(delegate->scroll_end()); | 2305 EXPECT_FALSE(delegate->scroll_end()); |
2306 | 2306 |
2307 // Move the touch-point enough so that it would normally be considered a | 2307 // Move the touch-point enough so that it would normally be considered a |
2308 // scroll. But since the touch-moves will be consumed, the scroll should not | 2308 // scroll. But since the touch-moves will be consumed, the scroll should not |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2357 EXPECT_TRUE(delegate->scroll_update()); | 2357 EXPECT_TRUE(delegate->scroll_update()); |
2358 EXPECT_FALSE(delegate->scroll_end()); | 2358 EXPECT_FALSE(delegate->scroll_end()); |
2359 EXPECT_EQ(30, delegate->scroll_x()); | 2359 EXPECT_EQ(30, delegate->scroll_x()); |
2360 EXPECT_EQ(4, delegate->scroll_y()); | 2360 EXPECT_EQ(4, delegate->scroll_y()); |
2361 | 2361 |
2362 // Release the touch. This should end the scroll. | 2362 // Release the touch. This should end the scroll. |
2363 delegate->Reset(); | 2363 delegate->Reset(); |
2364 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), | 2364 TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), |
2365 kTouchId, press.time_stamp() + | 2365 kTouchId, press.time_stamp() + |
2366 base::TimeDelta::FromMilliseconds(50)); | 2366 base::TimeDelta::FromMilliseconds(50)); |
2367 root_window()->DispatchTouchEvent(&release); | 2367 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); |
2368 EXPECT_FALSE(delegate->tap()); | 2368 EXPECT_FALSE(delegate->tap()); |
2369 EXPECT_FALSE(delegate->tap_down()); | 2369 EXPECT_FALSE(delegate->tap_down()); |
2370 EXPECT_FALSE(delegate->begin()); | 2370 EXPECT_FALSE(delegate->begin()); |
2371 EXPECT_TRUE(delegate->end()); | 2371 EXPECT_TRUE(delegate->end()); |
2372 EXPECT_FALSE(delegate->double_tap()); | 2372 EXPECT_FALSE(delegate->double_tap()); |
2373 EXPECT_FALSE(delegate->scroll_begin()); | 2373 EXPECT_FALSE(delegate->scroll_begin()); |
2374 EXPECT_FALSE(delegate->scroll_update()); | 2374 EXPECT_FALSE(delegate->scroll_update()); |
2375 EXPECT_TRUE(delegate->scroll_end()); | 2375 EXPECT_TRUE(delegate->scroll_end()); |
2376 } | 2376 } |
2377 | 2377 |
2378 } // namespace test | 2378 } // namespace test |
2379 } // namespace aura | 2379 } // namespace aura |
OLD | NEW |