diff options
author | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 20:02:48 +0000 |
---|---|---|
committer | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 20:02:48 +0000 |
commit | fa20eb802253bc44a48053f55d71f72b20ad062e (patch) | |
tree | 146516bfba22fdc6dbe5753c181704146fc22e9a /chrome/test/live_sync/live_sync_test.cc | |
parent | d3878dbe457b10c50ac1df6eed2f2255e990801a (diff) | |
download | chromium_src-fa20eb802253bc44a48053f55d71f72b20ad062e.zip chromium_src-fa20eb802253bc44a48053f55d71f72b20ad062e.tar.gz chromium_src-fa20eb802253bc44a48053f55d71f72b20ad062e.tar.bz2 |
In order to run the sync integration tests on the chromium buildbots, we need a way to load the GAIA credentials from a local password file instead of via command line parameters.
This changelist implements a new command line parameter called "--password-file-for-test" for this purpose.
BUG=48525
TEST=sync_integration_tests;valid password file;invalid password file;blank password file;non-existent password file
Review URL: http://codereview.chromium.org/2899001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51882 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/live_sync/live_sync_test.cc')
-rw-r--r-- | chrome/test/live_sync/live_sync_test.cc | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/chrome/test/live_sync/live_sync_test.cc b/chrome/test/live_sync/live_sync_test.cc index a7ccacb..8d4eee3 100644 --- a/chrome/test/live_sync/live_sync_test.cc +++ b/chrome/test/live_sync/live_sync_test.cc @@ -4,12 +4,17 @@ #include "chrome/test/live_sync/live_sync_test.h" +#include <vector> + +#include "base/file_util.h" +#include "base/string_util.h" #include "chrome/browser/profile.h" #include "chrome/browser/profile_manager.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" namespace switches { +const wchar_t kPasswordFileForTest[] = L"password-file-for-test"; const wchar_t kSyncUserForTest[] = L"sync-user-for-test"; const wchar_t kSyncPasswordForTest[] = L"sync-password-for-test"; } @@ -19,12 +24,36 @@ void LiveSyncTest::SetUp() { // available. But we can verify our command line parameters and fail // early. const CommandLine* cl = CommandLine::ForCurrentProcess(); - username_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncUserForTest)); - password_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncPasswordForTest)); - ASSERT_FALSE(username_.empty()) << "Can't run live server test " - << "without specifying --" << switches::kSyncUserForTest; - ASSERT_FALSE(password_.empty()) << "Can't run live server test " - << "without specifying --" << switches::kSyncPasswordForTest; + if (cl->HasSwitch(switches::kPasswordFileForTest)) { + // Read GAIA credentials from a local password file if specified via the + // "--password-file-for-test" command line switch. Note: The password file + // must be a plain text file with exactly two lines -- the username on the + // first line and the password on the second line. + password_file_ = cl->GetSwitchValue(switches::kPasswordFileForTest); + ASSERT_FALSE(password_file_.empty()) << "Can't run live server test " + << "without specifying --" << switches::kPasswordFileForTest + << "=<filename>"; + std::string file_contents; + file_util::ReadFileToString(password_file_, &file_contents); + ASSERT_NE(file_contents, "") << "Password file \"" << password_file_ + << "\" does not exist."; + std::vector<std::string> tokens; + std::string delimiters = "\r\n"; + Tokenize(file_contents, delimiters, &tokens); + ASSERT_TRUE(tokens.size() == 2) << "Password file \"" << password_file_ + << "\" must contain exactly two lines of text."; + username_ = tokens[0]; + password_ = tokens[1]; + } else { + // Read GAIA credentials from the "--sync-XXX-for-test" command line + // parameters. + username_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncUserForTest)); + password_ = WideToUTF8(cl->GetSwitchValue(switches::kSyncPasswordForTest)); + ASSERT_FALSE(username_.empty()) << "Can't run live server test " + << "without specifying --" << switches::kSyncUserForTest; + ASSERT_FALSE(password_.empty()) << "Can't run live server test " + << "without specifying --" << switches::kSyncPasswordForTest; + } // Unless a sync server was explicitly provided, run a test one locally. // TODO(ncarter): It might be better to allow the user to specify a choice |