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)) | |
skym
2017/03/17 19:51:17
can you add a { } here, the comment makes this wei
Gang Wu
2017/03/17 20:00:29
Done.
| |
525 // Sets Arc flags, need to be called before create test profiles. | |
526 ArcAppListPrefsFactory::SetFactoryForSyncTest(); | |
527 #endif | |
528 | |
516 for (int i = 0; i < num_clients_; ++i) { | 529 for (int i = 0; i < num_clients_; ++i) { |
517 CreateProfile(i); | 530 CreateProfile(i); |
518 } | 531 } |
519 | 532 |
520 // Verifier account is not useful when running against external servers. | 533 // Verifier account is not useful when running against external servers. |
521 if (UsingExternalServers()) | 534 if (UsingExternalServers()) |
522 DisableVerifier(); | 535 DisableVerifier(); |
523 | 536 |
524 // Create the verifier profile. | 537 // Create the verifier profile. |
525 if (use_verifier_) { | 538 if (use_verifier_) { |
526 base::FilePath user_data_dir; | 539 base::FilePath user_data_dir; |
527 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 540 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
528 profile_delegates_[num_clients_] = | 541 profile_delegates_[num_clients_] = |
529 base::MakeUnique<SyncProfileDelegate>(base::Callback<void(Profile*)>()); | 542 base::MakeUnique<SyncProfileDelegate>(base::Callback<void(Profile*)>()); |
530 verifier_ = MakeTestProfile( | 543 verifier_ = MakeTestProfile( |
531 user_data_dir.Append(FILE_PATH_LITERAL("Verifier")), num_clients_); | 544 user_data_dir.Append(FILE_PATH_LITERAL("Verifier")), num_clients_); |
532 WaitForDataModels(verifier()); | 545 WaitForDataModels(verifier()); |
533 } | 546 } |
547 | |
548 #if defined(OS_CHROMEOS) | |
549 if (ArcAppListPrefsFactory::IsFactorySetForSyncTest()) { | |
550 // Init SyncArcPackageHelper to ensure that the arc services are initialized | |
551 // for each Profile, only can be called after test profiles are created. | |
552 if (!sync_arc_helper()) | |
553 return false; | |
554 } | |
555 #endif | |
556 | |
534 // Error cases are all handled by LOG(FATAL) messages. So there is not really | 557 // 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, | 558 // a case that returns false. In case we failed to create a verifier profile, |
536 // any call to the verifier() would fail. | 559 // any call to the verifier() would fail. |
537 return true; | 560 return true; |
538 } | 561 } |
539 | 562 |
540 void SyncTest::InitializeProfile(int index, Profile* profile) { | 563 void SyncTest::InitializeProfile(int index, Profile* profile) { |
541 DCHECK(profile); | 564 DCHECK(profile); |
542 profiles_[index] = profile; | 565 profiles_[index] = profile; |
543 | 566 |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1166 | 1189 |
1167 fake_server::FakeServer* SyncTest::GetFakeServer() const { | 1190 fake_server::FakeServer* SyncTest::GetFakeServer() const { |
1168 return fake_server_.get(); | 1191 return fake_server_.get(); |
1169 } | 1192 } |
1170 | 1193 |
1171 void SyncTest::TriggerSyncForModelTypes(int index, | 1194 void SyncTest::TriggerSyncForModelTypes(int index, |
1172 syncer::ModelTypeSet model_types) { | 1195 syncer::ModelTypeSet model_types) { |
1173 GetSyncService(index)->TriggerRefresh(model_types); | 1196 GetSyncService(index)->TriggerRefresh(model_types); |
1174 } | 1197 } |
1175 | 1198 |
1199 arc::SyncArcPackageHelper* SyncTest::sync_arc_helper() { | |
1200 #if defined(OS_CHROMEOS) | |
1201 return arc::SyncArcPackageHelper::GetInstance(); | |
1202 #else | |
1203 return nullptr; | |
1204 #endif | |
1205 } | |
1206 | |
1176 void SyncTest::SetPreexistingPreferencesFileContents( | 1207 void SyncTest::SetPreexistingPreferencesFileContents( |
1177 const std::string& contents) { | 1208 const std::string& contents) { |
1178 preexisting_preferences_file_contents_ = contents; | 1209 preexisting_preferences_file_contents_ = contents; |
1179 } | 1210 } |
1180 | 1211 |
1181 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { | 1212 bool SyncTest::ClearServerData(ProfileSyncServiceHarness* harness) { |
1182 // At this point our birthday is good. | 1213 // At this point our birthday is good. |
1183 base::RunLoop run_loop; | 1214 base::RunLoop run_loop; |
1184 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); | 1215 harness->service()->ClearServerDataForTest(run_loop.QuitClosure()); |
1185 run_loop.Run(); | 1216 run_loop.Run(); |
1186 | 1217 |
1187 // Our birthday is invalidated on the server here so restart sync to get | 1218 // Our birthday is invalidated on the server here so restart sync to get |
1188 // the new birthday from the server. | 1219 // the new birthday from the server. |
1189 return harness->RestartSyncService(); | 1220 return harness->RestartSyncService(); |
1190 } | 1221 } |
OLD | NEW |