Chromium Code Reviews| 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 "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 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 | 97 |
| 98 InProcessBrowserTest::~InProcessBrowserTest() { | 98 InProcessBrowserTest::~InProcessBrowserTest() { |
| 99 } | 99 } |
| 100 | 100 |
| 101 void InProcessBrowserTest::SetUp() { | 101 void InProcessBrowserTest::SetUp() { |
| 102 // Remember the command line. Normally this doesn't matter, because the test | 102 // Remember the command line. Normally this doesn't matter, because the test |
| 103 // harness creates a new process for each test, but when the test harness is | 103 // harness creates a new process for each test, but when the test harness is |
| 104 // running in single process mode, we can't let one test's command-line | 104 // running in single process mode, we can't let one test's command-line |
| 105 // changes (e.g. enabling DOM automation) affect other tests. | 105 // changes (e.g. enabling DOM automation) affect other tests. |
| 106 // TODO(phajdan.jr): This save/restore logic is unnecessary. Remove it. | 106 // TODO(phajdan.jr): This save/restore logic is unnecessary. Remove it. |
| 107 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 107 CommandLine* command_line = CommandLine::current_process_commandline_; |
|
Paweł Hajdan Jr.
2011/02/25 18:01:53
nit: Accessing a private variable like that is ugl
msw
2011/05/10 23:18:43
Done (r76339).
| |
| 108 original_command_line_.reset(new CommandLine(*command_line)); | 108 original_command_line_.reset(new CommandLine(*command_line)); |
| 109 | 109 |
| 110 // Create a temporary user data directory if required. | 110 // Create a temporary user data directory if required. |
| 111 ASSERT_TRUE(CreateUserDataDirectory()) | 111 ASSERT_TRUE(CreateUserDataDirectory()) |
| 112 << "Could not create user data directory."; | 112 << "Could not create user data directory."; |
| 113 | 113 |
| 114 // The unit test suite creates a testingbrowser, but we want the real thing. | 114 // The unit test suite creates a testingbrowser, but we want the real thing. |
| 115 // Delete the current one. We'll install the testing one in TearDown. | 115 // Delete the current one. We'll install the testing one in TearDown. |
| 116 delete g_browser_process; | 116 delete g_browser_process; |
| 117 g_browser_process = NULL; | 117 g_browser_process = NULL; |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 209 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, | 209 command_line->AppendSwitchPath(switches::kBrowserSubprocessPath, |
| 210 subprocess_path); | 210 subprocess_path); |
| 211 #endif | 211 #endif |
| 212 | 212 |
| 213 // If neccessary, disable TabCloseableStateWatcher. | 213 // If neccessary, disable TabCloseableStateWatcher. |
| 214 if (!tab_closeable_state_watcher_enabled_) | 214 if (!tab_closeable_state_watcher_enabled_) |
| 215 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); | 215 command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); |
| 216 } | 216 } |
| 217 | 217 |
| 218 bool InProcessBrowserTest::CreateUserDataDirectory() { | 218 bool InProcessBrowserTest::CreateUserDataDirectory() { |
| 219 CommandLine* command_line = CommandLine::ForCurrentProcessMutable(); | 219 static CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 220 FilePath user_data_dir = | 220 FilePath user_data_dir = |
| 221 command_line->GetSwitchValuePath(switches::kUserDataDir); | 221 command_line->GetSwitchValuePath(switches::kUserDataDir); |
| 222 if (user_data_dir.empty()) { | 222 if (user_data_dir.empty()) { |
| 223 if (temp_user_data_dir_.CreateUniqueTempDir() && | 223 if (temp_user_data_dir_.CreateUniqueTempDir() && |
| 224 temp_user_data_dir_.IsValid()) { | 224 temp_user_data_dir_.IsValid()) { |
| 225 user_data_dir = temp_user_data_dir_.path(); | 225 user_data_dir = temp_user_data_dir_.path(); |
| 226 } else { | 226 } else { |
| 227 LOG(ERROR) << "Could not create temporary user data directory \"" | 227 LOG(ERROR) << "Could not create temporary user data directory \"" |
| 228 << temp_user_data_dir_.path().value() << "\"."; | 228 << temp_user_data_dir_.path().value() << "\"."; |
| 229 return false; | 229 return false; |
| 230 } | 230 } |
| 231 } | 231 } |
| 232 return test_launcher_utils::OverrideUserDataDir(user_data_dir); | 232 return test_launcher_utils::OverrideUserDataDir(user_data_dir); |
| 233 } | 233 } |
| 234 | 234 |
| 235 void InProcessBrowserTest::TearDown() { | 235 void InProcessBrowserTest::TearDown() { |
| 236 // Reinstall testing browser process. | 236 // Reinstall testing browser process. |
| 237 delete g_browser_process; | 237 delete g_browser_process; |
| 238 g_browser_process = new TestingBrowserProcess(); | 238 g_browser_process = new TestingBrowserProcess(); |
| 239 | 239 |
| 240 browser_shutdown::delete_resources_on_shutdown = true; | 240 browser_shutdown::delete_resources_on_shutdown = true; |
| 241 | 241 |
| 242 #if defined(OS_WIN) | 242 #if defined(OS_WIN) |
| 243 BrowserView::SetShowState(-1); | 243 BrowserView::SetShowState(-1); |
| 244 #endif | 244 #endif |
| 245 | 245 |
| 246 *CommandLine::ForCurrentProcessMutable() = *original_command_line_; | 246 *CommandLine::current_process_commandline_ = *original_command_line_; |
| 247 RenderProcessHost::set_run_renderer_in_process(original_single_process_); | 247 RenderProcessHost::set_run_renderer_in_process(original_single_process_); |
| 248 } | 248 } |
| 249 | 249 |
| 250 void InProcessBrowserTest::AddTabAtIndexToBrowser( | 250 void InProcessBrowserTest::AddTabAtIndexToBrowser( |
| 251 Browser* browser, | 251 Browser* browser, |
| 252 int index, | 252 int index, |
| 253 const GURL& url, | 253 const GURL& url, |
| 254 PageTransition::Type transition) { | 254 PageTransition::Type transition) { |
| 255 browser::NavigateParams params(browser, url, transition); | 255 browser::NavigateParams params(browser, url, transition); |
| 256 params.tabstrip_index = index; | 256 params.tabstrip_index = index; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 return; | 352 return; |
| 353 | 353 |
| 354 // Invoke CloseAllBrowsersAndExit on a running message loop. | 354 // Invoke CloseAllBrowsersAndExit on a running message loop. |
| 355 // CloseAllBrowsersAndExit exits the message loop after everything has been | 355 // CloseAllBrowsersAndExit exits the message loop after everything has been |
| 356 // shut down properly. | 356 // shut down properly. |
| 357 MessageLoopForUI::current()->PostTask( | 357 MessageLoopForUI::current()->PostTask( |
| 358 FROM_HERE, | 358 FROM_HERE, |
| 359 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); | 359 NewRunnableFunction(&BrowserList::CloseAllBrowsersAndExit)); |
| 360 ui_test_utils::RunMessageLoop(); | 360 ui_test_utils::RunMessageLoop(); |
| 361 } | 361 } |
| OLD | NEW |