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

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

Issue 256593003: Also pass unclamped delta and velocity values to GestureEventDetails. (DEPRECATED) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 event.SetId(++motion_event_id); 297 event.SetId(++motion_event_id);
298 298
299 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 299 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
300 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 300 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
301 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 301 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
302 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 302 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
303 303
304 event = ObtainMotionEvent(event_time + delta_time, 304 event = ObtainMotionEvent(event_time + delta_time,
305 MotionEvent::ACTION_MOVE, 305 MotionEvent::ACTION_MOVE,
306 kFakeCoordX * 10, 306 kFakeCoordX * 10,
307 kFakeCoordY * 10); 307 kFakeCoordY * 1.5);
308 event.SetId(++motion_event_id); 308 event.SetId(++motion_event_id);
309 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 309 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
310 310
311 event = ObtainMotionEvent(event_time + delta_time * 2, 311 event = ObtainMotionEvent(event_time + delta_time * 2,
312 MotionEvent::ACTION_UP, 312 MotionEvent::ACTION_UP,
313 kFakeCoordX * 10, 313 kFakeCoordX * 10,
314 kFakeCoordY * 10); 314 kFakeCoordY * 1.5);
315 event.SetId(++motion_event_id); 315 event.SetId(++motion_event_id);
316 316
317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 317 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
318 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 318 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
319
320 EXPECT_EQ(8000, GetMostRecentGestureEvent().details.velocity_x());
jdduke (slow) 2014/04/24 19:58:53 We should probably get 8000 using the |maximum_fli
321 EXPECT_EQ(0, GetMostRecentGestureEvent().details.velocity_y());
322 EXPECT_EQ(8000, GetMostRecentGestureEvent().details.velocity_x_ordinal());
323 EXPECT_EQ(2400, GetMostRecentGestureEvent().details.velocity_y_ordinal());
324
319 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 325 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
320 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 326 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
321 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS)); 327 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_LONG_PRESS));
322 EXPECT_EQ( 328 EXPECT_EQ(
323 BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 10), 329 BoundsForSingleMockTouchAtLocation(kFakeCoordX * 10, kFakeCoordY * 1.5),
324 GetMostRecentGestureEvent().details.bounding_box()); 330 GetMostRecentGestureEvent().details.bounding_box());
325 } 331 }
326 332
327 // Verify that for a normal scroll the following events are sent: 333 // Verify that for a normal scroll the following events are sent:
328 // - ET_GESTURE_SCROLL_BEGIN 334 // - ET_GESTURE_SCROLL_BEGIN
329 // - ET_GESTURE_SCROLL_UPDATE 335 // - ET_GESTURE_SCROLL_UPDATE
330 // - ET_GESTURE_SCROLL_END 336 // - ET_GESTURE_SCROLL_END
331 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) { 337 TEST_F(GestureProviderTest, ScrollEventActionUpSequence) {
332 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP); 338 CheckScrollEventSequenceForEndActionType(MotionEvent::ACTION_UP);
333 } 339 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 event = ObtainMotionEvent(event_time + delta_time * 2, 386 event = ObtainMotionEvent(event_time + delta_time * 2,
381 MotionEvent::ACTION_UP, 387 MotionEvent::ACTION_UP,
382 kFakeCoordX * 10, 388 kFakeCoordX * 10,
383 kFakeCoordY * 10); 389 kFakeCoordY * 10);
384 event.SetId(++motion_event_id); 390 event.SetId(++motion_event_id);
385 391
386 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 392 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
387 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 393 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
388 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 394 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
389 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 395 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
396
397 EXPECT_EQ(8000, GetMostRecentGestureEvent().details.velocity_x());
398 EXPECT_EQ(8000, GetMostRecentGestureEvent().details.velocity_y());
399 EXPECT_EQ(8000, GetMostRecentGestureEvent().details.velocity_x_ordinal());
400 EXPECT_EQ(8000, GetMostRecentGestureEvent().details.velocity_y_ordinal());
401
390 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 402 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
391 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 403 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
392 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) 404 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
393 << "FlingStart should have the time of the ACTION_UP"; 405 << "FlingStart should have the time of the ACTION_UP";
394 } 406 }
395 407
396 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) { 408 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) {
397 const base::TimeTicks event_time = TimeTicks::Now(); 409 const base::TimeTicks event_time = TimeTicks::Now();
398 410
399 MockMotionEvent event = 411 MockMotionEvent event =
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 ASSERT_LT(0U, GetReceivedGestureCount()); 597 ASSERT_LT(0U, GetReceivedGestureCount());
586 GestureEventData gesture = GetMostRecentGestureEvent(); 598 GestureEventData gesture = GetMostRecentGestureEvent();
587 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); 599 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type);
588 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); 600 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
589 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); 601 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
590 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); 602 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
591 EXPECT_EQ(1, gesture.details.touch_points()); 603 EXPECT_EQ(1, gesture.details.touch_points());
592 604
593 // No horizontal delta because of snapping. 605 // No horizontal delta because of snapping.
594 EXPECT_EQ(0, gesture.details.scroll_x()); 606 EXPECT_EQ(0, gesture.details.scroll_x());
607 EXPECT_EQ(-delta_x / 2, gesture.details.scroll_x_ordinal());
595 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); 608 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
jdduke (slow) 2014/04/24 19:58:53 Might as well round this out with EXPECT_EQ(-del
596 } 609 }
597 610
598 // Verify that fractional scroll deltas are rounded as expected and that 611 // Verify that fractional scroll deltas are rounded as expected and that
599 // fractional scrolling doesn't break scroll snapping. 612 // fractional scrolling doesn't break scroll snapping.
600 TEST_F(GestureProviderTest, FractionalScroll) { 613 TEST_F(GestureProviderTest, FractionalScroll) {
601 const float delta_x = 0.4f; 614 const float delta_x = 0.4f;
602 const float delta_y = 5.2f; 615 const float delta_y = 5.2f;
603 616
604 const base::TimeTicks event_time = TimeTicks::Now(); 617 const base::TimeTicks event_time = TimeTicks::Now();
605 618
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 1529
1517 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL); 1530 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_CANCEL);
1518 event.pointer_count = 1; 1531 event.pointer_count = 1;
1519 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1532 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1520 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType()); 1533 EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
1521 EXPECT_EQ(12U, GetReceivedGestureCount()); 1534 EXPECT_EQ(12U, GetReceivedGestureCount());
1522 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1535 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1523 } 1536 }
1524 1537
1525 } // namespace ui 1538 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698