| OLD | NEW |
| 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/browser/renderer_host/input/mock_input_router_client.h" | 5 #include "content/browser/renderer_host/input/mock_input_router_client.h" |
| 6 | 6 |
| 7 #include "content/browser/renderer_host/input/input_router.h" | 7 #include "content/browser/renderer_host/input/input_router.h" |
| 8 #include "content/common/input/input_event.h" | 8 #include "content/common/input/input_event.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| 11 using base::TimeDelta; | 11 using base::TimeDelta; |
| 12 using blink::WebGestureEvent; | 12 using blink::WebGestureEvent; |
| 13 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
| 14 using blink::WebMouseEvent; | 14 using blink::WebMouseEvent; |
| 15 using blink::WebMouseWheelEvent; | 15 using blink::WebMouseWheelEvent; |
| 16 using blink::WebTouchEvent; | 16 using blink::WebTouchEvent; |
| 17 using blink::WebTouchPoint; | 17 using blink::WebTouchPoint; |
| 18 | 18 |
| 19 namespace content { | 19 namespace content { |
| 20 | 20 |
| 21 MockInputRouterClient::MockInputRouterClient() | 21 MockInputRouterClient::MockInputRouterClient() |
| 22 : input_router_(NULL), | 22 : input_router_(NULL), |
| 23 in_flight_event_count_(0), | 23 in_flight_event_count_(0), |
| 24 has_touch_handler_(false), | 24 has_touch_handler_(false), |
| 25 filter_state_(INPUT_EVENT_ACK_STATE_NOT_CONSUMED), | 25 filter_state_(INPUT_EVENT_ACK_STATE_NOT_CONSUMED), |
| 26 filter_input_event_called_(false), | 26 filter_input_event_called_(false) {} |
| 27 did_flush_called_count_(0) { | |
| 28 } | |
| 29 | 27 |
| 30 MockInputRouterClient::~MockInputRouterClient() {} | 28 MockInputRouterClient::~MockInputRouterClient() {} |
| 31 | 29 |
| 32 InputEventAckState MockInputRouterClient::FilterInputEvent( | 30 InputEventAckState MockInputRouterClient::FilterInputEvent( |
| 33 const WebInputEvent& input_event, | 31 const WebInputEvent& input_event, |
| 34 const ui::LatencyInfo& latency_info) { | 32 const ui::LatencyInfo& latency_info) { |
| 35 filter_input_event_called_ = true; | 33 filter_input_event_called_ = true; |
| 36 last_filter_event_.reset(new InputEvent(input_event, latency_info)); | 34 last_filter_event_.reset(new InputEvent(input_event, latency_info)); |
| 37 return filter_state_; | 35 return filter_state_; |
| 38 } | 36 } |
| 39 | 37 |
| 40 void MockInputRouterClient::IncrementInFlightEventCount( | 38 void MockInputRouterClient::IncrementInFlightEventCount( |
| 41 blink::WebInputEvent::Type event_type) { | 39 blink::WebInputEvent::Type event_type) { |
| 42 ++in_flight_event_count_; | 40 ++in_flight_event_count_; |
| 43 } | 41 } |
| 44 | 42 |
| 45 void MockInputRouterClient::DecrementInFlightEventCount( | 43 void MockInputRouterClient::DecrementInFlightEventCount( |
| 46 InputEventAckSource ack_source) { | 44 InputEventAckSource ack_source) { |
| 47 --in_flight_event_count_; | 45 --in_flight_event_count_; |
| 48 } | 46 } |
| 49 | 47 |
| 50 void MockInputRouterClient::OnHasTouchEventHandlers( | 48 void MockInputRouterClient::OnHasTouchEventHandlers( |
| 51 bool has_handlers) { | 49 bool has_handlers) { |
| 52 has_touch_handler_ = has_handlers; | 50 has_touch_handler_ = has_handlers; |
| 53 } | 51 } |
| 54 | 52 |
| 55 void MockInputRouterClient::DidFlush() { | |
| 56 ++did_flush_called_count_; | |
| 57 } | |
| 58 | |
| 59 void MockInputRouterClient::DidOverscroll( | 53 void MockInputRouterClient::DidOverscroll( |
| 60 const ui::DidOverscrollParams& params) { | 54 const ui::DidOverscrollParams& params) { |
| 61 overscroll_ = params; | 55 overscroll_ = params; |
| 62 } | 56 } |
| 63 | 57 |
| 64 void MockInputRouterClient::DidStopFlinging() { | 58 void MockInputRouterClient::DidStopFlinging() { |
| 65 } | 59 } |
| 66 | 60 |
| 67 void MockInputRouterClient::ForwardGestureEventWithLatencyInfo( | 61 void MockInputRouterClient::ForwardGestureEventWithLatencyInfo( |
| 68 const blink::WebGestureEvent& gesture_event, | 62 const blink::WebGestureEvent& gesture_event, |
| 69 const ui::LatencyInfo& latency_info) { | 63 const ui::LatencyInfo& latency_info) { |
| 70 if (input_router_) | 64 if (input_router_) |
| 71 input_router_->SendGestureEvent( | 65 input_router_->SendGestureEvent( |
| 72 GestureEventWithLatencyInfo(gesture_event, latency_info)); | 66 GestureEventWithLatencyInfo(gesture_event, latency_info)); |
| 73 } | 67 } |
| 74 | 68 |
| 75 bool MockInputRouterClient::GetAndResetFilterEventCalled() { | 69 bool MockInputRouterClient::GetAndResetFilterEventCalled() { |
| 76 bool filter_input_event_called = filter_input_event_called_; | 70 bool filter_input_event_called = filter_input_event_called_; |
| 77 filter_input_event_called_ = false; | 71 filter_input_event_called_ = false; |
| 78 return filter_input_event_called; | 72 return filter_input_event_called; |
| 79 } | 73 } |
| 80 | 74 |
| 81 size_t MockInputRouterClient::GetAndResetDidFlushCount() { | |
| 82 size_t did_flush_called_count = did_flush_called_count_; | |
| 83 did_flush_called_count_ = 0; | |
| 84 return did_flush_called_count; | |
| 85 } | |
| 86 | |
| 87 ui::DidOverscrollParams MockInputRouterClient::GetAndResetOverscroll() { | 75 ui::DidOverscrollParams MockInputRouterClient::GetAndResetOverscroll() { |
| 88 ui::DidOverscrollParams overscroll; | 76 ui::DidOverscrollParams overscroll; |
| 89 std::swap(overscroll_, overscroll); | 77 std::swap(overscroll_, overscroll); |
| 90 return overscroll; | 78 return overscroll; |
| 91 } | 79 } |
| 92 | 80 |
| 93 } // namespace content | 81 } // namespace content |
| OLD | NEW |