| 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/i18n/icu_util.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 13 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 15 #include "content/public/app/content_main.h" | 15 #include "content/public/app/content_main.h" |
| 16 #include "content/browser/renderer_host/render_process_host_impl.h" | 16 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/tracing_controller.h" |
| 18 #include "content/public/common/content_switches.h" | 19 #include "content/public/common/content_switches.h" |
| 19 #include "content/public/common/main_function_params.h" | 20 #include "content/public/common/main_function_params.h" |
| 20 #include "content/public/test/test_launcher.h" | 21 #include "content/public/test/test_launcher.h" |
| 21 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
| 22 #include "net/base/net_errors.h" | 23 #include "net/base/net_errors.h" |
| 23 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
| 24 #include "net/test/embedded_test_server/embedded_test_server.h" | 25 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 25 #include "ui/compositor/compositor_switches.h" | 26 #include "ui/compositor/compositor_switches.h" |
| 26 #include "ui/gl/gl_implementation.h" | 27 #include "ui/gl/gl_implementation.h" |
| 27 #include "ui/gl/gl_switches.h" | 28 #include "ui/gl/gl_switches.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 115 } |
| 115 | 116 |
| 116 return ResolveUsingPrevious(host, address_family, host_resolver_flags, | 117 return ResolveUsingPrevious(host, address_family, host_resolver_flags, |
| 117 addrlist, os_error); | 118 addrlist, os_error); |
| 118 } | 119 } |
| 119 | 120 |
| 120 private: | 121 private: |
| 121 virtual ~LocalHostResolverProc() {} | 122 virtual ~LocalHostResolverProc() {} |
| 122 }; | 123 }; |
| 123 | 124 |
| 125 void TraceDisableRecordingComplete(const base::Closure& quit, |
| 126 const base::FilePath& file_path) { |
| 127 LOG(ERROR) << "Tracing written to: " << file_path.value(); |
| 128 quit.Run(); |
| 129 } |
| 130 |
| 124 } // namespace | 131 } // namespace |
| 125 | 132 |
| 126 extern int BrowserMain(const MainFunctionParams&); | 133 extern int BrowserMain(const MainFunctionParams&); |
| 127 | 134 |
| 128 BrowserTestBase::BrowserTestBase() | 135 BrowserTestBase::BrowserTestBase() |
| 129 : expected_exit_code_(0), | 136 : expected_exit_code_(0), |
| 130 enable_pixel_output_(false), | 137 enable_pixel_output_(false), |
| 131 use_software_compositing_(false) { | 138 use_software_compositing_(false) { |
| 132 #if defined(OS_MACOSX) | 139 #if defined(OS_MACOSX) |
| 133 base::mac::SetOverrideAmIBundled(true); | 140 base::mac::SetOverrideAmIBundled(true); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 void BrowserTestBase::TearDown() { | 269 void BrowserTestBase::TearDown() { |
| 263 } | 270 } |
| 264 | 271 |
| 265 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { | 272 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { |
| 266 #if defined(OS_POSIX) | 273 #if defined(OS_POSIX) |
| 267 if (handle_sigterm_) { | 274 if (handle_sigterm_) { |
| 268 g_browser_process_pid = base::GetCurrentProcId(); | 275 g_browser_process_pid = base::GetCurrentProcId(); |
| 269 signal(SIGTERM, DumpStackTraceSignalHandler); | 276 signal(SIGTERM, DumpStackTraceSignalHandler); |
| 270 } | 277 } |
| 271 #endif // defined(OS_POSIX) | 278 #endif // defined(OS_POSIX) |
| 279 |
| 280 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTracing)) { |
| 281 base::debug::CategoryFilter category_filter( |
| 282 CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 283 switches::kEnableTracing)); |
| 284 TracingController::GetInstance()->EnableRecording( |
| 285 category_filter, |
| 286 base::debug::TraceOptions(base::debug::RECORD_CONTINUOUSLY), |
| 287 TracingController::EnableRecordingDoneCallback()); |
| 288 } |
| 289 |
| 272 RunTestOnMainThreadLoop(); | 290 RunTestOnMainThreadLoop(); |
| 291 |
| 292 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableTracing)) { |
| 293 base::FilePath trace_file = |
| 294 CommandLine::ForCurrentProcess()->GetSwitchValuePath( |
| 295 switches::kEnableTracingOutput); |
| 296 // If there was no file specified, put a hardcoded one in the current |
| 297 // working directory. |
| 298 if (trace_file.empty()) |
| 299 trace_file = base::FilePath().AppendASCII("trace.json"); |
| 300 |
| 301 // Wait for tracing to collect results from the renderers. |
| 302 base::RunLoop run_loop; |
| 303 TracingController::GetInstance()->DisableRecording( |
| 304 trace_file, |
| 305 base::Bind(&TraceDisableRecordingComplete, run_loop.QuitClosure())); |
| 306 run_loop.Run(); |
| 307 } |
| 273 } | 308 } |
| 274 | 309 |
| 275 void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) { | 310 void BrowserTestBase::CreateTestServer(const base::FilePath& test_server_base) { |
| 276 CHECK(!test_server_.get()); | 311 CHECK(!test_server_.get()); |
| 277 test_server_.reset(new net::SpawnedTestServer( | 312 test_server_.reset(new net::SpawnedTestServer( |
| 278 net::SpawnedTestServer::TYPE_HTTP, | 313 net::SpawnedTestServer::TYPE_HTTP, |
| 279 net::SpawnedTestServer::kLocalhost, | 314 net::SpawnedTestServer::kLocalhost, |
| 280 test_server_base)); | 315 test_server_base)); |
| 281 } | 316 } |
| 282 | 317 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 302 use_software_compositing_ = true; | 337 use_software_compositing_ = true; |
| 303 } | 338 } |
| 304 | 339 |
| 305 bool BrowserTestBase::UsingOSMesa() const { | 340 bool BrowserTestBase::UsingOSMesa() const { |
| 306 CommandLine* cmd = CommandLine::ForCurrentProcess(); | 341 CommandLine* cmd = CommandLine::ForCurrentProcess(); |
| 307 return cmd->GetSwitchValueASCII(switches::kUseGL) == | 342 return cmd->GetSwitchValueASCII(switches::kUseGL) == |
| 308 gfx::kGLImplementationOSMesaName; | 343 gfx::kGLImplementationOSMesaName; |
| 309 } | 344 } |
| 310 | 345 |
| 311 } // namespace content | 346 } // namespace content |
| OLD | NEW |