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/process_util.h" | 10 #include "base/process_util.h" |
11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
12 #include "content/public/common/main_function_params.h" | 12 #include "content/public/common/main_function_params.h" |
13 | 13 |
14 #if defined(OS_MACOSX) | 14 #if defined(OS_MACOSX) |
15 #include "base/mac/mac_util.h" | 15 #include "base/mac/mac_util.h" |
16 #include "base/system_monitor/system_monitor.h" | 16 #include "base/system_monitor/system_monitor.h" |
17 #endif | 17 #endif |
18 | 18 |
19 #if defined(OS_ANDROID) | 19 #if defined(OS_ANDROID) |
| 20 #include "base/threading/thread_restrictions.h" |
20 #include "content/public/browser/browser_main_runner.h" | 21 #include "content/public/browser/browser_main_runner.h" |
| 22 #include "content/public/browser/browser_thread.h" |
21 #endif | 23 #endif |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
25 #if defined(OS_POSIX) | 27 #if defined(OS_POSIX) |
26 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make | 28 // On SIGTERM (sent by the runner on timeouts), dump a stack trace (to make |
27 // debugging easier) and also exit with a known error code (so that the test | 29 // debugging easier) and also exit with a known error code (so that the test |
28 // framework considers this a failure -- http://crbug.com/57578). | 30 // framework considers this a failure -- http://crbug.com/57578). |
29 // Note: We only want to do this in the browser process, and not forked | 31 // Note: We only want to do this in the browser process, and not forked |
30 // processes. That might lead to hangs because of locks inside tcmalloc or the | 32 // processes. That might lead to hangs because of locks inside tcmalloc or the |
(...skipping 21 matching lines...) Expand all Loading... |
52 base::mac::SetOverrideAmIBundled(true); | 54 base::mac::SetOverrideAmIBundled(true); |
53 base::SystemMonitor::AllocateSystemIOPorts(); | 55 base::SystemMonitor::AllocateSystemIOPorts(); |
54 #endif | 56 #endif |
55 | 57 |
56 #if defined(OS_POSIX) | 58 #if defined(OS_POSIX) |
57 handle_sigterm_ = true; | 59 handle_sigterm_ = true; |
58 #endif | 60 #endif |
59 } | 61 } |
60 | 62 |
61 BrowserTestBase::~BrowserTestBase() { | 63 BrowserTestBase::~BrowserTestBase() { |
| 64 #if defined(OS_ANDROID) |
| 65 // RemoteTestServer can cause wait on the UI thread. |
| 66 base::ThreadRestrictions::ScopedAllowWait allow_wait; |
| 67 test_server_.reset(NULL); |
| 68 #endif |
62 } | 69 } |
63 | 70 |
64 void BrowserTestBase::SetUp() { | 71 void BrowserTestBase::SetUp() { |
65 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 72 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
66 | 73 |
67 // The tests assume that file:// URIs can freely access other file:// URIs. | 74 // The tests assume that file:// URIs can freely access other file:// URIs. |
68 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); | 75 command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); |
69 | 76 |
70 command_line->AppendSwitch(switches::kDomAutomationController); | 77 command_line->AppendSwitch(switches::kDomAutomationController); |
71 | 78 |
72 command_line->AppendSwitch(switches::kSkipGpuDataLoading); | 79 command_line->AppendSwitch(switches::kSkipGpuDataLoading); |
73 | 80 |
74 MainFunctionParams params(*command_line); | 81 MainFunctionParams params(*command_line); |
75 params.ui_task = | 82 params.ui_task = |
76 new base::Closure( | 83 new base::Closure( |
77 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); | 84 base::Bind(&BrowserTestBase::ProxyRunTestOnMainThreadLoop, this)); |
78 | 85 |
79 SetUpInProcessBrowserTestFixture(); | 86 SetUpInProcessBrowserTestFixture(); |
80 #if defined(OS_ANDROID) | 87 #if defined(OS_ANDROID) |
81 BrowserMainRunner::Create()->Initialize(params); | 88 BrowserMainRunner::Create()->Initialize(params); |
| 89 // We are done running the test by now. During teardown we |
| 90 // need to be able to perform IO. |
| 91 base::ThreadRestrictions::SetIOAllowed(true); |
| 92 BrowserThread::PostTask( |
| 93 BrowserThread::IO, FROM_HERE, |
| 94 base::Bind(base::IgnoreResult(&base::ThreadRestrictions::SetIOAllowed), |
| 95 true)); |
82 #else | 96 #else |
83 BrowserMain(params); | 97 BrowserMain(params); |
84 #endif | 98 #endif |
85 TearDownInProcessBrowserTestFixture(); | 99 TearDownInProcessBrowserTestFixture(); |
86 } | 100 } |
87 | 101 |
88 void BrowserTestBase::TearDown() { | 102 void BrowserTestBase::TearDown() { |
89 } | 103 } |
90 | 104 |
91 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { | 105 void BrowserTestBase::ProxyRunTestOnMainThreadLoop() { |
92 #if defined(OS_POSIX) | 106 #if defined(OS_POSIX) |
93 if (handle_sigterm_) { | 107 if (handle_sigterm_) { |
94 g_browser_process_pid = base::GetCurrentProcId(); | 108 g_browser_process_pid = base::GetCurrentProcId(); |
95 signal(SIGTERM, DumpStackTraceSignalHandler); | 109 signal(SIGTERM, DumpStackTraceSignalHandler); |
96 } | 110 } |
97 #endif // defined(OS_POSIX) | 111 #endif // defined(OS_POSIX) |
98 RunTestOnMainThreadLoop(); | 112 RunTestOnMainThreadLoop(); |
99 } | 113 } |
100 | 114 |
101 void BrowserTestBase::CreateTestServer(const FilePath& test_server_base) { | 115 void BrowserTestBase::CreateTestServer(const FilePath& test_server_base) { |
102 CHECK(!test_server_.get()); | 116 CHECK(!test_server_.get()); |
103 test_server_.reset(new net::TestServer( | 117 test_server_.reset(new net::TestServer( |
104 net::TestServer::TYPE_HTTP, | 118 net::TestServer::TYPE_HTTP, |
105 net::TestServer::kLocalhost, | 119 net::TestServer::kLocalhost, |
106 test_server_base)); | 120 test_server_base)); |
107 } | 121 } |
108 | 122 |
109 } // namespace content | 123 } // namespace content |
OLD | NEW |