| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/chromedriver/session_commands.h" | 5 #include "chrome/test/chromedriver/session_commands.h" |
| 6 | 6 |
| 7 #include <list> | 7 #include <list> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "chrome/test/chromedriver/chrome_launcher.h" | 33 #include "chrome/test/chromedriver/chrome_launcher.h" |
| 34 #include "chrome/test/chromedriver/command_listener.h" | 34 #include "chrome/test/chromedriver/command_listener.h" |
| 35 #include "chrome/test/chromedriver/logging.h" | 35 #include "chrome/test/chromedriver/logging.h" |
| 36 #include "chrome/test/chromedriver/net/url_request_context_getter.h" | 36 #include "chrome/test/chromedriver/net/url_request_context_getter.h" |
| 37 #include "chrome/test/chromedriver/session.h" | 37 #include "chrome/test/chromedriver/session.h" |
| 38 #include "chrome/test/chromedriver/util.h" | 38 #include "chrome/test/chromedriver/util.h" |
| 39 #include "chrome/test/chromedriver/version.h" | 39 #include "chrome/test/chromedriver/version.h" |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 // The minimium chrome build no that supports window management devtools |
| 44 // commands. |
| 45 const int kBrowserWindowDevtoolsBuildNo = 3076; |
| 46 |
| 43 const int kWifiMask = 0x2; | 47 const int kWifiMask = 0x2; |
| 44 const int k4GMask = 0x8; | 48 const int k4GMask = 0x8; |
| 45 const int k3GMask = 0x10; | 49 const int k3GMask = 0x10; |
| 46 const int k2GMask = 0x20; | 50 const int k2GMask = 0x20; |
| 47 | 51 |
| 48 const int kAirplaneModeLatency = 0; | 52 const int kAirplaneModeLatency = 0; |
| 49 const int kAirplaneModeThroughput = 0; | 53 const int kAirplaneModeThroughput = 0; |
| 50 const int kWifiLatency = 2; | 54 const int kWifiLatency = 2; |
| 51 const int kWifiThroughput = 30720 * 1024; | 55 const int kWifiThroughput = 30720 * 1024; |
| 52 const int k4GLatency = 20; | 56 const int k4GLatency = 20; |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 } | 653 } |
| 650 | 654 |
| 651 Status ExecuteGetWindowPosition(Session* session, | 655 Status ExecuteGetWindowPosition(Session* session, |
| 652 const base::DictionaryValue& params, | 656 const base::DictionaryValue& params, |
| 653 std::unique_ptr<base::Value>* value) { | 657 std::unique_ptr<base::Value>* value) { |
| 654 ChromeDesktopImpl* desktop = NULL; | 658 ChromeDesktopImpl* desktop = NULL; |
| 655 Status status = session->chrome->GetAsDesktop(&desktop); | 659 Status status = session->chrome->GetAsDesktop(&desktop); |
| 656 if (status.IsError()) | 660 if (status.IsError()) |
| 657 return status; | 661 return status; |
| 658 | 662 |
| 659 AutomationExtension* extension = NULL; | |
| 660 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); | |
| 661 if (status.IsError()) | |
| 662 return status; | |
| 663 | |
| 664 int x, y; | 663 int x, y; |
| 665 status = extension->GetWindowPosition(&x, &y); | 664 |
| 665 if (desktop->GetBrowserInfo()->build_no >= kBrowserWindowDevtoolsBuildNo) { |
| 666 status = desktop->GetWindowPosition(session->window, &x, &y); |
| 667 } else { |
| 668 AutomationExtension* extension = NULL; |
| 669 status = |
| 670 desktop->GetAutomationExtension(&extension, session->w3c_compliant); |
| 671 if (status.IsError()) |
| 672 return status; |
| 673 |
| 674 status = extension->GetWindowPosition(&x, &y); |
| 675 } |
| 666 if (status.IsError()) | 676 if (status.IsError()) |
| 667 return status; | 677 return status; |
| 668 | 678 |
| 669 base::DictionaryValue position; | 679 base::DictionaryValue position; |
| 670 position.SetInteger("x", x); | 680 position.SetInteger("x", x); |
| 671 position.SetInteger("y", y); | 681 position.SetInteger("y", y); |
| 672 value->reset(position.DeepCopy()); | 682 value->reset(position.DeepCopy()); |
| 673 return Status(kOk); | 683 return Status(kOk); |
| 674 } | 684 } |
| 675 | 685 |
| 676 Status ExecuteSetWindowPosition(Session* session, | 686 Status ExecuteSetWindowPosition(Session* session, |
| 677 const base::DictionaryValue& params, | 687 const base::DictionaryValue& params, |
| 678 std::unique_ptr<base::Value>* value) { | 688 std::unique_ptr<base::Value>* value) { |
| 679 double x = 0; | 689 double x = 0; |
| 680 double y = 0; | 690 double y = 0; |
| 681 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y)) | 691 if (!params.GetDouble("x", &x) || !params.GetDouble("y", &y)) |
| 682 return Status(kUnknownError, "missing or invalid 'x' or 'y'"); | 692 return Status(kUnknownError, "missing or invalid 'x' or 'y'"); |
| 683 | 693 |
| 684 ChromeDesktopImpl* desktop = NULL; | 694 ChromeDesktopImpl* desktop = NULL; |
| 685 Status status = session->chrome->GetAsDesktop(&desktop); | 695 Status status = session->chrome->GetAsDesktop(&desktop); |
| 686 if (status.IsError()) | 696 if (status.IsError()) |
| 687 return status; | 697 return status; |
| 688 | 698 |
| 699 if (desktop->GetBrowserInfo()->build_no >= kBrowserWindowDevtoolsBuildNo) { |
| 700 return desktop->SetWindowPosition(session->window, static_cast<int>(x), |
| 701 static_cast<int>(y)); |
| 702 } |
| 703 |
| 689 AutomationExtension* extension = NULL; | 704 AutomationExtension* extension = NULL; |
| 690 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); | 705 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); |
| 691 if (status.IsError()) | 706 if (status.IsError()) |
| 692 return status; | 707 return status; |
| 693 | 708 |
| 694 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y)); | 709 return extension->SetWindowPosition(static_cast<int>(x), static_cast<int>(y)); |
| 695 } | 710 } |
| 696 | 711 |
| 697 Status ExecuteGetWindowSize(Session* session, | 712 Status ExecuteGetWindowSize(Session* session, |
| 698 const base::DictionaryValue& params, | 713 const base::DictionaryValue& params, |
| 699 std::unique_ptr<base::Value>* value) { | 714 std::unique_ptr<base::Value>* value) { |
| 700 ChromeDesktopImpl* desktop = NULL; | 715 ChromeDesktopImpl* desktop = NULL; |
| 701 Status status = session->chrome->GetAsDesktop(&desktop); | 716 Status status = session->chrome->GetAsDesktop(&desktop); |
| 702 if (status.IsError()) | 717 if (status.IsError()) |
| 703 return status; | 718 return status; |
| 704 | 719 |
| 705 AutomationExtension* extension = NULL; | |
| 706 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); | |
| 707 if (status.IsError()) | |
| 708 return status; | |
| 709 | |
| 710 int width, height; | 720 int width, height; |
| 711 status = extension->GetWindowSize(&width, &height); | 721 |
| 722 if (desktop->GetBrowserInfo()->build_no >= kBrowserWindowDevtoolsBuildNo) { |
| 723 status = desktop->GetWindowSize(session->window, &width, &height); |
| 724 } else { |
| 725 AutomationExtension* extension = NULL; |
| 726 status = |
| 727 desktop->GetAutomationExtension(&extension, session->w3c_compliant); |
| 728 if (status.IsError()) |
| 729 return status; |
| 730 |
| 731 status = extension->GetWindowSize(&width, &height); |
| 732 } |
| 712 if (status.IsError()) | 733 if (status.IsError()) |
| 713 return status; | 734 return status; |
| 714 | 735 |
| 715 base::DictionaryValue size; | 736 base::DictionaryValue size; |
| 716 size.SetInteger("width", width); | 737 size.SetInteger("width", width); |
| 717 size.SetInteger("height", height); | 738 size.SetInteger("height", height); |
| 718 value->reset(size.DeepCopy()); | 739 value->reset(size.DeepCopy()); |
| 719 return Status(kOk); | 740 return Status(kOk); |
| 720 } | 741 } |
| 721 | 742 |
| 722 Status ExecuteSetWindowSize(Session* session, | 743 Status ExecuteSetWindowSize(Session* session, |
| 723 const base::DictionaryValue& params, | 744 const base::DictionaryValue& params, |
| 724 std::unique_ptr<base::Value>* value) { | 745 std::unique_ptr<base::Value>* value) { |
| 725 double width = 0; | 746 double width = 0; |
| 726 double height = 0; | 747 double height = 0; |
| 727 if (!params.GetDouble("width", &width) || | 748 if (!params.GetDouble("width", &width) || |
| 728 !params.GetDouble("height", &height)) | 749 !params.GetDouble("height", &height)) |
| 729 return Status(kUnknownError, "missing or invalid 'width' or 'height'"); | 750 return Status(kUnknownError, "missing or invalid 'width' or 'height'"); |
| 730 | 751 |
| 731 ChromeDesktopImpl* desktop = NULL; | 752 ChromeDesktopImpl* desktop = NULL; |
| 732 Status status = session->chrome->GetAsDesktop(&desktop); | 753 Status status = session->chrome->GetAsDesktop(&desktop); |
| 733 if (status.IsError()) | 754 if (status.IsError()) |
| 734 return status; | 755 return status; |
| 735 | 756 |
| 757 if (desktop->GetBrowserInfo()->build_no >= kBrowserWindowDevtoolsBuildNo) { |
| 758 return desktop->SetWindowSize(session->window, static_cast<int>(width), |
| 759 static_cast<int>(height)); |
| 760 } |
| 761 |
| 736 AutomationExtension* extension = NULL; | 762 AutomationExtension* extension = NULL; |
| 737 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); | 763 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); |
| 738 if (status.IsError()) | 764 if (status.IsError()) |
| 739 return status; | 765 return status; |
| 740 | 766 |
| 741 return extension->SetWindowSize( | 767 return extension->SetWindowSize( |
| 742 static_cast<int>(width), static_cast<int>(height)); | 768 static_cast<int>(width), static_cast<int>(height)); |
| 743 } | 769 } |
| 744 | 770 |
| 745 Status ExecuteMaximizeWindow(Session* session, | 771 Status ExecuteMaximizeWindow(Session* session, |
| 746 const base::DictionaryValue& params, | 772 const base::DictionaryValue& params, |
| 747 std::unique_ptr<base::Value>* value) { | 773 std::unique_ptr<base::Value>* value) { |
| 748 ChromeDesktopImpl* desktop = NULL; | 774 ChromeDesktopImpl* desktop = NULL; |
| 749 Status status = session->chrome->GetAsDesktop(&desktop); | 775 Status status = session->chrome->GetAsDesktop(&desktop); |
| 750 if (status.IsError()) | 776 if (status.IsError()) |
| 751 return status; | 777 return status; |
| 752 | 778 |
| 779 if (desktop->GetBrowserInfo()->build_no >= kBrowserWindowDevtoolsBuildNo) |
| 780 return desktop->MaximizeWindow(session->window); |
| 781 |
| 753 AutomationExtension* extension = NULL; | 782 AutomationExtension* extension = NULL; |
| 754 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); | 783 status = desktop->GetAutomationExtension(&extension, session->w3c_compliant); |
| 755 if (status.IsError()) | 784 if (status.IsError()) |
| 756 return status; | 785 return status; |
| 757 | 786 |
| 758 return extension->MaximizeWindow(); | 787 return extension->MaximizeWindow(); |
| 759 } | 788 } |
| 760 | 789 |
| 761 Status ExecuteGetAvailableLogTypes(Session* session, | 790 Status ExecuteGetAvailableLogTypes(Session* session, |
| 762 const base::DictionaryValue& params, | 791 const base::DictionaryValue& params, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 std::unique_ptr<base::Value>* value) { | 925 std::unique_ptr<base::Value>* value) { |
| 897 WebView* web_view = nullptr; | 926 WebView* web_view = nullptr; |
| 898 Status status = session->GetTargetWindow(&web_view); | 927 Status status = session->GetTargetWindow(&web_view); |
| 899 if (status.IsError()) | 928 if (status.IsError()) |
| 900 return status; | 929 return status; |
| 901 status = web_view->DeleteScreenOrientation(); | 930 status = web_view->DeleteScreenOrientation(); |
| 902 if (status.IsError()) | 931 if (status.IsError()) |
| 903 return status; | 932 return status; |
| 904 return Status(kOk); | 933 return Status(kOk); |
| 905 } | 934 } |
| OLD | NEW |