| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 #include "net/base/load_flags.h" | 82 #include "net/base/load_flags.h" |
| 83 #include "net/base/network_change_notifier.h" | 83 #include "net/base/network_change_notifier.h" |
| 84 #include "net/base/port_util.h" | 84 #include "net/base/port_util.h" |
| 85 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" | 85 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 86 #include "net/url_request/test_url_fetcher_factory.h" | 86 #include "net/url_request/test_url_fetcher_factory.h" |
| 87 #include "net/url_request/url_fetcher.h" | 87 #include "net/url_request/url_fetcher.h" |
| 88 #include "net/url_request/url_fetcher_delegate.h" | 88 #include "net/url_request/url_fetcher_delegate.h" |
| 89 #include "url/gurl.h" | 89 #include "url/gurl.h" |
| 90 | 90 |
| 91 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 92 #include "chrome/browser/sync/test/integration/sync_arc_package_helper.h" |
| 93 #include "chrome/browser/ui/app_list/arc/arc_app_list_prefs_factory.h" |
| 92 #include "chromeos/chromeos_switches.h" | 94 #include "chromeos/chromeos_switches.h" |
| 95 #include "components/arc/arc_util.h" |
| 93 #endif | 96 #endif |
| 94 | 97 |
| 95 using browser_sync::ProfileSyncService; | 98 using browser_sync::ProfileSyncService; |
| 96 using content::BrowserThread; | 99 using content::BrowserThread; |
| 97 | 100 |
| 98 namespace switches { | 101 namespace switches { |
| 99 const char kPasswordFileForTest[] = "password-file-for-test"; | 102 const char kPasswordFileForTest[] = "password-file-for-test"; |
| 100 const char kSyncUserForTest[] = "sync-user-for-test"; | 103 const char kSyncUserForTest[] = "sync-user-for-test"; |
| 101 const char kSyncPasswordForTest[] = "sync-password-for-test"; | 104 const char kSyncPasswordForTest[] = "sync-password-for-test"; |
| 102 const char kSyncServerCommandLine[] = "sync-server-command-line"; | 105 const char kSyncServerCommandLine[] = "sync-server-command-line"; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 294 |
| 292 fake_server_.reset(); | 295 fake_server_.reset(); |
| 293 } | 296 } |
| 294 | 297 |
| 295 void SyncTest::SetUpCommandLine(base::CommandLine* cl) { | 298 void SyncTest::SetUpCommandLine(base::CommandLine* cl) { |
| 296 AddTestSwitches(cl); | 299 AddTestSwitches(cl); |
| 297 AddOptionalTypesToCommandLine(cl); | 300 AddOptionalTypesToCommandLine(cl); |
| 298 | 301 |
| 299 #if defined(OS_CHROMEOS) | 302 #if defined(OS_CHROMEOS) |
| 300 cl->AppendSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests); | 303 cl->AppendSwitch(chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 304 arc::SetArcAvailableCommandLineForTesting(cl); |
| 301 #endif | 305 #endif |
| 302 } | 306 } |
| 303 | 307 |
| 304 void SyncTest::AddTestSwitches(base::CommandLine* cl) { | 308 void SyncTest::AddTestSwitches(base::CommandLine* cl) { |
| 305 // Disable non-essential access of external network resources. | 309 // Disable non-essential access of external network resources. |
| 306 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) | 310 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) |
| 307 cl->AppendSwitch(switches::kDisableBackgroundNetworking); | 311 cl->AppendSwitch(switches::kDisableBackgroundNetworking); |
| 308 | 312 |
| 309 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) | 313 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) |
| 310 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); | 314 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 sync_refreshers_.resize(num_clients_); | 510 sync_refreshers_.resize(num_clients_); |
| 507 fake_server_invalidation_services_.resize(num_clients_); | 511 fake_server_invalidation_services_.resize(num_clients_); |
| 508 | 512 |
| 509 if (create_gaia_account_at_runtime_) { | 513 if (create_gaia_account_at_runtime_) { |
| 510 CHECK(UsingExternalServers()) << | 514 CHECK(UsingExternalServers()) << |
| 511 "Cannot create Gaia accounts without external authentication servers"; | 515 "Cannot create Gaia accounts without external authentication servers"; |
| 512 if (!CreateGaiaAccount(username_, password_)) | 516 if (!CreateGaiaAccount(username_, password_)) |
| 513 LOG(FATAL) << "Could not create Gaia account."; | 517 LOG(FATAL) << "Could not create Gaia account."; |
| 514 } | 518 } |
| 515 | 519 |
| 520 #if defined(OS_CHROMEOS) |
| 521 const auto* cl = base::CommandLine::ForCurrentProcess(); |
| 522 // ARC_PACKAGE do not support supervised users, switches::kSupervisedUserId |
| 523 // need to be set in SetUpCommandLine() when a test will use supervise users. |
| 524 if (!cl->HasSwitch(switches::kSupervisedUserId)) { |
| 525 // Sets Arc flags, need to be called before create test profiles. |
| 526 ArcAppListPrefsFactory::SetFactoryForSyncTest(); |
| 527 } |
| 528 #endif |
| 529 |
| 516 for (int i = 0; i < num_clients_; ++i) { | 530 for (int i = 0; i < num_clients_; ++i) { |
| 517 CreateProfile(i); | 531 CreateProfile(i); |
| 518 } | 532 } |
| 519 | 533 |
| 520 // Verifier account is not useful when running against external servers. | 534 // Verifier account is not useful when running against external servers. |
| 521 if (UsingExternalServers()) | 535 if (UsingExternalServers()) |
| 522 DisableVerifier(); | 536 DisableVerifier(); |
| 523 | 537 |
| 524 // Create the verifier profile. | 538 // Create the verifier profile. |
| 525 if (use_verifier_) { | 539 if (use_verifier_) { |
| 526 base::FilePath user_data_dir; | 540 base::FilePath user_data_dir; |
| 527 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 541 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 528 profile_delegates_[num_clients_] = | 542 profile_delegates_[num_clients_] = |
| 529 base::MakeUnique<SyncProfileDelegate>(base::Callback<void(Profile*)>()); | 543 base::MakeUnique<SyncProfileDelegate>(base::Callback<void(Profile*)>()); |
| 530 verifier_ = MakeTestProfile( | 544 verifier_ = MakeTestProfile( |
| 531 user_data_dir.Append(FILE_PATH_LITERAL("Verifier")), num_clients_); | 545 user_data_dir.Append(FILE_PATH_LITERAL("Verifier")), num_clients_); |
| 532 WaitForDataModels(verifier()); | 546 WaitForDataModels(verifier()); |
| 533 } | 547 } |
| 548 |
| 549 #if defined(OS_CHROMEOS) |
| 550 if (ArcAppListPrefsFactory::IsFactorySetForSyncTest()) { |
| 551 // Init SyncArcPackageHelper to ensure that the arc services are initialized |
| 552 // for each Profile, only can be called after test profiles are created. |
| 553 if (!sync_arc_helper()) |
| 554 return false; |
| 555 } |
| 556 #endif |
| 557 |
| 534 // Error cases are all handled by LOG(FATAL) messages. So there is not really | 558 // 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, | 559 // a case that returns false. In case we failed to create a verifier profile, |
| 536 // any call to the verifier() would fail. | 560 // any call to the verifier() would fail. |
| 537 return true; | 561 return true; |
| 538 } | 562 } |
| 539 | 563 |
| 540 void SyncTest::InitializeProfile(int index, Profile* profile) { | 564 void SyncTest::InitializeProfile(int index, Profile* profile) { |
| 541 DCHECK(profile); | 565 DCHECK(profile); |
| 542 profiles_[index] = profile; | 566 profiles_[index] = profile; |
| 543 | 567 |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 | 1190 |
| 1167 fake_server::FakeServer* SyncTest::GetFakeServer() const { | 1191 fake_server::FakeServer* SyncTest::GetFakeServer() const { |
| 1168 return fake_server_.get(); | 1192 return fake_server_.get(); |
| 1169 } | 1193 } |
| 1170 | 1194 |
| 1171 void SyncTest::TriggerSyncForModelTypes(int index, | 1195 void SyncTest::TriggerSyncForModelTypes(int index, |
| 1172 syncer::ModelTypeSet model_types) { | 1196 syncer::ModelTypeSet model_types) { |
| 1173 GetSyncService(index)->TriggerRefresh(model_types); | 1197 GetSyncService(index)->TriggerRefresh(model_types); |
| 1174 } | 1198 } |
| 1175 | 1199 |
| 1200 arc::SyncArcPackageHelper* SyncTest::sync_arc_helper() { |
| 1201 #if defined(OS_CHROMEOS) |
| 1202 return arc::SyncArcPackageHelper::GetInstance(); |
| 1203 #else |
| 1204 return nullptr; |
| 1205 #endif |
| 1206 } |
| 1207 |
| 1176 void SyncTest::SetPreexistingPreferencesFileContents( | 1208 void SyncTest::SetPreexistingPreferencesFileContents( |
| 1177 const std::string& contents) { | 1209 const std::string& contents) { |
| 1178 preexisting_preferences_file_contents_ = contents; | 1210 preexisting_preferences_file_contents_ = contents; |
| 1179 } | 1211 } |
| 1180 | 1212 |
| 1181 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { | 1213 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { |
| 1182 // At this point our birthday is good. | 1214 // At this point our birthday is good. |
| 1183 base::RunLoop run_loop; | 1215 base::RunLoop run_loop; |
| 1184 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); | 1216 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); |
| 1185 run_loop.Run(); | 1217 run_loop.Run(); |
| 1186 | 1218 |
| 1187 // Our birthday is invalidated on the server here so restart sync to get | 1219 // Our birthday is invalidated on the server here so restart sync to get |
| 1188 // the new birthday from the server. | 1220 // the new birthday from the server. |
| 1189 return harness->RestartSyncService(); | 1221 return harness->RestartSyncService(); |
| 1190 } | 1222 } |
| OLD | NEW |