| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
| 10 #include "base/timer/timer.h" | 10 #include "base/timer/timer.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 explicit MockInputRouter(InputRouterClient* client) | 60 explicit MockInputRouter(InputRouterClient* client) |
| 61 : send_event_called_(false), | 61 : send_event_called_(false), |
| 62 sent_mouse_event_(false), | 62 sent_mouse_event_(false), |
| 63 sent_wheel_event_(false), | 63 sent_wheel_event_(false), |
| 64 sent_keyboard_event_(false), | 64 sent_keyboard_event_(false), |
| 65 sent_gesture_event_(false), | 65 sent_gesture_event_(false), |
| 66 send_touch_event_not_cancelled_(false), | 66 send_touch_event_not_cancelled_(false), |
| 67 message_received_(false), | 67 message_received_(false), |
| 68 client_(client) { | 68 client_(client) { |
| 69 } | 69 } |
| 70 virtual ~MockInputRouter() {} | 70 ~MockInputRouter() override {} |
| 71 | 71 |
| 72 // InputRouter | 72 // InputRouter |
| 73 virtual void Flush() override { | 73 void Flush() override { flush_called_ = true; } |
| 74 flush_called_ = true; | 74 bool SendInput(scoped_ptr<IPC::Message> message) override { |
| 75 } | |
| 76 virtual bool SendInput(scoped_ptr<IPC::Message> message) override { | |
| 77 send_event_called_ = true; | 75 send_event_called_ = true; |
| 78 return true; | 76 return true; |
| 79 } | 77 } |
| 80 virtual void SendMouseEvent( | 78 void SendMouseEvent(const MouseEventWithLatencyInfo& mouse_event) override { |
| 81 const MouseEventWithLatencyInfo& mouse_event) override { | |
| 82 sent_mouse_event_ = true; | 79 sent_mouse_event_ = true; |
| 83 } | 80 } |
| 84 virtual void SendWheelEvent( | 81 void SendWheelEvent( |
| 85 const MouseWheelEventWithLatencyInfo& wheel_event) override { | 82 const MouseWheelEventWithLatencyInfo& wheel_event) override { |
| 86 sent_wheel_event_ = true; | 83 sent_wheel_event_ = true; |
| 87 } | 84 } |
| 88 virtual void SendKeyboardEvent( | 85 void SendKeyboardEvent(const NativeWebKeyboardEvent& key_event, |
| 89 const NativeWebKeyboardEvent& key_event, | 86 const ui::LatencyInfo& latency_info, |
| 90 const ui::LatencyInfo& latency_info, | 87 bool is_shortcut) override { |
| 91 bool is_shortcut) override { | |
| 92 sent_keyboard_event_ = true; | 88 sent_keyboard_event_ = true; |
| 93 } | 89 } |
| 94 virtual void SendGestureEvent( | 90 void SendGestureEvent( |
| 95 const GestureEventWithLatencyInfo& gesture_event) override { | 91 const GestureEventWithLatencyInfo& gesture_event) override { |
| 96 sent_gesture_event_ = true; | 92 sent_gesture_event_ = true; |
| 97 } | 93 } |
| 98 virtual void SendTouchEvent( | 94 void SendTouchEvent(const TouchEventWithLatencyInfo& touch_event) override { |
| 99 const TouchEventWithLatencyInfo& touch_event) override { | |
| 100 send_touch_event_not_cancelled_ = | 95 send_touch_event_not_cancelled_ = |
| 101 client_->FilterInputEvent(touch_event.event, touch_event.latency) == | 96 client_->FilterInputEvent(touch_event.event, touch_event.latency) == |
| 102 INPUT_EVENT_ACK_STATE_NOT_CONSUMED; | 97 INPUT_EVENT_ACK_STATE_NOT_CONSUMED; |
| 103 } | 98 } |
| 104 virtual const NativeWebKeyboardEvent* GetLastKeyboardEvent() const override { | 99 const NativeWebKeyboardEvent* GetLastKeyboardEvent() const override { |
| 105 NOTREACHED(); | 100 NOTREACHED(); |
| 106 return NULL; | 101 return NULL; |
| 107 } | 102 } |
| 108 virtual bool ShouldForwardTouchEvent() const override { return true; } | 103 bool ShouldForwardTouchEvent() const override { return true; } |
| 109 virtual void OnViewUpdated(int view_flags) override {} | 104 void OnViewUpdated(int view_flags) override {} |
| 110 virtual bool HasPendingEvents() const override { return false; } | 105 bool HasPendingEvents() const override { return false; } |
| 111 | 106 |
| 112 // IPC::Listener | 107 // IPC::Listener |
| 113 virtual bool OnMessageReceived(const IPC::Message& message) override { | 108 bool OnMessageReceived(const IPC::Message& message) override { |
| 114 message_received_ = true; | 109 message_received_ = true; |
| 115 return false; | 110 return false; |
| 116 } | 111 } |
| 117 | 112 |
| 118 bool flush_called_; | 113 bool flush_called_; |
| 119 bool send_event_called_; | 114 bool send_event_called_; |
| 120 bool sent_mouse_event_; | 115 bool sent_mouse_event_; |
| 121 bool sent_wheel_event_; | 116 bool sent_wheel_event_; |
| 122 bool sent_keyboard_event_; | 117 bool sent_keyboard_event_; |
| 123 bool sent_gesture_event_; | 118 bool sent_gesture_event_; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 144 } | 139 } |
| 145 | 140 |
| 146 // Allow poking at a few private members. | 141 // Allow poking at a few private members. |
| 147 using RenderWidgetHostImpl::OnUpdateRect; | 142 using RenderWidgetHostImpl::OnUpdateRect; |
| 148 using RenderWidgetHostImpl::RendererExited; | 143 using RenderWidgetHostImpl::RendererExited; |
| 149 using RenderWidgetHostImpl::last_requested_size_; | 144 using RenderWidgetHostImpl::last_requested_size_; |
| 150 using RenderWidgetHostImpl::is_hidden_; | 145 using RenderWidgetHostImpl::is_hidden_; |
| 151 using RenderWidgetHostImpl::resize_ack_pending_; | 146 using RenderWidgetHostImpl::resize_ack_pending_; |
| 152 using RenderWidgetHostImpl::input_router_; | 147 using RenderWidgetHostImpl::input_router_; |
| 153 | 148 |
| 154 virtual void OnTouchEventAck( | 149 void OnTouchEventAck(const TouchEventWithLatencyInfo& event, |
| 155 const TouchEventWithLatencyInfo& event, | 150 InputEventAckState ack_result) override { |
| 156 InputEventAckState ack_result) override { | |
| 157 // Sniff touch acks. | 151 // Sniff touch acks. |
| 158 acked_touch_event_type_ = event.event.type; | 152 acked_touch_event_type_ = event.event.type; |
| 159 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); | 153 RenderWidgetHostImpl::OnTouchEventAck(event, ack_result); |
| 160 } | 154 } |
| 161 | 155 |
| 162 bool unresponsive_timer_fired() const { | 156 bool unresponsive_timer_fired() const { |
| 163 return unresponsive_timer_fired_; | 157 return unresponsive_timer_fired_; |
| 164 } | 158 } |
| 165 | 159 |
| 166 void set_hung_renderer_delay_ms(int64 delay_ms) { | 160 void set_hung_renderer_delay_ms(int64 delay_ms) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 178 | 172 |
| 179 void SetupForInputRouterTest() { | 173 void SetupForInputRouterTest() { |
| 180 input_router_.reset(new MockInputRouter(this)); | 174 input_router_.reset(new MockInputRouter(this)); |
| 181 } | 175 } |
| 182 | 176 |
| 183 MockInputRouter* mock_input_router() { | 177 MockInputRouter* mock_input_router() { |
| 184 return static_cast<MockInputRouter*>(input_router_.get()); | 178 return static_cast<MockInputRouter*>(input_router_.get()); |
| 185 } | 179 } |
| 186 | 180 |
| 187 protected: | 181 protected: |
| 188 virtual void NotifyRendererUnresponsive() override { | 182 void NotifyRendererUnresponsive() override { |
| 189 unresponsive_timer_fired_ = true; | 183 unresponsive_timer_fired_ = true; |
| 190 } | 184 } |
| 191 | 185 |
| 192 bool unresponsive_timer_fired_; | 186 bool unresponsive_timer_fired_; |
| 193 WebInputEvent::Type acked_touch_event_type_; | 187 WebInputEvent::Type acked_touch_event_type_; |
| 194 | 188 |
| 195 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); | 189 DISALLOW_COPY_AND_ASSIGN(MockRenderWidgetHost); |
| 196 }; | 190 }; |
| 197 | 191 |
| 198 namespace { | 192 namespace { |
| 199 | 193 |
| 200 // RenderWidgetHostProcess ----------------------------------------------------- | 194 // RenderWidgetHostProcess ----------------------------------------------------- |
| 201 | 195 |
| 202 class RenderWidgetHostProcess : public MockRenderProcessHost { | 196 class RenderWidgetHostProcess : public MockRenderProcessHost { |
| 203 public: | 197 public: |
| 204 explicit RenderWidgetHostProcess(BrowserContext* browser_context) | 198 explicit RenderWidgetHostProcess(BrowserContext* browser_context) |
| 205 : MockRenderProcessHost(browser_context), | 199 : MockRenderProcessHost(browser_context), |
| 206 update_msg_reply_flags_(0) { | 200 update_msg_reply_flags_(0) { |
| 207 } | 201 } |
| 208 virtual ~RenderWidgetHostProcess() { | 202 ~RenderWidgetHostProcess() override {} |
| 209 } | |
| 210 | 203 |
| 211 void set_update_msg_reply_flags(int flags) { | 204 void set_update_msg_reply_flags(int flags) { |
| 212 update_msg_reply_flags_ = flags; | 205 update_msg_reply_flags_ = flags; |
| 213 } | 206 } |
| 214 | 207 |
| 215 // Fills the given update parameters with resonable default values. | 208 // Fills the given update parameters with resonable default values. |
| 216 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); | 209 void InitUpdateRectParams(ViewHostMsg_UpdateRect_Params* params); |
| 217 | 210 |
| 218 virtual bool HasConnection() const override { return true; } | 211 bool HasConnection() const override { return true; } |
| 219 | 212 |
| 220 protected: | 213 protected: |
| 221 // Indicates the flags that should be sent with a repaint request. This | 214 // Indicates the flags that should be sent with a repaint request. This |
| 222 // only has an effect when update_msg_should_reply_ is true. | 215 // only has an effect when update_msg_should_reply_ is true. |
| 223 int update_msg_reply_flags_; | 216 int update_msg_reply_flags_; |
| 224 | 217 |
| 225 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); | 218 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostProcess); |
| 226 }; | 219 }; |
| 227 | 220 |
| 228 void RenderWidgetHostProcess::InitUpdateRectParams( | 221 void RenderWidgetHostProcess::InitUpdateRectParams( |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 264 |
| 272 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { | 265 void SetMockPhysicalBackingSize(const gfx::Size& mock_physical_backing_size) { |
| 273 use_fake_physical_backing_size_ = true; | 266 use_fake_physical_backing_size_ = true; |
| 274 mock_physical_backing_size_ = mock_physical_backing_size; | 267 mock_physical_backing_size_ = mock_physical_backing_size; |
| 275 } | 268 } |
| 276 void ClearMockPhysicalBackingSize() { | 269 void ClearMockPhysicalBackingSize() { |
| 277 use_fake_physical_backing_size_ = false; | 270 use_fake_physical_backing_size_ = false; |
| 278 } | 271 } |
| 279 | 272 |
| 280 // RenderWidgetHostView override. | 273 // RenderWidgetHostView override. |
| 281 virtual gfx::Rect GetViewBounds() const override { | 274 gfx::Rect GetViewBounds() const override { return bounds_; } |
| 282 return bounds_; | 275 void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, |
| 283 } | 276 InputEventAckState ack_result) override { |
| 284 virtual void ProcessAckedTouchEvent(const TouchEventWithLatencyInfo& touch, | |
| 285 InputEventAckState ack_result) override { | |
| 286 acked_event_ = touch.event; | 277 acked_event_ = touch.event; |
| 287 ++acked_event_count_; | 278 ++acked_event_count_; |
| 288 } | 279 } |
| 289 virtual void WheelEventAck(const WebMouseWheelEvent& event, | 280 void WheelEventAck(const WebMouseWheelEvent& event, |
| 290 InputEventAckState ack_result) override { | 281 InputEventAckState ack_result) override { |
| 291 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) | 282 if (ack_result == INPUT_EVENT_ACK_STATE_CONSUMED) |
| 292 return; | 283 return; |
| 293 unhandled_wheel_event_count_++; | 284 unhandled_wheel_event_count_++; |
| 294 unhandled_wheel_event_ = event; | 285 unhandled_wheel_event_ = event; |
| 295 } | 286 } |
| 296 virtual void GestureEventAck(const WebGestureEvent& event, | 287 void GestureEventAck(const WebGestureEvent& event, |
| 297 InputEventAckState ack_result) override { | 288 InputEventAckState ack_result) override { |
| 298 gesture_event_type_ = event.type; | 289 gesture_event_type_ = event.type; |
| 299 ack_result_ = ack_result; | 290 ack_result_ = ack_result; |
| 300 } | 291 } |
| 301 virtual gfx::Size GetPhysicalBackingSize() const override { | 292 gfx::Size GetPhysicalBackingSize() const override { |
| 302 if (use_fake_physical_backing_size_) | 293 if (use_fake_physical_backing_size_) |
| 303 return mock_physical_backing_size_; | 294 return mock_physical_backing_size_; |
| 304 return TestRenderWidgetHostView::GetPhysicalBackingSize(); | 295 return TestRenderWidgetHostView::GetPhysicalBackingSize(); |
| 305 } | 296 } |
| 306 #if defined(USE_AURA) | 297 #if defined(USE_AURA) |
| 307 virtual ~TestView() { | 298 virtual ~TestView() { |
| 308 // Simulate the mouse exit event dispatched when an aura window is | 299 // Simulate the mouse exit event dispatched when an aura window is |
| 309 // destroyed. (MakeWebMouseEventFromAuraEvent translates ET_MOUSE_EXITED | 300 // destroyed. (MakeWebMouseEventFromAuraEvent translates ET_MOUSE_EXITED |
| 310 // into WebInputEvent::MouseMove.) | 301 // into WebInputEvent::MouseMove.) |
| 311 rwh_->input_router()->SendMouseEvent( | 302 rwh_->input_router()->SendMouseEvent( |
| (...skipping 23 matching lines...) Expand all Loading... |
| 335 public: | 326 public: |
| 336 MockRenderWidgetHostDelegate() | 327 MockRenderWidgetHostDelegate() |
| 337 : prehandle_keyboard_event_(false), | 328 : prehandle_keyboard_event_(false), |
| 338 prehandle_keyboard_event_called_(false), | 329 prehandle_keyboard_event_called_(false), |
| 339 prehandle_keyboard_event_type_(WebInputEvent::Undefined), | 330 prehandle_keyboard_event_type_(WebInputEvent::Undefined), |
| 340 unhandled_keyboard_event_called_(false), | 331 unhandled_keyboard_event_called_(false), |
| 341 unhandled_keyboard_event_type_(WebInputEvent::Undefined), | 332 unhandled_keyboard_event_type_(WebInputEvent::Undefined), |
| 342 handle_wheel_event_(false), | 333 handle_wheel_event_(false), |
| 343 handle_wheel_event_called_(false) { | 334 handle_wheel_event_called_(false) { |
| 344 } | 335 } |
| 345 virtual ~MockRenderWidgetHostDelegate() {} | 336 ~MockRenderWidgetHostDelegate() override {} |
| 346 | 337 |
| 347 // Tests that make sure we ignore keyboard event acknowledgments to events we | 338 // Tests that make sure we ignore keyboard event acknowledgments to events we |
| 348 // didn't send work by making sure we didn't call UnhandledKeyboardEvent(). | 339 // didn't send work by making sure we didn't call UnhandledKeyboardEvent(). |
| 349 bool unhandled_keyboard_event_called() const { | 340 bool unhandled_keyboard_event_called() const { |
| 350 return unhandled_keyboard_event_called_; | 341 return unhandled_keyboard_event_called_; |
| 351 } | 342 } |
| 352 | 343 |
| 353 WebInputEvent::Type unhandled_keyboard_event_type() const { | 344 WebInputEvent::Type unhandled_keyboard_event_type() const { |
| 354 return unhandled_keyboard_event_type_; | 345 return unhandled_keyboard_event_type_; |
| 355 } | 346 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 368 | 359 |
| 369 void set_handle_wheel_event(bool handle) { | 360 void set_handle_wheel_event(bool handle) { |
| 370 handle_wheel_event_ = handle; | 361 handle_wheel_event_ = handle; |
| 371 } | 362 } |
| 372 | 363 |
| 373 bool handle_wheel_event_called() { | 364 bool handle_wheel_event_called() { |
| 374 return handle_wheel_event_called_; | 365 return handle_wheel_event_called_; |
| 375 } | 366 } |
| 376 | 367 |
| 377 protected: | 368 protected: |
| 378 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, | 369 bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 379 bool* is_keyboard_shortcut) override { | 370 bool* is_keyboard_shortcut) override { |
| 380 prehandle_keyboard_event_type_ = event.type; | 371 prehandle_keyboard_event_type_ = event.type; |
| 381 prehandle_keyboard_event_called_ = true; | 372 prehandle_keyboard_event_called_ = true; |
| 382 return prehandle_keyboard_event_; | 373 return prehandle_keyboard_event_; |
| 383 } | 374 } |
| 384 | 375 |
| 385 virtual void HandleKeyboardEvent( | 376 void HandleKeyboardEvent(const NativeWebKeyboardEvent& event) override { |
| 386 const NativeWebKeyboardEvent& event) override { | |
| 387 unhandled_keyboard_event_type_ = event.type; | 377 unhandled_keyboard_event_type_ = event.type; |
| 388 unhandled_keyboard_event_called_ = true; | 378 unhandled_keyboard_event_called_ = true; |
| 389 } | 379 } |
| 390 | 380 |
| 391 virtual bool HandleWheelEvent( | 381 bool HandleWheelEvent(const blink::WebMouseWheelEvent& event) override { |
| 392 const blink::WebMouseWheelEvent& event) override { | |
| 393 handle_wheel_event_called_ = true; | 382 handle_wheel_event_called_ = true; |
| 394 return handle_wheel_event_; | 383 return handle_wheel_event_; |
| 395 } | 384 } |
| 396 | 385 |
| 397 private: | 386 private: |
| 398 bool prehandle_keyboard_event_; | 387 bool prehandle_keyboard_event_; |
| 399 bool prehandle_keyboard_event_called_; | 388 bool prehandle_keyboard_event_called_; |
| 400 WebInputEvent::Type prehandle_keyboard_event_type_; | 389 WebInputEvent::Type prehandle_keyboard_event_type_; |
| 401 | 390 |
| 402 bool unhandled_keyboard_event_called_; | 391 bool unhandled_keyboard_event_called_; |
| (...skipping 1097 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1500 | 1489 |
| 1501 ASSERT_TRUE(host_->is_hidden()); | 1490 ASSERT_TRUE(host_->is_hidden()); |
| 1502 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); | 1491 host_->RendererExited(base::TERMINATION_STATUS_PROCESS_CRASHED, -1); |
| 1503 ASSERT_FALSE(host_->is_hidden()); | 1492 ASSERT_FALSE(host_->is_hidden()); |
| 1504 | 1493 |
| 1505 // Make sure the input router is in a fresh state. | 1494 // Make sure the input router is in a fresh state. |
| 1506 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); | 1495 ASSERT_FALSE(host_->input_router()->HasPendingEvents()); |
| 1507 } | 1496 } |
| 1508 | 1497 |
| 1509 } // namespace content | 1498 } // namespace content |
| OLD | NEW |