| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 using base::TimeTicks; | 38 using base::TimeTicks; |
| 39 | 39 |
| 40 // Delay to let browser complete a requested action. | 40 // Delay to let browser complete a requested action. |
| 41 static const int kWaitForActionMsec = 2000; | 41 static const int kWaitForActionMsec = 2000; |
| 42 static const int kWaitForActionMaxMsec = 10000; | 42 static const int kWaitForActionMaxMsec = 10000; |
| 43 // Delay to let the browser complete the test. | 43 // Delay to let the browser complete the test. |
| 44 static const int kMaxTestExecutionTime = 30000; | 44 static const int kMaxTestExecutionTime = 30000; |
| 45 // Delay to let the browser shut down before trying more brutal methods. | 45 // Delay to let the browser shut down before trying more brutal methods. |
| 46 static const int kWaitForTerminateMsec = 30000; | 46 static const int kWaitForTerminateMsec = 30000; |
| 47 // Timeout after which the test will be aborted. |
| 48 static const int kPerTestTimeoutMsec = 360000; |
| 47 | 49 |
| 48 const wchar_t UITest::kFailedNoCrashService[] = | 50 const wchar_t UITest::kFailedNoCrashService[] = |
| 49 #if defined(OS_WIN) | 51 #if defined(OS_WIN) |
| 50 L"NOTE: This test is expected to fail if crash_service.exe is not " | 52 L"NOTE: This test is expected to fail if crash_service.exe is not " |
| 51 L"running. Start it manually before running this test (see the build " | 53 L"running. Start it manually before running this test (see the build " |
| 52 L"output directory)."; | 54 L"output directory)."; |
| 53 #elif defined(OS_LINUX) | 55 #elif defined(OS_LINUX) |
| 54 L"NOTE: This test is expected to fail if breakpad is not built in " | 56 L"NOTE: This test is expected to fail if breakpad is not built in " |
| 55 L"or if chromium is not running headless (try CHROME_HEADLESS=1)."; | 57 L"or if chromium is not running headless (try CHROME_HEADLESS=1)."; |
| 56 #else | 58 #else |
| 57 L"NOTE: Crash service not ported to this platform!"; | 59 L"NOTE: Crash service not ported to this platform!"; |
| 58 #endif | 60 #endif |
| 59 bool UITest::in_process_renderer_ = false; | 61 bool UITest::in_process_renderer_ = false; |
| 60 bool UITest::no_sandbox_ = false; | 62 bool UITest::no_sandbox_ = false; |
| 61 bool UITest::full_memory_dump_ = false; | 63 bool UITest::full_memory_dump_ = false; |
| 62 bool UITest::safe_plugins_ = false; | 64 bool UITest::safe_plugins_ = false; |
| 63 bool UITest::show_error_dialogs_ = true; | 65 bool UITest::show_error_dialogs_ = true; |
| 64 bool UITest::default_use_existing_browser_ = false; | 66 bool UITest::default_use_existing_browser_ = false; |
| 65 bool UITest::dump_histograms_on_exit_ = false; | 67 bool UITest::dump_histograms_on_exit_ = false; |
| 66 bool UITest::enable_dcheck_ = false; | 68 bool UITest::enable_dcheck_ = false; |
| 67 bool UITest::silent_dump_on_dcheck_ = false; | 69 bool UITest::silent_dump_on_dcheck_ = false; |
| 68 bool UITest::disable_breakpad_ = false; | 70 bool UITest::disable_breakpad_ = false; |
| 69 int UITest::timeout_ms_ = 20 * 60 * 1000; | 71 int UITest::timeout_ms_ = 20 * 60 * 1000; |
| 70 std::wstring UITest::js_flags_ = L""; | 72 std::wstring UITest::js_flags_ = L""; |
| 71 std::wstring UITest::log_level_ = L""; | 73 std::wstring UITest::log_level_ = L""; |
| 72 | 74 |
| 73 // Specify the time (in milliseconds) that the ui_tests should wait before | 75 // Specify the time (in milliseconds) that the ui_tests should wait before |
| 74 // timing out. This is used to specify longer timeouts when running under Purify | 76 // timing out. This is used to specify longer timeouts when running under Purify |
| 75 // which requires much more time. | 77 // which requires much more time. |
| 78 // TODO(phajdan.jr): ui-test-timeout is misleading name, rename it. |
| 76 const wchar_t kUiTestTimeout[] = L"ui-test-timeout"; | 79 const wchar_t kUiTestTimeout[] = L"ui-test-timeout"; |
| 77 const wchar_t kUiTestActionTimeout[] = L"ui-test-action-timeout"; | 80 const wchar_t kUiTestActionTimeout[] = L"ui-test-action-timeout"; |
| 78 const wchar_t kUiTestActionMaxTimeout[] = L"ui-test-action-max-timeout"; | 81 const wchar_t kUiTestActionMaxTimeout[] = L"ui-test-action-max-timeout"; |
| 79 const wchar_t kUiTestSleepTimeout[] = L"ui-test-sleep-timeout"; | 82 const wchar_t kUiTestSleepTimeout[] = L"ui-test-sleep-timeout"; |
| 80 const wchar_t kUiTestTerminateTimeout[] = L"ui-test-terminate-timeout"; | 83 const wchar_t kUiTestTerminateTimeout[] = L"ui-test-terminate-timeout"; |
| 84 const wchar_t kUiTestPerTestTimeout[] = L"ui-test-per-test-timeout"; |
| 81 | 85 |
| 82 const wchar_t kExtraChromeFlagsSwitch[] = L"extra-chrome-flags"; | 86 const wchar_t kExtraChromeFlagsSwitch[] = L"extra-chrome-flags"; |
| 83 | 87 |
| 84 // By default error dialogs are hidden, which makes debugging failures in the | 88 // By default error dialogs are hidden, which makes debugging failures in the |
| 85 // slave process frustrating. By passing this in error dialogs are enabled. | 89 // slave process frustrating. By passing this in error dialogs are enabled. |
| 86 const wchar_t kEnableErrorDialogs[] = L"enable-errdialogs"; | 90 const wchar_t kEnableErrorDialogs[] = L"enable-errdialogs"; |
| 87 | 91 |
| 88 // Uncomment this line to have the spawned process wait for the debugger to | 92 // Uncomment this line to have the spawned process wait for the debugger to |
| 89 // attach. This only works on Windows. On posix systems, you can set the | 93 // attach. This only works on Windows. On posix systems, you can set the |
| 90 // BROWSER_WRAPPER env variable to wrap the browser process. | 94 // BROWSER_WRAPPER env variable to wrap the browser process. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 104 clear_profile_(true), | 108 clear_profile_(true), |
| 105 include_testing_id_(true), | 109 include_testing_id_(true), |
| 106 use_existing_browser_(default_use_existing_browser_), | 110 use_existing_browser_(default_use_existing_browser_), |
| 107 enable_file_cookies_(true), | 111 enable_file_cookies_(true), |
| 108 profile_type_(UITest::DEFAULT_THEME), | 112 profile_type_(UITest::DEFAULT_THEME), |
| 109 test_start_time_(base::Time::NowFromSystemTime()), | 113 test_start_time_(base::Time::NowFromSystemTime()), |
| 110 command_execution_timeout_ms_(kMaxTestExecutionTime), | 114 command_execution_timeout_ms_(kMaxTestExecutionTime), |
| 111 action_timeout_ms_(kWaitForActionMsec), | 115 action_timeout_ms_(kWaitForActionMsec), |
| 112 action_max_timeout_ms_(kWaitForActionMaxMsec), | 116 action_max_timeout_ms_(kWaitForActionMaxMsec), |
| 113 sleep_timeout_ms_(kWaitForActionMsec), | 117 sleep_timeout_ms_(kWaitForActionMsec), |
| 114 terminate_timeout_ms_(kWaitForTerminateMsec) { | 118 terminate_timeout_ms_(kWaitForTerminateMsec), |
| 119 per_test_timeout_ms_(kPerTestTimeoutMsec) { |
| 115 PathService::Get(chrome::DIR_APP, &browser_directory_); | 120 PathService::Get(chrome::DIR_APP, &browser_directory_); |
| 116 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); | 121 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); |
| 117 } | 122 } |
| 118 | 123 |
| 119 void UITest::SetUp() { | 124 void UITest::SetUp() { |
| 120 if (!use_existing_browser_) { | 125 if (!use_existing_browser_) { |
| 121 AssertAppNotRunning(L"Please close any other instances " | 126 AssertAppNotRunning(L"Please close any other instances " |
| 122 L"of the app before testing."); | 127 L"of the app before testing."); |
| 123 } | 128 } |
| 124 | 129 |
| 125 // Pass the test case name to chrome.exe on the command line to help with | 130 // Pass the test case name to chrome.exe on the command line to help with |
| 126 // parsing Purify output. | 131 // parsing Purify output. |
| 127 const testing::TestInfo* const test_info = | 132 const testing::TestInfo* const test_info = |
| 128 testing::UnitTest::GetInstance()->current_test_info(); | 133 testing::UnitTest::GetInstance()->current_test_info(); |
| 129 if (test_info) { | 134 if (test_info) { |
| 130 std::string test_name = test_info->test_case_name(); | 135 std::string test_name = test_info->test_case_name(); |
| 131 test_name += "."; | 136 test_name += "."; |
| 132 test_name += test_info->name(); | 137 test_name += test_info->name(); |
| 133 ui_test_name_ = ASCIIToWide(test_name); | 138 ui_test_name_ = ASCIIToWide(test_name); |
| 134 } | 139 } |
| 135 | 140 |
| 136 InitializeTimeouts(); | 141 InitializeTimeouts(); |
| 137 LaunchBrowserAndServer(); | 142 LaunchBrowserAndServer(); |
| 143 |
| 144 automation()->QuitAfterTimeout(per_test_timeout_ms_); |
| 138 } | 145 } |
| 139 | 146 |
| 140 void UITest::TearDown() { | 147 void UITest::TearDown() { |
| 141 CloseBrowserAndServer(); | 148 CloseBrowserAndServer(); |
| 142 | 149 |
| 143 // Make sure that we didn't encounter any assertion failures | 150 // Make sure that we didn't encounter any assertion failures |
| 144 logging::AssertionList assertions; | 151 logging::AssertionList assertions; |
| 145 logging::GetFatalAssertions(&assertions); | 152 logging::GetFatalAssertions(&assertions); |
| 146 | 153 |
| 147 // If there were errors, get all the error strings for display. | 154 // If there were errors, get all the error strings for display. |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout); | 207 sleep_timeout_ms_ = std::max(kWaitForActionMsec, sleep_timeout); |
| 201 } | 208 } |
| 202 | 209 |
| 203 if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestTerminateTimeout)) { | 210 if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestTerminateTimeout)) { |
| 204 std::wstring terminate_timeout_str = | 211 std::wstring terminate_timeout_str = |
| 205 CommandLine::ForCurrentProcess()->GetSwitchValue( | 212 CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 206 kUiTestTerminateTimeout); | 213 kUiTestTerminateTimeout); |
| 207 int terminate_timeout = StringToInt(WideToUTF16Hack(terminate_timeout_str)); | 214 int terminate_timeout = StringToInt(WideToUTF16Hack(terminate_timeout_str)); |
| 208 terminate_timeout_ms_ = std::max(kWaitForActionMsec, terminate_timeout); | 215 terminate_timeout_ms_ = std::max(kWaitForActionMsec, terminate_timeout); |
| 209 } | 216 } |
| 217 |
| 218 if (CommandLine::ForCurrentProcess()->HasSwitch(kUiTestPerTestTimeout)) { |
| 219 std::wstring per_test_timeout_str = |
| 220 CommandLine::ForCurrentProcess()->GetSwitchValue( |
| 221 kUiTestPerTestTimeout); |
| 222 int per_test_timeout = StringToInt(WideToUTF16Hack(per_test_timeout_str)); |
| 223 per_test_timeout_ms_ = std::max(kPerTestTimeoutMsec, per_test_timeout); |
| 224 } |
| 210 } | 225 } |
| 211 | 226 |
| 212 AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) { | 227 AutomationProxy* UITest::CreateAutomationProxy(int execution_timeout) { |
| 213 // By default we create a plain vanilla AutomationProxy. | 228 // By default we create a plain vanilla AutomationProxy. |
| 214 return new AutomationProxy(execution_timeout); | 229 return new AutomationProxy(execution_timeout); |
| 215 } | 230 } |
| 216 | 231 |
| 217 void UITest::LaunchBrowserAndServer() { | 232 void UITest::LaunchBrowserAndServer() { |
| 218 // Set up IPC testing interface server. | 233 // Set up IPC testing interface server. |
| 219 server_.reset(CreateAutomationProxy(command_execution_timeout_ms_)); | 234 server_.reset(CreateAutomationProxy(command_execution_timeout_ms_)); |
| (...skipping 903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1123 #else | 1138 #else |
| 1124 // TODO(port): above code is very Windows-specific; we need to | 1139 // TODO(port): above code is very Windows-specific; we need to |
| 1125 // figure out and abstract out how we'll handle finding any existing | 1140 // figure out and abstract out how we'll handle finding any existing |
| 1126 // running process, etc. on other platforms. | 1141 // running process, etc. on other platforms. |
| 1127 NOTIMPLEMENTED(); | 1142 NOTIMPLEMENTED(); |
| 1128 #endif | 1143 #endif |
| 1129 } | 1144 } |
| 1130 | 1145 |
| 1131 return true; | 1146 return true; |
| 1132 } | 1147 } |
| OLD | NEW |