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

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

Issue 469523003: Add the actual location coordinates to the touch cancel event (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: canceling the touch points from GestureConsumer Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/aura/window_event_dispatcher.cc » ('j') | ui/aura/window_event_dispatcher.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/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 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
595 base::TimeDelta::FromMilliseconds(simulated_now_)); 595 base::TimeDelta::FromMilliseconds(simulated_now_));
596 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move); 596 ui::EventDispatchDetails details = dispatcher->OnEventFromSource(&move);
597 ASSERT_FALSE(details.dispatcher_destroyed); 597 ASSERT_FALSE(details.dispatcher_destroyed);
598 simulated_now_++; 598 simulated_now_++;
599 } 599 }
600 }; 600 };
601 601
602 // An event handler to keep track of events. 602 // An event handler to keep track of events.
603 class TestEventHandler : public ui::EventHandler { 603 class TestEventHandler : public ui::EventHandler {
604 public: 604 public:
605 TestEventHandler() : touch_released_count_(0), 605 TestEventHandler()
606 touch_pressed_count_(0), 606 : touch_released_count_(0),
607 touch_moved_count_(0), 607 touch_pressed_count_(0),
608 touch_cancelled_count_(0) { 608 touch_moved_count_(0) {}
609 }
610 609
611 virtual ~TestEventHandler() {} 610 virtual ~TestEventHandler() {}
612 611
613 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 612 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
614 switch (event->type()) { 613 switch (event->type()) {
615 case ui::ET_TOUCH_RELEASED: 614 case ui::ET_TOUCH_RELEASED:
616 touch_released_count_++; 615 touch_released_count_++;
617 break; 616 break;
618 case ui::ET_TOUCH_PRESSED: 617 case ui::ET_TOUCH_PRESSED:
619 touch_pressed_count_++; 618 touch_pressed_count_++;
620 break; 619 break;
621 case ui::ET_TOUCH_MOVED: 620 case ui::ET_TOUCH_MOVED:
622 touch_moved_count_++; 621 touch_moved_count_++;
623 break; 622 break;
624 case ui::ET_TOUCH_CANCELLED: 623 case ui::ET_TOUCH_CANCELLED:
625 touch_cancelled_count_++; 624 touch_points_.push_back(event->location());
626 break; 625 break;
627 default: 626 default:
628 break; 627 break;
629 } 628 }
630 } 629 }
631 630
632 void Reset() { 631 void Reset() {
633 touch_released_count_ = 0; 632 touch_released_count_ = 0;
634 touch_pressed_count_ = 0; 633 touch_pressed_count_ = 0;
635 touch_moved_count_ = 0; 634 touch_moved_count_ = 0;
636 touch_cancelled_count_ = 0; 635 touch_points_.clear();
637 } 636 }
638 637
639 int touch_released_count() const { return touch_released_count_; } 638 int touch_released_count() const { return touch_released_count_; }
640 int touch_pressed_count() const { return touch_pressed_count_; } 639 int touch_pressed_count() const { return touch_pressed_count_; }
641 int touch_moved_count() const { return touch_moved_count_; } 640 int touch_moved_count() const { return touch_moved_count_; }
642 int touch_cancelled_count() const { return touch_cancelled_count_; } 641 int touch_cancelled_count() const {
642 return static_cast<int>(touch_points_.size());
643 }
644 const std::vector<gfx::PointF>& touch_points() const { return touch_points_; }
643 645
644 private: 646 private:
645 int touch_released_count_; 647 int touch_released_count_;
646 int touch_pressed_count_; 648 int touch_pressed_count_;
647 int touch_moved_count_; 649 int touch_moved_count_;
648 int touch_cancelled_count_; 650 std::vector<gfx::PointF> touch_points_;
649 651
650 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 652 DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
651 }; 653 };
652 654
653 // Removes the target window from its parent when it receives a touch-cancel
654 // event.
655 class RemoveOnTouchCancelHandler : public TestEventHandler {
656 public:
657 RemoveOnTouchCancelHandler() {}
658 virtual ~RemoveOnTouchCancelHandler() {}
659
660 private:
661 // ui::EventHandler:
662 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
663 TestEventHandler::OnTouchEvent(event);
664 if (event->type() == ui::ET_TOUCH_CANCELLED) {
665 Window* target = static_cast<Window*>(event->target());
666 // This is tiptoeing around crbug.com/310172. If this event handler isn't
667 // removed, we enter an infinite loop.
668 target->RemovePreTargetHandler(this);
669 target->parent()->RemoveChild(target);
670 }
671 }
672
673 DISALLOW_COPY_AND_ASSIGN(RemoveOnTouchCancelHandler);
674 };
675
676 } // namespace 655 } // namespace
677 656
678 class GestureRecognizerTest : public AuraTestBase, 657 class GestureRecognizerTest : public AuraTestBase,
679 public ::testing::WithParamInterface<bool> { 658 public ::testing::WithParamInterface<bool> {
680 public: 659 public:
681 GestureRecognizerTest() {} 660 GestureRecognizerTest() {}
682 661
683 bool UsingUnifiedGR() { 662 bool UsingUnifiedGR() {
684 return GetParam(); 663 return GetParam();
685 } 664 }
(...skipping 3076 matching lines...) Expand 10 before | Expand all | Expand 10 after
3762 EXPECT_FALSE(delegate->tap()); 3741 EXPECT_FALSE(delegate->tap());
3763 EXPECT_FALSE(delegate->tap_down()); 3742 EXPECT_FALSE(delegate->tap_down());
3764 EXPECT_TRUE(delegate->tap_cancel()); 3743 EXPECT_TRUE(delegate->tap_cancel());
3765 EXPECT_FALSE(delegate->begin()); 3744 EXPECT_FALSE(delegate->begin());
3766 EXPECT_FALSE(delegate->scroll_update()); 3745 EXPECT_FALSE(delegate->scroll_update());
3767 EXPECT_FALSE(delegate->scroll_end()); 3746 EXPECT_FALSE(delegate->scroll_end());
3768 } 3747 }
3769 3748
3770 TEST_P(GestureRecognizerTest, 3749 TEST_P(GestureRecognizerTest,
3771 TransferEventDispatchesTouchCancel) { 3750 TransferEventDispatchesTouchCancel) {
3751 // Only enabled for unified GR, as the old Aura GR doesn't assign
3752 // positions to touch cancel events correctly.
3753 if (!UsingUnifiedGR())
3754 return;
3755
3772 scoped_ptr<GestureEventConsumeDelegate> delegate( 3756 scoped_ptr<GestureEventConsumeDelegate> delegate(
3773 new GestureEventConsumeDelegate()); 3757 new GestureEventConsumeDelegate());
3774 TimedEvents tes; 3758 TimedEvents tes;
3775 const int kWindowWidth = 800; 3759 const int kWindowWidth = 800;
3776 const int kWindowHeight = 600; 3760 const int kWindowHeight = 600;
3777 const int kTouchId = 2; 3761 const int kTouchId1 = 1;
3762 const int kTouchId2 = 2;
3778 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3763 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3779 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3764 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3780 delegate.get(), -1234, bounds, root_window())); 3765 delegate.get(), -1234, bounds, root_window()));
3781 scoped_ptr<RemoveOnTouchCancelHandler> 3766 scoped_ptr<TestEventHandler> handler(new TestEventHandler());
3782 handler(new RemoveOnTouchCancelHandler());
3783 window->AddPreTargetHandler(handler.get()); 3767 window->AddPreTargetHandler(handler.get());
3784 3768
3785 // Start a gesture sequence on |window|. Then transfer the events to NULL. 3769 // Start a gesture sequence on |window|. Then transfer the events to NULL.
3786 // Make sure |window| receives a touch-cancel event. 3770 // Make sure |window| receives a touch-cancel event.
3787 delegate->Reset(); 3771 delegate->Reset();
3788 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3772 ui::TouchEvent press(
3789 kTouchId, tes.Now()); 3773 ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId1, tes.Now());
3790 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 1, tes.Now());
3791 DispatchEventUsingWindowDispatcher(&press); 3774 DispatchEventUsingWindowDispatcher(&press);
3775 EXPECT_2_EVENTS(
3776 delegate->events(), ui::ET_GESTURE_BEGIN, ui::ET_GESTURE_TAP_DOWN);
3777 delegate->Reset();
3778 ui::TouchEvent p2(
3779 ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), kTouchId2, tes.Now());
3792 DispatchEventUsingWindowDispatcher(&p2); 3780 DispatchEventUsingWindowDispatcher(&p2);
3793 EXPECT_FALSE(delegate->tap()); 3781 EXPECT_2_EVENTS(
3794 EXPECT_TRUE(delegate->tap_down()); 3782 delegate->events(), ui::ET_GESTURE_TAP_CANCEL, ui::ET_GESTURE_BEGIN);
3795 EXPECT_TRUE(delegate->tap_cancel()); 3783 delegate->Reset();
3796 EXPECT_TRUE(delegate->begin()); 3784 ui::TouchEvent move(
3785 ui::ET_TOUCH_MOVED, gfx::Point(350, 300), kTouchId2, tes.Now());
3786 DispatchEventUsingWindowDispatcher(&move);
3787 EXPECT_3_EVENTS(delegate->events(),
3788 ui::ET_GESTURE_SCROLL_BEGIN,
3789 ui::ET_GESTURE_SCROLL_UPDATE,
3790 ui::ET_GESTURE_PINCH_BEGIN);
3797 EXPECT_EQ(2, handler->touch_pressed_count()); 3791 EXPECT_EQ(2, handler->touch_pressed_count());
3798 delegate->Reset(); 3792 delegate->Reset();
3799 handler->Reset(); 3793 handler->Reset();
3800 3794
3801 ui::GestureRecognizer* gesture_recognizer = ui::GestureRecognizer::Get(); 3795 ui::GestureRecognizer* gesture_recognizer = ui::GestureRecognizer::Get();
3802 EXPECT_EQ(window.get(), 3796 EXPECT_EQ(window.get(),
3803 gesture_recognizer->GetTouchLockedTarget(press)); 3797 gesture_recognizer->GetTouchLockedTarget(press));
3804 gesture_recognizer->TransferEventsTo(window.get(), NULL); 3798 gesture_recognizer->TransferEventsTo(window.get(), NULL);
3805 EXPECT_EQ(NULL, 3799 EXPECT_EQ(NULL,
3806 gesture_recognizer->GetTouchLockedTarget(press)); 3800 gesture_recognizer->GetTouchLockedTarget(press));
3807 // The event-handler removes |window| from its parent on the first 3801 EXPECT_4_EVENTS(delegate->events(),
3808 // touch-cancel event, so it won't receive the second touch-cancel event. 3802 ui::ET_GESTURE_PINCH_END,
3809 EXPECT_EQ(1, handler->touch_cancelled_count()); 3803 ui::ET_GESTURE_SCROLL_END,
3804 ui::ET_GESTURE_END,
3805 ui::ET_GESTURE_END);
3806 const std::vector<gfx::PointF>& points = handler->touch_points();
3807 EXPECT_EQ(2U, points.size());
3808 EXPECT_EQ(gfx::Point(101, 201), points[0]);
3809 EXPECT_EQ(gfx::Point(350, 300), points[1]);
3810 } 3810 }
3811 3811
3812 // Check that appropriate touch events generate show press events 3812 // Check that appropriate touch events generate show press events
3813 TEST_P(GestureRecognizerTest, GestureEventShowPress) { 3813 TEST_P(GestureRecognizerTest, GestureEventShowPress) {
3814 scoped_ptr<GestureEventConsumeDelegate> delegate( 3814 scoped_ptr<GestureEventConsumeDelegate> delegate(
3815 new GestureEventConsumeDelegate()); 3815 new GestureEventConsumeDelegate());
3816 TimedEvents tes; 3816 TimedEvents tes;
3817 const int kWindowWidth = 123; 3817 const int kWindowWidth = 123;
3818 const int kWindowHeight = 45; 3818 const int kWindowHeight = 45;
3819 const int kTouchId = 2; 3819 const int kTouchId = 2;
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 EXPECT_TRUE(delegate->tap()); 4573 EXPECT_TRUE(delegate->tap());
4574 EXPECT_FALSE(delegate->long_press()); 4574 EXPECT_FALSE(delegate->long_press());
4575 } 4575 }
4576 4576
4577 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4577 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4578 GestureRecognizerTest, 4578 GestureRecognizerTest,
4579 ::testing::Bool()); 4579 ::testing::Bool());
4580 4580
4581 } // namespace test 4581 } // namespace test
4582 } // namespace aura 4582 } // namespace aura
OLDNEW
« no previous file with comments | « no previous file | ui/aura/window_event_dispatcher.cc » ('j') | ui/aura/window_event_dispatcher.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698