| 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/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "base/timer/timer.h" | 9 #include "base/timer/timer.h" |
| 10 #include "content/browser/browser_thread_impl.h" | 10 #include "content/browser/browser_thread_impl.h" |
| 11 #include "content/browser/renderer_host/backing_store.h" | 11 #include "content/browser/renderer_host/backing_store.h" |
| 12 #include "content/browser/renderer_host/input/gesture_event_queue.h" | 12 #include "content/browser/renderer_host/input/gesture_event_queue.h" |
| 13 #include "content/browser/renderer_host/input/input_router_impl.h" | 13 #include "content/browser/renderer_host/input/input_router_impl.h" |
| 14 #include "content/browser/renderer_host/input/tap_suppression_controller.h" | 14 #include "content/browser/renderer_host/input/tap_suppression_controller.h" |
| 15 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" | 15 #include "content/browser/renderer_host/input/tap_suppression_controller_client.
h" |
| 16 #include "content/browser/renderer_host/input/touch_event_queue.h" | 16 #include "content/browser/renderer_host/input/touch_event_queue.h" |
| 17 #include "content/browser/renderer_host/overscroll_controller.h" | 17 #include "content/browser/renderer_host/overscroll_controller.h" |
| 18 #include "content/browser/renderer_host/overscroll_controller_delegate.h" | 18 #include "content/browser/renderer_host/overscroll_controller_delegate.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_delegate.h" | 19 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 20 #include "content/common/input/synthetic_web_input_event_builders.h" | 20 #include "content/common/input/synthetic_web_input_event_builders.h" |
| 21 #include "content/common/input_messages.h" | 21 #include "content/common/input_messages.h" |
| 22 #include "content/common/view_messages.h" | 22 #include "content/common/view_messages.h" |
| 23 #include "content/port/browser/render_widget_host_view_port.h" | 23 #include "content/port/browser/render_widget_host_view_port.h" |
| 24 #include "content/public/browser/notification_details.h" | |
| 25 #include "content/public/browser/notification_observer.h" | |
| 26 #include "content/public/browser/notification_registrar.h" | |
| 27 #include "content/public/browser/notification_source.h" | |
| 28 #include "content/public/browser/notification_types.h" | |
| 29 #include "content/public/test/mock_render_process_host.h" | 24 #include "content/public/test/mock_render_process_host.h" |
| 30 #include "content/public/test/test_browser_context.h" | 25 #include "content/public/test/test_browser_context.h" |
| 31 #include "content/test/test_render_view_host.h" | 26 #include "content/test/test_render_view_host.h" |
| 32 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 33 #include "ui/events/keycodes/keyboard_codes.h" | 28 #include "ui/events/keycodes/keyboard_codes.h" |
| 34 #include "ui/gfx/canvas.h" | 29 #include "ui/gfx/canvas.h" |
| 35 #include "ui/gfx/screen.h" | 30 #include "ui/gfx/screen.h" |
| 36 | 31 |
| 37 #if defined(USE_AURA) | 32 #if defined(USE_AURA) |
| 38 #include "content/browser/compositor/image_transport_factory.h" | 33 #include "content/browser/compositor/image_transport_factory.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 MockRenderWidgetHost( | 193 MockRenderWidgetHost( |
| 199 RenderWidgetHostDelegate* delegate, | 194 RenderWidgetHostDelegate* delegate, |
| 200 RenderProcessHost* process, | 195 RenderProcessHost* process, |
| 201 int routing_id) | 196 int routing_id) |
| 202 : RenderWidgetHostImpl(delegate, process, routing_id, false), | 197 : RenderWidgetHostImpl(delegate, process, routing_id, false), |
| 203 unresponsive_timer_fired_(false) { | 198 unresponsive_timer_fired_(false) { |
| 204 input_router_impl_ = static_cast<InputRouterImpl*>(input_router_.get()); | 199 input_router_impl_ = static_cast<InputRouterImpl*>(input_router_.get()); |
| 205 } | 200 } |
| 206 | 201 |
| 207 // Allow poking at a few private members. | 202 // Allow poking at a few private members. |
| 208 using RenderWidgetHostImpl::OnPaintAtSizeAck; | |
| 209 using RenderWidgetHostImpl::OnUpdateRect; | 203 using RenderWidgetHostImpl::OnUpdateRect; |
| 210 using RenderWidgetHostImpl::RendererExited; | 204 using RenderWidgetHostImpl::RendererExited; |
| 211 using RenderWidgetHostImpl::last_requested_size_; | 205 using RenderWidgetHostImpl::last_requested_size_; |
| 212 using RenderWidgetHostImpl::is_hidden_; | 206 using RenderWidgetHostImpl::is_hidden_; |
| 213 using RenderWidgetHostImpl::resize_ack_pending_; | 207 using RenderWidgetHostImpl::resize_ack_pending_; |
| 214 using RenderWidgetHostImpl::input_router_; | 208 using RenderWidgetHostImpl::input_router_; |
| 215 | 209 |
| 216 bool unresponsive_timer_fired() const { | 210 bool unresponsive_timer_fired() const { |
| 217 return unresponsive_timer_fired_; | 211 return unresponsive_timer_fired_; |
| 218 } | 212 } |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 546 |
| 553 private: | 547 private: |
| 554 bool prehandle_keyboard_event_; | 548 bool prehandle_keyboard_event_; |
| 555 bool prehandle_keyboard_event_called_; | 549 bool prehandle_keyboard_event_called_; |
| 556 WebInputEvent::Type prehandle_keyboard_event_type_; | 550 WebInputEvent::Type prehandle_keyboard_event_type_; |
| 557 | 551 |
| 558 bool unhandled_keyboard_event_called_; | 552 bool unhandled_keyboard_event_called_; |
| 559 WebInputEvent::Type unhandled_keyboard_event_type_; | 553 WebInputEvent::Type unhandled_keyboard_event_type_; |
| 560 }; | 554 }; |
| 561 | 555 |
| 562 // MockPaintingObserver -------------------------------------------------------- | |
| 563 | |
| 564 class MockPaintingObserver : public NotificationObserver { | |
| 565 public: | |
| 566 void WidgetDidReceivePaintAtSizeAck(RenderWidgetHostImpl* host, | |
| 567 int tag, | |
| 568 const gfx::Size& size) { | |
| 569 host_ = reinterpret_cast<MockRenderWidgetHost*>(host); | |
| 570 tag_ = tag; | |
| 571 size_ = size; | |
| 572 } | |
| 573 | |
| 574 virtual void Observe(int type, | |
| 575 const NotificationSource& source, | |
| 576 const NotificationDetails& details) OVERRIDE { | |
| 577 if (type == NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK) { | |
| 578 std::pair<int, gfx::Size>* size_ack_details = | |
| 579 Details<std::pair<int, gfx::Size> >(details).ptr(); | |
| 580 WidgetDidReceivePaintAtSizeAck( | |
| 581 RenderWidgetHostImpl::From(Source<RenderWidgetHost>(source).ptr()), | |
| 582 size_ack_details->first, | |
| 583 size_ack_details->second); | |
| 584 } | |
| 585 } | |
| 586 | |
| 587 MockRenderWidgetHost* host() const { return host_; } | |
| 588 int tag() const { return tag_; } | |
| 589 gfx::Size size() const { return size_; } | |
| 590 | |
| 591 private: | |
| 592 MockRenderWidgetHost* host_; | |
| 593 int tag_; | |
| 594 gfx::Size size_; | |
| 595 }; | |
| 596 | |
| 597 // RenderWidgetHostTest -------------------------------------------------------- | 556 // RenderWidgetHostTest -------------------------------------------------------- |
| 598 | 557 |
| 599 class RenderWidgetHostTest : public testing::Test { | 558 class RenderWidgetHostTest : public testing::Test { |
| 600 public: | 559 public: |
| 601 RenderWidgetHostTest() | 560 RenderWidgetHostTest() |
| 602 : process_(NULL), | 561 : process_(NULL), |
| 603 handle_key_press_event_(false), | 562 handle_key_press_event_(false), |
| 604 handle_mouse_event_(false) { | 563 handle_mouse_event_(false) { |
| 605 } | 564 } |
| 606 virtual ~RenderWidgetHostTest() { | 565 virtual ~RenderWidgetHostTest() { |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1111 | 1070 |
| 1112 // It should have sent out a restored message with a request to paint. | 1071 // It should have sent out a restored message with a request to paint. |
| 1113 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( | 1072 const IPC::Message* restored = process_->sink().GetUniqueMessageMatching( |
| 1114 ViewMsg_WasShown::ID); | 1073 ViewMsg_WasShown::ID); |
| 1115 ASSERT_TRUE(restored); | 1074 ASSERT_TRUE(restored); |
| 1116 Tuple1<bool> needs_repaint; | 1075 Tuple1<bool> needs_repaint; |
| 1117 ViewMsg_WasShown::Read(restored, &needs_repaint); | 1076 ViewMsg_WasShown::Read(restored, &needs_repaint); |
| 1118 EXPECT_TRUE(needs_repaint.a); | 1077 EXPECT_TRUE(needs_repaint.a); |
| 1119 } | 1078 } |
| 1120 | 1079 |
| 1121 TEST_F(RenderWidgetHostTest, PaintAtSize) { | |
| 1122 const int kPaintAtSizeTag = 42; | |
| 1123 host_->PaintAtSize(TransportDIB::GetFakeHandleForTest(), kPaintAtSizeTag, | |
| 1124 gfx::Size(40, 60), gfx::Size(20, 30)); | |
| 1125 EXPECT_TRUE( | |
| 1126 process_->sink().GetUniqueMessageMatching(ViewMsg_PaintAtSize::ID)); | |
| 1127 | |
| 1128 NotificationRegistrar registrar; | |
| 1129 MockPaintingObserver observer; | |
| 1130 registrar.Add( | |
| 1131 &observer, | |
| 1132 NOTIFICATION_RENDER_WIDGET_HOST_DID_RECEIVE_PAINT_AT_SIZE_ACK, | |
| 1133 Source<RenderWidgetHost>(host_.get())); | |
| 1134 | |
| 1135 host_->OnPaintAtSizeAck(kPaintAtSizeTag, gfx::Size(20, 30)); | |
| 1136 EXPECT_EQ(host_.get(), observer.host()); | |
| 1137 EXPECT_EQ(kPaintAtSizeTag, observer.tag()); | |
| 1138 EXPECT_EQ(20, observer.size().width()); | |
| 1139 EXPECT_EQ(30, observer.size().height()); | |
| 1140 } | |
| 1141 | |
| 1142 TEST_F(RenderWidgetHostTest, IgnoreKeyEventsHandledByRenderer) { | 1080 TEST_F(RenderWidgetHostTest, IgnoreKeyEventsHandledByRenderer) { |
| 1143 // Simulate a keyboard event. | 1081 // Simulate a keyboard event. |
| 1144 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 1082 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
| 1145 | 1083 |
| 1146 // Make sure we sent the input event to the renderer. | 1084 // Make sure we sent the input event to the renderer. |
| 1147 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( | 1085 EXPECT_TRUE(process_->sink().GetUniqueMessageMatching( |
| 1148 InputMsg_HandleInputEvent::ID)); | 1086 InputMsg_HandleInputEvent::ID)); |
| 1149 process_->sink().ClearMessages(); | 1087 process_->sink().ClearMessages(); |
| 1150 | 1088 |
| 1151 // Send the simulated response from the renderer back. | 1089 // Send the simulated response from the renderer back. |
| (...skipping 1464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2616 | 2554 |
| 2617 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). | 2555 // Tests RWHI::ForwardTouchEventWithLatencyInfo(). |
| 2618 PressTouchPoint(0, 1); | 2556 PressTouchPoint(0, 1); |
| 2619 SendTouchEvent(); | 2557 SendTouchEvent(); |
| 2620 CheckLatencyInfoComponentInMessage( | 2558 CheckLatencyInfoComponentInMessage( |
| 2621 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); | 2559 process_, GetLatencyComponentId(), WebInputEvent::TouchStart); |
| 2622 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); | 2560 SendInputEventACK(WebInputEvent::TouchStart, INPUT_EVENT_ACK_STATE_CONSUMED); |
| 2623 } | 2561 } |
| 2624 | 2562 |
| 2625 } // namespace content | 2563 } // namespace content |
| OLD | NEW |