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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 << "Could not set up user data directory."; | 131 << "Could not set up user data directory."; |
132 | 132 |
133 // Don't delete the resources when BrowserMain returns. Many ui classes | 133 // Don't delete the resources when BrowserMain returns. Many ui classes |
134 // cache SkBitmaps in a static field so that if we delete the resource | 134 // cache SkBitmaps in a static field so that if we delete the resource |
135 // bundle we'll crash. | 135 // bundle we'll crash. |
136 browser_shutdown::delete_resources_on_shutdown = false; | 136 browser_shutdown::delete_resources_on_shutdown = false; |
137 | 137 |
138 // Allow subclasses the opportunity to make changes to the command line before | 138 // Allow subclasses the opportunity to make changes to the command line before |
139 // running any tests. | 139 // running any tests. |
140 SetUpCommandLine(command_line); | 140 SetUpCommandLine(command_line); |
| 141 // Add command line arguments that are used by all InProcessBrowserTests. |
| 142 PrepareCommonInProcessBrowserTestCommandLine(command_line); |
| 143 // Add browser command line arguments that are used by all tests. |
| 144 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); |
141 | 145 |
142 #if defined(OS_WIN) | 146 // Save the single process mode state before it was reset in this test. This |
143 // Hide windows on show. | 147 // state will be recovered in TearDown(). single-process mode is not set in |
144 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) | 148 // BrowserMain so it needs to be processed explicitly. |
145 BrowserView::SetShowState(SW_HIDE); | |
146 #endif | |
147 | |
148 if (dom_automation_enabled_) | |
149 command_line->AppendSwitch(switches::kDomAutomationController); | |
150 | |
151 // This is a Browser test. | |
152 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); | |
153 | |
154 // Single-process mode is not set in BrowserMain so it needs to be processed | |
155 // explicitly. | |
156 original_single_process_ = RenderProcessHost::run_renderer_in_process(); | 149 original_single_process_ = RenderProcessHost::run_renderer_in_process(); |
157 if (command_line->HasSwitch(switches::kSingleProcess)) | 150 if (command_line->HasSwitch(switches::kSingleProcess)) |
158 RenderProcessHost::set_run_renderer_in_process(true); | 151 RenderProcessHost::set_run_renderer_in_process(true); |
159 | 152 |
160 #if defined(OS_WIN) | |
161 // The Windows sandbox requires that the browser and child processes are the | |
162 // same binary. So we launch browser_process.exe which loads chrome.dll | |
163 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | |
164 command_line->GetProgram()); | |
165 #else | |
166 // Explicitly set the path of the binary used for child processes, otherwise | |
167 // they'll try to use browser_tests which doesn't contain ChromeMain. | |
168 FilePath subprocess_path; | |
169 PathService::Get(base::FILE_EXE, &subprocess_path); | |
170 subprocess_path = subprocess_path.DirName(); | |
171 subprocess_path = subprocess_path.AppendASCII(WideToASCII( | |
172 chrome::kBrowserProcessExecutablePath)); | |
173 #if defined(OS_MACOSX) | |
174 // Recreate the real environment, run the helper within the app bundle. | |
175 subprocess_path = subprocess_path.DirName().DirName(); | |
176 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | |
177 subprocess_path = | |
178 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); | |
179 subprocess_path = | |
180 subprocess_path.Append(chrome::kHelperProcessExecutablePath); | |
181 #endif | |
182 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | |
183 subprocess_path); | |
184 #endif | |
185 | |
186 // If ncecessary, disable TabCloseableStateWatcher. | |
187 if (!tab_closeable_state_watcher_enabled_) | |
188 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); | |
189 | |
190 test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); | |
191 | |
192 #if defined(OS_CHROMEOS) | 153 #if defined(OS_CHROMEOS) |
193 chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); | 154 chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); |
194 | 155 |
195 // Make sure that the log directory exists. | 156 // Make sure that the log directory exists. |
196 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); | 157 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); |
197 file_util::CreateDirectory(log_dir); | 158 file_util::CreateDirectory(log_dir); |
198 #endif // defined(OS_CHROMEOS) | 159 #endif // defined(OS_CHROMEOS) |
199 | 160 |
200 SandboxInitWrapper sandbox_wrapper; | 161 SandboxInitWrapper sandbox_wrapper; |
201 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); | 162 MainFunctionParams params(*command_line, sandbox_wrapper, NULL); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 #if defined(OS_LINUX) | 197 #if defined(OS_LINUX) |
237 // Initialize the RenderSandbox and Zygote hosts. Apparently they get used | 198 // Initialize the RenderSandbox and Zygote hosts. Apparently they get used |
238 // for InProcessBrowserTest, and this is not the normal browser startup path. | 199 // for InProcessBrowserTest, and this is not the normal browser startup path. |
239 Singleton<LinuxHostInit>::get(); | 200 Singleton<LinuxHostInit>::get(); |
240 #endif | 201 #endif |
241 | 202 |
242 BrowserMain(params); | 203 BrowserMain(params); |
243 TearDownInProcessBrowserTestFixture(); | 204 TearDownInProcessBrowserTestFixture(); |
244 } | 205 } |
245 | 206 |
| 207 void InProcessBrowserTest::PrepareCommonInProcessBrowserTestCommandLine( |
| 208 CommandLine* command_line) { |
| 209 #if defined(OS_WIN) |
| 210 // Hide windows on show. |
| 211 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) |
| 212 BrowserView::SetShowState(SW_HIDE); |
| 213 #endif |
| 214 |
| 215 if (dom_automation_enabled_) |
| 216 command_line->AppendSwitch(switches::kDomAutomationController); |
| 217 |
| 218 // This is a Browser test. |
| 219 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); |
| 220 |
| 221 #if defined(OS_WIN) |
| 222 // The Windows sandbox requires that the browser and child processes are the |
| 223 // same binary. So we launch browser_process.exe which loads chrome.dll |
| 224 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
| 225 command_line->GetProgram()); |
| 226 #else |
| 227 // Explicitly set the path of the binary used for child processes, otherwise |
| 228 // they'll try to use browser_tests which doesn't contain ChromeMain. |
| 229 FilePath subprocess_path; |
| 230 PathService::Get(base::FILE_EXE, &subprocess_path); |
| 231 subprocess_path = subprocess_path.DirName(); |
| 232 subprocess_path = subprocess_path.AppendASCII(WideToASCII( |
| 233 chrome::kBrowserProcessExecutablePath)); |
| 234 #if defined(OS_MACOSX) |
| 235 // Recreate the real environment, run the helper within the app bundle. |
| 236 subprocess_path = subprocess_path.DirName().DirName(); |
| 237 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); |
| 238 subprocess_path = |
| 239 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); |
| 240 subprocess_path = |
| 241 subprocess_path.Append(chrome::kHelperProcessExecutablePath); |
| 242 #endif |
| 243 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
| 244 subprocess_path); |
| 245 #endif |
| 246 |
| 247 // If ncecessary, disable TabCloseableStateWatcher. |
| 248 if (!tab_closeable_state_watcher_enabled_) |
| 249 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); |
| 250 } |
| 251 |
| 252 |
246 bool InProcessBrowserTest::CreateUserDataDirectory() { | 253 bool InProcessBrowserTest::CreateUserDataDirectory() { |
247 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 254 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); |
248 FilePath user_data_dir = | 255 FilePath user_data_dir = |
249 command_line->GetSwitchValuePath(switches::kUserDataDir); | 256 command_line->GetSwitchValuePath(switches::kUserDataDir); |
250 if (user_data_dir.empty()) { | 257 if (user_data_dir.empty()) { |
251 if (temp_user_data_dir_.CreateUniqueTempDir() && | 258 if (temp_user_data_dir_.CreateUniqueTempDir() && |
252 temp_user_data_dir_.IsValid()) { | 259 temp_user_data_dir_.IsValid()) { |
253 user_data_dir = temp_user_data_dir_.path(); | 260 user_data_dir = temp_user_data_dir_.path(); |
254 } else { | 261 } else { |
255 LOG(ERROR) << "Could not create temporary user data directory \"" | 262 LOG(ERROR) << "Could not create temporary user data directory \"" |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
365 return; | 372 return; |
366 | 373 |
367 // Invoke CloseAllBrowsersAndExit on a running message loop. | 374 // Invoke CloseAllBrowsersAndExit on a running message loop. |
368 // CloseAllBrowsersAndExit exits the message loop after everything has been | 375 // CloseAllBrowsersAndExit exits the message loop after everything has been |
369 // shut down properly. | 376 // shut down properly. |
370 MessageLoopForUI::current()->PostTask( | 377 MessageLoopForUI::current()->PostTask( |
371 FROM_HERE, | 378 FROM_HERE, |
372 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); | 379 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); |
373 ui_test_utils::RunMessageLoop(); | 380 ui_test_utils::RunMessageLoop(); |
374 } | 381 } |
OLD | NEW |