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

Side by Side Diff: chrome/browser/sync/test/integration/sync_test.cc

Issue 2725813003: reland of [sync] Add Sessions integration tests (Closed)
Patch Set: Switch back to WaitForURLOnServer, make everything a constant Created 3 years, 9 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } 412 }
413 } 413 }
414 414
415 Profile* profile = 415 Profile* profile =
416 Profile::CreateProfile(profile_path, profile_delegates_[index].get(), 416 Profile::CreateProfile(profile_path, profile_delegates_[index].get(),
417 Profile::CREATE_MODE_SYNCHRONOUS); 417 Profile::CREATE_MODE_SYNCHRONOUS);
418 return profile; 418 return profile;
419 } 419 }
420 420
421 Profile* SyncTest::GetProfile(int index) { 421 Profile* SyncTest::GetProfile(int index) {
422 if (profiles_.empty()) 422 EXPECT_FALSE(profiles_.empty()) << "SetupClients() has not yet been called.";
423 LOG(FATAL) << "SetupClients() has not yet been called."; 423 EXPECT_FALSE(index < 0 || index >= static_cast<int>(profiles_.size()))
424 if (index < 0 || index >= static_cast<int>(profiles_.size())) 424 << "GetProfile(): Index is out of bounds.";
425 LOG(FATAL) << "GetProfile(): Index is out of bounds."; 425
426 return profiles_[index]; 426 Profile* profile = profiles_[index];
427 EXPECT_NE(nullptr, profile) << "No profile found at index: " << index;
428
429 return profile;
427 } 430 }
428 431
429 std::vector<Profile*> SyncTest::GetAllProfiles() { 432 std::vector<Profile*> SyncTest::GetAllProfiles() {
430 std::vector<Profile*> profiles; 433 std::vector<Profile*> profiles;
431 if (use_verifier()) { 434 if (use_verifier()) {
432 profiles.push_back(verifier()); 435 profiles.push_back(verifier());
433 } 436 }
434 for (int i = 0; i < num_clients(); ++i) { 437 for (int i = 0; i < num_clients(); ++i) {
435 profiles.push_back(GetProfile(i)); 438 profiles.push_back(GetProfile(i));
436 } 439 }
437 return profiles; 440 return profiles;
438 } 441 }
439 442
440 Browser* SyncTest::GetBrowser(int index) { 443 Browser* SyncTest::GetBrowser(int index) {
441 if (browsers_.empty()) 444 EXPECT_FALSE(browsers_.empty()) << "SetupClients() has not yet been called.";
442 LOG(FATAL) << "SetupClients() has not yet been called."; 445 EXPECT_FALSE(index < 0 || index >= static_cast<int>(browsers_.size()))
443 if (index < 0 || index >= static_cast<int>(browsers_.size())) 446 << "GetBrowser(): Index is out of bounds.";
444 LOG(FATAL) << "GetBrowser(): Index is out of bounds."; 447
448 Browser* browser = browsers_[index];
449 EXPECT_NE(browser, nullptr);
450
445 return browsers_[index]; 451 return browsers_[index];
446 } 452 }
447 453
454 Browser* SyncTest::AddBrowser(int profile_index) {
455 Profile* profile = GetProfile(profile_index);
456 browsers_.push_back(new Browser(Browser::CreateParams(profile, true)));
457 profiles_.push_back(profile);
458
459 return browsers_[browsers_.size() - 1];
460 }
461
448 ProfileSyncServiceHarness* SyncTest::GetClient(int index) { 462 ProfileSyncServiceHarness* SyncTest::GetClient(int index) {
449 if (clients_.empty()) 463 if (clients_.empty())
450 LOG(FATAL) << "SetupClients() has not yet been called."; 464 LOG(FATAL) << "SetupClients() has not yet been called.";
451 if (index < 0 || index >= static_cast<int>(clients_.size())) 465 if (index < 0 || index >= static_cast<int>(clients_.size()))
452 LOG(FATAL) << "GetClient(): Index is out of bounds."; 466 LOG(FATAL) << "GetClient(): Index is out of bounds.";
453 return clients_[index]; 467 return clients_[index];
454 } 468 }
455 469
456 ProfileSyncService* SyncTest::GetSyncService(int index) { 470 ProfileSyncService* SyncTest::GetSyncService(int index) {
457 return ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); 471 return ProfileSyncServiceFactory::GetForProfile(GetProfile(index));
(...skipping 22 matching lines...) Expand all
480 bool SyncTest::SetupClients() { 494 bool SyncTest::SetupClients() {
481 if (num_clients_ <= 0) 495 if (num_clients_ <= 0)
482 LOG(FATAL) << "num_clients_ incorrectly initialized."; 496 LOG(FATAL) << "num_clients_ incorrectly initialized.";
483 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) 497 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty())
484 LOG(FATAL) << "SetupClients() has already been called."; 498 LOG(FATAL) << "SetupClients() has already been called.";
485 499
486 // Create the required number of sync profiles, browsers and clients. 500 // Create the required number of sync profiles, browsers and clients.
487 profiles_.resize(num_clients_); 501 profiles_.resize(num_clients_);
488 profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier. 502 profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier.
489 tmp_profile_paths_.resize(num_clients_); 503 tmp_profile_paths_.resize(num_clients_);
490 browsers_.resize(num_clients_);
491 clients_.resize(num_clients_); 504 clients_.resize(num_clients_);
492 invalidation_forwarders_.resize(num_clients_); 505 invalidation_forwarders_.resize(num_clients_);
493 sync_refreshers_.resize(num_clients_); 506 sync_refreshers_.resize(num_clients_);
494 fake_server_invalidation_services_.resize(num_clients_); 507 fake_server_invalidation_services_.resize(num_clients_);
495 508
496 if (create_gaia_account_at_runtime_) { 509 if (create_gaia_account_at_runtime_) {
497 CHECK(UsingExternalServers()) << 510 CHECK(UsingExternalServers()) <<
498 "Cannot create Gaia accounts without external authentication servers"; 511 "Cannot create Gaia accounts without external authentication servers";
499 if (!CreateGaiaAccount(username_, password_)) 512 if (!CreateGaiaAccount(username_, password_))
500 LOG(FATAL) << "Could not create Gaia account."; 513 LOG(FATAL) << "Could not create Gaia account.";
(...skipping 20 matching lines...) Expand all
521 // Error cases are all handled by LOG(FATAL) messages. So there is not really 534 // Error cases are all handled by LOG(FATAL) messages. So there is not really
522 // a case that returns false. In case we failed to create a verifier profile, 535 // a case that returns false. In case we failed to create a verifier profile,
523 // any call to the verifier() would fail. 536 // any call to the verifier() would fail.
524 return true; 537 return true;
525 } 538 }
526 539
527 void SyncTest::InitializeProfile(int index, Profile* profile) { 540 void SyncTest::InitializeProfile(int index, Profile* profile) {
528 DCHECK(profile); 541 DCHECK(profile);
529 profiles_[index] = profile; 542 profiles_[index] = profile;
530 543
531 // CheckInitialState() assumes that no windows are open at startup. 544 AddBrowser(index);
532 browsers_[index] =
533 new Browser(Browser::CreateParams(GetProfile(index), true));
534
535 EXPECT_NE(nullptr, GetBrowser(index)) << "Could not create Browser " << index;
536 545
537 // Make sure the ProfileSyncService has been created before creating the 546 // Make sure the ProfileSyncService has been created before creating the
538 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to 547 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to
539 // already exist. 548 // already exist.
540 ProfileSyncService* profile_sync_service = 549 ProfileSyncService* profile_sync_service =
541 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); 550 ProfileSyncServiceFactory::GetForProfile(GetProfile(index));
542 551
543 if (server_type_ == IN_PROCESS_FAKE_SERVER) { 552 if (server_type_ == IN_PROCESS_FAKE_SERVER) {
544 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer. 553 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer.
545 profile_sync_service->OverrideNetworkResourcesForTest( 554 profile_sync_service->OverrideNetworkResourcesForTest(
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 1141
1133 void SyncTest::TriggerSyncForModelTypes(int index, 1142 void SyncTest::TriggerSyncForModelTypes(int index,
1134 syncer::ModelTypeSet model_types) { 1143 syncer::ModelTypeSet model_types) {
1135 GetSyncService(index)->TriggerRefresh(model_types); 1144 GetSyncService(index)->TriggerRefresh(model_types);
1136 } 1145 }
1137 1146
1138 void SyncTest::SetPreexistingPreferencesFileContents( 1147 void SyncTest::SetPreexistingPreferencesFileContents(
1139 const std::string& contents) { 1148 const std::string& contents) {
1140 preexisting_preferences_file_contents_ = contents; 1149 preexisting_preferences_file_contents_ = contents;
1141 } 1150 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698