| 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 int motion_event_id = 0; | 159 int motion_event_id = 0; |
| 153 | 160 |
| 154 MockMotionEvent event = | 161 MockMotionEvent event = |
| 155 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 162 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| (...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, | 1121 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
| 1115 MotionEvent::ACTION_UP); | 1122 MotionEvent::ACTION_UP); |
| 1116 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); | 1123 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); |
| 1117 | 1124 |
| 1118 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, | 1125 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, |
| 1119 MotionEvent::ACTION_DOWN); | 1126 MotionEvent::ACTION_DOWN); |
| 1120 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1127 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1121 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1128 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1122 } | 1129 } |
| 1123 | 1130 |
| 1131 // Verify that gesture begin and gesture end events are dispatched correctly. |
| 1132 TEST_F(GestureProviderTest, GestureBeginAndEnd) { |
| 1133 SetBeginEndTypesEnabled(true); |
| 1134 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 1135 |
| 1136 EXPECT_EQ(0U, GetReceivedGestureCount()); |
| 1137 MockMotionEvent event = |
| 1138 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 1139 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1140 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); |
| 1141 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1142 EXPECT_EQ(2U, GetReceivedGestureCount()); |
| 1143 |
| 1144 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
| 1145 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1146 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
| 1147 EXPECT_EQ(3U, GetReceivedGestureCount()); |
| 1148 |
| 1149 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
| 1150 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1151 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
| 1152 EXPECT_EQ(4U, GetReceivedGestureCount()); |
| 1153 |
| 1154 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
| 1155 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1156 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1157 EXPECT_EQ(5U, GetReceivedGestureCount()); |
| 1158 |
| 1159 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
| 1160 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1161 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
| 1162 EXPECT_EQ(6U, GetReceivedGestureCount()); |
| 1163 |
| 1164 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
| 1165 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1166 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1167 EXPECT_EQ(7U, GetReceivedGestureCount()); |
| 1168 |
| 1169 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
| 1170 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1171 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1172 EXPECT_EQ(8U, GetReceivedGestureCount()); |
| 1173 |
| 1174 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); |
| 1175 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1176 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1177 EXPECT_EQ(9U, GetReceivedGestureCount()); |
| 1178 |
| 1179 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
| 1180 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1181 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(9).type); |
| 1182 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(10).type); |
| 1183 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
| 1184 EXPECT_EQ(12U, GetReceivedGestureCount()); |
| 1185 |
| 1186 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL); |
| 1187 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 1188 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(12).type); |
| 1189 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
| 1190 EXPECT_EQ(14U, GetReceivedGestureCount()); |
| 1191 |
| 1192 |
| 1193 } |
| 1194 |
| 1124 } // namespace ui | 1195 } // namespace ui |
| OLD | NEW |