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/webdriver/automation.h" | 5 #include "chrome/test/webdriver/automation.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windows.h> | 8 #include <windows.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/callback.h" | 13 #include "base/callback.h" |
14 #include "base/command_line.h" | |
15 #include "base/environment.h" | 14 #include "base/environment.h" |
16 #include "base/file_path.h" | 15 #include "base/file_path.h" |
17 #include "base/file_util.h" | 16 #include "base/file_util.h" |
18 #include "base/json/json_writer.h" | 17 #include "base/json/json_writer.h" |
19 #include "base/logging.h" | 18 #include "base/logging.h" |
20 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
21 #include "base/path_service.h" | 20 #include "base/path_service.h" |
22 #include "base/string_number_conversions.h" | 21 #include "base/string_number_conversions.h" |
23 #include "base/string_split.h" | 22 #include "base/string_split.h" |
24 #include "base/stringprintf.h" | 23 #include "base/stringprintf.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // Step 3: For each browser exe path, check each location to see if the | 176 // Step 3: For each browser exe path, check each location to see if the |
178 // browser is installed there. Check the chromium locations lastly. | 177 // browser is installed there. Check the chromium locations lastly. |
179 return CheckForChromeExe(browser_exes, locations, browser_exe) || | 178 return CheckForChromeExe(browser_exes, locations, browser_exe) || |
180 CheckForChromeExe(browser_exes, chromium_locations, browser_exe); | 179 CheckForChromeExe(browser_exes, chromium_locations, browser_exe); |
181 } | 180 } |
182 | 181 |
183 } // namespace | 182 } // namespace |
184 | 183 |
185 namespace webdriver { | 184 namespace webdriver { |
186 | 185 |
| 186 Automation::BrowserOptions::BrowserOptions() |
| 187 : cmdline(CommandLine::NO_PROGRAM) {} |
| 188 |
| 189 Automation::BrowserOptions::~BrowserOptions() {} |
| 190 |
187 Automation::Automation() {} | 191 Automation::Automation() {} |
188 | 192 |
189 Automation::~Automation() {} | 193 Automation::~Automation() {} |
190 | 194 |
191 void Automation::Init(const CommandLine& options, | 195 void Automation::Init(const BrowserOptions& options, Error** error) { |
192 const FilePath& user_data_dir, | 196 CommandLine cmdline = options.cmdline; |
193 Error** error) { | 197 if (cmdline.GetProgram().empty()) { |
194 FilePath browser_exe; | 198 FilePath browser_exe; |
195 if (!GetDefaultChromeExe(&browser_exe)) { | 199 if (!GetDefaultChromeExe(&browser_exe)) { |
196 *error = new Error(kUnknownError, "Could not find default Chrome binary"); | 200 *error = new Error(kUnknownError, "Could not find default Chrome binary"); |
197 return; | 201 return; |
| 202 } |
| 203 cmdline.SetProgram(browser_exe); |
198 } | 204 } |
199 | 205 if (!file_util::PathExists(cmdline.GetProgram())) { |
200 InitWithBrowserPath(browser_exe, user_data_dir, options, error); | |
201 } | |
202 | |
203 void Automation::InitWithBrowserPath(const FilePath& browser_exe, | |
204 const FilePath& user_data_dir, | |
205 const CommandLine& options, | |
206 Error** error) { | |
207 if (!file_util::PathExists(browser_exe)) { | |
208 std::string message = base::StringPrintf( | 206 std::string message = base::StringPrintf( |
209 "Could not find Chrome binary at: %" PRFilePath, | 207 "Could not find Chrome binary at: %" PRFilePath, |
210 browser_exe.value().c_str()); | 208 cmdline.GetProgram().value().c_str()); |
211 *error = new Error(kUnknownError, message); | 209 *error = new Error(kUnknownError, message); |
212 return; | 210 return; |
213 } | 211 } |
| 212 std::string chrome_details = base::StringPrintf( |
| 213 "Using Chrome binary at: %" PRFilePath, |
| 214 cmdline.GetProgram().value().c_str()); |
| 215 LOG(INFO) << chrome_details; |
214 | 216 |
215 CommandLine command(browser_exe); | 217 cmdline.AppendSwitch(switches::kDisableHangMonitor); |
216 command.AppendSwitch(switches::kDisableHangMonitor); | 218 cmdline.AppendSwitch(switches::kDisablePromptOnRepost); |
217 command.AppendSwitch(switches::kDisablePromptOnRepost); | 219 cmdline.AppendSwitch(switches::kDomAutomationController); |
218 command.AppendSwitch(switches::kDomAutomationController); | 220 cmdline.AppendSwitch(switches::kFullMemoryCrashReport); |
219 command.AppendSwitch(switches::kFullMemoryCrashReport); | 221 cmdline.AppendSwitch(switches::kNoDefaultBrowserCheck); |
220 command.AppendSwitch(switches::kNoDefaultBrowserCheck); | 222 cmdline.AppendSwitch(switches::kNoFirstRun); |
221 command.AppendSwitch(switches::kNoFirstRun); | |
222 command.AppendSwitchASCII(switches::kTestType, "webdriver"); | |
223 | 223 |
224 if (user_data_dir.empty()) | 224 if (options.user_data_dir.empty()) |
225 command.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); | 225 cmdline.AppendSwitchASCII(switches::kHomePage, chrome::kAboutBlankURL); |
226 | 226 |
227 command.AppendArguments(options, false); | 227 if (options.channel_id.empty()) { |
| 228 launcher_.reset(new AnonymousProxyLauncher(false)); |
| 229 } else { |
| 230 launcher_.reset(new NamedProxyLauncher(options.channel_id, false, false)); |
| 231 } |
228 | 232 |
229 launcher_.reset(new AnonymousProxyLauncher(false)); | |
230 ProxyLauncher::LaunchState launch_props = { | 233 ProxyLauncher::LaunchState launch_props = { |
231 false, // clear_profile | 234 false, // clear_profile |
232 user_data_dir, // template_user_data | 235 options.user_data_dir, // template_user_data |
233 base::Closure(), | 236 base::Closure(), |
234 command, | 237 cmdline, |
235 true, // include_testing_id | 238 true, // include_testing_id |
236 true // show_window | 239 true // show_window |
237 }; | 240 }; |
238 | 241 if (!launcher_->InitializeConnection(launch_props, true)) { |
239 std::string chrome_details = base::StringPrintf( | 242 LOG(ERROR) << "Failed to initialize connection"; |
240 "Using Chrome binary at: %" PRFilePath, | |
241 browser_exe.value().c_str()); | |
242 LOG(INFO) << chrome_details; | |
243 | |
244 if (!launcher_->LaunchBrowserAndServer(launch_props, true)) { | |
245 *error = new Error( | 243 *error = new Error( |
246 kUnknownError, | 244 kUnknownError, |
247 "Unable to either launch or connect to Chrome. Please check that " | 245 "Unable to either launch or connect to Chrome. Please check that " |
248 "ChromeDriver is up-to-date. " + chrome_details); | 246 "ChromeDriver is up-to-date. " + chrome_details); |
249 return; | 247 return; |
250 } | 248 } |
251 | 249 |
252 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout); | 250 launcher_->automation()->set_action_timeout_ms(base::kNoTimeout); |
253 LOG(INFO) << "Chrome launched successfully. Version: " | 251 LOG(INFO) << "Chrome launched successfully. Version: " |
254 << automation()->server_version(); | 252 << automation()->server_version(); |
255 | 253 |
256 bool has_automation_version = false; | 254 chrome_details += ", version (" + automation()->server_version() + ")"; |
257 *error = CompareVersion(730, 0, &has_automation_version); | 255 int version = 0; |
258 if (*error) | 256 std::string error_msg; |
| 257 if (!SendGetChromeDriverAutomationVersion( |
| 258 automation(), &version, &error_msg)) { |
| 259 *error = new Error(kUnknownError, error_msg + " " + chrome_details); |
259 return; | 260 return; |
260 | 261 } |
261 chrome_details += ", version (" + automation()->server_version() + ")"; | 262 if (version > automation::kChromeDriverAutomationVersion) { |
262 if (has_automation_version) { | 263 *error = new Error( |
263 int version = 0; | 264 kUnknownError, |
264 std::string error_msg; | 265 "ChromeDriver is not compatible with this version of Chrome. " + |
265 if (!SendGetChromeDriverAutomationVersion( | 266 chrome_details); |
266 automation(), &version, &error_msg)) { | 267 return; |
267 *error = new Error(kUnknownError, error_msg + " " + chrome_details); | |
268 return; | |
269 } | |
270 if (version > automation::kChromeDriverAutomationVersion) { | |
271 *error = new Error( | |
272 kUnknownError, | |
273 "ChromeDriver is not compatible with this version of Chrome. " + | |
274 chrome_details); | |
275 return; | |
276 } | |
277 } | 268 } |
278 } | 269 } |
279 | 270 |
280 void Automation::Terminate() { | 271 void Automation::Terminate() { |
281 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { | 272 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { |
282 launcher_->QuitBrowser(); | 273 launcher_->QuitBrowser(); |
283 } | 274 } |
284 } | 275 } |
285 | 276 |
286 void Automation::ExecuteScript(int tab_id, | 277 void Automation::ExecuteScript(int tab_id, |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 768, 0, "Alerts are not supported for this version of Chrome"); | 711 768, 0, "Alerts are not supported for this version of Chrome"); |
721 } | 712 } |
722 | 713 |
723 Error* Automation::CheckAdvancedInteractionsSupported() { | 714 Error* Automation::CheckAdvancedInteractionsSupported() { |
724 const char* message = | 715 const char* message = |
725 "Advanced user interactions are not supported for this version of Chrome"; | 716 "Advanced user interactions are not supported for this version of Chrome"; |
726 return CheckVersion(750, 0, message); | 717 return CheckVersion(750, 0, message); |
727 } | 718 } |
728 | 719 |
729 } // namespace webdriver | 720 } // namespace webdriver |
OLD | NEW |