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

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

Issue 409563004: Fix gesture debugging (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Actually add the changes... Created 6 years, 5 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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 config.min_gesture_bounds_length = min_gesture_bound_length; 257 config.min_gesture_bounds_length = min_gesture_bound_length;
258 SetUpWithConfig(config); 258 SetUpWithConfig(config);
259 } 259 }
260 260
261 void SetMaxGestureBoundsLength(float max_gesture_bound_length) { 261 void SetMaxGestureBoundsLength(float max_gesture_bound_length) {
262 GestureProvider::Config config = GetDefaultConfig(); 262 GestureProvider::Config config = GetDefaultConfig();
263 config.max_gesture_bounds_length = max_gesture_bound_length; 263 config.max_gesture_bounds_length = max_gesture_bound_length;
264 SetUpWithConfig(config); 264 SetUpWithConfig(config);
265 } 265 }
266 266
267 void EnableTouchMajorUseInScaling() {
268 GestureProvider::Config config = GetDefaultConfig();
269 config.scale_gesture_detector_config.use_touch_major_in_span = true;
270 SetUpWithConfig(config);
271 }
272
273 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } 267 bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
274 268
275 protected: 269 protected:
276 void CheckScrollEventSequenceForEndActionType( 270 void CheckScrollEventSequenceForEndActionType(
277 MotionEvent::Action end_action_type) { 271 MotionEvent::Action end_action_type) {
278 base::TimeTicks event_time = base::TimeTicks::Now(); 272 base::TimeTicks event_time = base::TimeTicks::Now();
279 const float scroll_to_x = kFakeCoordX + 100; 273 const float scroll_to_x = kFakeCoordX + 100;
280 const float scroll_to_y = kFakeCoordY + 100; 274 const float scroll_to_y = kFakeCoordY + 100;
281 int motion_event_id = 0; 275 int motion_event_id = 0;
282 276
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 gesture_provider_->OnTouchEvent(event); 1556 gesture_provider_->OnTouchEvent(event);
1563 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1557 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1564 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1558 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1565 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius, 1559 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
1566 kFakeCoordY - kMockTouchRadius, 1560 kFakeCoordY - kMockTouchRadius,
1567 kMockTouchRadius * 2, 1561 kMockTouchRadius * 2,
1568 kMockTouchRadius * 2), 1562 kMockTouchRadius * 2),
1569 GetMostRecentGestureEvent().details.bounding_box()); 1563 GetMostRecentGestureEvent().details.bounding_box());
1570 } 1564 }
1571 1565
1572 // Verify that pinch zoom that uses touch major values sends the proper event
1573 // sequence.
1574 TEST_F(GestureProviderTest, PinchZoomWithTouchMajor) {
1575 EnableTouchMajorUseInScaling();
1576
1577 base::TimeTicks event_time = base::TimeTicks::Now();
1578 const float touch_slop = GetTouchSlop();
1579 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1580
1581 int secondary_coord_x = kFakeCoordX + 20 * touch_slop;
1582 int secondary_coord_y = kFakeCoordY + 20 * touch_slop;
1583
1584 MockMotionEvent event =
1585 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1586 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1587 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1588
1589 event = ObtainMotionEvent(event_time,
1590 MotionEvent::ACTION_POINTER_DOWN,
1591 kFakeCoordX,
1592 kFakeCoordY,
1593 secondary_coord_x,
1594 secondary_coord_y);
1595
1596 gesture_provider_->OnTouchEvent(event);
1597 EXPECT_EQ(1U, GetReceivedGestureCount());
1598
1599 secondary_coord_x += 5 * touch_slop;
1600 secondary_coord_y += 5 * touch_slop;
1601 event = ObtainMotionEvent(event_time,
1602 MotionEvent::ACTION_MOVE,
1603 kFakeCoordX,
1604 kFakeCoordY,
1605 secondary_coord_x,
1606 secondary_coord_y);
1607 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1608 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
1609 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1610 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
1611 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_UPDATE));
1612
1613 secondary_coord_x += 2 * touch_slop;
1614 secondary_coord_y += 2 * touch_slop;
1615 event = ObtainMotionEvent(event_time,
1616 MotionEvent::ACTION_MOVE,
1617 kFakeCoordX,
1618 kFakeCoordY,
1619 secondary_coord_x,
1620 secondary_coord_y);
1621 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1622 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1623 EXPECT_LT(1.f, GetMostRecentGestureEvent().details.scale());
1624
1625 secondary_coord_x -= 2 * touch_slop;
1626 secondary_coord_y -= 2 * touch_slop;
1627 event = ObtainMotionEvent(event_time,
1628 MotionEvent::ACTION_MOVE,
1629 kFakeCoordX,
1630 kFakeCoordY,
1631 secondary_coord_x,
1632 secondary_coord_y);
1633 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1634 EXPECT_EQ(ET_GESTURE_PINCH_UPDATE, GetMostRecentGestureEventType());
1635 EXPECT_GT(1.f, GetMostRecentGestureEvent().details.scale());
1636
1637 event = ObtainMotionEvent(event_time,
1638 MotionEvent::ACTION_POINTER_UP,
1639 kFakeCoordX,
1640 kFakeCoordY,
1641 secondary_coord_x,
1642 secondary_coord_y);
1643 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1644 EXPECT_EQ(ET_GESTURE_PINCH_END, GetMostRecentGestureEventType());
1645 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
1646
1647 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
1648 gesture_provider_->OnTouchEvent(event);
1649 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1650 }
1651
1652 // Verify that no accidental pinching occurs if the touch size is large relative 1566 // Verify that no accidental pinching occurs if the touch size is large relative
1653 // to the min scaling span when the touch major value is used in scaling. 1567 // to the min scaling span when the touch major value is used in scaling.
1654 TEST_F(GestureProviderTest, NoPinchZoomWithTouchMajorAndFatFinger) { 1568 TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) {
tdresser 2014/07/22 12:10:40 What's making this test pass? Is it just the incre
1655 EnableTouchMajorUseInScaling();
1656
1657 base::TimeTicks event_time = base::TimeTicks::Now(); 1569 base::TimeTicks event_time = base::TimeTicks::Now();
1658 const float kFatFingerSize = GetMinScalingSpan() * 3.f; 1570 const float kFatFingerSize = GetMinScalingSpan() * 3.f;
1659 1571
1660 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1572 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1661 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); 1573 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1662 1574
1663 MockMotionEvent event = 1575 MockMotionEvent event =
1664 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1576 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1665 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1577 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1666 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1578 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
(...skipping 17 matching lines...) Expand all
1684 MotionEvent::ACTION_MOVE); 1596 MotionEvent::ACTION_MOVE);
1685 event.SetTouchMajor(kFatFingerSize * 3.5f); 1597 event.SetTouchMajor(kFatFingerSize * 3.5f);
1686 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1598 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1687 EXPECT_EQ(1U, GetReceivedGestureCount()); 1599 EXPECT_EQ(1U, GetReceivedGestureCount());
1688 1600
1689 event = ObtainMotionEvent(event_time + kOneSecond * 4, 1601 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1690 MotionEvent::ACTION_MOVE); 1602 MotionEvent::ACTION_MOVE);
1691 event.SetTouchMajor(kFatFingerSize * 5.f); 1603 event.SetTouchMajor(kFatFingerSize * 5.f);
1692 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1604 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1693 EXPECT_EQ(1U, GetReceivedGestureCount()); 1605 EXPECT_EQ(1U, GetReceivedGestureCount());
1606
1607 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1608 MotionEvent::ACTION_MOVE,
1609 kFakeCoordX + 50.f,
1610 kFakeCoordY - 25.f);
1611 event.SetTouchMajor(kFatFingerSize * 10.f);
1612 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1613 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1614
1615 event = ObtainMotionEvent(event_time + kOneSecond * 4,
1616 MotionEvent::ACTION_MOVE,
1617 kFakeCoordX + 100.f,
1618 kFakeCoordY - 50.f);
1619 event.SetTouchMajor(kFatFingerSize * 5.f);
1620 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1621 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_PINCH_BEGIN));
1694 } 1622 }
1695 1623
1696 // Verify that multi-finger swipe sends the proper event sequence. 1624 // Verify that multi-finger swipe sends the proper event sequence.
1697 TEST_F(GestureProviderTest, MultiFingerSwipe) { 1625 TEST_F(GestureProviderTest, MultiFingerSwipe) {
1698 EnableSwipe(); 1626 EnableSwipe();
1699 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 1627 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
1700 const float min_swipe_velocity = GetMinSwipeVelocity(); 1628 const float min_swipe_velocity = GetMinSwipeVelocity();
1701 1629
1702 // One finger - swipe right 1630 // One finger - swipe right
1703 OneFingerSwipe(2 * min_swipe_velocity, 0); 1631 OneFingerSwipe(2 * min_swipe_velocity, 0);
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
2410 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP); 2338 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2411 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2339 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2412 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2340 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2413 EXPECT_EQ(kMaxGestureBoundsLength, 2341 EXPECT_EQ(kMaxGestureBoundsLength,
2414 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2342 GetMostRecentGestureEvent().details.bounding_box_f().width());
2415 EXPECT_EQ(kMaxGestureBoundsLength, 2343 EXPECT_EQ(kMaxGestureBoundsLength,
2416 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2344 GetMostRecentGestureEvent().details.bounding_box_f().height());
2417 } 2345 }
2418 2346
2419 } // namespace ui 2347 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_config_helper_android.cc ('k') | ui/events/gesture_detection/scale_gesture_detector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698