| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/gpu/input_handler_proxy.h" | 5 #include "content/renderer/gpu/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 "content/renderer/gpu/input_handler_proxy_client.h" | 9 #include "content/renderer/gpu/input_handler_proxy_client.h" |
| 10 #include "testing/gmock/include/gmock/gmock.h" | 10 #include "testing/gmock/include/gmock/gmock.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "third_party/WebKit/public/platform/WebFloatPoint.h" | 12 #include "third_party/WebKit/public/platform/WebFloatPoint.h" |
| 13 #include "third_party/WebKit/public/platform/WebFloatSize.h" | 13 #include "third_party/WebKit/public/platform/WebFloatSize.h" |
| 14 #include "third_party/WebKit/public/platform/WebGestureCurve.h" | 14 #include "third_party/WebKit/public/platform/WebGestureCurve.h" |
| 15 #include "third_party/WebKit/public/platform/WebPoint.h" | 15 #include "third_party/WebKit/public/platform/WebPoint.h" |
| 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| 17 | 17 |
| 18 using WebKit::WebActiveWheelFlingParameters; | 18 using WebKit::WebActiveWheelFlingParameters; |
| 19 using WebKit::WebFloatPoint; | 19 using WebKit::WebFloatPoint; |
| 20 using WebKit::WebFloatSize; | 20 using WebKit::WebFloatSize; |
| 21 using WebKit::WebGestureEvent; | 21 using WebKit::WebGestureEvent; |
| 22 using WebKit::WebInputEvent; | 22 using WebKit::WebInputEvent; |
| 23 using WebKit::WebMouseWheelEvent; | 23 using WebKit::WebMouseWheelEvent; |
| 24 using WebKit::WebPoint; | 24 using WebKit::WebPoint; |
| 25 using WebKit::WebSize; | 25 using WebKit::WebSize; |
| 26 | 26 |
| 27 namespace content { |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 class MockInputHandler : public cc::InputHandler { | 30 class MockInputHandler : public cc::InputHandler { |
| 30 public: | 31 public: |
| 31 MockInputHandler() {} | 32 MockInputHandler() {} |
| 32 virtual ~MockInputHandler() {} | 33 virtual ~MockInputHandler() {} |
| 33 | 34 |
| 34 MOCK_METHOD0(PinchGestureBegin, void()); | 35 MOCK_METHOD0(PinchGestureBegin, void()); |
| 35 MOCK_METHOD2(PinchGestureUpdate, | 36 MOCK_METHOD2(PinchGestureUpdate, |
| 36 void(float magnify_delta, gfx::Point anchor)); | 37 void(float magnify_delta, gfx::Point anchor)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 class MockInputHandlerProxyClient | 109 class MockInputHandlerProxyClient |
| 109 : public content::InputHandlerProxyClient { | 110 : public content::InputHandlerProxyClient { |
| 110 public: | 111 public: |
| 111 MockInputHandlerProxyClient() {} | 112 MockInputHandlerProxyClient() {} |
| 112 virtual ~MockInputHandlerProxyClient() {} | 113 virtual ~MockInputHandlerProxyClient() {} |
| 113 | 114 |
| 114 virtual void WillShutdown() OVERRIDE {} | 115 virtual void WillShutdown() OVERRIDE {} |
| 115 | 116 |
| 116 MOCK_METHOD0(DidHandleInputEvent, void()); | |
| 117 MOCK_METHOD1(DidNotHandleInputEvent, void(bool send_to_widget)); | |
| 118 | |
| 119 MOCK_METHOD1(TransferActiveWheelFlingAnimation, | 117 MOCK_METHOD1(TransferActiveWheelFlingAnimation, |
| 120 void(const WebActiveWheelFlingParameters&)); | 118 void(const WebActiveWheelFlingParameters&)); |
| 121 | 119 |
| 122 virtual WebKit::WebGestureCurve* CreateFlingAnimationCurve( | 120 virtual WebKit::WebGestureCurve* CreateFlingAnimationCurve( |
| 123 int deviceSource, | 121 int deviceSource, |
| 124 const WebFloatPoint& velocity, | 122 const WebFloatPoint& velocity, |
| 125 const WebSize& cumulative_scroll) OVERRIDE { | 123 const WebSize& cumulative_scroll) OVERRIDE { |
| 126 return new FakeWebGestureCurve(velocity, cumulative_scroll); | 124 return new FakeWebGestureCurve(velocity, cumulative_scroll); |
| 127 } | 125 } |
| 128 | 126 |
| 129 virtual void DidOverscroll(gfx::Vector2dF overscroll, | 127 virtual void DidOverscroll(gfx::Vector2dF overscroll, |
| 130 gfx::Vector2dF fling_velocity) {} | 128 gfx::Vector2dF fling_velocity) {} |
| 131 | 129 |
| 132 private: | 130 private: |
| 133 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient); | 131 DISALLOW_COPY_AND_ASSIGN(MockInputHandlerProxyClient); |
| 134 }; | 132 }; |
| 135 | 133 |
| 136 class InputHandlerProxyTest : public testing::Test { | 134 class InputHandlerProxyTest : public testing::Test { |
| 137 public: | 135 public: |
| 138 InputHandlerProxyTest() : expected_disposition_(DidHandle) { | 136 InputHandlerProxyTest() |
| 137 : expected_disposition_(InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE) { |
| 139 input_handler_.reset( | 138 input_handler_.reset( |
| 140 new content::InputHandlerProxy(&mock_input_handler_)); | 139 new content::InputHandlerProxy(&mock_input_handler_)); |
| 141 input_handler_->SetClient(&mock_client_); | 140 input_handler_->SetClient(&mock_client_); |
| 142 } | 141 } |
| 143 | 142 |
| 144 ~InputHandlerProxyTest() { | 143 ~InputHandlerProxyTest() { |
| 145 input_handler_.reset(); | 144 input_handler_.reset(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 // This is defined as a macro because when an expectation is not satisfied the | 147 // This is defined as a macro because when an expectation is not satisfied the |
| 149 // only output you get | 148 // only output you get |
| 150 // out of gmock is the line number that set the expectation. | 149 // out of gmock is the line number that set the expectation. |
| 151 #define VERIFY_AND_RESET_MOCKS() \ | 150 #define VERIFY_AND_RESET_MOCKS() \ |
| 152 do { \ | 151 do { \ |
| 153 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); \ | 152 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); \ |
| 154 testing::Mock::VerifyAndClearExpectations(&mock_client_); \ | 153 testing::Mock::VerifyAndClearExpectations(&mock_client_); \ |
| 155 switch (expected_disposition_) { \ | |
| 156 case DidHandle: \ | |
| 157 /* If we expect to handle events, we shouldn't get any */ \ | |
| 158 /* DidNotHandleInputEvent() calls with any parameter. */ \ | |
| 159 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(::testing::_)) \ | |
| 160 .Times(0); \ | |
| 161 EXPECT_CALL(mock_client_, DidHandleInputEvent()); \ | |
| 162 break; \ | |
| 163 case DidNotHandle: \ | |
| 164 /* If we aren't expecting to handle events, we shouldn't call */ \ | |
| 165 /* DidHandleInputEvent(). */ \ | |
| 166 EXPECT_CALL(mock_client_, DidHandleInputEvent()).Times(0); \ | |
| 167 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(false)).Times(0); \ | |
| 168 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(true)); \ | |
| 169 break; \ | |
| 170 case DropEvent: \ | |
| 171 /* If we're expecting to drop, we shouldn't get any didHandle..() */ \ | |
| 172 /* or DidNotHandleInputEvent(true) calls. */ \ | |
| 173 EXPECT_CALL(mock_client_, DidHandleInputEvent()).Times(0); \ | |
| 174 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(true)).Times(0); \ | |
| 175 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(false)); \ | |
| 176 break; \ | |
| 177 } \ | |
| 178 } while (false) | 154 } while (false) |
| 179 | 155 |
| 180 protected: | 156 protected: |
| 181 testing::StrictMock<MockInputHandler> mock_input_handler_; | 157 testing::StrictMock<MockInputHandler> mock_input_handler_; |
| 182 scoped_ptr<content::InputHandlerProxy> input_handler_; | 158 scoped_ptr<content::InputHandlerProxy> input_handler_; |
| 183 testing::StrictMock<MockInputHandlerProxyClient> mock_client_; | 159 testing::StrictMock<MockInputHandlerProxyClient> mock_client_; |
| 184 WebGestureEvent gesture_; | 160 WebGestureEvent gesture_; |
| 185 | 161 |
| 186 enum ExpectedDisposition { | 162 InputHandlerProxy::EventDisposition expected_disposition_; |
| 187 DidHandle, | |
| 188 DidNotHandle, | |
| 189 DropEvent | |
| 190 }; | |
| 191 ExpectedDisposition expected_disposition_; | |
| 192 }; | 163 }; |
| 193 | 164 |
| 194 TEST_F(InputHandlerProxyTest, MouseWheelByPageMainThread) { | 165 TEST_F(InputHandlerProxyTest, MouseWheelByPageMainThread) { |
| 166 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 195 WebMouseWheelEvent wheel; | 167 WebMouseWheelEvent wheel; |
| 196 wheel.type = WebInputEvent::MouseWheel; | 168 wheel.type = WebInputEvent::MouseWheel; |
| 197 wheel.scrollByPage = true; | 169 wheel.scrollByPage = true; |
| 198 | 170 |
| 199 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(true)).Times(1); | 171 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(wheel)); |
| 200 input_handler_->HandleInputEvent(wheel); | |
| 201 testing::Mock::VerifyAndClearExpectations(&mock_client_); | 172 testing::Mock::VerifyAndClearExpectations(&mock_client_); |
| 202 } | 173 } |
| 203 | 174 |
| 204 TEST_F(InputHandlerProxyTest, GestureScrollStarted) { | 175 TEST_F(InputHandlerProxyTest, GestureScrollStarted) { |
| 205 // We shouldn't send any events to the widget for this gesture. | 176 // We shouldn't send any events to the widget for this gesture. |
| 206 expected_disposition_ = DidHandle; | 177 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 207 VERIFY_AND_RESET_MOCKS(); | 178 VERIFY_AND_RESET_MOCKS(); |
| 208 | 179 |
| 209 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 180 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 210 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 181 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 211 | 182 |
| 212 gesture_.type = WebInputEvent::GestureScrollBegin; | 183 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 213 input_handler_->HandleInputEvent(gesture_); | 184 EXPECT_EQ(expected_disposition_,input_handler_->HandleInputEvent(gesture_)); |
| 214 | 185 |
| 215 // The event should not be marked as handled if scrolling is not possible. | 186 // The event should not be marked as handled if scrolling is not possible. |
| 216 expected_disposition_ = DropEvent; | 187 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DROP_EVENT; |
| 217 VERIFY_AND_RESET_MOCKS(); | 188 VERIFY_AND_RESET_MOCKS(); |
| 218 | 189 |
| 219 gesture_.type = WebInputEvent::GestureScrollUpdate; | 190 gesture_.type = WebInputEvent::GestureScrollUpdate; |
| 220 gesture_.data.scrollUpdate.deltaY = | 191 gesture_.data.scrollUpdate.deltaY = |
| 221 -40; // -Y means scroll down - i.e. in the +Y direction. | 192 -40; // -Y means scroll down - i.e. in the +Y direction. |
| 222 EXPECT_CALL(mock_input_handler_, | 193 EXPECT_CALL(mock_input_handler_, |
| 223 ScrollBy(testing::_, | 194 ScrollBy(testing::_, |
| 224 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))) | 195 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))) |
| 225 .WillOnce(testing::Return(false)); | 196 .WillOnce(testing::Return(false)); |
| 226 input_handler_->HandleInputEvent(gesture_); | 197 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 227 | 198 |
| 228 // Mark the event as handled if scroll happens. | 199 // Mark the event as handled if scroll happens. |
| 229 expected_disposition_ = DidHandle; | 200 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 230 VERIFY_AND_RESET_MOCKS(); | 201 VERIFY_AND_RESET_MOCKS(); |
| 231 | 202 |
| 232 gesture_.type = WebInputEvent::GestureScrollUpdate; | 203 gesture_.type = WebInputEvent::GestureScrollUpdate; |
| 233 gesture_.data.scrollUpdate.deltaY = | 204 gesture_.data.scrollUpdate.deltaY = |
| 234 -40; // -Y means scroll down - i.e. in the +Y direction. | 205 -40; // -Y means scroll down - i.e. in the +Y direction. |
| 235 EXPECT_CALL(mock_input_handler_, | 206 EXPECT_CALL(mock_input_handler_, |
| 236 ScrollBy(testing::_, | 207 ScrollBy(testing::_, |
| 237 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))) | 208 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))) |
| 238 .WillOnce(testing::Return(true)); | 209 .WillOnce(testing::Return(true)); |
| 239 input_handler_->HandleInputEvent(gesture_); | 210 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 240 | 211 |
| 241 VERIFY_AND_RESET_MOCKS(); | 212 VERIFY_AND_RESET_MOCKS(); |
| 242 | 213 |
| 243 gesture_.type = WebInputEvent::GestureScrollEnd; | 214 gesture_.type = WebInputEvent::GestureScrollEnd; |
| 244 gesture_.data.scrollUpdate.deltaY = 0; | 215 gesture_.data.scrollUpdate.deltaY = 0; |
| 245 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 216 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 246 input_handler_->HandleInputEvent(gesture_); | 217 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 247 } | 218 } |
| 248 | 219 |
| 249 TEST_F(InputHandlerProxyTest, GestureScrollOnMainThread) { | 220 TEST_F(InputHandlerProxyTest, GestureScrollOnMainThread) { |
| 250 // We should send all events to the widget for this gesture. | 221 // We should send all events to the widget for this gesture. |
| 251 expected_disposition_ = DidNotHandle; | 222 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 252 VERIFY_AND_RESET_MOCKS(); | 223 VERIFY_AND_RESET_MOCKS(); |
| 253 | 224 |
| 254 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_)) | 225 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_)) |
| 255 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); | 226 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); |
| 256 | 227 |
| 257 gesture_.type = WebInputEvent::GestureScrollBegin; | 228 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 258 input_handler_->HandleInputEvent(gesture_); | 229 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 259 | 230 |
| 260 VERIFY_AND_RESET_MOCKS(); | 231 VERIFY_AND_RESET_MOCKS(); |
| 261 | 232 |
| 262 gesture_.type = WebInputEvent::GestureScrollUpdate; | 233 gesture_.type = WebInputEvent::GestureScrollUpdate; |
| 263 gesture_.data.scrollUpdate.deltaY = 40; | 234 gesture_.data.scrollUpdate.deltaY = 40; |
| 264 input_handler_->HandleInputEvent(gesture_); | 235 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 265 | 236 |
| 266 VERIFY_AND_RESET_MOCKS(); | 237 VERIFY_AND_RESET_MOCKS(); |
| 267 | 238 |
| 268 gesture_.type = WebInputEvent::GestureScrollEnd; | 239 gesture_.type = WebInputEvent::GestureScrollEnd; |
| 269 gesture_.data.scrollUpdate.deltaY = 0; | 240 gesture_.data.scrollUpdate.deltaY = 0; |
| 270 input_handler_->HandleInputEvent(gesture_); | 241 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 271 } | 242 } |
| 272 | 243 |
| 273 TEST_F(InputHandlerProxyTest, GestureScrollIgnored) { | 244 TEST_F(InputHandlerProxyTest, GestureScrollIgnored) { |
| 274 // We shouldn't handle the GestureScrollBegin. | 245 // We shouldn't handle the GestureScrollBegin. |
| 275 // Instead, we should get one DidNotHandleInputEvent(false) call per | 246 // Instead, we should get a EVENT_DISPOSITION_DROP_EVENT result, indicating |
| 276 // HandleInputEvent(), indicating that we could determine that there's nothing | 247 // that we could determine that there's nothing that could scroll or otherwise |
| 277 // that could scroll or otherwise react to this gesture sequence and thus we | 248 // react to this gesture sequence and thus we should drop the whole gesture |
| 278 // should drop the whole gesture sequence on the floor. | 249 // sequence on the floor. |
| 279 expected_disposition_ = DropEvent; | 250 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DROP_EVENT; |
| 280 VERIFY_AND_RESET_MOCKS(); | 251 VERIFY_AND_RESET_MOCKS(); |
| 281 | 252 |
| 282 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 253 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 283 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored)); | 254 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored)); |
| 284 | 255 |
| 285 gesture_.type = WebInputEvent::GestureScrollBegin; | 256 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 286 input_handler_->HandleInputEvent(gesture_); | 257 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 287 } | 258 } |
| 288 | 259 |
| 289 TEST_F(InputHandlerProxyTest, GesturePinch) { | 260 TEST_F(InputHandlerProxyTest, GesturePinch) { |
| 290 // We shouldn't send any events to the widget for this gesture. | 261 // We shouldn't send any events to the widget for this gesture. |
| 291 expected_disposition_ = DidHandle; | 262 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 292 VERIFY_AND_RESET_MOCKS(); | 263 VERIFY_AND_RESET_MOCKS(); |
| 293 | 264 |
| 294 gesture_.type = WebInputEvent::GesturePinchBegin; | 265 gesture_.type = WebInputEvent::GesturePinchBegin; |
| 295 EXPECT_CALL(mock_input_handler_, PinchGestureBegin()); | 266 EXPECT_CALL(mock_input_handler_, PinchGestureBegin()); |
| 296 input_handler_->HandleInputEvent(gesture_); | 267 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 297 | 268 |
| 298 VERIFY_AND_RESET_MOCKS(); | 269 VERIFY_AND_RESET_MOCKS(); |
| 299 | 270 |
| 300 gesture_.type = WebInputEvent::GesturePinchUpdate; | 271 gesture_.type = WebInputEvent::GesturePinchUpdate; |
| 301 gesture_.data.pinchUpdate.scale = 1.5; | 272 gesture_.data.pinchUpdate.scale = 1.5; |
| 302 gesture_.x = 7; | 273 gesture_.x = 7; |
| 303 gesture_.y = 13; | 274 gesture_.y = 13; |
| 304 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(1.5, gfx::Point(7, 13))); | 275 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(1.5, gfx::Point(7, 13))); |
| 305 input_handler_->HandleInputEvent(gesture_); | 276 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 306 | 277 |
| 307 VERIFY_AND_RESET_MOCKS(); | 278 VERIFY_AND_RESET_MOCKS(); |
| 308 | 279 |
| 309 gesture_.type = WebInputEvent::GesturePinchUpdate; | 280 gesture_.type = WebInputEvent::GesturePinchUpdate; |
| 310 gesture_.data.pinchUpdate.scale = 0.5; | 281 gesture_.data.pinchUpdate.scale = 0.5; |
| 311 gesture_.x = 9; | 282 gesture_.x = 9; |
| 312 gesture_.y = 6; | 283 gesture_.y = 6; |
| 313 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(.5, gfx::Point(9, 6))); | 284 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(.5, gfx::Point(9, 6))); |
| 314 input_handler_->HandleInputEvent(gesture_); | 285 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 315 | 286 |
| 316 VERIFY_AND_RESET_MOCKS(); | 287 VERIFY_AND_RESET_MOCKS(); |
| 317 | 288 |
| 318 gesture_.type = WebInputEvent::GesturePinchEnd; | 289 gesture_.type = WebInputEvent::GesturePinchEnd; |
| 319 EXPECT_CALL(mock_input_handler_, PinchGestureEnd()); | 290 EXPECT_CALL(mock_input_handler_, PinchGestureEnd()); |
| 320 input_handler_->HandleInputEvent(gesture_); | 291 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 321 } | 292 } |
| 322 | 293 |
| 323 TEST_F(InputHandlerProxyTest, GesturePinchAfterScrollOnMainThread) { | 294 TEST_F(InputHandlerProxyTest, GesturePinchAfterScrollOnMainThread) { |
| 324 // Scrolls will start by being sent to the main thread. | 295 // Scrolls will start by being sent to the main thread. |
| 325 expected_disposition_ = DidNotHandle; | 296 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 326 VERIFY_AND_RESET_MOCKS(); | 297 VERIFY_AND_RESET_MOCKS(); |
| 327 | 298 |
| 328 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_)) | 299 EXPECT_CALL(mock_input_handler_, ScrollBegin(::testing::_, ::testing::_)) |
| 329 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); | 300 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); |
| 330 | 301 |
| 331 gesture_.type = WebInputEvent::GestureScrollBegin; | 302 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 332 input_handler_->HandleInputEvent(gesture_); | 303 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 333 | 304 |
| 334 VERIFY_AND_RESET_MOCKS(); | 305 VERIFY_AND_RESET_MOCKS(); |
| 335 | 306 |
| 336 gesture_.type = WebInputEvent::GestureScrollUpdate; | 307 gesture_.type = WebInputEvent::GestureScrollUpdate; |
| 337 gesture_.data.scrollUpdate.deltaY = 40; | 308 gesture_.data.scrollUpdate.deltaY = 40; |
| 338 input_handler_->HandleInputEvent(gesture_); | 309 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 339 | 310 |
| 340 // However, after the pinch gesture starts, they should go to the impl | 311 // However, after the pinch gesture starts, they should go to the impl |
| 341 // thread. | 312 // thread. |
| 342 expected_disposition_ = DidHandle; | 313 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 343 VERIFY_AND_RESET_MOCKS(); | 314 VERIFY_AND_RESET_MOCKS(); |
| 344 | 315 |
| 345 gesture_.type = WebInputEvent::GesturePinchBegin; | 316 gesture_.type = WebInputEvent::GesturePinchBegin; |
| 346 EXPECT_CALL(mock_input_handler_, PinchGestureBegin()); | 317 EXPECT_CALL(mock_input_handler_, PinchGestureBegin()); |
| 347 input_handler_->HandleInputEvent(gesture_); | 318 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 348 | 319 |
| 349 VERIFY_AND_RESET_MOCKS(); | 320 VERIFY_AND_RESET_MOCKS(); |
| 350 | 321 |
| 351 gesture_.type = WebInputEvent::GesturePinchUpdate; | 322 gesture_.type = WebInputEvent::GesturePinchUpdate; |
| 352 gesture_.data.pinchUpdate.scale = 1.5; | 323 gesture_.data.pinchUpdate.scale = 1.5; |
| 353 gesture_.x = 7; | 324 gesture_.x = 7; |
| 354 gesture_.y = 13; | 325 gesture_.y = 13; |
| 355 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(1.5, gfx::Point(7, 13))); | 326 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(1.5, gfx::Point(7, 13))); |
| 356 input_handler_->HandleInputEvent(gesture_); | 327 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 357 | 328 |
| 358 VERIFY_AND_RESET_MOCKS(); | 329 VERIFY_AND_RESET_MOCKS(); |
| 359 | 330 |
| 360 gesture_.type = WebInputEvent::GestureScrollUpdate; | 331 gesture_.type = WebInputEvent::GestureScrollUpdate; |
| 361 gesture_.data.scrollUpdate.deltaY = | 332 gesture_.data.scrollUpdate.deltaY = |
| 362 -40; // -Y means scroll down - i.e. in the +Y direction. | 333 -40; // -Y means scroll down - i.e. in the +Y direction. |
| 363 EXPECT_CALL(mock_input_handler_, | 334 EXPECT_CALL(mock_input_handler_, |
| 364 ScrollBy(testing::_, | 335 ScrollBy(testing::_, |
| 365 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))) | 336 testing::Property(&gfx::Vector2dF::y, testing::Gt(0)))) |
| 366 .WillOnce(testing::Return(true)); | 337 .WillOnce(testing::Return(true)); |
| 367 input_handler_->HandleInputEvent(gesture_); | 338 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 368 | 339 |
| 369 VERIFY_AND_RESET_MOCKS(); | 340 VERIFY_AND_RESET_MOCKS(); |
| 370 | 341 |
| 371 gesture_.type = WebInputEvent::GesturePinchUpdate; | 342 gesture_.type = WebInputEvent::GesturePinchUpdate; |
| 372 gesture_.data.pinchUpdate.scale = 0.5; | 343 gesture_.data.pinchUpdate.scale = 0.5; |
| 373 gesture_.x = 9; | 344 gesture_.x = 9; |
| 374 gesture_.y = 6; | 345 gesture_.y = 6; |
| 375 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(.5, gfx::Point(9, 6))); | 346 EXPECT_CALL(mock_input_handler_, PinchGestureUpdate(.5, gfx::Point(9, 6))); |
| 376 input_handler_->HandleInputEvent(gesture_); | 347 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 377 | 348 |
| 378 VERIFY_AND_RESET_MOCKS(); | 349 VERIFY_AND_RESET_MOCKS(); |
| 379 | 350 |
| 380 gesture_.type = WebInputEvent::GesturePinchEnd; | 351 gesture_.type = WebInputEvent::GesturePinchEnd; |
| 381 EXPECT_CALL(mock_input_handler_, PinchGestureEnd()); | 352 EXPECT_CALL(mock_input_handler_, PinchGestureEnd()); |
| 382 input_handler_->HandleInputEvent(gesture_); | 353 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 383 | 354 |
| 384 // After the pinch gesture ends, they should go to back to the main | 355 // After the pinch gesture ends, they should go to back to the main |
| 385 // thread. | 356 // thread. |
| 386 expected_disposition_ = DidNotHandle; | 357 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 387 VERIFY_AND_RESET_MOCKS(); | 358 VERIFY_AND_RESET_MOCKS(); |
| 388 | 359 |
| 389 gesture_.type = WebInputEvent::GestureScrollEnd; | 360 gesture_.type = WebInputEvent::GestureScrollEnd; |
| 390 gesture_.data.scrollUpdate.deltaY = 0; | 361 gesture_.data.scrollUpdate.deltaY = 0; |
| 391 input_handler_->HandleInputEvent(gesture_); | 362 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 392 } | 363 } |
| 393 | 364 |
| 394 TEST_F(InputHandlerProxyTest, GestureFlingStartedTouchpad) { | 365 TEST_F(InputHandlerProxyTest, GestureFlingStartedTouchpad) { |
| 395 // We shouldn't send any events to the widget for this gesture. | 366 // We shouldn't send any events to the widget for this gesture. |
| 396 expected_disposition_ = DidHandle; | 367 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 397 VERIFY_AND_RESET_MOCKS(); | 368 VERIFY_AND_RESET_MOCKS(); |
| 398 | 369 |
| 399 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 370 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 400 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 371 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 401 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 372 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 402 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 373 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 403 | 374 |
| 404 gesture_.type = WebInputEvent::GestureFlingStart; | 375 gesture_.type = WebInputEvent::GestureFlingStart; |
| 405 gesture_.data.flingStart.velocityX = 10; | 376 gesture_.data.flingStart.velocityX = 10; |
| 406 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 377 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 407 input_handler_->HandleInputEvent(gesture_); | 378 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 408 | 379 |
| 409 VERIFY_AND_RESET_MOCKS(); | 380 VERIFY_AND_RESET_MOCKS(); |
| 410 | 381 |
| 411 // Verify that a GestureFlingCancel during an animation cancels it. | 382 // Verify that a GestureFlingCancel during an animation cancels it. |
| 412 gesture_.type = WebInputEvent::GestureFlingCancel; | 383 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 413 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 384 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 414 input_handler_->HandleInputEvent(gesture_); | 385 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 415 } | 386 } |
| 416 | 387 |
| 417 TEST_F(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) { | 388 TEST_F(InputHandlerProxyTest, GestureFlingOnMainThreadTouchpad) { |
| 418 // We should send all events to the widget for this gesture. | 389 // We should send all events to the widget for this gesture. |
| 419 expected_disposition_ = DidNotHandle; | 390 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 420 VERIFY_AND_RESET_MOCKS(); | 391 VERIFY_AND_RESET_MOCKS(); |
| 421 | 392 |
| 422 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 393 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 423 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); | 394 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); |
| 424 | 395 |
| 425 gesture_.type = WebInputEvent::GestureFlingStart; | 396 gesture_.type = WebInputEvent::GestureFlingStart; |
| 426 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 397 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 427 input_handler_->HandleInputEvent(gesture_); | 398 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 428 | 399 |
| 429 // Since we returned ScrollStatusOnMainThread from scrollBegin, ensure the | 400 // Since we returned ScrollStatusOnMainThread from scrollBegin, ensure the |
| 430 // input handler knows it's scrolling off the impl thread | 401 // input handler knows it's scrolling off the impl thread |
| 431 ASSERT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); | 402 ASSERT_FALSE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); |
| 432 | 403 |
| 433 VERIFY_AND_RESET_MOCKS(); | 404 VERIFY_AND_RESET_MOCKS(); |
| 434 | 405 |
| 435 // Even if we didn't start a fling ourselves, we still need to send the cancel | 406 // Even if we didn't start a fling ourselves, we still need to send the cancel |
| 436 // event to the widget. | 407 // event to the widget. |
| 437 gesture_.type = WebInputEvent::GestureFlingCancel; | 408 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 438 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 409 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 439 input_handler_->HandleInputEvent(gesture_); | 410 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 440 } | 411 } |
| 441 | 412 |
| 442 TEST_F(InputHandlerProxyTest, GestureFlingIgnoredTouchpad) { | 413 TEST_F(InputHandlerProxyTest, GestureFlingIgnoredTouchpad) { |
| 443 expected_disposition_ = DidNotHandle; | 414 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 444 VERIFY_AND_RESET_MOCKS(); | 415 VERIFY_AND_RESET_MOCKS(); |
| 445 | 416 |
| 446 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 417 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 447 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored)); | 418 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored)); |
| 448 | 419 |
| 449 gesture_.type = WebInputEvent::GestureFlingStart; | 420 gesture_.type = WebInputEvent::GestureFlingStart; |
| 450 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 421 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 451 input_handler_->HandleInputEvent(gesture_); | 422 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 452 | 423 |
| 453 expected_disposition_ = DropEvent; | 424 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DROP_EVENT; |
| 454 VERIFY_AND_RESET_MOCKS(); | 425 VERIFY_AND_RESET_MOCKS(); |
| 455 | 426 |
| 456 // Since the previous fling was ignored, we should also be dropping the next | 427 // Since the previous fling was ignored, we should also be dropping the next |
| 457 // fling_cancel. | 428 // fling_cancel. |
| 458 gesture_.type = WebInputEvent::GestureFlingCancel; | 429 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 459 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 430 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 460 input_handler_->HandleInputEvent(gesture_); | 431 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 461 } | 432 } |
| 462 | 433 |
| 463 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchpad) { | 434 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchpad) { |
| 464 // We shouldn't send any events to the widget for this gesture. | 435 // We shouldn't send any events to the widget for this gesture. |
| 465 expected_disposition_ = DidHandle; | 436 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 466 VERIFY_AND_RESET_MOCKS(); | 437 VERIFY_AND_RESET_MOCKS(); |
| 467 | 438 |
| 468 // On the fling start, we should schedule an animation but not actually start | 439 // On the fling start, we should schedule an animation but not actually start |
| 469 // scrolling. | 440 // scrolling. |
| 470 gesture_.type = WebInputEvent::GestureFlingStart; | 441 gesture_.type = WebInputEvent::GestureFlingStart; |
| 471 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); | 442 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); |
| 472 WebPoint fling_point = WebPoint(7, 13); | 443 WebPoint fling_point = WebPoint(7, 13); |
| 473 WebPoint fling_global_point = WebPoint(17, 23); | 444 WebPoint fling_global_point = WebPoint(17, 23); |
| 474 int modifiers = 7; | 445 int modifiers = 7; |
| 475 gesture_.data.flingStart.velocityX = fling_delta.x; | 446 gesture_.data.flingStart.velocityX = fling_delta.x; |
| 476 gesture_.data.flingStart.velocityY = fling_delta.y; | 447 gesture_.data.flingStart.velocityY = fling_delta.y; |
| 477 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 448 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 478 gesture_.x = fling_point.x; | 449 gesture_.x = fling_point.x; |
| 479 gesture_.y = fling_point.y; | 450 gesture_.y = fling_point.y; |
| 480 gesture_.globalX = fling_global_point.x; | 451 gesture_.globalX = fling_global_point.x; |
| 481 gesture_.globalY = fling_global_point.y; | 452 gesture_.globalY = fling_global_point.y; |
| 482 gesture_.modifiers = modifiers; | 453 gesture_.modifiers = modifiers; |
| 483 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 454 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 484 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 455 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 485 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 456 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 486 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 457 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 487 input_handler_->HandleInputEvent(gesture_); | 458 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 488 | 459 |
| 489 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 460 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 490 // The first animate call should let us pick up an animation start time, but | 461 // The first animate call should let us pick up an animation start time, but |
| 491 // we shouldn't actually move anywhere just yet. The first frame after the | 462 // we shouldn't actually move anywhere just yet. The first frame after the |
| 492 // fling start will typically include the last scroll from the gesture that | 463 // fling start will typically include the last scroll from the gesture that |
| 493 // lead to the scroll (either wheel or gesture scroll), so there should be no | 464 // lead to the scroll (either wheel or gesture scroll), so there should be no |
| 494 // visible hitch. | 465 // visible hitch. |
| 495 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 466 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 496 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 467 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 497 .Times(0); | 468 .Times(0); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 // frame being requested. | 528 // frame being requested. |
| 558 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()).Times(0); | 529 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()).Times(0); |
| 559 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 530 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 560 .Times(0); | 531 .Times(0); |
| 561 time += base::TimeDelta::FromMilliseconds(100); | 532 time += base::TimeDelta::FromMilliseconds(100); |
| 562 input_handler_->Animate(time); | 533 input_handler_->Animate(time); |
| 563 | 534 |
| 564 // Since we've transferred the fling to the main thread, we need to pass the | 535 // Since we've transferred the fling to the main thread, we need to pass the |
| 565 // next GestureFlingCancel to the main | 536 // next GestureFlingCancel to the main |
| 566 // thread as well. | 537 // thread as well. |
| 567 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(true)); | 538 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 568 gesture_.type = WebInputEvent::GestureFlingCancel; | 539 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 569 input_handler_->HandleInputEvent(gesture_); | 540 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 570 } | 541 } |
| 571 | 542 |
| 572 TEST_F(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) { | 543 TEST_F(InputHandlerProxyTest, GestureFlingTransferResetsTouchpad) { |
| 573 // We shouldn't send any events to the widget for this gesture. | 544 // We shouldn't send any events to the widget for this gesture. |
| 574 expected_disposition_ = DidHandle; | 545 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 575 VERIFY_AND_RESET_MOCKS(); | 546 VERIFY_AND_RESET_MOCKS(); |
| 576 | 547 |
| 577 // Start a gesture fling in the -X direction with zero Y movement. | 548 // Start a gesture fling in the -X direction with zero Y movement. |
| 578 gesture_.type = WebInputEvent::GestureFlingStart; | 549 gesture_.type = WebInputEvent::GestureFlingStart; |
| 579 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); | 550 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); |
| 580 WebPoint fling_point = WebPoint(7, 13); | 551 WebPoint fling_point = WebPoint(7, 13); |
| 581 WebPoint fling_global_point = WebPoint(17, 23); | 552 WebPoint fling_global_point = WebPoint(17, 23); |
| 582 int modifiers = 1; | 553 int modifiers = 1; |
| 583 gesture_.data.flingStart.velocityX = fling_delta.x; | 554 gesture_.data.flingStart.velocityX = fling_delta.x; |
| 584 gesture_.data.flingStart.velocityY = fling_delta.y; | 555 gesture_.data.flingStart.velocityY = fling_delta.y; |
| 585 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 556 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 586 gesture_.x = fling_point.x; | 557 gesture_.x = fling_point.x; |
| 587 gesture_.y = fling_point.y; | 558 gesture_.y = fling_point.y; |
| 588 gesture_.globalX = fling_global_point.x; | 559 gesture_.globalX = fling_global_point.x; |
| 589 gesture_.globalY = fling_global_point.y; | 560 gesture_.globalY = fling_global_point.y; |
| 590 gesture_.modifiers = modifiers; | 561 gesture_.modifiers = modifiers; |
| 591 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 562 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 592 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 563 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 593 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 564 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 594 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 565 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 595 input_handler_->HandleInputEvent(gesture_); | 566 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 596 | 567 |
| 597 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 568 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 598 | 569 |
| 599 // Start the fling animation at time 10. This shouldn't actually scroll, just | 570 // Start the fling animation at time 10. This shouldn't actually scroll, just |
| 600 // establish a start time. | 571 // establish a start time. |
| 601 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 572 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 602 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 573 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 603 .Times(0); | 574 .Times(0); |
| 604 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); | 575 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); |
| 605 input_handler_->Animate(time); | 576 input_handler_->Animate(time); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 637 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 667 .Times(0); | 638 .Times(0); |
| 668 time += base::TimeDelta::FromMilliseconds(100); | 639 time += base::TimeDelta::FromMilliseconds(100); |
| 669 input_handler_->Animate(time); | 640 input_handler_->Animate(time); |
| 670 | 641 |
| 671 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 642 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 672 | 643 |
| 673 // Since we've transferred the fling to the main thread, we need to pass the | 644 // Since we've transferred the fling to the main thread, we need to pass the |
| 674 // next GestureFlingCancel to the main | 645 // next GestureFlingCancel to the main |
| 675 // thread as well. | 646 // thread as well. |
| 676 EXPECT_CALL(mock_client_, DidNotHandleInputEvent(true)); | 647 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 677 gesture_.type = WebInputEvent::GestureFlingCancel; | 648 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 678 input_handler_->HandleInputEvent(gesture_); | 649 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 679 | 650 |
| 680 VERIFY_AND_RESET_MOCKS(); | 651 VERIFY_AND_RESET_MOCKS(); |
| 681 input_handler_->MainThreadHasStoppedFlinging(); | 652 input_handler_->MainThreadHasStoppedFlinging(); |
| 682 | 653 |
| 683 // Start a second gesture fling, this time in the +Y direction with no X. | 654 // Start a second gesture fling, this time in the +Y direction with no X. |
| 684 gesture_.type = WebInputEvent::GestureFlingStart; | 655 gesture_.type = WebInputEvent::GestureFlingStart; |
| 685 fling_delta = WebFloatPoint(0, -1000); | 656 fling_delta = WebFloatPoint(0, -1000); |
| 686 fling_point = WebPoint(95, 87); | 657 fling_point = WebPoint(95, 87); |
| 687 fling_global_point = WebPoint(32, 71); | 658 fling_global_point = WebPoint(32, 71); |
| 688 modifiers = 2; | 659 modifiers = 2; |
| 689 gesture_.data.flingStart.velocityX = fling_delta.x; | 660 gesture_.data.flingStart.velocityX = fling_delta.x; |
| 690 gesture_.data.flingStart.velocityY = fling_delta.y; | 661 gesture_.data.flingStart.velocityY = fling_delta.y; |
| 691 gesture_.sourceDevice = WebGestureEvent::Touchpad; | 662 gesture_.sourceDevice = WebGestureEvent::Touchpad; |
| 692 gesture_.x = fling_point.x; | 663 gesture_.x = fling_point.x; |
| 693 gesture_.y = fling_point.y; | 664 gesture_.y = fling_point.y; |
| 694 gesture_.globalX = fling_global_point.x; | 665 gesture_.globalX = fling_global_point.x; |
| 695 gesture_.globalY = fling_global_point.y; | 666 gesture_.globalY = fling_global_point.y; |
| 696 gesture_.modifiers = modifiers; | 667 gesture_.modifiers = modifiers; |
| 697 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 668 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 698 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 669 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 699 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 670 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 700 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 671 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 701 input_handler_->HandleInputEvent(gesture_); | 672 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 673 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 702 | 674 |
| 703 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 675 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 704 | 676 |
| 705 // Start the second fling animation at time 30. | 677 // Start the second fling animation at time 30. |
| 706 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 678 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 707 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 679 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 708 .Times(0); | 680 .Times(0); |
| 709 time = base::TimeTicks() + base::TimeDelta::FromSeconds(30); | 681 time = base::TimeTicks() + base::TimeDelta::FromSeconds(30); |
| 710 input_handler_->Animate(time); | 682 input_handler_->Animate(time); |
| 711 | 683 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 testing::Field(&WebActiveWheelFlingParameters::startTime, | 720 testing::Field(&WebActiveWheelFlingParameters::startTime, |
| 749 testing::Eq(30)), | 721 testing::Eq(30)), |
| 750 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll, | 722 testing::Field(&WebActiveWheelFlingParameters::cumulativeScroll, |
| 751 testing::Field(&WebSize::height, testing::Lt(0)))))); | 723 testing::Field(&WebSize::height, testing::Lt(0)))))); |
| 752 time += base::TimeDelta::FromMilliseconds(100); | 724 time += base::TimeDelta::FromMilliseconds(100); |
| 753 input_handler_->Animate(time); | 725 input_handler_->Animate(time); |
| 754 } | 726 } |
| 755 | 727 |
| 756 TEST_F(InputHandlerProxyTest, GestureFlingStartedTouchscreen) { | 728 TEST_F(InputHandlerProxyTest, GestureFlingStartedTouchscreen) { |
| 757 // We shouldn't send any events to the widget for this gesture. | 729 // We shouldn't send any events to the widget for this gesture. |
| 758 expected_disposition_ = DidHandle; | 730 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 759 VERIFY_AND_RESET_MOCKS(); | 731 VERIFY_AND_RESET_MOCKS(); |
| 760 | 732 |
| 761 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 733 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 762 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 734 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 763 gesture_.type = WebInputEvent::GestureScrollBegin; | 735 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 764 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 736 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 765 input_handler_->HandleInputEvent(gesture_); | 737 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 766 | 738 |
| 767 VERIFY_AND_RESET_MOCKS(); | 739 VERIFY_AND_RESET_MOCKS(); |
| 768 | 740 |
| 769 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) | 741 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) |
| 770 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 742 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 771 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 743 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 772 | 744 |
| 773 gesture_.type = WebInputEvent::GestureFlingStart; | 745 gesture_.type = WebInputEvent::GestureFlingStart; |
| 774 gesture_.data.flingStart.velocityX = 10; | 746 gesture_.data.flingStart.velocityX = 10; |
| 775 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 747 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 776 input_handler_->HandleInputEvent(gesture_); | 748 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 777 | 749 |
| 778 VERIFY_AND_RESET_MOCKS(); | 750 VERIFY_AND_RESET_MOCKS(); |
| 779 | 751 |
| 780 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 752 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 781 | 753 |
| 782 // Verify that a GestureFlingCancel during an animation cancels it. | 754 // Verify that a GestureFlingCancel during an animation cancels it. |
| 783 gesture_.type = WebInputEvent::GestureFlingCancel; | 755 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 784 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 756 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 785 input_handler_->HandleInputEvent(gesture_); | 757 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 786 } | 758 } |
| 787 | 759 |
| 788 TEST_F(InputHandlerProxyTest, GestureFlingOnMainThreadTouchscreen) { | 760 TEST_F(InputHandlerProxyTest, GestureFlingOnMainThreadTouchscreen) { |
| 789 // We should send all events to the widget for this gesture. | 761 // We should send all events to the widget for this gesture. |
| 790 expected_disposition_ = DidNotHandle; | 762 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_NOT_HANDLE; |
| 791 VERIFY_AND_RESET_MOCKS(); | 763 VERIFY_AND_RESET_MOCKS(); |
| 792 | 764 |
| 793 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 765 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 794 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); | 766 .WillOnce(testing::Return(cc::InputHandler::ScrollOnMainThread)); |
| 795 | 767 |
| 796 gesture_.type = WebInputEvent::GestureScrollBegin; | 768 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 797 input_handler_->HandleInputEvent(gesture_); | 769 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 798 | 770 |
| 799 VERIFY_AND_RESET_MOCKS(); | 771 VERIFY_AND_RESET_MOCKS(); |
| 800 | 772 |
| 801 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()).Times(0); | 773 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()).Times(0); |
| 802 | 774 |
| 803 gesture_.type = WebInputEvent::GestureFlingStart; | 775 gesture_.type = WebInputEvent::GestureFlingStart; |
| 804 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 776 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 805 input_handler_->HandleInputEvent(gesture_); | 777 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 806 | 778 |
| 807 VERIFY_AND_RESET_MOCKS(); | 779 VERIFY_AND_RESET_MOCKS(); |
| 808 | 780 |
| 809 // Even if we didn't start a fling ourselves, we still need to send the cancel | 781 // Even if we didn't start a fling ourselves, we still need to send the cancel |
| 810 // event to the widget. | 782 // event to the widget. |
| 811 gesture_.type = WebInputEvent::GestureFlingCancel; | 783 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 812 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 784 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 813 input_handler_->HandleInputEvent(gesture_); | 785 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 814 } | 786 } |
| 815 | 787 |
| 816 TEST_F(InputHandlerProxyTest, GestureFlingIgnoredTouchscreen) { | 788 TEST_F(InputHandlerProxyTest, GestureFlingIgnoredTouchscreen) { |
| 817 expected_disposition_ = DidHandle; | 789 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 818 VERIFY_AND_RESET_MOCKS(); | 790 VERIFY_AND_RESET_MOCKS(); |
| 819 | 791 |
| 820 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 792 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 821 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 793 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 822 | 794 |
| 823 gesture_.type = WebInputEvent::GestureScrollBegin; | 795 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 824 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 796 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 825 input_handler_->HandleInputEvent(gesture_); | 797 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 826 | 798 |
| 827 expected_disposition_ = DropEvent; | 799 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DROP_EVENT; |
| 828 VERIFY_AND_RESET_MOCKS(); | 800 VERIFY_AND_RESET_MOCKS(); |
| 829 | 801 |
| 830 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) | 802 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) |
| 831 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored)); | 803 .WillOnce(testing::Return(cc::InputHandler::ScrollIgnored)); |
| 832 | 804 |
| 833 gesture_.type = WebInputEvent::GestureFlingStart; | 805 gesture_.type = WebInputEvent::GestureFlingStart; |
| 834 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 806 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 835 input_handler_->HandleInputEvent(gesture_); | 807 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 836 | 808 |
| 837 VERIFY_AND_RESET_MOCKS(); | 809 VERIFY_AND_RESET_MOCKS(); |
| 838 | 810 |
| 839 // Even if we didn't start a fling ourselves, we still need to send the cancel | 811 // Even if we didn't start a fling ourselves, we still need to send the cancel |
| 840 // event to the widget. | 812 // event to the widget. |
| 841 gesture_.type = WebInputEvent::GestureFlingCancel; | 813 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 842 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 814 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 843 input_handler_->HandleInputEvent(gesture_); | 815 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 844 } | 816 } |
| 845 | 817 |
| 846 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchscreen) { | 818 TEST_F(InputHandlerProxyTest, GestureFlingAnimatesTouchscreen) { |
| 847 // We shouldn't send any events to the widget for this gesture. | 819 // We shouldn't send any events to the widget for this gesture. |
| 848 expected_disposition_ = DidHandle; | 820 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 849 VERIFY_AND_RESET_MOCKS(); | 821 VERIFY_AND_RESET_MOCKS(); |
| 850 | 822 |
| 851 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 823 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 852 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 824 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 853 | 825 |
| 854 gesture_.type = WebInputEvent::GestureScrollBegin; | 826 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 855 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 827 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 856 input_handler_->HandleInputEvent(gesture_); | 828 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 857 | 829 |
| 858 VERIFY_AND_RESET_MOCKS(); | 830 VERIFY_AND_RESET_MOCKS(); |
| 859 | 831 |
| 860 // On the fling start, we should schedule an animation but not actually start | 832 // On the fling start, we should schedule an animation but not actually start |
| 861 // scrolling. | 833 // scrolling. |
| 862 gesture_.type = WebInputEvent::GestureFlingStart; | 834 gesture_.type = WebInputEvent::GestureFlingStart; |
| 863 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); | 835 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); |
| 864 WebPoint fling_point = WebPoint(7, 13); | 836 WebPoint fling_point = WebPoint(7, 13); |
| 865 WebPoint fling_global_point = WebPoint(17, 23); | 837 WebPoint fling_global_point = WebPoint(17, 23); |
| 866 int modifiers = 7; | 838 int modifiers = 7; |
| 867 gesture_.data.flingStart.velocityX = fling_delta.x; | 839 gesture_.data.flingStart.velocityX = fling_delta.x; |
| 868 gesture_.data.flingStart.velocityY = fling_delta.y; | 840 gesture_.data.flingStart.velocityY = fling_delta.y; |
| 869 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 841 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 870 gesture_.x = fling_point.x; | 842 gesture_.x = fling_point.x; |
| 871 gesture_.y = fling_point.y; | 843 gesture_.y = fling_point.y; |
| 872 gesture_.globalX = fling_global_point.x; | 844 gesture_.globalX = fling_global_point.x; |
| 873 gesture_.globalY = fling_global_point.y; | 845 gesture_.globalY = fling_global_point.y; |
| 874 gesture_.modifiers = modifiers; | 846 gesture_.modifiers = modifiers; |
| 875 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 847 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 876 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) | 848 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) |
| 877 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 849 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 878 input_handler_->HandleInputEvent(gesture_); | 850 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 879 | 851 |
| 880 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 852 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 881 // The first animate call should let us pick up an animation start time, but | 853 // The first animate call should let us pick up an animation start time, but |
| 882 // we shouldn't actually move anywhere just yet. The first frame after the | 854 // we shouldn't actually move anywhere just yet. The first frame after the |
| 883 // fling start will typically include the last scroll from the gesture that | 855 // fling start will typically include the last scroll from the gesture that |
| 884 // lead to the scroll (either wheel or gesture scroll), so there should be no | 856 // lead to the scroll (either wheel or gesture scroll), so there should be no |
| 885 // visible hitch. | 857 // visible hitch. |
| 886 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 858 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 887 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); | 859 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); |
| 888 input_handler_->Animate(time); | 860 input_handler_->Animate(time); |
| 889 | 861 |
| 890 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 862 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 891 | 863 |
| 892 // The second call should start scrolling in the -X direction. | 864 // The second call should start scrolling in the -X direction. |
| 893 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 865 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 894 EXPECT_CALL(mock_input_handler_, | 866 EXPECT_CALL(mock_input_handler_, |
| 895 ScrollBy(testing::_, | 867 ScrollBy(testing::_, |
| 896 testing::Property(&gfx::Vector2dF::x, testing::Lt(0)))) | 868 testing::Property(&gfx::Vector2dF::x, testing::Lt(0)))) |
| 897 .WillOnce(testing::Return(true)); | 869 .WillOnce(testing::Return(true)); |
| 898 time += base::TimeDelta::FromMilliseconds(100); | 870 time += base::TimeDelta::FromMilliseconds(100); |
| 899 input_handler_->Animate(time); | 871 input_handler_->Animate(time); |
| 900 | 872 |
| 901 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 873 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 902 | 874 |
| 903 EXPECT_CALL(mock_client_, DidHandleInputEvent()); | |
| 904 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 875 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 905 gesture_.type = WebInputEvent::GestureFlingCancel; | 876 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 906 input_handler_->HandleInputEvent(gesture_); | 877 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 907 } | 878 } |
| 908 | 879 |
| 909 TEST_F(InputHandlerProxyTest, | 880 TEST_F(InputHandlerProxyTest, |
| 910 GestureScrollOnImplThreadFlagClearedAfterFling) { | 881 GestureScrollOnImplThreadFlagClearedAfterFling) { |
| 911 // We shouldn't send any events to the widget for this gesture. | 882 // We shouldn't send any events to the widget for this gesture. |
| 912 expected_disposition_ = DidHandle; | 883 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 913 VERIFY_AND_RESET_MOCKS(); | 884 VERIFY_AND_RESET_MOCKS(); |
| 914 | 885 |
| 915 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) | 886 EXPECT_CALL(mock_input_handler_, ScrollBegin(testing::_, testing::_)) |
| 916 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 887 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 917 | 888 |
| 918 gesture_.type = WebInputEvent::GestureScrollBegin; | 889 gesture_.type = WebInputEvent::GestureScrollBegin; |
| 919 input_handler_->HandleInputEvent(gesture_); | 890 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 920 | 891 |
| 921 // After sending a GestureScrollBegin, the member variable | 892 // After sending a GestureScrollBegin, the member variable |
| 922 // |gesture_scroll_on_impl_thread_| should be true. | 893 // |gesture_scroll_on_impl_thread_| should be true. |
| 923 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); | 894 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); |
| 924 | 895 |
| 925 expected_disposition_ = DidHandle; | 896 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DID_HANDLE; |
| 926 VERIFY_AND_RESET_MOCKS(); | 897 VERIFY_AND_RESET_MOCKS(); |
| 927 | 898 |
| 928 // On the fling start, we should schedule an animation but not actually start | 899 // On the fling start, we should schedule an animation but not actually start |
| 929 // scrolling. | 900 // scrolling. |
| 930 gesture_.type = WebInputEvent::GestureFlingStart; | 901 gesture_.type = WebInputEvent::GestureFlingStart; |
| 931 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); | 902 WebFloatPoint fling_delta = WebFloatPoint(1000, 0); |
| 932 WebPoint fling_point = WebPoint(7, 13); | 903 WebPoint fling_point = WebPoint(7, 13); |
| 933 WebPoint fling_global_point = WebPoint(17, 23); | 904 WebPoint fling_global_point = WebPoint(17, 23); |
| 934 int modifiers = 7; | 905 int modifiers = 7; |
| 935 gesture_.data.flingStart.velocityX = fling_delta.x; | 906 gesture_.data.flingStart.velocityX = fling_delta.x; |
| 936 gesture_.data.flingStart.velocityY = fling_delta.y; | 907 gesture_.data.flingStart.velocityY = fling_delta.y; |
| 937 gesture_.sourceDevice = WebGestureEvent::Touchscreen; | 908 gesture_.sourceDevice = WebGestureEvent::Touchscreen; |
| 938 gesture_.x = fling_point.x; | 909 gesture_.x = fling_point.x; |
| 939 gesture_.y = fling_point.y; | 910 gesture_.y = fling_point.y; |
| 940 gesture_.globalX = fling_global_point.x; | 911 gesture_.globalX = fling_global_point.x; |
| 941 gesture_.globalY = fling_global_point.y; | 912 gesture_.globalY = fling_global_point.y; |
| 942 gesture_.modifiers = modifiers; | 913 gesture_.modifiers = modifiers; |
| 943 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 914 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 944 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) | 915 EXPECT_CALL(mock_input_handler_, FlingScrollBegin()) |
| 945 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); | 916 .WillOnce(testing::Return(cc::InputHandler::ScrollStarted)); |
| 946 input_handler_->HandleInputEvent(gesture_); | 917 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 947 | 918 |
| 948 // |gesture_scroll_on_impl_thread_| should still be true after | 919 // |gesture_scroll_on_impl_thread_| should still be true after |
| 949 // a GestureFlingStart is sent. | 920 // a GestureFlingStart is sent. |
| 950 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); | 921 EXPECT_TRUE(input_handler_->gesture_scroll_on_impl_thread_for_testing()); |
| 951 | 922 |
| 952 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 923 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 953 // The first animate call should let us pick up an animation start time, but | 924 // The first animate call should let us pick up an animation start time, but |
| 954 // we shouldn't actually move anywhere just yet. The first frame after the | 925 // we shouldn't actually move anywhere just yet. The first frame after the |
| 955 // fling start will typically include the last scroll from the gesture that | 926 // fling start will typically include the last scroll from the gesture that |
| 956 // lead to the scroll (either wheel or gesture scroll), so there should be no | 927 // lead to the scroll (either wheel or gesture scroll), so there should be no |
| 957 // visible hitch. | 928 // visible hitch. |
| 958 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 929 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 959 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); | 930 base::TimeTicks time = base::TimeTicks() + base::TimeDelta::FromSeconds(10); |
| 960 input_handler_->Animate(time); | 931 input_handler_->Animate(time); |
| 961 | 932 |
| 962 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 933 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 963 | 934 |
| 964 // The second call should start scrolling in the -X direction. | 935 // The second call should start scrolling in the -X direction. |
| 965 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); | 936 EXPECT_CALL(mock_input_handler_, ScheduleAnimation()); |
| 966 EXPECT_CALL(mock_input_handler_, | 937 EXPECT_CALL(mock_input_handler_, |
| 967 ScrollBy(testing::_, | 938 ScrollBy(testing::_, |
| 968 testing::Property(&gfx::Vector2dF::x, testing::Lt(0)))) | 939 testing::Property(&gfx::Vector2dF::x, testing::Lt(0)))) |
| 969 .WillOnce(testing::Return(true)); | 940 .WillOnce(testing::Return(true)); |
| 970 time += base::TimeDelta::FromMilliseconds(100); | 941 time += base::TimeDelta::FromMilliseconds(100); |
| 971 input_handler_->Animate(time); | 942 input_handler_->Animate(time); |
| 972 | 943 |
| 973 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 944 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 974 | 945 |
| 975 EXPECT_CALL(mock_client_, DidHandleInputEvent()); | |
| 976 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 946 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 977 gesture_.type = WebInputEvent::GestureFlingCancel; | 947 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 978 input_handler_->HandleInputEvent(gesture_); | 948 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 979 | 949 |
| 980 // |gesture_scroll_on_impl_thread_| should be false once | 950 // |gesture_scroll_on_impl_thread_| should be false once |
| 981 // the fling has finished (note no GestureScrollEnd has been sent). | 951 // the fling has finished (note no GestureScrollEnd has been sent). |
| 982 EXPECT_TRUE(!input_handler_->gesture_scroll_on_impl_thread_for_testing()); | 952 EXPECT_TRUE(!input_handler_->gesture_scroll_on_impl_thread_for_testing()); |
| 983 } | 953 } |
| 984 | 954 |
| 985 TEST_F(InputHandlerProxyTest, LastInputEventForVSync) { | 955 TEST_F(InputHandlerProxyTest, LastInputEventForVSync) { |
| 986 expected_disposition_ = DropEvent; | 956 expected_disposition_ = InputHandlerProxy::EVENT_DISPOSITION_DROP_EVENT; |
| 987 VERIFY_AND_RESET_MOCKS(); | 957 VERIFY_AND_RESET_MOCKS(); |
| 988 | 958 |
| 989 gesture_.type = WebInputEvent::GestureFlingCancel; | 959 gesture_.type = WebInputEvent::GestureFlingCancel; |
| 990 gesture_.timeStampSeconds = 1234; | 960 gesture_.timeStampSeconds = 1234; |
| 991 base::TimeTicks time = | 961 base::TimeTicks time = |
| 992 base::TimeTicks() + | 962 base::TimeTicks() + |
| 993 base::TimeDelta::FromSeconds(gesture_.timeStampSeconds); | 963 base::TimeDelta::FromSeconds(gesture_.timeStampSeconds); |
| 994 gesture_.modifiers |= WebInputEvent::IsLastInputEventForCurrentVSync; | 964 gesture_.modifiers |= WebInputEvent::IsLastInputEventForCurrentVSync; |
| 995 EXPECT_CALL(mock_input_handler_, DidReceiveLastInputEventForBeginFrame(time)); | 965 EXPECT_CALL(mock_input_handler_, DidReceiveLastInputEventForBeginFrame(time)); |
| 996 input_handler_->HandleInputEvent(gesture_); | 966 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(gesture_)); |
| 997 } | 967 } |
| 998 | 968 |
| 999 } // namespace | 969 } // namespace |
| 970 } // namespace content |
| OLD | NEW |