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 3 // found in the LICENSE file. 4 5 #include "base/command_line.h" 6 #include "base/memory/scoped_vector.h" 7 #include "base/run_loop.h" 8 #include "base/strings/string_number_conversions.h" 9 #include "base/timer/timer.h" 10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "ui/aura/env.h" 12 #include "ui/aura/root_window.h" 13 #include "ui/aura/test/aura_test_base.h" 14 #include "ui/aura/test/event_generator.h" 15 #include "ui/aura/test/test_window_delegate.h" 16 #include "ui/aura/test/test_windows.h" 17 #include "ui/base/events/event.h" 18 #include "ui/base/events/event_utils.h" 19 #include "ui/base/gestures/gesture_configuration.h" 20 #include "ui/base/gestures/gesture_recognizer_impl.h" 21 #include "ui/base/gestures/gesture_sequence.h" 22 #include "ui/base/gestures/gesture_types.h" 23 #include "ui/base/hit_test.h" 24 #include "ui/base/ui_base_switches.h" 25 #include "ui/gfx/point.h" 26 #include "ui/gfx/rect.h" 27 28 #include <queue> 29 30 namespace aura { 31 namespace test { 32 33 namespace { 34 35 std::string WindowIDAsString(ui::GestureConsumer* consumer) { 36 return consumer && !consumer->ignores_events() ? 37 base::IntToString(static_cast<Window*>(consumer)->id()) : "?"; 38 } 39 40 #define EXPECT_0_EVENTS(events) \ 41 EXPECT_EQ(0u, events.size()) 42 43 #define EXPECT_1_EVENT(events, e0) \ 44 EXPECT_EQ(1u, events.size()); \ 45 EXPECT_EQ(e0, events[0]) 46 47 #define EXPECT_2_EVENTS(events, e0, e1) \ 48 EXPECT_EQ(2u, events.size()); \ 49 EXPECT_EQ(e0, events[0]); \ 50 EXPECT_EQ(e1, events[1]) 51 52 #define EXPECT_3_EVENTS(events, e0, e1, e2) \ 53 EXPECT_EQ(3u, events.size()); \ 54 EXPECT_EQ(e0, events[0]); \ 55 EXPECT_EQ(e1, events[1]); \ 56 EXPECT_EQ(e2, events[2]) 57 58 #define EXPECT_4_EVENTS(events, e0, e1, e2, e3) \ 59 EXPECT_EQ(4u, events.size()); \ 60 EXPECT_EQ(e0, events[0]); \ 61 EXPECT_EQ(e1, events[1]); \ 62 EXPECT_EQ(e2, events[2]); \ 63 EXPECT_EQ(e3, events[3]) 64 65 // A delegate that keeps track of gesture events. 66 class GestureEventConsumeDelegate : public TestWindowDelegate { 67 public: 68 GestureEventConsumeDelegate() 69 : tap_(false), 70 tap_down_(false), 71 tap_cancel_(false), 72 begin_(false), 73 end_(false), 74 scroll_begin_(false), 75 scroll_update_(false), 76 scroll_end_(false), 77 pinch_begin_(false), 78 pinch_update_(false), 79 pinch_end_(false), 80 long_press_(false), 81 fling_(false), 82 two_finger_tap_(false), 83 swipe_left_(false), 84 swipe_right_(false), 85 swipe_up_(false), 86 swipe_down_(false), 87 scroll_x_(0), 88 scroll_y_(0), 89 scroll_velocity_x_(0), 90 scroll_velocity_y_(0), 91 velocity_x_(0), 92 velocity_y_(0), 93 scroll_x_ordinal_(0), 94 scroll_y_ordinal_(0), 95 scroll_velocity_x_ordinal_(0), 96 scroll_velocity_y_ordinal_(0), 97 velocity_x_ordinal_(0), 98 velocity_y_ordinal_(0), 99 tap_count_(0), 100 wait_until_event_(ui::ET_UNKNOWN) { 101 } 102 103 virtual ~GestureEventConsumeDelegate() {} 104 105 void Reset() { 106 events_.clear(); 107 tap_ = false; 108 tap_down_ = false; 109 tap_cancel_ = false; 110 begin_ = false; 111 end_ = false; 112 scroll_begin_ = false; 113 scroll_update_ = false; 114 scroll_end_ = false; 115 pinch_begin_ = false; 116 pinch_update_ = false; 117 pinch_end_ = false; 118 long_press_ = false; 119 fling_ = false; 120 two_finger_tap_ = false; 121 swipe_left_ = false; 122 swipe_right_ = false; 123 swipe_up_ = false; 124 swipe_down_ = false; 125 126 scroll_begin_position_.SetPoint(0, 0); 127 tap_location_.SetPoint(0, 0); 128 129 scroll_x_ = 0; 130 scroll_y_ = 0; 131 scroll_velocity_x_ = 0; 132 scroll_velocity_y_ = 0; 133 velocity_x_ = 0; 134 velocity_y_ = 0; 135 scroll_x_ordinal_ = 0; 136 scroll_y_ordinal_ = 0; 137 scroll_velocity_x_ordinal_ = 0; 138 scroll_velocity_y_ordinal_ = 0; 139 velocity_x_ordinal_ = 0; 140 velocity_y_ordinal_ = 0; 141 tap_count_ = 0; 142 } 143 144 const std::vector<ui::EventType>& events() const { return events_; }; 145 146 bool tap() const { return tap_; } 147 bool tap_down() const { return tap_down_; } 148 bool tap_cancel() const { return tap_cancel_; } 149 bool begin() const { return begin_; } 150 bool end() const { return end_; } 151 bool scroll_begin() const { return scroll_begin_; } 152 bool scroll_update() const { return scroll_update_; } 153 bool scroll_end() const { return scroll_end_; } 154 bool pinch_begin() const { return pinch_begin_; } 155 bool pinch_update() const { return pinch_update_; } 156 bool pinch_end() const { return pinch_end_; } 157 bool long_press() const { return long_press_; } 158 bool long_tap() const { return long_tap_; } 159 bool fling() const { return fling_; } 160 bool two_finger_tap() const { return two_finger_tap_; } 161 bool swipe_left() const { return swipe_left_; } 162 bool swipe_right() const { return swipe_right_; } 163 bool swipe_up() const { return swipe_up_; } 164 bool swipe_down() const { return swipe_down_; } 165 166 const gfx::Point scroll_begin_position() const { 167 return scroll_begin_position_; 168 } 169 170 const gfx::Point tap_location() const { 171 return tap_location_; 172 } 173 174 float scroll_x() const { return scroll_x_; } 175 float scroll_y() const { return scroll_y_; } 176 float scroll_velocity_x() const { return scroll_velocity_x_; } 177 float scroll_velocity_y() const { return scroll_velocity_y_; } 178 float velocity_x() const { return velocity_x_; } 179 float velocity_y() const { return velocity_y_; } 180 float scroll_x_ordinal() const { return scroll_x_ordinal_; } 181 float scroll_y_ordinal() const { return scroll_y_ordinal_; } 182 float scroll_velocity_x_ordinal() const { return scroll_velocity_x_ordinal_; } 183 float scroll_velocity_y_ordinal() const { return scroll_velocity_y_ordinal_; } 184 float velocity_x_ordinal() const { return velocity_x_ordinal_; } 185 float velocity_y_ordinal() const { return velocity_y_ordinal_; } 186 int touch_id() const { return touch_id_; } 187 const gfx::Rect& bounding_box() const { return bounding_box_; } 188 int tap_count() const { return tap_count_; } 189 190 void WaitUntilReceivedGesture(ui::EventType type) { 191 wait_until_event_ = type; 192 run_loop_.reset(new base::RunLoop( 193 Env::GetInstance()->GetDispatcher())); 194 run_loop_->Run(); 195 } 196 197 virtual void OnGestureEvent(ui::GestureEvent* gesture) OVERRIDE { 198 events_.push_back(gesture->type()); 199 bounding_box_ = gesture->details().bounding_box(); 200 switch (gesture->type()) { 201 case ui::ET_GESTURE_TAP: 202 tap_location_ = gesture->location(); 203 tap_count_ = gesture->details().tap_count(); 204 tap_ = true; 205 break; 206 case ui::ET_GESTURE_TAP_DOWN: 207 tap_down_ = true; 208 break; 209 case ui::ET_GESTURE_TAP_CANCEL: 210 tap_cancel_ = true; 211 break; 212 case ui::ET_GESTURE_BEGIN: 213 begin_ = true; 214 break; 215 case ui::ET_GESTURE_END: 216 end_ = true; 217 break; 218 case ui::ET_GESTURE_SCROLL_BEGIN: 219 scroll_begin_ = true; 220 scroll_begin_position_ = gesture->location(); 221 break; 222 case ui::ET_GESTURE_SCROLL_UPDATE: 223 scroll_update_ = true; 224 scroll_x_ += gesture->details().scroll_x(); 225 scroll_y_ += gesture->details().scroll_y(); 226 scroll_velocity_x_ = gesture->details().velocity_x(); 227 scroll_velocity_y_ = gesture->details().velocity_y(); 228 scroll_x_ordinal_ += gesture->details().scroll_x_ordinal(); 229 scroll_y_ordinal_ += gesture->details().scroll_y_ordinal(); 230 scroll_velocity_x_ordinal_ = gesture->details().velocity_x_ordinal(); 231 scroll_velocity_y_ordinal_ = gesture->details().velocity_y_ordinal(); 232 break; 233 case ui::ET_GESTURE_SCROLL_END: 234 EXPECT_TRUE(velocity_x_ == 0 && velocity_y_ == 0); 235 scroll_end_ = true; 236 break; 237 case ui::ET_GESTURE_PINCH_BEGIN: 238 pinch_begin_ = true; 239 break; 240 case ui::ET_GESTURE_PINCH_UPDATE: 241 pinch_update_ = true; 242 break; 243 case ui::ET_GESTURE_PINCH_END: 244 pinch_end_ = true; 245 break; 246 case ui::ET_GESTURE_LONG_PRESS: 247 long_press_ = true; 248 touch_id_ = gesture->details().touch_id(); 249 break; 250 case ui::ET_GESTURE_LONG_TAP: 251 long_tap_ = true; 252 break; 253 case ui::ET_SCROLL_FLING_START: 254 EXPECT_TRUE(gesture->details().velocity_x() != 0 || 255 gesture->details().velocity_y() != 0); 256 EXPECT_FALSE(scroll_end_); 257 fling_ = true; 258 velocity_x_ = gesture->details().velocity_x(); 259 velocity_y_ = gesture->details().velocity_y(); 260 velocity_x_ordinal_ = gesture->details().velocity_x_ordinal(); 261 velocity_y_ordinal_ = gesture->details().velocity_y_ordinal(); 262 break; 263 case ui::ET_GESTURE_TWO_FINGER_TAP: 264 two_finger_tap_ = true; 265 break; 266 case ui::ET_GESTURE_MULTIFINGER_SWIPE: 267 swipe_left_ = gesture->details().swipe_left(); 268 swipe_right_ = gesture->details().swipe_right(); 269 swipe_up_ = gesture->details().swipe_up(); 270 swipe_down_ = gesture->details().swipe_down(); 271 break; 272 default: 273 NOTREACHED(); 274 } 275 if (wait_until_event_ == gesture->type() && run_loop_) { 276 run_loop_->Quit(); 277 wait_until_event_ = ui::ET_UNKNOWN; 278 } 279 gesture->StopPropagation(); 280 } 281 282 private: 283 scoped_ptr<base::RunLoop> run_loop_; 284 std::vector<ui::EventType> events_; 285 286 bool tap_; 287 bool tap_down_; 288 bool tap_cancel_; 289 bool begin_; 290 bool end_; 291 bool scroll_begin_; 292 bool scroll_update_; 293 bool scroll_end_; 294 bool pinch_begin_; 295 bool pinch_update_; 296 bool pinch_end_; 297 bool long_press_; 298 bool long_tap_; 299 bool fling_; 300 bool two_finger_tap_; 301 bool swipe_left_; 302 bool swipe_right_; 303 bool swipe_up_; 304 bool swipe_down_; 305 306 gfx::Point scroll_begin_position_; 307 gfx::Point tap_location_; 308 309 float scroll_x_; 310 float scroll_y_; 311 float scroll_velocity_x_; 312 float scroll_velocity_y_; 313 float velocity_x_; 314 float velocity_y_; 315 float scroll_x_ordinal_; 316 float scroll_y_ordinal_; 317 float scroll_velocity_x_ordinal_; 318 float scroll_velocity_y_ordinal_; 319 float velocity_x_ordinal_; 320 float velocity_y_ordinal_; 321 int touch_id_; 322 gfx::Rect bounding_box_; 323 int tap_count_; 324 325 ui::EventType wait_until_event_; 326 327 DISALLOW_COPY_AND_ASSIGN(GestureEventConsumeDelegate); 328 }; 329 330 class QueueTouchEventDelegate : public GestureEventConsumeDelegate { 331 public: 332 explicit QueueTouchEventDelegate(RootWindow* root_window) 333 : window_(NULL), 334 root_window_(root_window), 335 queue_events_(true) { 336 } 337 virtual ~QueueTouchEventDelegate() {} 338 339 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 340 if (queue_events_) { 341 queue_.push(new ui::TouchEvent(*event, window_, window_)); 342 event->StopPropagation(); 343 } 344 } 345 346 void ReceivedAck() { 347 ReceivedAckImpl(false); 348 } 349 350 void ReceivedAckPreventDefaulted() { 351 ReceivedAckImpl(true); 352 } 353 354 void set_window(Window* w) { window_ = w; } 355 void set_queue_events(bool queue) { queue_events_ = queue; } 356 357 private: 358 void ReceivedAckImpl(bool prevent_defaulted) { 359 scoped_ptr<ui::TouchEvent> event(queue_.front()); 360 root_window_->ProcessedTouchEvent(event.get(), window_, 361 prevent_defaulted ? ui::ER_HANDLED : ui::ER_UNHANDLED); 362 queue_.pop(); 363 } 364 365 std::queue<ui::TouchEvent*> queue_; 366 Window* window_; 367 RootWindow* root_window_; 368 bool queue_events_; 369 370 DISALLOW_COPY_AND_ASSIGN(QueueTouchEventDelegate); 371 }; 372 373 // A delegate that ignores gesture events but keeps track of [synthetic] mouse 374 // events. 375 class GestureEventSynthDelegate : public TestWindowDelegate { 376 public: 377 GestureEventSynthDelegate() 378 : mouse_enter_(false), 379 mouse_exit_(false), 380 mouse_press_(false), 381 mouse_release_(false), 382 mouse_move_(false), 383 double_click_(false) { 384 } 385 386 void Reset() { 387 mouse_enter_ = false; 388 mouse_exit_ = false; 389 mouse_press_ = false; 390 mouse_release_ = false; 391 mouse_move_ = false; 392 double_click_ = false; 393 } 394 395 bool mouse_enter() const { return mouse_enter_; } 396 bool mouse_exit() const { return mouse_exit_; } 397 bool mouse_press() const { return mouse_press_; } 398 bool mouse_move() const { return mouse_move_; } 399 bool mouse_release() const { return mouse_release_; } 400 bool double_click() const { return double_click_; } 401 402 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { 403 switch (event->type()) { 404 case ui::ET_MOUSE_PRESSED: 405 double_click_ = event->flags() & ui::EF_IS_DOUBLE_CLICK; 406 mouse_press_ = true; 407 break; 408 case ui::ET_MOUSE_RELEASED: 409 mouse_release_ = true; 410 break; 411 case ui::ET_MOUSE_MOVED: 412 mouse_move_ = true; 413 break; 414 case ui::ET_MOUSE_ENTERED: 415 mouse_enter_ = true; 416 break; 417 case ui::ET_MOUSE_EXITED: 418 mouse_exit_ = true; 419 break; 420 default: 421 NOTREACHED(); 422 } 423 event->SetHandled(); 424 } 425 426 private: 427 bool mouse_enter_; 428 bool mouse_exit_; 429 bool mouse_press_; 430 bool mouse_release_; 431 bool mouse_move_; 432 bool double_click_; 433 434 DISALLOW_COPY_AND_ASSIGN(GestureEventSynthDelegate); 435 }; 436 437 class TestOneShotGestureSequenceTimer 438 : public base::OneShotTimer<ui::GestureSequence> { 439 public: 440 TestOneShotGestureSequenceTimer() {} 441 442 void ForceTimeout() { 443 if (IsRunning()) { 444 user_task().Run(); 445 Stop(); 446 } 447 } 448 449 private: 450 DISALLOW_COPY_AND_ASSIGN(TestOneShotGestureSequenceTimer); 451 }; 452 453 class TimerTestGestureSequence : public ui::GestureSequence { 454 public: 455 explicit TimerTestGestureSequence(ui::GestureEventHelper* helper) 456 : ui::GestureSequence(helper) { 457 } 458 459 void ForceTimeout() { 460 static_cast<TestOneShotGestureSequenceTimer*>( 461 GetLongPressTimer())->ForceTimeout(); 462 } 463 464 bool IsTimerRunning() { 465 return GetLongPressTimer()->IsRunning(); 466 } 467 468 virtual base::OneShotTimer<ui::GestureSequence>* CreateTimer() OVERRIDE { 469 return new TestOneShotGestureSequenceTimer(); 470 } 471 472 private: 473 DISALLOW_COPY_AND_ASSIGN(TimerTestGestureSequence); 474 }; 475 476 class TestGestureRecognizer : public ui::GestureRecognizerImpl { 477 public: 478 explicit TestGestureRecognizer(RootWindow* root_window) 479 : GestureRecognizerImpl(root_window) { 480 } 481 482 ui::GestureSequence* GetGestureSequenceForTesting(Window* window) { 483 return GetGestureSequenceForConsumer(window); 484 } 485 486 private: 487 DISALLOW_COPY_AND_ASSIGN(TestGestureRecognizer); 488 }; 489 490 class TimerTestGestureRecognizer : public TestGestureRecognizer { 491 public: 492 explicit TimerTestGestureRecognizer(RootWindow* root_window) 493 : TestGestureRecognizer(root_window) { 494 } 495 496 virtual ui::GestureSequence* CreateSequence( 497 ui::GestureEventHelper* helper) OVERRIDE { 498 return new TimerTestGestureSequence(helper); 499 } 500 501 private: 502 DISALLOW_COPY_AND_ASSIGN(TimerTestGestureRecognizer); 503 }; 504 505 base::TimeDelta GetTime() { 506 return ui::EventTimeForNow(); 507 } 508 509 class TimedEvents { 510 private: 511 int simulated_now_; 512 513 public: 514 TimedEvents() : simulated_now_(0) { 515 } 516 517 base::TimeDelta Now() { 518 base::TimeDelta t = base::TimeDelta::FromMilliseconds(simulated_now_); 519 simulated_now_++; 520 return t; 521 } 522 523 base::TimeDelta LeapForward(int time_in_millis) { 524 simulated_now_ += time_in_millis; 525 return base::TimeDelta::FromMilliseconds(simulated_now_); 526 } 527 528 base::TimeDelta InFuture(int time_in_millis) { 529 return base::TimeDelta::FromMilliseconds(simulated_now_ + time_in_millis); 530 } 531 532 void SendScrollEvents(RootWindow* root_window, 533 int x_start, 534 int y_start, 535 int dx, 536 int dy, 537 int touch_id, 538 int time_step, 539 int num_steps, 540 GestureEventConsumeDelegate* delegate) { 541 int x = x_start; 542 int y = y_start; 543 544 for (int i = 0; i < num_steps; i++) { 545 x += dx; 546 y += dy; 547 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 548 touch_id, 549 base::TimeDelta::FromMilliseconds(simulated_now_)); 550 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 551 simulated_now_ += time_step; 552 } 553 } 554 555 void SendScrollEvent(RootWindow* root_window, 556 int x, 557 int y, 558 int touch_id, 559 GestureEventConsumeDelegate* delegate) { 560 delegate->Reset(); 561 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(x, y), 562 touch_id, 563 base::TimeDelta::FromMilliseconds(simulated_now_)); 564 root_window->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 565 simulated_now_++; 566 } 567 }; 568 569 // An event handler to keep track of events. 570 class TestEventHandler : public ui::EventHandler { 571 public: 572 TestEventHandler() : touch_released_count_(0), touch_pressed_count_(0), 573 touch_moved_count_(0), touch_stationary_count_(0), 574 touch_cancelled_count_(0) { 575 } 576 577 virtual ~TestEventHandler() {} 578 579 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 580 switch (event->type()) { 581 case ui::ET_TOUCH_RELEASED: 582 touch_released_count_++; 583 break; 584 case ui::ET_TOUCH_PRESSED: 585 touch_pressed_count_++; 586 break; 587 case ui::ET_TOUCH_MOVED: 588 touch_moved_count_++; 589 break; 590 case ui::ET_TOUCH_STATIONARY: 591 touch_stationary_count_++; 592 break; 593 case ui::ET_TOUCH_CANCELLED: 594 touch_cancelled_count_++; 595 break; 596 default: 597 break; 598 } 599 } 600 601 void Reset() { 602 touch_released_count_ = 0; 603 touch_pressed_count_ = 0; 604 touch_moved_count_ = 0; 605 touch_stationary_count_ = 0; 606 touch_cancelled_count_ = 0; 607 } 608 609 int touch_released_count() const { return touch_released_count_; } 610 int touch_pressed_count() const { return touch_pressed_count_; } 611 int touch_moved_count() const { return touch_moved_count_; } 612 int touch_stationary_count() const { return touch_stationary_count_; } 613 int touch_cancelled_count() const { return touch_cancelled_count_; } 614 615 private: 616 int touch_released_count_; 617 int touch_pressed_count_; 618 int touch_moved_count_; 619 int touch_stationary_count_; 620 int touch_cancelled_count_; 621 622 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 623 }; 624 625 } // namespace 626 627 class GestureRecognizerTest : public AuraTestBase { 628 public: 629 GestureRecognizerTest() {} 630 631 virtual void SetUp() OVERRIDE { 632 CommandLine::ForCurrentProcess()->AppendSwitch( 633 switches::kEnableScrollPrediction); 634 AuraTestBase::SetUp(); 635 } 636 637 DISALLOW_COPY_AND_ASSIGN(GestureRecognizerTest); 638 }; 639 640 // Check that appropriate touch events generate tap gesture events. 641 TEST_F(GestureRecognizerTest, GestureEventTap) { 642 scoped_ptr<GestureEventConsumeDelegate> delegate( 643 new GestureEventConsumeDelegate()); 644 TimedEvents tes; 645 const int kWindowWidth = 123; 646 const int kWindowHeight = 45; 647 const int kTouchId = 2; 648 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 649 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 650 delegate.get(), -1234, bounds, root_window())); 651 652 delegate->Reset(); 653 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 654 kTouchId, tes.Now()); 655 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 656 EXPECT_FALSE(delegate->tap()); 657 EXPECT_TRUE(delegate->tap_down()); 658 EXPECT_FALSE(delegate->tap_cancel()); 659 EXPECT_TRUE(delegate->begin()); 660 EXPECT_FALSE(delegate->scroll_begin()); 661 EXPECT_FALSE(delegate->scroll_update()); 662 EXPECT_FALSE(delegate->scroll_end()); 663 EXPECT_FALSE(delegate->long_press()); 664 665 // Make sure there is enough delay before the touch is released so that it is 666 // recognized as a tap. 667 delegate->Reset(); 668 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 669 kTouchId, tes.LeapForward(50)); 670 671 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 672 EXPECT_TRUE(delegate->tap()); 673 EXPECT_FALSE(delegate->tap_down()); 674 EXPECT_FALSE(delegate->tap_cancel()); 675 EXPECT_FALSE(delegate->begin()); 676 EXPECT_TRUE(delegate->end()); 677 EXPECT_FALSE(delegate->scroll_begin()); 678 EXPECT_FALSE(delegate->scroll_update()); 679 EXPECT_FALSE(delegate->scroll_end()); 680 681 EXPECT_EQ(1, delegate->tap_count()); 682 } 683 684 // Check that appropriate touch events generate tap gesture events 685 // when information about the touch radii are provided. 686 TEST_F(GestureRecognizerTest, GestureEventTapRegion) { 687 scoped_ptr<GestureEventConsumeDelegate> delegate( 688 new GestureEventConsumeDelegate()); 689 TimedEvents tes; 690 const int kWindowWidth = 800; 691 const int kWindowHeight = 600; 692 const int kTouchId = 2; 693 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 694 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 695 delegate.get(), -1234, bounds, root_window())); 696 697 // Test with no ET_TOUCH_MOVED events. 698 { 699 delegate->Reset(); 700 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 701 kTouchId, tes.Now()); 702 press.set_radius_x(5); 703 press.set_radius_y(12); 704 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 705 EXPECT_FALSE(delegate->tap()); 706 EXPECT_TRUE(delegate->tap_down()); 707 EXPECT_FALSE(delegate->tap_cancel()); 708 EXPECT_TRUE(delegate->begin()); 709 EXPECT_FALSE(delegate->scroll_begin()); 710 EXPECT_FALSE(delegate->scroll_update()); 711 EXPECT_FALSE(delegate->scroll_end()); 712 EXPECT_FALSE(delegate->long_press()); 713 714 // Make sure there is enough delay before the touch is released so that it 715 // is recognized as a tap. 716 delegate->Reset(); 717 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 718 kTouchId, tes.LeapForward(50)); 719 release.set_radius_x(5); 720 release.set_radius_y(12); 721 722 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 723 EXPECT_TRUE(delegate->tap()); 724 EXPECT_FALSE(delegate->tap_down()); 725 EXPECT_FALSE(delegate->tap_cancel()); 726 EXPECT_FALSE(delegate->begin()); 727 EXPECT_TRUE(delegate->end()); 728 EXPECT_FALSE(delegate->scroll_begin()); 729 EXPECT_FALSE(delegate->scroll_update()); 730 EXPECT_FALSE(delegate->scroll_end()); 731 732 EXPECT_EQ(1, delegate->tap_count()); 733 gfx::Point actual_point(delegate->tap_location()); 734 EXPECT_EQ(24, delegate->bounding_box().width()); 735 EXPECT_EQ(24, delegate->bounding_box().height()); 736 EXPECT_EQ(101, actual_point.x()); 737 EXPECT_EQ(201, actual_point.y()); 738 } 739 740 // Test with no ET_TOUCH_MOVED events but different touch points and radii. 741 { 742 delegate->Reset(); 743 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(365, 290), 744 kTouchId, tes.Now()); 745 press.set_radius_x(8); 746 press.set_radius_y(14); 747 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 748 EXPECT_FALSE(delegate->tap()); 749 EXPECT_TRUE(delegate->tap_down()); 750 EXPECT_FALSE(delegate->tap_cancel()); 751 EXPECT_TRUE(delegate->begin()); 752 EXPECT_FALSE(delegate->scroll_begin()); 753 EXPECT_FALSE(delegate->scroll_update()); 754 EXPECT_FALSE(delegate->scroll_end()); 755 EXPECT_FALSE(delegate->long_press()); 756 757 delegate->Reset(); 758 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(367, 291), 759 kTouchId, tes.LeapForward(50)); 760 release.set_radius_x(20); 761 release.set_radius_y(13); 762 763 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 764 EXPECT_TRUE(delegate->tap()); 765 EXPECT_FALSE(delegate->tap_down()); 766 EXPECT_FALSE(delegate->tap_cancel()); 767 EXPECT_FALSE(delegate->begin()); 768 EXPECT_TRUE(delegate->end()); 769 EXPECT_FALSE(delegate->scroll_begin()); 770 EXPECT_FALSE(delegate->scroll_update()); 771 EXPECT_FALSE(delegate->scroll_end()); 772 773 EXPECT_EQ(1, delegate->tap_count()); 774 gfx::Point actual_point(delegate->tap_location()); 775 EXPECT_EQ(40, delegate->bounding_box().width()); 776 EXPECT_EQ(40, delegate->bounding_box().height()); 777 EXPECT_EQ(367, actual_point.x()); 778 EXPECT_EQ(291, actual_point.y()); 779 } 780 781 // Test with a single ET_TOUCH_MOVED event. 782 { 783 delegate->Reset(); 784 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(46, 205), 785 kTouchId, tes.Now()); 786 press.set_radius_x(6); 787 press.set_radius_y(10); 788 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 789 EXPECT_FALSE(delegate->tap()); 790 EXPECT_TRUE(delegate->tap_down()); 791 EXPECT_FALSE(delegate->tap_cancel()); 792 EXPECT_TRUE(delegate->begin()); 793 EXPECT_FALSE(delegate->tap_cancel()); 794 EXPECT_FALSE(delegate->scroll_begin()); 795 EXPECT_FALSE(delegate->scroll_update()); 796 EXPECT_FALSE(delegate->scroll_end()); 797 EXPECT_FALSE(delegate->long_press()); 798 799 delegate->Reset(); 800 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(49, 204), 801 kTouchId, tes.LeapForward(50)); 802 move.set_radius_x(8); 803 move.set_radius_y(12); 804 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 805 EXPECT_FALSE(delegate->tap()); 806 EXPECT_FALSE(delegate->tap_down()); 807 EXPECT_FALSE(delegate->tap_cancel()); 808 EXPECT_FALSE(delegate->begin()); 809 EXPECT_FALSE(delegate->scroll_begin()); 810 EXPECT_FALSE(delegate->scroll_update()); 811 EXPECT_FALSE(delegate->scroll_end()); 812 EXPECT_FALSE(delegate->long_press()); 813 814 delegate->Reset(); 815 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(49, 204), 816 kTouchId, tes.LeapForward(50)); 817 release.set_radius_x(4); 818 release.set_radius_y(8); 819 820 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 821 EXPECT_TRUE(delegate->tap()); 822 EXPECT_FALSE(delegate->tap_down()); 823 EXPECT_FALSE(delegate->tap_cancel()); 824 EXPECT_FALSE(delegate->begin()); 825 EXPECT_TRUE(delegate->end()); 826 EXPECT_FALSE(delegate->scroll_begin()); 827 EXPECT_FALSE(delegate->scroll_update()); 828 EXPECT_FALSE(delegate->scroll_end()); 829 830 EXPECT_EQ(1, delegate->tap_count()); 831 gfx::Point actual_point(delegate->tap_location()); 832 EXPECT_EQ(25, delegate->bounding_box().width()); 833 EXPECT_EQ(24, delegate->bounding_box().height()); 834 EXPECT_EQ(48, actual_point.x()); 835 EXPECT_EQ(204, actual_point.y()); 836 } 837 838 // Test with a few ET_TOUCH_MOVED events. 839 { 840 delegate->Reset(); 841 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(400, 150), 842 kTouchId, tes.Now()); 843 press.set_radius_x(7); 844 press.set_radius_y(10); 845 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 846 EXPECT_FALSE(delegate->tap()); 847 EXPECT_TRUE(delegate->tap_down()); 848 EXPECT_FALSE(delegate->tap_cancel()); 849 EXPECT_TRUE(delegate->begin()); 850 EXPECT_FALSE(delegate->scroll_begin()); 851 EXPECT_FALSE(delegate->scroll_update()); 852 EXPECT_FALSE(delegate->scroll_end()); 853 EXPECT_FALSE(delegate->long_press()); 854 855 delegate->Reset(); 856 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(397, 151), 857 kTouchId, tes.LeapForward(50)); 858 move.set_radius_x(13); 859 move.set_radius_y(12); 860 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 861 EXPECT_FALSE(delegate->tap()); 862 EXPECT_FALSE(delegate->tap_down()); 863 EXPECT_FALSE(delegate->tap_cancel()); 864 EXPECT_FALSE(delegate->begin()); 865 EXPECT_FALSE(delegate->scroll_begin()); 866 EXPECT_FALSE(delegate->scroll_update()); 867 EXPECT_FALSE(delegate->scroll_end()); 868 EXPECT_FALSE(delegate->long_press()); 869 870 delegate->Reset(); 871 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(397, 149), 872 kTouchId, tes.LeapForward(50)); 873 move1.set_radius_x(16); 874 move1.set_radius_y(16); 875 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 876 EXPECT_FALSE(delegate->tap()); 877 EXPECT_FALSE(delegate->tap_down()); 878 EXPECT_FALSE(delegate->tap_cancel()); 879 EXPECT_FALSE(delegate->begin()); 880 EXPECT_FALSE(delegate->scroll_begin()); 881 EXPECT_FALSE(delegate->scroll_update()); 882 EXPECT_FALSE(delegate->scroll_end()); 883 EXPECT_FALSE(delegate->long_press()); 884 885 delegate->Reset(); 886 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(400, 150), 887 kTouchId, tes.LeapForward(50)); 888 move2.set_radius_x(14); 889 move2.set_radius_y(10); 890 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 891 EXPECT_FALSE(delegate->tap()); 892 EXPECT_FALSE(delegate->tap_down()); 893 EXPECT_FALSE(delegate->tap_cancel()); 894 EXPECT_FALSE(delegate->begin()); 895 EXPECT_FALSE(delegate->scroll_begin()); 896 EXPECT_FALSE(delegate->scroll_update()); 897 EXPECT_FALSE(delegate->scroll_end()); 898 EXPECT_FALSE(delegate->long_press()); 899 900 delegate->Reset(); 901 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(401, 149), 902 kTouchId, tes.LeapForward(50)); 903 release.set_radius_x(8); 904 release.set_radius_y(9); 905 906 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 907 EXPECT_TRUE(delegate->tap()); 908 EXPECT_FALSE(delegate->tap_down()); 909 EXPECT_FALSE(delegate->tap_cancel()); 910 EXPECT_FALSE(delegate->begin()); 911 EXPECT_TRUE(delegate->end()); 912 EXPECT_FALSE(delegate->scroll_begin()); 913 EXPECT_FALSE(delegate->scroll_update()); 914 EXPECT_FALSE(delegate->scroll_end()); 915 916 EXPECT_EQ(1, delegate->tap_count()); 917 gfx::Point actual_point(delegate->tap_location()); 918 EXPECT_EQ(33, delegate->bounding_box().width()); 919 EXPECT_EQ(32, delegate->bounding_box().height()); 920 EXPECT_EQ(397, actual_point.x()); 921 EXPECT_EQ(149, actual_point.y()); 922 } 923 } 924 925 // Check that appropriate touch events generate scroll gesture events. 926 TEST_F(GestureRecognizerTest, GestureEventScroll) { 927 scoped_ptr<GestureEventConsumeDelegate> delegate( 928 new GestureEventConsumeDelegate()); 929 TimedEvents tes; 930 const int kWindowWidth = 123; 931 const int kWindowHeight = 45; 932 const int kTouchId = 5; 933 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 934 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 935 delegate.get(), -1234, bounds, root_window())); 936 937 delegate->Reset(); 938 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 939 kTouchId, tes.Now()); 940 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 941 EXPECT_2_EVENTS(delegate->events(), 942 ui::ET_GESTURE_BEGIN, 943 ui::ET_GESTURE_TAP_DOWN); 944 945 // Move the touch-point enough so that it is considered as a scroll. This 946 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 947 // The first movement is diagonal, to ensure that we have a free scroll, 948 // and not a rail scroll. 949 tes.SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 950 EXPECT_3_EVENTS(delegate->events(), 951 ui::ET_GESTURE_TAP_CANCEL, 952 ui::ET_GESTURE_SCROLL_BEGIN, 953 ui::ET_GESTURE_SCROLL_UPDATE); 954 EXPECT_EQ(29, delegate->scroll_x()); 955 EXPECT_EQ(29, delegate->scroll_y()); 956 EXPECT_EQ(gfx::Point(1, 1).ToString(), 957 delegate->scroll_begin_position().ToString()); 958 959 // When scrolling with a single finger, the bounding box of the gesture should 960 // be empty, since it's a single point and the radius for testing is zero. 961 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 962 963 // Move some more to generate a few more scroll updates. 964 tes.SendScrollEvent(root_window(), 110, 211, kTouchId, delegate.get()); 965 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 966 EXPECT_EQ(-20, delegate->scroll_x()); 967 EXPECT_EQ(-19, delegate->scroll_y()); 968 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 969 970 tes.SendScrollEvent(root_window(), 140, 215, kTouchId, delegate.get()); 971 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 972 EXPECT_EQ(30, delegate->scroll_x()); 973 EXPECT_EQ(4, delegate->scroll_y()); 974 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 975 976 // Release the touch. This should end the scroll. 977 delegate->Reset(); 978 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 979 kTouchId, 980 tes.LeapForward(50)); 981 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 982 EXPECT_2_EVENTS(delegate->events(), 983 ui::ET_SCROLL_FLING_START, 984 ui::ET_GESTURE_END); 985 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 986 } 987 988 // Check that predicted scroll update positions are correct. 989 TEST_F(GestureRecognizerTest, GestureEventScrollPrediction) { 990 const double prediction_interval = 0.03; 991 ui::GestureConfiguration::set_scroll_prediction_seconds(prediction_interval); 992 scoped_ptr<GestureEventConsumeDelegate> delegate( 993 new GestureEventConsumeDelegate()); 994 TimedEvents tes; 995 const int kWindowWidth = 123; 996 const int kWindowHeight = 45; 997 const int kTouchId = 5; 998 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 999 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1000 delegate.get(), -1234, bounds, root_window())); 1001 1002 delegate->Reset(); 1003 // Tracks the total scroll since we want to verify that the correct position 1004 // will be scrolled to throughout the prediction. 1005 gfx::Vector2dF total_scroll; 1006 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1007 kTouchId, tes.Now()); 1008 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1009 EXPECT_2_EVENTS(delegate->events(), 1010 ui::ET_GESTURE_BEGIN, 1011 ui::ET_GESTURE_TAP_DOWN); 1012 1013 // Move the touch-point enough so that it is considered as a scroll. This 1014 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1015 // The first movement is diagonal, to ensure that we have a free scroll, 1016 // and not a rail scroll. 1017 tes.LeapForward(30); 1018 tes.SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 1019 EXPECT_3_EVENTS(delegate->events(), 1020 ui::ET_GESTURE_TAP_CANCEL, 1021 ui::ET_GESTURE_SCROLL_BEGIN, 1022 ui::ET_GESTURE_SCROLL_UPDATE); 1023 EXPECT_GT(delegate->scroll_velocity_x(), 0); 1024 EXPECT_GT(delegate->scroll_velocity_y(), 0); 1025 total_scroll.set_x(total_scroll.x() + delegate->scroll_x()); 1026 total_scroll.set_y(total_scroll.y() + delegate->scroll_y()); 1027 EXPECT_EQ((int)(29 + delegate->scroll_velocity_x() * prediction_interval), 1028 (int)(total_scroll.x())); 1029 EXPECT_EQ((int)(29 + delegate->scroll_velocity_y() * prediction_interval), 1030 (int)(total_scroll.y())); 1031 1032 // Move some more to generate a few more scroll updates. 1033 tes.LeapForward(30); 1034 tes.SendScrollEvent(root_window(), 110, 211, kTouchId, delegate.get()); 1035 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1036 total_scroll.set_x(total_scroll.x() + delegate->scroll_x()); 1037 total_scroll.set_y(total_scroll.y() + delegate->scroll_y()); 1038 EXPECT_EQ((int)(9 + delegate->scroll_velocity_x() * prediction_interval), 1039 (int)(total_scroll.x())); 1040 EXPECT_EQ((int)(10 + delegate->scroll_velocity_y() * prediction_interval), 1041 (int)(total_scroll.y())); 1042 1043 tes.LeapForward(30); 1044 tes.SendScrollEvent(root_window(), 140, 215, kTouchId, delegate.get()); 1045 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1046 total_scroll.set_x(total_scroll.x() + delegate->scroll_x()); 1047 total_scroll.set_y(total_scroll.y() + delegate->scroll_y()); 1048 EXPECT_EQ((int)(39 + delegate->scroll_velocity_x() * prediction_interval), 1049 (int)(total_scroll.x())); 1050 EXPECT_EQ((int)(14 + delegate->scroll_velocity_y() * prediction_interval), 1051 (int)(total_scroll.y())); 1052 1053 // Release the touch. This should end the scroll. 1054 delegate->Reset(); 1055 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1056 kTouchId, 1057 tes.LeapForward(50)); 1058 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1059 } 1060 1061 // Check that the bounding box during a scroll event is correct. 1062 TEST_F(GestureRecognizerTest, GestureEventScrollBoundingBox) { 1063 TimedEvents tes; 1064 for (int radius = 1; radius <= 10; ++radius) { 1065 ui::GestureConfiguration::set_default_radius(radius); 1066 scoped_ptr<GestureEventConsumeDelegate> delegate( 1067 new GestureEventConsumeDelegate()); 1068 const int kWindowWidth = 123; 1069 const int kWindowHeight = 45; 1070 const int kTouchId = 5; 1071 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1072 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1073 delegate.get(), -1234, bounds, root_window())); 1074 1075 const int kPositionX = 101; 1076 const int kPositionY = 201; 1077 delegate->Reset(); 1078 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 1079 gfx::Point(kPositionX, kPositionY), 1080 kTouchId, 1081 tes.Now()); 1082 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1083 EXPECT_EQ(gfx::Rect(kPositionX - radius, 1084 kPositionY - radius, 1085 radius * 2, 1086 radius * 2).ToString(), 1087 delegate->bounding_box().ToString()); 1088 1089 const int kScrollAmount = 50; 1090 tes.SendScrollEvents(root_window(), kPositionX, kPositionY, 1091 1, 1, kTouchId, 1, kScrollAmount, delegate.get()); 1092 EXPECT_EQ(gfx::Point(1, 1).ToString(), 1093 delegate->scroll_begin_position().ToString()); 1094 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, 1095 kPositionY + kScrollAmount - radius, 1096 radius * 2, 1097 radius * 2).ToString(), 1098 delegate->bounding_box().ToString()); 1099 1100 // Release the touch. This should end the scroll. 1101 delegate->Reset(); 1102 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, 1103 gfx::Point(kPositionX + kScrollAmount, 1104 kPositionY + kScrollAmount), 1105 kTouchId, press.time_stamp() + 1106 base::TimeDelta::FromMilliseconds(50)); 1107 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1108 EXPECT_EQ(gfx::Rect(kPositionX + kScrollAmount - radius, 1109 kPositionY + kScrollAmount - radius, 1110 radius * 2, 1111 radius * 2).ToString(), 1112 delegate->bounding_box().ToString()); 1113 } 1114 ui::GestureConfiguration::set_default_radius(0); 1115 } 1116 1117 // Check Scroll End Events report correct velocities 1118 // if the user was on a horizontal rail 1119 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailFling) { 1120 scoped_ptr<GestureEventConsumeDelegate> delegate( 1121 new GestureEventConsumeDelegate()); 1122 TimedEvents tes; 1123 const int kTouchId = 7; 1124 gfx::Rect bounds(0, 0, 1000, 1000); 1125 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1126 delegate.get(), -1234, bounds, root_window())); 1127 1128 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1129 kTouchId, tes.Now()); 1130 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1131 1132 // Move the touch-point horizontally enough that it is considered a 1133 // horizontal scroll. 1134 tes.SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 1135 EXPECT_EQ(0, delegate->scroll_y()); 1136 EXPECT_EQ(1, delegate->scroll_y_ordinal()); 1137 EXPECT_EQ(20, delegate->scroll_x()); 1138 EXPECT_EQ(20, delegate->scroll_x_ordinal()); 1139 1140 // Get a high x velocity, while still staying on the rail 1141 tes.SendScrollEvents(root_window(), 1, 1, 1142 100, 10, kTouchId, 1, 1143 ui::GestureConfiguration::points_buffered_for_velocity(), 1144 delegate.get()); 1145 // The y-velocity during the scroll should be 0 since this is in a horizontal 1146 // rail scroll. 1147 EXPECT_GT(delegate->scroll_velocity_x(), 0); 1148 EXPECT_EQ(0, delegate->scroll_velocity_y()); 1149 1150 delegate->Reset(); 1151 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1152 kTouchId, tes.Now()); 1153 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1154 1155 EXPECT_TRUE(delegate->fling()); 1156 EXPECT_FALSE(delegate->scroll_end()); 1157 EXPECT_GT(delegate->velocity_x(), 0); 1158 EXPECT_EQ(0, delegate->velocity_y()); 1159 } 1160 1161 // Check Scroll End Events report correct velocities 1162 // if the user was on a vertical rail 1163 TEST_F(GestureRecognizerTest, GestureEventVerticalRailFling) { 1164 scoped_ptr<GestureEventConsumeDelegate> delegate( 1165 new GestureEventConsumeDelegate()); 1166 TimedEvents tes; 1167 const int kTouchId = 7; 1168 gfx::Rect bounds(0, 0, 1000, 1000); 1169 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1170 delegate.get(), -1234, bounds, root_window())); 1171 1172 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1173 kTouchId, tes.Now()); 1174 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1175 1176 // Move the touch-point vertically enough that it is considered a 1177 // vertical scroll. 1178 tes.SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 1179 EXPECT_EQ(20, delegate->scroll_y()); 1180 EXPECT_EQ(20, delegate->scroll_y_ordinal()); 1181 EXPECT_EQ(0, delegate->scroll_x()); 1182 EXPECT_EQ(1, delegate->scroll_x_ordinal()); 1183 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1184 EXPECT_GT(delegate->scroll_velocity_x_ordinal(), 0); 1185 1186 // Get a high y velocity, while still staying on the rail 1187 tes.SendScrollEvents(root_window(), 1, 1, 1188 10, 100, kTouchId, 1, 1189 ui::GestureConfiguration::points_buffered_for_velocity(), 1190 delegate.get()); 1191 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1192 EXPECT_GT(delegate->scroll_velocity_y(), 0); 1193 1194 delegate->Reset(); 1195 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1196 kTouchId, tes.Now()); 1197 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1198 1199 EXPECT_TRUE(delegate->fling()); 1200 EXPECT_FALSE(delegate->scroll_end()); 1201 EXPECT_EQ(0, delegate->velocity_x()); 1202 EXPECT_GT(delegate->velocity_y(), 0); 1203 } 1204 1205 // Check Scroll End Events reports zero velocities 1206 // if the user is not on a rail 1207 TEST_F(GestureRecognizerTest, GestureEventNonRailFling) { 1208 scoped_ptr<GestureEventConsumeDelegate> delegate( 1209 new GestureEventConsumeDelegate()); 1210 TimedEvents tes; 1211 const int kTouchId = 7; 1212 gfx::Rect bounds(0, 0, 1000, 1000); 1213 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1214 delegate.get(), -1234, bounds, root_window())); 1215 1216 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1217 kTouchId, tes.Now()); 1218 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1219 1220 // Move the touch-point such that a non-rail scroll begins 1221 tes.SendScrollEvent(root_window(), 20, 20, kTouchId, delegate.get()); 1222 EXPECT_EQ(20, delegate->scroll_y()); 1223 EXPECT_EQ(20, delegate->scroll_x()); 1224 1225 tes.SendScrollEvents(root_window(), 1, 1, 1226 10, 100, kTouchId, 1, 1227 ui::GestureConfiguration::points_buffered_for_velocity(), 1228 delegate.get()); 1229 1230 delegate->Reset(); 1231 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1232 kTouchId, tes.Now()); 1233 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1234 1235 EXPECT_TRUE(delegate->fling()); 1236 EXPECT_FALSE(delegate->scroll_end()); 1237 EXPECT_GT(delegate->velocity_x(), 0); 1238 EXPECT_GT(delegate->velocity_y(), 0); 1239 } 1240 1241 // Check that appropriate touch events generate long press events 1242 TEST_F(GestureRecognizerTest, GestureEventLongPress) { 1243 scoped_ptr<GestureEventConsumeDelegate> delegate( 1244 new GestureEventConsumeDelegate()); 1245 TimedEvents tes; 1246 const int kWindowWidth = 123; 1247 const int kWindowHeight = 45; 1248 const int kTouchId = 2; 1249 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1250 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1251 delegate.get(), -1234, bounds, root_window())); 1252 1253 delegate->Reset(); 1254 1255 TimerTestGestureRecognizer* gesture_recognizer = 1256 new TimerTestGestureRecognizer(root_window()); 1257 1258 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1259 1260 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1261 kTouchId, tes.Now()); 1262 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1263 EXPECT_TRUE(delegate->tap_down()); 1264 EXPECT_TRUE(delegate->begin()); 1265 EXPECT_FALSE(delegate->tap_cancel()); 1266 1267 // We haven't pressed long enough for a long press to occur 1268 EXPECT_FALSE(delegate->long_press()); 1269 1270 // Wait until the timer runs out 1271 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 1272 EXPECT_TRUE(delegate->long_press()); 1273 EXPECT_EQ(0, delegate->touch_id()); 1274 EXPECT_FALSE(delegate->tap_cancel()); 1275 1276 delegate->Reset(); 1277 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1278 kTouchId, tes.Now()); 1279 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1280 EXPECT_FALSE(delegate->long_press()); 1281 1282 // Note the tap down isn't cancelled until the release 1283 EXPECT_TRUE(delegate->tap_cancel()); 1284 } 1285 1286 // Check that scrolling cancels a long press 1287 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledByScroll) { 1288 scoped_ptr<GestureEventConsumeDelegate> delegate( 1289 new GestureEventConsumeDelegate()); 1290 TimedEvents tes; 1291 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1292 const int kWindowWidth = 123; 1293 const int kWindowHeight = 45; 1294 const int kTouchId = 6; 1295 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1296 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1297 delegate.get(), -1234, bounds, root_window())); 1298 1299 delegate->Reset(); 1300 1301 TimerTestGestureRecognizer* gesture_recognizer = 1302 new TimerTestGestureRecognizer(root_window()); 1303 TimerTestGestureSequence* gesture_sequence = 1304 static_cast<TimerTestGestureSequence*>( 1305 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 1306 1307 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1308 1309 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1310 kTouchId, tes.Now()); 1311 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1312 EXPECT_TRUE(delegate->tap_down()); 1313 1314 // We haven't pressed long enough for a long press to occur 1315 EXPECT_FALSE(delegate->long_press()); 1316 EXPECT_FALSE(delegate->tap_cancel()); 1317 1318 // Scroll around, to cancel the long press 1319 tes.SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 1320 // Wait until the timer runs out 1321 gesture_sequence->ForceTimeout(); 1322 EXPECT_FALSE(delegate->long_press()); 1323 EXPECT_TRUE(delegate->tap_cancel()); 1324 1325 delegate->Reset(); 1326 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1327 kTouchId, tes.LeapForward(10)); 1328 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1329 EXPECT_FALSE(delegate->long_press()); 1330 EXPECT_FALSE(delegate->tap_cancel()); 1331 } 1332 1333 // Check that appropriate touch events generate long tap events 1334 TEST_F(GestureRecognizerTest, GestureEventLongTap) { 1335 scoped_ptr<GestureEventConsumeDelegate> delegate( 1336 new GestureEventConsumeDelegate()); 1337 TimedEvents tes; 1338 const int kWindowWidth = 123; 1339 const int kWindowHeight = 45; 1340 const int kTouchId = 2; 1341 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1342 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1343 delegate.get(), -1234, bounds, root_window())); 1344 1345 delegate->Reset(); 1346 1347 TimerTestGestureRecognizer* gesture_recognizer = 1348 new TimerTestGestureRecognizer(root_window()); 1349 1350 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1351 1352 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1353 kTouchId, tes.Now()); 1354 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1355 EXPECT_TRUE(delegate->tap_down()); 1356 EXPECT_TRUE(delegate->begin()); 1357 EXPECT_FALSE(delegate->tap_cancel()); 1358 1359 // We haven't pressed long enough for a long press to occur 1360 EXPECT_FALSE(delegate->long_press()); 1361 1362 // Wait until the timer runs out 1363 delegate->WaitUntilReceivedGesture(ui::ET_GESTURE_LONG_PRESS); 1364 EXPECT_TRUE(delegate->long_press()); 1365 EXPECT_EQ(0, delegate->touch_id()); 1366 EXPECT_FALSE(delegate->tap_cancel()); 1367 1368 delegate->Reset(); 1369 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1370 kTouchId, tes.Now()); 1371 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1372 EXPECT_FALSE(delegate->long_press()); 1373 EXPECT_TRUE(delegate->long_tap()); 1374 1375 // Note the tap down isn't cancelled until the release 1376 EXPECT_TRUE(delegate->tap_cancel()); 1377 } 1378 1379 // Check that second tap cancels a long press 1380 TEST_F(GestureRecognizerTest, GestureEventLongPressCancelledBySecondTap) { 1381 scoped_ptr<GestureEventConsumeDelegate> delegate( 1382 new GestureEventConsumeDelegate()); 1383 TimedEvents tes; 1384 ui::GestureConfiguration::set_long_press_time_in_seconds(.01); 1385 const int kWindowWidth = 300; 1386 const int kWindowHeight = 400; 1387 const int kTouchId1 = 8; 1388 const int kTouchId2 = 2; 1389 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1390 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1391 delegate.get(), -1234, bounds, root_window())); 1392 1393 TimerTestGestureRecognizer* gesture_recognizer = 1394 new TimerTestGestureRecognizer(root_window()); 1395 TimerTestGestureSequence* gesture_sequence = 1396 static_cast<TimerTestGestureSequence*>( 1397 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 1398 1399 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 1400 1401 delegate->Reset(); 1402 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1403 kTouchId1, tes.Now()); 1404 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1405 EXPECT_TRUE(delegate->tap_down()); 1406 EXPECT_TRUE(delegate->begin()); 1407 1408 // We haven't pressed long enough for a long press to occur 1409 EXPECT_FALSE(delegate->long_press()); 1410 1411 // Second tap, to cancel the long press 1412 delegate->Reset(); 1413 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1414 kTouchId2, tes.Now()); 1415 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1416 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 1417 EXPECT_TRUE(delegate->tap_cancel()); 1418 EXPECT_TRUE(delegate->begin()); 1419 1420 // Wait until the timer runs out 1421 gesture_sequence->ForceTimeout(); 1422 1423 // No long press occurred 1424 EXPECT_FALSE(delegate->long_press()); 1425 1426 delegate->Reset(); 1427 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1428 kTouchId1, tes.Now()); 1429 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1430 EXPECT_FALSE(delegate->long_press()); 1431 EXPECT_TRUE(delegate->two_finger_tap()); 1432 EXPECT_FALSE(delegate->tap_cancel()); 1433 } 1434 1435 // Check that horizontal scroll gestures cause scrolls on horizontal rails. 1436 // Also tests that horizontal rails can be broken. 1437 TEST_F(GestureRecognizerTest, GestureEventHorizontalRailScroll) { 1438 scoped_ptr<GestureEventConsumeDelegate> delegate( 1439 new GestureEventConsumeDelegate()); 1440 TimedEvents tes; 1441 const int kTouchId = 7; 1442 gfx::Rect bounds(0, 0, 1000, 1000); 1443 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1444 delegate.get(), -1234, bounds, root_window())); 1445 1446 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1447 kTouchId, tes.Now()); 1448 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1449 1450 // Move the touch-point horizontally enough that it is considered a 1451 // horizontal scroll. 1452 tes.SendScrollEvent(root_window(), 20, 1, kTouchId, delegate.get()); 1453 EXPECT_EQ(0, delegate->scroll_y()); 1454 EXPECT_EQ(20, delegate->scroll_x()); 1455 1456 tes.SendScrollEvent(root_window(), 25, 6, kTouchId, delegate.get()); 1457 EXPECT_TRUE(delegate->scroll_update()); 1458 EXPECT_EQ(5, delegate->scroll_x()); 1459 // y shouldn't change, as we're on a horizontal rail. 1460 EXPECT_EQ(0, delegate->scroll_y()); 1461 1462 // Send enough information that a velocity can be calculated for the gesture, 1463 // and we can break the rail 1464 tes.SendScrollEvents(root_window(), 1, 1, 1465 1, 100, kTouchId, 1, 1466 ui::GestureConfiguration::points_buffered_for_velocity(), 1467 delegate.get()); 1468 // Since the scroll is not longer railing, the velocity should be set for both 1469 // axis. 1470 EXPECT_GT(delegate->scroll_velocity_x(), 0); 1471 EXPECT_GT(delegate->scroll_velocity_y(), 0); 1472 1473 tes.SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); 1474 tes.SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); 1475 1476 // The rail should be broken 1477 EXPECT_TRUE(delegate->scroll_update()); 1478 EXPECT_EQ(5, delegate->scroll_x()); 1479 EXPECT_EQ(5, delegate->scroll_y()); 1480 } 1481 1482 // Check that vertical scroll gestures cause scrolls on vertical rails. 1483 // Also tests that vertical rails can be broken. 1484 TEST_F(GestureRecognizerTest, GestureEventVerticalRailScroll) { 1485 scoped_ptr<GestureEventConsumeDelegate> delegate( 1486 new GestureEventConsumeDelegate()); 1487 TimedEvents tes; 1488 const int kTouchId = 7; 1489 gfx::Rect bounds(0, 0, 1000, 1000); 1490 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1491 delegate.get(), -1234, bounds, root_window())); 1492 1493 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 0), 1494 kTouchId, tes.Now()); 1495 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1496 1497 // Move the touch-point vertically enough that it is considered a 1498 // vertical scroll. 1499 tes.SendScrollEvent(root_window(), 1, 20, kTouchId, delegate.get()); 1500 EXPECT_EQ(0, delegate->scroll_x()); 1501 EXPECT_EQ(20, delegate->scroll_y()); 1502 1503 tes.SendScrollEvent(root_window(), 6, 25, kTouchId, delegate.get()); 1504 EXPECT_TRUE(delegate->scroll_update()); 1505 EXPECT_EQ(5, delegate->scroll_y()); 1506 // x shouldn't change, as we're on a vertical rail. 1507 EXPECT_EQ(0, delegate->scroll_x()); 1508 EXPECT_EQ(0, delegate->scroll_velocity_x()); 1509 1510 // Send enough information that a velocity can be calculated for the gesture, 1511 // and we can break the rail 1512 tes.SendScrollEvents(root_window(), 1, 1, 1513 100, 1, kTouchId, 1, 1514 ui::GestureConfiguration::points_buffered_for_velocity(), 1515 delegate.get()); 1516 EXPECT_GT(delegate->scroll_velocity_x(), 0); 1517 EXPECT_GT(delegate->scroll_velocity_y(), 0); 1518 1519 tes.SendScrollEvent(root_window(), 0, 0, kTouchId, delegate.get()); 1520 tes.SendScrollEvent(root_window(), 5, 5, kTouchId, delegate.get()); 1521 1522 // The rail should be broken 1523 EXPECT_TRUE(delegate->scroll_update()); 1524 EXPECT_EQ(5, delegate->scroll_x()); 1525 EXPECT_EQ(5, delegate->scroll_y()); 1526 } 1527 1528 TEST_F(GestureRecognizerTest, GestureTapFollowedByScroll) { 1529 // First, tap. Then, do a scroll using the same touch-id. 1530 scoped_ptr<GestureEventConsumeDelegate> delegate( 1531 new GestureEventConsumeDelegate()); 1532 TimedEvents tes; 1533 const int kWindowWidth = 123; 1534 const int kWindowHeight = 45; 1535 const int kTouchId = 3; 1536 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1537 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1538 delegate.get(), -1234, bounds, root_window())); 1539 1540 delegate->Reset(); 1541 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1542 kTouchId, tes.Now()); 1543 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1544 EXPECT_FALSE(delegate->tap()); 1545 EXPECT_TRUE(delegate->tap_down()); 1546 EXPECT_FALSE(delegate->tap_cancel()); 1547 EXPECT_FALSE(delegate->scroll_begin()); 1548 EXPECT_FALSE(delegate->scroll_update()); 1549 EXPECT_FALSE(delegate->scroll_end()); 1550 1551 // Make sure there is enough delay before the touch is released so that it is 1552 // recognized as a tap. 1553 delegate->Reset(); 1554 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1555 kTouchId, tes.LeapForward(50)); 1556 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1557 EXPECT_TRUE(delegate->tap()); 1558 EXPECT_FALSE(delegate->tap_down()); 1559 EXPECT_FALSE(delegate->tap_cancel()); 1560 EXPECT_FALSE(delegate->scroll_begin()); 1561 EXPECT_FALSE(delegate->scroll_update()); 1562 EXPECT_FALSE(delegate->scroll_end()); 1563 1564 // Now, do a scroll gesture. Delay it sufficiently so that it doesn't trigger 1565 // a double-tap. 1566 delegate->Reset(); 1567 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1568 kTouchId, tes.LeapForward(1000)); 1569 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 1570 EXPECT_FALSE(delegate->tap()); 1571 EXPECT_TRUE(delegate->tap_down()); 1572 EXPECT_FALSE(delegate->tap_cancel()); 1573 EXPECT_FALSE(delegate->scroll_begin()); 1574 EXPECT_FALSE(delegate->scroll_update()); 1575 EXPECT_FALSE(delegate->scroll_end()); 1576 1577 // Move the touch-point enough so that it is considered as a scroll. This 1578 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1579 // The first movement is diagonal, to ensure that we have a free scroll, 1580 // and not a rail scroll. 1581 delegate->Reset(); 1582 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 230), 1583 kTouchId, tes.Now()); 1584 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1585 EXPECT_FALSE(delegate->tap()); 1586 EXPECT_FALSE(delegate->tap_down()); 1587 EXPECT_TRUE(delegate->tap_cancel()); 1588 EXPECT_TRUE(delegate->scroll_begin()); 1589 EXPECT_TRUE(delegate->scroll_update()); 1590 EXPECT_FALSE(delegate->scroll_end()); 1591 EXPECT_EQ(29, delegate->scroll_x()); 1592 EXPECT_EQ(29, delegate->scroll_y()); 1593 1594 // Move some more to generate a few more scroll updates. 1595 delegate->Reset(); 1596 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(110, 211), 1597 kTouchId, tes.Now()); 1598 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 1599 EXPECT_FALSE(delegate->tap()); 1600 EXPECT_FALSE(delegate->tap_down()); 1601 EXPECT_FALSE(delegate->tap_cancel()); 1602 EXPECT_FALSE(delegate->scroll_begin()); 1603 EXPECT_TRUE(delegate->scroll_update()); 1604 EXPECT_FALSE(delegate->scroll_end()); 1605 EXPECT_EQ(-20, delegate->scroll_x()); 1606 EXPECT_EQ(-19, delegate->scroll_y()); 1607 1608 delegate->Reset(); 1609 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(140, 215), 1610 kTouchId, tes.Now()); 1611 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1612 EXPECT_FALSE(delegate->tap()); 1613 EXPECT_FALSE(delegate->tap_down()); 1614 EXPECT_FALSE(delegate->tap_cancel()); 1615 EXPECT_FALSE(delegate->scroll_begin()); 1616 EXPECT_TRUE(delegate->scroll_update()); 1617 EXPECT_FALSE(delegate->scroll_end()); 1618 EXPECT_EQ(30, delegate->scroll_x()); 1619 EXPECT_EQ(4, delegate->scroll_y()); 1620 1621 // Release the touch. This should end the scroll. 1622 delegate->Reset(); 1623 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1624 kTouchId, tes.Now()); 1625 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 1626 EXPECT_FALSE(delegate->tap()); 1627 EXPECT_FALSE(delegate->tap_down()); 1628 EXPECT_FALSE(delegate->tap_cancel()); 1629 EXPECT_FALSE(delegate->scroll_begin()); 1630 EXPECT_FALSE(delegate->scroll_update()); 1631 EXPECT_FALSE(delegate->scroll_end()); 1632 EXPECT_TRUE(delegate->fling()); 1633 } 1634 1635 TEST_F(GestureRecognizerTest, AsynchronousGestureRecognition) { 1636 scoped_ptr<QueueTouchEventDelegate> queued_delegate( 1637 new QueueTouchEventDelegate(root_window())); 1638 const int kWindowWidth = 123; 1639 const int kWindowHeight = 45; 1640 const int kTouchId1 = 6; 1641 const int kTouchId2 = 4; 1642 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 1643 scoped_ptr<aura::Window> queue(CreateTestWindowWithDelegate( 1644 queued_delegate.get(), -1234, bounds, root_window())); 1645 1646 queued_delegate->set_window(queue.get()); 1647 1648 // Touch down on the window. This should not generate any gesture event. 1649 queued_delegate->Reset(); 1650 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1651 kTouchId1, GetTime()); 1652 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1653 EXPECT_FALSE(queued_delegate->tap()); 1654 EXPECT_FALSE(queued_delegate->tap_down()); 1655 EXPECT_FALSE(queued_delegate->tap_cancel()); 1656 EXPECT_FALSE(queued_delegate->begin()); 1657 EXPECT_FALSE(queued_delegate->scroll_begin()); 1658 EXPECT_FALSE(queued_delegate->scroll_update()); 1659 EXPECT_FALSE(queued_delegate->scroll_end()); 1660 1661 // Introduce some delay before the touch is released so that it is recognized 1662 // as a tap. However, this still should not create any gesture events. 1663 queued_delegate->Reset(); 1664 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1665 kTouchId1, press.time_stamp() + 1666 base::TimeDelta::FromMilliseconds(50)); 1667 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1668 EXPECT_FALSE(queued_delegate->tap()); 1669 EXPECT_FALSE(queued_delegate->tap_down()); 1670 EXPECT_FALSE(queued_delegate->tap_cancel()); 1671 EXPECT_FALSE(queued_delegate->begin()); 1672 EXPECT_FALSE(queued_delegate->end()); 1673 EXPECT_FALSE(queued_delegate->scroll_begin()); 1674 EXPECT_FALSE(queued_delegate->scroll_update()); 1675 EXPECT_FALSE(queued_delegate->scroll_end()); 1676 1677 // Create another window, and place a touch-down on it. This should create a 1678 // tap-down gesture. 1679 scoped_ptr<GestureEventConsumeDelegate> delegate( 1680 new GestureEventConsumeDelegate()); 1681 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1682 delegate.get(), -2345, gfx::Rect(0, 0, 50, 50), root_window())); 1683 delegate->Reset(); 1684 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 20), 1685 kTouchId2, GetTime()); 1686 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1687 EXPECT_FALSE(delegate->tap()); 1688 EXPECT_TRUE(delegate->tap_down()); 1689 EXPECT_FALSE(delegate->tap_cancel()); 1690 EXPECT_FALSE(queued_delegate->begin()); 1691 EXPECT_FALSE(queued_delegate->end()); 1692 EXPECT_FALSE(delegate->scroll_begin()); 1693 EXPECT_FALSE(delegate->scroll_update()); 1694 EXPECT_FALSE(delegate->scroll_end()); 1695 1696 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(10, 20), 1697 kTouchId2, GetTime()); 1698 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 1699 1700 // Process the first queued event. 1701 queued_delegate->Reset(); 1702 queued_delegate->ReceivedAck(); 1703 EXPECT_FALSE(queued_delegate->tap()); 1704 EXPECT_TRUE(queued_delegate->tap_down()); 1705 EXPECT_TRUE(queued_delegate->begin()); 1706 EXPECT_FALSE(queued_delegate->tap_cancel()); 1707 EXPECT_FALSE(queued_delegate->end()); 1708 EXPECT_FALSE(queued_delegate->scroll_begin()); 1709 EXPECT_FALSE(queued_delegate->scroll_update()); 1710 EXPECT_FALSE(queued_delegate->scroll_end()); 1711 1712 // Now, process the second queued event. 1713 queued_delegate->Reset(); 1714 queued_delegate->ReceivedAck(); 1715 EXPECT_TRUE(queued_delegate->tap()); 1716 EXPECT_FALSE(queued_delegate->tap_down()); 1717 EXPECT_FALSE(queued_delegate->tap_cancel()); 1718 EXPECT_FALSE(queued_delegate->begin()); 1719 EXPECT_TRUE(queued_delegate->end()); 1720 EXPECT_FALSE(queued_delegate->scroll_begin()); 1721 EXPECT_FALSE(queued_delegate->scroll_update()); 1722 EXPECT_FALSE(queued_delegate->scroll_end()); 1723 1724 // Start all over. Press on the first window, then press again on the second 1725 // window. The second press should still go to the first window. 1726 queued_delegate->Reset(); 1727 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1728 kTouchId1, GetTime()); 1729 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 1730 EXPECT_FALSE(queued_delegate->tap()); 1731 EXPECT_FALSE(queued_delegate->tap_down()); 1732 EXPECT_FALSE(queued_delegate->tap_cancel()); 1733 EXPECT_FALSE(queued_delegate->begin()); 1734 EXPECT_FALSE(queued_delegate->end()); 1735 EXPECT_FALSE(queued_delegate->begin()); 1736 EXPECT_FALSE(queued_delegate->end()); 1737 EXPECT_FALSE(queued_delegate->scroll_begin()); 1738 EXPECT_FALSE(queued_delegate->scroll_update()); 1739 EXPECT_FALSE(queued_delegate->scroll_end()); 1740 1741 queued_delegate->Reset(); 1742 delegate->Reset(); 1743 ui::TouchEvent press4(ui::ET_TOUCH_PRESSED, gfx::Point(103, 203), 1744 kTouchId2, GetTime()); 1745 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press4); 1746 EXPECT_FALSE(delegate->tap()); 1747 EXPECT_FALSE(delegate->tap_down()); 1748 EXPECT_FALSE(delegate->tap_cancel()); 1749 EXPECT_FALSE(delegate->begin()); 1750 EXPECT_FALSE(delegate->end()); 1751 EXPECT_FALSE(delegate->scroll_begin()); 1752 EXPECT_FALSE(delegate->scroll_update()); 1753 EXPECT_FALSE(delegate->scroll_end()); 1754 EXPECT_FALSE(queued_delegate->tap()); 1755 EXPECT_FALSE(queued_delegate->tap_down()); 1756 EXPECT_FALSE(queued_delegate->tap_cancel()); 1757 EXPECT_FALSE(queued_delegate->begin()); 1758 EXPECT_FALSE(queued_delegate->end()); 1759 EXPECT_FALSE(queued_delegate->scroll_begin()); 1760 EXPECT_FALSE(queued_delegate->scroll_update()); 1761 EXPECT_FALSE(queued_delegate->scroll_end()); 1762 1763 // Move the second touch-point enough so that it is considered a pinch. This 1764 // should generate both SCROLL_BEGIN and PINCH_BEGIN gestures. 1765 queued_delegate->Reset(); 1766 delegate->Reset(); 1767 int x_move = ui::GestureConfiguration::max_touch_move_in_pixels_for_click(); 1768 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(103 + x_move, 203), 1769 kTouchId2, GetTime()); 1770 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1771 EXPECT_FALSE(delegate->tap()); 1772 EXPECT_FALSE(delegate->tap_down()); 1773 EXPECT_FALSE(delegate->tap_cancel()); 1774 EXPECT_FALSE(delegate->begin()); 1775 EXPECT_FALSE(delegate->scroll_begin()); 1776 EXPECT_FALSE(delegate->scroll_update()); 1777 EXPECT_FALSE(delegate->scroll_end()); 1778 EXPECT_FALSE(queued_delegate->tap()); 1779 EXPECT_FALSE(queued_delegate->tap_down()); 1780 EXPECT_FALSE(queued_delegate->tap_cancel()); 1781 EXPECT_FALSE(queued_delegate->begin()); 1782 EXPECT_FALSE(queued_delegate->scroll_begin()); 1783 EXPECT_FALSE(queued_delegate->scroll_update()); 1784 EXPECT_FALSE(queued_delegate->scroll_end()); 1785 1786 queued_delegate->Reset(); 1787 queued_delegate->ReceivedAck(); 1788 EXPECT_FALSE(queued_delegate->tap()); 1789 EXPECT_TRUE(queued_delegate->tap_down()); 1790 EXPECT_TRUE(queued_delegate->begin()); 1791 EXPECT_FALSE(queued_delegate->tap_cancel()); 1792 EXPECT_FALSE(queued_delegate->end()); 1793 EXPECT_FALSE(queued_delegate->scroll_begin()); 1794 EXPECT_FALSE(queued_delegate->scroll_update()); 1795 EXPECT_FALSE(queued_delegate->scroll_end()); 1796 1797 queued_delegate->Reset(); 1798 queued_delegate->ReceivedAck(); 1799 EXPECT_FALSE(queued_delegate->tap()); 1800 EXPECT_FALSE(queued_delegate->tap_down()); // no touch down for second tap. 1801 EXPECT_TRUE(queued_delegate->tap_cancel()); 1802 EXPECT_TRUE(queued_delegate->begin()); 1803 EXPECT_FALSE(queued_delegate->end()); 1804 EXPECT_FALSE(queued_delegate->scroll_begin()); 1805 EXPECT_FALSE(queued_delegate->scroll_update()); 1806 EXPECT_FALSE(queued_delegate->scroll_end()); 1807 EXPECT_FALSE(queued_delegate->pinch_begin()); 1808 EXPECT_FALSE(queued_delegate->pinch_update()); 1809 EXPECT_FALSE(queued_delegate->pinch_end()); 1810 1811 queued_delegate->Reset(); 1812 queued_delegate->ReceivedAck(); 1813 EXPECT_FALSE(queued_delegate->tap()); 1814 EXPECT_FALSE(queued_delegate->tap_down()); 1815 EXPECT_FALSE(queued_delegate->tap_cancel()); 1816 EXPECT_FALSE(queued_delegate->begin()); 1817 EXPECT_FALSE(queued_delegate->end()); 1818 EXPECT_TRUE(queued_delegate->scroll_begin()); 1819 EXPECT_FALSE(queued_delegate->scroll_update()); 1820 EXPECT_FALSE(queued_delegate->scroll_end()); 1821 EXPECT_TRUE(queued_delegate->pinch_begin()); 1822 EXPECT_FALSE(queued_delegate->pinch_update()); 1823 EXPECT_FALSE(queued_delegate->pinch_end()); 1824 } 1825 1826 // Check that appropriate touch events generate pinch gesture events. 1827 TEST_F(GestureRecognizerTest, GestureEventPinchFromScroll) { 1828 scoped_ptr<GestureEventConsumeDelegate> delegate( 1829 new GestureEventConsumeDelegate()); 1830 TimedEvents tes; 1831 const int kWindowWidth = 300; 1832 const int kWindowHeight = 400; 1833 const int kTouchId1 = 5; 1834 const int kTouchId2 = 3; 1835 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1836 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1837 delegate.get(), -1234, bounds, root_window())); 1838 1839 aura::RootWindow* root = root_window(); 1840 1841 delegate->Reset(); 1842 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 1843 kTouchId1, tes.Now()); 1844 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1845 EXPECT_2_EVENTS(delegate->events(), 1846 ui::ET_GESTURE_BEGIN, 1847 ui::ET_GESTURE_TAP_DOWN); 1848 1849 // Move the touch-point enough so that it is considered as a scroll. This 1850 // should generate both SCROLL_BEGIN and SCROLL_UPDATE gestures. 1851 delegate->Reset(); 1852 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(130, 301), 1853 kTouchId1, tes.Now()); 1854 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 1855 EXPECT_3_EVENTS(delegate->events(), 1856 ui::ET_GESTURE_TAP_CANCEL, 1857 ui::ET_GESTURE_SCROLL_BEGIN, 1858 ui::ET_GESTURE_SCROLL_UPDATE); 1859 1860 // Press the second finger. It should cause pinch-begin. Note that we will not 1861 // transition to two finger tap here because the touch points are far enough. 1862 delegate->Reset(); 1863 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1864 kTouchId2, tes.Now()); 1865 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1866 EXPECT_2_EVENTS(delegate->events(), 1867 ui::ET_GESTURE_BEGIN, 1868 ui::ET_GESTURE_PINCH_BEGIN); 1869 EXPECT_EQ(gfx::Rect(10, 10, 120, 291).ToString(), 1870 delegate->bounding_box().ToString()); 1871 1872 // Move the first finger. 1873 delegate->Reset(); 1874 ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(95, 201), 1875 kTouchId1, tes.Now()); 1876 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 1877 EXPECT_2_EVENTS(delegate->events(), 1878 ui::ET_GESTURE_PINCH_UPDATE, 1879 ui::ET_GESTURE_SCROLL_UPDATE); 1880 EXPECT_EQ(gfx::Rect(10, 10, 85, 191).ToString(), 1881 delegate->bounding_box().ToString()); 1882 1883 // Now move the second finger. 1884 delegate->Reset(); 1885 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 1886 kTouchId2, tes.Now()); 1887 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 1888 EXPECT_2_EVENTS(delegate->events(), 1889 ui::ET_GESTURE_PINCH_UPDATE, 1890 ui::ET_GESTURE_SCROLL_UPDATE); 1891 EXPECT_EQ(gfx::Rect(55, 15, 40, 186).ToString(), 1892 delegate->bounding_box().ToString()); 1893 1894 // Release the first finger. This should end pinch. 1895 delegate->Reset(); 1896 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1897 kTouchId1, tes.Now()); 1898 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1899 EXPECT_2_EVENTS(delegate->events(), 1900 ui::ET_GESTURE_PINCH_END, 1901 ui::ET_GESTURE_END); 1902 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), 1903 delegate->bounding_box().ToString()); 1904 1905 // Move the second finger. This should still generate a scroll. 1906 delegate->Reset(); 1907 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 1908 kTouchId2, tes.Now()); 1909 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); 1910 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 1911 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1912 } 1913 1914 TEST_F(GestureRecognizerTest, GestureEventPinchFromScrollFromPinch) { 1915 scoped_ptr<GestureEventConsumeDelegate> delegate( 1916 new GestureEventConsumeDelegate()); 1917 TimedEvents tes; 1918 const int kWindowWidth = 300; 1919 const int kWindowHeight = 400; 1920 const int kTouchId1 = 5; 1921 const int kTouchId2 = 3; 1922 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1923 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1924 delegate.get(), -1234, bounds, root_window())); 1925 1926 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 1927 kTouchId1, tes.Now()); 1928 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1929 delegate->Reset(); 1930 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1931 kTouchId2, tes.Now()); 1932 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1933 // Since the touch points are far enough we will go to pinch rather than two 1934 // finger tap. 1935 EXPECT_TRUE(delegate->pinch_begin()); 1936 1937 tes.SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 1938 EXPECT_TRUE(delegate->pinch_update()); 1939 1940 // Pinch has started, now release the second finger 1941 delegate->Reset(); 1942 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 1943 kTouchId1, tes.Now()); 1944 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 1945 EXPECT_TRUE(delegate->pinch_end()); 1946 1947 tes.SendScrollEvent(root_window(), 130, 230, kTouchId2, delegate.get()); 1948 EXPECT_TRUE(delegate->scroll_update()); 1949 1950 // Pinch again 1951 delegate->Reset(); 1952 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1953 kTouchId1, tes.Now()); 1954 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 1955 // Now the touch points are close. So we will go into two finger tap. 1956 // Move the touch-point enough to break two-finger-tap and enter pinch. 1957 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 202), 1958 kTouchId1, tes.Now()); 1959 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 1960 EXPECT_TRUE(delegate->pinch_begin()); 1961 1962 tes.SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 1963 EXPECT_TRUE(delegate->pinch_update()); 1964 } 1965 1966 TEST_F(GestureRecognizerTest, GestureEventPinchFromTap) { 1967 scoped_ptr<GestureEventConsumeDelegate> delegate( 1968 new GestureEventConsumeDelegate()); 1969 TimedEvents tes; 1970 const int kWindowWidth = 300; 1971 const int kWindowHeight = 400; 1972 const int kTouchId1 = 3; 1973 const int kTouchId2 = 5; 1974 gfx::Rect bounds(5, 5, kWindowWidth, kWindowHeight); 1975 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 1976 delegate.get(), -1234, bounds, root_window())); 1977 1978 aura::RootWindow* root = root_window(); 1979 1980 delegate->Reset(); 1981 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 301), 1982 kTouchId1, tes.Now()); 1983 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1984 EXPECT_2_EVENTS(delegate->events(), 1985 ui::ET_GESTURE_BEGIN, 1986 ui::ET_GESTURE_TAP_DOWN); 1987 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 1988 1989 // Press the second finger far enough to break two finger tap. It should 1990 // instead cause a scroll-begin and pinch-begin. 1991 delegate->Reset(); 1992 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 1993 kTouchId2, tes.Now()); 1994 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 1995 EXPECT_4_EVENTS(delegate->events(), 1996 ui::ET_GESTURE_TAP_CANCEL, 1997 ui::ET_GESTURE_BEGIN, 1998 ui::ET_GESTURE_PINCH_BEGIN, 1999 ui::ET_GESTURE_SCROLL_BEGIN); 2000 EXPECT_EQ(gfx::Rect(10, 10, 91, 291).ToString(), 2001 delegate->bounding_box().ToString()); 2002 2003 // Move the first finger. 2004 delegate->Reset(); 2005 ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(65, 201), 2006 kTouchId1, tes.Now()); 2007 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 2008 EXPECT_2_EVENTS(delegate->events(), 2009 ui::ET_GESTURE_PINCH_UPDATE, 2010 ui::ET_GESTURE_SCROLL_UPDATE); 2011 EXPECT_EQ(gfx::Rect(10, 10, 55, 191).ToString(), 2012 delegate->bounding_box().ToString()); 2013 2014 // Now move the second finger. 2015 delegate->Reset(); 2016 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(55, 15), 2017 kTouchId2, tes.Now()); 2018 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 2019 EXPECT_2_EVENTS(delegate->events(), 2020 ui::ET_GESTURE_PINCH_UPDATE, 2021 ui::ET_GESTURE_SCROLL_UPDATE); 2022 EXPECT_EQ(gfx::Rect(55, 15, 10, 186).ToString(), 2023 delegate->bounding_box().ToString()); 2024 2025 // Release the first finger. This should end pinch. 2026 delegate->Reset(); 2027 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2028 kTouchId1, tes.LeapForward(10)); 2029 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2030 EXPECT_2_EVENTS(delegate->events(), 2031 ui::ET_GESTURE_PINCH_END, 2032 ui::ET_GESTURE_END); 2033 EXPECT_EQ(gfx::Rect(55, 15, 46, 186).ToString(), 2034 delegate->bounding_box().ToString()); 2035 2036 // Move the second finger. This should still generate a scroll. 2037 delegate->Reset(); 2038 ui::TouchEvent move5(ui::ET_TOUCH_MOVED, gfx::Point(25, 10), 2039 kTouchId2, tes.Now()); 2040 root->AsRootWindowHostDelegate()->OnHostTouchEvent(&move5); 2041 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); 2042 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 2043 } 2044 2045 TEST_F(GestureRecognizerTest, GestureEventIgnoresDisconnectedEvents) { 2046 scoped_ptr<GestureEventConsumeDelegate> delegate( 2047 new GestureEventConsumeDelegate()); 2048 TimedEvents tes; 2049 2050 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2051 6, tes.Now()); 2052 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2053 EXPECT_FALSE(delegate->tap()); 2054 EXPECT_FALSE(delegate->tap_down()); 2055 } 2056 2057 // Check that a touch is locked to the window of the closest current touch 2058 // within max_separation_for_gesture_touches_in_pixels 2059 TEST_F(GestureRecognizerTest, GestureEventTouchLockSelectsCorrectWindow) { 2060 ui::GestureRecognizer* gesture_recognizer = 2061 new ui::GestureRecognizerImpl(root_window()); 2062 TimedEvents tes; 2063 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2064 2065 ui::GestureConsumer* target; 2066 const int kNumWindows = 4; 2067 2068 scoped_ptr<GestureEventConsumeDelegate*[]> delegates( 2069 new GestureEventConsumeDelegate*[kNumWindows]); 2070 2071 ui::GestureConfiguration:: 2072 set_max_separation_for_gesture_touches_in_pixels(499); 2073 2074 scoped_ptr<gfx::Rect[]> window_bounds(new gfx::Rect[kNumWindows]); 2075 window_bounds[0] = gfx::Rect(0, 0, 1, 1); 2076 window_bounds[1] = gfx::Rect(500, 0, 1, 1); 2077 window_bounds[2] = gfx::Rect(0, 500, 1, 1); 2078 window_bounds[3] = gfx::Rect(500, 500, 1, 1); 2079 2080 scoped_ptr<aura::Window*[]> windows(new aura::Window*[kNumWindows]); 2081 2082 // Instantiate windows with |window_bounds| and touch each window at 2083 // its origin. 2084 for (int i = 0; i < kNumWindows; ++i) { 2085 delegates[i] = new GestureEventConsumeDelegate(); 2086 windows[i] = CreateTestWindowWithDelegate( 2087 delegates[i], i, window_bounds[i], root_window()); 2088 windows[i]->set_id(i); 2089 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, window_bounds[i].origin(), 2090 i, tes.Now()); 2091 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2092 } 2093 2094 // Touches should now be associated with the closest touch within 2095 // ui::GestureConfiguration::max_separation_for_gesture_touches_in_pixels 2096 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 11)); 2097 EXPECT_EQ("0", WindowIDAsString(target)); 2098 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 11)); 2099 EXPECT_EQ("1", WindowIDAsString(target)); 2100 target = gesture_recognizer->GetTargetForLocation(gfx::Point(11, 511)); 2101 EXPECT_EQ("2", WindowIDAsString(target)); 2102 target = gesture_recognizer->GetTargetForLocation(gfx::Point(511, 511)); 2103 EXPECT_EQ("3", WindowIDAsString(target)); 2104 2105 // Add a touch in the middle associated with windows[2] 2106 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(0, 500), 2107 kNumWindows, tes.Now()); 2108 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2109 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(250, 250), 2110 kNumWindows, tes.Now()); 2111 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 2112 2113 target = gesture_recognizer->GetTargetForLocation(gfx::Point(250, 250)); 2114 EXPECT_EQ("2", WindowIDAsString(target)); 2115 2116 // Make sure that ties are broken by distance to a current touch 2117 // Closer to the point in the bottom right. 2118 target = gesture_recognizer->GetTargetForLocation(gfx::Point(380, 380)); 2119 EXPECT_EQ("3", WindowIDAsString(target)); 2120 2121 // This touch is closer to the point in the middle 2122 target = gesture_recognizer->GetTargetForLocation(gfx::Point(300, 300)); 2123 EXPECT_EQ("2", WindowIDAsString(target)); 2124 2125 // A touch too far from other touches won't be locked to anything 2126 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 2127 EXPECT_TRUE(target == NULL); 2128 2129 // Move a touch associated with windows[2] to 1000, 1000 2130 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(1000, 1000), 2131 kNumWindows, tes.Now()); 2132 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2133 2134 target = gesture_recognizer->GetTargetForLocation(gfx::Point(1000, 1000)); 2135 EXPECT_EQ("2", WindowIDAsString(target)); 2136 2137 for (int i = 0; i < kNumWindows; ++i) { 2138 // Delete windows before deleting delegates. 2139 delete windows[i]; 2140 delete delegates[i]; 2141 } 2142 } 2143 2144 // Check that touch events outside the root window are still handled 2145 // by the root window's gesture sequence. 2146 TEST_F(GestureRecognizerTest, GestureEventOutsideRootWindowTap) { 2147 TestGestureRecognizer* gesture_recognizer = 2148 new TestGestureRecognizer(root_window()); 2149 TimedEvents tes; 2150 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2151 2152 scoped_ptr<aura::Window> window(CreateTestWindowWithBounds( 2153 gfx::Rect(-100, -100, 2000, 2000), root_window())); 2154 2155 ui::GestureSequence* window_gesture_sequence = 2156 gesture_recognizer->GetGestureSequenceForTesting(window.get()); 2157 2158 ui::GestureSequence* root_window_gesture_sequence = 2159 gesture_recognizer->GetGestureSequenceForTesting(root_window()); 2160 2161 gfx::Point pos1(-10, -10); 2162 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, pos1, 0, tes.Now()); 2163 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2164 2165 gfx::Point pos2(1000, 1000); 2166 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, pos2, 1, tes.Now()); 2167 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2168 2169 // As these presses were outside the root window, they should be 2170 // associated with the root window. 2171 EXPECT_EQ(0, window_gesture_sequence->point_count()); 2172 EXPECT_EQ(2, root_window_gesture_sequence->point_count()); 2173 } 2174 2175 TEST_F(GestureRecognizerTest, NoTapWithPreventDefaultedRelease) { 2176 scoped_ptr<QueueTouchEventDelegate> delegate( 2177 new QueueTouchEventDelegate(root_window())); 2178 TimedEvents tes; 2179 const int kTouchId = 2; 2180 gfx::Rect bounds(100, 200, 100, 100); 2181 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2182 delegate.get(), -1234, bounds, root_window())); 2183 delegate->set_window(window.get()); 2184 2185 delegate->Reset(); 2186 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2187 kTouchId, tes.Now()); 2188 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2189 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2190 kTouchId, tes.LeapForward(50)); 2191 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2192 2193 delegate->Reset(); 2194 delegate->ReceivedAck(); 2195 EXPECT_TRUE(delegate->tap_down()); 2196 delegate->Reset(); 2197 delegate->ReceivedAckPreventDefaulted(); 2198 EXPECT_FALSE(delegate->tap()); 2199 EXPECT_TRUE(delegate->tap_cancel()); 2200 } 2201 2202 TEST_F(GestureRecognizerTest, PinchScrollWithPreventDefaultedRelease) { 2203 scoped_ptr<QueueTouchEventDelegate> delegate( 2204 new QueueTouchEventDelegate(root_window())); 2205 TimedEvents tes; 2206 const int kTouchId1 = 7; 2207 const int kTouchId2 = 5; 2208 gfx::Rect bounds(10, 20, 100, 100); 2209 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2210 delegate.get(), -1234, bounds, root_window())); 2211 delegate->set_window(window.get()); 2212 2213 { 2214 delegate->Reset(); 2215 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(15, 25), kTouchId1, 2216 tes.Now()); 2217 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(20, 95), kTouchId1, 2218 tes.LeapForward(200)); 2219 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(15, 25), kTouchId1, 2220 tes.LeapForward(50)); 2221 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2222 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 2223 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2224 delegate->Reset(); 2225 2226 // Ack the press event. 2227 delegate->ReceivedAck(); 2228 EXPECT_TRUE(delegate->tap_down()); 2229 delegate->Reset(); 2230 2231 // Ack the move event. 2232 delegate->ReceivedAck(); 2233 EXPECT_TRUE(delegate->tap_cancel()); 2234 EXPECT_TRUE(delegate->scroll_begin()); 2235 delegate->Reset(); 2236 2237 // Ack the release event. Although the release event has been processed, it 2238 // should still generate a scroll-end event. 2239 delegate->ReceivedAckPreventDefaulted(); 2240 EXPECT_TRUE(delegate->scroll_end()); 2241 } 2242 2243 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(15, 25), kTouchId1, 2244 tes.Now()); 2245 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(20, 95), kTouchId1, 2246 tes.LeapForward(200)); 2247 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(15, 25), kTouchId1, 2248 tes.LeapForward(50)); 2249 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 25), kTouchId2, 2250 tes.Now()); 2251 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(45, 85), kTouchId2, 2252 tes.LeapForward(1000)); 2253 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(45, 85), kTouchId2, 2254 tes.LeapForward(14)); 2255 2256 // Do a pinch. 2257 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2258 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move); 2259 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2260 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2261 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2262 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2263 2264 // Ack the press and move events. 2265 delegate->Reset(); 2266 delegate->ReceivedAck(); 2267 EXPECT_TRUE(delegate->begin()); 2268 EXPECT_TRUE(delegate->tap_down()); 2269 2270 delegate->Reset(); 2271 delegate->ReceivedAck(); 2272 EXPECT_TRUE(delegate->scroll_begin()); 2273 2274 delegate->Reset(); 2275 delegate->ReceivedAck(); 2276 EXPECT_TRUE(delegate->begin()); 2277 EXPECT_TRUE(delegate->pinch_begin()); 2278 2279 delegate->Reset(); 2280 delegate->ReceivedAck(); 2281 EXPECT_TRUE(delegate->pinch_update()); 2282 2283 // Ack the first release. Although the release is processed, it should still 2284 // generate a pinch-end event. 2285 delegate->Reset(); 2286 delegate->ReceivedAckPreventDefaulted(); 2287 EXPECT_TRUE(delegate->pinch_end()); 2288 EXPECT_TRUE(delegate->end()); 2289 2290 delegate->Reset(); 2291 delegate->ReceivedAckPreventDefaulted(); 2292 EXPECT_TRUE(delegate->scroll_end()); 2293 EXPECT_TRUE(delegate->end()); 2294 } 2295 2296 TEST_F(GestureRecognizerTest, CaptureSendsGestureEnd) { 2297 scoped_ptr<GestureEventConsumeDelegate> delegate( 2298 new GestureEventConsumeDelegate()); 2299 TestGestureRecognizer* gesture_recognizer = 2300 new TestGestureRecognizer(root_window()); 2301 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2302 2303 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2304 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2305 EventGenerator generator(root_window()); 2306 2307 generator.MoveMouseRelativeTo(window.get(), gfx::Point(10, 10)); 2308 generator.PressTouch(); 2309 RunAllPendingInMessageLoop(); 2310 2311 EXPECT_TRUE(delegate->tap_down()); 2312 2313 scoped_ptr<aura::Window> capture(CreateTestWindowWithBounds( 2314 gfx::Rect(10, 10, 200, 200), root_window())); 2315 capture->SetCapture(); 2316 RunAllPendingInMessageLoop(); 2317 2318 EXPECT_TRUE(delegate->end()); 2319 EXPECT_TRUE(delegate->tap_cancel()); 2320 } 2321 2322 // Check that previous touch actions that are completely finished (either 2323 // released or cancelled), do not receive extra synthetic cancels upon change of 2324 // capture. 2325 TEST_F(GestureRecognizerTest, CaptureDoesNotCancelFinishedTouches) { 2326 scoped_ptr<TestEventHandler> handler(new TestEventHandler); 2327 root_window()->AddPreTargetHandler(handler.get()); 2328 2329 // Create a window and set it as the capture window. 2330 scoped_ptr<aura::Window> window1(CreateTestWindowWithBounds( 2331 gfx::Rect(10, 10, 300, 300), root_window())); 2332 window1->SetCapture(); 2333 2334 EventGenerator generator(root_window()); 2335 TimedEvents tes; 2336 2337 // Generate two touch-press events on the window. 2338 scoped_ptr<ui::TouchEvent> touch0(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, 2339 gfx::Point(20, 20), 0, 2340 tes.Now())); 2341 scoped_ptr<ui::TouchEvent> touch1(new ui::TouchEvent(ui::ET_TOUCH_PRESSED, 2342 gfx::Point(30, 30), 1, 2343 tes.Now())); 2344 generator.Dispatch(touch0.get()); 2345 generator.Dispatch(touch1.get()); 2346 RunAllPendingInMessageLoop(); 2347 EXPECT_EQ(2, handler->touch_pressed_count()); 2348 2349 // Advance time. 2350 tes.LeapForward(1000); 2351 2352 // End the two touches, one by a touch-release and one by a touch-cancel; to 2353 // cover both cases. 2354 touch0.reset(new ui::TouchEvent(ui::ET_TOUCH_RELEASED, gfx::Point(20, 20), 0, 2355 tes.Now())); 2356 touch1.reset(new ui::TouchEvent(ui::ET_TOUCH_CANCELLED, gfx::Point(30, 30), 1, 2357 tes.Now())); 2358 generator.Dispatch(touch0.get()); 2359 generator.Dispatch(touch1.get()); 2360 RunAllPendingInMessageLoop(); 2361 EXPECT_EQ(1, handler->touch_released_count()); 2362 EXPECT_EQ(1, handler->touch_cancelled_count()); 2363 2364 // Create a new window and set it as the new capture window. 2365 scoped_ptr<aura::Window> window2(CreateTestWindowWithBounds( 2366 gfx::Rect(100, 100, 300, 300), root_window())); 2367 window2->SetCapture(); 2368 RunAllPendingInMessageLoop(); 2369 // Check that setting capture does not generate any synthetic touch-cancels 2370 // for the two previously finished touch actions. 2371 EXPECT_EQ(1, handler->touch_cancelled_count()); 2372 2373 root_window()->RemovePreTargetHandler(handler.get()); 2374 } 2375 2376 TEST_F(GestureRecognizerTest, PressDoesNotCrash) { 2377 scoped_ptr<GestureEventConsumeDelegate> delegate( 2378 new GestureEventConsumeDelegate()); 2379 TestGestureRecognizer* gesture_recognizer = 2380 new TestGestureRecognizer(root_window()); 2381 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2382 TimedEvents tes; 2383 2384 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2385 delegate.get(), -1234, gfx::Rect(10, 10, 300, 300), root_window())); 2386 2387 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(45, 45), 7, tes.Now()); 2388 press.set_radius_x(40); 2389 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2390 EXPECT_TRUE(delegate->tap_down()); 2391 EXPECT_EQ(gfx::Rect(5, 5, 80, 80).ToString(), 2392 delegate->bounding_box().ToString()); 2393 delegate->Reset(); 2394 2395 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(55, 45), 7, tes.Now()); 2396 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2397 2398 // This new press should not generate a tap-down. 2399 EXPECT_FALSE(delegate->begin()); 2400 EXPECT_FALSE(delegate->tap_down()); 2401 EXPECT_FALSE(delegate->tap_cancel()); 2402 EXPECT_FALSE(delegate->scroll_begin()); 2403 } 2404 2405 TEST_F(GestureRecognizerTest, TwoFingerTap) { 2406 scoped_ptr<GestureEventConsumeDelegate> delegate( 2407 new GestureEventConsumeDelegate()); 2408 const int kWindowWidth = 123; 2409 const int kWindowHeight = 45; 2410 const int kTouchId1 = 2; 2411 const int kTouchId2 = 3; 2412 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2413 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2414 delegate.get(), -1234, bounds, root_window())); 2415 TimedEvents tes; 2416 2417 delegate->Reset(); 2418 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2419 kTouchId1, tes.Now()); 2420 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2421 EXPECT_FALSE(delegate->tap()); 2422 EXPECT_TRUE(delegate->tap_down()); 2423 EXPECT_FALSE(delegate->tap_cancel()); 2424 EXPECT_FALSE(delegate->scroll_begin()); 2425 EXPECT_FALSE(delegate->scroll_update()); 2426 EXPECT_FALSE(delegate->scroll_end()); 2427 EXPECT_FALSE(delegate->long_press()); 2428 EXPECT_FALSE(delegate->two_finger_tap()); 2429 2430 delegate->Reset(); 2431 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2432 kTouchId2, tes.Now()); 2433 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2434 EXPECT_FALSE(delegate->tap()); 2435 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 2436 EXPECT_TRUE(delegate->tap_cancel()); 2437 EXPECT_FALSE(delegate->scroll_begin()); 2438 EXPECT_FALSE(delegate->scroll_update()); 2439 EXPECT_FALSE(delegate->scroll_end()); 2440 EXPECT_FALSE(delegate->long_press()); 2441 EXPECT_FALSE(delegate->two_finger_tap()); 2442 2443 // Little bit of touch move should not affect our state. 2444 delegate->Reset(); 2445 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(102, 202), 2446 kTouchId1, tes.Now()); 2447 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 2448 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(131, 202), 2449 kTouchId2, tes.Now()); 2450 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 2451 EXPECT_FALSE(delegate->tap()); 2452 EXPECT_FALSE(delegate->tap_down()); 2453 EXPECT_FALSE(delegate->tap_cancel()); 2454 EXPECT_FALSE(delegate->scroll_begin()); 2455 EXPECT_FALSE(delegate->scroll_update()); 2456 EXPECT_FALSE(delegate->scroll_end()); 2457 EXPECT_FALSE(delegate->long_press()); 2458 EXPECT_FALSE(delegate->two_finger_tap()); 2459 2460 // Make sure there is enough delay before the touch is released so that it is 2461 // recognized as a tap. 2462 delegate->Reset(); 2463 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2464 kTouchId1, tes.LeapForward(50)); 2465 2466 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2467 EXPECT_FALSE(delegate->tap()); 2468 EXPECT_FALSE(delegate->tap_down()); 2469 EXPECT_FALSE(delegate->tap_cancel()); 2470 EXPECT_FALSE(delegate->scroll_begin()); 2471 EXPECT_FALSE(delegate->scroll_update()); 2472 EXPECT_FALSE(delegate->scroll_end()); 2473 EXPECT_TRUE(delegate->two_finger_tap()); 2474 2475 // Lift second finger. 2476 // Make sure there is enough delay before the touch is released so that it is 2477 // recognized as a tap. 2478 delegate->Reset(); 2479 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2480 kTouchId2, tes.LeapForward(50)); 2481 2482 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2483 EXPECT_FALSE(delegate->tap()); 2484 EXPECT_FALSE(delegate->tap_down()); 2485 EXPECT_FALSE(delegate->tap_cancel()); 2486 EXPECT_FALSE(delegate->scroll_begin()); 2487 EXPECT_FALSE(delegate->scroll_update()); 2488 EXPECT_FALSE(delegate->scroll_end()); 2489 EXPECT_TRUE(delegate->fling()); 2490 EXPECT_FALSE(delegate->two_finger_tap()); 2491 } 2492 2493 TEST_F(GestureRecognizerTest, TwoFingerTapExpired) { 2494 scoped_ptr<GestureEventConsumeDelegate> delegate( 2495 new GestureEventConsumeDelegate()); 2496 const int kWindowWidth = 123; 2497 const int kWindowHeight = 45; 2498 const int kTouchId1 = 2; 2499 const int kTouchId2 = 3; 2500 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2501 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2502 delegate.get(), -1234, bounds, root_window())); 2503 TimedEvents tes; 2504 2505 delegate->Reset(); 2506 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2507 kTouchId1, tes.Now()); 2508 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2509 2510 delegate->Reset(); 2511 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2512 kTouchId2, tes.Now()); 2513 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2514 2515 // Send release event after sufficient delay so that two finger time expires. 2516 delegate->Reset(); 2517 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2518 kTouchId1, tes.LeapForward(1000)); 2519 2520 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 2521 EXPECT_FALSE(delegate->two_finger_tap()); 2522 2523 // Lift second finger. 2524 // Make sure there is enough delay before the touch is released so that it is 2525 // recognized as a tap. 2526 delegate->Reset(); 2527 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 2528 kTouchId2, tes.LeapForward(50)); 2529 2530 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 2531 EXPECT_FALSE(delegate->two_finger_tap()); 2532 } 2533 2534 TEST_F(GestureRecognizerTest, TwoFingerTapChangesToPinch) { 2535 scoped_ptr<GestureEventConsumeDelegate> delegate( 2536 new GestureEventConsumeDelegate()); 2537 const int kWindowWidth = 123; 2538 const int kWindowHeight = 45; 2539 const int kTouchId1 = 2; 2540 const int kTouchId2 = 3; 2541 TimedEvents tes; 2542 2543 // Test moving first finger 2544 { 2545 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2546 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2547 delegate.get(), -1234, bounds, root_window())); 2548 2549 delegate->Reset(); 2550 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2551 kTouchId1, tes.Now()); 2552 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2553 2554 delegate->Reset(); 2555 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2556 kTouchId2, tes.Now()); 2557 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2558 2559 tes.SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 2560 EXPECT_FALSE(delegate->two_finger_tap()); 2561 EXPECT_TRUE(delegate->pinch_begin()); 2562 2563 // Make sure there is enough delay before the touch is released so that it 2564 // is recognized as a tap. 2565 delegate->Reset(); 2566 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2567 kTouchId2, tes.LeapForward(50)); 2568 2569 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2570 EXPECT_FALSE(delegate->two_finger_tap()); 2571 EXPECT_TRUE(delegate->pinch_end()); 2572 } 2573 2574 // Test moving second finger 2575 { 2576 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2577 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2578 delegate.get(), -1234, bounds, root_window())); 2579 2580 delegate->Reset(); 2581 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2582 kTouchId1, tes.Now()); 2583 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2584 2585 delegate->Reset(); 2586 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2587 kTouchId2, tes.Now()); 2588 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2589 2590 tes.SendScrollEvent(root_window(), 101, 230, kTouchId2, delegate.get()); 2591 EXPECT_FALSE(delegate->two_finger_tap()); 2592 EXPECT_TRUE(delegate->pinch_begin()); 2593 2594 // Make sure there is enough delay before the touch is released so that it 2595 // is recognized as a tap. 2596 delegate->Reset(); 2597 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2598 kTouchId1, tes.LeapForward(50)); 2599 2600 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2601 EXPECT_FALSE(delegate->two_finger_tap()); 2602 EXPECT_TRUE(delegate->pinch_end()); 2603 } 2604 } 2605 2606 TEST_F(GestureRecognizerTest, NoTwoFingerTapWhenFirstFingerHasScrolled) { 2607 scoped_ptr<GestureEventConsumeDelegate> delegate( 2608 new GestureEventConsumeDelegate()); 2609 const int kWindowWidth = 123; 2610 const int kWindowHeight = 45; 2611 const int kTouchId1 = 2; 2612 const int kTouchId2 = 3; 2613 TimedEvents tes; 2614 2615 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2616 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2617 delegate.get(), -1234, bounds, root_window())); 2618 2619 delegate->Reset(); 2620 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2621 kTouchId1, tes.Now()); 2622 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2623 tes.SendScrollEvent(root_window(), 130, 230, kTouchId1, delegate.get()); 2624 2625 delegate->Reset(); 2626 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2627 kTouchId2, tes.Now()); 2628 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2629 2630 EXPECT_TRUE(delegate->pinch_begin()); 2631 2632 // Make sure there is enough delay before the touch is released so that it 2633 // is recognized as a tap. 2634 delegate->Reset(); 2635 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2636 kTouchId2, tes.LeapForward(50)); 2637 2638 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2639 EXPECT_FALSE(delegate->two_finger_tap()); 2640 EXPECT_TRUE(delegate->pinch_end()); 2641 } 2642 2643 TEST_F(GestureRecognizerTest, MultiFingerSwipe) { 2644 scoped_ptr<GestureEventConsumeDelegate> delegate( 2645 new GestureEventConsumeDelegate()); 2646 const int kWindowWidth = 123; 2647 const int kWindowHeight = 45; 2648 2649 gfx::Rect bounds(5, 10, kWindowWidth, kWindowHeight); 2650 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2651 delegate.get(), -1234, bounds, root_window())); 2652 2653 const int kSteps = 15; 2654 const int kTouchPoints = 4; 2655 gfx::Point points[kTouchPoints] = { 2656 gfx::Point(10, 30), 2657 gfx::Point(30, 20), 2658 gfx::Point(50, 30), 2659 gfx::Point(80, 50) 2660 }; 2661 2662 aura::test::EventGenerator generator(root_window(), window.get()); 2663 2664 for (int count = 2; count <= kTouchPoints; ++count) { 2665 generator.GestureMultiFingerScroll(count, points, 15, kSteps, 0, -150); 2666 EXPECT_TRUE(delegate->swipe_up()); 2667 delegate->Reset(); 2668 2669 generator.GestureMultiFingerScroll(count, points, 15, kSteps, 0, 150); 2670 EXPECT_TRUE(delegate->swipe_down()); 2671 delegate->Reset(); 2672 2673 generator.GestureMultiFingerScroll(count, points, 15, kSteps, -150, 0); 2674 EXPECT_TRUE(delegate->swipe_left()); 2675 delegate->Reset(); 2676 2677 generator.GestureMultiFingerScroll(count, points, 15, kSteps, 150, 0); 2678 EXPECT_TRUE(delegate->swipe_right()); 2679 delegate->Reset(); 2680 } 2681 } 2682 2683 TEST_F(GestureRecognizerTest, TwoFingerTapCancelled) { 2684 scoped_ptr<GestureEventConsumeDelegate> delegate( 2685 new GestureEventConsumeDelegate()); 2686 const int kWindowWidth = 123; 2687 const int kWindowHeight = 45; 2688 const int kTouchId1 = 2; 2689 const int kTouchId2 = 3; 2690 TimedEvents tes; 2691 2692 // Test canceling first finger. 2693 { 2694 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2695 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2696 delegate.get(), -1234, bounds, root_window())); 2697 2698 delegate->Reset(); 2699 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2700 kTouchId1, tes.Now()); 2701 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2702 2703 delegate->Reset(); 2704 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2705 kTouchId2, tes.Now()); 2706 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2707 2708 delegate->Reset(); 2709 ui::TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), 2710 kTouchId1, tes.Now()); 2711 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); 2712 EXPECT_FALSE(delegate->two_finger_tap()); 2713 2714 // Make sure there is enough delay before the touch is released so that it 2715 // is recognized as a tap. 2716 delegate->Reset(); 2717 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2718 kTouchId2, tes.LeapForward(50)); 2719 2720 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2721 EXPECT_FALSE(delegate->two_finger_tap()); 2722 } 2723 2724 // Test canceling second finger 2725 { 2726 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2727 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2728 delegate.get(), -1234, bounds, root_window())); 2729 2730 delegate->Reset(); 2731 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2732 kTouchId1, tes.Now()); 2733 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2734 2735 delegate->Reset(); 2736 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2737 kTouchId2, tes.Now()); 2738 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2739 2740 delegate->Reset(); 2741 ui::TouchEvent cancel(ui::ET_TOUCH_CANCELLED, gfx::Point(130, 201), 2742 kTouchId2, tes.Now()); 2743 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&cancel); 2744 EXPECT_FALSE(delegate->two_finger_tap()); 2745 2746 // Make sure there is enough delay before the touch is released so that it 2747 // is recognized as a tap. 2748 delegate->Reset(); 2749 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 2750 kTouchId1, tes.LeapForward(50)); 2751 2752 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2753 EXPECT_FALSE(delegate->two_finger_tap()); 2754 } 2755 } 2756 2757 TEST_F(GestureRecognizerTest, VeryWideTwoFingerTouchDownShouldBeAPinch) { 2758 scoped_ptr<GestureEventConsumeDelegate> delegate( 2759 new GestureEventConsumeDelegate()); 2760 const int kWindowWidth = 523; 2761 const int kWindowHeight = 45; 2762 const int kTouchId1 = 2; 2763 const int kTouchId2 = 3; 2764 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2765 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2766 delegate.get(), -1234, bounds, root_window())); 2767 TimedEvents tes; 2768 2769 delegate->Reset(); 2770 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2771 kTouchId1, tes.Now()); 2772 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2773 EXPECT_FALSE(delegate->tap()); 2774 EXPECT_TRUE(delegate->tap_down()); 2775 EXPECT_FALSE(delegate->tap_cancel()); 2776 EXPECT_FALSE(delegate->scroll_begin()); 2777 EXPECT_FALSE(delegate->scroll_update()); 2778 EXPECT_FALSE(delegate->scroll_end()); 2779 EXPECT_FALSE(delegate->long_press()); 2780 EXPECT_FALSE(delegate->two_finger_tap()); 2781 2782 delegate->Reset(); 2783 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(430, 201), 2784 kTouchId2, tes.Now()); 2785 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2786 EXPECT_FALSE(delegate->tap()); 2787 EXPECT_FALSE(delegate->tap_down()); // no touch down for second tap. 2788 EXPECT_TRUE(delegate->tap_cancel()); 2789 EXPECT_TRUE(delegate->scroll_begin()); 2790 EXPECT_FALSE(delegate->scroll_update()); 2791 EXPECT_FALSE(delegate->scroll_end()); 2792 EXPECT_FALSE(delegate->long_press()); 2793 EXPECT_FALSE(delegate->two_finger_tap()); 2794 EXPECT_TRUE(delegate->pinch_begin()); 2795 } 2796 2797 // Verifies if a window is the target of multiple touch-ids and we hide the 2798 // window everything is cleaned up correctly. 2799 TEST_F(GestureRecognizerTest, FlushAllOnHide) { 2800 scoped_ptr<GestureEventConsumeDelegate> delegate( 2801 new GestureEventConsumeDelegate()); 2802 gfx::Rect bounds(0, 0, 200, 200); 2803 scoped_ptr<aura::Window> window( 2804 CreateTestWindowWithDelegate(delegate.get(), 0, bounds, root_window())); 2805 const int kTouchId1 = 8; 2806 const int kTouchId2 = 2; 2807 TimedEvents tes; 2808 2809 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(10, 10), 2810 kTouchId1, tes.Now()); 2811 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2812 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(20, 20), 2813 kTouchId2, tes.Now()); 2814 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2815 window->Hide(); 2816 EXPECT_EQ(NULL, 2817 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press1)); 2818 EXPECT_EQ(NULL, 2819 root_window()->gesture_recognizer()->GetTouchLockedTarget(&press2)); 2820 } 2821 2822 TEST_F(GestureRecognizerTest, LongPressTimerStopsOnPreventDefaultedTouchMoves) { 2823 scoped_ptr<QueueTouchEventDelegate> delegate( 2824 new QueueTouchEventDelegate(root_window())); 2825 const int kTouchId = 2; 2826 gfx::Rect bounds(100, 200, 100, 100); 2827 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2828 delegate.get(), -1234, bounds, root_window())); 2829 delegate->set_window(window.get()); 2830 TimedEvents tes; 2831 2832 TimerTestGestureRecognizer* gesture_recognizer = 2833 new TimerTestGestureRecognizer(root_window()); 2834 TimerTestGestureSequence* gesture_sequence = 2835 static_cast<TimerTestGestureSequence*>( 2836 gesture_recognizer->GetGestureSequenceForTesting(window.get())); 2837 2838 root_window()->SetGestureRecognizerForTesting(gesture_recognizer); 2839 2840 delegate->Reset(); 2841 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2842 kTouchId, tes.Now()); 2843 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2844 // Scroll around, to cancel the long press 2845 tes.SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 2846 2847 delegate->Reset(); 2848 delegate->ReceivedAck(); 2849 EXPECT_TRUE(delegate->tap_down()); 2850 EXPECT_TRUE(gesture_sequence->IsTimerRunning()); 2851 2852 delegate->Reset(); 2853 delegate->ReceivedAckPreventDefaulted(); 2854 EXPECT_FALSE(gesture_sequence->IsTimerRunning()); 2855 gesture_sequence->ForceTimeout(); 2856 EXPECT_FALSE(delegate->long_press()); 2857 } 2858 2859 // Same as GestureEventConsumeDelegate, but consumes all the touch-move events. 2860 class ConsumesTouchMovesDelegate : public GestureEventConsumeDelegate { 2861 public: 2862 ConsumesTouchMovesDelegate() : consume_touch_move_(true) {} 2863 virtual ~ConsumesTouchMovesDelegate() {} 2864 2865 void set_consume_touch_move(bool consume) { consume_touch_move_ = consume; } 2866 2867 private: 2868 virtual void OnTouchEvent(ui::TouchEvent* touch) OVERRIDE { 2869 if (consume_touch_move_ && touch->type() == ui::ET_TOUCH_MOVED) 2870 touch->SetHandled(); 2871 else 2872 GestureEventConsumeDelegate::OnTouchEvent(touch); 2873 } 2874 2875 bool consume_touch_move_; 2876 2877 DISALLOW_COPY_AND_ASSIGN(ConsumesTouchMovesDelegate); 2878 }; 2879 2880 // Same as GestureEventScroll, but tests that the behavior is the same 2881 // even if all the touch-move events are consumed. 2882 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMoveConsumed) { 2883 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 2884 new ConsumesTouchMovesDelegate()); 2885 const int kWindowWidth = 123; 2886 const int kWindowHeight = 45; 2887 const int kTouchId = 5; 2888 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2889 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2890 delegate.get(), -1234, bounds, root_window())); 2891 TimedEvents tes; 2892 2893 delegate->Reset(); 2894 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2895 kTouchId, tes.Now()); 2896 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 2897 EXPECT_FALSE(delegate->tap()); 2898 EXPECT_TRUE(delegate->tap_down()); 2899 EXPECT_FALSE(delegate->tap_cancel()); 2900 EXPECT_TRUE(delegate->begin()); 2901 EXPECT_FALSE(delegate->scroll_begin()); 2902 EXPECT_FALSE(delegate->scroll_update()); 2903 EXPECT_FALSE(delegate->scroll_end()); 2904 2905 // Move the touch-point enough so that it would normally be considered a 2906 // scroll. But since the touch-moves will be consumed, the scroll should not 2907 // start. 2908 tes.SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 2909 EXPECT_FALSE(delegate->tap()); 2910 EXPECT_FALSE(delegate->tap_down()); 2911 // TODO(rbyers): Really we should get the TapCancel here instead of below, 2912 // but this is a symptom of a larger issue: crbug.com/146397. 2913 EXPECT_FALSE(delegate->tap_cancel()); 2914 EXPECT_FALSE(delegate->begin()); 2915 EXPECT_FALSE(delegate->scroll_begin()); 2916 EXPECT_FALSE(delegate->scroll_update()); 2917 EXPECT_FALSE(delegate->scroll_end()); 2918 2919 // Release the touch back at the start point. This should end without causing 2920 // a tap. 2921 delegate->Reset(); 2922 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(130, 230), 2923 kTouchId, tes.LeapForward(50)); 2924 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 2925 EXPECT_FALSE(delegate->tap()); 2926 EXPECT_FALSE(delegate->tap_down()); 2927 EXPECT_TRUE(delegate->tap_cancel()); 2928 EXPECT_FALSE(delegate->begin()); 2929 EXPECT_TRUE(delegate->end()); 2930 EXPECT_FALSE(delegate->scroll_begin()); 2931 EXPECT_FALSE(delegate->scroll_update()); 2932 EXPECT_FALSE(delegate->scroll_end()); 2933 } 2934 2935 // Tests the behavior of 2F scroll when all the touch-move events are consumed. 2936 TEST_F(GestureRecognizerTest, GestureEventScrollTwoFingerTouchMoveConsumed) { 2937 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 2938 new ConsumesTouchMovesDelegate()); 2939 const int kWindowWidth = 123; 2940 const int kWindowHeight = 100; 2941 const int kTouchId1 = 2; 2942 const int kTouchId2 = 3; 2943 TimedEvents tes; 2944 2945 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 2946 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 2947 delegate.get(), -1234, bounds, root_window())); 2948 2949 delegate->Reset(); 2950 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 2951 kTouchId1, tes.Now()); 2952 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 2953 tes.SendScrollEvent(root_window(), 131, 231, kTouchId1, delegate.get()); 2954 2955 // First finger touches down and moves. 2956 EXPECT_FALSE(delegate->tap()); 2957 EXPECT_FALSE(delegate->scroll_begin()); 2958 EXPECT_FALSE(delegate->scroll_update()); 2959 EXPECT_FALSE(delegate->scroll_end()); 2960 2961 delegate->Reset(); 2962 // Second finger touches down and moves. 2963 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(130, 201), 2964 kTouchId2, tes.LeapForward(50)); 2965 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 2966 tes.SendScrollEvent(root_window(), 161, 231, kTouchId2, delegate.get()); 2967 2968 // PinchBegin & ScrollBegin were sent even though the touch-move events 2969 // were consumed. This seems reasonable, as long as we don't send PinchUpdate 2970 // ScrollUpdate when touch-move are consumed. 2971 EXPECT_TRUE(delegate->pinch_begin()); 2972 EXPECT_TRUE(delegate->scroll_begin()); 2973 2974 EXPECT_FALSE(delegate->tap()); 2975 EXPECT_FALSE(delegate->two_finger_tap()); 2976 2977 // Should be no PinchUpdate & ScrollUpdate. 2978 EXPECT_FALSE(delegate->pinch_update()); 2979 EXPECT_FALSE(delegate->pinch_end()); 2980 EXPECT_FALSE(delegate->scroll_update()); 2981 EXPECT_FALSE(delegate->scroll_end()); 2982 2983 delegate->Reset(); 2984 // Moves First finger again, no PinchUpdate & ScrollUpdate. 2985 tes.SendScrollEvent(root_window(), 161, 261, kTouchId1, delegate.get()); 2986 2987 EXPECT_FALSE(delegate->pinch_update()); 2988 EXPECT_FALSE(delegate->pinch_end()); 2989 EXPECT_FALSE(delegate->scroll_update()); 2990 EXPECT_FALSE(delegate->scroll_end()); 2991 2992 // Stops consuming touch-move. 2993 delegate->set_consume_touch_move(false); 2994 2995 delegate->Reset(); 2996 // Making a pinch gesture. 2997 tes.SendScrollEvent(root_window(), 161, 251, kTouchId1, delegate.get()); 2998 tes.SendScrollEvent(root_window(), 161, 241, kTouchId2, delegate.get()); 2999 3000 // Now we see PinchUpdate & ScrollUpdate. 3001 EXPECT_FALSE(delegate->scroll_begin()); 3002 EXPECT_TRUE(delegate->scroll_update()); 3003 EXPECT_FALSE(delegate->scroll_end()); 3004 3005 EXPECT_FALSE(delegate->pinch_begin()); 3006 EXPECT_TRUE(delegate->pinch_update()); 3007 EXPECT_FALSE(delegate->pinch_end()); 3008 3009 delegate->Reset(); 3010 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3011 kTouchId1, tes.Now()); 3012 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(130, 201), 3013 kTouchId2, tes.Now()); 3014 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 3015 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 3016 3017 EXPECT_FALSE(delegate->tap()); 3018 EXPECT_FALSE(delegate->two_finger_tap()); 3019 3020 // Should see PinchEnd & ScrollEnd. 3021 EXPECT_FALSE(delegate->scroll_begin()); 3022 EXPECT_FALSE(delegate->scroll_update()); 3023 EXPECT_TRUE(delegate->scroll_end()); 3024 3025 EXPECT_FALSE(delegate->pinch_begin()); 3026 EXPECT_FALSE(delegate->pinch_update()); 3027 EXPECT_TRUE(delegate->pinch_end()); 3028 } 3029 3030 // Like as GestureEventTouchMoveConsumed but tests the different behavior 3031 // depending on whether the events were consumed before or after the scroll 3032 // started. 3033 TEST_F(GestureRecognizerTest, GestureEventScrollTouchMovePartialConsumed) { 3034 scoped_ptr<ConsumesTouchMovesDelegate> delegate( 3035 new ConsumesTouchMovesDelegate()); 3036 const int kWindowWidth = 123; 3037 const int kWindowHeight = 45; 3038 const int kTouchId = 5; 3039 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3040 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3041 delegate.get(), -1234, bounds, root_window())); 3042 TimedEvents tes; 3043 3044 delegate->Reset(); 3045 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3046 kTouchId, tes.Now()); 3047 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 3048 EXPECT_FALSE(delegate->tap()); 3049 EXPECT_TRUE(delegate->tap_down()); 3050 EXPECT_FALSE(delegate->tap_cancel()); 3051 EXPECT_TRUE(delegate->begin()); 3052 EXPECT_FALSE(delegate->scroll_begin()); 3053 EXPECT_FALSE(delegate->scroll_update()); 3054 EXPECT_FALSE(delegate->scroll_end()); 3055 3056 // Move the touch-point enough so that it would normally be considered a 3057 // scroll. But since the touch-moves will be consumed, the scroll should not 3058 // start. 3059 tes.SendScrollEvent(root_window(), 130, 230, kTouchId, delegate.get()); 3060 EXPECT_FALSE(delegate->tap()); 3061 EXPECT_FALSE(delegate->tap_down()); 3062 // TODO(rbyers): Really we should get the TapCancel here instead of below, 3063 // but this is a symptom of a larger issue: crbug.com/146397. 3064 EXPECT_FALSE(delegate->tap_cancel()); 3065 EXPECT_FALSE(delegate->begin()); 3066 EXPECT_FALSE(delegate->scroll_begin()); 3067 EXPECT_FALSE(delegate->scroll_update()); 3068 EXPECT_FALSE(delegate->scroll_end()); 3069 3070 // Now, stop consuming touch-move events, and move the touch-point again. 3071 delegate->set_consume_touch_move(false); 3072 tes.SendScrollEvent(root_window(), 159, 259, kTouchId, delegate.get()); 3073 EXPECT_FALSE(delegate->tap()); 3074 EXPECT_FALSE(delegate->tap_down()); 3075 EXPECT_TRUE(delegate->tap_cancel()); 3076 EXPECT_FALSE(delegate->begin()); 3077 EXPECT_TRUE(delegate->scroll_begin()); 3078 EXPECT_TRUE(delegate->scroll_update()); 3079 EXPECT_FALSE(delegate->scroll_end()); 3080 // Consuming move events doesn't effect what the ultimate scroll position 3081 // will be if scrolling is later allowed to happen. 3082 EXPECT_EQ(58, delegate->scroll_x()); 3083 EXPECT_EQ(58, delegate->scroll_y()); 3084 EXPECT_EQ(gfx::Point(1, 1).ToString(), 3085 delegate->scroll_begin_position().ToString()); 3086 3087 // Start consuming touch-move events again. However, since gesture-scroll has 3088 // already started, the touch-move events should still result in scroll-update 3089 // gestures. 3090 delegate->set_consume_touch_move(true); 3091 3092 // Move some more to generate a few more scroll updates. 3093 tes.SendScrollEvent(root_window(), 110, 211, kTouchId, delegate.get()); 3094 EXPECT_FALSE(delegate->tap()); 3095 EXPECT_FALSE(delegate->tap_down()); 3096 EXPECT_FALSE(delegate->tap_cancel()); 3097 EXPECT_FALSE(delegate->begin()); 3098 EXPECT_FALSE(delegate->scroll_begin()); 3099 EXPECT_TRUE(delegate->scroll_update()); 3100 EXPECT_FALSE(delegate->scroll_end()); 3101 EXPECT_EQ(-49, delegate->scroll_x()); 3102 EXPECT_EQ(-48, delegate->scroll_y()); 3103 3104 tes.SendScrollEvent(root_window(), 140, 215, kTouchId, delegate.get()); 3105 EXPECT_FALSE(delegate->tap()); 3106 EXPECT_FALSE(delegate->tap_down()); 3107 EXPECT_FALSE(delegate->tap_cancel()); 3108 EXPECT_FALSE(delegate->begin()); 3109 EXPECT_FALSE(delegate->scroll_begin()); 3110 EXPECT_TRUE(delegate->scroll_update()); 3111 EXPECT_FALSE(delegate->scroll_end()); 3112 EXPECT_EQ(30, delegate->scroll_x()); 3113 EXPECT_EQ(4, delegate->scroll_y()); 3114 3115 // Release the touch. This should end the scroll. 3116 delegate->Reset(); 3117 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3118 kTouchId, tes.LeapForward(50)); 3119 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release); 3120 EXPECT_FALSE(delegate->tap()); 3121 EXPECT_FALSE(delegate->tap_down()); 3122 EXPECT_FALSE(delegate->tap_cancel()); 3123 EXPECT_FALSE(delegate->begin()); 3124 EXPECT_TRUE(delegate->end()); 3125 EXPECT_FALSE(delegate->scroll_begin()); 3126 EXPECT_FALSE(delegate->scroll_update()); 3127 EXPECT_FALSE(delegate->scroll_end()); 3128 // Moves arrive without delays and hence have high velocity. 3129 EXPECT_TRUE(delegate->fling()); 3130 } 3131 3132 // Check that appropriate touch events generate double tap gesture events. 3133 TEST_F(GestureRecognizerTest, GestureEventDoubleTap) { 3134 scoped_ptr<GestureEventConsumeDelegate> delegate( 3135 new GestureEventConsumeDelegate()); 3136 const int kWindowWidth = 123; 3137 const int kWindowHeight = 45; 3138 const int kTouchId = 2; 3139 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3140 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3141 delegate.get(), -1234, bounds, root_window())); 3142 TimedEvents tes; 3143 3144 // First tap (tested in GestureEventTap) 3145 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201), 3146 kTouchId, tes.Now()); 3147 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 3148 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201), 3149 kTouchId, tes.LeapForward(50)); 3150 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 3151 delegate->Reset(); 3152 3153 // Second tap 3154 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 203), 3155 kTouchId, tes.LeapForward(200)); 3156 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 3157 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206), 3158 kTouchId, tes.LeapForward(50)); 3159 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 3160 3161 EXPECT_TRUE(delegate->tap()); 3162 EXPECT_TRUE(delegate->tap_down()); 3163 EXPECT_FALSE(delegate->tap_cancel()); 3164 EXPECT_TRUE(delegate->begin()); 3165 EXPECT_TRUE(delegate->end()); 3166 EXPECT_FALSE(delegate->scroll_begin()); 3167 EXPECT_FALSE(delegate->scroll_update()); 3168 EXPECT_FALSE(delegate->scroll_end()); 3169 3170 EXPECT_EQ(2, delegate->tap_count()); 3171 } 3172 3173 // Check that appropriate touch events generate triple tap gesture events. 3174 TEST_F(GestureRecognizerTest, GestureEventTripleTap) { 3175 scoped_ptr<GestureEventConsumeDelegate> delegate( 3176 new GestureEventConsumeDelegate()); 3177 const int kWindowWidth = 123; 3178 const int kWindowHeight = 45; 3179 const int kTouchId = 2; 3180 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3181 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3182 delegate.get(), -1234, bounds, root_window())); 3183 TimedEvents tes; 3184 3185 // First tap (tested in GestureEventTap) 3186 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(104, 201), 3187 kTouchId, tes.Now()); 3188 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 3189 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(104, 201), 3190 kTouchId, tes.LeapForward(50)); 3191 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 3192 3193 EXPECT_EQ(1, delegate->tap_count()); 3194 delegate->Reset(); 3195 3196 // Second tap (tested in GestureEventDoubleTap) 3197 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 203), 3198 kTouchId, tes.LeapForward(200)); 3199 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 3200 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206), 3201 kTouchId, tes.LeapForward(50)); 3202 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 3203 3204 EXPECT_EQ(2, delegate->tap_count()); 3205 delegate->Reset(); 3206 3207 // Third tap 3208 ui::TouchEvent press3(ui::ET_TOUCH_PRESSED, gfx::Point(102, 206), 3209 kTouchId, tes.LeapForward(200)); 3210 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press3); 3211 ui::TouchEvent release3(ui::ET_TOUCH_RELEASED, gfx::Point(102, 206), 3212 kTouchId, tes.LeapForward(50)); 3213 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release3); 3214 3215 3216 EXPECT_TRUE(delegate->tap()); 3217 EXPECT_TRUE(delegate->tap_down()); 3218 EXPECT_FALSE(delegate->tap_cancel()); 3219 EXPECT_TRUE(delegate->begin()); 3220 EXPECT_TRUE(delegate->end()); 3221 EXPECT_FALSE(delegate->scroll_begin()); 3222 EXPECT_FALSE(delegate->scroll_update()); 3223 EXPECT_FALSE(delegate->scroll_end()); 3224 3225 EXPECT_EQ(3, delegate->tap_count()); 3226 } 3227 3228 // Check that we don't get a double tap when the two taps are far apart. 3229 TEST_F(GestureRecognizerTest, TwoTapsFarApart) { 3230 scoped_ptr<GestureEventConsumeDelegate> delegate( 3231 new GestureEventConsumeDelegate()); 3232 const int kWindowWidth = 123; 3233 const int kWindowHeight = 45; 3234 const int kTouchId = 2; 3235 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3236 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3237 delegate.get(), -1234, bounds, root_window())); 3238 TimedEvents tes; 3239 3240 // First tap (tested in GestureEventTap) 3241 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3242 kTouchId, tes.Now()); 3243 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 3244 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3245 kTouchId, tes.LeapForward(50)); 3246 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 3247 delegate->Reset(); 3248 3249 // Second tap, close in time but far in distance 3250 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), 3251 kTouchId, tes.LeapForward(200)); 3252 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 3253 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(201, 201), 3254 kTouchId, tes.LeapForward(50)); 3255 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 3256 3257 EXPECT_TRUE(delegate->tap()); 3258 EXPECT_TRUE(delegate->tap_down()); 3259 EXPECT_FALSE(delegate->tap_cancel()); 3260 EXPECT_TRUE(delegate->begin()); 3261 EXPECT_TRUE(delegate->end()); 3262 EXPECT_FALSE(delegate->scroll_begin()); 3263 EXPECT_FALSE(delegate->scroll_update()); 3264 EXPECT_FALSE(delegate->scroll_end()); 3265 3266 EXPECT_EQ(1, delegate->tap_count()); 3267 } 3268 3269 // Check that we don't get a double tap when the two taps have a long enough 3270 // delay in between. 3271 TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) { 3272 scoped_ptr<GestureEventConsumeDelegate> delegate( 3273 new GestureEventConsumeDelegate()); 3274 const int kWindowWidth = 123; 3275 const int kWindowHeight = 45; 3276 const int kTouchId = 2; 3277 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3278 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3279 delegate.get(), -1234, bounds, root_window())); 3280 TimedEvents tes; 3281 3282 // First tap (tested in GestureEventTap) 3283 ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3284 kTouchId, tes.Now()); 3285 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 3286 ui::TouchEvent release1(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3287 kTouchId, tes.LeapForward(50)); 3288 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release1); 3289 delegate->Reset(); 3290 3291 // Second tap, close in distance but after some delay 3292 ui::TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3293 kTouchId, tes.LeapForward(2000)); 3294 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 3295 ui::TouchEvent release2(ui::ET_TOUCH_RELEASED, gfx::Point(101, 201), 3296 kTouchId, tes.LeapForward(50)); 3297 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&release2); 3298 3299 EXPECT_TRUE(delegate->tap()); 3300 EXPECT_TRUE(delegate->tap_down()); 3301 EXPECT_FALSE(delegate->tap_cancel()); 3302 EXPECT_TRUE(delegate->begin()); 3303 EXPECT_TRUE(delegate->end()); 3304 EXPECT_FALSE(delegate->scroll_begin()); 3305 EXPECT_FALSE(delegate->scroll_update()); 3306 EXPECT_FALSE(delegate->scroll_end()); 3307 3308 EXPECT_EQ(1, delegate->tap_count()); 3309 } 3310 3311 // Checks that if the bounding-box of a gesture changes because of change in 3312 // radius of a touch-point, and not because of change in position, then there 3313 // are not gesture events from that. 3314 TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) { 3315 scoped_ptr<GestureEventConsumeDelegate> delegate( 3316 new GestureEventConsumeDelegate()); 3317 const int kWindowWidth = 234; 3318 const int kWindowHeight = 345; 3319 const int kTouchId = 5, kTouchId2 = 7; 3320 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3321 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3322 delegate.get(), -1234, bounds, root_window())); 3323 TimedEvents tes; 3324 3325 ui::TouchEvent press1( 3326 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId, tes.Now()); 3327 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 3328 EXPECT_TRUE(delegate->bounding_box().IsEmpty()); 3329 3330 delegate->Reset(); 3331 3332 ui::TouchEvent press2( 3333 ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), kTouchId2, 3334 tes.LeapForward(400)); 3335 press2.set_radius_x(5); 3336 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2); 3337 EXPECT_FALSE(delegate->pinch_begin()); 3338 EXPECT_EQ(gfx::Rect(101, 201, 100, 0).ToString(), 3339 delegate->bounding_box().ToString()); 3340 3341 delegate->Reset(); 3342 3343 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId, 3344 tes.LeapForward(40)); 3345 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 3346 EXPECT_TRUE(delegate->pinch_begin()); 3347 EXPECT_EQ(gfx::Rect(141, 201, 60, 0).ToString(), 3348 delegate->bounding_box().ToString()); 3349 3350 delegate->Reset(); 3351 3352 // The position doesn't move, but the radius changes. 3353 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId, 3354 tes.LeapForward(40)); 3355 move2.set_radius_x(50); 3356 move2.set_radius_y(60); 3357 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 3358 EXPECT_FALSE(delegate->tap()); 3359 EXPECT_FALSE(delegate->tap_cancel()); 3360 EXPECT_FALSE(delegate->scroll_update()); 3361 EXPECT_FALSE(delegate->pinch_update()); 3362 3363 delegate->Reset(); 3364 } 3365 3366 // Checks that slow scrolls deliver the correct deltas. 3367 // In particular, fix for http;//crbug.com/150573. 3368 TEST_F(GestureRecognizerTest, NoDriftInScroll) { 3369 ui::GestureConfiguration::set_max_touch_move_in_pixels_for_click(3); 3370 ui::GestureConfiguration::set_min_scroll_delta_squared(9); 3371 scoped_ptr<GestureEventConsumeDelegate> delegate( 3372 new GestureEventConsumeDelegate()); 3373 const int kWindowWidth = 234; 3374 const int kWindowHeight = 345; 3375 const int kTouchId = 5; 3376 TimedEvents tes; 3377 gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight); 3378 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3379 delegate.get(), -1234, bounds, root_window())); 3380 3381 ui::TouchEvent press1( 3382 ui::ET_TOUCH_PRESSED, gfx::Point(101, 208), kTouchId, tes.Now()); 3383 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1); 3384 EXPECT_TRUE(delegate->begin()); 3385 3386 delegate->Reset(); 3387 3388 ui::TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(101, 206), kTouchId, 3389 tes.LeapForward(40)); 3390 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1); 3391 EXPECT_FALSE(delegate->scroll_begin()); 3392 3393 delegate->Reset(); 3394 3395 ui::TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 204), kTouchId, 3396 tes.LeapForward(40)); 3397 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2); 3398 EXPECT_TRUE(delegate->tap_cancel()); 3399 EXPECT_TRUE(delegate->scroll_begin()); 3400 EXPECT_TRUE(delegate->scroll_update()); 3401 EXPECT_EQ(-4, delegate->scroll_y()); 3402 3403 delegate->Reset(); 3404 3405 ui::TouchEvent move3(ui::ET_TOUCH_MOVED, gfx::Point(101, 204), kTouchId, 3406 tes.LeapForward(40)); 3407 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move3); 3408 EXPECT_FALSE(delegate->scroll_update()); 3409 3410 delegate->Reset(); 3411 3412 ui::TouchEvent move4(ui::ET_TOUCH_MOVED, gfx::Point(101, 203), kTouchId, 3413 tes.LeapForward(40)); 3414 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move4); 3415 EXPECT_TRUE(delegate->scroll_update()); 3416 EXPECT_EQ(-1, delegate->scroll_y()); 3417 3418 delegate->Reset(); 3419 } 3420 3421 } // namespace test 3422 } // namespace aura 3423