OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/command_line.h" | |
6 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
7 #include "base/shared_memory.h" | 8 #include "base/shared_memory.h" |
8 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/test/base/test_launcher_utils.h" | |
sky
2011/10/13 19:52:00
content shouldn't depend on chrome or views.
danakj
2011/10/14 15:15:13
Oh this isn't even needed now, removed.
| |
9 #include "content/browser/browser_thread.h" | 11 #include "content/browser/browser_thread.h" |
10 #include "content/browser/content_browser_client.h" | 12 #include "content/browser/content_browser_client.h" |
11 #include "content/browser/renderer_host/backing_store.h" | 13 #include "content/browser/renderer_host/backing_store.h" |
12 #include "content/browser/renderer_host/test_render_view_host.h" | 14 #include "content/browser/renderer_host/test_render_view_host.h" |
13 #include "content/common/notification_details.h" | 15 #include "content/common/notification_details.h" |
14 #include "content/common/notification_observer.h" | 16 #include "content/common/notification_observer.h" |
15 #include "content/common/notification_registrar.h" | 17 #include "content/common/notification_registrar.h" |
16 #include "content/common/notification_source.h" | 18 #include "content/common/notification_source.h" |
17 #include "content/common/view_messages.h" | 19 #include "content/common/view_messages.h" |
18 #include "content/test/test_browser_context.h" | 20 #include "content/test/test_browser_context.h" |
19 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
20 #include "ui/base/keycodes/keyboard_codes.h" | 22 #include "ui/base/keycodes/keyboard_codes.h" |
21 #include "ui/gfx/canvas_skia.h" | 23 #include "ui/gfx/canvas_skia.h" |
22 | 24 |
25 #if defined(VIEWS_COMPOSITOR) | |
26 #include "ui/gfx/compositor/test_compositor.h" | |
27 #include "views/widget/widget.h" | |
28 #endif | |
29 | |
23 using base::TimeDelta; | 30 using base::TimeDelta; |
24 | 31 |
25 using WebKit::WebInputEvent; | 32 using WebKit::WebInputEvent; |
26 using WebKit::WebMouseWheelEvent; | 33 using WebKit::WebMouseWheelEvent; |
27 | 34 |
28 namespace gfx { | 35 namespace gfx { |
29 class Size; | 36 class Size; |
30 } | 37 } |
31 | 38 |
32 // RenderWidgetHostProcess ----------------------------------------------------- | 39 // RenderWidgetHostProcess ----------------------------------------------------- |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 MockRenderWidgetHost* host() const { return host_; } | 237 MockRenderWidgetHost* host() const { return host_; } |
231 int tag() const { return tag_; } | 238 int tag() const { return tag_; } |
232 gfx::Size size() const { return size_; } | 239 gfx::Size size() const { return size_; } |
233 | 240 |
234 private: | 241 private: |
235 MockRenderWidgetHost* host_; | 242 MockRenderWidgetHost* host_; |
236 int tag_; | 243 int tag_; |
237 gfx::Size size_; | 244 gfx::Size size_; |
238 }; | 245 }; |
239 | 246 |
247 #if defined(VIEWS_COMPOSITOR) | |
248 // static | |
249 static ui::Compositor* TestCreateCompositor(ui::CompositorDelegate* owner) { | |
250 return new ui::TestCompositor(owner); | |
251 } | |
252 #endif | |
240 | 253 |
241 // RenderWidgetHostTest -------------------------------------------------------- | 254 // RenderWidgetHostTest -------------------------------------------------------- |
242 | 255 |
243 class RenderWidgetHostTest : public testing::Test { | 256 class RenderWidgetHostTest : public testing::Test { |
244 public: | 257 public: |
245 RenderWidgetHostTest() : process_(NULL) { | 258 RenderWidgetHostTest() : process_(NULL) { |
246 } | 259 } |
247 ~RenderWidgetHostTest() { | 260 ~RenderWidgetHostTest() { |
248 } | 261 } |
249 | 262 |
250 protected: | 263 protected: |
251 // testing::Test | 264 // testing::Test |
252 void SetUp() { | 265 void SetUp() { |
266 #if defined(VIEWS_COMPOSITOR) | |
267 // Use a mock compositor that noops draws. | |
268 views::Widget::set_compositor_factory_for_testing(&TestCreateCompositor); | |
danakj
2011/10/14 15:15:13
Moved the factory to ui::Compositor.
| |
269 #endif | |
253 browser_context_.reset(new TestBrowserContext()); | 270 browser_context_.reset(new TestBrowserContext()); |
254 process_ = new RenderWidgetHostProcess(browser_context_.get()); | 271 process_ = new RenderWidgetHostProcess(browser_context_.get()); |
255 host_.reset(new MockRenderWidgetHost(process_, 1)); | 272 host_.reset(new MockRenderWidgetHost(process_, 1)); |
256 view_.reset(new TestView(host_.get())); | 273 view_.reset(new TestView(host_.get())); |
257 host_->SetView(view_.get()); | 274 host_->SetView(view_.get()); |
258 host_->Init(); | 275 host_->Init(); |
259 } | 276 } |
260 void TearDown() { | 277 void TearDown() { |
261 view_.reset(); | 278 view_.reset(); |
262 host_.reset(); | 279 host_.reset(); |
263 process_ = NULL; | 280 process_ = NULL; |
264 browser_context_.reset(); | 281 browser_context_.reset(); |
282 #if defined(VIEWS_COMPOSITOR) | |
283 views::Widget::set_compositor_factory_for_testing(NULL); | |
284 #endif | |
265 | 285 |
266 // Process all pending tasks to avoid leaks. | 286 // Process all pending tasks to avoid leaks. |
267 MessageLoop::current()->RunAllPending(); | 287 MessageLoop::current()->RunAllPending(); |
268 } | 288 } |
269 | 289 |
270 void SendInputEventACK(WebInputEvent::Type type, bool processed) { | 290 void SendInputEventACK(WebInputEvent::Type type, bool processed) { |
271 scoped_ptr<IPC::Message> response( | 291 scoped_ptr<IPC::Message> response( |
272 new ViewHostMsg_HandleInputEvent_ACK(0, type, processed)); | 292 new ViewHostMsg_HandleInputEvent_ACK(0, type, processed)); |
273 host_->OnMessageReceived(*response); | 293 host_->OnMessageReceived(*response); |
274 } | 294 } |
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 // Start it again to ensure it still works. | 741 // Start it again to ensure it still works. |
722 EXPECT_FALSE(host_->unresponsive_timer_fired()); | 742 EXPECT_FALSE(host_->unresponsive_timer_fired()); |
723 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); | 743 host_->StartHangMonitorTimeout(TimeDelta::FromMilliseconds(10)); |
724 | 744 |
725 // Wait long enough for first timeout and see if it fired. | 745 // Wait long enough for first timeout and see if it fired. |
726 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 746 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
727 new MessageLoop::QuitTask(), 10); | 747 new MessageLoop::QuitTask(), 10); |
728 MessageLoop::current()->Run(); | 748 MessageLoop::current()->Run(); |
729 EXPECT_TRUE(host_->unresponsive_timer_fired()); | 749 EXPECT_TRUE(host_->unresponsive_timer_fired()); |
730 } | 750 } |
OLD | NEW |