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

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

Issue 302463004: Implementing the dispatch of the swipe gesture for one-finger touch swipes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Implementing review feedback. Created 6 years, 7 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
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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 base::TimeDelta GetDoubleTapTimeout() const { 193 base::TimeDelta GetDoubleTapTimeout() const {
194 return GetDefaultConfig().gesture_detector_config.double_tap_timeout; 194 return GetDefaultConfig().gesture_detector_config.double_tap_timeout;
195 } 195 }
196 196
197 void EnableBeginEndTypes() { 197 void EnableBeginEndTypes() {
198 GestureProvider::Config config = GetDefaultConfig(); 198 GestureProvider::Config config = GetDefaultConfig();
199 config.gesture_begin_end_types_enabled = true; 199 config.gesture_begin_end_types_enabled = true;
200 SetUpWithConfig(config); 200 SetUpWithConfig(config);
201 } 201 }
202 202
203 void EnableMultiFingerSwipe() { 203 void EnableSwipe() {
204 GestureProvider::Config config = GetDefaultConfig(); 204 GestureProvider::Config config = GetDefaultConfig();
205 config.gesture_detector_config.swipe_enabled = true; 205 config.gesture_detector_config.swipe_enabled = true;
206 SetUpWithConfig(config); 206 SetUpWithConfig(config);
207 } 207 }
208 208
209 void EnableTwoFingerTap(float max_distance_for_two_finger_tap, 209 void EnableTwoFingerTap(float max_distance_for_two_finger_tap,
210 base::TimeDelta two_finger_tap_timeout) { 210 base::TimeDelta two_finger_tap_timeout) {
211 GestureProvider::Config config = GetDefaultConfig(); 211 GestureProvider::Config config = GetDefaultConfig();
212 config.gesture_detector_config.two_finger_tap_enabled = true; 212 config.gesture_detector_config.two_finger_tap_enabled = true;
213 config.gesture_detector_config.two_finger_tap_max_separation = 213 config.gesture_detector_config.two_finger_tap_max_separation =
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 gesture_provider_->OnTouchEvent(event); 269 gesture_provider_->OnTouchEvent(event);
270 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 270 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
271 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 271 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
272 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 272 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
273 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 273 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
274 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 274 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
275 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y), 275 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
276 GetMostRecentGestureEvent().details.bounding_box()); 276 GetMostRecentGestureEvent().details.bounding_box());
277 } 277 }
278 278
279 void OneFingerSwipe(float vx, float vy) {
280 std::vector<gfx::Vector2dF> velocities;
281 velocities.push_back(gfx::Vector2dF(vx, vy));
282 MultiFingerSwipe(velocities);
283 }
284
279 void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) { 285 void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) {
280 std::vector<gfx::Vector2dF> velocities; 286 std::vector<gfx::Vector2dF> velocities;
281 velocities.push_back(gfx::Vector2dF(vx0, vy0)); 287 velocities.push_back(gfx::Vector2dF(vx0, vy0));
282 velocities.push_back(gfx::Vector2dF(vx1, vy1)); 288 velocities.push_back(gfx::Vector2dF(vx1, vy1));
283 MultiFingerSwipe(velocities); 289 MultiFingerSwipe(velocities);
284 } 290 }
285 291
286 void ThreeFingerSwipe(float vx0, 292 void ThreeFingerSwipe(float vx0,
287 float vy0, 293 float vy0,
288 float vx1, 294 float vx1,
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1454 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1449 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius, 1455 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
1450 kFakeCoordY - kMockTouchRadius, 1456 kFakeCoordY - kMockTouchRadius,
1451 kMockTouchRadius * 2, 1457 kMockTouchRadius * 2,
1452 kMockTouchRadius * 2), 1458 kMockTouchRadius * 2),
1453 GetMostRecentGestureEvent().details.bounding_box()); 1459 GetMostRecentGestureEvent().details.bounding_box());
1454 } 1460 }
1455 1461
1456 // Verify that multi-finger swipe sends the proper event sequence. 1462 // Verify that multi-finger swipe sends the proper event sequence.
1457 TEST_F(GestureProviderTest, MultiFingerSwipe) { 1463 TEST_F(GestureProviderTest, MultiFingerSwipe) {
1458 EnableMultiFingerSwipe(); 1464 EnableSwipe();
1459 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 1465 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
1460 const float min_swipe_velocity = GetMinSwipeVelocity(); 1466 const float min_swipe_velocity = GetMinSwipeVelocity();
1461 1467
1468 // One finger - swipe right
1469 OneFingerSwipe(2 * min_swipe_velocity, 0);
1470 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1471 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1472 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1473 ResetGestureDetection();
1474
1475 // One finger - swipe left
1476 OneFingerSwipe(-2 * min_swipe_velocity, 0);
1477 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1478 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1479 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1480 ResetGestureDetection();
1481
1482 // One finger - swipe down
1483 OneFingerSwipe(0, 2 * min_swipe_velocity);
1484 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1485 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1486 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1487 ResetGestureDetection();
1488
1489 // One finger - swipe up
1490 OneFingerSwipe(0, -2 * min_swipe_velocity);
1491 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1492 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1493 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1494 ResetGestureDetection();
1495
1496 // Two fingers
1462 // Swipe right. 1497 // Swipe right.
1463 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0); 1498 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0);
1464 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1499 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1465 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1500 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1466 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1501 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1467 ResetGestureDetection(); 1502 ResetGestureDetection();
1468 1503
1469 // Swipe left. 1504 // Swipe left.
1470 TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0); 1505 TwoFingerSwipe(-min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
1471 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1506 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1472 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left()); 1507 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1473 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1508 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1474 ResetGestureDetection(); 1509 ResetGestureDetection();
1475 1510
1476 // No swipe with different touch directions. 1511 // No swipe with different touch directions.
1477 TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0); 1512 TwoFingerSwipe(min_swipe_velocity * 2, 0, -min_swipe_velocity * 2, 0);
1478 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1513 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1479 ResetGestureDetection(); 1514 ResetGestureDetection();
1480 1515
1481 // No swipe without a dominant direction. 1516 // No swipe without a dominant direction.
1482 TwoFingerSwipe(min_swipe_velocity * 2, 1517 TwoFingerSwipe(min_swipe_velocity * 2,
1483 min_swipe_velocity * 2, 1518 min_swipe_velocity * 2,
1484 min_swipe_velocity * 2, 1519 min_swipe_velocity * 2,
1485 min_swipe_velocity * 2); 1520 min_swipe_velocity * 2);
1486 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1521 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1487 ResetGestureDetection(); 1522 ResetGestureDetection();
1488 1523
1489 // Swipe up with non-zero velocities on both axes and dominant direction. 1524 // Swipe down with non-zero velocities on both axes and dominant direction.
1490 TwoFingerSwipe(-min_swipe_velocity, 1525 TwoFingerSwipe(-min_swipe_velocity,
1491 min_swipe_velocity * 4, 1526 min_swipe_velocity * 4,
1492 -min_swipe_velocity, 1527 -min_swipe_velocity,
1493 min_swipe_velocity * 4); 1528 min_swipe_velocity * 4);
1494 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1529 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1495 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1530 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1496 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left()); 1531 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left());
1497 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1532 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1498 ResetGestureDetection(); 1533 ResetGestureDetection();
1499 1534
1500 // Swipe down with non-zero velocities on both axes. 1535 // Swipe up with non-zero velocities on both axes.
1501 TwoFingerSwipe(min_swipe_velocity, 1536 TwoFingerSwipe(min_swipe_velocity,
1502 -min_swipe_velocity * 4, 1537 -min_swipe_velocity * 4,
1503 min_swipe_velocity, 1538 min_swipe_velocity,
1504 -min_swipe_velocity * 4); 1539 -min_swipe_velocity * 4);
1505 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1540 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1506 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up()); 1541 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1507 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right()); 1542 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1508 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1543 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1509 ResetGestureDetection(); 1544 ResetGestureDetection();
1510 1545
1511 // No swipe without sufficient velocity. 1546 // No swipe without sufficient velocity.
1512 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0); 1547 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0);
1513 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1548 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1514 ResetGestureDetection(); 1549 ResetGestureDetection();
1515 1550
1516 // Swipe up with one small and one medium velocity in slightly different but 1551 // Swipe up with one small and one medium velocity in slightly different but
1517 // not opposing directions. 1552 // not opposing directions.
1518 TwoFingerSwipe(min_swipe_velocity / 2, 1553 TwoFingerSwipe(min_swipe_velocity / 2,
1519 min_swipe_velocity / 2, 1554 min_swipe_velocity / 2,
1520 0, 1555 0,
1521 min_swipe_velocity * 2); 1556 min_swipe_velocity * 2);
1522 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1557 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1523 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1558 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1524 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right()); 1559 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1525 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1560 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1526 ResetGestureDetection(); 1561 ResetGestureDetection();
1527 1562
1528 // No swipe in orthogonal directions. 1563 // No swipe in orthogonal directions.
1529 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7); 1564 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7);
1530 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1565 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1531 ResetGestureDetection(); 1566 ResetGestureDetection();
1532 1567
1533 // Three finger swipe in same directions. 1568 // Three finger swipe in same directions.
1534 ThreeFingerSwipe(min_swipe_velocity * 2, 1569 ThreeFingerSwipe(min_swipe_velocity * 2,
1535 0, 1570 0,
1536 min_swipe_velocity * 3, 1571 min_swipe_velocity * 3,
1537 0, 1572 0,
1538 min_swipe_velocity * 4, 1573 min_swipe_velocity * 4,
1539 0); 1574 0);
1540 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1575 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1541 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1576 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1542 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1577 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1543 ResetGestureDetection(); 1578 ResetGestureDetection();
1544 1579
1545 // No three finger swipe in different directions. 1580 // No three finger swipe in different directions.
1546 ThreeFingerSwipe(min_swipe_velocity * 2, 1581 ThreeFingerSwipe(min_swipe_velocity * 2,
1547 0, 1582 0,
1548 0, 1583 0,
1549 min_swipe_velocity * 3, 1584 min_swipe_velocity * 3,
1550 min_swipe_velocity * 4, 1585 min_swipe_velocity * 4,
1551 0); 1586 0);
1552 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1587 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1553 } 1588 }
1554 1589
1555 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins 1590 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1556 // so LONG_PRESS and LONG_TAP won't be triggered. 1591 // so LONG_PRESS and LONG_TAP won't be triggered.
1557 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) { 1592 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
1558 base::TimeTicks event_time = base::TimeTicks::Now(); 1593 base::TimeTicks event_time = base::TimeTicks::Now();
1559 1594
1560 MockMotionEvent event = 1595 MockMotionEvent event =
1561 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1596 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1562 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1597 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 secondary_coord_x + kMinPinchUpdateDistance + 2027 secondary_coord_x + kMinPinchUpdateDistance +
1993 kOvershootMinPinchUpdateDistance, 2028 kOvershootMinPinchUpdateDistance,
1994 secondary_coord_y); 2029 secondary_coord_y);
1995 2030
1996 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2031 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1997 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 2032 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
1998 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 2033 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1999 } 2034 }
2000 2035
2001 } // namespace ui 2036 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | ui/events/gesture_detection/touch_disposition_gesture_filter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698