OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/test/in_process_browser_test.h" | 5 #include "chrome/test/in_process_browser_test.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/mac/scoped_nsautorelease_pool.h" | 10 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 << "Could not set up user data directory."; | 132 << "Could not set up user data directory."; |
133 | 133 |
134 // Don't delete the resources when BrowserMain returns. Many ui classes | 134 // Don't delete the resources when BrowserMain returns. Many ui classes |
135 // cache SkBitmaps in a static field so that if we delete the resource | 135 // cache SkBitmaps in a static field so that if we delete the resource |
136 // bundle we'll crash. | 136 // bundle we'll crash. |
137 browser_shutdown::delete_resources_on_shutdown = false; | 137 browser_shutdown::delete_resources_on_shutdown = false; |
138 | 138 |
139 // Allow subclasses the opportunity to make changes to the command line before | 139 // Allow subclasses the opportunity to make changes to the command line before |
140 // running any tests. | 140 // running any tests. |
141 SetUpCommandLine(command_line); | 141 SetUpCommandLine(command_line); |
| 142 // Add command line arguments that are used by all InProcessBrowserTests. |
| 143 PrepareTestCommandLine(command_line); |
| 144 |
| 145 // Save the single process mode state before it was reset in this test. This |
| 146 // state will be recovered in TearDown(). Single-process mode is not set in |
| 147 // BrowserMain so it needs to be processed explicitly. |
| 148 original_single_process_ = RenderProcessHost::run_renderer_in_process(); |
| 149 if (command_line->HasSwitch(switches::kSingleProcess)) |
| 150 RenderProcessHost::set_run_renderer_in_process(true); |
| 151 |
| 152 #if defined(OS_CHROMEOS) |
| 153 chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); |
| 154 |
| 155 // Make sure that the log directory exists. |
| 156 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); |
| 157 file_util::CreateDirectory(log_dir); |
| 158 #endif // defined(OS_CHROMEOS) |
| 159 |
| 160 SandboxInitWrapper sandbox_wrapper; |
| 161 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); |
| 162 params.ui_task = |
| 163 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); |
| 164 |
| 165 host_resolver_ = new net::RuleBasedHostResolverProc( |
| 166 new IntranetRedirectHostResolverProc(NULL)); |
| 167 |
| 168 // Something inside the browser does this lookup implicitly. Make it fail |
| 169 // to avoid external dependency. It won't break the tests. |
| 170 host_resolver_->AddSimulatedFailure("*.google.com"); |
| 171 |
| 172 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol |
| 173 // We don't want the test code to use it. |
| 174 host_resolver_->AddSimulatedFailure("wpad"); |
| 175 |
| 176 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( |
| 177 host_resolver_.get()); |
| 178 |
| 179 SetUpInProcessBrowserTestFixture(); |
| 180 |
| 181 BrowserMain(params); |
| 182 TearDownInProcessBrowserTestFixture(); |
| 183 } |
| 184 |
| 185 void InProcessBrowserTest::PrepareTestCommandLine( |
| 186 CommandLine* command_line) { |
| 187 // Propagate commandline settings from test_launcher_utils. |
| 188 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
142 | 189 |
143 #if defined(OS_WIN) | 190 #if defined(OS_WIN) |
144 // Hide windows on show. | 191 // Hide windows on show. |
145 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) | 192 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) |
146 BrowserView::SetShowState(SW_HIDE); | 193 BrowserView::SetShowState(SW_HIDE); |
147 #endif | 194 #endif |
148 | 195 |
149 if (dom_automation_enabled_) | 196 if (dom_automation_enabled_) |
150 command_line->AppendSwitch(switches::kDomAutomationController); | 197 command_line->AppendSwitch(switches::kDomAutomationController); |
151 | 198 |
152 // This is a Browser test. | 199 // This is a Browser test. |
153 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); | 200 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); |
154 | 201 |
155 // Single-process mode is not set in BrowserMain so it needs to be processed | |
156 // explicitly. | |
157 original_single_process_ = RenderProcessHost::run_renderer_in_process(); | |
158 if (command_line->HasSwitch(switches::kSingleProcess)) | |
159 RenderProcessHost::set_run_renderer_in_process(true); | |
160 | |
161 #if defined(OS_WIN) | 202 #if defined(OS_WIN) |
162 // The Windows sandbox requires that the browser and child processes are the | 203 // The Windows sandbox requires that the browser and child processes are the |
163 // same binary. So we launch browser_process.exe which loads chrome.dll | 204 // same binary. So we launch browser_process.exe which loads chrome.dll |
164 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | 205 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
165 command_line->GetProgram()); | 206 command_line->GetProgram()); |
166 #else | 207 #else |
167 // Explicitly set the path of the binary used for child processes, otherwise | 208 // Explicitly set the path of the binary used for child processes, otherwise |
168 // they'll try to use browser_tests which doesn't contain ChromeMain. | 209 // they'll try to use browser_tests which doesn't contain ChromeMain. |
169 FilePath subprocess_path; | 210 FilePath subprocess_path; |
170 PathService::Get(base::FILE_EXE, &subprocess_path); | 211 PathService::Get(base::FILE_EXE, &subprocess_path); |
171 #if defined(OS_MACOSX) | 212 #if defined(OS_MACOSX) |
172 // Recreate the real environment, run the helper within the app bundle. | 213 // Recreate the real environment, run the helper within the app bundle. |
173 subprocess_path = subprocess_path.DirName().DirName(); | 214 subprocess_path = subprocess_path.DirName().DirName(); |
174 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | 215 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
175 subprocess_path = | 216 subprocess_path = |
176 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); | 217 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); |
177 subprocess_path = | 218 subprocess_path = |
178 subprocess_path.Append(chrome::kHelperProcessExecutablePath); | 219 subprocess_path.Append(chrome::kHelperProcessExecutablePath); |
179 #endif | 220 #endif |
180 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | 221 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
181 subprocess_path); | 222 subprocess_path); |
182 #endif | 223 #endif |
183 | 224 |
184 // If ncecessary, disable TabCloseableStateWatcher. | 225 // If ncecessary, disable TabCloseableStateWatcher. |
185 if (!tab_closeable_state_watcher_enabled_) | 226 if (!tab_closeable_state_watcher_enabled_) |
186 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); | 227 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); |
187 | |
188 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | |
189 | |
190 #if defined(OS_CHROMEOS) | |
191 chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); | |
192 | |
193 // Make sure that the log directory exists. | |
194 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); | |
195 file_util::CreateDirectory(log_dir); | |
196 #endif // defined(OS_CHROMEOS) | |
197 | |
198 SandboxInitWrapper sandbox_wrapper; | |
199 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); | |
200 params.ui_task = | |
201 NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); | |
202 | |
203 host_resolver_ = new net::RuleBasedHostResolverProc( | |
204 new IntranetRedirectHostResolverProc(NULL)); | |
205 | |
206 // Something inside the browser does this lookup implicitly. Make it fail | |
207 // to avoid external dependency. It won't break the tests. | |
208 host_resolver_->AddSimulatedFailure("*.google.com"); | |
209 | |
210 // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol | |
211 // We don't want the test code to use it. | |
212 host_resolver_->AddSimulatedFailure("wpad"); | |
213 | |
214 net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( | |
215 host_resolver_.get()); | |
216 | |
217 SetUpInProcessBrowserTestFixture(); | |
218 | |
219 BrowserMain(params); | |
220 TearDownInProcessBrowserTestFixture(); | |
221 } | 228 } |
222 | 229 |
223 bool InProcessBrowserTest::CreateUserDataDirectory() { | 230 bool InProcessBrowserTest::CreateUserDataDirectory() { |
224 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 231 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); |
225 FilePath user_data_dir = | 232 FilePath user_data_dir = |
226 command_line->GetSwitchValuePath(switches::kUserDataDir); | 233 command_line->GetSwitchValuePath(switches::kUserDataDir); |
227 if (user_data_dir.empty()) { | 234 if (user_data_dir.empty()) { |
228 if (temp_user_data_dir_.CreateUniqueTempDir() && | 235 if (temp_user_data_dir_.CreateUniqueTempDir() && |
229 temp_user_data_dir_.IsValid()) { | 236 temp_user_data_dir_.IsValid()) { |
230 user_data_dir = temp_user_data_dir_.path(); | 237 user_data_dir = temp_user_data_dir_.path(); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 return; | 349 return; |
343 | 350 |
344 // Invoke CloseAllBrowsersAndExit on a running message loop. | 351 // Invoke CloseAllBrowsersAndExit on a running message loop. |
345 // CloseAllBrowsersAndExit exits the message loop after everything has been | 352 // CloseAllBrowsersAndExit exits the message loop after everything has been |
346 // shut down properly. | 353 // shut down properly. |
347 MessageLoopForUI::current()->PostTask( | 354 MessageLoopForUI::current()->PostTask( |
348 FROM_HERE, | 355 FROM_HERE, |
349 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); | 356 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); |
350 ui_test_utils::RunMessageLoop(); | 357 ui_test_utils::RunMessageLoop(); |
351 } | 358 } |
OLD | NEW |