Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 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 | |
| 37 PlatformAppBrowserTest::SetUp(); | 38 PlatformAppBrowserTest::SetUp(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void RemoteDesktopBrowserTest::SetUpOnMainThread() { | 41 void RemoteDesktopBrowserTest::SetUpOnMainThread() { |
| 41 PlatformAppBrowserTest::SetUpOnMainThread(); | 42 PlatformAppBrowserTest::SetUpOnMainThread(); |
| 42 | 43 |
| 43 // Pushing the initial WebContents instance onto the stack before | 44 // Pushing the initial WebContents instance onto the stack before |
| 44 // RunTestOnMainThread() and after |InProcessBrowserTest::browser_| | 45 // RunTestOnMainThread() and after |InProcessBrowserTest::browser_| |
| 45 // is initialized in InProcessBrowserTest::RunTestOnMainThreadLoop() | 46 // is initialized in InProcessBrowserTest::RunTestOnMainThreadLoop() |
| 46 web_contents_stack_.push_back( | 47 web_contents_stack_.push_back( |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 if (command_line->HasSwitch(kOverrideUserDataDir)) { | 566 if (command_line->HasSwitch(kOverrideUserDataDir)) { |
| 566 const base::FilePath& override_user_data_dir = | 567 const base::FilePath& override_user_data_dir = |
| 567 command_line->GetSwitchValuePath(kOverrideUserDataDir); | 568 command_line->GetSwitchValuePath(kOverrideUserDataDir); |
| 568 | 569 |
| 569 ASSERT_FALSE(override_user_data_dir.empty()); | 570 ASSERT_FALSE(override_user_data_dir.empty()); |
| 570 | 571 |
| 571 command_line->AppendSwitchPath(switches::kUserDataDir, | 572 command_line->AppendSwitchPath(switches::kUserDataDir, |
| 572 override_user_data_dir); | 573 override_user_data_dir); |
| 573 } | 574 } |
| 574 | 575 |
| 575 username_ = command_line->GetSwitchValueASCII(kUsername); | 576 accounts_file_ = command_line->GetSwitchValueASCII(kAccountsFile); |
| 576 password_ = command_line->GetSwitchValueASCII(kkPassword); | 577 account_type_ = command_line->GetSwitchValueASCII(kAccountType); |
| 578 if (!accounts_file_.empty()) { | |
| 579 // We've been passed in a file containing accounts information. | |
| 580 // In this case, we'll obtain the user-name and password information from | |
| 581 // the specified file, even if user-name and password have been specified | |
| 582 // on the command-line. | |
| 583 base::FilePath accounts_file_path(accounts_file_); | |
| 584 ASSERT_FALSE(account_type_.empty()); | |
| 585 ASSERT_TRUE(base::PathExists(accounts_file_path)); | |
| 586 SetUserNameAndPassword(accounts_file_path); | |
| 587 } else { | |
| 588 // No file for accounts specified. Read user-name and password from command | |
| 589 // line. | |
| 590 username_ = command_line->GetSwitchValueASCII(kUserName); | |
| 591 password_ = command_line->GetSwitchValueASCII(kPassword); | |
| 592 } | |
| 593 | |
| 577 me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin); | 594 me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin); |
| 578 remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName); | 595 remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName); |
| 579 extension_name_ = command_line->GetSwitchValueASCII(kExtensionName); | 596 extension_name_ = command_line->GetSwitchValueASCII(kExtensionName); |
| 580 http_server_ = command_line->GetSwitchValueASCII(kHttpServer); | 597 http_server_ = command_line->GetSwitchValueASCII(kHttpServer); |
| 581 | 598 |
| 582 no_cleanup_ = command_line->HasSwitch(kNoCleanup); | 599 no_cleanup_ = command_line->HasSwitch(kNoCleanup); |
| 583 no_install_ = command_line->HasSwitch(kNoInstall); | 600 no_install_ = command_line->HasSwitch(kNoInstall); |
| 584 | 601 |
| 585 if (!no_install_) { | 602 if (!no_install_) { |
| 586 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); | 603 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 bool RemoteDesktopBrowserTest::IsPinFormVisible() { | 808 bool RemoteDesktopBrowserTest::IsPinFormVisible() { |
| 792 DismissHostVersionWarningIfVisible(); | 809 DismissHostVersionWarningIfVisible(); |
| 793 return HtmlElementVisible("pin-form"); | 810 return HtmlElementVisible("pin-form"); |
| 794 } | 811 } |
| 795 | 812 |
| 796 void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() { | 813 void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() { |
| 797 if (HtmlElementVisible("host-needs-update-connect-button")) | 814 if (HtmlElementVisible("host-needs-update-connect-button")) |
| 798 ClickOnControl("host-needs-update-connect-button"); | 815 ClickOnControl("host-needs-update-connect-button"); |
| 799 } | 816 } |
| 800 | 817 |
| 818 void RemoteDesktopBrowserTest::SetUserNameAndPassword( | |
|
weitao
2014/10/08 23:19:16
I suggest that we don't store the accounts file pa
anandc
2014/10/09 00:15:25
Done.
| |
| 819 const base::FilePath &accounts_file_path) { | |
| 820 | |
| 821 // Read contents of accounts file. | |
| 822 std::string accounts_info; | |
| 823 ASSERT_TRUE(base::ReadFileToString(accounts_file_path, &accounts_info)); | |
| 824 | |
| 825 scoped_ptr<base::Value> root( | |
| 826 base::JSONReader::Read(accounts_info, base::JSON_ALLOW_TRAILING_COMMAS)); | |
| 827 DCHECK(root.get() != NULL); | |
| 828 ASSERT_TRUE(root.get() && root->GetType() == base::Value::TYPE_DICTIONARY); | |
| 829 | |
| 830 // Get the root dictionary from the input json file contents. | |
| 831 const base::DictionaryValue* root_dict = | |
| 832 static_cast<base::DictionaryValue*>(root.get()); | |
|
weitao
2014/10/08 23:19:16
Please use GetAsDictionary. And instead of asserti
anandc
2014/10/09 00:15:25
Done.
| |
| 833 // And now the dictionary for the specified account type. | |
| 834 const base::DictionaryValue* account_dict = NULL; | |
| 835 root_dict->GetDictionary(account_type_, &account_dict); | |
|
weitao
2014/10/08 23:19:16
assert the result of GetDictionary.
anandc
2014/10/09 00:15:24
Done.
| |
| 836 | |
| 837 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); | |
| 838 | |
| 839 ASSERT_TRUE(account_dict->GetString(kPassword, &password_)); | |
| 840 } | |
| 841 | |
| 801 // static | 842 // static |
| 802 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( | 843 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( |
| 803 content::WebContents* web_contents) { | 844 content::WebContents* web_contents) { |
| 804 return ExecuteScriptAndExtractBool( | 845 return ExecuteScriptAndExtractBool( |
| 805 web_contents, "remoting.identity.isAuthenticated()"); | 846 web_contents, "remoting.identity.isAuthenticated()"); |
| 806 } | 847 } |
| 807 | 848 |
| 808 // static | 849 // static |
| 809 bool RemoteDesktopBrowserTest::IsHostActionComplete( | 850 bool RemoteDesktopBrowserTest::IsHostActionComplete( |
| 810 content::WebContents* client_web_content, | 851 content::WebContents* client_web_content, |
| 811 std::string host_action_var) { | 852 std::string host_action_var) { |
| 812 return ExecuteScriptAndExtractBool( | 853 return ExecuteScriptAndExtractBool( |
| 813 client_web_content, | 854 client_web_content, |
| 814 host_action_var); | 855 host_action_var); |
| 815 } | 856 } |
| 816 | 857 |
| 817 // static | 858 // static |
| 818 bool RemoteDesktopBrowserTest::IsEnabled( | 859 bool RemoteDesktopBrowserTest::IsEnabled( |
| 819 content::WebContents* client_web_content, | 860 content::WebContents* client_web_content, |
| 820 const std::string& element_name) { | 861 const std::string& element_name) { |
| 821 return !ExecuteScriptAndExtractBool( | 862 return !ExecuteScriptAndExtractBool( |
| 822 client_web_content, | 863 client_web_content, |
| 823 "document.getElementById(\"" + element_name + "\").disabled"); | 864 "document.getElementById(\"" + element_name + "\").disabled"); |
| 824 } | 865 } |
| 825 | 866 |
| 826 } // namespace remoting | 867 } // namespace remoting |
| OLD | NEW |