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 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
167 event = ObtainMotionEvent(event_time + kOneSecond, | 167 event = ObtainMotionEvent(event_time + kOneSecond, |
168 MotionEvent::ACTION_MOVE, | 168 MotionEvent::ACTION_MOVE, |
169 scroll_to_x, | 169 scroll_to_x, |
170 scroll_to_y); | 170 scroll_to_y); |
171 event.SetId(++motion_event_id); | 171 event.SetId(++motion_event_id); |
172 | 172 |
173 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 173 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
174 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | 174 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); |
175 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | 175 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
176 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 176 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
177 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
177 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | 178 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); |
178 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, " | 179 ASSERT_EQ(4U, GetReceivedGestureCount()) << "Only TapDown, TapCancel, " |
179 "ScrollBegin and ScrollBy " | 180 "ScrollBegin and ScrollBy " |
180 "should have been sent"; | 181 "should have been sent"; |
181 | 182 |
182 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(1).type); | 183 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(1).type); |
183 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id); | 184 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id); |
184 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); | 185 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); |
185 EXPECT_EQ(motion_event_id, GetReceivedGesture(2).motion_event_id); | 186 EXPECT_EQ(motion_event_id, GetReceivedGesture(2).motion_event_id); |
186 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time) | 187 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(2).time) |
187 << "ScrollBegin should have the time of the ACTION_MOVE"; | 188 << "ScrollBegin should have the time of the ACTION_MOVE"; |
188 | 189 |
189 event = ObtainMotionEvent( | 190 event = ObtainMotionEvent( |
190 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); | 191 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); |
191 event.SetId(++motion_event_id); | 192 event.SetId(++motion_event_id); |
192 | 193 |
193 gesture_provider_->OnTouchEvent(event); | 194 gesture_provider_->OnTouchEvent(event); |
194 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); | 195 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); |
195 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); | 196 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); |
196 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | 197 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); |
197 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 198 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
199 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
198 } | 200 } |
199 | 201 |
200 static void RunTasksAndWait(base::TimeDelta delay) { | 202 static void RunTasksAndWait(base::TimeDelta delay) { |
201 base::MessageLoop::current()->PostDelayedTask( | 203 base::MessageLoop::current()->PostDelayedTask( |
202 FROM_HERE, base::MessageLoop::QuitClosure(), delay); | 204 FROM_HERE, base::MessageLoop::QuitClosure(), delay); |
203 base::MessageLoop::current()->Run(); | 205 base::MessageLoop::current()->Run(); |
204 } | 206 } |
205 | 207 |
206 std::vector<GestureEventData> gestures_; | 208 std::vector<GestureEventData> gestures_; |
207 scoped_ptr<GestureProvider> gesture_provider_; | 209 scoped_ptr<GestureProvider> gesture_provider_; |
208 scoped_ptr<GestureEventData> active_scroll_begin_event_; | 210 scoped_ptr<GestureEventData> active_scroll_begin_event_; |
209 base::MessageLoopForUI message_loop_; | 211 base::MessageLoopForUI message_loop_; |
210 }; | 212 }; |
211 | 213 |
212 // Verify that a DOWN followed shortly by an UP will trigger a single tap. | 214 // Verify that a DOWN followed shortly by an UP will trigger a single tap. |
213 TEST_F(GestureProviderTest, GestureTapTap) { | 215 TEST_F(GestureProviderTest, GestureTapTap) { |
214 base::TimeTicks event_time = base::TimeTicks::Now(); | 216 base::TimeTicks event_time = base::TimeTicks::Now(); |
215 int motion_event_id = 0; | 217 int motion_event_id = 0; |
216 | 218 |
217 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); | 219 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); |
218 | 220 |
219 MockMotionEvent event = | 221 MockMotionEvent event = |
220 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 222 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
221 event.SetId(++motion_event_id); | 223 event.SetId(++motion_event_id); |
222 | 224 |
223 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 225 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
224 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 226 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
227 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
225 | 228 |
226 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 229 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
227 MotionEvent::ACTION_UP); | 230 MotionEvent::ACTION_UP); |
228 event.SetId(++motion_event_id); | 231 event.SetId(++motion_event_id); |
229 | 232 |
230 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 233 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
231 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | 234 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); |
232 // Ensure tap details have been set. | 235 // Ensure tap details have been set. |
233 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); | 236 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); |
234 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); | 237 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); |
235 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | 238 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); |
236 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 239 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
240 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
237 } | 241 } |
238 | 242 |
239 // Verify that a DOWN followed shortly by an UP will trigger | 243 // Verify that a DOWN followed shortly by an UP will trigger |
240 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled. | 244 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled. |
241 TEST_F(GestureProviderTest, GestureTapTapWithDelay) { | 245 TEST_F(GestureProviderTest, GestureTapTapWithDelay) { |
242 base::TimeTicks event_time = base::TimeTicks::Now(); | 246 base::TimeTicks event_time = base::TimeTicks::Now(); |
243 int motion_event_id = 0; | 247 int motion_event_id = 0; |
244 | 248 |
245 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); | 249 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); |
246 | 250 |
247 MockMotionEvent event = | 251 MockMotionEvent event = |
248 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 252 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
249 event.SetId(++motion_event_id); | 253 event.SetId(++motion_event_id); |
250 | 254 |
251 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 255 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
252 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 256 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
253 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 257 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
258 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
254 | 259 |
255 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 260 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
256 MotionEvent::ACTION_UP); | 261 MotionEvent::ACTION_UP); |
257 event.SetId(++motion_event_id); | 262 event.SetId(++motion_event_id); |
258 | 263 |
259 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 264 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
260 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | 265 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); |
261 // Ensure tap details have been set. | 266 // Ensure tap details have been set. |
262 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); | 267 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().width()); |
263 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); | 268 EXPECT_EQ(10, GetMostRecentGestureEvent().details.bounding_box().height()); |
264 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | 269 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); |
265 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 270 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
271 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
266 | 272 |
267 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP)); | 273 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_TAP)); |
268 } | 274 } |
269 | 275 |
270 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). | 276 // Verify that a DOWN followed by a MOVE will trigger fling (but not LONG). |
271 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) { | 277 TEST_F(GestureProviderTest, GestureFlingAndCancelLongPress) { |
272 base::TimeTicks event_time = TimeTicks::Now(); | 278 base::TimeTicks event_time = TimeTicks::Now(); |
273 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; | 279 base::TimeDelta delta_time = kDeltaTimeForFlingSequences; |
274 int motion_event_id = 0; | 280 int motion_event_id = 0; |
275 | 281 |
276 MockMotionEvent event = | 282 MockMotionEvent event = |
277 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 283 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
278 event.SetId(++motion_event_id); | 284 event.SetId(++motion_event_id); |
279 | 285 |
280 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 286 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
281 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 287 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
282 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 288 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
289 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
283 | 290 |
284 event = ObtainMotionEvent(event_time + delta_time, | 291 event = ObtainMotionEvent(event_time + delta_time, |
285 MotionEvent::ACTION_MOVE, | 292 MotionEvent::ACTION_MOVE, |
286 kFakeCoordX * 10, | 293 kFakeCoordX * 10, |
287 kFakeCoordY * 10); | 294 kFakeCoordY * 10); |
288 event.SetId(++motion_event_id); | 295 event.SetId(++motion_event_id); |
289 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 296 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
290 | 297 |
291 event = ObtainMotionEvent(event_time + delta_time * 2, | 298 event = ObtainMotionEvent(event_time + delta_time * 2, |
292 MotionEvent::ACTION_UP, | 299 MotionEvent::ACTION_UP, |
293 kFakeCoordX * 10, | 300 kFakeCoordX * 10, |
294 kFakeCoordY * 10); | 301 kFakeCoordY * 10); |
295 event.SetId(++motion_event_id); | 302 event.SetId(++motion_event_id); |
296 | 303 |
297 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 304 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
298 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); | 305 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); |
299 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 306 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
307 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
300 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); | 308 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); |
301 } | 309 } |
302 | 310 |
303 // Verify that for a normal scroll the following events are sent: | 311 // Verify that for a normal scroll the following events are sent: |
304 // - ET_GESTURE_SCROLL_BEGIN | 312 // - ET_GESTURE_SCROLL_BEGIN |
305 // - ET_GESTURE_SCROLL_UPDATE | 313 // - ET_GESTURE_SCROLL_UPDATE |
306 // - ET_GESTURE_SCROLL_END | 314 // - ET_GESTURE_SCROLL_END |
307 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { | 315 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { |
308 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP); | 316 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP); |
309 } | 317 } |
(...skipping 25 matching lines...) Expand all Loading... | |
335 MotionEvent::ACTION_MOVE, | 343 MotionEvent::ACTION_MOVE, |
336 kFakeCoordX * 5, | 344 kFakeCoordX * 5, |
337 kFakeCoordY * 5); | 345 kFakeCoordY * 5); |
338 event.SetId(++motion_event_id); | 346 event.SetId(++motion_event_id); |
339 | 347 |
340 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 348 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
341 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); | 349 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); |
342 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | 350 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
343 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | 351 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); |
344 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 352 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
353 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
345 ASSERT_EQ(4U, GetReceivedGestureCount()); | 354 ASSERT_EQ(4U, GetReceivedGestureCount()); |
346 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); | 355 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(2).type); |
347 EXPECT_EQ(motion_event_id, GetReceivedGesture(2).motion_event_id); | 356 EXPECT_EQ(motion_event_id, GetReceivedGesture(2).motion_event_id); |
348 | 357 |
349 // We don't want to take a dependency here on exactly how hints are calculated | 358 // We don't want to take a dependency here on exactly how hints are calculated |
350 // for a fling (eg. may depend on velocity), so just validate the direction. | 359 // for a fling (eg. may depend on velocity), so just validate the direction. |
351 int hint_x = GetReceivedGesture(2).details.scroll_x_hint(); | 360 int hint_x = GetReceivedGesture(2).details.scroll_x_hint(); |
352 int hint_y = GetReceivedGesture(2).details.scroll_y_hint(); | 361 int hint_y = GetReceivedGesture(2).details.scroll_y_hint(); |
353 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) | 362 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) |
354 << "ScrollBegin hint should be in positive X axis"; | 363 << "ScrollBegin hint should be in positive X axis"; |
355 | 364 |
356 event = ObtainMotionEvent(event_time + delta_time * 2, | 365 event = ObtainMotionEvent(event_time + delta_time * 2, |
357 MotionEvent::ACTION_UP, | 366 MotionEvent::ACTION_UP, |
358 kFakeCoordX * 10, | 367 kFakeCoordX * 10, |
359 kFakeCoordY * 10); | 368 kFakeCoordY * 10); |
360 event.SetId(++motion_event_id); | 369 event.SetId(++motion_event_id); |
361 | 370 |
362 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 371 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
363 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); | 372 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); |
364 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); | 373 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); |
365 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 374 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
375 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
366 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); | 376 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); |
367 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) | 377 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) |
368 << "FlingStart should have the time of the ACTION_UP"; | 378 << "FlingStart should have the time of the ACTION_UP"; |
369 } | 379 } |
370 | 380 |
371 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) { | 381 TEST_F(GestureProviderTest, TapCancelledWhenWindowFocusLost) { |
372 const base::TimeTicks event_time = TimeTicks::Now(); | 382 const base::TimeTicks event_time = TimeTicks::Now(); |
373 | 383 |
374 MockMotionEvent event = | 384 MockMotionEvent event = |
375 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 385 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
376 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 386 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
377 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 387 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
388 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
378 | 389 |
379 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + | 390 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + |
380 kOneMicrosecond); | 391 kOneMicrosecond); |
381 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); | 392 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); |
382 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 393 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
394 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
383 | 395 |
384 // The long press triggers window focus loss by opening a context menu | 396 // The long press triggers window focus loss by opening a context menu |
385 EXPECT_TRUE(CancelActiveTouchSequence()); | 397 EXPECT_TRUE(CancelActiveTouchSequence()); |
386 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | 398 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); |
399 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
387 } | 400 } |
388 | 401 |
389 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) { | 402 TEST_F(GestureProviderTest, TapCancelledWhenScrollBegins) { |
390 base::TimeTicks event_time = base::TimeTicks::Now(); | 403 base::TimeTicks event_time = base::TimeTicks::Now(); |
391 | 404 |
392 MockMotionEvent event = | 405 MockMotionEvent event = |
393 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 406 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
394 | 407 |
395 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 408 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
396 | 409 |
397 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 410 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
411 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
398 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 412 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
399 MotionEvent::ACTION_MOVE, | 413 MotionEvent::ACTION_MOVE, |
400 kFakeCoordX + 50, | 414 kFakeCoordX + 50, |
401 kFakeCoordY + 50); | 415 kFakeCoordY + 50); |
402 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 416 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
403 | 417 |
404 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | 418 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); |
419 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
405 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL)); | 420 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL)); |
406 } | 421 } |
407 | 422 |
408 TEST_F(GestureProviderTest, DoubleTap) { | 423 TEST_F(GestureProviderTest, DoubleTap) { |
409 base::TimeTicks event_time = base::TimeTicks::Now(); | 424 base::TimeTicks event_time = base::TimeTicks::Now(); |
410 | 425 |
411 MockMotionEvent event = | 426 MockMotionEvent event = |
412 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 427 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
413 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 428 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
414 | 429 |
415 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 430 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
431 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
416 | 432 |
417 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 433 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
418 MotionEvent::ACTION_UP, | 434 MotionEvent::ACTION_UP, |
419 kFakeCoordX, | 435 kFakeCoordX, |
420 kFakeCoordY); | 436 kFakeCoordY); |
421 gesture_provider_->OnTouchEvent(event); | 437 gesture_provider_->OnTouchEvent(event); |
422 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | 438 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); |
439 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
423 | 440 |
424 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, | 441 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, |
425 MotionEvent::ACTION_DOWN, | 442 MotionEvent::ACTION_DOWN, |
426 kFakeCoordX, | 443 kFakeCoordX, |
427 kFakeCoordY); | 444 kFakeCoordY); |
428 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 445 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
429 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 446 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
447 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
430 | 448 |
431 // Moving a very small amount of distance should not trigger the double tap | 449 // Moving a very small amount of distance should not trigger the double tap |
432 // drag zoom mode. | 450 // drag zoom mode. |
433 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, | 451 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, |
434 MotionEvent::ACTION_MOVE, | 452 MotionEvent::ACTION_MOVE, |
435 kFakeCoordX, | 453 kFakeCoordX, |
436 kFakeCoordY + 1); | 454 kFakeCoordY + 1); |
437 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 455 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
438 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 456 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
457 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
439 | 458 |
440 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, | 459 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, |
441 MotionEvent::ACTION_UP, | 460 MotionEvent::ACTION_UP, |
442 kFakeCoordX, | 461 kFakeCoordX, |
443 kFakeCoordY + 1); | 462 kFakeCoordY + 1); |
444 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 463 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
445 | 464 |
446 const GestureEventData& double_tap = GetMostRecentGestureEvent(); | 465 const GestureEventData& double_tap = GetMostRecentGestureEvent(); |
447 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); | 466 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); |
448 // Ensure tap details have been set. | 467 // Ensure tap details have been set. |
449 EXPECT_EQ(10, double_tap.details.bounding_box().width()); | 468 EXPECT_EQ(10, double_tap.details.bounding_box().width()); |
450 EXPECT_EQ(10, double_tap.details.bounding_box().height()); | 469 EXPECT_EQ(10, double_tap.details.bounding_box().height()); |
451 EXPECT_EQ(1, double_tap.details.tap_count()); | 470 EXPECT_EQ(1, double_tap.details.tap_count()); |
452 } | 471 } |
453 | 472 |
454 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { | 473 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { |
455 const base::TimeTicks down_time_1 = TimeTicks::Now(); | 474 const base::TimeTicks down_time_1 = TimeTicks::Now(); |
456 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; | 475 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; |
457 | 476 |
458 MockMotionEvent event = | 477 MockMotionEvent event = |
459 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); | 478 ObtainMotionEvent(down_time_1, MotionEvent::ACTION_DOWN); |
460 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 479 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
461 | 480 |
462 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, | 481 event = ObtainMotionEvent(down_time_1 + kOneMicrosecond, |
463 MotionEvent::ACTION_UP, | 482 MotionEvent::ACTION_UP, |
464 kFakeCoordX, | 483 kFakeCoordX, |
465 kFakeCoordY); | 484 kFakeCoordY); |
466 gesture_provider_->OnTouchEvent(event); | 485 gesture_provider_->OnTouchEvent(event); |
467 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | 486 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); |
487 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
468 | 488 |
469 event = ObtainMotionEvent( | 489 event = ObtainMotionEvent( |
470 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | 490 down_time_2, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); |
471 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 491 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
472 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 492 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
493 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
473 | 494 |
474 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, | 495 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond, |
475 MotionEvent::ACTION_MOVE, | 496 MotionEvent::ACTION_MOVE, |
476 kFakeCoordX, | 497 kFakeCoordX, |
477 kFakeCoordY + 100); | 498 kFakeCoordY + 100); |
478 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 499 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
479 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | 500 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
480 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | 501 ASSERT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); |
481 | 502 |
482 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, | 503 event = ObtainMotionEvent(down_time_2 + kOneMicrosecond * 2, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 kFakeCoordY - delta_y); | 551 kFakeCoordY - delta_y); |
531 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 552 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
532 | 553 |
533 // Make sure the reported gesture event has all the expected details. | 554 // Make sure the reported gesture event has all the expected details. |
534 ASSERT_LT(0U, GetReceivedGestureCount()); | 555 ASSERT_LT(0U, GetReceivedGestureCount()); |
535 GestureEventData gesture = GetMostRecentGestureEvent(); | 556 GestureEventData gesture = GetMostRecentGestureEvent(); |
536 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); | 557 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); |
537 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); | 558 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); |
538 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); | 559 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); |
539 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); | 560 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); |
561 EXPECT_EQ(1, gesture.details.touch_points()); | |
540 | 562 |
541 // No horizontal delta because of snapping. | 563 // No horizontal delta because of snapping. |
542 EXPECT_EQ(0, gesture.details.scroll_x()); | 564 EXPECT_EQ(0, gesture.details.scroll_x()); |
543 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); | 565 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); |
544 } | 566 } |
545 | 567 |
546 // Verify that fractional scroll deltas are rounded as expected and that | 568 // Verify that fractional scroll deltas are rounded as expected and that |
547 // fractional scrolling doesn't break scroll snapping. | 569 // fractional scrolling doesn't break scroll snapping. |
548 TEST_F(GestureProviderTest, FractionalScroll) { | 570 TEST_F(GestureProviderTest, FractionalScroll) { |
549 const float delta_x = 0.4f; | 571 const float delta_x = 0.4f; |
(...skipping 21 matching lines...) Expand all Loading... | |
571 event = ObtainMotionEvent(event_time + kOneMicrosecond * i, | 593 event = ObtainMotionEvent(event_time + kOneMicrosecond * i, |
572 MotionEvent::ACTION_MOVE, | 594 MotionEvent::ACTION_MOVE, |
573 kFakeCoordX + delta_x * i, | 595 kFakeCoordX + delta_x * i, |
574 kFakeCoordY + delta_y * i); | 596 kFakeCoordY + delta_y * i); |
575 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 597 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
576 | 598 |
577 ASSERT_LT(0U, GetReceivedGestureCount()); | 599 ASSERT_LT(0U, GetReceivedGestureCount()); |
578 GestureEventData gesture = GetMostRecentGestureEvent(); | 600 GestureEventData gesture = GetMostRecentGestureEvent(); |
579 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); | 601 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); |
580 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time); | 602 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time); |
603 EXPECT_EQ(1, gesture.details.touch_points()); | |
581 | 604 |
582 // Verify that the event co-ordinates are still the precise values we | 605 // Verify that the event co-ordinates are still the precise values we |
583 // supplied. | 606 // supplied. |
584 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); | 607 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); |
585 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y); | 608 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y); |
586 | 609 |
587 // Verify that we're scrolling vertically by the expected amount | 610 // Verify that we're scrolling vertically by the expected amount |
588 // (modulo rounding). | 611 // (modulo rounding). |
589 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y); | 612 EXPECT_GE(gesture.details.scroll_y(), (int)delta_y); |
590 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1); | 613 EXPECT_LE(gesture.details.scroll_y(), ((int)delta_y) + 1); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 | 683 |
661 MockMotionEvent event = | 684 MockMotionEvent event = |
662 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 685 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
663 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 686 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
664 | 687 |
665 const base::TimeDelta long_press_timeout = | 688 const base::TimeDelta long_press_timeout = |
666 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; | 689 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; |
667 RunTasksAndWait(long_press_timeout); | 690 RunTasksAndWait(long_press_timeout); |
668 | 691 |
669 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 692 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
693 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
670 | 694 |
671 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP); | 695 event = ObtainMotionEvent(event_time + kOneSecond, MotionEvent::ACTION_UP); |
672 gesture_provider_->OnTouchEvent(event); | 696 gesture_provider_->OnTouchEvent(event); |
673 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType()); | 697 EXPECT_EQ(ET_GESTURE_LONG_TAP, GetMostRecentGestureEventType()); |
698 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
674 } | 699 } |
675 | 700 |
676 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) { | 701 TEST_F(GestureProviderTest, GestureLongPressDoesNotPreventScrolling) { |
677 base::TimeTicks event_time = base::TimeTicks::Now(); | 702 base::TimeTicks event_time = base::TimeTicks::Now(); |
678 | 703 |
679 MockMotionEvent event = | 704 MockMotionEvent event = |
680 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 705 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
681 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 706 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
682 | 707 |
683 const base::TimeDelta long_press_timeout = | 708 const base::TimeDelta long_press_timeout = |
684 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; | 709 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; |
685 RunTasksAndWait(long_press_timeout); | 710 RunTasksAndWait(long_press_timeout); |
686 | 711 |
687 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 712 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
713 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
688 event = ObtainMotionEvent(event_time + long_press_timeout, | 714 event = ObtainMotionEvent(event_time + long_press_timeout, |
689 MotionEvent::ACTION_MOVE, | 715 MotionEvent::ACTION_MOVE, |
690 kFakeCoordX + 100, | 716 kFakeCoordX + 100, |
691 kFakeCoordY + 100); | 717 kFakeCoordY + 100); |
692 gesture_provider_->OnTouchEvent(event); | 718 gesture_provider_->OnTouchEvent(event); |
693 | 719 |
694 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); | 720 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); |
721 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
695 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); | 722 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); |
696 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL)); | 723 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_TAP_CANCEL)); |
697 | 724 |
698 event = ObtainMotionEvent(event_time + long_press_timeout, | 725 event = ObtainMotionEvent(event_time + long_press_timeout, |
699 MotionEvent::ACTION_UP); | 726 MotionEvent::ACTION_UP); |
700 gesture_provider_->OnTouchEvent(event); | 727 gesture_provider_->OnTouchEvent(event); |
701 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); | 728 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); |
702 } | 729 } |
703 | 730 |
704 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { | 731 TEST_F(GestureProviderTest, NoGestureLongPressDuringDoubleTap) { |
705 base::TimeTicks event_time = base::TimeTicks::Now(); | 732 base::TimeTicks event_time = base::TimeTicks::Now(); |
706 int motion_event_id = 0; | 733 int motion_event_id = 0; |
707 | 734 |
708 MockMotionEvent event = ObtainMotionEvent( | 735 MockMotionEvent event = ObtainMotionEvent( |
709 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); | 736 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); |
710 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 737 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
711 | 738 |
712 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 739 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
713 MotionEvent::ACTION_UP, | 740 MotionEvent::ACTION_UP, |
714 kFakeCoordX, | 741 kFakeCoordX, |
715 kFakeCoordY); | 742 kFakeCoordY); |
716 gesture_provider_->OnTouchEvent(event); | 743 gesture_provider_->OnTouchEvent(event); |
717 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); | 744 EXPECT_EQ(ET_GESTURE_TAP_UNCONFIRMED, GetMostRecentGestureEventType()); |
745 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
718 | 746 |
719 event = ObtainMotionEvent(event_time + kOneMicrosecond, | 747 event = ObtainMotionEvent(event_time + kOneMicrosecond, |
720 MotionEvent::ACTION_DOWN, | 748 MotionEvent::ACTION_DOWN, |
721 kFakeCoordX, | 749 kFakeCoordX, |
722 kFakeCoordY); | 750 kFakeCoordY); |
723 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 751 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
724 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 752 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
753 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
725 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); | 754 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); |
726 | 755 |
727 const base::TimeDelta long_press_timeout = | 756 const base::TimeDelta long_press_timeout = |
728 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; | 757 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; |
729 RunTasksAndWait(long_press_timeout); | 758 RunTasksAndWait(long_press_timeout); |
730 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); | 759 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); |
731 | 760 |
732 event = ObtainMotionEvent(event_time + long_press_timeout, | 761 event = ObtainMotionEvent(event_time + long_press_timeout, |
733 MotionEvent::ACTION_MOVE, | 762 MotionEvent::ACTION_MOVE, |
734 kFakeCoordX + 20, | 763 kFakeCoordX + 20, |
735 kFakeCoordY + 20); | 764 kFakeCoordY + 20); |
736 event.SetId(++motion_event_id); | 765 event.SetId(++motion_event_id); |
737 | 766 |
738 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 767 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
739 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); | 768 EXPECT_EQ(ET_GESTURE_PINCH_BEGIN, GetMostRecentGestureEventType()); |
740 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 769 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
770 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
741 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); | 771 EXPECT_TRUE(gesture_provider_->IsDoubleTapInProgress()); |
742 | 772 |
743 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond, | 773 event = ObtainMotionEvent(event_time + long_press_timeout + kOneMicrosecond, |
744 MotionEvent::ACTION_UP, | 774 MotionEvent::ACTION_UP, |
745 kFakeCoordX, | 775 kFakeCoordX, |
746 kFakeCoordY + 1); | 776 kFakeCoordY + 1); |
747 event.SetId(++motion_event_id); | 777 event.SetId(++motion_event_id); |
748 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 778 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
749 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); | 779 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); |
750 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); | 780 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); |
781 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
751 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress()); | 782 EXPECT_FALSE(gesture_provider_->IsDoubleTapInProgress()); |
752 } | 783 } |
753 | 784 |
754 // Verify that the touch slop region is removed from the first scroll delta to | 785 // Verify that the touch slop region is removed from the first scroll delta to |
755 // avoid a jump when starting to scroll. | 786 // avoid a jump when starting to scroll. |
756 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { | 787 TEST_F(GestureProviderTest, TouchSlopRemovedFromScroll) { |
757 const int scaled_touch_slop = GetTouchSlop(); | 788 const int scaled_touch_slop = GetTouchSlop(); |
758 const int scroll_delta = 5; | 789 const int scroll_delta = 5; |
759 | 790 |
760 base::TimeTicks event_time = base::TimeTicks::Now(); | 791 base::TimeTicks event_time = base::TimeTicks::Now(); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 gesture_provider_->SetMultiTouchSupportEnabled(true); | 1032 gesture_provider_->SetMultiTouchSupportEnabled(true); |
1002 | 1033 |
1003 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; | 1034 int secondary_coord_x = kFakeCoordX + 20 * scaled_touch_slop; |
1004 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; | 1035 int secondary_coord_y = kFakeCoordY + 20 * scaled_touch_slop; |
1005 | 1036 |
1006 MockMotionEvent event = | 1037 MockMotionEvent event = |
1007 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 1038 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
1008 event.SetId(++motion_event_id); | 1039 event.SetId(++motion_event_id); |
1009 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1040 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1010 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1041 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
1042 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
1011 | 1043 |
1012 event = ObtainMotionEvent(event_time, | 1044 event = ObtainMotionEvent(event_time, |
1013 MotionEvent::ACTION_POINTER_DOWN, | 1045 MotionEvent::ACTION_POINTER_DOWN, |
1014 kFakeCoordX, | 1046 kFakeCoordX, |
1015 kFakeCoordY, | 1047 kFakeCoordY, |
1016 secondary_coord_x, | 1048 secondary_coord_x, |
1017 secondary_coord_y); | 1049 secondary_coord_y); |
1018 event.SetId(++motion_event_id); | 1050 event.SetId(++motion_event_id); |
jdduke (slow)
2014/04/08 21:07:41
Hmm, it's a little odd you stop checking |touch_po
tdresser
2014/04/09 14:50:48
Done.
| |
1019 | 1051 |
1020 gesture_provider_->OnTouchEvent(event); | 1052 gesture_provider_->OnTouchEvent(event); |
1021 EXPECT_EQ(1U, GetReceivedGestureCount()); | 1053 EXPECT_EQ(1U, GetReceivedGestureCount()); |
1022 | 1054 |
1023 secondary_coord_x += 5 * scaled_touch_slop; | 1055 secondary_coord_x += 5 * scaled_touch_slop; |
1024 secondary_coord_y += 5 * scaled_touch_slop; | 1056 secondary_coord_y += 5 * scaled_touch_slop; |
1025 event = ObtainMotionEvent(event_time, | 1057 event = ObtainMotionEvent(event_time, |
1026 MotionEvent::ACTION_MOVE, | 1058 MotionEvent::ACTION_MOVE, |
1027 kFakeCoordX, | 1059 kFakeCoordX, |
1028 kFakeCoordY, | 1060 kFakeCoordY, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1079 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 1111 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
1080 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1112 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1081 | 1113 |
1082 const base::TimeDelta long_press_timeout = | 1114 const base::TimeDelta long_press_timeout = |
1083 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; | 1115 GetLongPressTimeout() + GetShowPressTimeout() + kOneMicrosecond; |
1084 RunTasksAndWait(long_press_timeout); | 1116 RunTasksAndWait(long_press_timeout); |
1085 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); | 1117 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); |
1086 | 1118 |
1087 EXPECT_TRUE(CancelActiveTouchSequence()); | 1119 EXPECT_TRUE(CancelActiveTouchSequence()); |
1088 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); | 1120 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetMostRecentGestureEventType()); |
1121 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
1089 | 1122 |
1090 event = ObtainMotionEvent(event_time + long_press_timeout, | 1123 event = ObtainMotionEvent(event_time + long_press_timeout, |
1091 MotionEvent::ACTION_UP); | 1124 MotionEvent::ACTION_UP); |
1092 gesture_provider_->OnTouchEvent(event); | 1125 gesture_provider_->OnTouchEvent(event); |
1093 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); | 1126 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_TAP)); |
1094 } | 1127 } |
1095 | 1128 |
1096 // Verify that inserting a touch cancel event will trigger proper touch and | 1129 // Verify that inserting a touch cancel event will trigger proper touch and |
1097 // gesture sequence cancellation. | 1130 // gesture sequence cancellation. |
1098 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { | 1131 TEST_F(GestureProviderTest, CancelActiveTouchSequence) { |
(...skipping 30 matching lines...) Expand all Loading... | |
1129 } | 1162 } |
1130 | 1163 |
1131 // Verify that gesture begin and gesture end events are dispatched correctly. | 1164 // Verify that gesture begin and gesture end events are dispatched correctly. |
1132 TEST_F(GestureProviderTest, GestureBeginAndEnd) { | 1165 TEST_F(GestureProviderTest, GestureBeginAndEnd) { |
1133 SetBeginEndTypesEnabled(true); | 1166 SetBeginEndTypesEnabled(true); |
1134 base::TimeTicks event_time = base::TimeTicks::Now(); | 1167 base::TimeTicks event_time = base::TimeTicks::Now(); |
1135 | 1168 |
1136 EXPECT_EQ(0U, GetReceivedGestureCount()); | 1169 EXPECT_EQ(0U, GetReceivedGestureCount()); |
1137 MockMotionEvent event = | 1170 MockMotionEvent event = |
1138 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 1171 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
1172 event.pointer_count = 1; | |
1139 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1173 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1140 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); | 1174 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); |
1141 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1175 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
1142 EXPECT_EQ(2U, GetReceivedGestureCount()); | 1176 EXPECT_EQ(2U, GetReceivedGestureCount()); |
1177 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
1143 | 1178 |
1144 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); | 1179 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
1180 event.pointer_count = 2; | |
1145 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1181 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1146 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); | 1182 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
1147 EXPECT_EQ(3U, GetReceivedGestureCount()); | 1183 EXPECT_EQ(3U, GetReceivedGestureCount()); |
1184 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); | |
1148 | 1185 |
1149 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); | 1186 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
1187 event.pointer_count = 3; | |
1150 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1188 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1151 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); | 1189 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
1152 EXPECT_EQ(4U, GetReceivedGestureCount()); | 1190 EXPECT_EQ(4U, GetReceivedGestureCount()); |
1191 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); | |
1153 | 1192 |
1154 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); | 1193 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
1194 event.pointer_count = 2; | |
1155 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1195 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1156 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); | 1196 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
1157 EXPECT_EQ(5U, GetReceivedGestureCount()); | 1197 EXPECT_EQ(5U, GetReceivedGestureCount()); |
1198 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); | |
1158 | 1199 |
1159 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); | 1200 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_DOWN); |
1201 event.pointer_count = 3; | |
1160 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1202 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1161 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); | 1203 EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType()); |
1162 EXPECT_EQ(6U, GetReceivedGestureCount()); | 1204 EXPECT_EQ(6U, GetReceivedGestureCount()); |
1205 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); | |
1163 | 1206 |
1164 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); | 1207 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
1208 event.pointer_count = 2; | |
1165 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1209 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1166 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); | 1210 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
1167 EXPECT_EQ(7U, GetReceivedGestureCount()); | 1211 EXPECT_EQ(7U, GetReceivedGestureCount()); |
1212 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); | |
1168 | 1213 |
1169 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); | 1214 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP); |
1215 event.pointer_count = 1; | |
1170 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1216 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1171 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); | 1217 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
1172 EXPECT_EQ(8U, GetReceivedGestureCount()); | 1218 EXPECT_EQ(8U, GetReceivedGestureCount()); |
1219 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
1173 | 1220 |
1174 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | 1221 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); |
1222 event.pointer_count = 1; | |
1175 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1223 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1176 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); | 1224 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
1177 EXPECT_EQ(9U, GetReceivedGestureCount()); | 1225 EXPECT_EQ(9U, GetReceivedGestureCount()); |
1226 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
1178 | 1227 |
1179 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | 1228 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); |
1229 event.pointer_count = 1; | |
1180 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1230 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1181 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(9).type); | 1231 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(9).type); |
1182 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(10).type); | 1232 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(10).type); |
1183 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); | 1233 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); |
1184 EXPECT_EQ(12U, GetReceivedGestureCount()); | 1234 EXPECT_EQ(12U, GetReceivedGestureCount()); |
1235 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | |
1185 | 1236 |
1186 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL); | 1237 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL); |
1238 event.pointer_count = 1; | |
1187 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 1239 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
1188 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(12).type); | 1240 EXPECT_EQ(ET_GESTURE_TAP_CANCEL, GetReceivedGesture(12).type); |
1189 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); | 1241 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); |
1190 EXPECT_EQ(14U, GetReceivedGestureCount()); | 1242 EXPECT_EQ(14U, GetReceivedGestureCount()); |
1191 | 1243 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
1192 | |
1193 } | 1244 } |
1194 | 1245 |
1195 } // namespace ui | 1246 } // namespace ui |
OLD | NEW |