diff options
author | lzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-16 00:38:26 +0000 |
---|---|---|
committer | lzheng@chromium.org <lzheng@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-11-16 00:38:26 +0000 |
commit | 03c79d5060fd71b50bf80ecd0ddce71c2c80f298 (patch) | |
tree | 7cf4725f4b298198e45de939056427d5e060e822 /chrome/test | |
parent | 9b2b3ae87d1b1a6e7f210b51e46c78c3ba920d44 (diff) | |
download | chromium_src-03c79d5060fd71b50bf80ecd0ddce71c2c80f298.zip chromium_src-03c79d5060fd71b50bf80ecd0ddce71c2c80f298.tar.gz chromium_src-03c79d5060fd71b50bf80ecd0ddce71c2c80f298.tar.bz2 |
Group cmdline settings in UI test and in_process_browser_test.
BUG=none
TEST=all UI tests and browser tests stays green.
Review URL: http://codereview.chromium.org/4724004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66202 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test')
-rw-r--r-- | chrome/test/in_process_browser_test.cc | 87 | ||||
-rw-r--r-- | chrome/test/in_process_browser_test.h | 4 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.cc | 73 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.h | 4 |
4 files changed, 94 insertions, 74 deletions
diff --git a/chrome/test/in_process_browser_test.cc b/chrome/test/in_process_browser_test.cc index c690cd2..08dd200 100644 --- a/chrome/test/in_process_browser_test.cc +++ b/chrome/test/in_process_browser_test.cc @@ -139,6 +139,53 @@ void InProcessBrowserTest::SetUp() { // Allow subclasses the opportunity to make changes to the command line before // running any tests. SetUpCommandLine(command_line); + // Add command line arguments that are used by all InProcessBrowserTests. + PrepareTestCommandLine(command_line); + + // Save the single process mode state before it was reset in this test. This + // state will be recovered in TearDown(). Single-process mode is not set in + // BrowserMain so it needs to be processed explicitly. + original_single_process_ = RenderProcessHost::run_renderer_in_process(); + if (command_line->HasSwitch(switches::kSingleProcess)) + RenderProcessHost::set_run_renderer_in_process(true); + +#if defined(OS_CHROMEOS) + chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); + + // Make sure that the log directory exists. + FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); + file_util::CreateDirectory(log_dir); +#endif // defined(OS_CHROMEOS) + + SandboxInitWrapper sandbox_wrapper; + MainFunctionParams params(*command_line, sandbox_wrapper, NULL); + params.ui_task = + NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); + + host_resolver_ = new net::RuleBasedHostResolverProc( + new IntranetRedirectHostResolverProc(NULL)); + + // Something inside the browser does this lookup implicitly. Make it fail + // to avoid external dependency. It won't break the tests. + host_resolver_->AddSimulatedFailure("*.google.com"); + + // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol + // We don't want the test code to use it. + host_resolver_->AddSimulatedFailure("wpad"); + + net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( + host_resolver_.get()); + + SetUpInProcessBrowserTestFixture(); + + BrowserMain(params); + TearDownInProcessBrowserTestFixture(); +} + +void InProcessBrowserTest::PrepareTestCommandLine( + CommandLine* command_line) { + // Propagate commandline settings from test_launcher_utils. + test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); #if defined(OS_WIN) // Hide windows on show. @@ -152,12 +199,6 @@ void InProcessBrowserTest::SetUp() { // This is a Browser test. command_line->AppendSwitchASCII(switches::kTestType, kBrowserTestType); - // Single-process mode is not set in BrowserMain so it needs to be processed - // explicitly. - original_single_process_ = RenderProcessHost::run_renderer_in_process(); - if (command_line->HasSwitch(switches::kSingleProcess)) - RenderProcessHost::set_run_renderer_in_process(true); - #if defined(OS_WIN) // The Windows sandbox requires that the browser and child processes are the // same binary. So we launch browser_process.exe which loads chrome.dll @@ -184,40 +225,6 @@ void InProcessBrowserTest::SetUp() { // If ncecessary, disable TabCloseableStateWatcher. if (!tab_closeable_state_watcher_enabled_) command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); - - test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); - -#if defined(OS_CHROMEOS) - chromeos::CrosLibrary::Get()->GetTestApi()->SetUseStubImpl(); - - // Make sure that the log directory exists. - FilePath log_dir = logging::GetSessionLogFile(*command_line).DirName(); - file_util::CreateDirectory(log_dir); -#endif // defined(OS_CHROMEOS) - - SandboxInitWrapper sandbox_wrapper; - MainFunctionParams params(*command_line, sandbox_wrapper, NULL); - params.ui_task = - NewRunnableMethod(this, &InProcessBrowserTest::RunTestOnMainThreadLoop); - - host_resolver_ = new net::RuleBasedHostResolverProc( - new IntranetRedirectHostResolverProc(NULL)); - - // Something inside the browser does this lookup implicitly. Make it fail - // to avoid external dependency. It won't break the tests. - host_resolver_->AddSimulatedFailure("*.google.com"); - - // See http://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol - // We don't want the test code to use it. - host_resolver_->AddSimulatedFailure("wpad"); - - net::ScopedDefaultHostResolverProc scoped_host_resolver_proc( - host_resolver_.get()); - - SetUpInProcessBrowserTestFixture(); - - BrowserMain(params); - TearDownInProcessBrowserTestFixture(); } bool InProcessBrowserTest::CreateUserDataDirectory() { diff --git a/chrome/test/in_process_browser_test.h b/chrome/test/in_process_browser_test.h index 444519b..b71ca5c 100644 --- a/chrome/test/in_process_browser_test.h +++ b/chrome/test/in_process_browser_test.h @@ -149,6 +149,10 @@ class InProcessBrowserTest : public testing::Test { // Quits all open browsers and waits until there are no more browsers. void QuitBrowsers(); + // Prepare command line that will be used to launch the child browser process + // with an in-process test. + void PrepareTestCommandLine(CommandLine* command_line); + // Browser created from CreateBrowser. Browser* browser_; diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 34cd0d2..9fbb857 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -661,12 +661,9 @@ FilePath UITestBase::ComputeTypicalUserDataSource(ProfileType profile_type) { return source_history_file; } -bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, - bool wait, - base::ProcessHandle* process) { - FilePath command = browser_directory_.Append( - FilePath::FromWStringHack(chrome::kBrowserProcessExecutablePath)); - CommandLine command_line(command); +void UITestBase::PrepareTestCommandline(CommandLine* command_line) { + // Propagate commandline settings from test_launcher_utils. + test_launcher_utils::PrepareBrowserCommandLineForTests(command_line); // Add any explicit command line flags passed to the process. CommandLine::StringType extra_chrome_flags = @@ -677,85 +674,94 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, std::vector<CommandLine::StringType> flags; base::SplitString(extra_chrome_flags, ' ', &flags); for (size_t i = 0; i < flags.size(); ++i) - command_line.AppendArgNative(flags[i]); + command_line->AppendArgNative(flags[i]); } // No default browser check, it would create an info-bar (if we are not the // default browser) that could conflicts with some tests expectations. - command_line.AppendSwitch(switches::kNoDefaultBrowserCheck); + command_line->AppendSwitch(switches::kNoDefaultBrowserCheck); // This is a UI test. - command_line.AppendSwitchASCII(switches::kTestType, kUITestType); + command_line->AppendSwitchASCII(switches::kTestType, kUITestType); // Tell the browser to use a temporary directory just for this test. - command_line.AppendSwitchPath(switches::kUserDataDir, user_data_dir()); + command_line->AppendSwitchPath(switches::kUserDataDir, user_data_dir()); // We need cookies on file:// for things like the page cycler. if (enable_file_cookies_) - command_line.AppendSwitch(switches::kEnableFileCookies); + command_line->AppendSwitch(switches::kEnableFileCookies); if (dom_automation_enabled_) - command_line.AppendSwitch(switches::kDomAutomationController); + command_line->AppendSwitch(switches::kDomAutomationController); if (include_testing_id_) { - command_line.AppendSwitchASCII(switches::kTestingChannelID, + command_line->AppendSwitchASCII(switches::kTestingChannelID, server_->channel_id()); } if (!show_error_dialogs_ && !CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableErrorDialogs)) { - command_line.AppendSwitch(switches::kNoErrorDialogs); + command_line->AppendSwitch(switches::kNoErrorDialogs); } if (in_process_renderer_) - command_line.AppendSwitch(switches::kSingleProcess); + command_line->AppendSwitch(switches::kSingleProcess); if (no_sandbox_) - command_line.AppendSwitch(switches::kNoSandbox); + command_line->AppendSwitch(switches::kNoSandbox); if (full_memory_dump_) - command_line.AppendSwitch(switches::kFullMemoryCrashReport); + command_line->AppendSwitch(switches::kFullMemoryCrashReport); if (safe_plugins_) - command_line.AppendSwitch(switches::kSafePlugins); + command_line->AppendSwitch(switches::kSafePlugins); if (enable_dcheck_) - command_line.AppendSwitch(switches::kEnableDCHECK); + command_line->AppendSwitch(switches::kEnableDCHECK); if (silent_dump_on_dcheck_) - command_line.AppendSwitch(switches::kSilentDumpOnDCHECK); + command_line->AppendSwitch(switches::kSilentDumpOnDCHECK); if (disable_breakpad_) - command_line.AppendSwitch(switches::kDisableBreakpad); + command_line->AppendSwitch(switches::kDisableBreakpad); if (!homepage_.empty()) - command_line.AppendSwitchASCII(switches::kHomePage, homepage_); + command_line->AppendSwitchASCII(switches::kHomePage, homepage_); if (!js_flags_.empty()) - command_line.AppendSwitchASCII(switches::kJavaScriptFlags, js_flags_); + command_line->AppendSwitchASCII(switches::kJavaScriptFlags, js_flags_); if (!log_level_.empty()) - command_line.AppendSwitchASCII(switches::kLoggingLevel, log_level_); + command_line->AppendSwitchASCII(switches::kLoggingLevel, log_level_); - command_line.AppendSwitch(switches::kMetricsRecordingOnly); + command_line->AppendSwitch(switches::kMetricsRecordingOnly); if (!CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnableErrorDialogs)) - command_line.AppendSwitch(switches::kEnableLogging); + command_line->AppendSwitch(switches::kEnableLogging); if (dump_histograms_on_exit_) - command_line.AppendSwitch(switches::kDumpHistogramsOnExit); + command_line->AppendSwitch(switches::kDumpHistogramsOnExit); #ifdef WAIT_FOR_DEBUGGER_ON_OPEN - command_line.AppendSwitch(switches::kDebugOnStart); + command_line->AppendSwitch(switches::kDebugOnStart); #endif if (!ui_test_name_.empty()) - command_line.AppendSwitchASCII(switches::kTestName, ui_test_name_); + command_line->AppendSwitchASCII(switches::kTestName, ui_test_name_); // The tests assume that file:// URIs can freely access other file:// URIs. - command_line.AppendSwitch(switches::kAllowFileAccessFromFiles); + command_line->AppendSwitch(switches::kAllowFileAccessFromFiles); // Disable TabCloseableStateWatcher for tests. - command_line.AppendSwitch(switches::kDisableTabCloseableStateWatcher); + command_line->AppendSwitch(switches::kDisableTabCloseableStateWatcher); // Allow file:// access on ChromeOS. - command_line.AppendSwitch(switches::kAllowFileAccess); + command_line->AppendSwitch(switches::kAllowFileAccess); +} - test_launcher_utils::PrepareBrowserCommandLineForTests(&command_line); +bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, + bool wait, + base::ProcessHandle* process) { + FilePath command = browser_directory_.Append( + FilePath::FromWStringHack(chrome::kBrowserProcessExecutablePath)); + CommandLine command_line(command); + + // Add command line arguments that should be applied to all UI tests. + PrepareTestCommandline(&command_line); DebugFlags::ProcessDebugFlags( &command_line, ChildProcessInfo::UNKNOWN_PROCESS, false); command_line.AppendArguments(arguments, false); @@ -1191,4 +1197,3 @@ bool UITest::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser, ADD_FAILURE() << "Timeout reached in " << __FUNCTION__; return false; } - diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index 9378512..ced9f34 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -423,6 +423,10 @@ class UITestBase { bool wait, base::ProcessHandle* process); + // Prepare command line that will be used to launch the child browser process + // with an UI test. + void PrepareTestCommandline(CommandLine* arguments); + // We want to have a current history database when we start the browser so // things like the NTP will have thumbnails. This method updates the dates // in the history to be more recent. |