| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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/remoting/remote_desktop_browsertest.h" | 5 #include "chrome/test/remoting/remote_desktop_browsertest.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "extensions/browser/extension_registry.h" | 22 #include "extensions/browser/extension_registry.h" |
| 23 #include "extensions/common/constants.h" | 23 #include "extensions/common/constants.h" |
| 24 #include "extensions/common/extension.h" | 24 #include "extensions/common/extension.h" |
| 25 #include "extensions/common/extension_set.h" | 25 #include "extensions/common/extension_set.h" |
| 26 #include "extensions/common/switches.h" | 26 #include "extensions/common/switches.h" |
| 27 #include "ui/base/window_open_disposition.h" | 27 #include "ui/base/window_open_disposition.h" |
| 28 | 28 |
| 29 namespace remoting { | 29 namespace remoting { |
| 30 | 30 |
| 31 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() | 31 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() |
| 32 : extension_(NULL) { | 32 : remote_test_helper_(nullptr), extension_(nullptr) { |
| 33 } | 33 } |
| 34 | 34 |
| 35 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} | 35 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} |
| 36 | 36 |
| 37 void RemoteDesktopBrowserTest::SetUp() { | 37 void RemoteDesktopBrowserTest::SetUp() { |
| 38 ParseCommandLine(); | 38 ParseCommandLine(); |
| 39 PlatformAppBrowserTest::SetUp(); | 39 PlatformAppBrowserTest::SetUp(); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void RemoteDesktopBrowserTest::SetUpOnMainThread() { | 42 void RemoteDesktopBrowserTest::SetUpOnMainThread() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( | 65 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete( |
| 66 browser(), GURL("http://www.google.com"), 1); | 66 browser(), GURL("http://www.google.com"), 1); |
| 67 | 67 |
| 68 EXPECT_EQ(GetCurrentURL().host(), "www.google.com"); | 68 EXPECT_EQ(GetCurrentURL().host(), "www.google.com"); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void RemoteDesktopBrowserTest::OpenClientBrowserPage() { | 71 void RemoteDesktopBrowserTest::OpenClientBrowserPage() { |
| 72 // Open the client browser page in a new tab | 72 // Open the client browser page in a new tab |
| 73 ui_test_utils::NavigateToURLWithDisposition( | 73 ui_test_utils::NavigateToURLWithDisposition( |
| 74 browser(), | 74 browser(), |
| 75 GURL(http_server() + "/clientpage.html"), | 75 GURL(http_server() + "/client.html"), |
| 76 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); | 76 NEW_FOREGROUND_TAB, ui_test_utils::BROWSER_TEST_WAIT_FOR_TAB); |
| 77 | 77 |
| 78 // Save this web content for later reference | 78 // Save this web content for later reference |
| 79 client_web_content_ = browser()->tab_strip_model()->GetActiveWebContents(); | 79 client_web_content_ = browser()->tab_strip_model()->GetActiveWebContents(); |
| 80 | 80 |
| 81 // Go back to the previous tab that has chromoting opened | 81 // Go back to the previous tab that has chromoting opened |
| 82 browser()->tab_strip_model()->SelectPreviousTab(); | 82 browser()->tab_strip_model()->SelectPreviousTab(); |
| 83 |
| 84 // Create the RemoteTestHelper object to use. |
| 85 remote_test_helper_.reset(new RemoteTestHelper(client_web_content_)); |
| 83 } | 86 } |
| 84 | 87 |
| 85 bool RemoteDesktopBrowserTest::HtmlElementVisible(const std::string& name) { | 88 bool RemoteDesktopBrowserTest::HtmlElementVisible(const std::string& name) { |
| 86 _ASSERT_TRUE(HtmlElementExists(name)); | 89 _ASSERT_TRUE(HtmlElementExists(name)); |
| 87 | 90 |
| 88 ExecuteScript( | 91 ExecuteScript( |
| 89 "function isElementVisible(name) {" | 92 "function isElementVisible(name) {" |
| 90 " var element = document.getElementById(name);" | 93 " var element = document.getElementById(name);" |
| 91 " /* The existence of the element has already been ASSERTed. */" | 94 " /* The existence of the element has already been ASSERTed. */" |
| 92 " do {" | 95 " do {" |
| (...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 content::Source<content::NavigationController>( | 673 content::Source<content::NavigationController>( |
| 671 &active_web_contents()-> | 674 &active_web_contents()-> |
| 672 GetController())); | 675 GetController())); |
| 673 | 676 |
| 674 ExecuteScript(script); | 677 ExecuteScript(script); |
| 675 | 678 |
| 676 observer.Wait(); | 679 observer.Wait(); |
| 677 } | 680 } |
| 678 | 681 |
| 679 // static | 682 // static |
| 680 bool RemoteDesktopBrowserTest::ExecuteScriptAndExtractBool( | |
| 681 content::WebContents* web_contents, const std::string& script) { | |
| 682 bool result; | |
| 683 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 684 web_contents, | |
| 685 "window.domAutomationController.send(" + script + ");", | |
| 686 &result)); | |
| 687 | |
| 688 return result; | |
| 689 } | |
| 690 | |
| 691 // static | |
| 692 int RemoteDesktopBrowserTest::ExecuteScriptAndExtractInt( | |
| 693 content::WebContents* web_contents, const std::string& script) { | |
| 694 int result; | |
| 695 _ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 696 web_contents, | |
| 697 "window.domAutomationController.send(" + script + ");", | |
| 698 &result)); | |
| 699 | |
| 700 return result; | |
| 701 } | |
| 702 | |
| 703 // static | |
| 704 std::string RemoteDesktopBrowserTest::ExecuteScriptAndExtractString( | |
| 705 content::WebContents* web_contents, const std::string& script) { | |
| 706 std::string result; | |
| 707 _ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 708 web_contents, | |
| 709 "window.domAutomationController.send(" + script + ");", | |
| 710 &result)); | |
| 711 | |
| 712 return result; | |
| 713 } | |
| 714 | |
| 715 // static | |
| 716 bool RemoteDesktopBrowserTest::LoadScript( | 683 bool RemoteDesktopBrowserTest::LoadScript( |
| 717 content::WebContents* web_contents, | 684 content::WebContents* web_contents, |
| 718 const base::FilePath::StringType& path) { | 685 const base::FilePath::StringType& path) { |
| 719 std::string script; | 686 std::string script; |
| 720 base::FilePath src_dir; | 687 base::FilePath src_dir; |
| 721 _ASSERT_TRUE(PathService::Get(base::DIR_EXE, &src_dir)); | 688 _ASSERT_TRUE(PathService::Get(base::DIR_EXE, &src_dir)); |
| 722 base::FilePath script_path = src_dir.Append(path); | 689 base::FilePath script_path = src_dir.Append(path); |
| 723 | 690 |
| 724 if (!base::ReadFileToString(script_path, &script)) { | 691 if (!base::ReadFileToString(script_path, &script)) { |
| 725 LOG(ERROR) << "Failed to load script " << script_path.value(); | 692 LOG(ERROR) << "Failed to load script " << script_path.value(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 763 | 730 |
| 764 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; | 731 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; |
| 765 } | 732 } |
| 766 | 733 |
| 767 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { | 734 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { |
| 768 ASSERT_TRUE(HtmlElementVisible(name)); | 735 ASSERT_TRUE(HtmlElementVisible(name)); |
| 769 | 736 |
| 770 std::string has_disabled_attribute = | 737 std::string has_disabled_attribute = |
| 771 "document.getElementById('" + name + "').hasAttribute('disabled')"; | 738 "document.getElementById('" + name + "').hasAttribute('disabled')"; |
| 772 | 739 |
| 773 if (ExecuteScriptAndExtractBool(active_web_contents(), | 740 if (RemoteTestHelper::ExecuteScriptAndExtractBool(active_web_contents(), |
| 774 has_disabled_attribute)) { | 741 has_disabled_attribute)) { |
| 775 // This element has a disabled attribute. Wait for it become enabled. | 742 // This element has a disabled attribute. Wait for it become enabled. |
| 776 ConditionalTimeoutWaiter waiter( | 743 ConditionalTimeoutWaiter waiter( |
| 777 base::TimeDelta::FromSeconds(5), | 744 base::TimeDelta::FromSeconds(5), |
| 778 base::TimeDelta::FromMilliseconds(500), | 745 base::TimeDelta::FromMilliseconds(500), |
| 779 base::Bind(&RemoteDesktopBrowserTest::IsEnabled, | 746 base::Bind(&RemoteDesktopBrowserTest::IsEnabled, |
| 780 active_web_contents(), name)); | 747 active_web_contents(), name)); |
| 781 ASSERT_TRUE(waiter.Wait()); | 748 ASSERT_TRUE(waiter.Wait()); |
| 782 } | 749 } |
| 783 | 750 |
| 784 ExecuteScript("document.getElementById(\"" + name + "\").click();"); | 751 ExecuteScript("document.getElementById(\"" + name + "\").click();"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 // Now get the dictionary for the specified account type. | 851 // Now get the dictionary for the specified account type. |
| 885 const base::DictionaryValue* account_dict = NULL; | 852 const base::DictionaryValue* account_dict = NULL; |
| 886 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict)); | 853 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict)); |
| 887 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); | 854 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); |
| 888 ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_)); | 855 ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_)); |
| 889 } | 856 } |
| 890 | 857 |
| 891 // static | 858 // static |
| 892 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( | 859 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( |
| 893 content::WebContents* web_contents) { | 860 content::WebContents* web_contents) { |
| 894 return ExecuteScriptAndExtractBool( | 861 return RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 895 web_contents, "remoting.identity.isAuthenticated()"); | 862 web_contents, "remoting.identity.isAuthenticated()"); |
| 896 } | 863 } |
| 897 | 864 |
| 898 // static | 865 // static |
| 899 bool RemoteDesktopBrowserTest::IsHostActionComplete( | 866 bool RemoteDesktopBrowserTest::IsHostActionComplete( |
| 900 content::WebContents* client_web_content, | 867 content::WebContents* client_web_content, |
| 901 std::string host_action_var) { | 868 std::string host_action_var) { |
| 902 return ExecuteScriptAndExtractBool( | 869 return RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 903 client_web_content, | 870 client_web_content, |
| 904 host_action_var); | 871 host_action_var); |
| 905 } | 872 } |
| 906 | 873 |
| 907 // static | 874 // static |
| 908 bool RemoteDesktopBrowserTest::IsEnabled( | 875 bool RemoteDesktopBrowserTest::IsEnabled( |
| 909 content::WebContents* client_web_content, | 876 content::WebContents* client_web_content, |
| 910 const std::string& element_name) { | 877 const std::string& element_name) { |
| 911 return !ExecuteScriptAndExtractBool( | 878 return !RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 912 client_web_content, | 879 client_web_content, |
| 913 "document.getElementById(\"" + element_name + "\").disabled"); | 880 "document.getElementById(\"" + element_name + "\").disabled"); |
| 914 } | 881 } |
| 915 | 882 |
| 916 } // namespace remoting | 883 } // namespace remoting |
| OLD | NEW |