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

Side by Side 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: fix comments Created 5 years, 3 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser/sync/test/integration/sync_test.h" 5 #include "chrome/browser/sync/test/integration/sync_test.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/guid.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
15 #include "base/path_service.h" 16 #include "base/path_service.h"
16 #include "base/process/launch.h" 17 #include "base/process/launch.h"
17 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
18 #include "base/strings/string_util.h" 19 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "base/synchronization/waitable_event.h" 22 #include "base/synchronization/waitable_event.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "components/invalidation/impl/p2p_invalidator.h" 59 #include "components/invalidation/impl/p2p_invalidator.h"
59 #include "components/invalidation/impl/profile_invalidation_provider.h" 60 #include "components/invalidation/impl/profile_invalidation_provider.h"
60 #include "components/invalidation/public/invalidation_service.h" 61 #include "components/invalidation/public/invalidation_service.h"
61 #include "components/keyed_service/core/keyed_service.h" 62 #include "components/keyed_service/core/keyed_service.h"
62 #include "components/os_crypt/os_crypt.h" 63 #include "components/os_crypt/os_crypt.h"
63 #include "components/search_engines/template_url_service.h" 64 #include "components/search_engines/template_url_service.h"
64 #include "components/signin/core/browser/profile_identity_provider.h" 65 #include "components/signin/core/browser/profile_identity_provider.h"
65 #include "components/signin/core/browser/signin_manager.h" 66 #include "components/signin/core/browser/signin_manager.h"
66 #include "components/sync_driver/invalidation_helper.h" 67 #include "components/sync_driver/invalidation_helper.h"
67 #include "components/sync_driver/sync_driver_switches.h" 68 #include "components/sync_driver/sync_driver_switches.h"
69 #include "content/public/browser/navigation_entry.h"
68 #include "content/public/browser/notification_service.h" 70 #include "content/public/browser/notification_service.h"
69 #include "content/public/browser/web_contents.h" 71 #include "content/public/browser/web_contents.h"
70 #include "content/public/test/test_browser_thread.h" 72 #include "content/public/test/test_browser_thread.h"
71 #include "google_apis/gaia/gaia_urls.h" 73 #include "google_apis/gaia/gaia_urls.h"
72 #include "net/base/escape.h" 74 #include "net/base/escape.h"
73 #include "net/base/load_flags.h" 75 #include "net/base/load_flags.h"
74 #include "net/base/network_change_notifier.h" 76 #include "net/base/network_change_notifier.h"
75 #include "net/base/port_util.h" 77 #include "net/base/port_util.h"
76 #include "net/cookies/cookie_monster.h" 78 #include "net/cookies/cookie_monster.h"
77 #include "net/test/spawned_test_server/spawned_test_server.h" 79 #include "net/test/spawned_test_server/spawned_test_server.h"
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 case MULTIPLE_CLIENT: { 203 case MULTIPLE_CLIENT: {
202 num_clients_ = 3; 204 num_clients_ = 3;
203 break; 205 break;
204 } 206 }
205 } 207 }
206 } 208 }
207 209
208 SyncTest::~SyncTest() {} 210 SyncTest::~SyncTest() {}
209 211
210 void SyncTest::SetUp() { 212 void SyncTest::SetUp() {
213 // Sets |server_type_| if it wasn't specified by the test.
214 DecideServerType();
215
211 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); 216 base::CommandLine* cl = base::CommandLine::ForCurrentProcess();
212 if (cl->HasSwitch(switches::kPasswordFileForTest)) { 217 if (cl->HasSwitch(switches::kPasswordFileForTest)) {
213 ReadPasswordFile(); 218 ReadPasswordFile();
214 } else if (cl->HasSwitch(switches::kSyncUserForTest) &&
215 cl->HasSwitch(switches::kSyncPasswordForTest)) {
216 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest);
217 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest);
218 } else { 219 } else {
219 username_ = "user@gmail.com"; 220 // Decide on username to use or create one.
220 password_ = "password"; 221 if (cl->HasSwitch(switches::kSyncUserForTest)) {
222 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest);
223 } else if (UsingExternalServers()) {
224 // If --sync-user-for-test is not provided and we are using external
225 // 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.
226 // Creating a Gaia account requires URL navigation and thus needs to be
227 // done outside the SetUp() function.
228 create_gaia_account_at_runtime_ = true;
229 username_ = base::GenerateGUID();
230 } else {
231 username_ = "user@gmail.com";
232 }
233 // Decide on password to use.
234 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.
235 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest);
236 } else {
237 password_ = "password";
238 }
221 } 239 }
222 240
223 if (username_.empty() || password_.empty()) 241 if (username_.empty() || password_.empty())
224 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; 242 LOG(FATAL) << "Cannot run sync tests without GAIA credentials.";
225 243
226 // Sets |server_type_| if it wasn't specified by the test.
227 DecideServerType();
228
229 // Mock the Mac Keychain service. The real Keychain can block on user input. 244 // Mock the Mac Keychain service. The real Keychain can block on user input.
230 #if defined(OS_MACOSX) 245 #if defined(OS_MACOSX)
231 OSCrypt::UseMockKeychain(true); 246 OSCrypt::UseMockKeychain(true);
232 #endif 247 #endif
233 248
234 // Start up a sync test server if one is needed and setup mock gaia responses. 249 // Start up a sync test server if one is needed and setup mock gaia responses.
235 // Note: This must be done prior to the call to SetupClients() because we want 250 // Note: This must be done prior to the call to SetupClients() because we want
236 // the mock gaia responses to be available before GaiaUrls is initialized. 251 // the mock gaia responses to be available before GaiaUrls is initialized.
237 SetUpTestServerIfRequired(); 252 SetUpTestServerIfRequired();
238 253
(...skipping 30 matching lines...) Expand all
269 // Disable non-essential access of external network resources. 284 // Disable non-essential access of external network resources.
270 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) 285 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking))
271 cl->AppendSwitch(switches::kDisableBackgroundNetworking); 286 cl->AppendSwitch(switches::kDisableBackgroundNetworking);
272 287
273 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) 288 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride))
274 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); 289 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride);
275 } 290 }
276 291
277 void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {} 292 void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {}
278 293
294 bool SyncTest::CreateGaiaAccount(const std::string& username,
295 const std::string& password) {
296 std::string relative_url = base::StringPrintf("/CreateUsers?%s=%s",
297 username.c_str(),
298 password.c_str());
299 GURL create_user_url =
300 GaiaUrls::GetInstance()->gaia_url().Resolve(relative_url);
301 // NavigateToURL blocks until the navigation finishes.
302 ui_test_utils::NavigateToURL(browser(), create_user_url);
303 content::WebContents* contents =
304 browser()->tab_strip_model()->GetActiveWebContents();
305 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry();
306 CHECK(entry) << "Could not get a hold on NavigationEntry post URL navigate.";
307 DVLOG(1) << "Create Gaia account request return code = "
308 << entry->GetHttpStatusCode();
309 return entry->GetHttpStatusCode() == 200;
310 }
311
279 // Called when the ProfileManager has created a profile. 312 // Called when the ProfileManager has created a profile.
280 // static 313 // static
281 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, 314 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure,
282 Profile* profile, 315 Profile* profile,
283 Profile::CreateStatus status) { 316 Profile::CreateStatus status) {
284 EXPECT_TRUE(profile); 317 EXPECT_TRUE(profile);
285 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); 318 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status);
286 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); 319 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status);
287 // This will be called multiple times. Wait until the profile is initialized 320 // This will be called multiple times. Wait until the profile is initialized
288 // fully to quit the loop. 321 // fully to quit the loop.
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 GetInvalidationService()); 559 GetInvalidationService());
527 p2p_invalidation_service->UpdateCredentials(username_, password_); 560 p2p_invalidation_service->UpdateCredentials(username_, password_);
528 // Start listening for and emitting notifications of commits. 561 // Start listening for and emitting notifications of commits.
529 invalidation_forwarders_[index] = 562 invalidation_forwarders_[index] =
530 new P2PInvalidationForwarder(clients_[index]->service(), 563 new P2PInvalidationForwarder(clients_[index]->service(),
531 p2p_invalidation_service); 564 p2p_invalidation_service);
532 } 565 }
533 } 566 }
534 567
535 bool SyncTest::SetupSync() { 568 bool SyncTest::SetupSync() {
569 if (create_gaia_account_at_runtime_) {
570 CHECK(UsingExternalServers()) <<
571 "Cannot create Gaia accounts without external authentication servers";
572 if (!CreateGaiaAccount(username_, password_))
573 LOG(FATAL) << "Could not create Gaia account.";
574 }
536 // Create sync profiles and clients if they haven't already been created. 575 // Create sync profiles and clients if they haven't already been created.
537 if (profiles_.empty()) { 576 if (profiles_.empty()) {
538 if (!SetupClients()) 577 if (!SetupClients())
539 LOG(FATAL) << "SetupClients() failed."; 578 LOG(FATAL) << "SetupClients() failed.";
540 } 579 }
541 580
542 // Sync each of the profiles. 581 // Sync each of the profiles.
543 for (int i = 0; i < num_clients_; ++i) { 582 for (int i = 0; i < num_clients_; ++i) {
544 if (!GetClient(i)->SetupSync()) 583 if (!GetClient(i)->SetupSync())
545 LOG(FATAL) << "SetupSync() failed."; 584 LOG(FATAL) << "SetupSync() failed.";
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
1062 content::NotificationService::current()->Notify( 1101 content::NotificationService::current()->Notify(
1063 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, 1102 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL,
1064 content::Source<Profile>(GetProfile(index)), 1103 content::Source<Profile>(GetProfile(index)),
1065 content::Details<const syncer::ModelTypeSet>(&model_types)); 1104 content::Details<const syncer::ModelTypeSet>(&model_types));
1066 } 1105 }
1067 1106
1068 void SyncTest::SetPreexistingPreferencesFileContents( 1107 void SyncTest::SetPreexistingPreferencesFileContents(
1069 const std::string& contents) { 1108 const std::string& contents) {
1070 preexisting_preferences_file_contents_ = contents; 1109 preexisting_preferences_file_contents_ = contents;
1071 } 1110 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698