OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_vector.h" | 6 #include "base/memory/scoped_vector.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
524 base::TimeDelta::FromMilliseconds(simulated_now_)); | 524 base::TimeDelta::FromMilliseconds(simulated_now_)); |
525 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); | 525 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); |
526 ASSERT_FALSE(details.dispatcher_destroyed); | 526 ASSERT_FALSE(details.dispatcher_destroyed); |
527 simulated_now_++; | 527 simulated_now_++; |
528 } | 528 } |
529 }; | 529 }; |
530 | 530 |
531 // An event handler to keep track of events. | 531 // An event handler to keep track of events. |
532 class TestEventHandler : public ui::EventHandler { | 532 class TestEventHandler : public ui::EventHandler { |
533 public: | 533 public: |
534 TestEventHandler() : touch_released_count_(0), | 534 TestEventHandler() |
535 touch_pressed_count_(0), | 535 : touch_released_count_(0), |
536 touch_moved_count_(0), | 536 touch_pressed_count_(0), |
537 touch_cancelled_count_(0) { | 537 touch_moved_count_(0) {} |
538 } | |
539 | 538 |
540 virtual ~TestEventHandler() {} | 539 virtual ~TestEventHandler() {} |
541 | 540 |
542 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | 541 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
543 switch (event->type()) { | 542 switch (event->type()) { |
544 case ui::ET_TOUCH_RELEASED: | 543 case ui::ET_TOUCH_RELEASED: |
545 touch_released_count_++; | 544 touch_released_count_++; |
546 break; | 545 break; |
547 case ui::ET_TOUCH_PRESSED: | 546 case ui::ET_TOUCH_PRESSED: |
548 touch_pressed_count_++; | 547 touch_pressed_count_++; |
549 break; | 548 break; |
550 case ui::ET_TOUCH_MOVED: | 549 case ui::ET_TOUCH_MOVED: |
551 touch_moved_count_++; | 550 touch_moved_count_++; |
552 break; | 551 break; |
553 case ui::ET_TOUCH_CANCELLED: | 552 case ui::ET_TOUCH_CANCELLED: |
554 touch_cancelled_count_++; | 553 touch_points_.push_back(event->location()); |
555 break; | 554 break; |
556 default: | 555 default: |
557 break; | 556 break; |
558 } | 557 } |
559 } | 558 } |
560 | 559 |
561 void Reset() { | 560 void Reset() { |
562 touch_released_count_ = 0; | 561 touch_released_count_ = 0; |
563 touch_pressed_count_ = 0; | 562 touch_pressed_count_ = 0; |
564 touch_moved_count_ = 0; | 563 touch_moved_count_ = 0; |
565 touch_cancelled_count_ = 0; | 564 touch_points_.clear(); |
566 } | 565 } |
567 | 566 |
568 int touch_released_count() const { return touch_released_count_; } | 567 int touch_released_count() const { return touch_released_count_; } |
569 int touch_pressed_count() const { return touch_pressed_count_; } | 568 int touch_pressed_count() const { return touch_pressed_count_; } |
570 int touch_moved_count() const { return touch_moved_count_; } | 569 int touch_moved_count() const { return touch_moved_count_; } |
571 int touch_cancelled_count() const { return touch_cancelled_count_; } | 570 int touch_cancelled_count() const { |
571 return static_cast<int>(touch_points_.size()); | |
572 } | |
573 const std::vector<gfx::PointF>& touch_points() const { return touch_points_; } | |
572 | 574 |
573 private: | 575 private: |
574 int touch_released_count_; | 576 int touch_released_count_; |
575 int touch_pressed_count_; | 577 int touch_pressed_count_; |
576 int touch_moved_count_; | 578 int touch_moved_count_; |
577 int touch_cancelled_count_; | 579 std::vector<gfx::PointF> touch_points_; |
tdresser
2014/08/27 15:58:50
Perhaps we should name this |cancelled_touch_point
| |
578 | 580 |
579 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); | 581 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
580 }; | 582 }; |
581 | 583 |
582 // Removes the target window from its parent when it receives a touch-cancel | 584 // Removes the target window from its parent when it receives a touch-cancel |
583 // event. | 585 // event. |
584 class RemoveOnTouchCancelHandler : public TestEventHandler { | 586 class RemoveOnTouchCancelHandler : public TestEventHandler { |
585 public: | 587 public: |
586 RemoveOnTouchCancelHandler() {} | 588 RemoveOnTouchCancelHandler() {} |
587 virtual ~RemoveOnTouchCancelHandler() {} | 589 virtual ~RemoveOnTouchCancelHandler() {} |
(...skipping 2930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3518 EXPECT_FALSE(delegate->scroll_end()); | 3520 EXPECT_FALSE(delegate->scroll_end()); |
3519 } | 3521 } |
3520 | 3522 |
3521 TEST_F(GestureRecognizerTest, | 3523 TEST_F(GestureRecognizerTest, |
3522 TransferEventDispatchesTouchCancel) { | 3524 TransferEventDispatchesTouchCancel) { |
3523 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3525 scoped_ptr<GestureEventConsumeDelegate> delegate( |
3524 new GestureEventConsumeDelegate()); | 3526 new GestureEventConsumeDelegate()); |
3525 TimedEvents tes; | 3527 TimedEvents tes; |
3526 const int kWindowWidth = 800; | 3528 const int kWindowWidth = 800; |
3527 const int kWindowHeight = 600; | 3529 const int kWindowHeight = 600; |
3528 const int kTouchId = 2; | 3530 const int kTouchId1 = 1; |
3531 const int kTouchId2 = 2; | |
3529 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); | 3532 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); |
3530 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( | 3533 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( |
3531 delegate.get(), -1234, bounds, root_window())); | 3534 delegate.get(), -1234, bounds, root_window())); |
3532 scoped_ptr<RemoveOnTouchCancelHandler> | 3535 scoped_ptr<TestEventHandler> handler(new TestEventHandler()); |
3533 handler(new RemoveOnTouchCancelHandler()); | |
3534 window->AddPreTargetHandler(handler.get()); | 3536 window->AddPreTargetHandler(handler.get()); |
3535 | 3537 |
3536 // Start a gesture sequence on |window|. Then transfer the events to NULL. | 3538 // Start a gesture sequence on |window|. Then transfer the events to NULL. |
3537 // Make sure |window| receives a touch-cancel event. | 3539 // Make sure |window| receives a touch-cancel event. |
3538 delegate->Reset(); | 3540 delegate->Reset(); |
3539 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), | 3541 ui::TouchEvent press( |
3540 kTouchId, tes.Now()); | 3542 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now()); |
3541 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 1, tes.Now()); | |
3542 DispatchEventUsingWindowDispatcher(&press); | 3543 DispatchEventUsingWindowDispatcher(&press); |
3544 EXPECT_2_EVENTS( | |
3545 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN); | |
3546 delegate->Reset(); | |
3547 ui::TouchEvent p2( | |
3548 ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), kTouchId2, tes.Now()); | |
3543 DispatchEventUsingWindowDispatcher(&p2); | 3549 DispatchEventUsingWindowDispatcher(&p2); |
3544 EXPECT_FALSE(delegate->tap()); | 3550 EXPECT_2_EVENTS( |
3545 EXPECT_TRUE(delegate->tap_down()); | 3551 delegate->events(), ui::ET_GESTURE_TAP_CANCEL, ui::ET_GESTURE_BEGIN); |
3546 EXPECT_TRUE(delegate->tap_cancel()); | 3552 delegate->Reset(); |
3547 EXPECT_TRUE(delegate->begin()); | 3553 ui::TouchEvent move( |
3554 ui::ET_TOUCH_MOVED, gfx::Point(350, 300), kTouchId2, tes.Now()); | |
3555 DispatchEventUsingWindowDispatcher(&move); | |
3556 EXPECT_3_EVENTS(delegate->events(), | |
3557 ui::ET_GESTURE_SCROLL_BEGIN, | |
3558 ui::ET_GESTURE_SCROLL_UPDATE, | |
3559 ui::ET_GESTURE_PINCH_BEGIN); | |
3548 EXPECT_EQ(2, handler->touch_pressed_count()); | 3560 EXPECT_EQ(2, handler->touch_pressed_count()); |
3549 delegate->Reset(); | 3561 delegate->Reset(); |
3550 handler->Reset(); | 3562 handler->Reset(); |
3551 | 3563 |
3552 ui::GestureRecognizer* gesture_recognizer = ui::GestureRecognizer::Get(); | 3564 ui::GestureRecognizer* gesture_recognizer = ui::GestureRecognizer::Get(); |
3553 EXPECT_EQ(window.get(), | 3565 EXPECT_EQ(window.get(), |
3554 gesture_recognizer->GetTouchLockedTarget(press)); | 3566 gesture_recognizer->GetTouchLockedTarget(press)); |
3555 gesture_recognizer->TransferEventsTo(window.get(), NULL); | 3567 gesture_recognizer->TransferEventsTo(window.get(), NULL); |
3556 EXPECT_EQ(NULL, | 3568 EXPECT_EQ(NULL, |
3557 gesture_recognizer->GetTouchLockedTarget(press)); | 3569 gesture_recognizer->GetTouchLockedTarget(press)); |
3558 // The event-handler removes |window| from its parent on the first | 3570 EXPECT_4_EVENTS(delegate->events(), |
3559 // touch-cancel event, so it won't receive the second touch-cancel event. | 3571 ui::ET_GESTURE_PINCH_END, |
3560 EXPECT_EQ(1, handler->touch_cancelled_count()); | 3572 ui::ET_GESTURE_SCROLL_END, |
3573 ui::ET_GESTURE_END, | |
3574 ui::ET_GESTURE_END); | |
3575 const std::vector<gfx::PointF>& points = handler->touch_points(); | |
3576 EXPECT_EQ(2U, points.size()); | |
3577 EXPECT_EQ(gfx::Point(101, 201), points[0]); | |
3578 EXPECT_EQ(gfx::Point(350, 300), points[1]); | |
3561 } | 3579 } |
3562 | 3580 |
3563 // Check that appropriate touch events generate show press events | 3581 // Check that appropriate touch events generate show press events |
3564 TEST_F(GestureRecognizerTest, GestureEventShowPress) { | 3582 TEST_F(GestureRecognizerTest, GestureEventShowPress) { |
3565 scoped_ptr<GestureEventConsumeDelegate> delegate( | 3583 scoped_ptr<GestureEventConsumeDelegate> delegate( |
3566 new GestureEventConsumeDelegate()); | 3584 new GestureEventConsumeDelegate()); |
3567 TimedEvents tes; | 3585 TimedEvents tes; |
3568 const int kWindowWidth = 123; | 3586 const int kWindowWidth = 123; |
3569 const int kWindowHeight = 45; | 3587 const int kWindowHeight = 45; |
3570 const int kTouchId = 2; | 3588 const int kTouchId = 2; |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4258 ui::TouchEvent move3( | 4276 ui::TouchEvent move3( |
4259 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); | 4277 ui::ET_TOUCH_MOVED, gfx::Point(65, 202), kTouchId1, tes.Now()); |
4260 DispatchEventUsingWindowDispatcher(&move3); | 4278 DispatchEventUsingWindowDispatcher(&move3); |
4261 | 4279 |
4262 delegate->ReceivedAck(); | 4280 delegate->ReceivedAck(); |
4263 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); | 4281 EXPECT_1_EVENT(delegate->events(), ui::ET_GESTURE_SCROLL_UPDATE); |
4264 } | 4282 } |
4265 | 4283 |
4266 } // namespace test | 4284 } // namespace test |
4267 } // namespace aura | 4285 } // namespace aura |
OLD | NEW |