OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/basictypes.h" | 5 #include "base/basictypes.h" |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 active_scroll_begin_event_.reset(new GestureEventData(gesture)); | 136 active_scroll_begin_event_.reset(new GestureEventData(gesture)); |
137 gestures_.push_back(gesture); | 137 gestures_.push_back(gesture); |
138 } | 138 } |
139 | 139 |
140 void SetUpWithConfig(const GestureProvider::Config& config) { | 140 void SetUpWithConfig(const GestureProvider::Config& config) { |
141 gesture_provider_.reset(new GestureProvider(config, this)); | 141 gesture_provider_.reset(new GestureProvider(config, this)); |
142 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); | 142 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); |
143 } | 143 } |
144 | 144 |
145 void ResetGestureDetection() { | 145 void ResetGestureDetection() { |
146 CancelActiveTouchSequence(); | 146 gesture_provider_->ResetDetection(); |
147 gestures_.clear(); | 147 gestures_.clear(); |
148 } | 148 } |
149 | |
149 bool CancelActiveTouchSequence() { | 150 bool CancelActiveTouchSequence() { |
150 if (!gesture_provider_->current_down_event()) | 151 if (!gesture_provider_->current_down_event()) |
151 return false; | 152 return false; |
152 return gesture_provider_->OnTouchEvent( | 153 return gesture_provider_->OnTouchEvent( |
153 *gesture_provider_->current_down_event()->Cancel()); | 154 *gesture_provider_->current_down_event()->Cancel()); |
154 } | 155 } |
155 | 156 |
156 bool HasReceivedGesture(EventType type) const { | 157 bool HasReceivedGesture(EventType type) const { |
157 for (size_t i = 0; i < gestures_.size(); ++i) { | 158 for (size_t i = 0; i < gestures_.size(); ++i) { |
158 if (gestures_[i].type() == type) | 159 if (gestures_[i].type() == type) |
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
602 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 603 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
603 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); | 604 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); |
604 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); | 605 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); |
605 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 606 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
606 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | 607 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
607 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); | 608 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); |
608 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) | 609 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) |
609 << "FlingStart should have the time of the ACTION_UP"; | 610 << "FlingStart should have the time of the ACTION_UP"; |
610 } | 611 } |
611 | 612 |
612 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) { | 613 TEST_F(GestureProviderTest, GestureCancelledOnCancelEvent) { |
613 const base::TimeTicks event_time = TimeTicks::Now(); | 614 const base::TimeTicks event_time = TimeTicks::Now(); |
614 | 615 |
615 MockMotionEvent event = | 616 MockMotionEvent event = |
616 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 617 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
617 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 618 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
618 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 619 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
619 | 620 |
620 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + | 621 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + |
621 kOneMicrosecond); | 622 kOneMicrosecond); |
622 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); | 623 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); |
623 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 624 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
624 | 625 |
625 // The long press triggers window focus loss by opening a context menu. | 626 // The long press triggers window focus loss by opening a context menu. |
tdresser
2014/11/11 19:06:47
Update comment.
jdduke (slow)
2014/11/11 22:21:56
Done.
| |
626 EXPECT_TRUE(CancelActiveTouchSequence()); | 627 EXPECT_TRUE(CancelActiveTouchSequence()); |
627 EXPECT_FALSE(HasDownEvent()); | 628 EXPECT_FALSE(HasDownEvent()); |
628 | 629 |
629 // A final ACTION_UP should have no effect. | 630 // A final ACTION_UP should have no effect. |
630 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, | 631 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
631 MotionEvent::ACTION_UP); | 632 MotionEvent::ACTION_UP); |
632 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | 633 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); |
633 } | 634 } |
634 | 635 |
636 TEST_F(GestureProviderTest, GestureCancelledOnDetectionReset) { | |
637 const base::TimeTicks event_time = TimeTicks::Now(); | |
638 | |
639 MockMotionEvent event = | |
640 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
641 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
642 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | |
643 | |
644 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + | |
645 kOneMicrosecond); | |
646 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); | |
647 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | |
648 | |
649 ResetGestureDetection(); | |
650 EXPECT_FALSE(HasDownEvent()); | |
651 | |
652 // A final ACTION_UP should have no effect. | |
653 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, | |
654 MotionEvent::ACTION_UP); | |
655 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | |
656 } | |
657 | |
635 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) { | 658 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) { |
636 base::TimeTicks event_time = base::TimeTicks::Now(); | 659 base::TimeTicks event_time = base::TimeTicks::Now(); |
637 | 660 |
638 MockMotionEvent event = | 661 MockMotionEvent event = |
639 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 662 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
640 | 663 |
641 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 664 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
642 | 665 |
643 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 666 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
644 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | 667 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2493 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2516 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
2494 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | 2517 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); |
2495 | 2518 |
2496 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | 2519 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); |
2497 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | 2520 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
2498 EXPECT_EQ(gfx::RectF(0, 0, 20, 20), | 2521 EXPECT_EQ(gfx::RectF(0, 0, 20, 20), |
2499 GetMostRecentGestureEvent().details.bounding_box()); | 2522 GetMostRecentGestureEvent().details.bounding_box()); |
2500 } | 2523 } |
2501 | 2524 |
2502 } // namespace ui | 2525 } // namespace ui |
OLD | NEW |