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