| 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 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 content::Source<content::NavigationController>( | 661 content::Source<content::NavigationController>( |
| 659 &active_web_contents()-> | 662 &active_web_contents()-> |
| 660 GetController())); | 663 GetController())); |
| 661 | 664 |
| 662 ExecuteScript(script); | 665 ExecuteScript(script); |
| 663 | 666 |
| 664 observer.Wait(); | 667 observer.Wait(); |
| 665 } | 668 } |
| 666 | 669 |
| 667 // static | 670 // static |
| 668 bool RemoteDesktopBrowserTest::ExecuteScriptAndExtractBool( | |
| 669 content::WebContents* web_contents, const std::string& script) { | |
| 670 bool result; | |
| 671 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 672 web_contents, | |
| 673 "window.domAutomationController.send(" + script + ");", | |
| 674 &result)); | |
| 675 | |
| 676 return result; | |
| 677 } | |
| 678 | |
| 679 // static | |
| 680 int RemoteDesktopBrowserTest::ExecuteScriptAndExtractInt( | |
| 681 content::WebContents* web_contents, const std::string& script) { | |
| 682 int result; | |
| 683 _ASSERT_TRUE(content::ExecuteScriptAndExtractInt( | |
| 684 web_contents, | |
| 685 "window.domAutomationController.send(" + script + ");", | |
| 686 &result)); | |
| 687 | |
| 688 return result; | |
| 689 } | |
| 690 | |
| 691 // static | |
| 692 std::string RemoteDesktopBrowserTest::ExecuteScriptAndExtractString( | |
| 693 content::WebContents* web_contents, const std::string& script) { | |
| 694 std::string result; | |
| 695 _ASSERT_TRUE(content::ExecuteScriptAndExtractString( | |
| 696 web_contents, | |
| 697 "window.domAutomationController.send(" + script + ");", | |
| 698 &result)); | |
| 699 | |
| 700 return result; | |
| 701 } | |
| 702 | |
| 703 // static | |
| 704 bool RemoteDesktopBrowserTest::LoadScript( | 671 bool RemoteDesktopBrowserTest::LoadScript( |
| 705 content::WebContents* web_contents, | 672 content::WebContents* web_contents, |
| 706 const base::FilePath::StringType& path) { | 673 const base::FilePath::StringType& path) { |
| 707 std::string script; | 674 std::string script; |
| 708 base::FilePath src_dir; | 675 base::FilePath src_dir; |
| 709 _ASSERT_TRUE(PathService::Get(base::DIR_EXE, &src_dir)); | 676 _ASSERT_TRUE(PathService::Get(base::DIR_EXE, &src_dir)); |
| 710 base::FilePath script_path = src_dir.Append(path); | 677 base::FilePath script_path = src_dir.Append(path); |
| 711 | 678 |
| 712 if (!base::ReadFileToString(script_path, &script)) { | 679 if (!base::ReadFileToString(script_path, &script)) { |
| 713 LOG(ERROR) << "Failed to load script " << script_path.value(); | 680 LOG(ERROR) << "Failed to load script " << script_path.value(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 | 718 |
| 752 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; | 719 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; |
| 753 } | 720 } |
| 754 | 721 |
| 755 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { | 722 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { |
| 756 ASSERT_TRUE(HtmlElementVisible(name)); | 723 ASSERT_TRUE(HtmlElementVisible(name)); |
| 757 | 724 |
| 758 std::string has_disabled_attribute = | 725 std::string has_disabled_attribute = |
| 759 "document.getElementById('" + name + "').hasAttribute('disabled')"; | 726 "document.getElementById('" + name + "').hasAttribute('disabled')"; |
| 760 | 727 |
| 761 if (ExecuteScriptAndExtractBool(active_web_contents(), | 728 if (RemoteTestHelper::ExecuteScriptAndExtractBool(active_web_contents(), |
| 762 has_disabled_attribute)) { | 729 has_disabled_attribute)) { |
| 763 // This element has a disabled attribute. Wait for it become enabled. | 730 // This element has a disabled attribute. Wait for it become enabled. |
| 764 ConditionalTimeoutWaiter waiter( | 731 ConditionalTimeoutWaiter waiter( |
| 765 base::TimeDelta::FromSeconds(5), | 732 base::TimeDelta::FromSeconds(5), |
| 766 base::TimeDelta::FromMilliseconds(500), | 733 base::TimeDelta::FromMilliseconds(500), |
| 767 base::Bind(&RemoteDesktopBrowserTest::IsEnabled, | 734 base::Bind(&RemoteDesktopBrowserTest::IsEnabled, |
| 768 active_web_contents(), name)); | 735 active_web_contents(), name)); |
| 769 ASSERT_TRUE(waiter.Wait()); | 736 ASSERT_TRUE(waiter.Wait()); |
| 770 } | 737 } |
| 771 | 738 |
| 772 ExecuteScript("document.getElementById(\"" + name + "\").click();"); | 739 ExecuteScript("document.getElementById(\"" + name + "\").click();"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 // Now get the dictionary for the specified account type. | 839 // Now get the dictionary for the specified account type. |
| 873 const base::DictionaryValue* account_dict = NULL; | 840 const base::DictionaryValue* account_dict = NULL; |
| 874 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict)); | 841 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict)); |
| 875 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); | 842 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); |
| 876 ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_)); | 843 ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_)); |
| 877 } | 844 } |
| 878 | 845 |
| 879 // static | 846 // static |
| 880 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( | 847 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( |
| 881 content::WebContents* web_contents) { | 848 content::WebContents* web_contents) { |
| 882 return ExecuteScriptAndExtractBool( | 849 return RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 883 web_contents, "remoting.identity.isAuthenticated()"); | 850 web_contents, "remoting.identity.isAuthenticated()"); |
| 884 } | 851 } |
| 885 | 852 |
| 886 // static | 853 // static |
| 887 bool RemoteDesktopBrowserTest::IsHostActionComplete( | 854 bool RemoteDesktopBrowserTest::IsHostActionComplete( |
| 888 content::WebContents* client_web_content, | 855 content::WebContents* client_web_content, |
| 889 std::string host_action_var) { | 856 std::string host_action_var) { |
| 890 return ExecuteScriptAndExtractBool( | 857 return RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 891 client_web_content, | 858 client_web_content, |
| 892 host_action_var); | 859 host_action_var); |
| 893 } | 860 } |
| 894 | 861 |
| 895 // static | 862 // static |
| 896 bool RemoteDesktopBrowserTest::IsEnabled( | 863 bool RemoteDesktopBrowserTest::IsEnabled( |
| 897 content::WebContents* client_web_content, | 864 content::WebContents* client_web_content, |
| 898 const std::string& element_name) { | 865 const std::string& element_name) { |
| 899 return !ExecuteScriptAndExtractBool( | 866 return !RemoteTestHelper::ExecuteScriptAndExtractBool( |
| 900 client_web_content, | 867 client_web_content, |
| 901 "document.getElementById(\"" + element_name + "\").disabled"); | 868 "document.getElementById(\"" + element_name + "\").disabled"); |
| 902 } | 869 } |
| 903 | 870 |
| 904 } // namespace remoting | 871 } // namespace remoting |
| OLD | NEW |