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

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

Issue 340343013: Provide max gesture bounds and option to ignore touch size during pinch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix DCHECK 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 min_pinch_update_span_delta; 251 min_pinch_update_span_delta;
252 SetUpWithConfig(config); 252 SetUpWithConfig(config);
253 } 253 }
254 254
255 void SetMinGestureBoundsLength(float min_gesture_bound_length) { 255 void SetMinGestureBoundsLength(float min_gesture_bound_length) {
256 GestureProvider::Config config = GetDefaultConfig(); 256 GestureProvider::Config config = GetDefaultConfig();
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) {
262 GestureProvider::Config config = GetDefaultConfig();
263 config.max_gesture_bounds_length = max_gesture_bound_length;
264 SetUpWithConfig(config);
265 }
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
261 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } 273 bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
262 274
263 protected: 275 protected:
264 void CheckScrollEventSequenceForEndActionType( 276 void CheckScrollEventSequenceForEndActionType(
265 MotionEvent::Action end_action_type) { 277 MotionEvent::Action end_action_type) {
266 base::TimeTicks event_time = base::TimeTicks::Now(); 278 base::TimeTicks event_time = base::TimeTicks::Now();
267 const float scroll_to_x = kFakeCoordX + 100; 279 const float scroll_to_x = kFakeCoordX + 100;
268 const float scroll_to_y = kFakeCoordY + 100; 280 const float scroll_to_y = kFakeCoordY + 100;
269 int motion_event_id = 0; 281 int motion_event_id = 0;
270 282
(...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 gesture_provider_->OnTouchEvent(event); 1562 gesture_provider_->OnTouchEvent(event);
1551 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType()); 1563 EXPECT_EQ(ET_GESTURE_SCROLL_END, GetMostRecentGestureEventType());
1552 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1564 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1553 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius, 1565 EXPECT_EQ(gfx::RectF(kFakeCoordX - kMockTouchRadius,
1554 kFakeCoordY - kMockTouchRadius, 1566 kFakeCoordY - kMockTouchRadius,
1555 kMockTouchRadius * 2, 1567 kMockTouchRadius * 2,
1556 kMockTouchRadius * 2), 1568 kMockTouchRadius * 2),
1557 GetMostRecentGestureEvent().details.bounding_box()); 1569 GetMostRecentGestureEvent().details.bounding_box());
1558 } 1570 }
1559 1571
1572 // Verify that pinch zoom that doesn't use touch major values sends the proper
tdresser 2014/07/02 13:43:10 It doesn't look like this is testing the case wher
jdduke (slow) 2014/07/02 16:24:18 Oops, the comment is wrong, good catch.
1573 // event 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
1560 // Verify that no accidental pinching occurs if the touch size is large relative 1652 // Verify that no accidental pinching occurs if the touch size is large relative
1561 // to the min scaling span. 1653 // to the min scaling span when the touch major value is used in scaling.
1562 TEST_F(GestureProviderTest, NoPinchZoomWithFatFinger) { 1654 TEST_F(GestureProviderTest, NoPinchZoomWithTouchMajorAndFatFinger) {
1655 EnableTouchMajorUseInScaling();
1656
1563 base::TimeTicks event_time = base::TimeTicks::Now(); 1657 base::TimeTicks event_time = base::TimeTicks::Now();
1564 const float kFatFingerSize = GetMinScalingSpan() * 3.f; 1658 const float kFatFingerSize = GetMinScalingSpan() * 3.f;
1565 1659
1566 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 1660 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
1567 gesture_provider_->SetMultiTouchZoomSupportEnabled(true); 1661 gesture_provider_->SetMultiTouchZoomSupportEnabled(true);
1568 1662
1569 MockMotionEvent event = 1663 MockMotionEvent event =
1570 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 1664 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
1571 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1665 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1572 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1666 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
2289 event = 2383 event =
2290 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP); 2384 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2291 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2385 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2292 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2386 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2293 EXPECT_EQ(kMinGestureBoundsLength, 2387 EXPECT_EQ(kMinGestureBoundsLength,
2294 GetMostRecentGestureEvent().details.bounding_box_f().width()); 2388 GetMostRecentGestureEvent().details.bounding_box_f().width());
2295 EXPECT_EQ(kMinGestureBoundsLength, 2389 EXPECT_EQ(kMinGestureBoundsLength,
2296 GetMostRecentGestureEvent().details.bounding_box_f().height()); 2390 GetMostRecentGestureEvent().details.bounding_box_f().height());
2297 } 2391 }
2298 2392
2393 TEST_F(GestureProviderTest, MaxGestureBoundsLength) {
2394 const float kMaxGestureBoundsLength = kMockTouchRadius / 10.f;
2395 SetMaxGestureBoundsLength(kMaxGestureBoundsLength);
2396 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2397
2398 base::TimeTicks event_time = base::TimeTicks::Now();
2399 MockMotionEvent event =
2400 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2401 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2402
2403 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2404 EXPECT_EQ(kMaxGestureBoundsLength,
2405 GetMostRecentGestureEvent().details.bounding_box_f().width());
2406 EXPECT_EQ(kMaxGestureBoundsLength,
2407 GetMostRecentGestureEvent().details.bounding_box_f().height());
2408
2409 event =
2410 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2411 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2412 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2413 EXPECT_EQ(kMaxGestureBoundsLength,
2414 GetMostRecentGestureEvent().details.bounding_box_f().width());
2415 EXPECT_EQ(kMaxGestureBoundsLength,
2416 GetMostRecentGestureEvent().details.bounding_box_f().height());
2417 }
2418
2299 } // namespace ui 2419 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698