Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 } | 259 } |
| 260 | 260 |
| 261 void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout, | 261 void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout, |
| 262 base::TimeDelta longpress_timeout) { | 262 base::TimeDelta longpress_timeout) { |
| 263 GestureProvider::Config config = GetDefaultConfig(); | 263 GestureProvider::Config config = GetDefaultConfig(); |
| 264 config.gesture_detector_config.showpress_timeout = showpress_timeout; | 264 config.gesture_detector_config.showpress_timeout = showpress_timeout; |
| 265 config.gesture_detector_config.longpress_timeout = longpress_timeout; | 265 config.gesture_detector_config.longpress_timeout = longpress_timeout; |
| 266 SetUpWithConfig(config); | 266 SetUpWithConfig(config); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void SetSingleTapRepeatLength(int repeat_length) { | |
| 270 GestureProvider::Config config = GetDefaultConfig(); | |
| 271 config.gesture_detector_config.single_tap_repeat_length = repeat_length; | |
| 272 SetUpWithConfig(config); | |
| 273 } | |
| 274 | |
| 269 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } | 275 bool HasDownEvent() const { return gesture_provider_->current_down_event(); } |
| 270 | 276 |
| 271 protected: | 277 protected: |
| 272 void CheckScrollEventSequenceForEndActionType( | 278 void CheckScrollEventSequenceForEndActionType( |
| 273 MotionEvent::Action end_action_type) { | 279 MotionEvent::Action end_action_type) { |
| 274 base::TimeTicks event_time = base::TimeTicks::Now(); | 280 base::TimeTicks event_time = base::TimeTicks::Now(); |
| 275 const float scroll_to_x = kFakeCoordX + 100; | 281 const float scroll_to_x = kFakeCoordX + 100; |
| 276 const float scroll_to_y = kFakeCoordY + 100; | 282 const float scroll_to_y = kFakeCoordY + 100; |
| 277 int motion_event_id = 3; | 283 int motion_event_id = 3; |
| 278 int motion_event_flags = EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN; | 284 int motion_event_flags = EF_SHIFT_DOWN | EF_CAPS_LOCK_DOWN; |
| (...skipping 2237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2516 event.SetTouchMajor(30); | 2522 event.SetTouchMajor(30); |
| 2517 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | 2523 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); |
| 2518 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | 2524 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); |
| 2519 | 2525 |
| 2520 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | 2526 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); |
| 2521 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); | 2527 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); |
| 2522 EXPECT_EQ(gfx::RectF(0, 0, 20, 20), | 2528 EXPECT_EQ(gfx::RectF(0, 0, 20, 20), |
| 2523 GetMostRecentGestureEvent().details.bounding_box_f()); | 2529 GetMostRecentGestureEvent().details.bounding_box_f()); |
| 2524 } | 2530 } |
| 2525 | 2531 |
| 2532 TEST_F(GestureProviderTest, SingleTapRepeat) { | |
| 2533 SetSingleTapRepeatLength(3); | |
|
tdresser
2015/09/23 14:10:46
Do we have adequate coverage of when the repeat le
jdduke (slow)
2015/09/23 19:56:04
Probably not, I'll add a test.
| |
| 2534 | |
| 2535 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false); | |
| 2536 | |
| 2537 base::TimeTicks event_time = base::TimeTicks::Now(); | |
| 2538 | |
| 2539 MockMotionEvent event = | |
| 2540 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 2541 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2542 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 2543 gesture_provider_->OnTouchEvent(event); | |
| 2544 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | |
| 2545 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | |
| 2546 | |
| 2547 // A secondary tap within the tap repeat period should increment | |
| 2548 // the tap count. | |
| 2549 event_time += GetValidDoubleTapDelay(); | |
| 2550 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 2551 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2552 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 2553 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2554 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | |
| 2555 EXPECT_EQ(2, GetMostRecentGestureEvent().details.tap_count()); | |
| 2556 | |
| 2557 // A secondary tap within the tap repeat location threshold should increment | |
| 2558 // the tap count. | |
| 2559 event_time += GetValidDoubleTapDelay(); | |
| 2560 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX, | |
| 2561 kFakeCoordY + GetTouchSlop() / 2); | |
| 2562 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2563 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 2564 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2565 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | |
| 2566 EXPECT_EQ(3, GetMostRecentGestureEvent().details.tap_count()); | |
| 2567 | |
| 2568 // The tap count should reset after hitting the repeat length. | |
| 2569 event_time += GetValidDoubleTapDelay(); | |
| 2570 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 2571 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2572 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 2573 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2574 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | |
| 2575 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | |
| 2576 | |
| 2577 // If double-tap is enabled, the tap repeat count should always be 1. | |
| 2578 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true); | |
| 2579 event_time += GetValidDoubleTapDelay(); | |
| 2580 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 2581 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2582 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 2583 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2584 RunTasksAndWait(GetDoubleTapTimeout()); | |
| 2585 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | |
| 2586 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | |
| 2587 | |
| 2588 event_time += GetValidDoubleTapDelay(); | |
| 2589 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); | |
| 2590 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2591 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP); | |
| 2592 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); | |
| 2593 RunTasksAndWait(GetDoubleTapTimeout()); | |
| 2594 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); | |
| 2595 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); | |
| 2596 } | |
| 2597 | |
| 2526 } // namespace ui | 2598 } // namespace ui |
| OLD | NEW |