Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: chrome/test/remoting/remote_desktop_browsertest.cc

Issue 807343002: Adding the first set of remote test cases and associated framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: First round of fixes for the remote me2me tests and the associated remote_test_helper code. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 content::Source<content::NavigationController>( 653 content::Source<content::NavigationController>(
651 &active_web_contents()-> 654 &active_web_contents()->
652 GetController())); 655 GetController()));
653 656
654 ExecuteScript(script); 657 ExecuteScript(script);
655 658
656 observer.Wait(); 659 observer.Wait();
657 } 660 }
658 661
659 // static 662 // static
660 bool RemoteDesktopBrowserTest::ExecuteScriptAndExtractBool(
661 content::WebContents* web_contents, const std::string& script) {
662 bool result;
663 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
664 web_contents,
665 "window.domAutomationController.send(" + script + ");",
666 &result));
667
668 return result;
669 }
670
671 // static
672 int RemoteDesktopBrowserTest::ExecuteScriptAndExtractInt(
673 content::WebContents* web_contents, const std::string& script) {
674 int result;
675 _ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
676 web_contents,
677 "window.domAutomationController.send(" + script + ");",
678 &result));
679
680 return result;
681 }
682
683 // static
684 std::string RemoteDesktopBrowserTest::ExecuteScriptAndExtractString(
685 content::WebContents* web_contents, const std::string& script) {
686 std::string result;
687 _ASSERT_TRUE(content::ExecuteScriptAndExtractString(
688 web_contents,
689 "window.domAutomationController.send(" + script + ");",
690 &result));
691
692 return result;
693 }
694
695 // static
696 bool RemoteDesktopBrowserTest::LoadScript( 663 bool RemoteDesktopBrowserTest::LoadScript(
697 content::WebContents* web_contents, 664 content::WebContents* web_contents,
698 const base::FilePath::StringType& path) { 665 const base::FilePath::StringType& path) {
699 std::string script; 666 std::string script;
700 base::FilePath src_dir; 667 base::FilePath src_dir;
701 _ASSERT_TRUE(PathService::Get(base::DIR_EXE, &src_dir)); 668 _ASSERT_TRUE(PathService::Get(base::DIR_EXE, &src_dir));
702 base::FilePath script_path = src_dir.Append(path); 669 base::FilePath script_path = src_dir.Append(path);
703 670
704 if (!base::ReadFileToString(script_path, &script)) { 671 if (!base::ReadFileToString(script_path, &script)) {
705 LOG(ERROR) << "Failed to load script " << script_path.value(); 672 LOG(ERROR) << "Failed to load script " << script_path.value();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 710
744 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace; 711 EXPECT_TRUE(succeeded) << error_message << "\n" << stack_trace;
745 } 712 }
746 713
747 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) { 714 void RemoteDesktopBrowserTest::ClickOnControl(const std::string& name) {
748 ASSERT_TRUE(HtmlElementVisible(name)); 715 ASSERT_TRUE(HtmlElementVisible(name));
749 716
750 std::string has_disabled_attribute = 717 std::string has_disabled_attribute =
751 "document.getElementById('" + name + "').hasAttribute('disabled')"; 718 "document.getElementById('" + name + "').hasAttribute('disabled')";
752 719
753 if (ExecuteScriptAndExtractBool(active_web_contents(), 720 if (RemoteTestHelper::ExecuteScriptAndExtractBool(active_web_contents(),
754 has_disabled_attribute)) { 721 has_disabled_attribute)) {
755 // This element has a disabled attribute. Wait for it become enabled. 722 // This element has a disabled attribute. Wait for it become enabled.
756 ConditionalTimeoutWaiter waiter( 723 ConditionalTimeoutWaiter waiter(
757 base::TimeDelta::FromSeconds(5), 724 base::TimeDelta::FromSeconds(5),
758 base::TimeDelta::FromMilliseconds(500), 725 base::TimeDelta::FromMilliseconds(500),
759 base::Bind(&RemoteDesktopBrowserTest::IsEnabled, 726 base::Bind(&RemoteDesktopBrowserTest::IsEnabled,
760 active_web_contents(), name)); 727 active_web_contents(), name));
761 ASSERT_TRUE(waiter.Wait()); 728 ASSERT_TRUE(waiter.Wait());
762 } 729 }
763 730
764 ExecuteScript("document.getElementById(\"" + name + "\").click();"); 731 ExecuteScript("document.getElementById(\"" + name + "\").click();");
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
864 // Now get the dictionary for the specified account type. 831 // Now get the dictionary for the specified account type.
865 const base::DictionaryValue* account_dict = NULL; 832 const base::DictionaryValue* account_dict = NULL;
866 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict)); 833 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict));
867 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); 834 ASSERT_TRUE(account_dict->GetString(kUserName, &username_));
868 ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_)); 835 ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_));
869 } 836 }
870 837
871 // static 838 // static
872 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( 839 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow(
873 content::WebContents* web_contents) { 840 content::WebContents* web_contents) {
874 return ExecuteScriptAndExtractBool( 841 return RemoteTestHelper::ExecuteScriptAndExtractBool(
875 web_contents, "remoting.identity.isAuthenticated()"); 842 web_contents, "remoting.identity.isAuthenticated()");
876 } 843 }
877 844
878 // static 845 // static
879 bool RemoteDesktopBrowserTest::IsHostActionComplete( 846 bool RemoteDesktopBrowserTest::IsHostActionComplete(
880 content::WebContents* client_web_content, 847 content::WebContents* client_web_content,
881 std::string host_action_var) { 848 std::string host_action_var) {
882 return ExecuteScriptAndExtractBool( 849 return RemoteTestHelper::ExecuteScriptAndExtractBool(
883 client_web_content, 850 client_web_content,
884 host_action_var); 851 host_action_var);
885 } 852 }
886 853
887 // static 854 // static
888 bool RemoteDesktopBrowserTest::IsEnabled( 855 bool RemoteDesktopBrowserTest::IsEnabled(
889 content::WebContents* client_web_content, 856 content::WebContents* client_web_content,
890 const std::string& element_name) { 857 const std::string& element_name) {
891 return !ExecuteScriptAndExtractBool( 858 return !RemoteTestHelper::ExecuteScriptAndExtractBool(
892 client_web_content, 859 client_web_content,
893 "document.getElementById(\"" + element_name + "\").disabled"); 860 "document.getElementById(\"" + element_name + "\").disabled");
894 } 861 }
895 862
896 } // namespace remoting 863 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698