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/test/browser_test_base.h" | 5 #include "content/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" |
| 10 #include "base/process_util.h" |
9 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
10 #include "content/public/common/main_function_params.h" | 12 #include "content/public/common/main_function_params.h" |
11 #include "sandbox/win/src/dep.h" | 13 #include "sandbox/win/src/dep.h" |
12 | 14 |
13 #if defined(OS_MACOSX) | 15 #if defined(OS_MACOSX) |
14 #include "base/mac/mac_util.h" | 16 #include "base/mac/mac_util.h" |
15 #include "base/system_monitor/system_monitor.h" | 17 #include "base/system_monitor/system_monitor.h" |
16 #endif | 18 #endif |
17 | 19 |
18 extern int BrowserMain(const content::MainFunctionParams&); | 20 extern int BrowserMain(const content::MainFunctionParams&); |
19 | 21 |
| 22 namespace { |
| 23 |
| 24 #if defined(OS_POSIX) |
| 25 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make |
| 26 // debugging easier) and also exit with a known error code (so that the test |
| 27 // framework considers this a failure -- http://crbug.com/57578). |
| 28 // Note: We only want to do this in the browser process, and not forked |
| 29 // processes. That might lead to hangs because of locks inside tcmalloc or the |
| 30 // OS. See http://crbug.com/141302. |
| 31 static int g_browser_process_pid; |
| 32 static void DumpStackTraceSignalHandler(int signal) { |
| 33 if (g_browser_process_pid == base::GetCurrentProcId()) |
| 34 base::debug::StackTrace().PrintBacktrace(); |
| 35 _exit(128 + signal); |
| 36 } |
| 37 #endif // defined(OS_POSIX) |
| 38 |
| 39 } // namespace |
| 40 |
20 BrowserTestBase::BrowserTestBase() { | 41 BrowserTestBase::BrowserTestBase() { |
21 #if defined(OS_MACOSX) | 42 #if defined(OS_MACOSX) |
22 base::mac::SetOverrideAmIBundled(true); | 43 base::mac::SetOverrideAmIBundled(true); |
23 base::SystemMonitor::AllocateSystemIOPorts(); | 44 base::SystemMonitor::AllocateSystemIOPorts(); |
24 #endif | 45 #endif |
| 46 |
| 47 #if defined(OS_POSIX) |
| 48 handle_sigterm_ = true; |
| 49 #endif |
25 } | 50 } |
26 | 51 |
27 BrowserTestBase::~BrowserTestBase() { | 52 BrowserTestBase::~BrowserTestBase() { |
28 } | 53 } |
29 | 54 |
30 void BrowserTestBase::SetUp() { | 55 void BrowserTestBase::SetUp() { |
31 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 56 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
32 | 57 |
33 // The tests assume that file:// URIs can freely access other file:// URIs. | 58 // The tests assume that file:// URIs can freely access other file:// URIs. |
34 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); | 59 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); |
35 | 60 |
36 command_line->AppendSwitch(switches::kDomAutomationController); | 61 command_line->AppendSwitch(switches::kDomAutomationController); |
37 | 62 |
38 content::MainFunctionParams params(*command_line); | 63 content::MainFunctionParams params(*command_line); |
39 params.ui_task = | 64 params.ui_task = |
40 new base::Closure( | 65 new base::Closure( |
41 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); | 66 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); |
42 | 67 |
43 SetUpInProcessBrowserTestFixture(); | 68 SetUpInProcessBrowserTestFixture(); |
44 BrowserMain(params); | 69 BrowserMain(params); |
45 TearDownInProcessBrowserTestFixture(); | 70 TearDownInProcessBrowserTestFixture(); |
46 } | 71 } |
47 | 72 |
48 void BrowserTestBase::TearDown() { | 73 void BrowserTestBase::TearDown() { |
49 } | 74 } |
50 | 75 |
51 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { | 76 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { |
| 77 #if defined(OS_POSIX) |
| 78 if (handle_sigterm_) { |
| 79 g_browser_process_pid = base::GetCurrentProcId(); |
| 80 signal(SIGTERM, DumpStackTraceSignalHandler); |
| 81 } |
| 82 #endif // defined(OS_POSIX) |
52 RunTestOnMainThreadLoop(); | 83 RunTestOnMainThreadLoop(); |
53 } | 84 } |
54 | 85 |
55 void BrowserTestBase::CreateTestServer(const char* test_server_base) { | 86 void BrowserTestBase::CreateTestServer(const char* test_server_base) { |
56 CHECK(!test_server_.get()); | 87 CHECK(!test_server_.get()); |
57 test_server_.reset(new net::TestServer( | 88 test_server_.reset(new net::TestServer( |
58 net::TestServer::TYPE_HTTP, | 89 net::TestServer::TYPE_HTTP, |
59 net::TestServer::kLocalhost, | 90 net::TestServer::kLocalhost, |
60 FilePath().AppendASCII(test_server_base))); | 91 FilePath().AppendASCII(test_server_base))); |
61 } | 92 } |
OLD | NEW |