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

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

Issue 321563002: Support minimum gesture bounds in GestureProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix compile 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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 // Test 123 // Test
124 virtual void SetUp() OVERRIDE { SetUpWithConfig(GetDefaultConfig()); } 124 virtual void SetUp() OVERRIDE { SetUpWithConfig(GetDefaultConfig()); }
125 125
126 virtual void TearDown() OVERRIDE { 126 virtual void TearDown() OVERRIDE {
127 gestures_.clear(); 127 gestures_.clear();
128 gesture_provider_.reset(); 128 gesture_provider_.reset();
129 } 129 }
130 130
131 // GestureProviderClient 131 // GestureProviderClient
132 virtual void OnGestureEvent(const GestureEventData& gesture) OVERRIDE { 132 virtual void OnGestureEvent(const GestureEventData& gesture) OVERRIDE {
133 if (gesture.type == ET_GESTURE_SCROLL_BEGIN) 133 if (gesture.type() == ET_GESTURE_SCROLL_BEGIN)
134 active_scroll_begin_event_.reset(new GestureEventData(gesture)); 134 active_scroll_begin_event_.reset(new GestureEventData(gesture));
135 gestures_.push_back(gesture); 135 gestures_.push_back(gesture);
136 } 136 }
137 137
138 void SetUpWithConfig(const GestureProvider::Config& config) { 138 void SetUpWithConfig(const GestureProvider::Config& config) {
139 gesture_provider_.reset(new GestureProvider(config, this)); 139 gesture_provider_.reset(new GestureProvider(config, this));
140 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 140 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
141 } 141 }
142 142
143 void ResetGestureDetection() { 143 void ResetGestureDetection() {
144 CancelActiveTouchSequence(); 144 CancelActiveTouchSequence();
145 gestures_.clear(); 145 gestures_.clear();
146 } 146 }
147 bool CancelActiveTouchSequence() { 147 bool CancelActiveTouchSequence() {
148 if (!gesture_provider_->current_down_event()) 148 if (!gesture_provider_->current_down_event())
149 return false; 149 return false;
150 return gesture_provider_->OnTouchEvent( 150 return gesture_provider_->OnTouchEvent(
151 *gesture_provider_->current_down_event()->Cancel()); 151 *gesture_provider_->current_down_event()->Cancel());
152 } 152 }
153 153
154 bool HasReceivedGesture(EventType type) const { 154 bool HasReceivedGesture(EventType type) const {
155 for (size_t i = 0; i < gestures_.size(); ++i) { 155 for (size_t i = 0; i < gestures_.size(); ++i) {
156 if (gestures_[i].type == type) 156 if (gestures_[i].type() == type)
157 return true; 157 return true;
158 } 158 }
159 return false; 159 return false;
160 } 160 }
161 161
162 const GestureEventData& GetMostRecentGestureEvent() const { 162 const GestureEventData& GetMostRecentGestureEvent() const {
163 EXPECT_FALSE(gestures_.empty()); 163 EXPECT_FALSE(gestures_.empty());
164 return gestures_.back(); 164 return gestures_.back();
165 } 165 }
166 166
167 EventType GetMostRecentGestureEventType() const { 167 EventType GetMostRecentGestureEventType() const {
168 EXPECT_FALSE(gestures_.empty()); 168 EXPECT_FALSE(gestures_.empty());
169 return gestures_.back().type; 169 return gestures_.back().type();
170 } 170 }
171 171
172 size_t GetReceivedGestureCount() const { return gestures_.size(); } 172 size_t GetReceivedGestureCount() const { return gestures_.size(); }
173 173
174 const GestureEventData& GetReceivedGesture(size_t index) const { 174 const GestureEventData& GetReceivedGesture(size_t index) const {
175 EXPECT_LT(index, GetReceivedGestureCount()); 175 EXPECT_LT(index, GetReceivedGestureCount());
176 return gestures_[index]; 176 return gestures_[index];
177 } 177 }
178 178
179 const GestureEventData* GetActiveScrollBeginEvent() const { 179 const GestureEventData* GetActiveScrollBeginEvent() const {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 SetUpWithConfig(config); 228 SetUpWithConfig(config);
229 } 229 }
230 230
231 void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta) { 231 void SetMinPinchUpdateSpanDelta(float min_pinch_update_span_delta) {
232 GestureProvider::Config config = GetDefaultConfig(); 232 GestureProvider::Config config = GetDefaultConfig();
233 config.scale_gesture_detector_config.min_pinch_update_span_delta = 233 config.scale_gesture_detector_config.min_pinch_update_span_delta =
234 min_pinch_update_span_delta; 234 min_pinch_update_span_delta;
235 SetUpWithConfig(config); 235 SetUpWithConfig(config);
236 } 236 }
237 237
238 void SetMinGestureBoundsLength(float min_gesture_bound_length) {
239 GestureProvider::Config config = GetDefaultConfig();
240 config.min_gesture_bounds_length = min_gesture_bound_length;
241 SetUpWithConfig(config);
242 }
243
238 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } 244 bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
239 245
240 protected: 246 protected:
241 void CheckScrollEventSequenceForEndActionType( 247 void CheckScrollEventSequenceForEndActionType(
242 MotionEvent::Action end_action_type) { 248 MotionEvent::Action end_action_type) {
243 base::TimeTicks event_time = base::TimeTicks::Now(); 249 base::TimeTicks event_time = base::TimeTicks::Now();
244 const float scroll_to_x = kFakeCoordX + 100; 250 const float scroll_to_x = kFakeCoordX + 100;
245 const float scroll_to_y = kFakeCoordY + 100; 251 const float scroll_to_y = kFakeCoordY + 100;
246 int motion_event_id = 0; 252 int motion_event_id = 0;
247 253
(...skipping 13 matching lines...) Expand all
261 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 267 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
262 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 268 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
263 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 269 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
264 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 270 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
265 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y), 271 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(scroll_to_x, scroll_to_y),
266 GetMostRecentGestureEvent().details.bounding_box()); 272 GetMostRecentGestureEvent().details.bounding_box());
267 ASSERT_EQ(3U, GetReceivedGestureCount()) << "Only TapDown, " 273 ASSERT_EQ(3U, GetReceivedGestureCount()) << "Only TapDown, "
268 "ScrollBegin and ScrollBy " 274 "ScrollBegin and ScrollBy "
269 "should have been sent"; 275 "should have been sent";
270 276
271 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type); 277 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
272 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id); 278 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
273 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(1).time) 279 EXPECT_EQ(event_time + kOneSecond, GetReceivedGesture(1).time)
274 << "ScrollBegin should have the time of the ACTION_MOVE"; 280 << "ScrollBegin should have the time of the ACTION_MOVE";
275 281
276 event = ObtainMotionEvent( 282 event = ObtainMotionEvent(
277 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y); 283 event_time + kOneSecond, end_action_type, scroll_to_x, scroll_to_y);
278 event.SetId(++motion_event_id); 284 event.SetId(++motion_event_id);
279 285
280 gesture_provider_->OnTouchEvent(event); 286 gesture_provider_->OnTouchEvent(event);
281 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 287 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 base::MessageLoop::current()->Run(); 371 base::MessageLoop::current()->Run();
366 } 372 }
367 373
368 std::vector<GestureEventData> gestures_; 374 std::vector<GestureEventData> gestures_;
369 scoped_ptr<GestureProvider> gesture_provider_; 375 scoped_ptr<GestureProvider> gesture_provider_;
370 scoped_ptr<GestureEventData> active_scroll_begin_event_; 376 scoped_ptr<GestureEventData> active_scroll_begin_event_;
371 base::MessageLoopForUI message_loop_; 377 base::MessageLoopForUI message_loop_;
372 }; 378 };
373 379
374 // Verify that a DOWN followed shortly by an UP will trigger a single tap. 380 // Verify that a DOWN followed shortly by an UP will trigger a single tap.
375 TEST_F(GestureProviderTest, GestureTapTap) { 381 TEST_F(GestureProviderTest, GestureTap) {
376 base::TimeTicks event_time = base::TimeTicks::Now(); 382 base::TimeTicks event_time = base::TimeTicks::Now();
377 int motion_event_id = 0; 383 int motion_event_id = 0;
378 384
379 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); 385 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
380 386
381 MockMotionEvent event = 387 MockMotionEvent event =
382 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 388 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
383 event.SetId(++motion_event_id); 389 event.SetId(++motion_event_id);
384 390
385 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 391 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
(...skipping 11 matching lines...) Expand all
397 // Ensure tap details have been set. 403 // Ensure tap details have been set.
398 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 404 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
399 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 405 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
400 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 406 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
401 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY), 407 EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
402 GetMostRecentGestureEvent().details.bounding_box()); 408 GetMostRecentGestureEvent().details.bounding_box());
403 } 409 }
404 410
405 // Verify that a DOWN followed shortly by an UP will trigger 411 // Verify that a DOWN followed shortly by an UP will trigger
406 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled. 412 // a ET_GESTURE_TAP_UNCONFIRMED event if double-tap is enabled.
407 TEST_F(GestureProviderTest, GestureTapTapWithDelay) { 413 TEST_F(GestureProviderTest, GestureTapWithDelay) {
408 base::TimeTicks event_time = base::TimeTicks::Now(); 414 base::TimeTicks event_time = base::TimeTicks::Now();
409 int motion_event_id = 0; 415 int motion_event_id = 0;
410 416
411 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); 417 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
412 418
413 MockMotionEvent event = 419 MockMotionEvent event =
414 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 420 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
415 event.SetId(++motion_event_id); 421 event.SetId(++motion_event_id);
416 422
417 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 423 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 kFakeCoordX * 5, 519 kFakeCoordX * 5,
514 kFakeCoordY * 5); 520 kFakeCoordY * 5);
515 event.SetId(++motion_event_id); 521 event.SetId(++motion_event_id);
516 522
517 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 523 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
518 EXPECT_TRUE(gesture_provider_->IsScrollInProgress()); 524 EXPECT_TRUE(gesture_provider_->IsScrollInProgress());
519 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN)); 525 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SCROLL_BEGIN));
520 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType()); 526 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, GetMostRecentGestureEventType());
521 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 527 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
522 ASSERT_EQ(3U, GetReceivedGestureCount()); 528 ASSERT_EQ(3U, GetReceivedGestureCount());
523 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type); 529 ASSERT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
524 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id); 530 EXPECT_EQ(motion_event_id, GetReceivedGesture(1).motion_event_id);
525 531
526 // We don't want to take a dependency here on exactly how hints are calculated 532 // We don't want to take a dependency here on exactly how hints are calculated
527 // for a fling (eg. may depend on velocity), so just validate the direction. 533 // for a fling (eg. may depend on velocity), so just validate the direction.
528 int hint_x = GetReceivedGesture(1).details.scroll_x_hint(); 534 int hint_x = GetReceivedGesture(1).details.scroll_x_hint();
529 int hint_y = GetReceivedGesture(1).details.scroll_y_hint(); 535 int hint_y = GetReceivedGesture(1).details.scroll_y_hint();
530 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y) 536 EXPECT_TRUE(hint_x > 0 && hint_y > 0 && hint_x > hint_y)
531 << "ScrollBegin hint should be in positive X axis"; 537 << "ScrollBegin hint should be in positive X axis";
532 538
533 event = ObtainMotionEvent(event_time + delta_time * 2, 539 event = ObtainMotionEvent(event_time + delta_time * 2,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 637 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
632 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 638 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
633 639
634 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3, 640 event = ObtainMotionEvent(event_time + kOneMicrosecond * 3,
635 MotionEvent::ACTION_UP, 641 MotionEvent::ACTION_UP,
636 kFakeCoordX, 642 kFakeCoordX,
637 kFakeCoordY + 1); 643 kFakeCoordY + 1);
638 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 644 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
639 645
640 const GestureEventData& double_tap = GetMostRecentGestureEvent(); 646 const GestureEventData& double_tap = GetMostRecentGestureEvent();
641 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type); 647 EXPECT_EQ(ET_GESTURE_DOUBLE_TAP, double_tap.type());
642 // Ensure tap details have been set. 648 // Ensure tap details have been set.
643 EXPECT_EQ(10, double_tap.details.bounding_box().width()); 649 EXPECT_EQ(10, double_tap.details.bounding_box().width());
644 EXPECT_EQ(10, double_tap.details.bounding_box().height()); 650 EXPECT_EQ(10, double_tap.details.bounding_box().height());
645 EXPECT_EQ(1, double_tap.details.tap_count()); 651 EXPECT_EQ(1, double_tap.details.tap_count());
646 } 652 }
647 653
648 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) { 654 TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
649 const base::TimeTicks down_time_1 = TimeTicks::Now(); 655 const base::TimeTicks down_time_1 = TimeTicks::Now();
650 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2; 656 const base::TimeTicks down_time_2 = down_time_1 + kOneMicrosecond * 2;
651 657
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 736
731 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 737 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
732 MotionEvent::ACTION_MOVE, 738 MotionEvent::ACTION_MOVE,
733 kFakeCoordX - delta_x, 739 kFakeCoordX - delta_x,
734 kFakeCoordY - delta_y); 740 kFakeCoordY - delta_y);
735 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 741 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
736 742
737 // Make sure the reported gesture event has all the expected details. 743 // Make sure the reported gesture event has all the expected details.
738 ASSERT_LT(0U, GetReceivedGestureCount()); 744 ASSERT_LT(0U, GetReceivedGestureCount());
739 GestureEventData gesture = GetMostRecentGestureEvent(); 745 GestureEventData gesture = GetMostRecentGestureEvent();
740 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); 746 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
741 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time); 747 EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
742 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x); 748 EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
743 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y); 749 EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
744 EXPECT_EQ(1, gesture.details.touch_points()); 750 EXPECT_EQ(1, gesture.details.touch_points());
745 751
746 // No horizontal delta because of snapping. 752 // No horizontal delta because of snapping.
747 EXPECT_EQ(0, gesture.details.scroll_x()); 753 EXPECT_EQ(0, gesture.details.scroll_x());
748 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y()); 754 EXPECT_EQ(-delta_y / 2, gesture.details.scroll_y());
749 } 755 }
750 756
(...skipping 23 matching lines...) Expand all
774 // horizontal motion. 780 // horizontal motion.
775 for(int i = 1; i <= 10; i++) { 781 for(int i = 1; i <= 10; i++) {
776 event = ObtainMotionEvent(event_time + kOneMicrosecond * i, 782 event = ObtainMotionEvent(event_time + kOneMicrosecond * i,
777 MotionEvent::ACTION_MOVE, 783 MotionEvent::ACTION_MOVE,
778 kFakeCoordX + delta_x * i, 784 kFakeCoordX + delta_x * i,
779 kFakeCoordY + delta_y * i); 785 kFakeCoordY + delta_y * i);
780 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 786 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
781 787
782 ASSERT_LT(0U, GetReceivedGestureCount()); 788 ASSERT_LT(0U, GetReceivedGestureCount());
783 GestureEventData gesture = GetMostRecentGestureEvent(); 789 GestureEventData gesture = GetMostRecentGestureEvent();
784 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type); 790 EXPECT_EQ(ET_GESTURE_SCROLL_UPDATE, gesture.type());
785 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time); 791 EXPECT_EQ(event_time + kOneMicrosecond * i, gesture.time);
786 EXPECT_EQ(1, gesture.details.touch_points()); 792 EXPECT_EQ(1, gesture.details.touch_points());
787 793
788 // Verify that the event co-ordinates are still the precise values we 794 // Verify that the event co-ordinates are still the precise values we
789 // supplied. 795 // supplied.
790 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); 796 EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x);
791 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y); 797 EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y);
792 798
793 // Verify that we're scrolling vertically by the expected amount 799 // Verify that we're scrolling vertically by the expected amount
794 // (modulo rounding). 800 // (modulo rounding).
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 // Verify that gesture begin and gesture end events are dispatched correctly. 1731 // Verify that gesture begin and gesture end events are dispatched correctly.
1726 TEST_F(GestureProviderTest, GestureBeginAndEnd) { 1732 TEST_F(GestureProviderTest, GestureBeginAndEnd) {
1727 EnableBeginEndTypes(); 1733 EnableBeginEndTypes();
1728 base::TimeTicks event_time = base::TimeTicks::Now(); 1734 base::TimeTicks event_time = base::TimeTicks::Now();
1729 1735
1730 EXPECT_EQ(0U, GetReceivedGestureCount()); 1736 EXPECT_EQ(0U, GetReceivedGestureCount());
1731 MockMotionEvent event = 1737 MockMotionEvent event =
1732 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1); 1738 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
1733 event.pointer_count = 1; 1739 event.pointer_count = 1;
1734 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1740 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1735 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); 1741 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
1736 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1742 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1737 EXPECT_EQ(2U, GetReceivedGestureCount()); 1743 EXPECT_EQ(2U, GetReceivedGestureCount());
1738 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1744 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1739 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1745 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1740 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1746 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
1741 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1747 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
1742 1 - kMockTouchRadius, 1748 1 - kMockTouchRadius,
1743 kMockTouchRadius * 2, 1749 kMockTouchRadius * 2,
1744 kMockTouchRadius * 2), 1750 kMockTouchRadius * 2),
1745 GetMostRecentGestureEvent().details.bounding_box()); 1751 GetMostRecentGestureEvent().details.bounding_box());
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 // when an ACTION_CANCEL is received. 1825 // when an ACTION_CANCEL is received.
1820 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) { 1826 TEST_F(GestureProviderTest, GestureBeginAndEndOnCancel) {
1821 EnableBeginEndTypes(); 1827 EnableBeginEndTypes();
1822 base::TimeTicks event_time = base::TimeTicks::Now(); 1828 base::TimeTicks event_time = base::TimeTicks::Now();
1823 1829
1824 EXPECT_EQ(0U, GetReceivedGestureCount()); 1830 EXPECT_EQ(0U, GetReceivedGestureCount());
1825 MockMotionEvent event = 1831 MockMotionEvent event =
1826 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1); 1832 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
1827 event.pointer_count = 1; 1833 event.pointer_count = 1;
1828 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1834 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1829 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type); 1835 EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
1830 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 1836 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
1831 EXPECT_EQ(2U, GetReceivedGestureCount()); 1837 EXPECT_EQ(2U, GetReceivedGestureCount());
1832 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 1838 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
1833 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius, 1839 EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
1834 1 - kMockTouchRadius, 1840 1 - kMockTouchRadius,
1835 kMockTouchRadius * 2, 1841 kMockTouchRadius * 2,
1836 kMockTouchRadius * 2), 1842 kMockTouchRadius * 2),
1837 GetMostRecentGestureEvent().details.bounding_box()); 1843 GetMostRecentGestureEvent().details.bounding_box());
1838 EXPECT_EQ(1, GetMostRecentGestureEvent().x); 1844 EXPECT_EQ(1, GetMostRecentGestureEvent().x);
1839 EXPECT_EQ(1, GetMostRecentGestureEvent().y); 1845 EXPECT_EQ(1, GetMostRecentGestureEvent().y);
(...skipping 18 matching lines...) Expand all
1858 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points()); 1864 EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
1859 EXPECT_EQ(3, GetMostRecentGestureEvent().x); 1865 EXPECT_EQ(3, GetMostRecentGestureEvent().x);
1860 EXPECT_EQ(3, GetMostRecentGestureEvent().y); 1866 EXPECT_EQ(3, GetMostRecentGestureEvent().y);
1861 1867
1862 event = ObtainMotionEvent( 1868 event = ObtainMotionEvent(
1863 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 2, 2, 3, 3); 1869 event_time, MotionEvent::ACTION_CANCEL, 1, 1, 2, 2, 3, 3);
1864 event.pointer_count = 3; 1870 event.pointer_count = 3;
1865 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1871 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1866 EXPECT_EQ(7U, GetReceivedGestureCount()); 1872 EXPECT_EQ(7U, GetReceivedGestureCount());
1867 EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points()); 1873 EXPECT_EQ(3, GetReceivedGesture(4).details.touch_points());
1868 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).details.type()); 1874 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(4).type());
1869 EXPECT_EQ(2, GetReceivedGesture(5).details.touch_points()); 1875 EXPECT_EQ(2, GetReceivedGesture(5).details.touch_points());
1870 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(5).details.type()); 1876 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(5).type());
1871 EXPECT_EQ(1, GetReceivedGesture(6).details.touch_points()); 1877 EXPECT_EQ(1, GetReceivedGesture(6).details.touch_points());
1872 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(6).details.type()); 1878 EXPECT_EQ(ET_GESTURE_END, GetReceivedGesture(6).type());
1873 EXPECT_EQ(1, GetReceivedGesture(4).x); 1879 EXPECT_EQ(1, GetReceivedGesture(4).x);
1874 EXPECT_EQ(1, GetReceivedGesture(4).y); 1880 EXPECT_EQ(1, GetReceivedGesture(4).y);
1875 EXPECT_EQ(2, GetReceivedGesture(5).x); 1881 EXPECT_EQ(2, GetReceivedGesture(5).x);
1876 EXPECT_EQ(2, GetReceivedGesture(5).y); 1882 EXPECT_EQ(2, GetReceivedGesture(5).y);
1877 EXPECT_EQ(3, GetReceivedGesture(6).x); 1883 EXPECT_EQ(3, GetReceivedGesture(6).x);
1878 EXPECT_EQ(3, GetReceivedGesture(6).y); 1884 EXPECT_EQ(3, GetReceivedGesture(6).y);
1879 } 1885 }
1880 1886
1881 // Test a simple two finger tap 1887 // Test a simple two finger tap
1882 TEST_F(GestureProviderTest, TwoFingerTap) { 1888 TEST_F(GestureProviderTest, TwoFingerTap) {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1914 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1920 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1915 1921
1916 event = ObtainMotionEvent(event_time, 1922 event = ObtainMotionEvent(event_time,
1917 MotionEvent::ACTION_POINTER_UP, 1923 MotionEvent::ACTION_POINTER_UP,
1918 0, 1924 0,
1919 0, 1925 0,
1920 kMaxTwoFingerTapSeparation, 1926 kMaxTwoFingerTapSeparation,
1921 0); 1927 0);
1922 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1928 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1923 1929
1924 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); 1930 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
1925 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type); 1931 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
1926 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(2).type); 1932 EXPECT_EQ(ET_GESTURE_TWO_FINGER_TAP, GetReceivedGesture(2).type());
1927 EXPECT_EQ(3U, GetReceivedGestureCount()); 1933 EXPECT_EQ(3U, GetReceivedGestureCount());
1928 1934
1929 EXPECT_EQ(kMockTouchRadius * 2, 1935 EXPECT_EQ(kMockTouchRadius * 2,
1930 GetReceivedGesture(2).details.first_finger_width()); 1936 GetReceivedGesture(2).details.first_finger_width());
1931 EXPECT_EQ(kMockTouchRadius * 2, 1937 EXPECT_EQ(kMockTouchRadius * 2,
1932 GetReceivedGesture(2).details.first_finger_height()); 1938 GetReceivedGesture(2).details.first_finger_height());
1933 } 1939 }
1934 1940
1935 // Test preventing a two finger tap via finger movement. 1941 // Test preventing a two finger tap via finger movement.
1936 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) { 1942 TEST_F(GestureProviderTest, TwoFingerTapCancelledByFingerMovement) {
(...skipping 22 matching lines...) Expand all
1959 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1965 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1960 1966
1961 event = ObtainMotionEvent(event_time, 1967 event = ObtainMotionEvent(event_time,
1962 MotionEvent::ACTION_POINTER_UP, 1968 MotionEvent::ACTION_POINTER_UP,
1963 kFakeCoordX, 1969 kFakeCoordX,
1964 kFakeCoordY, 1970 kFakeCoordY,
1965 kFakeCoordX, 1971 kFakeCoordX,
1966 kFakeCoordY); 1972 kFakeCoordY);
1967 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 1973 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1968 1974
1969 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); 1975 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
1970 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type); 1976 EXPECT_EQ(ET_GESTURE_SCROLL_BEGIN, GetReceivedGesture(1).type());
1971 EXPECT_EQ(2U, GetReceivedGestureCount()); 1977 EXPECT_EQ(2U, GetReceivedGestureCount());
1972 } 1978 }
1973 1979
1974 // Test preventing a two finger tap by waiting too long before releasing the 1980 // Test preventing a two finger tap by waiting too long before releasing the
1975 // secondary pointer. 1981 // secondary pointer.
1976 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) { 1982 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDelay) {
1977 base::TimeDelta two_finger_tap_timeout = kOneSecond; 1983 base::TimeDelta two_finger_tap_timeout = kOneSecond;
1978 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout); 1984 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, two_finger_tap_timeout);
1979 base::TimeTicks event_time = base::TimeTicks::Now(); 1985 base::TimeTicks event_time = base::TimeTicks::Now();
1980 1986
(...skipping 15 matching lines...) Expand all
1996 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2002 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
1997 2003
1998 event = ObtainMotionEvent(event_time + kOneSecond + kOneMicrosecond, 2004 event = ObtainMotionEvent(event_time + kOneSecond + kOneMicrosecond,
1999 MotionEvent::ACTION_POINTER_UP, 2005 MotionEvent::ACTION_POINTER_UP,
2000 kFakeCoordX, 2006 kFakeCoordX,
2001 kFakeCoordY, 2007 kFakeCoordY,
2002 kFakeCoordX + kMaxTwoFingerTapSeparation / 2, 2008 kFakeCoordX + kMaxTwoFingerTapSeparation / 2,
2003 kFakeCoordY); 2009 kFakeCoordY);
2004 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2010 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2005 2011
2006 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); 2012 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2007 EXPECT_EQ(1U, GetReceivedGestureCount()); 2013 EXPECT_EQ(1U, GetReceivedGestureCount());
2008 } 2014 }
2009 2015
2010 // Test preventing a two finger tap by pressing the secondary pointer too far 2016 // Test preventing a two finger tap by pressing the secondary pointer too far
2011 // from the first 2017 // from the first
2012 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) { 2018 TEST_F(GestureProviderTest, TwoFingerTapCancelledByDistanceBetweenPointers) {
2013 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta()); 2019 EnableTwoFingerTap(kMaxTwoFingerTapSeparation, base::TimeDelta());
2014 base::TimeTicks event_time = base::TimeTicks::Now(); 2020 base::TimeTicks event_time = base::TimeTicks::Now();
2015 2021
2016 MockMotionEvent event = ObtainMotionEvent( 2022 MockMotionEvent event = ObtainMotionEvent(
2017 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY); 2023 event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, kFakeCoordY);
2018 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2024 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2019 2025
2020 event = ObtainMotionEvent(event_time, 2026 event = ObtainMotionEvent(event_time,
2021 MotionEvent::ACTION_POINTER_DOWN, 2027 MotionEvent::ACTION_POINTER_DOWN,
2022 kFakeCoordX, 2028 kFakeCoordX,
2023 kFakeCoordY, 2029 kFakeCoordY,
2024 kFakeCoordX + kMaxTwoFingerTapSeparation, 2030 kFakeCoordX + kMaxTwoFingerTapSeparation,
2025 kFakeCoordY); 2031 kFakeCoordY);
2026 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2032 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2027 2033
2028 event = ObtainMotionEvent(event_time, 2034 event = ObtainMotionEvent(event_time,
2029 MotionEvent::ACTION_POINTER_UP, 2035 MotionEvent::ACTION_POINTER_UP,
2030 kFakeCoordX, 2036 kFakeCoordX,
2031 kFakeCoordY, 2037 kFakeCoordY,
2032 kFakeCoordX + kMaxTwoFingerTapSeparation, 2038 kFakeCoordX + kMaxTwoFingerTapSeparation,
2033 kFakeCoordY); 2039 kFakeCoordY);
2034 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2040 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2035 2041
2036 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type); 2042 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetReceivedGesture(0).type());
2037 EXPECT_EQ(1U, GetReceivedGestureCount()); 2043 EXPECT_EQ(1U, GetReceivedGestureCount());
2038 } 2044 }
2039 2045
2040 // Verify that pinch zoom only sends updates which exceed the 2046 // Verify that pinch zoom only sends updates which exceed the
2041 // min_pinch_update_span_delta. 2047 // min_pinch_update_span_delta.
2042 TEST_F(GestureProviderTest, PinchZoomWithThreshold) { 2048 TEST_F(GestureProviderTest, PinchZoomWithThreshold) {
2043 const float kMinPinchUpdateDistance = 5; 2049 const float kMinPinchUpdateDistance = 5;
2044 2050
2045 base::TimeTicks event_time = base::TimeTicks::Now(); 2051 base::TimeTicks event_time = base::TimeTicks::Now();
2046 const float touch_slop = GetTouchSlop(); 2052 const float touch_slop = GetTouchSlop();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2111 kFakeCoordY, 2117 kFakeCoordY,
2112 secondary_coord_x + kMinPinchUpdateDistance + 2118 secondary_coord_x + kMinPinchUpdateDistance +
2113 kOvershootMinPinchUpdateDistance, 2119 kOvershootMinPinchUpdateDistance,
2114 secondary_coord_y); 2120 secondary_coord_y);
2115 2121
2116 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2122 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2117 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE)); 2123 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_PINCH_UPDATE));
2118 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points()); 2124 EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
2119 } 2125 }
2120 2126
2127 // Verify that the min gesture bound setting is honored.
2128 TEST_F(GestureProviderTest, MinGestureBoundsLength) {
2129 const float kMinGestureBoundsLength = 10.f * kMockTouchRadius;
2130 SetMinGestureBoundsLength(kMinGestureBoundsLength);
2131 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2132
2133 base::TimeTicks event_time = base::TimeTicks::Now();
2134 MockMotionEvent event =
2135 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2136 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2137
2138 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
2139 EXPECT_EQ(kMinGestureBoundsLength,
2140 GetMostRecentGestureEvent().details.bounding_box_f().width());
2141 EXPECT_EQ(kMinGestureBoundsLength,
2142 GetMostRecentGestureEvent().details.bounding_box_f().height());
2143
2144 event =
2145 ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
2146 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2147 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2148 EXPECT_EQ(kMinGestureBoundsLength,
2149 GetMostRecentGestureEvent().details.bounding_box_f().width());
2150 EXPECT_EQ(kMinGestureBoundsLength,
2151 GetMostRecentGestureEvent().details.bounding_box_f().height());
2152 }
2153
2121 } // namespace ui 2154 } // 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