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 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 467 VerifyInternetAccess(); | 468 VerifyInternetAccess(); |
| 468 Install(); | 469 Install(); |
| 469 LaunchChromotingApp(); | 470 LaunchChromotingApp(); |
| 470 Auth(); | 471 Auth(); |
| 471 LoadScript(app_web_content(), FILE_PATH_LITERAL("browser_test.js")); | 472 LoadScript(app_web_content(), FILE_PATH_LITERAL("browser_test.js")); |
| 472 ExpandMe2Me(); | 473 ExpandMe2Me(); |
| 473 EnsureRemoteConnectionEnabled(); | 474 EnsureRemoteConnectionEnabled(); |
| 474 } | 475 } |
| 475 | 476 |
| 476 void RemoteDesktopBrowserTest::Auth() { | 477 void RemoteDesktopBrowserTest::Auth() { |
| 478 // For this test, we must be given the user-name and password. | |
| 479 ASSERT_TRUE(!username_.empty() && !password_.empty()); | |
|
anandc
2014/10/09 00:15:25
Added these just to fail quicker.
| |
| 480 | |
| 477 Authorize(); | 481 Authorize(); |
| 478 Authenticate(); | 482 Authenticate(); |
| 479 Approve(); | 483 Approve(); |
| 480 } | 484 } |
| 481 | 485 |
| 482 void RemoteDesktopBrowserTest::EnsureRemoteConnectionEnabled() { | 486 void RemoteDesktopBrowserTest::EnsureRemoteConnectionEnabled() { |
| 483 // browser_test.ensureRemoteConnectionEnabled is defined in | 487 // browser_test.ensureRemoteConnectionEnabled is defined in |
| 484 // browser_test.js, which must be loaded before calling this function. | 488 // browser_test.js, which must be loaded before calling this function. |
| 485 // TODO(kelvinp): This function currently only works on linux when the user is | 489 // TODO(kelvinp): This function currently only works on linux when the user is |
| 486 // already part of the chrome-remote-desktop group. Extend this functionality | 490 // already part of the chrome-remote-desktop group. Extend this functionality |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 if (command_line->HasSwitch(kOverrideUserDataDir)) { | 569 if (command_line->HasSwitch(kOverrideUserDataDir)) { |
| 566 const base::FilePath& override_user_data_dir = | 570 const base::FilePath& override_user_data_dir = |
| 567 command_line->GetSwitchValuePath(kOverrideUserDataDir); | 571 command_line->GetSwitchValuePath(kOverrideUserDataDir); |
| 568 | 572 |
| 569 ASSERT_FALSE(override_user_data_dir.empty()); | 573 ASSERT_FALSE(override_user_data_dir.empty()); |
| 570 | 574 |
| 571 command_line->AppendSwitchPath(switches::kUserDataDir, | 575 command_line->AppendSwitchPath(switches::kUserDataDir, |
| 572 override_user_data_dir); | 576 override_user_data_dir); |
| 573 } | 577 } |
| 574 | 578 |
| 575 username_ = command_line->GetSwitchValueASCII(kUsername); | 579 std::string accounts_file = command_line->GetSwitchValueASCII(kAccountsFile); |
| 576 password_ = command_line->GetSwitchValueASCII(kkPassword); | 580 std::string account_type = command_line->GetSwitchValueASCII(kAccountType); |
| 581 if (!accounts_file.empty()) { | |
| 582 // We've been passed in a file containing accounts information. | |
| 583 // In this case, we'll obtain the user-name and password information from | |
| 584 // the specified file, even if user-name and password have been specified | |
| 585 // on the command-line. | |
| 586 base::FilePath accounts_file_path(accounts_file); | |
| 587 ASSERT_FALSE(account_type.empty()); | |
| 588 ASSERT_TRUE(base::PathExists(accounts_file_path)); | |
| 589 SetUserNameAndPassword(accounts_file_path, account_type); | |
| 590 } else { | |
| 591 // No file for accounts specified. Read user-name and password from command | |
| 592 // line. | |
| 593 username_ = command_line->GetSwitchValueASCII(kUserName); | |
| 594 password_ = command_line->GetSwitchValueASCII(kPassword); | |
| 595 } | |
| 596 | |
| 577 me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin); | 597 me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin); |
| 578 remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName); | 598 remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName); |
| 579 extension_name_ = command_line->GetSwitchValueASCII(kExtensionName); | 599 extension_name_ = command_line->GetSwitchValueASCII(kExtensionName); |
| 580 http_server_ = command_line->GetSwitchValueASCII(kHttpServer); | 600 http_server_ = command_line->GetSwitchValueASCII(kHttpServer); |
| 581 | 601 |
| 582 no_cleanup_ = command_line->HasSwitch(kNoCleanup); | 602 no_cleanup_ = command_line->HasSwitch(kNoCleanup); |
| 583 no_install_ = command_line->HasSwitch(kNoInstall); | 603 no_install_ = command_line->HasSwitch(kNoInstall); |
| 584 | 604 |
| 585 if (!no_install_) { | 605 if (!no_install_) { |
| 586 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); | 606 webapp_crx_ = command_line->GetSwitchValuePath(kWebAppCrx); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 bool RemoteDesktopBrowserTest::IsPinFormVisible() { | 811 bool RemoteDesktopBrowserTest::IsPinFormVisible() { |
| 792 DismissHostVersionWarningIfVisible(); | 812 DismissHostVersionWarningIfVisible(); |
| 793 return HtmlElementVisible("pin-form"); | 813 return HtmlElementVisible("pin-form"); |
| 794 } | 814 } |
| 795 | 815 |
| 796 void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() { | 816 void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() { |
| 797 if (HtmlElementVisible("host-needs-update-connect-button")) | 817 if (HtmlElementVisible("host-needs-update-connect-button")) |
| 798 ClickOnControl("host-needs-update-connect-button"); | 818 ClickOnControl("host-needs-update-connect-button"); |
| 799 } | 819 } |
| 800 | 820 |
| 821 void RemoteDesktopBrowserTest::SetUserNameAndPassword( | |
| 822 const base::FilePath &accounts_file_path, const std::string account_type) { | |
| 823 | |
| 824 // Read contents of accounts file. | |
| 825 std::string accounts_info; | |
| 826 ASSERT_TRUE(base::ReadFileToString(accounts_file_path, &accounts_info)); | |
| 827 | |
| 828 // Get the root dictionary from the input json file contents. | |
| 829 scoped_ptr<base::Value> root( | |
| 830 base::JSONReader::Read(accounts_info, base::JSON_ALLOW_TRAILING_COMMAS)); | |
| 831 DCHECK(root.get() != NULL); | |
|
weitao
2014/10/09 00:23:28
Change to ASSERT_TRUE?
anandc
2014/10/09 00:39:59
Merged with the following ASSERT_TRUE.
| |
| 832 | |
| 833 const base::DictionaryValue* root_dict = NULL; | |
| 834 ASSERT_TRUE(root.get() && root->GetAsDictionary(&root_dict)); | |
|
weitao
2014/10/09 00:23:28
You have already DCHECKed on root.Get() earlier.
anandc
2014/10/09 00:39:59
Done.
| |
| 835 | |
| 836 // Now get the dictionary for the specified account type. | |
| 837 const base::DictionaryValue* account_dict = NULL; | |
| 838 ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict)); | |
| 839 | |
|
weitao
2014/10/09 00:23:28
Remove this blank line.
anandc
2014/10/09 00:39:59
Done.
| |
| 840 ASSERT_TRUE(account_dict->GetString(kUserName, &username_)); | |
| 841 | |
|
weitao
2014/10/09 00:23:28
ditto.
anandc
2014/10/09 00:39:59
Done.
| |
| 842 ASSERT_TRUE(account_dict->GetString(kPassword, &password_)); | |
| 843 } | |
| 844 | |
| 801 // static | 845 // static |
| 802 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( | 846 bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow( |
| 803 content::WebContents* web_contents) { | 847 content::WebContents* web_contents) { |
| 804 return ExecuteScriptAndExtractBool( | 848 return ExecuteScriptAndExtractBool( |
| 805 web_contents, "remoting.identity.isAuthenticated()"); | 849 web_contents, "remoting.identity.isAuthenticated()"); |
| 806 } | 850 } |
| 807 | 851 |
| 808 // static | 852 // static |
| 809 bool RemoteDesktopBrowserTest::IsHostActionComplete( | 853 bool RemoteDesktopBrowserTest::IsHostActionComplete( |
| 810 content::WebContents* client_web_content, | 854 content::WebContents* client_web_content, |
| 811 std::string host_action_var) { | 855 std::string host_action_var) { |
| 812 return ExecuteScriptAndExtractBool( | 856 return ExecuteScriptAndExtractBool( |
| 813 client_web_content, | 857 client_web_content, |
| 814 host_action_var); | 858 host_action_var); |
| 815 } | 859 } |
| 816 | 860 |
| 817 // static | 861 // static |
| 818 bool RemoteDesktopBrowserTest::IsEnabled( | 862 bool RemoteDesktopBrowserTest::IsEnabled( |
| 819 content::WebContents* client_web_content, | 863 content::WebContents* client_web_content, |
| 820 const std::string& element_name) { | 864 const std::string& element_name) { |
| 821 return !ExecuteScriptAndExtractBool( | 865 return !ExecuteScriptAndExtractBool( |
| 822 client_web_content, | 866 client_web_content, |
| 823 "document.getElementById(\"" + element_name + "\").disabled"); | 867 "document.getElementById(\"" + element_name + "\").disabled"); |
| 824 } | 868 } |
| 825 | 869 |
| 826 } // namespace remoting | 870 } // namespace remoting |
| OLD | NEW |