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

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

Issue 1358263002: [Android] Support double-tap selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix contextual search Created 5 years, 2 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 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SetSingleTapRepeatInterval(int repeat_interval) {
270 GestureProvider::Config config = GetDefaultConfig();
271 config.gesture_detector_config.single_tap_repeat_interval = repeat_interval;
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
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 SetSingleTapRepeatInterval(3);
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 second tap after the double-tap timeout window will not increment
2548 // the tap count.
2549 event_time += GetDoubleTapTimeout() + kOneMicrosecond;
2550 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2551 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2552 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2553 gesture_provider_->OnTouchEvent(event);
2554 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2555 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2556
2557 // A secondary tap within the tap repeat period should increment
2558 // the tap count.
2559 event_time += GetValidDoubleTapDelay();
2560 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2561 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2562 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2563 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2564 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2565 EXPECT_EQ(2, GetMostRecentGestureEvent().details.tap_count());
2566
2567 // A secondary tap within the tap repeat location threshold should increment
2568 // the tap count.
2569 event_time += GetValidDoubleTapDelay();
2570 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX,
2571 kFakeCoordY + GetTouchSlop() / 2);
2572 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2573 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2574 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2575 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2576 EXPECT_EQ(3, GetMostRecentGestureEvent().details.tap_count());
2577
2578 // The tap count should reset after hitting the repeat length.
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 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2585 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2586
2587 // If double-tap is enabled, the tap repeat count should always be 1.
2588 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(true);
2589 event_time += GetValidDoubleTapDelay();
2590 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2591 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2592 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2593 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2594 RunTasksAndWait(GetDoubleTapTimeout());
2595 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2596 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2597
2598 event_time += GetValidDoubleTapDelay();
2599 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2600 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2601 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2602 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2603 RunTasksAndWait(GetDoubleTapTimeout());
2604 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2605 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2606 }
2607
2608 TEST_F(GestureProviderTest, SingleTapRepeatLengthOfOne) {
2609 SetSingleTapRepeatInterval(1);
2610
2611 gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
2612
2613 base::TimeTicks event_time = base::TimeTicks::Now();
2614
2615 MockMotionEvent event =
2616 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2617 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2618 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2619 gesture_provider_->OnTouchEvent(event);
2620 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2621 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2622
2623 // Repeated taps should still produce a tap count of 1 if the
2624 // tap repeat length is 1.
2625 event_time += GetValidDoubleTapDelay();
2626 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
2627 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2628 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2629 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2630 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2631 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2632
2633 event_time += GetValidDoubleTapDelay();
2634 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, kFakeCoordX,
2635 kFakeCoordY + GetTouchSlop() / 2);
2636 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2637 event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP);
2638 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2639 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2640 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2641 }
2642
2526 } // namespace ui 2643 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider_config_helper.cc ('k') | ui/events/gestures/gesture_provider_aura.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698