Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1027)

Unified Diff: chrome/browser/sync/test/integration/sync_test.cc

Issue 1306163003: Dynamically create Gaia accounts when running E2E sync integration tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 c0f0d85b24592f60bf9aa7e11a3370ae33977b4b..6525767c2250db8affbddc3b2ed425dc7953c019 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"
@@ -64,6 +65,7 @@
#include "components/signin/core/browser/profile_identity_provider.h"
#include "components/signin/core/browser/signin_manager.h"
#include "components/sync_driver/invalidation_helper.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"
@@ -207,6 +209,9 @@ 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();
@@ -214,7 +219,18 @@ void SyncTest::SetUp() {
cl->HasSwitch(switches::kSyncPasswordForTest)) {
username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest);
password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest);
- } else {
+ } 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.
+ // 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();
+ if (cl->HasSwitch(switches::kSyncPasswordForTest))
pval...(no longer on Chromium) 2015/08/26 19:26:33 can we simplify the logic in this method to only s
shadi 2015/09/03 22:17:08 PTAL at new logic.
+ password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest);
+ else
+ password_ = "password";
+ }else {
pval...(no longer on Chromium) 2015/08/26 19:26:33 space after }
shadi 2015/09/03 22:17:08 Done.
username_ = "user@gmail.com";
password_ = "password";
}
@@ -222,9 +238,6 @@ void SyncTest::SetUp() {
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);
@@ -275,6 +288,24 @@ void SyncTest::AddTestSwitches(base::CommandLine* cl) {
void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {}
+bool SyncTest::CreateGaiaAccount(const std::string& user_name,
+ const std::string& password) {
+ std::string relative_url = base::StringPrintf("/CreateUsers?%s=%s",
+ user_name.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 = " <<
pval...(no longer on Chromium) 2015/08/26 19:26:33 i believe the trailing << here should be on the ne
shadi 2015/09/03 22:17:08 Done.
+ entry->GetHttpStatusCode();
+ return entry->GetHttpStatusCode() == 200;
+}
+
// Called when the ProfileManager has created a profile.
// static
void SyncTest::CreateProfileCallback(const base::Closure& quit_closure,
@@ -532,6 +563,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())

Powered by Google App Engine
This is Rietveld 408576698