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

Side by Side Diff: ui/events/blink/input_handler_proxy_unittest.cc

Issue 2625453002: Touchpad and wheel scroll latching for ChromeOS behind flag. (Closed)
Patch Set: ScrollEnd gets called when the fling ends before hitting a scroll extent. Created 3 years, 11 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
« no previous file with comments | « ui/events/blink/input_handler_proxy.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/events/blink/input_handler_proxy.h" 5 #include "ui/events/blink/input_handler_proxy.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 EXPECT_EQ(expected_disposition_, 447 EXPECT_EQ(expected_disposition_,
448 input_handler_->HandleInputEvent(gesture_)); 448 input_handler_->HandleInputEvent(gesture_));
449 449
450 VERIFY_AND_RESET_MOCKS(); 450 VERIFY_AND_RESET_MOCKS();
451 } 451 }
452 452
453 void SetSmoothScrollEnabled(bool value) { 453 void SetSmoothScrollEnabled(bool value) {
454 input_handler_->smooth_scroll_enabled_ = value; 454 input_handler_->smooth_scroll_enabled_ = value;
455 } 455 }
456 456
457 void SetTouchpadAndWheelScrollLatchingEnabled(bool value) {
458 input_handler_->touchpad_and_wheel_scroll_latching_enabled_ = value;
459 }
460
457 base::HistogramTester& histogram_tester() { 461 base::HistogramTester& histogram_tester() {
458 return histogram_tester_; 462 return histogram_tester_;
459 } 463 }
460 464
461 protected: 465 protected:
462 const bool synchronous_root_scroll_; 466 const bool synchronous_root_scroll_;
463 const bool install_synchronous_handler_; 467 const bool install_synchronous_handler_;
464 testing::StrictMock<MockInputHandler> mock_input_handler_; 468 testing::StrictMock<MockInputHandler> mock_input_handler_;
465 testing::StrictMock<MockSynchronousInputHandler> 469 testing::StrictMock<MockSynchronousInputHandler>
466 mock_synchronous_input_handler_; 470 mock_synchronous_input_handler_;
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); 915 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
912 916
913 VERIFY_AND_RESET_MOCKS(); 917 VERIFY_AND_RESET_MOCKS();
914 918
915 // Verify that a GestureFlingCancel during an animation cancels it. 919 // Verify that a GestureFlingCancel during an animation cancels it.
916 gesture_.setType(WebInputEvent::GestureFlingCancel); 920 gesture_.setType(WebInputEvent::GestureFlingCancel);
917 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; 921 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
918 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); 922 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
919 } 923 }
920 924
925 TEST_P(InputHandlerProxyTest, GestureFlingTouchpadScrollLatchingEnabled) {
926 SetTouchpadAndWheelScrollLatchingEnabled(true);
927 // We shouldn't send any events to the widget for this gesture.
928 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
929 VERIFY_AND_RESET_MOCKS();
930
931 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_))
932 .WillOnce(testing::Return(kImplThreadScrollState));
933
934 // HandleGestureScrollBegin will set gesture_scroll_on_impl_thread_.
935 gesture_.setType(WebInputEvent::GestureScrollBegin);
936 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
937 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
938
939 VERIFY_AND_RESET_MOCKS();
940
941 // On the fling start, we should schedule an animation but not actually start
942 // scrolling.
943 gesture_.setType(WebInputEvent::GestureFlingStart);
944 WebFloatPoint fling_delta = WebFloatPoint(1000, 0);
945 WebPoint fling_point = WebPoint(7, 13);
946 WebPoint fling_global_point = WebPoint(17, 23);
947 // Note that for trackpad, wheel events with the Control modifier are
948 // special (reserved for zoom), so don't set that here.
949 int modifiers = WebInputEvent::ShiftKey | WebInputEvent::AltKey;
950 gesture_ = CreateFling(blink::WebGestureDeviceTouchpad, fling_delta,
951 fling_point, fling_global_point, modifiers);
952 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
953 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
954 .WillOnce(testing::Return(kImplThreadScrollState));
955
956 // When scroll latching is enabled, ScrollEnd shouldn't get called while
957 // handling GestureFlingStart.
958 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(0);
959 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
960
961 VERIFY_AND_RESET_MOCKS();
962
963 // The first animate call won't start scrolling.
964 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
965 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
966 Animate(time);
967
968 VERIFY_AND_RESET_MOCKS();
969
970 // The second call should start scrolling in the -X direction.
971 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
972 EXPECT_CALL(mock_input_handler_,
973 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
974 .WillOnce(testing::Return(cc::EventListenerProperties::kNone));
975
976 // When scroll latching is enabled, ScrollBegin shouldn't get called for
977 // every tick.
978 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
979 .Times(0);
980 EXPECT_CALL(
981 mock_input_handler_,
982 ScrollBy(testing::Property(&cc::ScrollState::delta_x, testing::Lt(0))))
983 .WillOnce(testing::Return(scroll_result_did_scroll_));
984
985 // When scroll latching is enabled, ScrollEnd shouldn't get called for every
986 // tick.
987 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(0);
988 time += base::TimeDelta::FromMilliseconds(100);
989 Animate(time);
990
991 VERIFY_AND_RESET_MOCKS();
992
993 // The last call should stop scrolling.
994 EXPECT_CALL(mock_input_handler_,
995 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
996 .WillOnce(testing::Return(cc::EventListenerProperties::kNone));
997
998 // When scroll latching is enabled, ScrollBegin shouldn't get called for
999 // every tick.
1000 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1001 .Times(0);
1002 EXPECT_CALL(
1003 mock_input_handler_,
1004 ScrollBy(testing::Property(&cc::ScrollState::delta_x, testing::Lt(0))))
1005 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
1006
1007 // When scroll latching is enabled, ScrollEnd gets called when the last
1008 // ScrollBy did not scroll.
1009 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_));
1010 time += base::TimeDelta::FromMilliseconds(100);
1011 Animate(time);
1012
1013 // Fling has ended, the last Animate won't cause any more wheel ticks.
1014 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_)).Times(0);
bokan 2017/01/12 19:33:17 This needs to go above the Animate call to be effe
sahel 2017/01/12 19:45:22 Thanks for the doc, I will do that. I think it's e
1015
1016 VERIFY_AND_RESET_MOCKS();
1017 }
1018
921 TEST_P(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) { 1019 TEST_P(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) {
922 // We should send all events to the widget for this gesture. 1020 // We should send all events to the widget for this gesture.
923 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; 1021 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
924 VERIFY_AND_RESET_MOCKS(); 1022 VERIFY_AND_RESET_MOCKS();
925 1023
926 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1024 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
927 .WillOnce(testing::Return(kMainThreadScrollState)); 1025 .WillOnce(testing::Return(kMainThreadScrollState));
928 1026
929 gesture_.setType(WebInputEvent::GestureFlingStart); 1027 gesture_.setType(WebInputEvent::GestureFlingStart);
930 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; 1028 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad;
(...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after
3132 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type); 3230 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type);
3133 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 3231 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
3134 } 3232 }
3135 3233
3136 INSTANTIATE_TEST_CASE_P(AnimateInput, 3234 INSTANTIATE_TEST_CASE_P(AnimateInput,
3137 InputHandlerProxyTest, 3235 InputHandlerProxyTest,
3138 testing::ValuesIn(test_types)); 3236 testing::ValuesIn(test_types));
3139 3237
3140 } // namespace test 3238 } // namespace test
3141 } // namespace ui 3239 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/input_handler_proxy.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698