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

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

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

Powered by Google App Engine
This is Rietveld 408576698