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/ui/ui_test.h" | 5 #include "chrome/test/ui/ui_test.h" |
6 | 6 |
7 #if defined(OS_POSIX) | 7 #if defined(OS_POSIX) |
8 #include <signal.h> | 8 #include <signal.h> |
9 #include <sys/types.h> | 9 #include <sys/types.h> |
10 #endif | 10 #endif |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 L"NOTE: This test is expected to fail if breakpad is not built in " | 70 L"NOTE: This test is expected to fail if breakpad is not built in " |
71 L"or if chromium is not running headless (try CHROME_HEADLESS=1)."; | 71 L"or if chromium is not running headless (try CHROME_HEADLESS=1)."; |
72 #else | 72 #else |
73 L"NOTE: Crash service not ported to this platform!"; | 73 L"NOTE: Crash service not ported to this platform!"; |
74 #endif | 74 #endif |
75 bool UITestBase::in_process_renderer_ = false; | 75 bool UITestBase::in_process_renderer_ = false; |
76 bool UITestBase::no_sandbox_ = false; | 76 bool UITestBase::no_sandbox_ = false; |
77 bool UITestBase::full_memory_dump_ = false; | 77 bool UITestBase::full_memory_dump_ = false; |
78 bool UITestBase::safe_plugins_ = false; | 78 bool UITestBase::safe_plugins_ = false; |
79 bool UITestBase::show_error_dialogs_ = true; | 79 bool UITestBase::show_error_dialogs_ = true; |
80 bool UITestBase::default_use_existing_browser_ = false; | |
81 bool UITestBase::dump_histograms_on_exit_ = false; | 80 bool UITestBase::dump_histograms_on_exit_ = false; |
82 bool UITestBase::enable_dcheck_ = false; | 81 bool UITestBase::enable_dcheck_ = false; |
83 bool UITestBase::silent_dump_on_dcheck_ = false; | 82 bool UITestBase::silent_dump_on_dcheck_ = false; |
84 bool UITestBase::disable_breakpad_ = false; | 83 bool UITestBase::disable_breakpad_ = false; |
85 int UITestBase::timeout_ms_ = 20 * 60 * 1000; | 84 int UITestBase::timeout_ms_ = 20 * 60 * 1000; |
86 std::wstring UITestBase::js_flags_ = L""; | 85 std::wstring UITestBase::js_flags_ = L""; |
87 std::wstring UITestBase::log_level_ = L""; | 86 std::wstring UITestBase::log_level_ = L""; |
88 | 87 |
89 // Specify the time (in milliseconds) that the ui_tests should wait before | 88 // Specify the time (in milliseconds) that the ui_tests should wait before |
90 // timing out. This is used to specify longer timeouts when running under Purify | 89 // timing out. This is used to specify longer timeouts when running under Purify |
(...skipping 20 matching lines...) Expand all Loading... |
111 expected_errors_(0), | 110 expected_errors_(0), |
112 expected_crashes_(0), | 111 expected_crashes_(0), |
113 homepage_(L"about:blank"), | 112 homepage_(L"about:blank"), |
114 wait_for_initial_loads_(true), | 113 wait_for_initial_loads_(true), |
115 dom_automation_enabled_(false), | 114 dom_automation_enabled_(false), |
116 process_(base::kNullProcessHandle), | 115 process_(base::kNullProcessHandle), |
117 process_id_(-1), | 116 process_id_(-1), |
118 show_window_(false), | 117 show_window_(false), |
119 clear_profile_(true), | 118 clear_profile_(true), |
120 include_testing_id_(true), | 119 include_testing_id_(true), |
121 use_existing_browser_(default_use_existing_browser_), | |
122 enable_file_cookies_(true), | 120 enable_file_cookies_(true), |
123 profile_type_(UITestBase::DEFAULT_THEME), | 121 profile_type_(UITestBase::DEFAULT_THEME), |
124 shutdown_type_(UITestBase::WINDOW_CLOSE), | 122 shutdown_type_(UITestBase::WINDOW_CLOSE), |
125 test_start_time_(Time::NowFromSystemTime()), | 123 test_start_time_(Time::NowFromSystemTime()), |
126 command_execution_timeout_ms_(kCommandExecutionTimeout), | 124 command_execution_timeout_ms_(kCommandExecutionTimeout), |
127 action_timeout_ms_(kWaitForActionMsec), | 125 action_timeout_ms_(kWaitForActionMsec), |
128 action_max_timeout_ms_(kWaitForActionMaxMsec), | 126 action_max_timeout_ms_(kWaitForActionMaxMsec), |
129 sleep_timeout_ms_(kWaitForActionMsec), | 127 sleep_timeout_ms_(kWaitForActionMsec), |
130 terminate_timeout_ms_(kWaitForTerminateMsec) { | 128 terminate_timeout_ms_(kWaitForTerminateMsec) { |
131 PathService::Get(chrome::DIR_APP, &browser_directory_); | 129 PathService::Get(chrome::DIR_APP, &browser_directory_); |
132 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); | 130 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); |
133 } | 131 } |
134 | 132 |
135 UITestBase::UITestBase(MessageLoop::Type msg_loop_type) | 133 UITestBase::UITestBase(MessageLoop::Type msg_loop_type) |
136 : launch_arguments_(CommandLine::ARGUMENTS_ONLY), | 134 : launch_arguments_(CommandLine::ARGUMENTS_ONLY), |
137 expected_errors_(0), | 135 expected_errors_(0), |
138 expected_crashes_(0), | 136 expected_crashes_(0), |
139 homepage_(L"about:blank"), | 137 homepage_(L"about:blank"), |
140 wait_for_initial_loads_(true), | 138 wait_for_initial_loads_(true), |
141 dom_automation_enabled_(false), | 139 dom_automation_enabled_(false), |
142 process_(base::kNullProcessHandle), | 140 process_(base::kNullProcessHandle), |
143 process_id_(-1), | 141 process_id_(-1), |
144 show_window_(false), | 142 show_window_(false), |
145 clear_profile_(true), | 143 clear_profile_(true), |
146 include_testing_id_(true), | 144 include_testing_id_(true), |
147 use_existing_browser_(default_use_existing_browser_), | |
148 enable_file_cookies_(true), | 145 enable_file_cookies_(true), |
149 profile_type_(UITestBase::DEFAULT_THEME), | 146 profile_type_(UITestBase::DEFAULT_THEME), |
150 shutdown_type_(UITestBase::WINDOW_CLOSE), | 147 shutdown_type_(UITestBase::WINDOW_CLOSE), |
151 test_start_time_(Time::NowFromSystemTime()), | 148 test_start_time_(Time::NowFromSystemTime()), |
152 command_execution_timeout_ms_(kCommandExecutionTimeout), | 149 command_execution_timeout_ms_(kCommandExecutionTimeout), |
153 action_timeout_ms_(kWaitForActionMsec), | 150 action_timeout_ms_(kWaitForActionMsec), |
154 action_max_timeout_ms_(kWaitForActionMaxMsec), | 151 action_max_timeout_ms_(kWaitForActionMaxMsec), |
155 sleep_timeout_ms_(kWaitForActionMsec), | 152 sleep_timeout_ms_(kWaitForActionMsec), |
156 terminate_timeout_ms_(kWaitForTerminateMsec) { | 153 terminate_timeout_ms_(kWaitForTerminateMsec) { |
157 PathService::Get(chrome::DIR_APP, &browser_directory_); | 154 PathService::Get(chrome::DIR_APP, &browser_directory_); |
158 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); | 155 PathService::Get(chrome::DIR_TEST_DATA, &test_data_directory_); |
159 } | 156 } |
160 | 157 |
161 UITestBase::~UITestBase() { | 158 UITestBase::~UITestBase() { |
162 } | 159 } |
163 | 160 |
164 void UITestBase::SetUp() { | 161 void UITestBase::SetUp() { |
165 if (!use_existing_browser_) { | 162 AssertAppNotRunning(L"Please close any other instances " |
166 AssertAppNotRunning(L"Please close any other instances " | 163 L"of the app before testing."); |
167 L"of the app before testing."); | |
168 } | |
169 | 164 |
170 InitializeTimeouts(); | 165 InitializeTimeouts(); |
171 JavaScriptExecutionController::set_timeout(action_max_timeout_ms_); | 166 JavaScriptExecutionController::set_timeout(action_max_timeout_ms_); |
172 LaunchBrowserAndServer(); | 167 LaunchBrowserAndServer(); |
173 } | 168 } |
174 | 169 |
175 void UITestBase::TearDown() { | 170 void UITestBase::TearDown() { |
176 CloseBrowserAndServer(); | 171 CloseBrowserAndServer(); |
177 | 172 |
178 // Make sure that we didn't encounter any assertion failures | 173 // Make sure that we didn't encounter any assertion failures |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 // If we're using the complex theme data, we need to write the | 389 // If we're using the complex theme data, we need to write the |
395 // user_data_dir_ to our preferences file. | 390 // user_data_dir_ to our preferences file. |
396 if (profile_type_ == UITestBase::COMPLEX_THEME) { | 391 if (profile_type_ == UITestBase::COMPLEX_THEME) { |
397 RewritePreferencesFile(user_data_dir_); | 392 RewritePreferencesFile(user_data_dir_); |
398 } | 393 } |
399 | 394 |
400 // Update the history file to include recent dates. | 395 // Update the history file to include recent dates. |
401 UpdateHistoryDates(); | 396 UpdateHistoryDates(); |
402 } | 397 } |
403 | 398 |
404 ASSERT_TRUE(LaunchBrowserHelper(arguments, use_existing_browser_, false, | 399 ASSERT_TRUE(LaunchBrowserHelper(arguments, false, &process_)); |
405 &process_)); | |
406 process_id_ = base::GetProcId(process_); | 400 process_id_ = base::GetProcId(process_); |
407 } | 401 } |
408 | 402 |
409 bool UITestBase::LaunchAnotherBrowserBlockUntilClosed( | 403 bool UITestBase::LaunchAnotherBrowserBlockUntilClosed( |
410 const CommandLine& cmdline) { | 404 const CommandLine& cmdline) { |
411 return LaunchBrowserHelper(cmdline, false, true, NULL); | 405 return LaunchBrowserHelper(cmdline, true, NULL); |
412 } | 406 } |
413 | 407 |
414 void UITestBase::QuitBrowser() { | 408 void UITestBase::QuitBrowser() { |
415 if (SESSION_ENDING == shutdown_type_) { | 409 if (SESSION_ENDING == shutdown_type_) { |
416 TerminateBrowser(); | 410 TerminateBrowser(); |
417 return; | 411 return; |
418 } | 412 } |
419 | 413 |
420 // There's nothing to do here if the browser is not running. | 414 // There's nothing to do here if the browser is not running. |
421 if (IsBrowserRunning()) { | 415 if (IsBrowserRunning()) { |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1072 } else { | 1066 } else { |
1073 EXPECT_NE(generated_file_size, original_file_size); | 1067 EXPECT_NE(generated_file_size, original_file_size); |
1074 EXPECT_FALSE(file_util::ContentsEqual(generated_file, original_file)); | 1068 EXPECT_FALSE(file_util::ContentsEqual(generated_file, original_file)); |
1075 } | 1069 } |
1076 } | 1070 } |
1077 if (delete_generated_file) | 1071 if (delete_generated_file) |
1078 EXPECT_TRUE(file_util::DieFileDie(generated_file, false)); | 1072 EXPECT_TRUE(file_util::DieFileDie(generated_file, false)); |
1079 } | 1073 } |
1080 | 1074 |
1081 bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, | 1075 bool UITestBase::LaunchBrowserHelper(const CommandLine& arguments, |
1082 bool use_existing_browser, | 1076 bool wait, |
1083 bool wait, | 1077 base::ProcessHandle* process) { |
1084 base::ProcessHandle* process) { | |
1085 FilePath command = browser_directory_.Append( | 1078 FilePath command = browser_directory_.Append( |
1086 FilePath::FromWStringHack(chrome::kBrowserProcessExecutablePath)); | 1079 FilePath::FromWStringHack(chrome::kBrowserProcessExecutablePath)); |
1087 CommandLine command_line(command); | 1080 CommandLine command_line(command); |
1088 | 1081 |
1089 // Add any explicit command line flags passed to the process. | 1082 // Add any explicit command line flags passed to the process. |
1090 std::wstring extra_chrome_flags = | 1083 std::wstring extra_chrome_flags = |
1091 CommandLine::ForCurrentProcess()->GetSwitchValue(kExtraChromeFlagsSwitch); | 1084 CommandLine::ForCurrentProcess()->GetSwitchValue(kExtraChromeFlagsSwitch); |
1092 if (!extra_chrome_flags.empty()) { | 1085 if (!extra_chrome_flags.empty()) { |
1093 // Split by spaces and append to command line | 1086 // Split by spaces and append to command line |
1094 std::vector<std::wstring> flags; | 1087 std::vector<std::wstring> flags; |
(...skipping 14 matching lines...) Expand all Loading... |
1109 ASCIIToWide(kUITestType)); | 1102 ASCIIToWide(kUITestType)); |
1110 | 1103 |
1111 // We need cookies on file:// for things like the page cycler. | 1104 // We need cookies on file:// for things like the page cycler. |
1112 if (enable_file_cookies_) | 1105 if (enable_file_cookies_) |
1113 command_line.AppendSwitch(switches::kEnableFileCookies); | 1106 command_line.AppendSwitch(switches::kEnableFileCookies); |
1114 | 1107 |
1115 if (dom_automation_enabled_) | 1108 if (dom_automation_enabled_) |
1116 command_line.AppendSwitch(switches::kDomAutomationController); | 1109 command_line.AppendSwitch(switches::kDomAutomationController); |
1117 | 1110 |
1118 if (include_testing_id_) { | 1111 if (include_testing_id_) { |
1119 if (use_existing_browser) { | 1112 command_line.AppendSwitchWithValue(switches::kTestingChannelID, |
1120 // TODO(erikkay): The new switch depends on a browser instance already | 1113 ASCIIToWide(server_->channel_id())); |
1121 // running, it won't open a new browser window if it's not. We could fix | |
1122 // this by passing an url (e.g. about:blank) on the command line, but | |
1123 // I decided to keep using the old switch in the existing use case to | |
1124 // minimize changes in behavior. | |
1125 command_line.AppendSwitchWithValue(switches::kAutomationClientChannelID, | |
1126 ASCIIToWide(server_->channel_id())); | |
1127 } else { | |
1128 command_line.AppendSwitchWithValue(switches::kTestingChannelID, | |
1129 ASCIIToWide(server_->channel_id())); | |
1130 } | |
1131 } | 1114 } |
1132 | 1115 |
1133 if (!show_error_dialogs_ && | 1116 if (!show_error_dialogs_ && |
1134 !CommandLine::ForCurrentProcess()->HasSwitch(kEnableErrorDialogs)) { | 1117 !CommandLine::ForCurrentProcess()->HasSwitch(kEnableErrorDialogs)) { |
1135 command_line.AppendSwitch(switches::kNoErrorDialogs); | 1118 command_line.AppendSwitch(switches::kNoErrorDialogs); |
1136 } | 1119 } |
1137 if (in_process_renderer_) | 1120 if (in_process_renderer_) |
1138 command_line.AppendSwitch(switches::kSingleProcess); | 1121 command_line.AppendSwitch(switches::kSingleProcess); |
1139 if (no_sandbox_) | 1122 if (no_sandbox_) |
1140 command_line.AppendSwitch(switches::kNoSandbox); | 1123 command_line.AppendSwitch(switches::kNoSandbox); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 command_line.PrependWrapper(ASCIIToWide(browser_wrapper)); | 1187 command_line.PrependWrapper(ASCIIToWide(browser_wrapper)); |
1205 LOG(INFO) << "BROWSER_WRAPPER was set, prefixing command_line with " | 1188 LOG(INFO) << "BROWSER_WRAPPER was set, prefixing command_line with " |
1206 << browser_wrapper; | 1189 << browser_wrapper; |
1207 } | 1190 } |
1208 | 1191 |
1209 bool started = base::LaunchApp(command_line.argv(), | 1192 bool started = base::LaunchApp(command_line.argv(), |
1210 server_->fds_to_map(), | 1193 server_->fds_to_map(), |
1211 wait, | 1194 wait, |
1212 process); | 1195 process); |
1213 #endif | 1196 #endif |
1214 if (!started) | |
1215 return false; | |
1216 | 1197 |
1217 if (use_existing_browser) { | 1198 return started; |
1218 #if defined(OS_WIN) | |
1219 DWORD pid = 0; | |
1220 HWND hwnd = FindWindowEx(HWND_MESSAGE, NULL, chrome::kMessageWindowClass, | |
1221 user_data_dir_.value().c_str()); | |
1222 GetWindowThreadProcessId(hwnd, &pid); | |
1223 // This mode doesn't work if we wound up launching a new browser ourselves. | |
1224 EXPECT_NE(pid, base::GetProcId(*process)); | |
1225 CloseHandle(*process); | |
1226 *process = OpenProcess(SYNCHRONIZE, false, pid); | |
1227 #else | |
1228 // TODO(port): above code is very Windows-specific; we need to | |
1229 // figure out and abstract out how we'll handle finding any existing | |
1230 // running process, etc. on other platforms. | |
1231 NOTIMPLEMENTED(); | |
1232 #endif | |
1233 } | |
1234 | |
1235 return true; | |
1236 } | 1199 } |
1237 | 1200 |
1238 void UITestBase::UpdateHistoryDates() { | 1201 void UITestBase::UpdateHistoryDates() { |
1239 // Migrate the times in the segment_usage table to yesterday so we get | 1202 // Migrate the times in the segment_usage table to yesterday so we get |
1240 // actual thumbnails on the NTP. | 1203 // actual thumbnails on the NTP. |
1241 sql::Connection db; | 1204 sql::Connection db; |
1242 FilePath history = | 1205 FilePath history = |
1243 user_data_dir_.AppendASCII("Default").AppendASCII("History"); | 1206 user_data_dir_.AppendASCII("Default").AppendASCII("History"); |
1244 // Not all test profiles have a history file. | 1207 // Not all test profiles have a history file. |
1245 if (!file_util::PathExists(history)) | 1208 if (!file_util::PathExists(history)) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 set_ui_test_name(ASCIIToWide(test_name)); | 1498 set_ui_test_name(ASCIIToWide(test_name)); |
1536 } | 1499 } |
1537 UITestBase::SetUp(); | 1500 UITestBase::SetUp(); |
1538 PlatformTest::SetUp(); | 1501 PlatformTest::SetUp(); |
1539 } | 1502 } |
1540 | 1503 |
1541 void UITest::TearDown() { | 1504 void UITest::TearDown() { |
1542 UITestBase::TearDown(); | 1505 UITestBase::TearDown(); |
1543 PlatformTest::TearDown(); | 1506 PlatformTest::TearDown(); |
1544 } | 1507 } |
OLD | NEW |