OLD | NEW |
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 Loading... |
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 | |
461 base::HistogramTester& histogram_tester() { | 457 base::HistogramTester& histogram_tester() { |
462 return histogram_tester_; | 458 return histogram_tester_; |
463 } | 459 } |
464 | 460 |
465 protected: | 461 protected: |
466 const bool synchronous_root_scroll_; | 462 const bool synchronous_root_scroll_; |
467 const bool install_synchronous_handler_; | 463 const bool install_synchronous_handler_; |
468 testing::StrictMock<MockInputHandler> mock_input_handler_; | 464 testing::StrictMock<MockInputHandler> mock_input_handler_; |
469 testing::StrictMock<MockSynchronousInputHandler> | 465 testing::StrictMock<MockSynchronousInputHandler> |
470 mock_synchronous_input_handler_; | 466 mock_synchronous_input_handler_; |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); | 911 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
916 | 912 |
917 VERIFY_AND_RESET_MOCKS(); | 913 VERIFY_AND_RESET_MOCKS(); |
918 | 914 |
919 // Verify that a GestureFlingCancel during an animation cancels it. | 915 // Verify that a GestureFlingCancel during an animation cancels it. |
920 gesture_.setType(WebInputEvent::GestureFlingCancel); | 916 gesture_.setType(WebInputEvent::GestureFlingCancel); |
921 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; | 917 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; |
922 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); | 918 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
923 } | 919 } |
924 | 920 |
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); | |
1015 | |
1016 VERIFY_AND_RESET_MOCKS(); | |
1017 } | |
1018 | |
1019 TEST_P(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) { | 921 TEST_P(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) { |
1020 // We should send all events to the widget for this gesture. | 922 // We should send all events to the widget for this gesture. |
1021 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; | 923 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; |
1022 VERIFY_AND_RESET_MOCKS(); | 924 VERIFY_AND_RESET_MOCKS(); |
1023 | 925 |
1024 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 926 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
1025 .WillOnce(testing::Return(kMainThreadScrollState)); | 927 .WillOnce(testing::Return(kMainThreadScrollState)); |
1026 | 928 |
1027 gesture_.setType(WebInputEvent::GestureFlingStart); | 929 gesture_.setType(WebInputEvent::GestureFlingStart); |
1028 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; | 930 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; |
(...skipping 2201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3230 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type); | 3132 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type); |
3231 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 3133 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
3232 } | 3134 } |
3233 | 3135 |
3234 INSTANTIATE_TEST_CASE_P(AnimateInput, | 3136 INSTANTIATE_TEST_CASE_P(AnimateInput, |
3235 InputHandlerProxyTest, | 3137 InputHandlerProxyTest, |
3236 testing::ValuesIn(test_types)); | 3138 testing::ValuesIn(test_types)); |
3237 | 3139 |
3238 } // namespace test | 3140 } // namespace test |
3239 } // namespace ui | 3141 } // namespace ui |
OLD | NEW |