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

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

Issue 2362863003: Handle touchpad flings with passive event listeners on compositor thread. (Closed)
Patch Set: Created 4 years, 3 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_client.h ('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/macros.h" 9 #include "base/macros.h"
10 #include "base/test/histogram_tester.h" 10 #include "base/test/histogram_tester.h"
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 CHILD_SCROLL_SYNCHRONOUS_HANDLER, 48 CHILD_SCROLL_SYNCHRONOUS_HANDLER,
49 }; 49 };
50 static const InputHandlerProxyTestType test_types[] = { 50 static const InputHandlerProxyTestType test_types[] = {
51 ROOT_SCROLL_NORMAL_HANDLER, ROOT_SCROLL_SYNCHRONOUS_HANDLER, 51 ROOT_SCROLL_NORMAL_HANDLER, ROOT_SCROLL_SYNCHRONOUS_HANDLER,
52 CHILD_SCROLL_NORMAL_HANDLER, CHILD_SCROLL_SYNCHRONOUS_HANDLER}; 52 CHILD_SCROLL_NORMAL_HANDLER, CHILD_SCROLL_SYNCHRONOUS_HANDLER};
53 53
54 double InSecondsF(const base::TimeTicks& time) { 54 double InSecondsF(const base::TimeTicks& time) {
55 return (time - base::TimeTicks()).InSecondsF(); 55 return (time - base::TimeTicks()).InSecondsF();
56 } 56 }
57 57
58 bool WheelEventsMatch(const WebInputEvent& lhs, const WebInputEvent& rhs) {
59 if (lhs.size == rhs.size && lhs.type == rhs.type &&
60 lhs.type == WebInputEvent::MouseWheel) {
61 WebMouseWheelEvent rhs_timestamped =
62 static_cast<const WebMouseWheelEvent&>(rhs);
63 rhs_timestamped.timeStampSeconds = lhs.timeStampSeconds;
64 return memcmp(&rhs_timestamped, &lhs, rhs.size) == 0;
65 }
66 return false;
67 }
68
69 MATCHER_P(WheelEventsMatch, expected, "") {
70 return WheelEventsMatch(arg, expected);
71 }
72
58 WebGestureEvent CreateFling(base::TimeTicks timestamp, 73 WebGestureEvent CreateFling(base::TimeTicks timestamp,
59 WebGestureDevice source_device, 74 WebGestureDevice source_device,
60 WebFloatPoint velocity, 75 WebFloatPoint velocity,
61 WebPoint point, 76 WebPoint point,
62 WebPoint global_point, 77 WebPoint global_point,
63 int modifiers) { 78 int modifiers) {
64 WebGestureEvent fling; 79 WebGestureEvent fling;
65 fling.type = WebInputEvent::GestureFlingStart; 80 fling.type = WebInputEvent::GestureFlingStart;
66 fling.sourceDevice = source_device; 81 fling.sourceDevice = source_device;
67 fling.timeStampSeconds = (timestamp - base::TimeTicks()).InSecondsF(); 82 fling.timeStampSeconds = (timestamp - base::TimeTicks()).InSecondsF();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 : public InputHandlerProxyClient { 222 : public InputHandlerProxyClient {
208 public: 223 public:
209 MockInputHandlerProxyClient() {} 224 MockInputHandlerProxyClient() {}
210 ~MockInputHandlerProxyClient() override {} 225 ~MockInputHandlerProxyClient() override {}
211 226
212 void WillShutdown() override {} 227 void WillShutdown() override {}
213 228
214 MOCK_METHOD1(TransferActiveWheelFlingAnimation, 229 MOCK_METHOD1(TransferActiveWheelFlingAnimation,
215 void(const WebActiveWheelFlingParameters&)); 230 void(const WebActiveWheelFlingParameters&));
216 231
232 MOCK_METHOD1(DispatchNonBlockingEventToMainThread_,
233 void(const WebInputEvent&));
234
235 void DispatchNonBlockingEventToMainThread(
236 ui::ScopedWebInputEvent event,
237 const ui::LatencyInfo& latency_info) override {
238 CHECK(event.get());
239 DispatchNonBlockingEventToMainThread_(*event.get());
240 }
241
217 blink::WebGestureCurve* CreateFlingAnimationCurve( 242 blink::WebGestureCurve* CreateFlingAnimationCurve(
218 WebGestureDevice deviceSource, 243 WebGestureDevice deviceSource,
219 const WebFloatPoint& velocity, 244 const WebFloatPoint& velocity,
220 const WebSize& cumulative_scroll) override { 245 const WebSize& cumulative_scroll) override {
221 return new FakeWebGestureCurve( 246 return new FakeWebGestureCurve(
222 blink::WebFloatSize(velocity.x, velocity.y), 247 blink::WebFloatSize(velocity.x, velocity.y),
223 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height)); 248 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height));
224 } 249 }
225 250
226 MOCK_METHOD4(DidOverscroll, 251 MOCK_METHOD4(DidOverscroll,
(...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after
992 // lead to the scroll (either wheel or gesture scroll), so there should be no 1017 // lead to the scroll (either wheel or gesture scroll), so there should be no
993 // visible hitch. 1018 // visible hitch.
994 EXPECT_SET_NEEDS_ANIMATE_INPUT(1); 1019 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
995 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1020 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
996 .Times(0); 1021 .Times(0);
997 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); 1022 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
998 Animate(time); 1023 Animate(time);
999 1024
1000 VERIFY_AND_RESET_MOCKS(); 1025 VERIFY_AND_RESET_MOCKS();
1001 1026
1002 // The second call should punt the fling to the main thread 1027 // The second call should punt activate the fling and call the method
1003 // because of a passive event listener. 1028 // dispatching the events for the passive event listeners.
1004 EXPECT_SET_NEEDS_ANIMATE_INPUT(0); 1029 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
1005 EXPECT_CALL(mock_input_handler_, 1030 EXPECT_CALL(mock_input_handler_,
1006 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel)) 1031 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
1007 .WillOnce(testing::Return(cc::EventListenerProperties::kPassive)); 1032 .WillOnce(testing::Return(cc::EventListenerProperties::kPassive));
1008 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1033 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1009 .Times(0); 1034 .WillOnce(testing::Return(kImplThreadScrollState));
1010 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_)).Times(0);
1011 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(0);
1012 // Expected wheel fling animation parameters:
1013 // *) fling_delta and fling_point should match the original GestureFlingStart
1014 // event
1015 // *) startTime should be 10 to match the time parameter of the first
1016 // Animate() call after the GestureFlingStart
1017 EXPECT_CALL( 1035 EXPECT_CALL(
1018 mock_client_, 1036 mock_input_handler_,
1019 TransferActiveWheelFlingAnimation(testing::AllOf( 1037 ScrollBy(testing::Property(&cc::ScrollState::delta_x, testing::Lt(0))))
1020 testing::Field(&WebActiveWheelFlingParameters::delta, 1038 .WillOnce(testing::Return(scroll_result_did_scroll_));
1021 testing::Eq(fling_delta)), 1039 WebMouseWheelEvent expected_wheel;
1022 testing::Field(&WebActiveWheelFlingParameters::point, 1040 expected_wheel.type = WebInputEvent::MouseWheel;
1023 testing::Eq(fling_point)), 1041 expected_wheel.modifiers = modifiers;
1024 testing::Field(&WebActiveWheelFlingParameters::globalPoint, 1042 expected_wheel.x = fling_point.x;
1025 testing::Eq(fling_global_point)), 1043 expected_wheel.y = fling_point.y;
1026 testing::Field(&WebActiveWheelFlingParameters::modifiers, 1044 expected_wheel.globalX = fling_global_point.x;
1027 testing::Eq(modifiers)), 1045 expected_wheel.globalY = fling_global_point.y;
1028 testing::Field(&WebActiveWheelFlingParameters::startTime, 1046 expected_wheel.deltaX = fling_delta.x / 10;
1029 testing::Eq(10)), 1047 expected_wheel.hasPreciseScrollingDeltas = true;
1030 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll, 1048
1031 testing::_)))); 1049 EXPECT_CALL(mock_client_, DispatchNonBlockingEventToMainThread_(
1050 WheelEventsMatch(expected_wheel)))
1051 .Times(1);
1052 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(1);
1053
1032 time += base::TimeDelta::FromMilliseconds(100); 1054 time += base::TimeDelta::FromMilliseconds(100);
1033 Animate(time); 1055 Animate(time);
1034 1056
1035 VERIFY_AND_RESET_MOCKS(); 1057 VERIFY_AND_RESET_MOCKS();
1036 1058
1037 // Since we've aborted the fling, the next animation should be a no-op and 1059 // Ensure we can cancel the gesture.
1038 // should not result in another 1060 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1039 // frame being requested.
1040 EXPECT_SET_NEEDS_ANIMATE_INPUT(0);
1041 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1042 .Times(0);
1043 time += base::TimeDelta::FromMilliseconds(100);
1044 Animate(time);
1045
1046 // Since we've transferred the fling to the main thread, we need to pass the
1047 // next GestureFlingCancel to the main
1048 // thread as well.
1049 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
1050 gesture_.type = WebInputEvent::GestureFlingCancel; 1061 gesture_.type = WebInputEvent::GestureFlingCancel;
1051 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); 1062 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1052 1063
1053 VERIFY_AND_RESET_MOCKS(); 1064 VERIFY_AND_RESET_MOCKS();
1054 } 1065 }
1055 1066
1056 TEST_P(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) { 1067 TEST_P(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) {
1057 // We shouldn't send any events to the widget for this gesture. 1068 // We shouldn't send any events to the widget for this gesture.
1058 expected_disposition_ = InputHandlerProxy::DID_HANDLE; 1069 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1059 VERIFY_AND_RESET_MOCKS(); 1070 VERIFY_AND_RESET_MOCKS();
(...skipping 1727 matching lines...) Expand 10 before | Expand all | Expand 10 after
2787 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1), 2798 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1),
2788 base::Bucket(5, 1), base::Bucket(14, 1))); 2799 base::Bucket(5, 1), base::Bucket(14, 1)));
2789 } 2800 }
2790 2801
2791 2802
2792 INSTANTIATE_TEST_CASE_P(AnimateInput, 2803 INSTANTIATE_TEST_CASE_P(AnimateInput,
2793 InputHandlerProxyTest, 2804 InputHandlerProxyTest,
2794 testing::ValuesIn(test_types)); 2805 testing::ValuesIn(test_types));
2795 } // namespace test 2806 } // namespace test
2796 } // namespace ui 2807 } // namespace ui
OLDNEW
« no previous file with comments | « ui/events/blink/input_handler_proxy_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698