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

Side by Side Diff: content/renderer/input/input_handler_proxy_unittest.cc

Issue 136173004: Early terminate flings when scrolling impossible (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 8 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 "content/renderer/input/input_handler_proxy.h" 5 #include "content/renderer/input/input_handler_proxy.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "cc/base/swap_promise_monitor.h" 9 #include "cc/base/swap_promise_monitor.h"
10 #include "content/common/input/did_overscroll_params.h"
10 #include "content/renderer/input/input_handler_proxy_client.h" 11 #include "content/renderer/input/input_handler_proxy_client.h"
11 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/WebKit/public/platform/WebFloatPoint.h" 14 #include "third_party/WebKit/public/platform/WebFloatPoint.h"
14 #include "third_party/WebKit/public/platform/WebFloatSize.h" 15 #include "third_party/WebKit/public/platform/WebFloatSize.h"
15 #include "third_party/WebKit/public/platform/WebGestureCurve.h" 16 #include "third_party/WebKit/public/platform/WebGestureCurve.h"
16 #include "third_party/WebKit/public/platform/WebPoint.h" 17 #include "third_party/WebKit/public/platform/WebPoint.h"
17 #include "third_party/WebKit/public/web/WebInputEvent.h" 18 #include "third_party/WebKit/public/web/WebInputEvent.h"
18 #include "ui/events/latency_info.h" 19 #include "ui/events/latency_info.h"
19 20
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 80
80 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE {} 81 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE {}
81 82
82 DISALLOW_COPY_AND_ASSIGN(MockInputHandler); 83 DISALLOW_COPY_AND_ASSIGN(MockInputHandler);
83 }; 84 };
84 85
85 // A simple WebGestureCurve implementation that flings at a constant velocity 86 // A simple WebGestureCurve implementation that flings at a constant velocity
86 // indefinitely. 87 // indefinitely.
87 class FakeWebGestureCurve : public blink::WebGestureCurve { 88 class FakeWebGestureCurve : public blink::WebGestureCurve {
88 public: 89 public:
89 FakeWebGestureCurve(const blink::WebFloatPoint& velocity, 90 FakeWebGestureCurve(const blink::WebFloatSize& velocity,
90 const blink::WebSize& cumulative_scroll) 91 const blink::WebFloatSize& cumulative_scroll)
91 : velocity_(velocity), cumulative_scroll_(cumulative_scroll) {} 92 : velocity_(velocity), cumulative_scroll_(cumulative_scroll) {}
92 93
93 virtual ~FakeWebGestureCurve() {} 94 virtual ~FakeWebGestureCurve() {}
94 95
95 // Returns false if curve has finished and can no longer be applied. 96 // Returns false if curve has finished and can no longer be applied.
96 virtual bool apply(double time, blink::WebGestureCurveTarget* target) { 97 virtual bool apply(double time, blink::WebGestureCurveTarget* target) {
97 blink::WebSize displacement(velocity_.x * time, velocity_.y * time); 98 blink::WebFloatSize displacement(velocity_.width * time,
99 velocity_.height * time);
98 blink::WebFloatSize increment( 100 blink::WebFloatSize increment(
99 displacement.width - cumulative_scroll_.width, 101 displacement.width - cumulative_scroll_.width,
100 displacement.height - cumulative_scroll_.height); 102 displacement.height - cumulative_scroll_.height);
101 cumulative_scroll_ = displacement; 103 cumulative_scroll_ = displacement;
102 // scrollBy() could delete this curve if the animation is over, so don't 104 // scrollBy() could delete this curve if the animation is over, so don't
103 // touch any member variables after making that call. 105 // touch any member variables after making that call.
104 target->scrollBy(increment); 106 target->scrollBy(increment, velocity_);
105 return true; 107 return true;
106 } 108 }
107 109
108 private: 110 private:
109 blink::WebFloatPoint velocity_; 111 blink::WebFloatSize velocity_;
110 blink::WebSize cumulative_scroll_; 112 blink::WebFloatSize cumulative_scroll_;
111 113
112 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve); 114 DISALLOW_COPY_AND_ASSIGN(FakeWebGestureCurve);
113 }; 115 };
114 116
115 class MockInputHandlerProxyClient 117 class MockInputHandlerProxyClient
116 : public content::InputHandlerProxyClient { 118 : public content::InputHandlerProxyClient {
117 public: 119 public:
118 MockInputHandlerProxyClient() {} 120 MockInputHandlerProxyClient() {}
119 virtual ~MockInputHandlerProxyClient() {} 121 virtual ~MockInputHandlerProxyClient() {}
120 122
121 virtual void WillShutdown() OVERRIDE {} 123 virtual void WillShutdown() OVERRIDE {}
122 124
123 MOCK_METHOD1(TransferActiveWheelFlingAnimation, 125 MOCK_METHOD1(TransferActiveWheelFlingAnimation,
124 void(const WebActiveWheelFlingParameters&)); 126 void(const WebActiveWheelFlingParameters&));
125 127
126 virtual blink::WebGestureCurve* CreateFlingAnimationCurve( 128 virtual blink::WebGestureCurve* CreateFlingAnimationCurve(
127 int deviceSource, 129 int deviceSource,
128 const WebFloatPoint& velocity, 130 const WebFloatPoint& velocity,
129 const WebSize& cumulative_scroll) OVERRIDE { 131 const WebSize& cumulative_scroll) OVERRIDE {
130 return new FakeWebGestureCurve(velocity, cumulative_scroll); 132 return new FakeWebGestureCurve(
133 blink::WebFloatSize(velocity.x, velocity.y),
134 blink::WebFloatSize(cumulative_scroll.width, cumulative_scroll.height));
131 } 135 }
132 136
133 virtual void DidOverscroll(const cc::DidOverscrollParams& params) OVERRIDE {} 137 MOCK_METHOD1(DidOverscroll, void(const DidOverscrollParams&));
134 virtual void DidStopFlinging() OVERRIDE {} 138 virtual void DidStopFlinging() OVERRIDE {}
135 139
136 private: 140 private:
137 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient); 141 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient);
138 }; 142 };
139 143
140 WebTouchPoint CreateWebTouchPoint(WebTouchPoint::State state, float x, 144 WebTouchPoint CreateWebTouchPoint(WebTouchPoint::State state, float x,
141 float y) { 145 float y) {
142 WebTouchPoint point; 146 WebTouchPoint point;
143 point.state = state; 147 point.state = state;
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after
1078 EXPECT_CALL(mock_input_handler_, 1082 EXPECT_CALL(mock_input_handler_,
1079 ScrollBy(testing::_, 1083 ScrollBy(testing::_,
1080 testing::Property(&gfx::Vector2dF::y, testing::Lt(0)))) 1084 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1081 .WillOnce(testing::Return(true)); 1085 .WillOnce(testing::Return(true));
1082 EXPECT_CALL(mock_input_handler_, ScrollEnd()); 1086 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1083 time += base::TimeDelta::FromMilliseconds(100); 1087 time += base::TimeDelta::FromMilliseconds(100);
1084 input_handler_->Animate(time); 1088 input_handler_->Animate(time);
1085 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 1089 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1086 1090
1087 // Simulate hitting the bottom content edge. 1091 // Simulate hitting the bottom content edge.
1088 cc::DidOverscrollParams overscroll_params; 1092 gfx::Vector2dF accumulated_overscroll(0, 100);
1089 overscroll_params.accumulated_overscroll = gfx::Vector2dF(0, 100); 1093 gfx::Vector2dF latest_overscroll_delta(0, 10);
1090 overscroll_params.current_fling_velocity = gfx::Vector2dF(0, 10); 1094 EXPECT_CALL(mock_client_,
1091 input_handler_->DidOverscroll(overscroll_params); 1095 DidOverscroll(testing::AllOf(
1096 testing::Field(&DidOverscrollParams::accumulated_overscroll,
1097 testing::Eq(accumulated_overscroll)),
1098 testing::Field(&DidOverscrollParams::latest_overscroll_delta,
1099 testing::Eq(latest_overscroll_delta)),
1100 testing::Field(
1101 &DidOverscrollParams::current_fling_velocity,
1102 testing::Property(&gfx::Vector2dF::y, testing::Gt(0))))));
1103 input_handler_->DidOverscroll(accumulated_overscroll,
1104 latest_overscroll_delta);
1092 1105
1093 // The next call to animate will no longer scroll vertically. 1106 // The next call to animate will no longer scroll vertically.
1094 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); 1107 EXPECT_CALL(mock_input_handler_, ScheduleAnimation());
1095 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) 1108 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_))
1096 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); 1109 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted));
1097 EXPECT_CALL(mock_input_handler_, 1110 EXPECT_CALL(mock_input_handler_,
1098 ScrollBy(testing::_, 1111 ScrollBy(testing::_,
1099 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) 1112 testing::Property(&gfx::Vector2dF::y, testing::Eq(0))))
1100 .WillOnce(testing::Return(true)); 1113 .WillOnce(testing::Return(true));
1101 EXPECT_CALL(mock_input_handler_, ScrollEnd()); 1114 EXPECT_CALL(mock_input_handler_, ScrollEnd());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1138 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); 1151 EXPECT_CALL(mock_input_handler_, ScheduleAnimation());
1139 EXPECT_CALL(mock_input_handler_, 1152 EXPECT_CALL(mock_input_handler_,
1140 ScrollBy(testing::_, 1153 ScrollBy(testing::_,
1141 testing::Property(&gfx::Vector2dF::y, testing::Lt(0)))) 1154 testing::Property(&gfx::Vector2dF::y, testing::Lt(0))))
1142 .WillOnce(testing::Return(true)); 1155 .WillOnce(testing::Return(true));
1143 time += base::TimeDelta::FromMilliseconds(10); 1156 time += base::TimeDelta::FromMilliseconds(10);
1144 input_handler_->Animate(time); 1157 input_handler_->Animate(time);
1145 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 1158 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1146 1159
1147 // Simulate hitting the bottom content edge. 1160 // Simulate hitting the bottom content edge.
1148 cc::DidOverscrollParams overscroll_params; 1161 gfx::Vector2dF accumulated_overscroll(0, 100);
1149 overscroll_params.accumulated_overscroll = gfx::Vector2dF(0, 100); 1162 gfx::Vector2dF latest_overscroll_delta(0, 100);
1150 input_handler_->DidOverscroll(overscroll_params); 1163 EXPECT_CALL(mock_client_,
1164 DidOverscroll(testing::AllOf(
1165 testing::Field(&DidOverscrollParams::accumulated_overscroll,
1166 testing::Eq(accumulated_overscroll)),
1167 testing::Field(&DidOverscrollParams::latest_overscroll_delta,
1168 testing::Eq(latest_overscroll_delta)),
1169 testing::Field(
1170 &DidOverscrollParams::current_fling_velocity,
1171 testing::Property(&gfx::Vector2dF::y, testing::Gt(0))))));
1172 input_handler_->DidOverscroll(accumulated_overscroll,
1173 latest_overscroll_delta);
1151 1174
1152 // The next call to animate will no longer scroll vertically. 1175 // The next call to animate will no longer scroll vertically.
1153 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); 1176 EXPECT_CALL(mock_input_handler_, ScheduleAnimation());
1154 EXPECT_CALL(mock_input_handler_, 1177 EXPECT_CALL(mock_input_handler_,
1155 ScrollBy(testing::_, 1178 ScrollBy(testing::_,
1156 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) 1179 testing::Property(&gfx::Vector2dF::y, testing::Eq(0))))
1157 .WillOnce(testing::Return(true)); 1180 .WillOnce(testing::Return(true));
1158 time += base::TimeDelta::FromMilliseconds(10); 1181 time += base::TimeDelta::FromMilliseconds(10);
1159 input_handler_->Animate(time); 1182 input_handler_->Animate(time);
1160 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 1183 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1161 1184
1162 // Simulate hitting the right content edge. 1185 // Simulate hitting the right content edge.
1163 overscroll_params.accumulated_overscroll = gfx::Vector2dF(100, 100); 1186 accumulated_overscroll = gfx::Vector2dF(100, 100);
1164 input_handler_->DidOverscroll(overscroll_params); 1187 latest_overscroll_delta = gfx::Vector2dF(100, 0);
1165 1188 EXPECT_CALL(mock_client_,
1189 DidOverscroll(testing::AllOf(
1190 testing::Field(&DidOverscrollParams::accumulated_overscroll,
1191 testing::Eq(accumulated_overscroll)),
1192 testing::Field(&DidOverscrollParams::latest_overscroll_delta,
1193 testing::Eq(latest_overscroll_delta)),
1194 testing::Field(
1195 &DidOverscrollParams::current_fling_velocity,
1196 testing::Property(&gfx::Vector2dF::x, testing::Gt(0))))));
1197 input_handler_->DidOverscroll(accumulated_overscroll,
1198 latest_overscroll_delta);
1166 // The next call to animate will no longer scroll horizontally or vertically, 1199 // The next call to animate will no longer scroll horizontally or vertically,
1167 // and the fling should be cancelled. 1200 // and the fling should be cancelled.
1168 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()).Times(0); 1201 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()).Times(0);
1169 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0); 1202 EXPECT_CALL(mock_input_handler_, ScrollBy(testing::_, testing::_)).Times(0);
1170 EXPECT_CALL(mock_input_handler_, ScrollEnd()); 1203 EXPECT_CALL(mock_input_handler_, ScrollEnd());
1171 time += base::TimeDelta::FromMilliseconds(10); 1204 time += base::TimeDelta::FromMilliseconds(10);
1172 input_handler_->Animate(time); 1205 input_handler_->Animate(time);
1173 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); 1206 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_);
1174 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); 1207 EXPECT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing());
1175 } 1208 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 1254
1222 touch.touchesLength = 3; 1255 touch.touchesLength = 3;
1223 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0); 1256 touch.touches[0] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 0, 0);
1224 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10); 1257 touch.touches[1] = CreateWebTouchPoint(WebTouchPoint::StatePressed, 10, 10);
1225 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10); 1258 touch.touches[2] = CreateWebTouchPoint(WebTouchPoint::StatePressed, -10, 10);
1226 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); 1259 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch));
1227 } 1260 }
1228 1261
1229 } // namespace 1262 } // namespace
1230 } // namespace content 1263 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698