| 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/webdriver_automation.h" | 5 #include "chrome/test/webdriver/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 |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 return; | 299 return; |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 void Automation::Terminate() { | 303 void Automation::Terminate() { |
| 304 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { | 304 if (launcher_.get() && launcher_->process() != base::kNullProcessHandle) { |
| 305 launcher_->QuitBrowser(); | 305 launcher_->QuitBrowser(); |
| 306 } | 306 } |
| 307 } | 307 } |
| 308 | 308 |
| 309 void Automation::ExecuteScript(int tab_id, | 309 void Automation::ExecuteScript(const WebViewId& view_id, |
| 310 const FramePath& frame_path, | 310 const FramePath& frame_path, |
| 311 const std::string& script, | 311 const std::string& script, |
| 312 std::string* result, | 312 std::string* result, |
| 313 Error** error) { | 313 Error** error) { |
| 314 int windex = 0, tab_index = 0; | 314 WebViewLocator view_locator; |
| 315 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 315 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 316 if (*error) | 316 if (*error) |
| 317 return; | 317 return; |
| 318 | 318 |
| 319 Value* unscoped_value; | 319 Value* unscoped_value; |
| 320 std::string error_msg; | 320 std::string error_msg; |
| 321 if (!SendExecuteJavascriptJSONRequest(automation(), windex, tab_index, | 321 if (!SendExecuteJavascriptJSONRequest(automation(), view_locator, |
| 322 frame_path.value(), script, | 322 frame_path.value(), script, |
| 323 &unscoped_value, &error_msg)) { | 323 &unscoped_value, &error_msg)) { |
| 324 *error = new Error(kUnknownError, error_msg); | 324 *error = new Error(kUnknownError, error_msg); |
| 325 return; | 325 return; |
| 326 } | 326 } |
| 327 scoped_ptr<Value> value(unscoped_value); | 327 scoped_ptr<Value> value(unscoped_value); |
| 328 if (!value->GetAsString(result)) | 328 if (!value->GetAsString(result)) |
| 329 *error = new Error(kUnknownError, "Execute script did not return string"); | 329 *error = new Error(kUnknownError, "Execute script did not return string"); |
| 330 } | 330 } |
| 331 | 331 |
| 332 void Automation::MouseMove(int tab_id, | 332 void Automation::MouseMove(const WebViewId& view_id, |
| 333 const Point& p, | 333 const Point& p, |
| 334 Error** error) { | 334 Error** error) { |
| 335 int windex = 0, tab_index = 0; | 335 WebViewLocator view_locator; |
| 336 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 336 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 337 if (*error) | 337 if (*error) |
| 338 return; | 338 return; |
| 339 | 339 |
| 340 std::string error_msg; | 340 std::string error_msg; |
| 341 if (!SendMouseMoveJSONRequest( | 341 if (!SendMouseMoveJSONRequest( |
| 342 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), | 342 automation(), view_locator, p.rounded_x(), p.rounded_y(), |
| 343 &error_msg)) { | 343 &error_msg)) { |
| 344 *error = new Error(kUnknownError, error_msg); | 344 *error = new Error(kUnknownError, error_msg); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 void Automation::MouseClick(int tab_id, | 348 void Automation::MouseClick(const WebViewId& view_id, |
| 349 const Point& p, | 349 const Point& p, |
| 350 automation::MouseButton button, | 350 automation::MouseButton button, |
| 351 Error** error) { | 351 Error** error) { |
| 352 int windex = 0, tab_index = 0; | 352 WebViewLocator view_locator; |
| 353 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 353 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 354 if (*error) | 354 if (*error) |
| 355 return; | 355 return; |
| 356 | 356 |
| 357 std::string error_msg; | 357 std::string error_msg; |
| 358 if (!SendMouseClickJSONRequest( | 358 if (!SendMouseClickJSONRequest( |
| 359 automation(), windex, tab_index, button, p.rounded_x(), | 359 automation(), view_locator, button, p.rounded_x(), |
| 360 p.rounded_y(), &error_msg)) { | 360 p.rounded_y(), &error_msg)) { |
| 361 *error = new Error(kUnknownError, error_msg); | 361 *error = new Error(kUnknownError, error_msg); |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 void Automation::MouseDrag(int tab_id, | 365 void Automation::MouseDrag(const WebViewId& view_id, |
| 366 const Point& start, | 366 const Point& start, |
| 367 const Point& end, | 367 const Point& end, |
| 368 Error** error) { | 368 Error** error) { |
| 369 int windex = 0, tab_index = 0; | 369 WebViewLocator view_locator; |
| 370 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 370 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 371 if (*error) | 371 if (*error) |
| 372 return; | 372 return; |
| 373 | 373 |
| 374 std::string error_msg; | 374 std::string error_msg; |
| 375 if (!SendMouseDragJSONRequest( | 375 if (!SendMouseDragJSONRequest( |
| 376 automation(), windex, tab_index, start.rounded_x(), start.rounded_y(), | 376 automation(), view_locator, start.rounded_x(), start.rounded_y(), |
| 377 end.rounded_x(), end.rounded_y(), &error_msg)) { | 377 end.rounded_x(), end.rounded_y(), &error_msg)) { |
| 378 *error = new Error(kUnknownError, error_msg); | 378 *error = new Error(kUnknownError, error_msg); |
| 379 } | 379 } |
| 380 } | 380 } |
| 381 | 381 |
| 382 void Automation::MouseButtonUp(int tab_id, | 382 void Automation::MouseButtonUp(const WebViewId& view_id, |
| 383 const Point& p, | 383 const Point& p, |
| 384 Error** error) { | 384 Error** error) { |
| 385 *error = CheckAdvancedInteractionsSupported(); | 385 *error = CheckAdvancedInteractionsSupported(); |
| 386 if (*error) | 386 if (*error) |
| 387 return; | 387 return; |
| 388 | 388 |
| 389 int windex = 0, tab_index = 0; | 389 WebViewLocator view_locator; |
| 390 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 390 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 391 if (*error) | 391 if (*error) |
| 392 return; | 392 return; |
| 393 | 393 |
| 394 std::string error_msg; | 394 std::string error_msg; |
| 395 if (!SendMouseButtonUpJSONRequest( | 395 if (!SendMouseButtonUpJSONRequest( |
| 396 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), | 396 automation(), view_locator, p.rounded_x(), p.rounded_y(), |
| 397 &error_msg)) { | 397 &error_msg)) { |
| 398 *error = new Error(kUnknownError, error_msg); | 398 *error = new Error(kUnknownError, error_msg); |
| 399 } | 399 } |
| 400 } | 400 } |
| 401 | 401 |
| 402 void Automation::MouseButtonDown(int tab_id, | 402 void Automation::MouseButtonDown(const WebViewId& view_id, |
| 403 const Point& p, | 403 const Point& p, |
| 404 Error** error) { | 404 Error** error) { |
| 405 *error = CheckAdvancedInteractionsSupported(); | 405 *error = CheckAdvancedInteractionsSupported(); |
| 406 if (*error) | 406 if (*error) |
| 407 return; | 407 return; |
| 408 | 408 |
| 409 int windex = 0, tab_index = 0; | 409 WebViewLocator view_locator; |
| 410 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 410 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 411 if (*error) | 411 if (*error) |
| 412 return; | 412 return; |
| 413 | 413 |
| 414 std::string error_msg; | 414 std::string error_msg; |
| 415 if (!SendMouseButtonDownJSONRequest( | 415 if (!SendMouseButtonDownJSONRequest( |
| 416 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), | 416 automation(), view_locator, p.rounded_x(), p.rounded_y(), |
| 417 &error_msg)) { | 417 &error_msg)) { |
| 418 *error = new Error(kUnknownError, error_msg); | 418 *error = new Error(kUnknownError, error_msg); |
| 419 } | 419 } |
| 420 } | 420 } |
| 421 | 421 |
| 422 void Automation::MouseDoubleClick(int tab_id, | 422 void Automation::MouseDoubleClick(const WebViewId& view_id, |
| 423 const Point& p, | 423 const Point& p, |
| 424 Error** error) { | 424 Error** error) { |
| 425 *error = CheckAdvancedInteractionsSupported(); | 425 *error = CheckAdvancedInteractionsSupported(); |
| 426 if (*error) | 426 if (*error) |
| 427 return; | 427 return; |
| 428 | 428 |
| 429 int windex = 0, tab_index = 0; | 429 WebViewLocator view_locator; |
| 430 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 430 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 431 if (*error) | 431 if (*error) |
| 432 return; | 432 return; |
| 433 | 433 |
| 434 std::string error_msg; | 434 std::string error_msg; |
| 435 if (!SendMouseDoubleClickJSONRequest( | 435 if (!SendMouseDoubleClickJSONRequest( |
| 436 automation(), windex, tab_index, p.rounded_x(), p.rounded_y(), | 436 automation(), view_locator, p.rounded_x(), p.rounded_y(), |
| 437 &error_msg)) { | 437 &error_msg)) { |
| 438 *error = new Error(kUnknownError, error_msg); | 438 *error = new Error(kUnknownError, error_msg); |
| 439 } | 439 } |
| 440 } | 440 } |
| 441 | 441 |
| 442 void Automation::DragAndDropFilePaths( | 442 void Automation::DragAndDropFilePaths( |
| 443 int tab_id, const Point& location, | 443 const WebViewId& view_id, const Point& location, |
| 444 const std::vector<FilePath::StringType>& paths, Error** error) { | 444 const std::vector<FilePath::StringType>& paths, Error** error) { |
| 445 int windex = 0, tab_index = 0; | 445 WebViewLocator view_locator; |
| 446 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 446 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 447 if (*error) { | 447 if (*error) { |
| 448 return; | 448 return; |
| 449 } | 449 } |
| 450 | 450 |
| 451 std::string error_msg; | 451 std::string error_msg; |
| 452 if (!SendDragAndDropFilePathsJSONRequest( | 452 if (!SendDragAndDropFilePathsJSONRequest( |
| 453 automation(), windex, tab_index, location.rounded_x(), | 453 automation(), view_locator, location.rounded_x(), |
| 454 location.rounded_y(), paths, &error_msg)) { | 454 location.rounded_y(), paths, &error_msg)) { |
| 455 *error = new Error(kUnknownError, error_msg); | 455 *error = new Error(kUnknownError, error_msg); |
| 456 } | 456 } |
| 457 } | 457 } |
| 458 | 458 |
| 459 void Automation::SendWebKeyEvent(int tab_id, | 459 void Automation::SendWebKeyEvent(const WebViewId& view_id, |
| 460 const WebKeyEvent& key_event, | 460 const WebKeyEvent& key_event, |
| 461 Error** error) { | 461 Error** error) { |
| 462 int windex = 0, tab_index = 0; | 462 WebViewLocator view_locator; |
| 463 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 463 *error = ConvertViewIdToLocator(view_id, &view_locator); |
| 464 if (*error) | 464 if (*error) |
| 465 return; | 465 return; |
| 466 | 466 |
| 467 std::string error_msg; | 467 std::string error_msg; |
| 468 if (!SendWebKeyEventJSONRequest( | 468 if (!SendWebKeyEventJSONRequest( |
| 469 automation(), windex, tab_index, key_event, &error_msg)) { | 469 automation(), view_locator, key_event, &error_msg)) { |
| 470 *error = new Error(kUnknownError, error_msg); | 470 *error = new Error(kUnknownError, error_msg); |
| 471 } | 471 } |
| 472 } | 472 } |
| 473 | 473 |
| 474 void Automation::SendNativeKeyEvent(int tab_id, | 474 void Automation::SendNativeKeyEvent(int tab_id, |
| 475 ui::KeyboardCode key_code, | 475 ui::KeyboardCode key_code, |
| 476 int modifiers, | 476 int modifiers, |
| 477 Error** error) { | 477 Error** error) { |
| 478 int windex = 0, tab_index = 0; | 478 int windex = 0, tab_index = 0; |
| 479 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 479 *error = GetIndicesForTab(tab_id, &windex, &tab_index); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 } | 601 } |
| 602 | 602 |
| 603 void Automation::SetCookie(const std::string& url, | 603 void Automation::SetCookie(const std::string& url, |
| 604 DictionaryValue* cookie_dict, | 604 DictionaryValue* cookie_dict, |
| 605 Error** error) { | 605 Error** error) { |
| 606 std::string error_msg; | 606 std::string error_msg; |
| 607 if (!SendSetCookieJSONRequest(automation(), url, cookie_dict, &error_msg)) | 607 if (!SendSetCookieJSONRequest(automation(), url, cookie_dict, &error_msg)) |
| 608 *error = new Error(kUnknownError, error_msg); | 608 *error = new Error(kUnknownError, error_msg); |
| 609 } | 609 } |
| 610 | 610 |
| 611 void Automation::GetTabIds(std::vector<int>* tab_ids, | 611 void Automation::GetViews(std::vector<WebViewInfo>* views, |
| 612 Error** error) { | 612 Error** error) { |
| 613 bool has_views = false; |
| 614 *error = CompareVersion(500, 0, &has_views); |
| 615 if (*error) |
| 616 return; |
| 617 |
| 613 std::string error_msg; | 618 std::string error_msg; |
| 614 if (!SendGetTabIdsJSONRequest(automation(), tab_ids, &error_msg)) | 619 if (has_views) { |
| 615 *error = new Error(kUnknownError, error_msg); | 620 if (!SendGetWebViewsJSONRequest(automation(), views, &error_msg)) |
| 616 } | 621 *error = new Error(kUnknownError, error_msg); |
| 617 | 622 } else { |
| 618 void Automation::DoesTabExist(int tab_id, bool* does_exist, Error** error) { | 623 if (!SendGetTabIdsJSONRequest(automation(), views, &error_msg)) |
| 619 std::string error_msg; | 624 *error = new Error(kUnknownError, error_msg); |
| 620 if (!SendIsTabIdValidJSONRequest( | |
| 621 automation(), tab_id, does_exist, &error_msg)) { | |
| 622 *error = new Error(kUnknownError, error_msg); | |
| 623 } | 625 } |
| 624 } | 626 } |
| 625 | 627 |
| 628 void Automation::DoesViewExist( |
| 629 const WebViewId& view_id, bool* does_exist, Error** error) { |
| 630 std::string error_msg; |
| 631 if (view_id.type == WebViewId::kTypeTabId) { |
| 632 if (!SendIsTabIdValidJSONRequest( |
| 633 automation(), view_id, does_exist, &error_msg)) |
| 634 *error = new Error(kUnknownError, error_msg); |
| 635 } else { |
| 636 if (!SendDoesViewExistJSONRequest( |
| 637 automation(), view_id, does_exist, &error_msg)) |
| 638 *error = new Error(kUnknownError, error_msg); |
| 639 } |
| 640 } |
| 641 |
| 626 void Automation::CloseTab(int tab_id, Error** error) { | 642 void Automation::CloseTab(int tab_id, Error** error) { |
| 627 int windex = 0, tab_index = 0; | 643 int windex = 0, tab_index = 0; |
| 628 *error = GetIndicesForTab(tab_id, &windex, &tab_index); | 644 *error = GetIndicesForTab(tab_id, &windex, &tab_index); |
| 629 if (*error) | 645 if (*error) |
| 630 return; | 646 return; |
| 631 | 647 |
| 632 std::string error_msg; | 648 std::string error_msg; |
| 633 if (!SendCloseTabJSONRequest(automation(), windex, tab_index, &error_msg)) | 649 if (!SendCloseTabJSONRequest(automation(), windex, tab_index, &error_msg)) |
| 634 *error = new Error(kUnknownError, error_msg); | 650 *error = new Error(kUnknownError, error_msg); |
| 635 } | 651 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 automation(), path, false /* with_ui */, extension_id, &error_msg)) | 758 automation(), path, false /* with_ui */, extension_id, &error_msg)) |
| 743 *error = new Error(kUnknownError, error_msg); | 759 *error = new Error(kUnknownError, error_msg); |
| 744 } | 760 } |
| 745 | 761 |
| 746 AutomationProxy* Automation::automation() const { | 762 AutomationProxy* Automation::automation() const { |
| 747 return launcher_->automation(); | 763 return launcher_->automation(); |
| 748 } | 764 } |
| 749 | 765 |
| 750 Error* Automation::GetIndicesForTab( | 766 Error* Automation::GetIndicesForTab( |
| 751 int tab_id, int* browser_index, int* tab_index) { | 767 int tab_id, int* browser_index, int* tab_index) { |
| 752 std::string error_msg; | 768 std::string error_msg; |
| 753 if (!SendGetIndicesFromTabIdJSONRequest( | 769 if (!SendGetIndicesFromTabIdJSONRequest( |
| 754 automation(), tab_id, browser_index, tab_index, &error_msg)) { | 770 automation(), tab_id, browser_index, tab_index, &error_msg)) { |
| 755 return new Error(kUnknownError, error_msg); | 771 return new Error(kUnknownError, error_msg); |
| 772 } |
| 773 return NULL; |
| 774 } |
| 775 |
| 776 Error* Automation::ConvertViewIdToLocator( |
| 777 const WebViewId& view_id, WebViewLocator* view_locator) { |
| 778 if (view_id.type == WebViewId::kTypeTabId) { |
| 779 int browser_index, tab_index; |
| 780 std::string error_msg; |
| 781 if (!SendGetIndicesFromTabIdJSONRequest( |
| 782 automation(), view_id.id.tab_id, &browser_index, &tab_index, &error_
msg)) { |
| 783 return new Error(kUnknownError, error_msg); |
| 784 } |
| 785 view_locator->type = WebViewLocator::kTypeIndexPair; |
| 786 view_locator->locator.index_pair.browser_index = browser_index; |
| 787 view_locator->locator.index_pair.tab_index = tab_index; |
| 788 } else if (view_id.type == WebViewId::kTypeViewId) { |
| 789 view_locator->type = WebViewLocator::kTypeViewId; |
| 790 view_locator->locator.view_id = view_id.id.view_id; |
| 756 } | 791 } |
| 757 return NULL; | 792 return NULL; |
| 758 } | 793 } |
| 759 | 794 |
| 760 Error* Automation::CompareVersion(int client_build_no, | 795 Error* Automation::CompareVersion(int client_build_no, |
| 761 int client_patch_no, | 796 int client_patch_no, |
| 762 bool* is_newer_or_equal) { | 797 bool* is_newer_or_equal) { |
| 763 std::string version = automation()->server_version(); | 798 std::string version = automation()->server_version(); |
| 764 std::vector<std::string> split_version; | 799 std::vector<std::string> split_version; |
| 765 base::SplitString(version, '.', &split_version); | 800 base::SplitString(version, '.', &split_version); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 806 return CheckVersion(750, 0, message); | 841 return CheckVersion(750, 0, message); |
| 807 } | 842 } |
| 808 | 843 |
| 809 Error* Automation::CheckNewExtensionInterfaceSupported() { | 844 Error* Automation::CheckNewExtensionInterfaceSupported() { |
| 810 const char* message = | 845 const char* message = |
| 811 "Extension interface is not supported for this version of Chrome"; | 846 "Extension interface is not supported for this version of Chrome"; |
| 812 return CheckVersion(947, 0, message); | 847 return CheckVersion(947, 0, message); |
| 813 } | 848 } |
| 814 | 849 |
| 815 } // namespace webdriver | 850 } // namespace webdriver |
| OLD | NEW |