Commit 940c62c2 authored by anandc's avatar anandc Committed by Commit bot

Parse user-name and password values from a json file, instead of from command line.

BUG=419850

Review URL: https://codereview.chromium.org/617103008

Cr-Commit-Position: refs/heads/master@{#298990}
parent b31efc78
......@@ -474,6 +474,9 @@ void RemoteDesktopBrowserTest::SetUpTestForMe2Me() {
}
void RemoteDesktopBrowserTest::Auth() {
// For this test, we must be given the user-name and password.
ASSERT_TRUE(!username_.empty() && !password_.empty());
Authorize();
Authenticate();
Approve();
......@@ -572,8 +575,25 @@ void RemoteDesktopBrowserTest::ParseCommandLine() {
override_user_data_dir);
}
username_ = command_line->GetSwitchValueASCII(kUsername);
password_ = command_line->GetSwitchValueASCII(kkPassword);
CommandLine::StringType accounts_file =
command_line->GetSwitchValueNative(kAccountsFile);
std::string account_type = command_line->GetSwitchValueASCII(kAccountType);
if (!accounts_file.empty()) {
// We've been passed in a file containing accounts information.
// In this case, we'll obtain the user-name and password information from
// the specified file, even if user-name and password have been specified
// on the command-line.
base::FilePath accounts_file_path((base::FilePath(accounts_file)));
ASSERT_FALSE(account_type.empty());
ASSERT_TRUE(base::PathExists((base::FilePath(accounts_file))));
SetUserNameAndPassword((base::FilePath(accounts_file)), account_type);
} else {
// No file for accounts specified. Read user-name and password from command
// line.
username_ = command_line->GetSwitchValueASCII(kUserName);
password_ = command_line->GetSwitchValueASCII(kUserPassword);
}
me2me_pin_ = command_line->GetSwitchValueASCII(kMe2MePin);
remote_host_name_ = command_line->GetSwitchValueASCII(kRemoteHostName);
extension_name_ = command_line->GetSwitchValueASCII(kExtensionName);
......@@ -798,6 +818,27 @@ void RemoteDesktopBrowserTest::DismissHostVersionWarningIfVisible() {
ClickOnControl("host-needs-update-connect-button");
}
void RemoteDesktopBrowserTest::SetUserNameAndPassword(
const base::FilePath &accounts_file_path, const std::string& account_type) {
// Read contents of accounts file.
std::string accounts_info;
ASSERT_TRUE(base::ReadFileToString(accounts_file_path, &accounts_info));
// Get the root dictionary from the input json file contents.
scoped_ptr<base::Value> root(
base::JSONReader::Read(accounts_info, base::JSON_ALLOW_TRAILING_COMMAS));
const base::DictionaryValue* root_dict = NULL;
ASSERT_TRUE(root.get() && root->GetAsDictionary(&root_dict));
// Now get the dictionary for the specified account type.
const base::DictionaryValue* account_dict = NULL;
ASSERT_TRUE(root_dict->GetDictionary(account_type, &account_dict));
ASSERT_TRUE(account_dict->GetString(kUserName, &username_));
ASSERT_TRUE(account_dict->GetString(kUserPassword, &password_));
}
// static
bool RemoteDesktopBrowserTest::IsAuthenticatedInWindow(
content::WebContents* web_contents) {
......
......@@ -21,8 +21,10 @@ const char kNoCleanup[] = "no-cleanup";
const char kNoInstall[] = "no-install";
const char kWebAppCrx[] = "webapp-crx";
const char kWebAppUnpacked[] = "webapp-unpacked";
const char kUsername[] = "username";
const char kkPassword[] = "password";
const char kUserName[] = "username";
const char kUserPassword[] = "password";
const char kAccountsFile[] = "accounts-file";
const char kAccountType[] = "account-type";
const char kMe2MePin[] = "me2me-pin";
const char kRemoteHostName[] = "remote-host-name";
const char kExtensionName[] = "extension-name";
......@@ -125,6 +127,9 @@ class RemoteDesktopBrowserTest : public extensions::PlatformAppBrowserTest {
void SimulateMouseClickAt(
int modifiers, blink::WebMouseEvent::Button button, int x, int y);
void SetUserNameAndPassword(
const base::FilePath &accounts_file, const std::string& account_type);
// The following helpers each perform a composite task.
// Install the chromoting extension
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment