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

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

Issue 717573004: [Android] Thoroughly reset gesture detection upon page navigation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix comment Created 6 years, 1 month 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
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 active_scroll_begin_event_.reset(new GestureEventData(gesture)); 136 active_scroll_begin_event_.reset(new GestureEventData(gesture));
137 gestures_.push_back(gesture); 137 gestures_.push_back(gesture);
138 } 138 }
139 139
140 void SetUpWithConfig(const GestureProvider::Config& config) { 140 void SetUpWithConfig(const GestureProvider::Config& config) {
141 gesture_provider_.reset(new GestureProvider(config, this)); 141 gesture_provider_.reset(new GestureProvider(config, this));
142 gesture_provider_->SetMultiTouchZoomSupportEnabled(false); 142 gesture_provider_->SetMultiTouchZoomSupportEnabled(false);
143 } 143 }
144 144
145 void ResetGestureDetection() { 145 void ResetGestureDetection() {
146 CancelActiveTouchSequence(); 146 gesture_provider_->ResetDetection();
147 gestures_.clear(); 147 gestures_.clear();
148 } 148 }
149
149 bool CancelActiveTouchSequence() { 150 bool CancelActiveTouchSequence() {
150 if (!gesture_provider_->current_down_event()) 151 if (!gesture_provider_->current_down_event())
151 return false; 152 return false;
152 return gesture_provider_->OnTouchEvent( 153 return gesture_provider_->OnTouchEvent(
153 *gesture_provider_->current_down_event()->Cancel()); 154 *gesture_provider_->current_down_event()->Cancel());
154 } 155 }
155 156
156 bool HasReceivedGesture(EventType type) const { 157 bool HasReceivedGesture(EventType type) const {
157 for (size_t i = 0; i < gestures_.size(); ++i) { 158 for (size_t i = 0; i < gestures_.size(); ++i) {
158 if (gestures_[i].type() == type) 159 if (gestures_[i].type() == type)
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 603 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
603 EXPECT_FALSE(gesture_provider_->IsScrollInProgress()); 604 EXPECT_FALSE(gesture_provider_->IsScrollInProgress());
604 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType()); 605 EXPECT_EQ(ET_SCROLL_FLING_START, GetMostRecentGestureEventType());
605 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id); 606 EXPECT_EQ(motion_event_id, GetMostRecentGestureEvent().motion_event_id);
606 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 607 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
607 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END)); 608 EXPECT_FALSE(HasReceivedGesture(ET_GESTURE_SCROLL_END));
608 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time) 609 EXPECT_EQ(event_time + delta_time * 2, GetMostRecentGestureEvent().time)
609 << "FlingStart should have the time of the ACTION_UP"; 610 << "FlingStart should have the time of the ACTION_UP";
610 } 611 }
611 612
612 TEST_F(GestureProviderTest, GestureCancelledWhenWindowFocusLost) { 613 TEST_F(GestureProviderTest, GestureCancelledOnCancelEvent) {
613 const base::TimeTicks event_time = TimeTicks::Now(); 614 const base::TimeTicks event_time = TimeTicks::Now();
614 615
615 MockMotionEvent event = 616 MockMotionEvent event =
616 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 617 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
617 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 618 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
618 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 619 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
619 620
620 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() + 621 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
621 kOneMicrosecond); 622 kOneMicrosecond);
622 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS)); 623 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
623 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType()); 624 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
624 625
625 // The long press triggers window focus loss by opening a context menu. 626 // A cancellation event may be triggered for a number of reasons, e.g.,
627 // from a context-menu-triggering long press resulting in loss of focus.
626 EXPECT_TRUE(CancelActiveTouchSequence()); 628 EXPECT_TRUE(CancelActiveTouchSequence());
627 EXPECT_FALSE(HasDownEvent()); 629 EXPECT_FALSE(HasDownEvent());
628 630
629 // A final ACTION_UP should have no effect. 631 // A final ACTION_UP should have no effect.
630 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2, 632 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
631 MotionEvent::ACTION_UP); 633 MotionEvent::ACTION_UP);
632 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event)); 634 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
633 } 635 }
634 636
637 TEST_F(GestureProviderTest, GestureCancelledOnDetectionReset) {
638 const base::TimeTicks event_time = TimeTicks::Now();
639
640 MockMotionEvent event =
641 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
642 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
643 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
644
645 RunTasksAndWait(GetLongPressTimeout() + GetShowPressTimeout() +
646 kOneMicrosecond);
647 EXPECT_TRUE(HasReceivedGesture(ET_GESTURE_SHOW_PRESS));
648 EXPECT_EQ(ET_GESTURE_LONG_PRESS, GetMostRecentGestureEventType());
649
650 ResetGestureDetection();
651 EXPECT_FALSE(HasDownEvent());
652
653 // A final ACTION_UP should have no effect.
654 event = ObtainMotionEvent(event_time + kOneMicrosecond * 2,
655 MotionEvent::ACTION_UP);
656 EXPECT_FALSE(gesture_provider_->OnTouchEvent(event));
657 }
658
635 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) { 659 TEST_F(GestureProviderTest, NoTapAfterScrollBegins) {
636 base::TimeTicks event_time = base::TimeTicks::Now(); 660 base::TimeTicks event_time = base::TimeTicks::Now();
637 661
638 MockMotionEvent event = 662 MockMotionEvent event =
639 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); 663 ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
640 664
641 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 665 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
642 666
643 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType()); 667 EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
644 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 668 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
(...skipping 1848 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); 2517 EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
2494 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); 2518 EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
2495 2519
2496 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count()); 2520 EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
2497 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points()); 2521 EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
2498 EXPECT_EQ(gfx::RectF(0, 0, 20, 20), 2522 EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
2499 GetMostRecentGestureEvent().details.bounding_box()); 2523 GetMostRecentGestureEvent().details.bounding_box());
2500 } 2524 }
2501 2525
2502 } // namespace ui 2526 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698