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

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

Issue 617103008: Update chromoting browser-tests to obtain user-name and password from a specified file. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months 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 16 matching lines...) Expand all
27 namespace remoting { 27 namespace remoting {
28 28
29 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest() 29 RemoteDesktopBrowserTest::RemoteDesktopBrowserTest()
30 : extension_(NULL) { 30 : extension_(NULL) {
31 } 31 }
32 32
33 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {} 33 RemoteDesktopBrowserTest::~RemoteDesktopBrowserTest() {}
34 34
35 void RemoteDesktopBrowserTest::SetUp() { 35 void RemoteDesktopBrowserTest::SetUp() {
36 ParseCommandLine(); 36 ParseCommandLine();
37
38 if (!accounts_file_.empty()) {
39 // We've been passed in a file containing accounts information.
40 base::FilePath accounts_file_path(accounts_file_);
41 ASSERT_FALSE(account_type_.empty());
42 ASSERT_TRUE(base::PathExists(accounts_file_path));
43 SetUserNameAndPassword(accounts_file_path);
44 }
45
37 PlatformAppBrowserTest::SetUp(); 46 PlatformAppBrowserTest::SetUp();
38 } 47 }
39 48
40 void RemoteDesktopBrowserTest::SetUpOnMainThread() { 49 void RemoteDesktopBrowserTest::SetUpOnMainThread() {
41 PlatformAppBrowserTest::SetUpOnMainThread(); 50 PlatformAppBrowserTest::SetUpOnMainThread();
42 51
43 // Pushing the initial WebContents instance onto the stack before 52 // Pushing the initial WebContents instance onto the stack before
44 // RunTestOnMainThread() and after |InProcessBrowserTest::browser_| 53 // RunTestOnMainThread() and after |InProcessBrowserTest::browser_|
45 // is initialized in InProcessBrowserTest::RunTestOnMainThreadLoop() 54 // is initialized in InProcessBrowserTest::RunTestOnMainThreadLoop()
46 web_contents_stack_.push_back( 55 web_contents_stack_.push_back(
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 if (command_line->HasSwitch(kOverrideUserDataDir)) { 574 if (command_line->HasSwitch(kOverrideUserDataDir)) {
566 const base::FilePath& override_user_data_dir = 575 const base::FilePath& override_user_data_dir =
567 command_line->GetSwitchValuePath(kOverrideUserDataDir); 576 command_line->GetSwitchValuePath(kOverrideUserDataDir);
568 577
569 ASSERT_FALSE(override_user_data_dir.empty()); 578 ASSERT_FALSE(override_user_data_dir.empty());
570 579
571 command_line->AppendSwitchPath(switches::kUserDataDir, 580 command_line->AppendSwitchPath(switches::kUserDataDir,
572 override_user_data_dir); 581 override_user_data_dir);
573 } 582 }
574 583
575 username_ = command_line->GetSwitchValueASCII(kUsername); 584 accounts_file_ = command_line->GetSwitchValueASCII(kAccountsFile);
576 password_ = command_line->GetSwitchValueASCII(kkPassword); 585 account_type_ = command_line->GetSwitchValueASCII(kAccountType);
586
577 me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin); 587 me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin);
578 remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName); 588 remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName);
579 extension_name_ = command_line->GetSwitchValueASCII(kExtensionName); 589 extension_name_ = command_line->GetSwitchValueASCII(kExtensionName);
580 http_server_ = command_line->GetSwitchValueASCII(kHttpServer); 590 http_server_ = command_line->GetSwitchValueASCII(kHttpServer);
581 591
582 no_cleanup_ = command_line->HasSwitch(kNoCleanup); 592 no_cleanup_ = command_line->HasSwitch(kNoCleanup);
583 no_install_ = command_line->HasSwitch(kNoInstall); 593 no_install_ = command_line->HasSwitch(kNoInstall);
584 594
585 if (!no_install_) { 595 if (!no_install_) {
586 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); 596 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx);
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
791 bool RemoteDesktopBrowserTest::IsPinFormVisible() { 801 bool RemoteDesktopBrowserTest::IsPinFormVisible() {
792 DismissHostVersionWarningIfVisible(); 802 DismissHostVersionWarningIfVisible();
793 return HtmlElementVisible("pin-form"); 803 return HtmlElementVisible("pin-form");
794 } 804 }
795 805
796 void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() { 806 void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() {
797 if (HtmlElementVisible("host-needs-update-connect-button")) 807 if (HtmlElementVisible("host-needs-update-connect-button"))
798 ClickOnControl("host-needs-update-connect-button"); 808 ClickOnControl("host-needs-update-connect-button");
799 } 809 }
800 810
811 bool RemoteDesktopBrowserTest::SetUserNameAndPassword(
812 const base::FilePath &accounts_file_path) {
813
814 // Read contents of accounts file.
815 std::string accounts_info;
816 if (!base::ReadFileToString(accounts_file_path, &accounts_info)){
817 LOG(WARNING) << "Failed to read file: " << accounts_file_path.value();
818 return false;
819 }
820
821 scoped_ptr<base::Value> root(
822 base::JSONReader::Read(accounts_info, base::JSON_ALLOW_TRAILING_COMMAS));
823 DCHECK(root.get() != NULL);
824 if (!root.get() || root->GetType() != base::Value::TYPE_DICTIONARY) {
825 LOG(WARNING) << "Bad config file";
826 return false;
827 }
828
829 // Get the root dictionary from the input json file contents.
830 const base::DictionaryValue* root_dict =
831 static_cast<base::DictionaryValue*>(root.get());
832 // And now the dictionary for the specified account type.
833 const base::DictionaryValue* account_dict = NULL;
834 root_dict->GetDictionary(account_type_, &account_dict);
835
836 if (!account_dict->GetString(kUserNameField, &username_)) {
837 LOG(WARNING) << "account info file missing username";
838 return false;
839 }
840
841 if (!account_dict->GetString(kPasswordField, &password_)) {
842 LOG(WARNING) << "account info file missing password";
843 return false;
844 }
845 LOG(INFO) << username_ << "=" << password_;
846 return true;
847 }
848
801 // static 849 // static
802 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( 850 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow(
803 content::WebContents* web_contents) { 851 content::WebContents* web_contents) {
804 return ExecuteScriptAndExtractBool( 852 return ExecuteScriptAndExtractBool(
805 web_contents, "remoting.identity.isAuthenticated()"); 853 web_contents, "remoting.identity.isAuthenticated()");
806 } 854 }
807 855
808 // static 856 // static
809 bool RemoteDesktopBrowserTest::IsHostActionComplete( 857 bool RemoteDesktopBrowserTest::IsHostActionComplete(
810 content::WebContents* client_web_content, 858 content::WebContents* client_web_content,
811 std::string host_action_var) { 859 std::string host_action_var) {
812 return ExecuteScriptAndExtractBool( 860 return ExecuteScriptAndExtractBool(
813 client_web_content, 861 client_web_content,
814 host_action_var); 862 host_action_var);
815 } 863 }
816 864
817 // static 865 // static
818 bool RemoteDesktopBrowserTest::IsEnabled( 866 bool RemoteDesktopBrowserTest::IsEnabled(
819 content::WebContents* client_web_content, 867 content::WebContents* client_web_content,
820 const std::string& element_name) { 868 const std::string& element_name) {
821 return !ExecuteScriptAndExtractBool( 869 return !ExecuteScriptAndExtractBool(
822 client_web_content, 870 client_web_content,
823 "document.getElementById(\"" + element_name + "\").disabled"); 871 "document.getElementById(\"" + element_name + "\").disabled");
824 } 872 }
825 873
826 } // namespace remoting 874 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698