diff options
-rw-r--r-- | chrome/browser/sanity_uitest.cc | 5 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 2 | ||||
-rw-r--r-- | chrome/test/test_switches.cc | 16 | ||||
-rw-r--r-- | chrome/test/test_switches.h | 11 | ||||
-rw-r--r-- | chrome/test/test_timeouts.cc | 67 | ||||
-rw-r--r-- | chrome/test/test_timeouts.h | 61 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.cc | 110 | ||||
-rw-r--r-- | chrome/test/ui/ui_test.h | 47 | ||||
-rw-r--r-- | chrome/test/ui/ui_test_suite.cc | 10 | ||||
-rw-r--r-- | chrome/test/unit/chrome_test_suite.cc | 3 | ||||
-rw-r--r-- | chrome/test/url_fetch_test/url_fetch_test.cc | 4 |
11 files changed, 195 insertions, 141 deletions
diff --git a/chrome/browser/sanity_uitest.cc b/chrome/browser/sanity_uitest.cc index 83f978a..0de52b7 100644 --- a/chrome/browser/sanity_uitest.cc +++ b/chrome/browser/sanity_uitest.cc @@ -54,11 +54,6 @@ class EarlyReturnTest : public UITest { public: EarlyReturnTest() { wait_for_initial_loads_ = false; - // We don't depend on these timeouts, they are set to the minimum so - // the automation server waits the minimun amount possible for the - // handshake that will never come. - set_command_execution_timeout_ms(1); - set_action_timeout_ms(1); launch_arguments_.AppendSwitchASCII(switches::kTryChromeAgain, "10001"); } }; diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 43f1b77..cde188b 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -118,6 +118,8 @@ 'test/test_location_bar.h', 'test/test_switches.cc', 'test/test_switches.h', + 'test/test_timeouts.cc', + 'test/test_timeouts.h', 'test/testing_pref_service.cc', 'test/testing_pref_service.h', 'test/testing_profile.cc', diff --git a/chrome/test/test_switches.cc b/chrome/test/test_switches.cc index 69f43ce..9fbf153 100644 --- a/chrome/test/test_switches.cc +++ b/chrome/test/test_switches.cc @@ -4,4 +4,20 @@ #include "chrome/test/test_switches.h" +// Extra flags that the test should pass to launched browser process. +const char switches::kExtraChromeFlags[] = "extra-chrome-flags"; + +// Enable displaying error dialogs (for debugging). +const char switches::kEnableErrorDialogs[] = "enable-errdialogs"; + +// Number of iterations that page cycler tests will run. const char switches::kPageCyclerIterations[] = "page-cycler-iterations"; + +// Time (in milliseconds) that the ui_tests should wait before timing out. +// TODO(phajdan.jr): Clean up the switch names. +const char switches::kUiTestActionTimeout[] = "ui-test-action-timeout"; +const char switches::kUiTestActionMaxTimeout[] = "ui-test-action-max-timeout"; +const char switches::kUiTestCommandExecutionTimeout[] = "ui-test-timeout"; +const char switches::kUiTestSleepTimeout[] = "ui-test-sleep-timeout"; +const char switches::kUiTestTerminateTimeout[] = "ui-test-terminate-timeout"; +const char switches::kUiTestTimeout[] = "test-timeout"; diff --git a/chrome/test/test_switches.h b/chrome/test/test_switches.h index 0f9f9d1..4497d1a 100644 --- a/chrome/test/test_switches.h +++ b/chrome/test/test_switches.h @@ -7,8 +7,17 @@ namespace switches { -// Number of iterations that page cycler tests will run. +// All switches in alphabetical order. The switches should be documented +// alongside the definition of their values in the .cc file. +extern const char kExtraChromeFlags[]; +extern const char kEnableErrorDialogs[]; extern const char kPageCyclerIterations[]; +extern const char kUiTestActionTimeout[]; +extern const char kUiTestActionMaxTimeout[]; +extern const char kUiTestCommandExecutionTimeout[]; +extern const char kUiTestSleepTimeout[]; +extern const char kUiTestTerminateTimeout[]; +extern const char kUiTestTimeout[]; } // namespace switches diff --git a/chrome/test/test_timeouts.cc b/chrome/test/test_timeouts.cc new file mode 100644 index 0000000..245f148 --- /dev/null +++ b/chrome/test/test_timeouts.cc @@ -0,0 +1,67 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/test/test_timeouts.h" + +#include "base/command_line.h" +#include "base/logging.h" +#include "base/string_number_conversions.h" +#include "chrome/test/test_switches.h" + +namespace { + +void InitializeTimeout(const char* switch_name, int* value) { + DCHECK(value); + if (CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { + std::string string_value( + CommandLine::ForCurrentProcess()->GetSwitchValueASCII(switch_name)); + int timeout; + base::StringToInt(string_value, &timeout); + *value = std::max(*value, timeout); + } +} + +} // namespace + +// static +bool TestTimeouts::initialized_ = false; + +// The timeout values should increase in the order they appear in this block. +// static +int TestTimeouts::action_timeout_ms_ = 2000; +int TestTimeouts::action_max_timeout_ms_ = 15000; +int TestTimeouts::large_test_timeout_ms_ = 10 * 60 * 1000; + +// static +int TestTimeouts::sleep_timeout_ms_ = 2000; + +// static +int TestTimeouts::command_execution_timeout_ms_ = 25000; + +// static +int TestTimeouts::wait_for_terminate_timeout_ms_ = 15000; + +// static +void TestTimeouts::Initialize() { + if (initialized_) { + NOTREACHED(); + return; + } + initialized_ = true; + + InitializeTimeout(switches::kUiTestActionTimeout, &action_timeout_ms_); + InitializeTimeout(switches::kUiTestActionMaxTimeout, + &action_max_timeout_ms_); + InitializeTimeout(switches::kUiTestTimeout, &large_test_timeout_ms_); + + // The timeout values should be increasing in the right order. + CHECK(action_timeout_ms_ <= action_max_timeout_ms_); + CHECK(action_max_timeout_ms_ <= large_test_timeout_ms_); + + InitializeTimeout(switches::kUiTestSleepTimeout, &sleep_timeout_ms_); + InitializeTimeout(switches::kUiTestCommandExecutionTimeout, + &command_execution_timeout_ms_); + InitializeTimeout(switches::kUiTestTerminateTimeout, + &wait_for_terminate_timeout_ms_); +} diff --git a/chrome/test/test_timeouts.h b/chrome/test/test_timeouts.h new file mode 100644 index 0000000..8405a51 --- /dev/null +++ b/chrome/test/test_timeouts.h @@ -0,0 +1,61 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_TEST_TEST_TIMEOUTS_H_ +#define CHROME_TEST_TEST_TIMEOUTS_H_ + +#include "base/basictypes.h" + +// Returns common timeouts to use in tests. Makes it possible to adjust +// the timeouts for different environments (like Valgrind). +class TestTimeouts { + public: + // Initializes the timeouts. Non thread-safe. Should be called exactly once + // by the test suite. + static void Initialize(); + + // Timeout to wait for something to happen. If you are not sure + // which timeout to use, this is the one you want. + static int action_timeout_ms() { return action_timeout_ms_; } + + // Timeout longer than the above, but still suitable to use + // multiple times in a single test. Use if the timeout above + // is not sufficient. + static int action_max_timeout_ms() { return action_max_timeout_ms_; } + + // Timeout for a large test (like running a layout test inside the browser). + // Do not use unless absolutely necessary - try to make the test smaller. + // Do not use multiple times in a single test. + static int large_test_timeout_ms() { return large_test_timeout_ms_; } + + // Timeout used when calling Sleep. Deprecated (recommended + // replacement is action_timeout_ms). + // TODO(phajdan.jr): Remove sleep_timeout_ms. + static int sleep_timeout_ms() { return sleep_timeout_ms_; } + + // Timeout to use for AutomationProxy. Do not use in other places. + // TODO(phajdan.jr): Remove command_execution_timeout_ms. + static int command_execution_timeout_ms() { + return command_execution_timeout_ms_; + } + + // Timeout to wait for a process to terminate. + static int wait_for_terminate_timeout_ms() { + return wait_for_terminate_timeout_ms_; + } + + private: + static bool initialized_; + + static int action_timeout_ms_; + static int action_max_timeout_ms_; + static int large_test_timeout_ms_; + static int sleep_timeout_ms_; + static int command_execution_timeout_ms_; + static int wait_for_terminate_timeout_ms_; + + DISALLOW_IMPLICIT_CONSTRUCTORS(TestTimeouts); +}; + +#endif // CHROME_TEST_TEST_TIMEOUTS_H_ diff --git a/chrome/test/ui/ui_test.cc b/chrome/test/ui/ui_test.cc index 5e55e6b..4177e88 100644 --- a/chrome/test/ui/ui_test.cc +++ b/chrome/test/ui/ui_test.cc @@ -43,6 +43,7 @@ #include "chrome/test/automation/tab_proxy.h" #include "chrome/test/automation/window_proxy.h" #include "chrome/test/chrome_process_util.h" +#include "chrome/test/test_switches.h" #include "googleurl/src/gurl.h" #include "net/base/net_util.h" @@ -55,13 +56,6 @@ using base::Time; using base::TimeDelta; using base::TimeTicks; -// Delay to let browser complete a requested action. -static const int kWaitForActionMsec = 2000; -static const int kWaitForActionMaxMsec = 15000; -// Command execution timeout passed to AutomationProxy. -static const int kCommandExecutionTimeout = 25000; -// Delay to let the browser shut down before trying more brutal methods. -static const int kWaitForTerminateMsec = 15000; // Passed as value of kTestType. static const char kUITestType[] = "ui"; @@ -85,25 +79,9 @@ bool UITestBase::dump_histograms_on_exit_ = false; bool UITestBase::enable_dcheck_ = false; bool UITestBase::silent_dump_on_dcheck_ = false; bool UITestBase::disable_breakpad_ = false; -int UITestBase::timeout_ms_ = 10 * 60 * 1000; std::string UITestBase::js_flags_ = ""; std::string UITestBase::log_level_ = ""; -// Specify the time (in milliseconds) that the ui_tests should wait before -// timing out. This is used to specify longer timeouts when running under Purify -// which requires much more time. -const char kUiTestTimeout[] = "ui-test-timeout"; -const char kUiTestActionTimeout[] = "ui-test-action-timeout"; -const char kUiTestActionMaxTimeout[] = "ui-test-action-max-timeout"; -const char kUiTestSleepTimeout[] = "ui-test-sleep-timeout"; -const char kUiTestTerminateTimeout[] = "ui-test-terminate-timeout"; - -const char kExtraChromeFlagsSwitch[] = "extra-chrome-flags"; - -// By default error dialogs are hidden, which makes debugging failures in the -// slave process frustrating. By passing this in error dialogs are enabled. -const char kEnableErrorDialogs[] = "enable-errdialogs"; - // Uncomment this line to have the spawned process wait for the debugger to // attach. This only works on Windows. On posix systems, you can set the // BROWSER_WRAPPER env variable to wrap the browser process. @@ -125,11 +103,6 @@ UITestBase::UITestBase() profile_type_(UITestBase::DEFAULT_THEME), shutdown_type_(UITestBase::WINDOW_CLOSE), test_start_time_(Time::NowFromSystemTime()), - command_execution_timeout_ms_(kCommandExecutionTimeout), - action_timeout_ms_(kWaitForActionMsec), - action_max_timeout_ms_(kWaitForActionMaxMsec), - sleep_timeout_ms_(kWaitForActionMsec), - terminate_timeout_ms_(kWaitForTerminateMsec), temp_profile_dir_(new ScopedTempDir()) { PathService::Get(chrome::DIR_APP, &browser_directory_); PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); @@ -150,12 +123,7 @@ UITestBase::UITestBase(MessageLoop::Type msg_loop_type) enable_file_cookies_(true), profile_type_(UITestBase::DEFAULT_THEME), shutdown_type_(UITestBase::WINDOW_CLOSE), - test_start_time_(Time::NowFromSystemTime()), - command_execution_timeout_ms_(kCommandExecutionTimeout), - action_timeout_ms_(kWaitForActionMsec), - action_max_timeout_ms_(kWaitForActionMaxMsec), - sleep_timeout_ms_(kWaitForActionMsec), - terminate_timeout_ms_(kWaitForTerminateMsec) { + test_start_time_(Time::NowFromSystemTime()) { PathService::Get(chrome::DIR_APP, &browser_directory_); PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); } @@ -167,8 +135,8 @@ void UITestBase::SetUp() { AssertAppNotRunning(L"Please close any other instances " L"of the app before testing."); - InitializeTimeouts(); - JavaScriptExecutionController::set_timeout(action_max_timeout_ms_); + JavaScriptExecutionController::set_timeout( + TestTimeouts::action_max_timeout_ms()); LaunchBrowserAndServer(); } @@ -211,67 +179,21 @@ void UITestBase::TearDown() { EXPECT_EQ(expected_crashes_, actual_crashes) << error_msg; } +// TODO(phajdan.jr): get rid of set_command_execution_timeout_ms. void UITestBase::set_command_execution_timeout_ms(int timeout) { - if (server_.get()) { - // automation channel already created. Set its timeout for use by - // subsequent automation calls. - server_->set_command_execution_timeout_ms(timeout); - } - command_execution_timeout_ms_ = timeout; + server_->set_command_execution_timeout_ms(timeout); LOG(INFO) << "Automation command execution timeout set to " << timeout << " milli secs."; } -// Pick up the various test time out values from the command line. -void UITestBase::InitializeTimeouts() { - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); - if (command_line.HasSwitch(kUiTestTimeout)) { - std::string timeout_str = command_line.GetSwitchValueASCII(kUiTestTimeout); - int timeout; - base::StringToInt(timeout_str, &timeout); - command_execution_timeout_ms_ = std::max(kCommandExecutionTimeout, timeout); - } - - if (command_line.HasSwitch(kUiTestActionTimeout)) { - std::string act_str = - command_line.GetSwitchValueASCII(kUiTestActionTimeout); - int act_timeout; - base::StringToInt(act_str, &act_timeout); - action_timeout_ms_ = std::max(kWaitForActionMsec, act_timeout); - } - - if (command_line.HasSwitch(kUiTestActionMaxTimeout)) { - std::string action_max_str = - command_line.GetSwitchValueASCII(kUiTestActionMaxTimeout); - int max_timeout; - base::StringToInt(action_max_str, &max_timeout); - action_max_timeout_ms_ = std::max(kWaitForActionMaxMsec, max_timeout); - } - - if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestSleepTimeout)) { - std::string sleep_timeout_str = - command_line.GetSwitchValueASCII(kUiTestSleepTimeout); - int sleep_timeout; - base::StringToInt(sleep_timeout_str, &sleep_timeout); - sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout); - } - - if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestTerminateTimeout)) { - std::string terminate_timeout_str = - command_line.GetSwitchValueASCII(kUiTestTerminateTimeout); - int terminate_timeout; - base::StringToInt(terminate_timeout_str, &terminate_timeout); - terminate_timeout_ms_ = std::max(kWaitForActionMsec, terminate_timeout); - } -} - AutomationProxy* UITestBase::CreateAutomationProxy(int execution_timeout) { return new AutomationProxy(execution_timeout, false); } void UITestBase::LaunchBrowserAndServer() { // Set up IPC testing interface server. - server_.reset(CreateAutomationProxy(command_execution_timeout_ms_)); + server_.reset(CreateAutomationProxy( + TestTimeouts::command_execution_timeout_ms())); const int kTries = 3; for (int i = 0; i < kTries; i++) { @@ -658,12 +580,12 @@ bool UITestBase::WaitForDownloadShelfInvisible(BrowserProxy* browser) { } bool UITestBase::WaitForBrowserProcessToQuit() { - // Wait for the browser process to quit. - int timeout = terminate_timeout_ms_; + // Wait for the browser process to quit. + int timeout = TestTimeouts::wait_for_terminate_timeout_ms(); #ifdef WAIT_FOR_DEBUGGER_ON_OPEN - timeout = 500000; + timeout = 500000; #endif - return base::WaitForSingleProcess(process_, timeout); + return base::WaitForSingleProcess(process_, timeout); } bool UITestBase::WaitForDownloadShelfVisibilityChange(BrowserProxy* browser, @@ -1106,7 +1028,7 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, // Add any explicit command line flags passed to the process. CommandLine::StringType extra_chrome_flags = CommandLine::ForCurrentProcess()->GetSwitchValueNative( - kExtraChromeFlagsSwitch); + switches::kExtraChromeFlags); if (!extra_chrome_flags.empty()) { // Split by spaces and append to command line std::vector<CommandLine::StringType> flags; @@ -1141,7 +1063,8 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, } if (!show_error_dialogs_ && - !CommandLine::ForCurrentProcess()->HasSwitch(kEnableErrorDialogs)) { + !CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableErrorDialogs)) { command_line.AppendSwitch(switches::kNoErrorDialogs); } if (in_process_renderer_) @@ -1170,7 +1093,8 @@ bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, command_line.AppendSwitch(switches::kMetricsRecordingOnly); - if (!CommandLine::ForCurrentProcess()->HasSwitch(kEnableErrorDialogs)) + if (!CommandLine::ForCurrentProcess()->HasSwitch( + switches::kEnableErrorDialogs)) command_line.AppendSwitch(switches::kEnableLogging); if (dump_histograms_on_exit_) diff --git a/chrome/test/ui/ui_test.h b/chrome/test/ui/ui_test.h index d583b41..9cb9f2d 100644 --- a/chrome/test/ui/ui_test.h +++ b/chrome/test/ui/ui_test.h @@ -30,6 +30,7 @@ // AutomationProxy here, but many files that #include this one don't // themselves #include automation_proxy.h. #include "chrome/test/automation/automation_proxy.h" +#include "chrome/test/test_timeouts.h" #include "testing/platform_test.h" class AutomationProxy; @@ -64,15 +65,15 @@ class UITestBase { // Closes the browser window. virtual void TearDown(); - // Set up the test time out values. - virtual void InitializeTimeouts(); - public: // ********* Utility functions ********* // Launches the browser and IPC testing server. void LaunchBrowserAndServer(); + // Only for pyauto. + void set_command_execution_timeout_ms(int timeout); + // Overridable so that derived classes can provide their own AutomationProxy. virtual AutomationProxy* CreateAutomationProxy(int execution_timeout); @@ -311,11 +312,6 @@ class UITestBase { dump_histograms_on_exit_ = value; } - static int test_timeout_ms() { return timeout_ms_; } - static void set_test_timeout_ms(int value) { - timeout_ms_ = value; - } - static const std::string& js_flags() { return js_flags_; } static void set_js_flags(const std::string& value) { js_flags_ = value; @@ -359,22 +355,23 @@ class UITestBase { // Return the process id of the browser process (-1 on error). base::ProcessId browser_process_id() const { return process_id_; } - // Timeout accessors. - void set_command_execution_timeout_ms(int timeout); - - int command_execution_timeout_ms() const { - return command_execution_timeout_ms_; + // Compatibility timeout accessors. + // TODO(phajdan.jr): update callers and remove these. + static int command_execution_timeout_ms() { + return TestTimeouts::command_execution_timeout_ms(); } - - int action_timeout_ms() const { return action_timeout_ms_; } - - void set_action_timeout_ms(int timeout) { - action_timeout_ms_ = timeout; + static int action_timeout_ms() { + return TestTimeouts::action_timeout_ms(); + } + static int action_max_timeout_ms() { + return TestTimeouts::action_max_timeout_ms(); + } + static int sleep_timeout_ms() { + return TestTimeouts::sleep_timeout_ms(); + } + static int test_timeout_ms() { + return TestTimeouts::large_test_timeout_ms(); } - - int action_max_timeout_ms() const { return action_max_timeout_ms_; } - - int sleep_timeout_ms() const { return sleep_timeout_ms_; } void set_ui_test_name(const std::string& name) { ui_test_name_ = name; @@ -542,12 +539,6 @@ class UITestBase { scoped_ptr<AutomationProxy> server_; - int command_execution_timeout_ms_; - int action_timeout_ms_; - int action_max_timeout_ms_; - int sleep_timeout_ms_; - int terminate_timeout_ms_; - std::string ui_test_name_; // We use a temporary directory for profile to avoid issues with being diff --git a/chrome/test/ui/ui_test_suite.cc b/chrome/test/ui/ui_test_suite.cc index 6cc32e5..9e0f39a 100644 --- a/chrome/test/ui/ui_test_suite.cc +++ b/chrome/test/ui/ui_test_suite.cc @@ -13,9 +13,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/env_vars.h" -// Timeout for the test in milliseconds. UI tests only. -const char UITestSuite::kTestTimeout[] = "test-timeout"; - // Parameters to run test in parallel. UI tests only. const char UITestSuite::kBatchCount[] = "batch-count"; const char UITestSuite::kBatchIndex[] = "batch-index"; @@ -50,13 +47,6 @@ void UITestSuite::Initialize() { parsed_command_line.HasSwitch(switches::kSilentDumpOnDCHECK)); UITest::set_disable_breakpad( parsed_command_line.HasSwitch(switches::kDisableBreakpad)); - std::string test_timeout = - parsed_command_line.GetSwitchValueASCII(UITestSuite::kTestTimeout); - if (!test_timeout.empty()) { - int timeout; - base::StringToInt(test_timeout, &timeout); - UITest::set_test_timeout_ms(timeout); - } #if defined(OS_WIN) int batch_count = 0; diff --git a/chrome/test/unit/chrome_test_suite.cc b/chrome/test/unit/chrome_test_suite.cc index 7995fd8..4aefaa6 100644 --- a/chrome/test/unit/chrome_test_suite.cc +++ b/chrome/test/unit/chrome_test_suite.cc @@ -16,6 +16,7 @@ #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" +#include "chrome/test/test_timeouts.h" #include "chrome/test/testing_browser_process.h" #if defined(OS_MACOSX) @@ -90,6 +91,8 @@ void ChromeTestSuite::Initialize() { app::RegisterPathProvider(); g_browser_process = new TestingBrowserProcess; + TestTimeouts::Initialize(); + if (!browser_dir_.empty()) { PathService::Override(base::DIR_EXE, browser_dir_); PathService::Override(base::DIR_MODULE, browser_dir_); diff --git a/chrome/test/url_fetch_test/url_fetch_test.cc b/chrome/test/url_fetch_test/url_fetch_test.cc index 76f73c3..98ea508 100644 --- a/chrome/test/url_fetch_test/url_fetch_test.cc +++ b/chrome/test/url_fetch_test/url_fetch_test.cc @@ -43,10 +43,6 @@ class UrlFetchTest : public UITest { browser_directory_ = dir; } UITest::SetUp(); - - // We've shortened the default timeouts, but dom_perf on Vista needs longer - // timeouts. Setting timeouts to the previous values before r52666. - set_action_timeout_ms(std::max(60000, action_timeout_ms())); } void RunTest(const GURL& url, const char* wait_cookie_name, |