| 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/public/web/WebInputEvent.h" | 16 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 17 #include "ui/events/latency_info.h" | 17 #include "ui/events/latency_info.h" |
| 18 | 18 |
| 19 using blink::WebActiveWheelFlingParameters; | 19 using blink::WebActiveWheelFlingParameters; |
| 20 using blink::WebFloatPoint; | 20 using blink::WebFloatPoint; |
| 21 using blink::WebFloatSize; | 21 using blink::WebFloatSize; |
| 22 using blink::WebGestureEvent; | 22 using blink::WebGestureEvent; |
| 23 using blink::WebInputEvent; | 23 using blink::WebInputEvent; |
| 24 using blink::WebMouseWheelEvent; | 24 using blink::WebMouseWheelEvent; |
| 25 using blink::WebPoint; | 25 using blink::WebPoint; |
| 26 using blink::WebSize; | 26 using blink::WebSize; |
| 27 using blink::WebTouchEvent; |
| 28 using blink::WebTouchPoint; |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 class MockInputHandler : public cc::InputHandler { | 33 class MockInputHandler : public cc::InputHandler { |
| 32 public: | 34 public: |
| 33 MockInputHandler() {} | 35 MockInputHandler() {} |
| 34 virtual ~MockInputHandler() {} | 36 virtual ~MockInputHandler() {} |
| 35 | 37 |
| 36 MOCK_METHOD0(PinchGestureBegin, void()); | 38 MOCK_METHOD0(PinchGestureBegin, void()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 57 virtual void BindToClient(cc::InputHandlerClient* client) OVERRIDE {} | 59 virtual void BindToClient(cc::InputHandlerClient* client) OVERRIDE {} |
| 58 | 60 |
| 59 virtual void StartPageScaleAnimation(gfx::Vector2d target_offset, | 61 virtual void StartPageScaleAnimation(gfx::Vector2d target_offset, |
| 60 bool anchor_point, | 62 bool anchor_point, |
| 61 float page_scale, | 63 float page_scale, |
| 62 base::TimeDelta duration) OVERRIDE {} | 64 base::TimeDelta duration) OVERRIDE {} |
| 63 | 65 |
| 64 virtual void NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) OVERRIDE {} | 66 virtual void NotifyCurrentFlingVelocity(gfx::Vector2dF velocity) OVERRIDE {} |
| 65 virtual void MouseMoveAt(gfx::Point mouse_position) OVERRIDE {} | 67 virtual void MouseMoveAt(gfx::Point mouse_position) OVERRIDE {} |
| 66 | 68 |
| 67 virtual bool HaveTouchEventHandlersAt(gfx::Point point) OVERRIDE { | 69 MOCK_METHOD1(HaveTouchEventHandlersAt, |
| 68 return false; | 70 bool(gfx::Point point)); |
| 69 } | |
| 70 | 71 |
| 71 virtual void SetRootLayerScrollOffsetDelegate( | 72 virtual void SetRootLayerScrollOffsetDelegate( |
| 72 cc::LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) | 73 cc::LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) |
| 73 OVERRIDE {} | 74 OVERRIDE {} |
| 74 | 75 |
| 75 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE {} | 76 virtual void OnRootLayerDelegatedScrollOffsetChanged() OVERRIDE {} |
| 76 | 77 |
| 77 DISALLOW_COPY_AND_ASSIGN(MockInputHandler); | 78 DISALLOW_COPY_AND_ASSIGN(MockInputHandler); |
| 78 }; | 79 }; |
| 79 | 80 |
| (...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 EXPECT_CALL(mock_input_handler_, | 1068 EXPECT_CALL(mock_input_handler_, |
| 1068 ScrollBy(testing::_, | 1069 ScrollBy(testing::_, |
| 1069 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) | 1070 testing::Property(&gfx::Vector2dF::y, testing::Eq(0)))) |
| 1070 .WillOnce(testing::Return(true)); | 1071 .WillOnce(testing::Return(true)); |
| 1071 EXPECT_CALL(mock_input_handler_, ScrollEnd()); | 1072 EXPECT_CALL(mock_input_handler_, ScrollEnd()); |
| 1072 time += base::TimeDelta::FromMilliseconds(100); | 1073 time += base::TimeDelta::FromMilliseconds(100); |
| 1073 input_handler_->Animate(time); | 1074 input_handler_->Animate(time); |
| 1074 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); | 1075 testing::Mock::VerifyAndClearExpectations(&mock_input_handler_); |
| 1075 } | 1076 } |
| 1076 | 1077 |
| 1078 TEST_F(InputHandlerProxyTest, MultiTouchPointHitTestNegative) { |
| 1079 // None of the three touch points fall in the touch region. So the event |
| 1080 // should be dropped. |
| 1081 expected_disposition_ = InputHandlerProxy::DROP_EVENT; |
| 1082 VERIFY_AND_RESET_MOCKS(); |
| 1083 |
| 1084 EXPECT_CALL(mock_input_handler_, |
| 1085 HaveTouchEventHandlersAt( |
| 1086 testing::Property(&gfx::Point::x, testing::Gt(0)))) |
| 1087 .WillOnce(testing::Return(false)); |
| 1088 EXPECT_CALL(mock_input_handler_, |
| 1089 HaveTouchEventHandlersAt( |
| 1090 testing::Property(&gfx::Point::x, testing::Lt(0)))) |
| 1091 .WillOnce(testing::Return(false)); |
| 1092 |
| 1093 WebTouchEvent touch; |
| 1094 touch.type = WebInputEvent::TouchStart; |
| 1095 |
| 1096 touch.touchesLength = 3; |
| 1097 touch.touches[0].state = WebTouchPoint::StateStationary; |
| 1098 touch.touches[0].screenPosition = WebPoint(); |
| 1099 touch.touches[0].position = WebPoint(); |
| 1100 |
| 1101 touch.touches[1].state = WebTouchPoint::StatePressed; |
| 1102 touch.touches[1].screenPosition = WebPoint(10, 10); |
| 1103 touch.touches[1].position = WebPoint(10, 10); |
| 1104 |
| 1105 touch.touches[2].state = WebTouchPoint::StatePressed; |
| 1106 touch.touches[2].screenPosition = WebPoint(-10, 10); |
| 1107 touch.touches[2].position = WebPoint(-10, 10); |
| 1108 |
| 1109 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 1110 } |
| 1111 |
| 1112 TEST_F(InputHandlerProxyTest, MultiTouchPointHitTestPositive) { |
| 1113 // One of the touch points is on a touch-region. So the event should be sent |
| 1114 // to the main thread. |
| 1115 expected_disposition_ = InputHandlerProxy::DID_NOT_HANDLE; |
| 1116 VERIFY_AND_RESET_MOCKS(); |
| 1117 |
| 1118 EXPECT_CALL(mock_input_handler_, |
| 1119 HaveTouchEventHandlersAt( |
| 1120 testing::Property(&gfx::Point::x, testing::Eq(0)))) |
| 1121 .WillOnce(testing::Return(false)); |
| 1122 EXPECT_CALL(mock_input_handler_, |
| 1123 HaveTouchEventHandlersAt( |
| 1124 testing::Property(&gfx::Point::x, testing::Gt(0)))) |
| 1125 .WillOnce(testing::Return(true)); |
| 1126 // Since the second touch point hits a touch-region, there should be no |
| 1127 // hit-testing for the third touch point. |
| 1128 |
| 1129 WebTouchEvent touch; |
| 1130 touch.type = WebInputEvent::TouchStart; |
| 1131 |
| 1132 touch.touchesLength = 3; |
| 1133 touch.touches[0].state = WebTouchPoint::StatePressed; |
| 1134 touch.touches[0].screenPosition = WebPoint(); |
| 1135 touch.touches[0].position = WebPoint(); |
| 1136 |
| 1137 touch.touches[1].state = WebTouchPoint::StatePressed; |
| 1138 touch.touches[1].screenPosition = WebPoint(10, 10); |
| 1139 touch.touches[1].position = WebPoint(10, 10); |
| 1140 |
| 1141 touch.touches[2].state = WebTouchPoint::StatePressed; |
| 1142 touch.touches[2].screenPosition = WebPoint(-10, 10); |
| 1143 touch.touches[2].position = WebPoint(-10, 10); |
| 1144 |
| 1145 EXPECT_EQ(expected_disposition_, input_handler_->HandleInputEvent(touch)); |
| 1146 } |
| 1147 |
| 1077 } // namespace | 1148 } // namespace |
| 1078 } // namespace content | 1149 } // namespace content |
| OLD | NEW |