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

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: Fixed the unit tests 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 587 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() : touch_released_count_(0),
606 touch_pressed_count_(0), 606 touch_pressed_count_(0),
607 touch_moved_count_(0), 607 touch_moved_count_(0),
608 touch_cancelled_count_(0) { 608 touch_points_() {
tdresser 2014/08/13 19:57:57 You don't need to initialize the std::vector.
lanwei 2014/08/14 00:38:45 Done.
609 } 609 }
610 610
611 virtual ~TestEventHandler() {} 611 virtual ~TestEventHandler() {}
612 612
613 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { 613 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE {
614 switch (event->type()) { 614 switch (event->type()) {
615 case ui::ET_TOUCH_RELEASED: 615 case ui::ET_TOUCH_RELEASED:
616 touch_released_count_++; 616 touch_released_count_++;
617 break; 617 break;
618 case ui::ET_TOUCH_PRESSED: 618 case ui::ET_TOUCH_PRESSED:
619 touch_pressed_count_++; 619 touch_pressed_count_++;
620 break; 620 break;
621 case ui::ET_TOUCH_MOVED: 621 case ui::ET_TOUCH_MOVED:
622 touch_moved_count_++; 622 touch_moved_count_++;
623 break; 623 break;
624 case ui::ET_TOUCH_CANCELLED: 624 case ui::ET_TOUCH_CANCELLED:
625 touch_cancelled_count_++; 625 touch_points_.push_back(event->location());
626 break; 626 break;
627 default: 627 default:
628 break; 628 break;
629 } 629 }
630 } 630 }
631 631
632 void Reset() { 632 void Reset() {
633 touch_released_count_ = 0; 633 touch_released_count_ = 0;
634 touch_pressed_count_ = 0; 634 touch_pressed_count_ = 0;
635 touch_moved_count_ = 0; 635 touch_moved_count_ = 0;
636 touch_cancelled_count_ = 0; 636 touch_points_.clear();
637 } 637 }
638 638
639 int touch_released_count() const { return touch_released_count_; } 639 int touch_released_count() const { return touch_released_count_; }
640 int touch_pressed_count() const { return touch_pressed_count_; } 640 int touch_pressed_count() const { return touch_pressed_count_; }
641 int touch_moved_count() const { return touch_moved_count_; } 641 int touch_moved_count() const { return touch_moved_count_; }
642 int touch_cancelled_count() const { return touch_cancelled_count_; } 642 int touch_cancelled_count() const { return (int) touch_points_.size(); }
tdresser 2014/08/13 19:57:58 Use static_cast<int>(touch_points_.size()); We don
lanwei 2014/08/14 00:38:46 Done.
643 std::vector<gfx::PointF> touch_points() const { return touch_points_; }
tdresser 2014/08/13 19:57:57 Return a const std::vector<gfx::PointF>&, to avoid
lanwei 2014/08/14 00:38:46 Done.
643 644
644 private: 645 private:
645 int touch_released_count_; 646 int touch_released_count_;
646 int touch_pressed_count_; 647 int touch_pressed_count_;
647 int touch_moved_count_; 648 int touch_moved_count_;
648 int touch_cancelled_count_; 649 std::vector<gfx::PointF> touch_points_;
649 650
650 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); 651 DISALLOW_COPY_AND_ASSIGN(TestEventHandler);
651 }; 652 };
652 653
653 // Removes the target window from its parent when it receives a touch-cancel 654 // Removes the target window from its parent when it receives a touch-cancel
654 // event. 655 // event.
655 class RemoveOnTouchCancelHandler : public TestEventHandler { 656 class RemoveOnTouchCancelHandler : public TestEventHandler {
656 public: 657 public:
657 RemoveOnTouchCancelHandler() {} 658 RemoveOnTouchCancelHandler() {}
658 virtual ~RemoveOnTouchCancelHandler() {} 659 virtual ~RemoveOnTouchCancelHandler() {}
(...skipping 3103 matching lines...) Expand 10 before | Expand all | Expand 10 after
3762 EXPECT_FALSE(delegate->tap()); 3763 EXPECT_FALSE(delegate->tap());
3763 EXPECT_FALSE(delegate->tap_down()); 3764 EXPECT_FALSE(delegate->tap_down());
3764 EXPECT_TRUE(delegate->tap_cancel()); 3765 EXPECT_TRUE(delegate->tap_cancel());
3765 EXPECT_FALSE(delegate->begin()); 3766 EXPECT_FALSE(delegate->begin());
3766 EXPECT_FALSE(delegate->scroll_update()); 3767 EXPECT_FALSE(delegate->scroll_update());
3767 EXPECT_FALSE(delegate->scroll_end()); 3768 EXPECT_FALSE(delegate->scroll_end());
3768 } 3769 }
3769 3770
3770 TEST_P(GestureRecognizerTest, 3771 TEST_P(GestureRecognizerTest,
3771 TransferEventDispatchesTouchCancel) { 3772 TransferEventDispatchesTouchCancel) {
3773 // Disabled for not unified GR
tdresser 2014/08/13 19:57:57 This is a little hard to read (double negative!) M
lanwei 2014/08/14 00:38:46 Done.
3774 if (!UsingUnifiedGR())
3775 return;
3776
3772 scoped_ptr<GestureEventConsumeDelegate> delegate( 3777 scoped_ptr<GestureEventConsumeDelegate> delegate(
3773 new GestureEventConsumeDelegate()); 3778 new GestureEventConsumeDelegate());
3774 TimedEvents tes; 3779 TimedEvents tes;
3775 const int kWindowWidth = 800; 3780 const int kWindowWidth = 800;
3776 const int kWindowHeight = 600; 3781 const int kWindowHeight = 600;
3777 const int kTouchId = 2; 3782 const int kTouchId = 2;
3778 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight); 3783 gfx::Rect bounds(0, 0, kWindowWidth, kWindowHeight);
3779 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate( 3784 scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
3780 delegate.get(), -1234, bounds, root_window())); 3785 delegate.get(), -1234, bounds, root_window()));
3781 scoped_ptr<RemoveOnTouchCancelHandler> 3786 scoped_ptr<TestEventHandler>
tdresser 2014/08/13 19:57:58 We should be able to delete the RemoveOnTouchCance
lanwei 2014/08/14 00:38:45 Done.
tdresser 2014/08/13 19:57:57 Would this fit on one line?
lanwei 2014/08/14 00:38:46 Done.
3782 handler(new RemoveOnTouchCancelHandler()); 3787 handler(new TestEventHandler());
3783 window->AddPreTargetHandler(handler.get()); 3788 window->AddPreTargetHandler(handler.get());
3784 3789
3785 // Start a gesture sequence on |window|. Then transfer the events to NULL. 3790 // Start a gesture sequence on |window|. Then transfer the events to NULL.
3786 // Make sure |window| receives a touch-cancel event. 3791 // Make sure |window| receives a touch-cancel event.
3787 delegate->Reset(); 3792 delegate->Reset();
3788 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), 3793 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201),
3789 kTouchId, tes.Now()); 3794 kTouchId, tes.Now());
3795 DispatchEventUsingWindowDispatcher(&press);
3796 EXPECT_2_EVENTS(delegate->events(),
3797 ui::ET_GESTURE_BEGIN,
tdresser 2014/08/13 19:57:58 These aren't indented correctly (silly eclipse).
lanwei 2014/08/14 00:38:46 Done.
3798 ui::ET_GESTURE_TAP_DOWN);
3799 delegate->Reset();
3790 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 1, tes.Now()); 3800 ui::TouchEvent p2(ui::ET_TOUCH_PRESSED, gfx::Point(50, 50), 1, tes.Now());
tdresser 2014/08/13 19:57:57 Store the touch id in another const int, similar t
lanwei 2014/08/14 00:38:45 Done.
3791 DispatchEventUsingWindowDispatcher(&press);
3792 DispatchEventUsingWindowDispatcher(&p2); 3801 DispatchEventUsingWindowDispatcher(&p2);
3793 EXPECT_FALSE(delegate->tap()); 3802 EXPECT_2_EVENTS(delegate->events(),
3794 EXPECT_TRUE(delegate->tap_down()); 3803 ui::ET_GESTURE_TAP_CANCEL,
3795 EXPECT_TRUE(delegate->tap_cancel()); 3804 ui::ET_GESTURE_BEGIN);
3796 EXPECT_TRUE(delegate->begin()); 3805 delegate->Reset();
3806 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(350, 300), 1, tes.Now());
3807 DispatchEventUsingWindowDispatcher(&move);
3808 EXPECT_3_EVENTS(delegate->events(),
3809 ui::ET_GESTURE_SCROLL_BEGIN,
3810 ui::ET_GESTURE_SCROLL_UPDATE,
3811 ui::ET_GESTURE_PINCH_BEGIN);
3797 EXPECT_EQ(2, handler->touch_pressed_count()); 3812 EXPECT_EQ(2, handler->touch_pressed_count());
3798 delegate->Reset(); 3813 delegate->Reset();
3799 handler->Reset(); 3814 handler->Reset();
3800 3815
3801 ui::GestureRecognizer* gesture_recognizer = ui::GestureRecognizer::Get(); 3816 ui::GestureRecognizer* gesture_recognizer = ui::GestureRecognizer::Get();
3802 EXPECT_EQ(window.get(), 3817 EXPECT_EQ(window.get(),
3803 gesture_recognizer->GetTouchLockedTarget(press)); 3818 gesture_recognizer->GetTouchLockedTarget(press));
3804 gesture_recognizer->TransferEventsTo(window.get(), NULL); 3819 gesture_recognizer->TransferEventsTo(window.get(), NULL);
3805 EXPECT_EQ(NULL, 3820 EXPECT_EQ(NULL,
3806 gesture_recognizer->GetTouchLockedTarget(press)); 3821 gesture_recognizer->GetTouchLockedTarget(press));
3807 // The event-handler removes |window| from its parent on the first 3822 EXPECT_4_EVENTS(delegate->events(),
3808 // touch-cancel event, so it won't receive the second touch-cancel event. 3823 ui::ET_GESTURE_PINCH_END,
3809 EXPECT_EQ(1, handler->touch_cancelled_count()); 3824 ui::ET_GESTURE_SCROLL_END,
3825 ui::ET_GESTURE_END,
3826 ui::ET_GESTURE_END);
3827 const std::vector<gfx::PointF>& points = handler->touch_points();
3828 EXPECT_EQ(2, (int) points.size());
tdresser 2014/08/13 19:57:57 To avoid the cast: EXPECT_EQ(2U, points.size());
lanwei 2014/08/14 00:38:46 Done.
3829 EXPECT_EQ(gfx::Point(350, 300), points[0]);
3830 EXPECT_EQ(gfx::Point(101, 201), points[1]);
3810 } 3831 }
3811 3832
3812 // Check that appropriate touch events generate show press events 3833 // Check that appropriate touch events generate show press events
3813 TEST_P(GestureRecognizerTest, GestureEventShowPress) { 3834 TEST_P(GestureRecognizerTest, GestureEventShowPress) {
3814 scoped_ptr<GestureEventConsumeDelegate> delegate( 3835 scoped_ptr<GestureEventConsumeDelegate> delegate(
3815 new GestureEventConsumeDelegate()); 3836 new GestureEventConsumeDelegate());
3816 TimedEvents tes; 3837 TimedEvents tes;
3817 const int kWindowWidth = 123; 3838 const int kWindowWidth = 123;
3818 const int kWindowHeight = 45; 3839 const int kWindowHeight = 45;
3819 const int kTouchId = 2; 3840 const int kTouchId = 2;
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
4573 EXPECT_TRUE(delegate->tap()); 4594 EXPECT_TRUE(delegate->tap());
4574 EXPECT_FALSE(delegate->long_press()); 4595 EXPECT_FALSE(delegate->long_press());
4575 } 4596 }
4576 4597
4577 INSTANTIATE_TEST_CASE_P(GestureRecognizer, 4598 INSTANTIATE_TEST_CASE_P(GestureRecognizer,
4578 GestureRecognizerTest, 4599 GestureRecognizerTest,
4579 ::testing::Bool()); 4600 ::testing::Bool());
4580 4601
4581 } // namespace test 4602 } // namespace test
4582 } // namespace aura 4603 } // 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