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 "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 Loading... |
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 222 } |
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 |
227 params.ui_task = | 233 base::Closure* ui_task = |
228 new base::Closure( | 234 new base::Closure( |
229 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); | 235 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); |
230 | 236 |
231 #if defined(OS_ANDROID) | 237 #if defined(OS_ANDROID) |
| 238 MainFunctionParams params(*command_line); |
| 239 params.ui_task = ui_task; |
232 BrowserMainRunner::Create()->Initialize(params); | 240 BrowserMainRunner::Create()->Initialize(params); |
233 // We are done running the test by now. During teardown we | 241 // We are done running the test by now. During teardown we |
234 // need to be able to perform IO. | 242 // need to be able to perform IO. |
235 base::ThreadRestrictions::SetIOAllowed(true); | 243 base::ThreadRestrictions::SetIOAllowed(true); |
236 BrowserThread::PostTask( | 244 BrowserThread::PostTask( |
237 BrowserThread::IO, FROM_HERE, | 245 BrowserThread::IO, FROM_HERE, |
238 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), | 246 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
239 true)); | 247 true)); |
240 #else | 248 #else |
241 BrowserMain(params); | 249 GetContentMainParams()->ui_task = ui_task; |
| 250 ContentMain(*GetContentMainParams()); |
242 #endif | 251 #endif |
243 TearDownInProcessBrowserTestFixture(); | 252 TearDownInProcessBrowserTestFixture(); |
244 } | 253 } |
245 | 254 |
246 void BrowserTestBase::TearDown() { | 255 void BrowserTestBase::TearDown() { |
247 } | 256 } |
248 | 257 |
249 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { | 258 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { |
250 #if defined(OS_POSIX) | 259 #if defined(OS_POSIX) |
251 if (handle_sigterm_) { | 260 if (handle_sigterm_) { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 use_software_compositing_ = true; | 299 use_software_compositing_ = true; |
291 } | 300 } |
292 | 301 |
293 bool BrowserTestBase::UsingOSMesa() const { | 302 bool BrowserTestBase::UsingOSMesa() const { |
294 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 303 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
295 return cmd->GetSwitchValueASCII(switches::kUseGL) == | 304 return cmd->GetSwitchValueASCII(switches::kUseGL) == |
296 gfx::kGLImplementationOSMesaName; | 305 gfx::kGLImplementationOSMesaName; |
297 } | 306 } |
298 | 307 |
299 } // namespace content | 308 } // namespace content |
OLD | NEW |