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

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: Created 6 years, 6 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 gesture_provider_->OnTouchEvent(event); 262 gesture_provider_->OnTouchEvent(event);
263 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 263 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
264 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 264 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
265 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 265 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
266 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 266 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
267 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 267 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
268 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y), 268 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
269 GetMostRecentGestureEvent().details.bounding_box()); 269 GetMostRecentGestureEvent().details.bounding_box());
270 } 270 }
271 271
272 void OneFingerSwipe(float vx, float vy) {
273 std::vector<gfx::Vector2dF> velocities;
274 velocities.push_back(gfx::Vector2dF(vx, vy));
275 MultiFingerSwipe(velocities);
276 }
277
272 void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) { 278 void TwoFingerSwipe(float vx0, float vy0, float vx1, float vy1) {
273 std::vector<gfx::Vector2dF> velocities; 279 std::vector<gfx::Vector2dF> velocities;
274 velocities.push_back(gfx::Vector2dF(vx0, vy0)); 280 velocities.push_back(gfx::Vector2dF(vx0, vy0));
275 velocities.push_back(gfx::Vector2dF(vx1, vy1)); 281 velocities.push_back(gfx::Vector2dF(vx1, vy1));
276 MultiFingerSwipe(velocities); 282 MultiFingerSwipe(velocities);
277 } 283 }
278 284
279 void ThreeFingerSwipe(float vx0, 285 void ThreeFingerSwipe(float vx0,
280 float vy0, 286 float vy0,
281 float vx1, 287 float vx1,
(...skipping 1159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1447 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1442 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius, 1448 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
1443 kFakeCoordY - kMockTouchRadius, 1449 kFakeCoordY - kMockTouchRadius,
1444 kMockTouchRadius * 2, 1450 kMockTouchRadius * 2,
1445 kMockTouchRadius * 2), 1451 kMockTouchRadius * 2),
1446 GetMostRecentGestureEvent().details.bounding_box()); 1452 GetMostRecentGestureEvent().details.bounding_box());
1447 } 1453 }
1448 1454
1449 // Verify that multi-finger swipe sends the proper event sequence. 1455 // Verify that multi-finger swipe sends the proper event sequence.
1450 TEST_F(GestureProviderTest, MultiFingerSwipe) { 1456 TEST_F(GestureProviderTest, MultiFingerSwipe) {
1451 EnableMultiFingerSwipe(); 1457 EnableSwipe();
1452 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 1458 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
1453 const float min_swipe_velocity = GetMinSwipeVelocity(); 1459 const float min_swipe_velocity = GetMinSwipeVelocity();
1454 1460
1461 // One finger - swipe right
1462 OneFingerSwipe(2 * min_swipe_velocity, 0);
1463 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1464 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1465 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1466 ResetGestureDetection();
1467
1468 // One finger - swipe left
1469 OneFingerSwipe(-2 * min_swipe_velocity, 0);
1470 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1471 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1472 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1473 ResetGestureDetection();
1474
1475 // One finger - swipe down
1476 OneFingerSwipe(0, 2 * min_swipe_velocity);
1477 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1478 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1479 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1480 ResetGestureDetection();
1481
1482 // One finger - swipe up
1483 OneFingerSwipe(0, -2 * min_swipe_velocity);
1484 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1485 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1486 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1487 ResetGestureDetection();
1488
1489 // Two fingers
1455 // Swipe right. 1490 // Swipe right.
1456 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0); 1491 TwoFingerSwipe(min_swipe_velocity * 2, 0, min_swipe_velocity * 2, 0);
1457 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1492 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1458 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1493 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1459 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1494 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1460 ResetGestureDetection(); 1495 ResetGestureDetection();
1461 1496
1462 // Swipe left. 1497 // Swipe left.
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_left()); 1500 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_left());
1466 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1501 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1467 ResetGestureDetection(); 1502 ResetGestureDetection();
1468 1503
1469 // No swipe with different touch directions. 1504 // No swipe with different touch directions.
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_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1506 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1472 ResetGestureDetection(); 1507 ResetGestureDetection();
1473 1508
1474 // No swipe without a dominant direction. 1509 // No swipe without a dominant direction.
1475 TwoFingerSwipe(min_swipe_velocity * 2, 1510 TwoFingerSwipe(min_swipe_velocity * 2,
1476 min_swipe_velocity * 2, 1511 min_swipe_velocity * 2,
1477 min_swipe_velocity * 2, 1512 min_swipe_velocity * 2,
1478 min_swipe_velocity * 2); 1513 min_swipe_velocity * 2);
1479 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1514 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1480 ResetGestureDetection(); 1515 ResetGestureDetection();
1481 1516
1482 // Swipe up with non-zero velocities on both axes and dominant direction. 1517 // Swipe down with non-zero velocities on both axes and dominant direction.
1483 TwoFingerSwipe(-min_swipe_velocity, 1518 TwoFingerSwipe(-min_swipe_velocity,
1484 min_swipe_velocity * 4, 1519 min_swipe_velocity * 4,
1485 -min_swipe_velocity, 1520 -min_swipe_velocity,
1486 min_swipe_velocity * 4); 1521 min_swipe_velocity * 4);
1487 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1522 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1488 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1523 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1489 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left()); 1524 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_left());
1490 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1525 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1491 ResetGestureDetection(); 1526 ResetGestureDetection();
1492 1527
1493 // Swipe down with non-zero velocities on both axes. 1528 // Swipe up with non-zero velocities on both axes.
1494 TwoFingerSwipe(min_swipe_velocity, 1529 TwoFingerSwipe(min_swipe_velocity,
1495 -min_swipe_velocity * 4, 1530 -min_swipe_velocity * 4,
1496 min_swipe_velocity, 1531 min_swipe_velocity,
1497 -min_swipe_velocity * 4); 1532 -min_swipe_velocity * 4);
1498 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1533 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1499 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up()); 1534 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_up());
1500 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right()); 1535 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1501 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1536 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1502 ResetGestureDetection(); 1537 ResetGestureDetection();
1503 1538
1504 // No swipe without sufficient velocity. 1539 // No swipe without sufficient velocity.
1505 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0); 1540 TwoFingerSwipe(min_swipe_velocity / 2, 0, 0, 0);
1506 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1541 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1507 ResetGestureDetection(); 1542 ResetGestureDetection();
1508 1543
1509 // Swipe up with one small and one medium velocity in slightly different but 1544 // Swipe up with one small and one medium velocity in slightly different but
1510 // not opposing directions. 1545 // not opposing directions.
1511 TwoFingerSwipe(min_swipe_velocity / 2, 1546 TwoFingerSwipe(min_swipe_velocity / 2,
1512 min_swipe_velocity / 2, 1547 min_swipe_velocity / 2,
1513 0, 1548 0,
1514 min_swipe_velocity * 2); 1549 min_swipe_velocity * 2);
1515 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1550 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1516 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down()); 1551 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_down());
1517 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right()); 1552 EXPECT_FALSE(GetMostRecentGestureEvent().details.swipe_right());
1518 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 1553 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1519 ResetGestureDetection(); 1554 ResetGestureDetection();
1520 1555
1521 // No swipe in orthogonal directions. 1556 // No swipe in orthogonal directions.
1522 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7); 1557 TwoFingerSwipe(min_swipe_velocity * 2, 0, 0, min_swipe_velocity * 7);
1523 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1558 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1524 ResetGestureDetection(); 1559 ResetGestureDetection();
1525 1560
1526 // Three finger swipe in same directions. 1561 // Three finger swipe in same directions.
1527 ThreeFingerSwipe(min_swipe_velocity * 2, 1562 ThreeFingerSwipe(min_swipe_velocity * 2,
1528 0, 1563 0,
1529 min_swipe_velocity * 3, 1564 min_swipe_velocity * 3,
1530 0, 1565 0,
1531 min_swipe_velocity * 4, 1566 min_swipe_velocity * 4,
1532 0); 1567 0);
1533 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1568 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SWIPE));
1534 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right()); 1569 EXPECT_TRUE(GetMostRecentGestureEvent().details.swipe_right());
1535 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1570 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1536 ResetGestureDetection(); 1571 ResetGestureDetection();
1537 1572
1538 // No three finger swipe in different directions. 1573 // No three finger swipe in different directions.
1539 ThreeFingerSwipe(min_swipe_velocity * 2, 1574 ThreeFingerSwipe(min_swipe_velocity * 2,
1540 0, 1575 0,
1541 0, 1576 0,
1542 min_swipe_velocity * 3, 1577 min_swipe_velocity * 3,
1543 min_swipe_velocity * 4, 1578 min_swipe_velocity * 4,
1544 0); 1579 0);
1545 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_MULTIFINGER_SWIPE)); 1580 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SWIPE));
1546 } 1581 }
1547 1582
1548 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins 1583 // Verify that the timer of LONG_PRESS will be cancelled when scrolling begins
1549 // so LONG_PRESS and LONG_TAP won't be triggered. 1584 // so LONG_PRESS and LONG_TAP won't be triggered.
1550 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) { 1585 TEST_F(GestureProviderTest, GesturesCancelledAfterLongPressCausesLostFocus) {
1551 base::TimeTicks event_time = base::TimeTicks::Now(); 1586 base::TimeTicks event_time = base::TimeTicks::Now();
1552 1587
1553 MockMotionEvent event = 1588 MockMotionEvent event =
1554 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1589 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1555 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1590 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
1904 kFakeCoordY, 1939 kFakeCoordY,
1905 kFakeCoordX + kMaxTwoFingerTapSeparation, 1940 kFakeCoordX + kMaxTwoFingerTapSeparation,
1906 kFakeCoordY); 1941 kFakeCoordY);
1907 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1942 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1908 1943
1909 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); 1944 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type);
1910 EXPECT_EQ(1U, GetReceivedGestureCount()); 1945 EXPECT_EQ(1U, GetReceivedGestureCount());
1911 } 1946 }
1912 1947
1913 } // namespace ui 1948 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698