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