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/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/shared_memory.h" | 7 #include "base/shared_memory.h" |
8 #include "base/timer.h" | 8 #include "base/timer.h" |
9 #include "content/browser/browser_thread_impl.h" | 9 #include "content/browser/browser_thread_impl.h" |
10 #include "content/browser/renderer_host/backing_store.h" | 10 #include "content/browser/renderer_host/backing_store.h" |
| 11 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
11 #include "content/browser/renderer_host/test_render_view_host.h" | 12 #include "content/browser/renderer_host/test_render_view_host.h" |
12 #include "content/common/view_messages.h" | 13 #include "content/common/view_messages.h" |
13 #include "content/port/browser/render_widget_host_view_port.h" | 14 #include "content/port/browser/render_widget_host_view_port.h" |
14 #include "content/public/browser/notification_details.h" | 15 #include "content/public/browser/notification_details.h" |
15 #include "content/public/browser/notification_observer.h" | 16 #include "content/public/browser/notification_observer.h" |
16 #include "content/public/browser/notification_registrar.h" | 17 #include "content/public/browser/notification_registrar.h" |
17 #include "content/public/browser/notification_source.h" | 18 #include "content/public/browser/notification_source.h" |
18 #include "content/public/browser/notification_types.h" | 19 #include "content/public/browser/notification_types.h" |
19 #include "content/test/mock_render_process_host.h" | 20 #include "content/test/mock_render_process_host.h" |
20 #include "content/test/test_browser_context.h" | 21 #include "content/test/test_browser_context.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 virtual gfx::Rect GetViewCocoaBounds() const { | 141 virtual gfx::Rect GetViewCocoaBounds() const { |
141 return bounds_; | 142 return bounds_; |
142 } | 143 } |
143 #endif | 144 #endif |
144 | 145 |
145 protected: | 146 protected: |
146 gfx::Rect bounds_; | 147 gfx::Rect bounds_; |
147 DISALLOW_COPY_AND_ASSIGN(TestView); | 148 DISALLOW_COPY_AND_ASSIGN(TestView); |
148 }; | 149 }; |
149 | 150 |
| 151 // MockRenderWidgetHostDelegate -------------------------------------------- |
| 152 |
| 153 class MockRenderWidgetHostDelegate : public content::RenderWidgetHostDelegate { |
| 154 public: |
| 155 MockRenderWidgetHostDelegate() {} |
| 156 virtual ~MockRenderWidgetHostDelegate() {} |
| 157 }; |
| 158 |
150 // MockRenderWidgetHost ---------------------------------------------------- | 159 // MockRenderWidgetHost ---------------------------------------------------- |
151 | 160 |
152 class MockRenderWidgetHost : public RenderWidgetHostImpl { | 161 class MockRenderWidgetHost : public RenderWidgetHostImpl { |
153 public: | 162 public: |
154 MockRenderWidgetHost(content::RenderProcessHost* process, int routing_id) | 163 MockRenderWidgetHost( |
155 : RenderWidgetHostImpl(process, routing_id), | 164 content::RenderWidgetHostDelegate* delegate, |
| 165 content::RenderProcessHost* process, |
| 166 int routing_id) |
| 167 : RenderWidgetHostImpl(delegate, process, routing_id), |
156 prehandle_keyboard_event_(false), | 168 prehandle_keyboard_event_(false), |
157 prehandle_keyboard_event_called_(false), | 169 prehandle_keyboard_event_called_(false), |
158 prehandle_keyboard_event_type_(WebInputEvent::Undefined), | 170 prehandle_keyboard_event_type_(WebInputEvent::Undefined), |
159 unhandled_keyboard_event_called_(false), | 171 unhandled_keyboard_event_called_(false), |
160 unhandled_keyboard_event_type_(WebInputEvent::Undefined), | 172 unhandled_keyboard_event_type_(WebInputEvent::Undefined), |
161 unresponsive_timer_fired_(false) { | 173 unresponsive_timer_fired_(false) { |
162 } | 174 } |
163 | 175 |
164 // Allow poking at a few private members. | 176 // Allow poking at a few private members. |
165 using RenderWidgetHostImpl::OnMsgPaintAtSizeAck; | 177 using RenderWidgetHostImpl::OnMsgPaintAtSizeAck; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 public: | 283 public: |
272 RenderWidgetHostTest() : process_(NULL) { | 284 RenderWidgetHostTest() : process_(NULL) { |
273 } | 285 } |
274 ~RenderWidgetHostTest() { | 286 ~RenderWidgetHostTest() { |
275 } | 287 } |
276 | 288 |
277 protected: | 289 protected: |
278 // testing::Test | 290 // testing::Test |
279 void SetUp() { | 291 void SetUp() { |
280 browser_context_.reset(new TestBrowserContext()); | 292 browser_context_.reset(new TestBrowserContext()); |
| 293 delegate_.reset(new MockRenderWidgetHostDelegate()); |
281 process_ = new RenderWidgetHostProcess(browser_context_.get()); | 294 process_ = new RenderWidgetHostProcess(browser_context_.get()); |
282 host_.reset(new MockRenderWidgetHost(process_, MSG_ROUTING_NONE)); | 295 host_.reset( |
| 296 new MockRenderWidgetHost(delegate_.get(), process_, MSG_ROUTING_NONE)); |
283 view_.reset(new TestView(host_.get())); | 297 view_.reset(new TestView(host_.get())); |
284 host_->SetView(view_.get()); | 298 host_->SetView(view_.get()); |
285 host_->Init(); | 299 host_->Init(); |
286 } | 300 } |
287 void TearDown() { | 301 void TearDown() { |
288 view_.reset(); | 302 view_.reset(); |
289 host_.reset(); | 303 host_.reset(); |
| 304 delegate_.reset(); |
290 process_ = NULL; | 305 process_ = NULL; |
291 browser_context_.reset(); | 306 browser_context_.reset(); |
292 | 307 |
293 // Process all pending tasks to avoid leaks. | 308 // Process all pending tasks to avoid leaks. |
294 MessageLoop::current()->RunAllPending(); | 309 MessageLoop::current()->RunAllPending(); |
295 } | 310 } |
296 | 311 |
297 void SendInputEventACK(WebInputEvent::Type type, bool processed) { | 312 void SendInputEventACK(WebInputEvent::Type type, bool processed) { |
298 scoped_ptr<IPC::Message> response( | 313 scoped_ptr<IPC::Message> response( |
299 new ViewHostMsg_HandleInputEvent_ACK(0, type, processed)); | 314 new ViewHostMsg_HandleInputEvent_ACK(0, type, processed)); |
(...skipping 13 matching lines...) Expand all Loading... |
313 wheel_event.deltaX = dX; | 328 wheel_event.deltaX = dX; |
314 wheel_event.deltaY = dY; | 329 wheel_event.deltaY = dY; |
315 wheel_event.modifiers = modifiers; | 330 wheel_event.modifiers = modifiers; |
316 host_->ForwardWheelEvent(wheel_event); | 331 host_->ForwardWheelEvent(wheel_event); |
317 } | 332 } |
318 | 333 |
319 MessageLoopForUI message_loop_; | 334 MessageLoopForUI message_loop_; |
320 | 335 |
321 scoped_ptr<TestBrowserContext> browser_context_; | 336 scoped_ptr<TestBrowserContext> browser_context_; |
322 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. | 337 RenderWidgetHostProcess* process_; // Deleted automatically by the widget. |
| 338 scoped_ptr<MockRenderWidgetHostDelegate> delegate_; |
323 scoped_ptr<MockRenderWidgetHost> host_; | 339 scoped_ptr<MockRenderWidgetHost> host_; |
324 scoped_ptr<TestView> view_; | 340 scoped_ptr<TestView> view_; |
325 | 341 |
326 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); | 342 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostTest); |
327 }; | 343 }; |
328 | 344 |
329 // ----------------------------------------------------------------------------- | 345 // ----------------------------------------------------------------------------- |
330 | 346 |
331 TEST_F(RenderWidgetHostTest, Resize) { | 347 TEST_F(RenderWidgetHostTest, Resize) { |
332 // The initial bounds is the empty rect, so setting it to the same thing | 348 // The initial bounds is the empty rect, so setting it to the same thing |
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 809 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
794 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); | 810 SimulateKeyboardEvent(WebInputEvent::RawKeyDown); |
795 SendInputEventACK(WebInputEvent::RawKeyDown, true); | 811 SendInputEventACK(WebInputEvent::RawKeyDown, true); |
796 | 812 |
797 // Wait long enough for first timeout and see if it fired. | 813 // Wait long enough for first timeout and see if it fired. |
798 MessageLoop::current()->PostDelayedTask( | 814 MessageLoop::current()->PostDelayedTask( |
799 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); | 815 FROM_HERE, MessageLoop::QuitClosure(), TimeDelta::FromMilliseconds(40)); |
800 MessageLoop::current()->Run(); | 816 MessageLoop::current()->Run(); |
801 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 817 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
802 } | 818 } |
OLD | NEW |