Chromium Code Reviews| 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 if (command_line->HasSwitch(switches::kSingleProcess)) |
| 143 // Hide windows on show. | 147 RenderProcessHost::set_run_renderer_in_process(true); |
|
Scott Hess - ex-Googler
2010/11/10 18:27:05
Previous code stored the original value in origina
| |
| 144 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) | |
| 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 | 148 |
| 154 // Single-process mode is not set in BrowserMain so it needs to be processed | 149 // Single-process mode is not set in BrowserMain so it needs to be processed |
| 155 // explicitly. | 150 // explicitly. |
| 156 original_single_process_ = RenderProcessHost::run_renderer_in_process(); | 151 original_single_process_ = RenderProcessHost::run_renderer_in_process(); |
| 157 if (command_line->HasSwitch(switches::kSingleProcess)) | |
| 158 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 | 153 |
| 192 #if defined(OS_CHROMEOS) | 154 #if defined(OS_CHROMEOS) |
| 193 chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); | 155 chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); |
| 194 | 156 |
| 195 // Make sure that the log directory exists. | 157 // Make sure that the log directory exists. |
| 196 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); | 158 FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); |
| 197 file_util::CreateDirectory(log_dir); | 159 file_util::CreateDirectory(log_dir); |
| 198 #endif // defined(OS_CHROMEOS) | 160 #endif // defined(OS_CHROMEOS) |
| 199 | 161 |
| 200 SandboxInitWrapper sandbox_wrapper; | 162 SandboxInitWrapper sandbox_wrapper; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 #if defined(OS_LINUX) | 198 #if defined(OS_LINUX) |
| 237 // Initialize the RenderSandbox and Zygote hosts. Apparently they get used | 199 // Initialize the RenderSandbox and Zygote hosts. Apparently they get used |
| 238 // for InProcessBrowserTest, and this is not the normal browser startup path. | 200 // for InProcessBrowserTest, and this is not the normal browser startup path. |
| 239 Singleton<LinuxHostInit>::get(); | 201 Singleton<LinuxHostInit>::get(); |
| 240 #endif | 202 #endif |
| 241 | 203 |
| 242 BrowserMain(params); | 204 BrowserMain(params); |
| 243 TearDownInProcessBrowserTestFixture(); | 205 TearDownInProcessBrowserTestFixture(); |
| 244 } | 206 } |
| 245 | 207 |
| 208 void InProcessBrowserTest::PrepareCommonInProcessBrowserTestCommandLine( | |
| 209 CommandLine* arguments) { | |
| 210 #if defined(OS_WIN) | |
| 211 // Hide windows on show. | |
| 212 if (!command_line->HasSwitch(kUnitTestShowWindows) && !show_window_) | |
| 213 BrowserView::SetShowState(SW_HIDE); | |
| 214 #endif | |
| 215 | |
| 216 if (dom_automation_enabled_) | |
| 217 command_line->AppendSwitch(switches::kDomAutomationController); | |
| 218 | |
| 219 // This is a Browser test. | |
| 220 command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); | |
| 221 | |
| 222 #if defined(OS_WIN) | |
| 223 // The Windows sandbox requires that the browser and child processes are the | |
| 224 // same binary. So we launch browser_process.exe which loads chrome.dll | |
| 225 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | |
| 226 command_line->GetProgram()); | |
| 227 #else | |
| 228 // Explicitly set the path of the binary used for child processes, otherwise | |
| 229 // they'll try to use browser_tests which doesn't contain ChromeMain. | |
| 230 FilePath subprocess_path; | |
| 231 PathService::Get(base::FILE_EXE, &subprocess_path); | |
| 232 subprocess_path = subprocess_path.DirName(); | |
| 233 subprocess_path = subprocess_path.AppendASCII(WideToASCII( | |
| 234 chrome::kBrowserProcessExecutablePath)); | |
| 235 #if defined(OS_MACOSX) | |
| 236 // Recreate the real environment, run the helper within the app bundle. | |
| 237 subprocess_path = subprocess_path.DirName().DirName(); | |
| 238 DCHECK_EQ(subprocess_path.BaseName().value(), "Contents"); | |
| 239 subprocess_path = | |
| 240 subprocess_path.Append("Versions").Append(chrome::kChromeVersion); | |
| 241 subprocess_path = | |
| 242 subprocess_path.Append(chrome::kHelperProcessExecutablePath); | |
| 243 #endif | |
| 244 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | |
| 245 subprocess_path); | |
| 246 #endif | |
| 247 | |
| 248 // If ncecessary, disable TabCloseableStateWatcher. | |
| 249 if (!tab_closeable_state_watcher_enabled_) | |
| 250 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); | |
| 251 } | |
| 252 | |
| 253 | |
| 246 bool InProcessBrowserTest::CreateUserDataDirectory() { | 254 bool InProcessBrowserTest::CreateUserDataDirectory() { |
| 247 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 255 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); |
| 248 FilePath user_data_dir = | 256 FilePath user_data_dir = |
| 249 command_line->GetSwitchValuePath(switches::kUserDataDir); | 257 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 250 if (user_data_dir.empty()) { | 258 if (user_data_dir.empty()) { |
| 251 if (temp_user_data_dir_.CreateUniqueTempDir() && | 259 if (temp_user_data_dir_.CreateUniqueTempDir() && |
| 252 temp_user_data_dir_.IsValid()) { | 260 temp_user_data_dir_.IsValid()) { |
| 253 user_data_dir = temp_user_data_dir_.path(); | 261 user_data_dir = temp_user_data_dir_.path(); |
| 254 } else { | 262 } else { |
| 255 LOG(ERROR) << "Could not create temporary user data directory \"" | 263 LOG(ERROR) << "Could not create temporary user data directory \"" |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 return; | 373 return; |
| 366 | 374 |
| 367 // Invoke CloseAllBrowsersAndExit on a running message loop. | 375 // Invoke CloseAllBrowsersAndExit on a running message loop. |
| 368 // CloseAllBrowsersAndExit exits the message loop after everything has been | 376 // CloseAllBrowsersAndExit exits the message loop after everything has been |
| 369 // shut down properly. | 377 // shut down properly. |
| 370 MessageLoopForUI::current()->PostTask( | 378 MessageLoopForUI::current()->PostTask( |
| 371 FROM_HERE, | 379 FROM_HERE, |
| 372 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); | 380 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); |
| 373 ui_test_utils::RunMessageLoop(); | 381 ui_test_utils::RunMessageLoop(); |
| 374 } | 382 } |
| OLD | NEW |