Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(531)

Side by Side Diff: content/test/test_renderer_host.cc

Issue 9706012: Add abstractions that let embedders drive tests of WebContents. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove CONTENT_EXPORT on statically linked functions. Merge to head for commit. Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « content/test/test_renderer_host.h ('k') | content/test/web_contents_tester.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/tab_contents/navigation_entry_impl.h" 10 #include "content/browser/tab_contents/navigation_entry_impl.h"
11 #include "content/browser/tab_contents/test_tab_contents.h" 11 #include "content/browser/tab_contents/test_tab_contents.h"
12 #include "content/public/browser/web_contents.h"
12 #include "content/test/mock_render_process_host.h" 13 #include "content/test/mock_render_process_host.h"
13 #include "content/test/test_browser_context.h" 14 #include "content/test/test_browser_context.h"
14 15
15 #if defined(USE_AURA) 16 #if defined(USE_AURA)
16 #include "ui/aura/monitor_manager.h" 17 #include "ui/aura/monitor_manager.h"
17 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
18 #include "ui/aura/test/test_screen.h" 19 #include "ui/aura/test/test_screen.h"
19 #include "ui/aura/test/test_stacking_client.h" 20 #include "ui/aura/test/test_stacking_client.h"
20 #endif 21 #endif
21 22
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 } 116 }
116 117
117 RenderViewHostTestHarness::RenderViewHostTestHarness() 118 RenderViewHostTestHarness::RenderViewHostTestHarness()
118 : contents_(NULL) { 119 : contents_(NULL) {
119 } 120 }
120 121
121 RenderViewHostTestHarness::~RenderViewHostTestHarness() { 122 RenderViewHostTestHarness::~RenderViewHostTestHarness() {
122 } 123 }
123 124
124 NavigationController& RenderViewHostTestHarness::controller() { 125 NavigationController& RenderViewHostTestHarness::controller() {
125 return contents()->GetController(); 126 return web_contents()->GetController();
126 } 127 }
127 128
128 TestTabContents* RenderViewHostTestHarness::contents() { 129 WebContents* RenderViewHostTestHarness::web_contents() {
129 return contents_.get(); 130 return contents_.get();
130 } 131 }
131 132
132 RenderViewHost* RenderViewHostTestHarness::rvh() { 133 RenderViewHost* RenderViewHostTestHarness::rvh() {
133 return contents()->GetRenderViewHost(); 134 return web_contents()->GetRenderViewHost();
134 } 135 }
135 136
136 RenderViewHost* RenderViewHostTestHarness::pending_rvh() { 137 RenderViewHost* RenderViewHostTestHarness::pending_rvh() {
137 return contents()->GetRenderManagerForTesting()->pending_render_view_host(); 138 return static_cast<TestTabContents*>(web_contents())->
139 GetRenderManagerForTesting()->pending_render_view_host();
138 } 140 }
139 141
140 RenderViewHost* RenderViewHostTestHarness::active_rvh() { 142 RenderViewHost* RenderViewHostTestHarness::active_rvh() {
141 return pending_rvh() ? pending_rvh() : rvh(); 143 return pending_rvh() ? pending_rvh() : rvh();
142 } 144 }
143 145
144 BrowserContext* RenderViewHostTestHarness::browser_context() { 146 BrowserContext* RenderViewHostTestHarness::browser_context() {
145 return browser_context_.get(); 147 return browser_context_.get();
146 } 148 }
147 149
148 MockRenderProcessHost* RenderViewHostTestHarness::process() { 150 MockRenderProcessHost* RenderViewHostTestHarness::process() {
149 return static_cast<MockRenderProcessHost*>(active_rvh()->GetProcess()); 151 return static_cast<MockRenderProcessHost*>(active_rvh()->GetProcess());
150 } 152 }
151 153
152 void RenderViewHostTestHarness::DeleteContents() { 154 void RenderViewHostTestHarness::DeleteContents() {
153 SetContents(NULL); 155 SetContents(NULL);
154 } 156 }
155 157
156 void RenderViewHostTestHarness::SetContents(TestTabContents* contents) { 158 void RenderViewHostTestHarness::SetContents(WebContents* contents) {
157 contents_.reset(contents); 159 contents_.reset(contents);
158 } 160 }
159 161
160 TestTabContents* RenderViewHostTestHarness::CreateTestTabContents() { 162 WebContents* RenderViewHostTestHarness::CreateTestWebContents() {
161 // See comment above browser_context_ decl for why we check for NULL here. 163 // See comment above browser_context_ decl for why we check for NULL here.
162 if (!browser_context_.get()) 164 if (!browser_context_.get())
163 browser_context_.reset(new TestBrowserContext()); 165 browser_context_.reset(new TestBrowserContext());
164 166
165 // This will be deleted when the TabContents goes away. 167 // This will be deleted when the TabContents goes away.
166 SiteInstance* instance = SiteInstance::Create(browser_context_.get()); 168 SiteInstance* instance = SiteInstance::Create(browser_context_.get());
167 169
168 return new TestTabContents(browser_context_.get(), instance); 170 return new TestTabContents(browser_context_.get(), instance);
169 } 171 }
170 172
171 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) { 173 void RenderViewHostTestHarness::NavigateAndCommit(const GURL& url) {
172 contents()->NavigateAndCommit(url); 174 static_cast<TestTabContents*>(web_contents())->NavigateAndCommit(url);
173 } 175 }
174 176
175 void RenderViewHostTestHarness::Reload() { 177 void RenderViewHostTestHarness::Reload() {
176 NavigationEntry* entry = controller().GetLastCommittedEntry(); 178 NavigationEntry* entry = controller().GetLastCommittedEntry();
177 DCHECK(entry); 179 DCHECK(entry);
178 controller().Reload(false); 180 controller().Reload(false);
179 static_cast<TestRenderViewHost*>( 181 static_cast<TestRenderViewHost*>(
180 rvh())->SendNavigate(entry->GetPageID(), entry->GetURL()); 182 rvh())->SendNavigate(entry->GetPageID(), entry->GetURL());
181 } 183 }
182 184
183 void RenderViewHostTestHarness::SetUp() { 185 void RenderViewHostTestHarness::SetUp() {
184 #if defined(USE_AURA) 186 #if defined(USE_AURA)
185 root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); 187 root_window_.reset(aura::MonitorManager::CreateRootWindowForPrimaryMonitor());
186 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); 188 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get()));
187 test_stacking_client_.reset( 189 test_stacking_client_.reset(
188 new aura::test::TestStackingClient(root_window_.get())); 190 new aura::test::TestStackingClient(root_window_.get()));
189 #endif 191 #endif
190 SetContents(CreateTestTabContents()); 192 SetContents(CreateTestWebContents());
191 } 193 }
192 194
193 void RenderViewHostTestHarness::TearDown() { 195 void RenderViewHostTestHarness::TearDown() {
194 SetContents(NULL); 196 SetContents(NULL);
195 #if defined(USE_AURA) 197 #if defined(USE_AURA)
196 test_stacking_client_.reset(); 198 test_stacking_client_.reset();
197 root_window_.reset(); 199 root_window_.reset();
198 #endif 200 #endif
199 201
200 // Make sure that we flush any messages related to TabContents destruction 202 // Make sure that we flush any messages related to TabContents destruction
201 // before we destroy the browser context. 203 // before we destroy the browser context.
202 MessageLoop::current()->RunAllPending(); 204 MessageLoop::current()->RunAllPending();
203 205
204 // Release the browser context on the UI thread. 206 // Release the browser context on the UI thread.
205 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); 207 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
206 message_loop_.RunAllPending(); 208 message_loop_.RunAllPending();
207 } 209 }
208 210
209 void RenderViewHostTestHarness::SetRenderProcessHostFactory( 211 void RenderViewHostTestHarness::SetRenderProcessHostFactory(
210 RenderProcessHostFactory* factory) { 212 RenderProcessHostFactory* factory) {
211 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory); 213 rvh_test_enabler_.rvh_factory_->set_render_process_host_factory(factory);
212 } 214 }
213 215
214 } // namespace content 216 } // namespace content
OLDNEW
« no previous file with comments | « content/test/test_renderer_host.h ('k') | content/test/web_contents_tester.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698