Index: chrome/browser/sync/test/integration/sync_test.cc |
diff --git a/chrome/browser/sync/test/integration/sync_test.cc b/chrome/browser/sync/test/integration/sync_test.cc |
index 1b14af9e2618a419bc42fbe3e60bd2674fb47c43..f3d5cc9569aedfcaa2d963fc3605d493590a9497 100644 |
--- a/chrome/browser/sync/test/integration/sync_test.cc |
+++ b/chrome/browser/sync/test/integration/sync_test.cc |
@@ -9,6 +9,7 @@ |
#include "base/basictypes.h" |
#include "base/bind.h" |
#include "base/command_line.h" |
+#include "base/guid.h" |
#include "base/memory/ref_counted.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/message_loop/message_loop.h" |
@@ -65,6 +66,7 @@ |
#include "components/signin/core/browser/signin_manager.h" |
#include "components/sync_driver/invalidation_helper.h" |
#include "components/sync_driver/sync_driver_switches.h" |
+#include "content/public/browser/navigation_entry.h" |
#include "content/public/browser/notification_service.h" |
#include "content/public/browser/web_contents.h" |
#include "content/public/test/test_browser_thread.h" |
@@ -208,24 +210,37 @@ SyncTest::SyncTest(TestType test_type) |
SyncTest::~SyncTest() {} |
void SyncTest::SetUp() { |
+ // Sets |server_type_| if it wasn't specified by the test. |
+ DecideServerType(); |
+ |
base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
if (cl->HasSwitch(switches::kPasswordFileForTest)) { |
ReadPasswordFile(); |
- } else if (cl->HasSwitch(switches::kSyncUserForTest) && |
- cl->HasSwitch(switches::kSyncPasswordForTest)) { |
- username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
- password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); |
} else { |
- username_ = "user@gmail.com"; |
- password_ = "password"; |
+ // Decide on username to use or create one. |
+ if (cl->HasSwitch(switches::kSyncUserForTest)) { |
+ username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
+ } else if (UsingExternalServers()) { |
+ // If --sync-user-for-test is not provided and we are using external |
+ // servers then we assume the need to automatically create a Gaia account. |
pval...(no longer on Chromium)
2015/09/04 16:48:32
I think you can remove everything up to "We assume
shadi
2015/09/04 21:43:45
Done.
|
+ // Creating a Gaia account requires URL navigation and thus needs to be |
+ // done outside the SetUp() function. |
+ create_gaia_account_at_runtime_ = true; |
+ username_ = base::GenerateGUID(); |
+ } else { |
+ username_ = "user@gmail.com"; |
+ } |
+ // Decide on password to use. |
+ if (cl->HasSwitch(switches::kSyncPasswordForTest)) { |
pval...(no longer on Chromium)
2015/09/04 16:48:32
Consider using the ternary (?) operator here?
shadi
2015/09/04 21:43:45
Done.
|
+ password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); |
+ } else { |
+ password_ = "password"; |
+ } |
} |
if (username_.empty() || password_.empty()) |
LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; |
- // Sets |server_type_| if it wasn't specified by the test. |
- DecideServerType(); |
- |
// Mock the Mac Keychain service. The real Keychain can block on user input. |
#if defined(OS_MACOSX) |
OSCrypt::UseMockKeychain(true); |
@@ -276,6 +291,24 @@ void SyncTest::AddTestSwitches(base::CommandLine* cl) { |
void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {} |
+bool SyncTest::CreateGaiaAccount(const std::string& username, |
+ const std::string& password) { |
+ std::string relative_url = base::StringPrintf("/CreateUsers?%s=%s", |
+ username.c_str(), |
+ password.c_str()); |
+ GURL create_user_url = |
+ GaiaUrls::GetInstance()->gaia_url().Resolve(relative_url); |
+ // NavigateToURL blocks until the navigation finishes. |
+ ui_test_utils::NavigateToURL(browser(), create_user_url); |
+ content::WebContents* contents = |
+ browser()->tab_strip_model()->GetActiveWebContents(); |
+ content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); |
+ CHECK(entry) << "Could not get a hold on NavigationEntry post URL navigate."; |
+ DVLOG(1) << "Create Gaia account request return code = " |
+ << entry->GetHttpStatusCode(); |
+ return entry->GetHttpStatusCode() == 200; |
+} |
+ |
// Called when the ProfileManager has created a profile. |
// static |
void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, |
@@ -533,6 +566,12 @@ void SyncTest::InitializeInvalidations(int index) { |
} |
bool SyncTest::SetupSync() { |
+ if (create_gaia_account_at_runtime_) { |
+ CHECK(UsingExternalServers()) << |
+ "Cannot create Gaia accounts without external authentication servers"; |
+ if (!CreateGaiaAccount(username_, password_)) |
+ LOG(FATAL) << "Could not create Gaia account."; |
+ } |
// Create sync profiles and clients if they haven't already been created. |
if (profiles_.empty()) { |
if (!SetupClients()) |