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