| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/renderer_host/input/mock_input_router_client.h" |
| 6 |
| 7 #include "content/browser/renderer_host/input/input_router.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 using base::TimeDelta; |
| 11 using WebKit::WebGestureEvent; |
| 12 using WebKit::WebInputEvent; |
| 13 using WebKit::WebMouseEvent; |
| 14 using WebKit::WebMouseWheelEvent; |
| 15 using WebKit::WebTouchEvent; |
| 16 using WebKit::WebTouchPoint; |
| 17 |
| 18 namespace content { |
| 19 |
| 20 MockInputRouterClient::MockInputRouterClient() |
| 21 : input_router_(NULL), |
| 22 in_flight_event_count_(0), |
| 23 has_touch_handler_(false), |
| 24 ack_count_(0), |
| 25 unexpected_event_ack_called_(false), |
| 26 ack_state_(INPUT_EVENT_ACK_STATE_UNKNOWN), |
| 27 filter_state_(INPUT_EVENT_ACK_STATE_NOT_CONSUMED), |
| 28 is_shortcut_(false), |
| 29 allow_send_event_(true), |
| 30 send_called_(false), |
| 31 send_immediately_called_(false), |
| 32 sync_flush_(false), |
| 33 did_flush_called_(false), |
| 34 set_needs_flush_called_(false) {} |
| 35 |
| 36 MockInputRouterClient::~MockInputRouterClient() {} |
| 37 |
| 38 InputEventAckState MockInputRouterClient::FilterInputEvent( |
| 39 const WebInputEvent& input_event, |
| 40 const ui::LatencyInfo& latency_info) { |
| 41 return filter_state_; |
| 42 } |
| 43 |
| 44 void MockInputRouterClient::IncrementInFlightEventCount() { |
| 45 ++in_flight_event_count_; |
| 46 } |
| 47 |
| 48 void MockInputRouterClient::DecrementInFlightEventCount() { |
| 49 --in_flight_event_count_; |
| 50 } |
| 51 |
| 52 void MockInputRouterClient::OnHasTouchEventHandlers( |
| 53 bool has_handlers) { |
| 54 has_touch_handler_ = has_handlers; |
| 55 } |
| 56 |
| 57 bool MockInputRouterClient::OnSendKeyboardEvent( |
| 58 const NativeWebKeyboardEvent& key_event, |
| 59 const ui::LatencyInfo& latency_info, |
| 60 bool* is_shortcut) { |
| 61 send_called_ = true; |
| 62 sent_key_event_ = key_event; |
| 63 *is_shortcut = is_shortcut_; |
| 64 |
| 65 return allow_send_event_; |
| 66 } |
| 67 |
| 68 bool MockInputRouterClient::OnSendWheelEvent( |
| 69 const MouseWheelEventWithLatencyInfo& wheel_event) { |
| 70 send_called_ = true; |
| 71 sent_wheel_event_ = wheel_event; |
| 72 |
| 73 return allow_send_event_; |
| 74 } |
| 75 |
| 76 bool MockInputRouterClient::OnSendMouseEvent( |
| 77 const MouseEventWithLatencyInfo& mouse_event) { |
| 78 send_called_ = true; |
| 79 sent_mouse_event_ = mouse_event; |
| 80 |
| 81 return allow_send_event_; |
| 82 } |
| 83 |
| 84 bool MockInputRouterClient::OnSendTouchEvent( |
| 85 const TouchEventWithLatencyInfo& touch_event) { |
| 86 send_called_ = true; |
| 87 sent_touch_event_ = touch_event; |
| 88 |
| 89 return allow_send_event_; |
| 90 } |
| 91 |
| 92 bool MockInputRouterClient::OnSendGestureEvent( |
| 93 const GestureEventWithLatencyInfo& gesture_event) { |
| 94 send_called_ = true; |
| 95 sent_gesture_event_ = gesture_event; |
| 96 |
| 97 return allow_send_event_ && |
| 98 input_router_->ShouldForwardGestureEvent(gesture_event); |
| 99 } |
| 100 |
| 101 bool MockInputRouterClient::OnSendMouseEventImmediately( |
| 102 const MouseEventWithLatencyInfo& mouse_event) { |
| 103 send_immediately_called_ = true; |
| 104 immediately_sent_mouse_event_ = mouse_event; |
| 105 |
| 106 return allow_send_event_; |
| 107 } |
| 108 |
| 109 bool MockInputRouterClient::OnSendTouchEventImmediately( |
| 110 const TouchEventWithLatencyInfo& touch_event) { |
| 111 send_immediately_called_ = true; |
| 112 immediately_sent_touch_event_ = touch_event; |
| 113 |
| 114 return allow_send_event_; |
| 115 } |
| 116 |
| 117 bool MockInputRouterClient::OnSendGestureEventImmediately( |
| 118 const GestureEventWithLatencyInfo& gesture_event) { |
| 119 send_immediately_called_ = true; |
| 120 immediately_sent_gesture_event_ = gesture_event; |
| 121 return allow_send_event_; |
| 122 } |
| 123 |
| 124 void MockInputRouterClient::OnKeyboardEventAck( |
| 125 const NativeWebKeyboardEvent& event, |
| 126 InputEventAckState ack_result) { |
| 127 VLOG(1) << __FUNCTION__ << " called!"; |
| 128 acked_key_event_ = event; |
| 129 RecordAckCalled(ack_result); |
| 130 } |
| 131 |
| 132 void MockInputRouterClient::OnWheelEventAck( |
| 133 const WebMouseWheelEvent& event, |
| 134 InputEventAckState ack_result) { |
| 135 VLOG(1) << __FUNCTION__ << " called!"; |
| 136 acked_wheel_event_ = event; |
| 137 RecordAckCalled(ack_result); |
| 138 } |
| 139 |
| 140 void MockInputRouterClient::OnTouchEventAck( |
| 141 const TouchEventWithLatencyInfo& event, |
| 142 InputEventAckState ack_result) { |
| 143 VLOG(1) << __FUNCTION__ << " called!"; |
| 144 acked_touch_event_ = event; |
| 145 RecordAckCalled(ack_result); |
| 146 if (touch_followup_event_) |
| 147 input_router_->SendGestureEvent(*touch_followup_event_); |
| 148 } |
| 149 |
| 150 void MockInputRouterClient::OnGestureEventAck( |
| 151 const WebGestureEvent& event, |
| 152 InputEventAckState ack_result) { |
| 153 VLOG(1) << __FUNCTION__ << " called!"; |
| 154 acked_gesture_event_ = event; |
| 155 RecordAckCalled(ack_result); |
| 156 } |
| 157 |
| 158 void MockInputRouterClient::OnUnexpectedEventAck(bool bad_message) { |
| 159 VLOG(1) << __FUNCTION__ << " called!"; |
| 160 unexpected_event_ack_called_ = true; |
| 161 } |
| 162 |
| 163 void MockInputRouterClient::ExpectSendCalled(bool called) { |
| 164 EXPECT_EQ(called, send_called_); |
| 165 send_called_ = false; |
| 166 } |
| 167 |
| 168 void MockInputRouterClient::ExpectSendImmediatelyCalled(bool called) { |
| 169 EXPECT_EQ(called, send_immediately_called_); |
| 170 send_immediately_called_ = false; |
| 171 } |
| 172 |
| 173 void MockInputRouterClient::ExpectAckCalled(int times) { |
| 174 EXPECT_EQ(times, ack_count_); |
| 175 ack_count_ = 0; |
| 176 } |
| 177 |
| 178 void MockInputRouterClient::ExpectNeedsFlushCalled(bool called) { |
| 179 EXPECT_EQ(called, set_needs_flush_called_); |
| 180 set_needs_flush_called_ = false; |
| 181 } |
| 182 |
| 183 void MockInputRouterClient::ExpectDidFlushCalled(bool called) { |
| 184 EXPECT_EQ(called, did_flush_called_); |
| 185 did_flush_called_ = false; |
| 186 } |
| 187 |
| 188 void MockInputRouterClient::RecordAckCalled(InputEventAckState ack_result) { |
| 189 ++ack_count_; |
| 190 ack_state_ = ack_result; |
| 191 } |
| 192 |
| 193 void MockInputRouterClient::DidFlush() { |
| 194 did_flush_called_ = true; |
| 195 } |
| 196 |
| 197 void MockInputRouterClient::SetNeedsFlush() { |
| 198 set_needs_flush_called_ = true; |
| 199 if (sync_flush_) |
| 200 input_router_->Flush(); |
| 201 } |
| 202 |
| 203 } // namespace content |
| OLD | NEW |