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

Side by Side Diff: content/public/test/browser_test_base.cc

Issue 190663012: Run ContentMain in a browser_test's browser process. This removes duplication of code in the browse… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: cleanup Created 6 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
OLDNEW
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 "content/public/test/browser_test_base.h" 5 #include "content/public/test/browser_test_base.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/debug/stack_trace.h" 9 #include "base/debug/stack_trace.h"
10 #include "base/i18n/icu_util.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/sys_info.h" 12 #include "base/sys_info.h"
13 #include "content/public/app/content_main.h"
12 #include "content/browser/renderer_host/render_process_host_impl.h" 14 #include "content/browser/renderer_host/render_process_host_impl.h"
13 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
14 #include "content/public/common/content_switches.h" 16 #include "content/public/common/content_switches.h"
15 #include "content/public/common/main_function_params.h" 17 #include "content/public/common/main_function_params.h"
18 #include "content/public/test/test_launcher.h"
16 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
17 #include "net/base/net_errors.h" 20 #include "net/base/net_errors.h"
18 #include "net/dns/mock_host_resolver.h" 21 #include "net/dns/mock_host_resolver.h"
19 #include "net/test/embedded_test_server/embedded_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
20 #include "ui/compositor/compositor_switches.h" 23 #include "ui/compositor/compositor_switches.h"
21 #include "ui/gl/gl_implementation.h" 24 #include "ui/gl/gl_implementation.h"
22 #include "ui/gl/gl_switches.h" 25 #include "ui/gl/gl_switches.h"
23 26
24 #if defined(OS_POSIX) 27 #if defined(OS_POSIX)
25 #include "base/process/process_handle.h" 28 #include "base/process/process_handle.h"
26 #endif 29 #endif
27 30
28 #if defined(OS_MACOSX) 31 #if defined(OS_MACOSX)
29 #include "base/mac/mac_util.h" 32 #include "base/mac/mac_util.h"
30 #include "base/power_monitor/power_monitor_device_source.h"
31 #endif 33 #endif
32 34
33 #if defined(OS_ANDROID) 35 #if defined(OS_ANDROID)
34 #include "base/threading/thread_restrictions.h" 36 #include "base/threading/thread_restrictions.h"
35 #include "content/public/browser/browser_main_runner.h" 37 #include "content/public/browser/browser_main_runner.h"
36 #include "content/public/browser/browser_thread.h" 38 #include "content/public/browser/browser_thread.h"
37 #endif 39 #endif
38 40
39 #if defined(USE_AURA) 41 #if defined(USE_AURA)
40 #include "content/browser/compositor/image_transport_factory.h" 42 #include "content/browser/compositor/image_transport_factory.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 }; 116 };
115 117
116 } // namespace 118 } // namespace
117 119
118 extern int BrowserMain(const MainFunctionParams&); 120 extern int BrowserMain(const MainFunctionParams&);
119 121
120 BrowserTestBase::BrowserTestBase() 122 BrowserTestBase::BrowserTestBase()
121 : enable_pixel_output_(false), use_software_compositing_(false) { 123 : enable_pixel_output_(false), use_software_compositing_(false) {
122 #if defined(OS_MACOSX) 124 #if defined(OS_MACOSX)
123 base::mac::SetOverrideAmIBundled(true); 125 base::mac::SetOverrideAmIBundled(true);
124 base::PowerMonitorDeviceSource::AllocateSystemIOPorts();
125 #endif 126 #endif
126 127
127 #if defined(OS_POSIX) 128 #if defined(OS_POSIX)
128 handle_sigterm_ = true; 129 handle_sigterm_ = true;
129 #endif 130 #endif
130 131
132 // This is called through base::TestSuite initially. It'll also be called
133 // inside BrowserMain, so tell the code to ignore the check that it's being
134 // called more than once
135 base::i18n::AllowMultipleInitializeCallsForTesting();
136
131 embedded_test_server_.reset(new net::test_server::EmbeddedTestServer); 137 embedded_test_server_.reset(new net::test_server::EmbeddedTestServer);
132 } 138 }
133 139
134 BrowserTestBase::~BrowserTestBase() { 140 BrowserTestBase::~BrowserTestBase() {
135 #if defined(OS_ANDROID) 141 #if defined(OS_ANDROID)
136 // RemoteTestServer can cause wait on the UI thread. 142 // RemoteTestServer can cause wait on the UI thread.
137 base::ThreadRestrictions::ScopedAllowWait allow_wait; 143 base::ThreadRestrictions::ScopedAllowWait allow_wait;
138 test_server_.reset(NULL); 144 test_server_.reset(NULL);
139 #endif 145 #endif
140 } 146 }
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 223
218 scoped_refptr<net::HostResolverProc> local_resolver = 224 scoped_refptr<net::HostResolverProc> local_resolver =
219 new LocalHostResolverProc(); 225 new LocalHostResolverProc();
220 rule_based_resolver_ = 226 rule_based_resolver_ =
221 new net::RuleBasedHostResolverProc(local_resolver.get()); 227 new net::RuleBasedHostResolverProc(local_resolver.get());
222 rule_based_resolver_->AddSimulatedFailure("wpad"); 228 rule_based_resolver_->AddSimulatedFailure("wpad");
223 net::ScopedDefaultHostResolverProc scoped_local_host_resolver_proc( 229 net::ScopedDefaultHostResolverProc scoped_local_host_resolver_proc(
224 rule_based_resolver_.get()); 230 rule_based_resolver_.get());
225 SetUpInProcessBrowserTestFixture(); 231 SetUpInProcessBrowserTestFixture();
226 MainFunctionParams params(*command_line); 232 MainFunctionParams params(*command_line);
233
234
235 ///*
sky 2014/03/14 21:35:56 I assume this and 251 is temporary.
jam 2014/03/14 22:35:40 Done.
227 params.ui_task = 236 params.ui_task =
228 new base::Closure( 237 new base::Closure(
229 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); 238 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this));
239 //*/
230 240
231 #if defined(OS_ANDROID) 241 #if defined(OS_ANDROID)
232 BrowserMainRunner::Create()->Initialize(params); 242 BrowserMainRunner::Create()->Initialize(params);
233 // We are done running the test by now. During teardown we 243 // We are done running the test by now. During teardown we
234 // need to be able to perform IO. 244 // need to be able to perform IO.
235 base::ThreadRestrictions::SetIOAllowed(true); 245 base::ThreadRestrictions::SetIOAllowed(true);
236 BrowserThread::PostTask( 246 BrowserThread::PostTask(
237 BrowserThread::IO, FROM_HERE, 247 BrowserThread::IO, FROM_HERE,
238 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), 248 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed),
239 true)); 249 true));
240 #else 250 #else
241 BrowserMain(params); 251 ///*
252 ///////////////////////////// BrowserMain(params);
253 //*/
254 ////BrowserTestBase::ProxyRunTestOnMainThreadLoop();
255 GetContentMainParams()->ui_task = params.ui_task;
256 ContentMain(*GetContentMainParams());
242 #endif 257 #endif
243 TearDownInProcessBrowserTestFixture(); 258 TearDownInProcessBrowserTestFixture();
244 } 259 }
245 260
246 void BrowserTestBase::TearDown() { 261 void BrowserTestBase::TearDown() {
247 } 262 }
248 263
249 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { 264 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() {
250 #if defined(OS_POSIX) 265 #if defined(OS_POSIX)
251 if (handle_sigterm_) { 266 if (handle_sigterm_) {
252 g_browser_process_pid = base::GetCurrentProcId(); 267 g_browser_process_pid = base::GetCurrentProcId();
253 signal(SIGTERM, DumpStackTraceSignalHandler); 268 signal(SIGTERM, DumpStackTraceSignalHandler);
254 } 269 }
255 #endif // defined(OS_POSIX) 270 #endif // defined(OS_POSIX)
271
256 RunTestOnMainThreadLoop(); 272 RunTestOnMainThreadLoop();
257 } 273 }
258 274
259 void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) { 275 void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) {
260 CHECK(!test_server_.get()); 276 CHECK(!test_server_.get());
261 test_server_.reset(new net::SpawnedTestServer( 277 test_server_.reset(new net::SpawnedTestServer(
262 net::SpawnedTestServer::TYPE_HTTP, 278 net::SpawnedTestServer::TYPE_HTTP,
263 net::SpawnedTestServer::kLocalhost, 279 net::SpawnedTestServer::kLocalhost,
264 test_server_base)); 280 test_server_base));
265 } 281 }
(...skipping 24 matching lines...) Expand all
290 use_software_compositing_ = true; 306 use_software_compositing_ = true;
291 } 307 }
292 308
293 bool BrowserTestBase::UsingOSMesa() const { 309 bool BrowserTestBase::UsingOSMesa() const {
294 CommandLine* cmd = CommandLine::ForCurrentProcess(); 310 CommandLine* cmd = CommandLine::ForCurrentProcess();
295 return cmd->GetSwitchValueASCII(switches::kUseGL) == 311 return cmd->GetSwitchValueASCII(switches::kUseGL) ==
296 gfx::kGLImplementationOSMesaName; 312 gfx::kGLImplementationOSMesaName;
297 } 313 }
298 314
299 } // namespace content 315 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698