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

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: 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
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 should let us pick up an animation start time, but
964 // we shouldn't actually move anywhere just yet. The first frame after the
965 // fling start will typically include the last scroll from the gesture that
966 // lead to the scroll (either wheel or gesture scroll), so there should be no
967 // visible hitch.
968 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
969 EXPECT_CALL(mock_input_handler_,
970 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
bokan 2017/01/10 18:53:59 I don't think we need this check. It seems to be o
sahel 2017/01/10 21:10:06 Done.
971 .Times(0);
972 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
973 Animate(time);
974
975 VERIFY_AND_RESET_MOCKS();
976
977 // The second call should start scrolling in the -X direction.
978 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
979 EXPECT_CALL(mock_input_handler_,
980 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
981 .WillOnce(testing::Return(cc::EventListenerProperties::kNone));
bokan 2017/01/10 18:53:58 Also don't need this, I think. The ScrollBy below
sahel 2017/01/10 21:10:06 I wanted to show that while ScrollBy in FlingScrol
bokan 2017/01/10 21:25:06 I guess I'm confused, how does GetEventListenerPro
sahel 2017/01/12 18:53:44 I want to check whether FlingScrollByMouseWheel is
982
983 // When scroll latching is enabled, ScrollBegin shouldn't get called for
984 // every tick.
985 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
986 .Times(0);
987 EXPECT_CALL(
988 mock_input_handler_,
989 ScrollBy(testing::Property(&cc::ScrollState::delta_x, testing::Lt(0))))
990 .WillOnce(testing::Return(scroll_result_did_scroll_));
991 // When scroll latching is enabled, ScrollEnd shouldn't get called for every
992 // tick.
993 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(0);
994 time += base::TimeDelta::FromMilliseconds(100);
995 Animate(time);
996
997 VERIFY_AND_RESET_MOCKS();
998
999 // The last call should stop scrolling.
1000 EXPECT_CALL(mock_input_handler_,
1001 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
1002 .WillOnce(testing::Return(cc::EventListenerProperties::kNone));
1003
1004 // When scroll latching is enabled, ScrollBegin shouldn't get called for
1005 // every tick.
1006 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1007 .Times(0);
1008 EXPECT_CALL(
1009 mock_input_handler_,
1010 ScrollBy(testing::Property(&cc::ScrollState::delta_x, testing::Lt(0))))
1011 .WillOnce(testing::Return(scroll_result_did_not_scroll_));
1012 // When scroll latching is enabled, ScrollEnd gets called when the last
1013 // ScrollBy did not scroll.
1014 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_));
1015 time += base::TimeDelta::FromMilliseconds(100);
1016 Animate(time);
1017
1018 VERIFY_AND_RESET_MOCKS();
1019
1020 // No more ticks.
1021 EXPECT_CALL(mock_input_handler_,
bokan 2017/01/10 18:53:59 I don't think you need this. All we do form here i
sahel 2017/01/10 21:10:06 When latching is enabled, ScrollEnd is called in F
bokan 2017/01/10 21:25:06 But you don't call Animate after it...
sahel 2017/01/12 18:53:44 I didn't know the behavior of VERIFY_AND_RESET_MOC
1022 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
1023 .Times(0);
1024 }
1025
921 TEST_P(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) { 1026 TEST_P(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) {
922 // We should send all events to the widget for this gesture. 1027 // We should send all events to the widget for this gesture.
923 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; 1028 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
924 VERIFY_AND_RESET_MOCKS(); 1029 VERIFY_AND_RESET_MOCKS();
925 1030
926 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1031 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
927 .WillOnce(testing::Return(kMainThreadScrollState)); 1032 .WillOnce(testing::Return(kMainThreadScrollState));
928 1033
929 gesture_.setType(WebInputEvent::GestureFlingStart); 1034 gesture_.setType(WebInputEvent::GestureFlingStart);
930 gesture_.sourceDevice = blink::WebGestureDeviceTouchpad; 1035 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); 3237 EXPECT_EQ(WebInputEvent::GesturePinchEnd, event_queue()[6]->event().type);
3133 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 3238 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
3134 } 3239 }
3135 3240
3136 INSTANTIATE_TEST_CASE_P(AnimateInput, 3241 INSTANTIATE_TEST_CASE_P(AnimateInput,
3137 InputHandlerProxyTest, 3242 InputHandlerProxyTest,
3138 testing::ValuesIn(test_types)); 3243 testing::ValuesIn(test_types));
3139 3244
3140 } // namespace test 3245 } // namespace test
3141 } // namespace ui 3246 } // namespace ui
OLDNEW
« ui/events/blink/input_handler_proxy.cc ('K') | « 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