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 "content/test/test_renderer_host.h" | 5 #include "content/test/test_renderer_host.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_view_host_factory.h" | 7 #include "content/browser/renderer_host/render_view_host_factory.h" |
8 #include "content/browser/renderer_host/test_render_view_host.h" | 8 #include "content/browser/renderer_host/test_render_view_host.h" |
9 #include "content/browser/site_instance_impl.h" | 9 #include "content/browser/site_instance_impl.h" |
10 #include "content/browser/web_contents/navigation_entry_impl.h" | 10 #include "content/browser/web_contents/navigation_entry_impl.h" |
11 #include "content/browser/web_contents/test_web_contents.h" | 11 #include "content/browser/web_contents/test_web_contents.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "content/test/mock_render_process_host.h" | 13 #include "content/test/mock_render_process_host.h" |
14 #include "content/test/test_browser_context.h" | 14 #include "content/test/test_browser_context.h" |
| 15 #include "content/test/test_render_view_host_factory.h" |
15 | 16 |
16 #if defined(USE_AURA) | 17 #if defined(USE_AURA) |
17 #include "ui/aura/env.h" | 18 #include "ui/aura/env.h" |
18 #include "ui/aura/monitor_manager.h" | 19 #include "ui/aura/monitor_manager.h" |
19 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
20 #include "ui/aura/single_monitor_manager.h" | 21 #include "ui/aura/single_monitor_manager.h" |
21 #include "ui/aura/test/test_screen.h" | 22 #include "ui/aura/test/test_screen.h" |
22 #include "ui/aura/test/test_stacking_client.h" | 23 #include "ui/aura/test/test_stacking_client.h" |
23 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
24 #endif | 25 #endif |
25 | 26 |
26 namespace content { | 27 namespace content { |
27 | 28 |
28 // Manages creation of the RenderViewHosts using our special subclass. This | |
29 // automatically registers itself when it goes in scope, and unregisters itself | |
30 // when it goes out of scope. Since you can't have more than one factory | |
31 // registered at a time, you can only have one of these objects at a time. | |
32 // | |
33 // This is an implementation detail of this file and used only via | |
34 // RenderViewHostTestEnabler. | |
35 class TestRenderViewHostFactory : public RenderViewHostFactory { | |
36 public: | |
37 explicit TestRenderViewHostFactory( | |
38 content::RenderProcessHostFactory* rph_factory); | |
39 virtual ~TestRenderViewHostFactory(); | |
40 | |
41 virtual void set_render_process_host_factory( | |
42 content::RenderProcessHostFactory* rph_factory); | |
43 virtual content::RenderViewHost* CreateRenderViewHost( | |
44 content::SiteInstance* instance, | |
45 content::RenderViewHostDelegate* delegate, | |
46 int routing_id, | |
47 content::SessionStorageNamespace* session_storage) OVERRIDE; | |
48 | |
49 private: | |
50 // This is a bit of a hack. With the current design of the site instances / | |
51 // browsing instances, it's difficult to pass a RenderProcessHostFactory | |
52 // around properly. | |
53 // | |
54 // Instead, we set it right before we create a new RenderViewHost, which | |
55 // happens before the RenderProcessHost is created. This way, the instance | |
56 // has the correct factory and creates our special RenderProcessHosts. | |
57 content::RenderProcessHostFactory* render_process_host_factory_; | |
58 | |
59 DISALLOW_COPY_AND_ASSIGN(TestRenderViewHostFactory); | |
60 }; | |
61 | |
62 TestRenderViewHostFactory::TestRenderViewHostFactory( | |
63 content::RenderProcessHostFactory* rph_factory) | |
64 : render_process_host_factory_(rph_factory) { | |
65 RenderViewHostFactory::RegisterFactory(this); | |
66 } | |
67 | |
68 TestRenderViewHostFactory::~TestRenderViewHostFactory() { | |
69 RenderViewHostFactory::UnregisterFactory(); | |
70 } | |
71 | |
72 void TestRenderViewHostFactory::set_render_process_host_factory( | |
73 content::RenderProcessHostFactory* rph_factory) { | |
74 render_process_host_factory_ = rph_factory; | |
75 } | |
76 | |
77 content::RenderViewHost* TestRenderViewHostFactory::CreateRenderViewHost( | |
78 SiteInstance* instance, | |
79 RenderViewHostDelegate* delegate, | |
80 int routing_id, | |
81 SessionStorageNamespace* session_storage) { | |
82 // See declaration of render_process_host_factory_ below. | |
83 static_cast<SiteInstanceImpl*>(instance)-> | |
84 set_render_process_host_factory(render_process_host_factory_); | |
85 return new TestRenderViewHost(instance, delegate, routing_id); | |
86 } | |
87 | |
88 // static | 29 // static |
89 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { | 30 RenderViewHostTester* RenderViewHostTester::For(RenderViewHost* host) { |
90 return static_cast<TestRenderViewHost*>(host); | 31 return static_cast<TestRenderViewHost*>(host); |
91 } | 32 } |
92 | 33 |
93 // static | 34 // static |
94 void RenderViewHostTester::EnableAccessibilityUpdatedNotifications( | 35 void RenderViewHostTester::EnableAccessibilityUpdatedNotifications( |
95 RenderViewHost* host) { | 36 RenderViewHost* host) { |
96 static_cast<RenderViewHostImpl*>( | 37 static_cast<RenderViewHostImpl*>( |
97 host)->set_send_accessibility_updated_notifications(true); | 38 host)->set_send_accessibility_updated_notifications(true); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 158 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
218 message_loop_.RunAllPending(); | 159 message_loop_.RunAllPending(); |
219 } | 160 } |
220 | 161 |
221 void RenderViewHostTestHarness::SetRenderProcessHostFactory( | 162 void RenderViewHostTestHarness::SetRenderProcessHostFactory( |
222 RenderProcessHostFactory* factory) { | 163 RenderProcessHostFactory* factory) { |
223 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); | 164 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); |
224 } | 165 } |
225 | 166 |
226 } // namespace content | 167 } // namespace content |
OLD | NEW |