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

Side by Side Diff: ui/events/gesture_detection/gesture_provider_unittest.cc

Issue 212663010: Store the id of a contributing motion event in GestureEventData (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address jdduke's comments. Created 6 years, 8 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 | Annotate | Revision Log
OLDNEW
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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 protected: 146 protected:
147 void CheckScrollEventSequenceForEndActionType( 147 void CheckScrollEventSequenceForEndActionType(
148 MotionEvent::Action end_action_type) { 148 MotionEvent::Action end_action_type) {
149 base::TimeTicks event_time = base::TimeTicks::Now(); 149 base::TimeTicks event_time = base::TimeTicks::Now();
150 const int scroll_to_x = kFakeCoordX + 100; 150 const int scroll_to_x = kFakeCoordX + 100;
151 const int scroll_to_y = kFakeCoordY + 100; 151 const int scroll_to_y = kFakeCoordY + 100;
152 int motion_event_id = 0;
152 153
153 MockMotionEvent event = 154 MockMotionEvent event =
154 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 155 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
156 event.SetId(++motion_event_id);
155 157
156 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 158 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
157 159
158 event = ObtainMotionEvent(event_time + kOneSecond, 160 event = ObtainMotionEvent(event_time + kOneSecond,
159 MotionEvent::ACTION_MOVE, 161 MotionEvent::ACTION_MOVE,
160 scroll_to_x, 162 scroll_to_x,
161 scroll_to_y); 163 scroll_to_y);
164 event.SetId(++motion_event_id);
165
162 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 166 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
163 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 167 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
164 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 168 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
169 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
165 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 170 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
166 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, " 171 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, "
167 "ScrollBegin and ScrollBy " 172 "ScrollBegin and ScrollBy "
168 "should have been sent"; 173 "should have been sent";
169 174
170 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(1).type); 175 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(1).type);
176 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
171 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); 177 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type);
178 EXPECT_EQ(motion_event_id, GetReceivedGesture(2).motion_event_id);
172 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time) 179 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time)
173 << "ScrollBegin should have the time of the ACTION_MOVE"; 180 << "ScrollBegin should have the time of the ACTION_MOVE";
174 181
175 event = ObtainMotionEvent( 182 event = ObtainMotionEvent(
176 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); 183 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
184 event.SetId(++motion_event_id);
185
177 gesture_provider_->OnTouchEvent(event); 186 gesture_provider_->OnTouchEvent(event);
178 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 187 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
179 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 188 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
180 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 189 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
190 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
181 } 191 }
182 192
183 static void RunTasksAndWait(base::TimeDelta delay) { 193 static void RunTasksAndWait(base::TimeDelta delay) {
184 base::MessageLoop::current()->PostDelayedTask( 194 base::MessageLoop::current()->PostDelayedTask(
185 FROM_HERE, base::MessageLoop::QuitClosure(), delay); 195 FROM_HERE, base::MessageLoop::QuitClosure(), delay);
186 base::MessageLoop::current()->Run(); 196 base::MessageLoop::current()->Run();
187 } 197 }
188 198
189 std::vector<GestureEventData> gestures_; 199 std::vector<GestureEventData> gestures_;
190 scoped_ptr<GestureProvider> gesture_provider_; 200 scoped_ptr<GestureProvider> gesture_provider_;
191 scoped_ptr<GestureEventData> active_scroll_begin_event_; 201 scoped_ptr<GestureEventData> active_scroll_begin_event_;
192 base::MessageLoopForUI message_loop_; 202 base::MessageLoopForUI message_loop_;
193 }; 203 };
194 204
195 // Verify that a DOWN followed shortly by an UP will trigger a single tap. 205 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
196 TEST_F(GestureProviderTest, GestureTapTap) { 206 TEST_F(GestureProviderTest, GestureTapTap) {
197 base::TimeTicks event_time = base::TimeTicks::Now(); 207 base::TimeTicks event_time = base::TimeTicks::Now();
208 int motion_event_id = 0;
198 209
199 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 210 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
200 211
201 MockMotionEvent event = 212 MockMotionEvent event =
202 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 213 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
214 event.SetId(++motion_event_id);
215
203 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 216 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
204 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 217 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
205 218
206 event = ObtainMotionEvent(event_time + kOneMicrosecond, 219 event = ObtainMotionEvent(event_time + kOneMicrosecond,
207 MotionEvent::ACTION_UP); 220 MotionEvent::ACTION_UP);
221 event.SetId(++motion_event_id);
222
208 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 223 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
209 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 224 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
210 // Ensure tap details have been set. 225 // Ensure tap details have been set.
211 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); 226 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width());
212 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); 227 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height());
213 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 228 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
229 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
214 } 230 }
215 231
216 // Verify that a DOWN followed shortly by an UP will trigger 232 // Verify that a DOWN followed shortly by an UP will trigger
217 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled. 233 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
218 TEST_F(GestureProviderTest, GestureTapTapWithDelay) { 234 TEST_F(GestureProviderTest, GestureTapTapWithDelay) {
219 base::TimeTicks event_time = base::TimeTicks::Now(); 235 base::TimeTicks event_time = base::TimeTicks::Now();
236 int motion_event_id = 0;
220 237
221 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 238 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
222 239
223 MockMotionEvent event = 240 MockMotionEvent event =
224 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 241 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
242 event.SetId(++motion_event_id);
243
225 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 244 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
226 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 245 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
246 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
227 247
228 event = ObtainMotionEvent(event_time + kOneMicrosecond, 248 event = ObtainMotionEvent(event_time + kOneMicrosecond,
229 MotionEvent::ACTION_UP); 249 MotionEvent::ACTION_UP);
250 event.SetId(++motion_event_id);
251
230 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 252 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
231 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 253 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
232 // Ensure tap details have been set. 254 // Ensure tap details have been set.
233 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); 255 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width());
234 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); 256 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height());
235 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 257 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
258 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
236 259
237 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP)); 260 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP));
238 } 261 }
239 262
240 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). 263 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG).
241 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) { 264 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) {
242 base::TimeTicks event_time = TimeTicks::Now(); 265 base::TimeTicks event_time = TimeTicks::Now();
243 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; 266 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
267 int motion_event_id = 0;
244 268
245 MockMotionEvent event = 269 MockMotionEvent event =
246 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 270 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
271 event.SetId(++motion_event_id);
247 272
248 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 273 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
249 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 274 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
275 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
250 276
251 event = ObtainMotionEvent(event_time + delta_time, 277 event = ObtainMotionEvent(event_time + delta_time,
252 MotionEvent::ACTION_MOVE, 278 MotionEvent::ACTION_MOVE,
253 kFakeCoordX * 10, 279 kFakeCoordX * 10,
254 kFakeCoordY * 10); 280 kFakeCoordY * 10);
281 event.SetId(++motion_event_id);
255 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 282 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
256 283
257 event = ObtainMotionEvent(event_time + delta_time * 2, 284 event = ObtainMotionEvent(event_time + delta_time * 2,
258 MotionEvent::ACTION_UP, 285 MotionEvent::ACTION_UP,
259 kFakeCoordX * 10, 286 kFakeCoordX * 10,
260 kFakeCoordY * 10); 287 kFakeCoordY * 10);
288 event.SetId(++motion_event_id);
289
261 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 290 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
262 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 291 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
292 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
263 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 293 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
264 } 294 }
265 295
266 // Verify that for a normal scroll the following events are sent: 296 // Verify that for a normal scroll the following events are sent:
267 // - ET_GESTURE_SCROLL_BEGIN 297 // - ET_GESTURE_SCROLL_BEGIN
268 // - ET_GESTURE_SCROLL_UPDATE 298 // - ET_GESTURE_SCROLL_UPDATE
269 // - ET_GESTURE_SCROLL_END 299 // - ET_GESTURE_SCROLL_END
270 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { 300 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
271 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP); 301 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP);
272 } 302 }
273 303
274 // Verify that for a cancelled scroll the following events are sent: 304 // Verify that for a cancelled scroll the following events are sent:
275 // - ET_GESTURE_SCROLL_BEGIN 305 // - ET_GESTURE_SCROLL_BEGIN
276 // - ET_GESTURE_SCROLL_UPDATE 306 // - ET_GESTURE_SCROLL_UPDATE
277 // - ET_GESTURE_SCROLL_END 307 // - ET_GESTURE_SCROLL_END
278 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) { 308 TEST_F(GestureProviderTest, ScrollEventActionCancelSequence) {
279 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL); 309 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_CANCEL);
280 } 310 }
281 311
282 // Verify that for a normal fling (fling after scroll) the following events are 312 // Verify that for a normal fling (fling after scroll) the following events are
283 // sent: 313 // sent:
284 // - ET_GESTURE_SCROLL_BEGIN 314 // - ET_GESTURE_SCROLL_BEGIN
285 // - ET_SCROLL_FLING_START 315 // - ET_SCROLL_FLING_START
286 TEST_F(GestureProviderTest, FlingEventSequence) { 316 TEST_F(GestureProviderTest, FlingEventSequence) {
287 base::TimeTicks event_time = base::TimeTicks::Now(); 317 base::TimeTicks event_time = base::TimeTicks::Now();
288 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; 318 base::TimeDelta delta_time = kDeltaTimeForFlingSequences;
319 int motion_event_id = 0;
289 320
290 MockMotionEvent event = 321 MockMotionEvent event =
291 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 322 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
323 event.SetId(++motion_event_id);
292 324
293 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 325 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
294 326
295 event = ObtainMotionEvent(event_time + delta_time, 327 event = ObtainMotionEvent(event_time + delta_time,
296 MotionEvent::ACTION_MOVE, 328 MotionEvent::ACTION_MOVE,
297 kFakeCoordX * 5, 329 kFakeCoordX * 5,
298 kFakeCoordY * 5); 330 kFakeCoordY * 5);
331 event.SetId(++motion_event_id);
332
299 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 333 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
300 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 334 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
301 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 335 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
302 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 336 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
337 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
303 ASSERT_EQ(4U, GetReceivedGestureCount()); 338 ASSERT_EQ(4U, GetReceivedGestureCount());
304 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); 339 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type);
340 EXPECT_EQ(motion_event_id, GetReceivedGesture(2).motion_event_id);
305 341
306 // We don't want to take a dependency here on exactly how hints are calculated 342 // We don't want to take a dependency here on exactly how hints are calculated
307 // for a fling (eg. may depend on velocity), so just validate the direction. 343 // for a fling (eg. may depend on velocity), so just validate the direction.
308 int hint_x = GetReceivedGesture(2).details.scroll_x_hint(); 344 int hint_x = GetReceivedGesture(2).details.scroll_x_hint();
309 int hint_y = GetReceivedGesture(2).details.scroll_y_hint(); 345 int hint_y = GetReceivedGesture(2).details.scroll_y_hint();
310 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) 346 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
311 << "ScrollBegin hint should be in positive X axis"; 347 << "ScrollBegin hint should be in positive X axis";
312 348
313 event = ObtainMotionEvent(event_time + delta_time * 2, 349 event = ObtainMotionEvent(event_time + delta_time * 2,
314 MotionEvent::ACTION_UP, 350 MotionEvent::ACTION_UP,
315 kFakeCoordX * 10, 351 kFakeCoordX * 10,
316 kFakeCoordY * 10); 352 kFakeCoordY * 10);
353 event.SetId(++motion_event_id);
354
317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 355 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
318 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 356 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
319 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 357 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
358 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
320 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 359 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
321 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) 360 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
322 << "FlingStart should have the time of the ACTION_UP"; 361 << "FlingStart should have the time of the ACTION_UP";
323 } 362 }
324 363
325 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) { 364 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) {
326 const base::TimeTicks event_time = TimeTicks::Now(); 365 const base::TimeTicks event_time = TimeTicks::Now();
327 366
328 MockMotionEvent event = 367 MockMotionEvent event =
329 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 368 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after
694 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL)); 733 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL));
695 734
696 event = ObtainMotionEvent(event_time + long_press_timeout, 735 event = ObtainMotionEvent(event_time + long_press_timeout,
697 MotionEvent::ACTION_UP); 736 MotionEvent::ACTION_UP);
698 gesture_provider_->OnTouchEvent(event); 737 gesture_provider_->OnTouchEvent(event);
699 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); 738 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP));
700 } 739 }
701 740
702 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { 741 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) {
703 base::TimeTicks event_time = base::TimeTicks::Now(); 742 base::TimeTicks event_time = base::TimeTicks::Now();
743 int motion_event_id = 0;
704 744
705 MockMotionEvent event = ObtainMotionEvent( 745 MockMotionEvent event = ObtainMotionEvent(
706 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 746 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
707 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 747 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
708 748
709 event = ObtainMotionEvent(event_time + kOneMicrosecond, 749 event = ObtainMotionEvent(event_time + kOneMicrosecond,
710 MotionEvent::ACTION_UP, 750 MotionEvent::ACTION_UP,
711 kFakeCoordX, 751 kFakeCoordX,
712 kFakeCoordY); 752 kFakeCoordY);
713 gesture_provider_->OnTouchEvent(event); 753 gesture_provider_->OnTouchEvent(event);
714 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); 754 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType());
715 755
716 event = ObtainMotionEvent(event_time + kOneMicrosecond, 756 event = ObtainMotionEvent(event_time + kOneMicrosecond,
717 MotionEvent::ACTION_DOWN, 757 MotionEvent::ACTION_DOWN,
718 kFakeCoordX, 758 kFakeCoordX,
719 kFakeCoordY); 759 kFakeCoordY);
720 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 760 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
721 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 761 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
722 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); 762 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
723 763
724 const base::TimeDelta long_press_timeout = 764 const base::TimeDelta long_press_timeout =
725 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; 765 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond;
726 RunTasksAndWait(long_press_timeout); 766 RunTasksAndWait(long_press_timeout);
727 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 767 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
728 768
729 event = ObtainMotionEvent(event_time + long_press_timeout, 769 event = ObtainMotionEvent(event_time + long_press_timeout,
730 MotionEvent::ACTION_MOVE, 770 MotionEvent::ACTION_MOVE,
731 kFakeCoordX + 20, 771 kFakeCoordX + 20,
732 kFakeCoordY + 20); 772 kFakeCoordY + 20);
773 event.SetId(++motion_event_id);
774
733 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 775 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
734 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); 776 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType());
777 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
735 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); 778 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress());
736 779
737 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond, 780 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond,
738 MotionEvent::ACTION_UP, 781 MotionEvent::ACTION_UP,
739 kFakeCoordX, 782 kFakeCoordX,
740 kFakeCoordY + 1); 783 kFakeCoordY + 1);
784 event.SetId(++motion_event_id);
741 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 785 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
742 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 786 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
787 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
743 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress()); 788 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress());
744 } 789 }
745 790
746 // Verify that the touch slop region is removed from the first scroll delta to 791 // Verify that the touch slop region is removed from the first scroll delta to
747 // avoid a jump when starting to scroll. 792 // avoid a jump when starting to scroll.
748 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { 793 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) {
749 const int scaled_touch_slop = GetTouchSlop(); 794 const int scaled_touch_slop = GetTouchSlop();
750 const int scroll_delta = 5; 795 const int scroll_delta = 5;
751 796
752 base::TimeTicks event_time = base::TimeTicks::Now(); 797 base::TimeTicks event_time = base::TimeTicks::Now();
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
981 kFakeCoordX, 1026 kFakeCoordX,
982 kFakeCoordY + 200); 1027 kFakeCoordY + 200);
983 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1028 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
984 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END)); 1029 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_END));
985 } 1030 }
986 1031
987 // Verify that pinch zoom sends the proper event sequence. 1032 // Verify that pinch zoom sends the proper event sequence.
988 TEST_F(GestureProviderTest, PinchZoom) { 1033 TEST_F(GestureProviderTest, PinchZoom) {
989 base::TimeTicks event_time = base::TimeTicks::Now(); 1034 base::TimeTicks event_time = base::TimeTicks::Now();
990 const int scaled_touch_slop = GetTouchSlop(); 1035 const int scaled_touch_slop = GetTouchSlop();
1036 int motion_event_id = 0;
991 1037
992 gesture_provider_->SetMultiTouchSupportEnabled(true); 1038 gesture_provider_->SetMultiTouchSupportEnabled(true);
993 1039
994 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; 1040 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop;
995 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; 1041 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop;
996 1042
997 MockMotionEvent event = 1043 MockMotionEvent event =
998 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1044 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1045 event.SetId(++motion_event_id);
999 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1046 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1000 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1047 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1001 1048
1002 event = ObtainMotionEvent(event_time, 1049 event = ObtainMotionEvent(event_time,
1003 MotionEvent::ACTION_POINTER_DOWN, 1050 MotionEvent::ACTION_POINTER_DOWN,
1004 kFakeCoordX, 1051 kFakeCoordX,
1005 kFakeCoordY, 1052 kFakeCoordY,
1006 secondary_coord_x, 1053 secondary_coord_x,
1007 secondary_coord_y); 1054 secondary_coord_y);
1055 event.SetId(++motion_event_id);
1056
1008 gesture_provider_->OnTouchEvent(event); 1057 gesture_provider_->OnTouchEvent(event);
1009 EXPECT_EQ(1U, GetReceivedGestureCount()); 1058 EXPECT_EQ(1U, GetReceivedGestureCount());
1010 1059
1011 secondary_coord_x += 5 * scaled_touch_slop; 1060 secondary_coord_x += 5 * scaled_touch_slop;
1012 secondary_coord_y += 5 * scaled_touch_slop; 1061 secondary_coord_y += 5 * scaled_touch_slop;
1013 1062
1014 event = ObtainMotionEvent(event_time, 1063 event = ObtainMotionEvent(event_time,
1015 MotionEvent::ACTION_MOVE, 1064 MotionEvent::ACTION_MOVE,
1016 kFakeCoordX, 1065 kFakeCoordX,
1017 kFakeCoordY, 1066 kFakeCoordY,
1018 secondary_coord_x, 1067 secondary_coord_x,
1019 secondary_coord_y); 1068 secondary_coord_y);
1069 event.SetId(++motion_event_id);
1020 1070
1021 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1071 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1022 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN)); 1072 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1023 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 1073 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1024 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 1074 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1025 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE)); 1075 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1026 1076
1027 event = ObtainMotionEvent(event_time, 1077 event = ObtainMotionEvent(event_time,
1028 MotionEvent::ACTION_POINTER_UP, 1078 MotionEvent::ACTION_POINTER_UP,
1029 kFakeCoordX, 1079 kFakeCoordX,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 MotionEvent::ACTION_UP); 1138 MotionEvent::ACTION_UP);
1089 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 1139 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
1090 1140
1091 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 1141 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
1092 MotionEvent::ACTION_DOWN); 1142 MotionEvent::ACTION_DOWN);
1093 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1143 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1094 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1144 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1095 } 1145 }
1096 1146
1097 } // namespace ui 1147 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698