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 } | 136 } |
137 | 137 |
138 base::TimeDelta GetLongPressTimeout() const { | 138 base::TimeDelta GetLongPressTimeout() const { |
139 return GetDefaultConfig().gesture_detector_config.longpress_timeout; | 139 return GetDefaultConfig().gesture_detector_config.longpress_timeout; |
140 } | 140 } |
141 | 141 |
142 base::TimeDelta GetShowPressTimeout() const { | 142 base::TimeDelta GetShowPressTimeout() const { |
143 return GetDefaultConfig().gesture_detector_config.showpress_timeout; | 143 return GetDefaultConfig().gesture_detector_config.showpress_timeout; |
144 } | 144 } |
145 | 145 |
| 146 void SetBeginEndTypesEnabled(bool enabled) { |
| 147 GestureProvider::Config config = GetDefaultConfig(); |
| 148 config.gesture_begin_end_types_enabled = true; |
| 149 gesture_provider_.reset(new GestureProvider(config, this)); |
| 150 gesture_provider_->SetMultiTouchSupportEnabled(false); |
| 151 } |
| 152 |
146 protected: | 153 protected: |
147 void CheckScrollEventSequenceForEndActionType( | 154 void CheckScrollEventSequenceForEndActionType( |
148 MotionEvent::Action end_action_type) { | 155 MotionEvent::Action end_action_type) { |
149 base::TimeTicks event_time = base::TimeTicks::Now(); | 156 base::TimeTicks event_time = base::TimeTicks::Now(); |
150 const int scroll_to_x = kFakeCoordX + 100; | 157 const int scroll_to_x = kFakeCoordX + 100; |
151 const int scroll_to_y = kFakeCoordY + 100; | 158 const int scroll_to_y = kFakeCoordY + 100; |
152 | 159 |
153 MockMotionEvent event = | 160 MockMotionEvent event = |
154 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 161 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
155 | 162 |
(...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1053 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, | 1060 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
1054 MotionEvent::ACTION_UP); | 1061 MotionEvent::ACTION_UP); |
1055 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | 1062 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); |
1056 | 1063 |
1057 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, | 1064 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, |
1058 MotionEvent::ACTION_DOWN); | 1065 MotionEvent::ACTION_DOWN); |
1059 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1066 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1060 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1067 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
1061 } | 1068 } |
1062 | 1069 |
| 1070 // Verify that gesture begin and gesture end events are dispatched correctly. |
| 1071 TEST_F(GestureProviderTest, GestureBeginAndEnd) { |
| 1072 SetBeginEndTypesEnabled(true); |
| 1073 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 1074 |
| 1075 EXPECT_EQ(0U, GetReceivedGestureCount()); |
| 1076 MockMotionEvent event = |
| 1077 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 1078 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1079 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); |
| 1080 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1081 EXPECT_EQ(2U, GetReceivedGestureCount()); |
| 1082 |
| 1083 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
| 1084 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1085 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
| 1086 EXPECT_EQ(3U, GetReceivedGestureCount()); |
| 1087 |
| 1088 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
| 1089 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1090 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
| 1091 EXPECT_EQ(4U, GetReceivedGestureCount()); |
| 1092 |
| 1093 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
| 1094 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1095 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1096 EXPECT_EQ(5U, GetReceivedGestureCount()); |
| 1097 |
| 1098 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
| 1099 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1100 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
| 1101 EXPECT_EQ(6U, GetReceivedGestureCount()); |
| 1102 |
| 1103 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
| 1104 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1105 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1106 EXPECT_EQ(7U, GetReceivedGestureCount()); |
| 1107 |
| 1108 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
| 1109 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1110 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1111 EXPECT_EQ(8U, GetReceivedGestureCount()); |
| 1112 |
| 1113 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); |
| 1114 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1115 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1116 EXPECT_EQ(9U, GetReceivedGestureCount()); |
| 1117 |
| 1118 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 1119 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1120 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(9).type); |
| 1121 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(10).type); |
| 1122 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1123 EXPECT_EQ(12U, GetReceivedGestureCount()); |
| 1124 |
| 1125 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL); |
| 1126 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1127 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(12).type); |
| 1128 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1129 EXPECT_EQ(14U, GetReceivedGestureCount()); |
| 1130 |
| 1131 |
| 1132 } |
| 1133 |
1063 } // namespace ui | 1134 } // namespace ui |
OLD | NEW |