Chromium Code Reviews| 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 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 if (profiles_.empty()) |
| 423 LOG(FATAL) << "SetupClients() has not yet been called."; | 423 LOG(FATAL) << "SetupClients() has not yet been called."; |
|
skym
2017/02/24 16:20:17
Can these be EXPECT_* and not LOG(FATAL)?
Patrick Noland
2017/02/27 18:53:26
Done.
| |
| 424 if (index < 0 || index >= static_cast<int>(profiles_.size())) | 424 if (index < 0 || index >= static_cast<int>(profiles_.size())) |
| 425 LOG(FATAL) << "GetProfile(): Index is out of bounds."; | 425 LOG(FATAL) << "GetProfile(): Index is out of bounds."; |
| 426 return profiles_[index]; | 426 return profiles_[index]; |
|
skym
2017/02/24 16:20:17
What would happen if you checked for nullptr here?
Patrick Noland
2017/02/27 18:53:26
Done.
| |
| 427 } | 427 } |
| 428 | 428 |
| 429 std::vector<Profile*> SyncTest::GetAllProfiles() { | 429 std::vector<Profile*> SyncTest::GetAllProfiles() { |
| 430 std::vector<Profile*> profiles; | 430 std::vector<Profile*> profiles; |
| 431 if (use_verifier()) { | 431 if (use_verifier()) { |
| 432 profiles.push_back(verifier()); | 432 profiles.push_back(verifier()); |
| 433 } | 433 } |
| 434 for (int i = 0; i < num_clients(); ++i) { | 434 for (int i = 0; i < num_clients(); ++i) { |
| 435 profiles.push_back(GetProfile(i)); | 435 profiles.push_back(GetProfile(i)); |
| 436 } | 436 } |
| 437 return profiles; | 437 return profiles; |
| 438 } | 438 } |
| 439 | 439 |
| 440 Browser* SyncTest::GetBrowser(int index) { | 440 Browser* SyncTest::GetBrowser(int index) { |
| 441 if (browsers_.empty()) | 441 if (browsers_.empty()) |
| 442 LOG(FATAL) << "SetupClients() has not yet been called."; | 442 LOG(FATAL) << "SetupClients() has not yet been called."; |
| 443 if (index < 0 || index >= static_cast<int>(browsers_.size())) | 443 if (index < 0 || index >= static_cast<int>(browsers_.size())) |
| 444 LOG(FATAL) << "GetBrowser(): Index is out of bounds."; | 444 LOG(FATAL) << "GetBrowser(): Index is out of bounds."; |
| 445 return browsers_[index]; | 445 return browsers_[index]; |
|
skym
2017/02/24 16:20:17
Same, can we check for nullptr?
Patrick Noland
2017/02/27 18:53:26
Done.
| |
| 446 } | 446 } |
| 447 | 447 |
| 448 Browser* SyncTest::AddBrowser(int profile_index) { | |
| 449 Profile* profile = GetProfile(profile_index); | |
| 450 EXPECT_NE(nullptr, profile) | |
| 451 << "No profile found at profile_index: " << profile_index; | |
| 452 | |
| 453 // Add the new browser at the end of the list. | |
| 454 int index = browsers_.size(); | |
| 455 browsers_.resize(browsers_.size() + 1); | |
|
skym
2017/02/24 00:14:09
why not browsers_.push_back(new Browser(...)); ?
Patrick Noland
2017/02/24 01:00:40
Because I'm copying the bizarre pattern used elsew
| |
| 456 profiles_.resize(profiles_.size() + 1); | |
| 457 browsers_[index] = new Browser(Browser::CreateParams(profile, true)); | |
| 458 | |
| 459 Browser* browser = GetBrowser(index); | |
|
skym
2017/02/24 00:14:09
But. What? You just made this thing, why fetch it
Patrick Noland
2017/02/24 01:00:40
Because I'm copying the bizarre pattern used elsew
skym
2017/02/24 16:20:17
...Is this a memory leak? Who owns this Browser ob
Patrick Noland
2017/02/27 18:53:26
According to sync_test.h "Browser object lifetime
| |
| 460 EXPECT_NE(nullptr, browser) << "Could not create Browser " << index; | |
|
skym
2017/02/24 00:14:09
So when does this happen?
Patrick Noland
2017/02/24 01:00:40
Good question. The old code seemed to think it was
skym
2017/02/24 16:20:17
This is test code, worst case a test fails. Remove
| |
| 461 profiles_[index] = profile; | |
|
skym
2017/02/24 00:14:09
I'm confused, is browsers_.size() allowed to != pr
Patrick Noland
2017/02/24 01:00:40
No, they should always match. There's a longwinded
| |
| 462 | |
| 463 return browser; | |
| 464 } | |
| 465 | |
| 448 ProfileSyncServiceHarness* SyncTest::GetClient(int index) { | 466 ProfileSyncServiceHarness* SyncTest::GetClient(int index) { |
| 449 if (clients_.empty()) | 467 if (clients_.empty()) |
| 450 LOG(FATAL) << "SetupClients() has not yet been called."; | 468 LOG(FATAL) << "SetupClients() has not yet been called."; |
| 451 if (index < 0 || index >= static_cast<int>(clients_.size())) | 469 if (index < 0 || index >= static_cast<int>(clients_.size())) |
| 452 LOG(FATAL) << "GetClient(): Index is out of bounds."; | 470 LOG(FATAL) << "GetClient(): Index is out of bounds."; |
| 453 return clients_[index]; | 471 return clients_[index]; |
| 454 } | 472 } |
| 455 | 473 |
| 456 ProfileSyncService* SyncTest::GetSyncService(int index) { | 474 ProfileSyncService* SyncTest::GetSyncService(int index) { |
| 457 return ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); | 475 return ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 480 bool SyncTest::SetupClients() { | 498 bool SyncTest::SetupClients() { |
| 481 if (num_clients_ <= 0) | 499 if (num_clients_ <= 0) |
| 482 LOG(FATAL) << "num_clients_ incorrectly initialized."; | 500 LOG(FATAL) << "num_clients_ incorrectly initialized."; |
| 483 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) | 501 if (!profiles_.empty() || !browsers_.empty() || !clients_.empty()) |
| 484 LOG(FATAL) << "SetupClients() has already been called."; | 502 LOG(FATAL) << "SetupClients() has already been called."; |
| 485 | 503 |
| 486 // Create the required number of sync profiles, browsers and clients. | 504 // Create the required number of sync profiles, browsers and clients. |
| 487 profiles_.resize(num_clients_); | 505 profiles_.resize(num_clients_); |
| 488 profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier. | 506 profile_delegates_.resize(num_clients_ + 1); // + 1 for the verifier. |
| 489 tmp_profile_paths_.resize(num_clients_); | 507 tmp_profile_paths_.resize(num_clients_); |
| 490 browsers_.resize(num_clients_); | |
| 491 clients_.resize(num_clients_); | 508 clients_.resize(num_clients_); |
| 492 invalidation_forwarders_.resize(num_clients_); | 509 invalidation_forwarders_.resize(num_clients_); |
| 493 sync_refreshers_.resize(num_clients_); | 510 sync_refreshers_.resize(num_clients_); |
| 494 fake_server_invalidation_services_.resize(num_clients_); | 511 fake_server_invalidation_services_.resize(num_clients_); |
| 495 | 512 |
| 496 if (create_gaia_account_at_runtime_) { | 513 if (create_gaia_account_at_runtime_) { |
| 497 CHECK(UsingExternalServers()) << | 514 CHECK(UsingExternalServers()) << |
| 498 "Cannot create Gaia accounts without external authentication servers"; | 515 "Cannot create Gaia accounts without external authentication servers"; |
| 499 if (!CreateGaiaAccount(username_, password_)) | 516 if (!CreateGaiaAccount(username_, password_)) |
| 500 LOG(FATAL) << "Could not create Gaia account."; | 517 LOG(FATAL) << "Could not create Gaia account."; |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 521 // Error cases are all handled by LOG(FATAL) messages. So there is not really | 538 // 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, | 539 // a case that returns false. In case we failed to create a verifier profile, |
| 523 // any call to the verifier() would fail. | 540 // any call to the verifier() would fail. |
| 524 return true; | 541 return true; |
| 525 } | 542 } |
| 526 | 543 |
| 527 void SyncTest::InitializeProfile(int index, Profile* profile) { | 544 void SyncTest::InitializeProfile(int index, Profile* profile) { |
| 528 DCHECK(profile); | 545 DCHECK(profile); |
| 529 profiles_[index] = profile; | 546 profiles_[index] = profile; |
| 530 | 547 |
| 531 // CheckInitialState() assumes that no windows are open at startup. | 548 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 | 549 |
| 537 // Make sure the ProfileSyncService has been created before creating the | 550 // Make sure the ProfileSyncService has been created before creating the |
| 538 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to | 551 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to |
| 539 // already exist. | 552 // already exist. |
| 540 ProfileSyncService* profile_sync_service = | 553 ProfileSyncService* profile_sync_service = |
| 541 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); | 554 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); |
| 542 | 555 |
| 543 if (server_type_ == IN_PROCESS_FAKE_SERVER) { | 556 if (server_type_ == IN_PROCESS_FAKE_SERVER) { |
| 544 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer. | 557 // TODO(pvalenzuela): Run the fake server via EmbeddedTestServer. |
| 545 profile_sync_service->OverrideNetworkResourcesForTest( | 558 profile_sync_service->OverrideNetworkResourcesForTest( |
| (...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1132 | 1145 |
| 1133 void SyncTest::TriggerSyncForModelTypes(int index, | 1146 void SyncTest::TriggerSyncForModelTypes(int index, |
| 1134 syncer::ModelTypeSet model_types) { | 1147 syncer::ModelTypeSet model_types) { |
| 1135 GetSyncService(index)->TriggerRefresh(model_types); | 1148 GetSyncService(index)->TriggerRefresh(model_types); |
| 1136 } | 1149 } |
| 1137 | 1150 |
| 1138 void SyncTest::SetPreexistingPreferencesFileContents( | 1151 void SyncTest::SetPreexistingPreferencesFileContents( |
| 1139 const std::string& contents) { | 1152 const std::string& contents) { |
| 1140 preexisting_preferences_file_contents_ = contents; | 1153 preexisting_preferences_file_contents_ = contents; |
| 1141 } | 1154 } |
| OLD | NEW |