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

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

Issue 2341873002: Handle touchpad flings with passive event listeners on compositor thread. (Closed)
Patch Set: Add dcheck for blimp 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 : public InputHandlerProxyClient { 223 : public InputHandlerProxyClient {
209 public: 224 public:
210 MockInputHandlerProxyClient() {} 225 MockInputHandlerProxyClient() {}
211 ~MockInputHandlerProxyClient() override {} 226 ~MockInputHandlerProxyClient() override {}
212 227
213 void WillShutdown() override {} 228 void WillShutdown() override {}
214 229
215 MOCK_METHOD1(TransferActiveWheelFlingAnimation, 230 MOCK_METHOD1(TransferActiveWheelFlingAnimation,
216 void(const WebActiveWheelFlingParameters&)); 231 void(const WebActiveWheelFlingParameters&));
217 232
233 MOCK_METHOD1(DispatchNonBlockingEventToMainThread_,
234 void(const WebInputEvent&));
235
236 void DispatchNonBlockingEventToMainThread(
237 ui::ScopedWebInputEvent event,
238 const ui::LatencyInfo& latency_info) override {
239 CHECK(event.get());
240 DispatchNonBlockingEventToMainThread_(*event.get());
241 }
242
218 blink::WebGestureCurve* CreateFlingAnimationCurve( 243 blink::WebGestureCurve* CreateFlingAnimationCurve(
219 WebGestureDevice deviceSource, 244 WebGestureDevice deviceSource,
220 const WebFloatPoint& velocity, 245 const WebFloatPoint& velocity,
221 const WebSize& cumulative_scroll) override { 246 const WebSize& cumulative_scroll) override {
222 return new FakeWebGestureCurve( 247 return new FakeWebGestureCurve(
223 blink::WebFloatSize(velocity.x, velocity.y), 248 blink::WebFloatSize(velocity.x, velocity.y),
224 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height)); 249 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height));
225 } 250 }
226 251
227 MOCK_METHOD4(DidOverscroll, 252 MOCK_METHOD4(DidOverscroll,
(...skipping 766 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 // lead to the scroll (either wheel or gesture scroll), so there should be no 1019 // lead to the scroll (either wheel or gesture scroll), so there should be no
995 // visible hitch. 1020 // visible hitch.
996 EXPECT_SET_NEEDS_ANIMATE_INPUT(1); 1021 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
997 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1022 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
998 .Times(0); 1023 .Times(0);
999 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); 1024 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10);
1000 Animate(time); 1025 Animate(time);
1001 1026
1002 VERIFY_AND_RESET_MOCKS(); 1027 VERIFY_AND_RESET_MOCKS();
1003 1028
1004 // The second call should punt the fling to the main thread 1029 // The second call should punt activate the fling and call the method
1005 // because of a passive event listener. 1030 // dispatching the events for the passive event listeners.
1006 EXPECT_SET_NEEDS_ANIMATE_INPUT(0); 1031 EXPECT_SET_NEEDS_ANIMATE_INPUT(1);
1007 EXPECT_CALL(mock_input_handler_, 1032 EXPECT_CALL(mock_input_handler_,
1008 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel)) 1033 GetEventListenerProperties(cc::EventListenerClass::kMouseWheel))
1009 .WillOnce(testing::Return(cc::EventListenerProperties::kPassive)); 1034 .WillOnce(testing::Return(cc::EventListenerProperties::kPassive));
1010 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1035 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1011 .Times(0); 1036 .WillOnce(testing::Return(kImplThreadScrollState));
1012 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_)).Times(0);
1013 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(0);
1014 // Expected wheel fling animation parameters:
1015 // *) fling_delta and fling_point should match the original GestureFlingStart
1016 // event
1017 // *) startTime should be 10 to match the time parameter of the first
1018 // Animate() call after the GestureFlingStart
1019 EXPECT_CALL( 1037 EXPECT_CALL(
1020 mock_client_, 1038 mock_input_handler_,
1021 TransferActiveWheelFlingAnimation(testing::AllOf( 1039 ScrollBy(testing::Property(&cc::ScrollState::delta_x, testing::Lt(0))))
1022 testing::Field(&WebActiveWheelFlingParameters::delta, 1040 .WillOnce(testing::Return(scroll_result_did_scroll_));
1023 testing::Eq(fling_delta)), 1041 WebMouseWheelEvent expected_wheel;
1024 testing::Field(&WebActiveWheelFlingParameters::point, 1042 expected_wheel.type = WebInputEvent::MouseWheel;
1025 testing::Eq(fling_point)), 1043 expected_wheel.modifiers = modifiers;
1026 testing::Field(&WebActiveWheelFlingParameters::globalPoint, 1044 expected_wheel.x = fling_point.x;
1027 testing::Eq(fling_global_point)), 1045 expected_wheel.y = fling_point.y;
1028 testing::Field(&WebActiveWheelFlingParameters::modifiers, 1046 expected_wheel.globalX = fling_global_point.x;
1029 testing::Eq(modifiers)), 1047 expected_wheel.globalY = fling_global_point.y;
1030 testing::Field(&WebActiveWheelFlingParameters::startTime, 1048 expected_wheel.deltaX = fling_delta.x / 10;
1031 testing::Eq(10)), 1049 expected_wheel.hasPreciseScrollingDeltas = true;
1032 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll, 1050
1033 testing::_)))); 1051 EXPECT_CALL(mock_client_, DispatchNonBlockingEventToMainThread_(
1052 WheelEventsMatch(expected_wheel)))
1053 .Times(1);
1054 EXPECT_CALL(mock_input_handler_, ScrollEnd(testing::_)).Times(1);
1055
1034 time += base::TimeDelta::FromMilliseconds(100); 1056 time += base::TimeDelta::FromMilliseconds(100);
1035 Animate(time); 1057 Animate(time);
1036 1058
1037 VERIFY_AND_RESET_MOCKS(); 1059 VERIFY_AND_RESET_MOCKS();
1038 1060
1039 // Since we've aborted the fling, the next animation should be a no-op and 1061 // Ensure we can cancel the gesture.
1040 // should not result in another 1062 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1041 // frame being requested.
1042 EXPECT_SET_NEEDS_ANIMATE_INPUT(0);
1043 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1044 .Times(0);
1045 time += base::TimeDelta::FromMilliseconds(100);
1046 Animate(time);
1047
1048 // Since we've transferred the fling to the main thread, we need to pass the
1049 // next GestureFlingCancel to the main
1050 // thread as well.
1051 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE;
1052 gesture_.type = WebInputEvent::GestureFlingCancel; 1063 gesture_.type = WebInputEvent::GestureFlingCancel;
1053 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); 1064 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_));
1054 1065
1055 VERIFY_AND_RESET_MOCKS(); 1066 VERIFY_AND_RESET_MOCKS();
1056 } 1067 }
1057 1068
1058 TEST_P(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) { 1069 TEST_P(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) {
1059 // We shouldn't send any events to the widget for this gesture. 1070 // We shouldn't send any events to the widget for this gesture.
1060 expected_disposition_ = InputHandlerProxy::DID_HANDLE; 1071 expected_disposition_ = InputHandlerProxy::DID_HANDLE;
1061 VERIFY_AND_RESET_MOCKS(); 1072 VERIFY_AND_RESET_MOCKS();
(...skipping 1741 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1), 2814 testing::ElementsAre(base::Bucket(1, 1), base::Bucket(3, 1),
2804 base::Bucket(5, 1), base::Bucket(14, 1))); 2815 base::Bucket(5, 1), base::Bucket(14, 1)));
2805 } 2816 }
2806 2817
2807 2818
2808 INSTANTIATE_TEST_CASE_P(AnimateInput, 2819 INSTANTIATE_TEST_CASE_P(AnimateInput,
2809 InputHandlerProxyTest, 2820 InputHandlerProxyTest,
2810 testing::ValuesIn(test_types)); 2821 testing::ValuesIn(test_types));
2811 } // namespace test 2822 } // namespace test
2812 } // namespace ui 2823 } // 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