| 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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 294 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 295 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 295 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 296 | 296 |
| 297 Wait(GetShowPressTimeout() + kFiveMilliseconds); | 297 Wait(GetShowPressTimeout() + kFiveMilliseconds); |
| 298 EXPECT_EQ(GESTURE_SHOW_PRESS, GetMostRecentGestureEventType()); | 298 EXPECT_EQ(GESTURE_SHOW_PRESS, GetMostRecentGestureEventType()); |
| 299 | 299 |
| 300 Wait(GetLongPressTimeout() + kFiveMilliseconds); | 300 Wait(GetLongPressTimeout() + kFiveMilliseconds); |
| 301 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 301 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
| 302 | 302 |
| 303 // The long press triggers window focus loss by opening a context menu | 303 // The long press triggers window focus loss by opening a context menu |
| 304 gesture_provider_->CancelActiveTouchSequence(); | 304 EXPECT_TRUE(gesture_provider_->CancelActiveTouchSequence()); |
| 305 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | 305 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); |
| 306 } | 306 } |
| 307 | 307 |
| 308 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) { | 308 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) { |
| 309 base::TimeTicks event_time = base::TimeTicks::Now(); | 309 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 310 | 310 |
| 311 MockMotionEvent event = | 311 MockMotionEvent event = |
| 312 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 312 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 313 | 313 |
| 314 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 314 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| (...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 | 963 |
| 964 MockMotionEvent event = | 964 MockMotionEvent event = |
| 965 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 965 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 966 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 966 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 967 | 967 |
| 968 const base::TimeDelta long_press_timeout = | 968 const base::TimeDelta long_press_timeout = |
| 969 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; | 969 GetLongPressTimeout() + GetShowPressTimeout() + kFiveMilliseconds * 2; |
| 970 Wait(long_press_timeout); | 970 Wait(long_press_timeout); |
| 971 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 971 EXPECT_EQ(GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
| 972 | 972 |
| 973 gesture_provider_->CancelActiveTouchSequence(); | 973 EXPECT_TRUE(gesture_provider_->CancelActiveTouchSequence()); |
| 974 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | 974 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); |
| 975 | 975 |
| 976 event = ObtainMotionEvent(event_time + long_press_timeout, | 976 event = ObtainMotionEvent(event_time + long_press_timeout, |
| 977 MotionEvent::ACTION_UP); | 977 MotionEvent::ACTION_UP); |
| 978 gesture_provider_->OnTouchEvent(event); | 978 gesture_provider_->OnTouchEvent(event); |
| 979 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP)); | 979 EXPECT_FALSE(HasReceivedGesture(GESTURE_LONG_TAP)); |
| 980 } | 980 } |
| 981 | 981 |
| 982 // Verify that ignoring the remaining touch sequence triggers proper touch and | 982 // Verify that ignoring the remaining touch sequence triggers proper touch and |
| 983 // gesture cancellation. | 983 // gesture cancellation. |
| 984 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { | 984 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { |
| 985 base::TimeTicks event_time = base::TimeTicks::Now(); | 985 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 986 | 986 |
| 987 gesture_provider_->CancelActiveTouchSequence(); | 987 EXPECT_FALSE(gesture_provider_->CancelActiveTouchSequence()); |
| 988 EXPECT_EQ(0U, GetReceivedGestureCount()); | 988 EXPECT_EQ(0U, GetReceivedGestureCount()); |
| 989 | 989 |
| 990 MockMotionEvent event = | 990 MockMotionEvent event = |
| 991 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 991 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 992 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 992 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 993 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 993 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 994 | 994 |
| 995 gesture_provider_->CancelActiveTouchSequence(); | 995 ASSERT_TRUE(gesture_provider_->CancelActiveTouchSequence()); |
| 996 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | 996 EXPECT_EQ(GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); |
| 997 | 997 |
| 998 // Subsequent MotionEvent's are dropped until ACTION_DOWN. | 998 // Subsequent MotionEvent's are dropped until ACTION_DOWN. |
| 999 event = ObtainMotionEvent(event_time + kFiveMilliseconds, | 999 event = ObtainMotionEvent(event_time + kFiveMilliseconds, |
| 1000 MotionEvent::ACTION_MOVE); | 1000 MotionEvent::ACTION_MOVE); |
| 1001 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | 1001 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); |
| 1002 | 1002 |
| 1003 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, | 1003 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 2, |
| 1004 MotionEvent::ACTION_UP); | 1004 MotionEvent::ACTION_UP); |
| 1005 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | 1005 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); |
| 1006 | 1006 |
| 1007 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, | 1007 event = ObtainMotionEvent(event_time + kFiveMilliseconds * 3, |
| 1008 MotionEvent::ACTION_DOWN); | 1008 MotionEvent::ACTION_DOWN); |
| 1009 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1009 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1010 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1010 EXPECT_EQ(GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1011 } | 1011 } |
| 1012 | 1012 |
| 1013 } // namespace ui | 1013 } // namespace ui |
| OLD | NEW |