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/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/environment.h" | 13 #include "base/environment.h" |
14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
15 #include "base/file_util.h" | 15 #include "base/file_util.h" |
16 #include "base/json/json_writer.h" | 16 #include "base/json/json_writer.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
| 19 #include "base/string_number_conversions.h" |
| 20 #include "base/string_split.h" |
19 #include "base/stringprintf.h" | 21 #include "base/stringprintf.h" |
20 #include "base/utf_string_conversions.h" | 22 #include "base/utf_string_conversions.h" |
21 #include "base/values.h" | 23 #include "base/values.h" |
22 #include "chrome/common/automation_constants.h" | 24 #include "chrome/common/automation_constants.h" |
23 #include "chrome/common/chrome_constants.h" | 25 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_switches.h" | 26 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
26 #include "chrome/test/automation/automation_json_requests.h" | 28 #include "chrome/test/automation/automation_json_requests.h" |
27 #include "chrome/test/automation/automation_proxy.h" | 29 #include "chrome/test/automation/automation_proxy.h" |
28 #include "chrome/test/automation/proxy_launcher.h" | 30 #include "chrome/test/automation/proxy_launcher.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 }; | 167 }; |
166 | 168 |
167 if (!launcher_->LaunchBrowserAndServer(launch_props, true)) { | 169 if (!launcher_->LaunchBrowserAndServer(launch_props, true)) { |
168 *error = new Error( | 170 *error = new Error( |
169 kUnknownError, | 171 kUnknownError, |
170 "Unable to either launch or connect to Chrome. Please check that " | 172 "Unable to either launch or connect to Chrome. Please check that " |
171 "ChromeDriver is up-to-date"); | 173 "ChromeDriver is up-to-date"); |
172 return; | 174 return; |
173 } | 175 } |
174 | 176 |
175 int version = 0; | 177 bool has_automation_version = false; |
176 std::string error_msg; | 178 *error = CompareVersion(730, 0, &has_automation_version); |
177 if (!SendGetChromeDriverAutomationVersion( | 179 if (*error) |
178 automation(), &version, &error_msg)) { | |
179 *error = CreateChromeError(error_msg); | |
180 return; | 180 return; |
181 } | 181 if (has_automation_version) { |
182 if (version > automation::kChromeDriverAutomationVersion) { | 182 int version = 0; |
183 *error = new Error( | 183 std::string error_msg; |
184 kUnknownError, | 184 if (!SendGetChromeDriverAutomationVersion( |
185 "ChromeDriver is not compatible with this version of Chrome."); | 185 automation(), &version, &error_msg)) { |
186 return; | 186 *error = CreateChromeError(error_msg); |
| 187 return; |
| 188 } |
| 189 if (version > automation::kChromeDriverAutomationVersion) { |
| 190 *error = new Error( |
| 191 kUnknownError, |
| 192 "ChromeDriver is not compatible with this version of Chrome."); |
| 193 return; |
| 194 } |
187 } | 195 } |
188 } | 196 } |
189 | 197 |
190 void Automation::Terminate() { | 198 void Automation::Terminate() { |
191 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { | 199 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { |
192 launcher_->QuitBrowser(); | 200 launcher_->QuitBrowser(); |
193 } | 201 } |
194 } | 202 } |
195 | 203 |
196 void Automation::ExecuteScript(int tab_id, | 204 void Automation::ExecuteScript(int tab_id, |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 std::string error_msg; | 267 std::string error_msg; |
260 if (!SendMouseDragJSONRequest(automation(), windex, tab_index, start.x(), | 268 if (!SendMouseDragJSONRequest(automation(), windex, tab_index, start.x(), |
261 start.y(), end.x(), end.y(), &error_msg)) { | 269 start.y(), end.x(), end.y(), &error_msg)) { |
262 *error = CreateChromeError(error_msg); | 270 *error = CreateChromeError(error_msg); |
263 } | 271 } |
264 } | 272 } |
265 | 273 |
266 void Automation::MouseButtonUp(int tab_id, | 274 void Automation::MouseButtonUp(int tab_id, |
267 const gfx::Point& p, | 275 const gfx::Point& p, |
268 Error** error) { | 276 Error** error) { |
| 277 *error = CheckAdvancedInteractionsSupported(); |
| 278 if (*error) |
| 279 return; |
| 280 |
269 int windex = 0, tab_index = 0; | 281 int windex = 0, tab_index = 0; |
270 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 282 *error = GetIndicesForTab(tab_id, &windex, &tab_index); |
271 if (*error) | 283 if (*error) |
272 return; | 284 return; |
273 | 285 |
274 std::string error_msg; | 286 std::string error_msg; |
275 if (!SendMouseButtonUpJSONRequest( | 287 if (!SendMouseButtonUpJSONRequest( |
276 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { | 288 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { |
277 *error = CreateChromeError(error_msg); | 289 *error = CreateChromeError(error_msg); |
278 } | 290 } |
279 } | 291 } |
280 | 292 |
281 void Automation::MouseButtonDown(int tab_id, | 293 void Automation::MouseButtonDown(int tab_id, |
282 const gfx::Point& p, | 294 const gfx::Point& p, |
283 Error** error) { | 295 Error** error) { |
| 296 *error = CheckAdvancedInteractionsSupported(); |
| 297 if (*error) |
| 298 return; |
| 299 |
284 int windex = 0, tab_index = 0; | 300 int windex = 0, tab_index = 0; |
285 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 301 *error = GetIndicesForTab(tab_id, &windex, &tab_index); |
286 if (*error) | 302 if (*error) |
287 return; | 303 return; |
288 | 304 |
289 std::string error_msg; | 305 std::string error_msg; |
290 if (!SendMouseButtonDownJSONRequest( | 306 if (!SendMouseButtonDownJSONRequest( |
291 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { | 307 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { |
292 *error = CreateChromeError(error_msg); | 308 *error = CreateChromeError(error_msg); |
293 } | 309 } |
294 } | 310 } |
295 | 311 |
296 void Automation::MouseDoubleClick(int tab_id, | 312 void Automation::MouseDoubleClick(int tab_id, |
297 const gfx::Point& p, | 313 const gfx::Point& p, |
298 Error** error) { | 314 Error** error) { |
| 315 *error = CheckAdvancedInteractionsSupported(); |
| 316 if (*error) |
| 317 return; |
| 318 |
299 int windex = 0, tab_index = 0; | 319 int windex = 0, tab_index = 0; |
300 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 320 *error = GetIndicesForTab(tab_id, &windex, &tab_index); |
301 if (*error) | 321 if (*error) |
302 return; | 322 return; |
303 | 323 |
304 std::string error_msg; | 324 std::string error_msg; |
305 if (!SendMouseDoubleClickJSONRequest( | 325 if (!SendMouseDoubleClickJSONRequest( |
306 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { | 326 automation(), windex, tab_index, p.x(), p.y(), &error_msg)) { |
307 *error = CreateChromeError(error_msg); | 327 *error = CreateChromeError(error_msg); |
308 } | 328 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 527 *error = GetIndicesForTab(tab_id, &windex, &tab_index); |
508 if (*error) | 528 if (*error) |
509 return; | 529 return; |
510 | 530 |
511 std::string error_msg; | 531 std::string error_msg; |
512 if (!SendCloseTabJSONRequest(automation(), windex, tab_index, &error_msg)) | 532 if (!SendCloseTabJSONRequest(automation(), windex, tab_index, &error_msg)) |
513 *error = CreateChromeError(error_msg); | 533 *error = CreateChromeError(error_msg); |
514 } | 534 } |
515 | 535 |
516 void Automation::GetAppModalDialogMessage(std::string* message, Error** error) { | 536 void Automation::GetAppModalDialogMessage(std::string* message, Error** error) { |
| 537 *error = CheckAlertsSupported(); |
| 538 if (*error) |
| 539 return; |
| 540 |
517 std::string error_msg; | 541 std::string error_msg; |
518 if (!SendGetAppModalDialogMessageJSONRequest( | 542 if (!SendGetAppModalDialogMessageJSONRequest( |
519 automation(), message, &error_msg)) { | 543 automation(), message, &error_msg)) { |
520 *error = CreateChromeError(error_msg); | 544 *error = CreateChromeError(error_msg); |
521 } | 545 } |
522 } | 546 } |
523 | 547 |
524 void Automation::AcceptOrDismissAppModalDialog(bool accept, Error** error) { | 548 void Automation::AcceptOrDismissAppModalDialog(bool accept, Error** error) { |
| 549 *error = CheckAlertsSupported(); |
| 550 if (*error) |
| 551 return; |
| 552 |
525 std::string error_msg; | 553 std::string error_msg; |
526 if (!SendAcceptOrDismissAppModalDialogJSONRequest( | 554 if (!SendAcceptOrDismissAppModalDialogJSONRequest( |
527 automation(), accept, &error_msg)) { | 555 automation(), accept, &error_msg)) { |
528 *error = CreateChromeError(error_msg); | 556 *error = CreateChromeError(error_msg); |
529 } | 557 } |
530 } | 558 } |
531 | 559 |
532 void Automation::AcceptPromptAppModalDialog(const std::string& prompt_text, | 560 void Automation::AcceptPromptAppModalDialog(const std::string& prompt_text, |
533 Error** error) { | 561 Error** error) { |
| 562 *error = CheckAlertsSupported(); |
| 563 if (*error) |
| 564 return; |
| 565 |
534 std::string error_msg; | 566 std::string error_msg; |
535 if (!SendAcceptPromptAppModalDialogJSONRequest( | 567 if (!SendAcceptPromptAppModalDialogJSONRequest( |
536 automation(), prompt_text, &error_msg)) { | 568 automation(), prompt_text, &error_msg)) { |
537 *error = CreateChromeError(error_msg); | 569 *error = CreateChromeError(error_msg); |
538 } | 570 } |
539 } | 571 } |
540 | 572 |
541 void Automation::GetBrowserVersion(std::string* version) { | 573 void Automation::GetBrowserVersion(std::string* version) { |
542 *version = automation()->server_version(); | 574 *version = automation()->server_version(); |
543 } | 575 } |
(...skipping 21 matching lines...) Expand all Loading... |
565 automation(), tab_id, browser_index, tab_index, &error_msg)) { | 597 automation(), tab_id, browser_index, tab_index, &error_msg)) { |
566 return CreateChromeError(error_msg); | 598 return CreateChromeError(error_msg); |
567 } | 599 } |
568 return NULL; | 600 return NULL; |
569 } | 601 } |
570 | 602 |
571 Error* Automation::CreateChromeError(const std::string& message) { | 603 Error* Automation::CreateChromeError(const std::string& message) { |
572 return new Error(kUnknownError, "Internal Chrome error: " + message); | 604 return new Error(kUnknownError, "Internal Chrome error: " + message); |
573 } | 605 } |
574 | 606 |
| 607 Error* Automation::CompareVersion(int client_build_no, |
| 608 int client_patch_no, |
| 609 bool* is_newer_or_equal) { |
| 610 std::string version = automation()->server_version(); |
| 611 std::vector<std::string> split_version; |
| 612 base::SplitString(version, '.', &split_version); |
| 613 if (split_version.size() != 4) { |
| 614 return new Error( |
| 615 kUnknownError, "Browser version has unrecognized format: " + version); |
| 616 } |
| 617 int build_no, patch_no; |
| 618 if (!base::StringToInt(split_version[2], &build_no) || |
| 619 !base::StringToInt(split_version[3], &patch_no)) { |
| 620 return new Error( |
| 621 kUnknownError, "Browser version has unrecognized format: " + version); |
| 622 } |
| 623 if (build_no < client_build_no) |
| 624 *is_newer_or_equal = false; |
| 625 else if (build_no > client_build_no) |
| 626 *is_newer_or_equal = true; |
| 627 else |
| 628 *is_newer_or_equal = patch_no >= client_patch_no; |
| 629 return NULL; |
| 630 } |
| 631 |
| 632 Error* Automation::CheckVersion(int client_build_no, |
| 633 int client_patch_no, |
| 634 const std::string& error_msg) { |
| 635 bool version_is_ok = false; |
| 636 Error* error = CompareVersion( |
| 637 client_build_no, client_patch_no, &version_is_ok); |
| 638 if (error) |
| 639 return error; |
| 640 if (!version_is_ok) |
| 641 return new Error(kUnknownError, error_msg); |
| 642 return NULL; |
| 643 } |
| 644 |
| 645 Error* Automation::CheckAlertsSupported() { |
| 646 return CheckVersion( |
| 647 768, 0, "Alerts are not supported for this version of Chrome"); |
| 648 } |
| 649 |
| 650 Error* Automation::CheckAdvancedInteractionsSupported() { |
| 651 const char* message = |
| 652 "Advanced user interactions are not supported for this version of Chrome"; |
| 653 return CheckVersion(750, 0, message); |
| 654 } |
| 655 |
575 } // namespace webdriver | 656 } // namespace webdriver |
OLD | NEW |