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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/guid.h" | |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
14 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
15 #include "base/path_service.h" | 16 #include "base/path_service.h" |
16 #include "base/process/launch.h" | 17 #include "base/process/launch.h" |
17 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "base/synchronization/waitable_event.h" | 22 #include "base/synchronization/waitable_event.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
57 #include "components/invalidation/impl/p2p_invalidation_service.h" | 58 #include "components/invalidation/impl/p2p_invalidation_service.h" |
58 #include "components/invalidation/impl/p2p_invalidator.h" | 59 #include "components/invalidation/impl/p2p_invalidator.h" |
59 #include "components/invalidation/impl/profile_invalidation_provider.h" | 60 #include "components/invalidation/impl/profile_invalidation_provider.h" |
60 #include "components/invalidation/public/invalidation_service.h" | 61 #include "components/invalidation/public/invalidation_service.h" |
61 #include "components/keyed_service/core/keyed_service.h" | 62 #include "components/keyed_service/core/keyed_service.h" |
62 #include "components/os_crypt/os_crypt.h" | 63 #include "components/os_crypt/os_crypt.h" |
63 #include "components/search_engines/template_url_service.h" | 64 #include "components/search_engines/template_url_service.h" |
64 #include "components/signin/core/browser/profile_identity_provider.h" | 65 #include "components/signin/core/browser/profile_identity_provider.h" |
65 #include "components/signin/core/browser/signin_manager.h" | 66 #include "components/signin/core/browser/signin_manager.h" |
66 #include "components/sync_driver/invalidation_helper.h" | 67 #include "components/sync_driver/invalidation_helper.h" |
68 #include "content/public/browser/navigation_entry.h" | |
67 #include "content/public/browser/notification_service.h" | 69 #include "content/public/browser/notification_service.h" |
68 #include "content/public/browser/web_contents.h" | 70 #include "content/public/browser/web_contents.h" |
69 #include "content/public/test/test_browser_thread.h" | 71 #include "content/public/test/test_browser_thread.h" |
70 #include "google_apis/gaia/gaia_urls.h" | 72 #include "google_apis/gaia/gaia_urls.h" |
71 #include "net/base/escape.h" | 73 #include "net/base/escape.h" |
72 #include "net/base/load_flags.h" | 74 #include "net/base/load_flags.h" |
73 #include "net/base/network_change_notifier.h" | 75 #include "net/base/network_change_notifier.h" |
74 #include "net/base/port_util.h" | 76 #include "net/base/port_util.h" |
75 #include "net/cookies/cookie_monster.h" | 77 #include "net/cookies/cookie_monster.h" |
76 #include "net/test/spawned_test_server/spawned_test_server.h" | 78 #include "net/test/spawned_test_server/spawned_test_server.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
200 case MULTIPLE_CLIENT: { | 202 case MULTIPLE_CLIENT: { |
201 num_clients_ = 3; | 203 num_clients_ = 3; |
202 break; | 204 break; |
203 } | 205 } |
204 } | 206 } |
205 } | 207 } |
206 | 208 |
207 SyncTest::~SyncTest() {} | 209 SyncTest::~SyncTest() {} |
208 | 210 |
209 void SyncTest::SetUp() { | 211 void SyncTest::SetUp() { |
212 // Sets |server_type_| if it wasn't specified by the test. | |
213 DecideServerType(); | |
214 | |
210 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 215 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
211 if (cl->HasSwitch(switches::kPasswordFileForTest)) { | 216 if (cl->HasSwitch(switches::kPasswordFileForTest)) { |
212 ReadPasswordFile(); | 217 ReadPasswordFile(); |
213 } else if (cl->HasSwitch(switches::kSyncUserForTest) && | 218 } else if (cl->HasSwitch(switches::kSyncUserForTest) && |
214 cl->HasSwitch(switches::kSyncPasswordForTest)) { | 219 cl->HasSwitch(switches::kSyncPasswordForTest)) { |
215 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); | 220 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
216 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); | 221 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); |
217 } else { | 222 } else if (UsingExternalServers()) { |
223 // If --sync-user-for-test is not provided and we are using external servers | |
224 // then we assume the need to automatically create a Gaia account. | |
225 // Creating a Gaia account requires URL navigation and thus needs to be done | |
226 // outside the SetUp() function. | |
227 create_gaia_account_at_runtime_ = true; | |
228 username_ = base::GenerateGUID(); | |
229 if (cl->HasSwitch(switches::kSyncPasswordForTest)) | |
pval...(no longer on Chromium)
2015/08/26 19:26:33
can we simplify the logic in this method to only s
shadi
2015/09/03 22:17:08
PTAL at new logic.
| |
230 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); | |
231 else | |
232 password_ = "password"; | |
233 }else { | |
pval...(no longer on Chromium)
2015/08/26 19:26:33
space after }
shadi
2015/09/03 22:17:08
Done.
| |
218 username_ = "user@gmail.com"; | 234 username_ = "user@gmail.com"; |
219 password_ = "password"; | 235 password_ = "password"; |
220 } | 236 } |
221 | 237 |
222 if (username_.empty() || password_.empty()) | 238 if (username_.empty() || password_.empty()) |
223 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; | 239 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; |
224 | 240 |
225 // Sets |server_type_| if it wasn't specified by the test. | |
226 DecideServerType(); | |
227 | |
228 // Mock the Mac Keychain service. The real Keychain can block on user input. | 241 // Mock the Mac Keychain service. The real Keychain can block on user input. |
229 #if defined(OS_MACOSX) | 242 #if defined(OS_MACOSX) |
230 OSCrypt::UseMockKeychain(true); | 243 OSCrypt::UseMockKeychain(true); |
231 #endif | 244 #endif |
232 | 245 |
233 // Start up a sync test server if one is needed and setup mock gaia responses. | 246 // Start up a sync test server if one is needed and setup mock gaia responses. |
234 // Note: This must be done prior to the call to SetupClients() because we want | 247 // Note: This must be done prior to the call to SetupClients() because we want |
235 // the mock gaia responses to be available before GaiaUrls is initialized. | 248 // the mock gaia responses to be available before GaiaUrls is initialized. |
236 SetUpTestServerIfRequired(); | 249 SetUpTestServerIfRequired(); |
237 | 250 |
(...skipping 30 matching lines...) Expand all Loading... | |
268 // Disable non-essential access of external network resources. | 281 // Disable non-essential access of external network resources. |
269 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) | 282 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) |
270 cl->AppendSwitch(switches::kDisableBackgroundNetworking); | 283 cl->AppendSwitch(switches::kDisableBackgroundNetworking); |
271 | 284 |
272 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) | 285 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) |
273 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); | 286 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); |
274 } | 287 } |
275 | 288 |
276 void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {} | 289 void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {} |
277 | 290 |
291 bool SyncTest::CreateGaiaAccount(const std::string& user_name, | |
292 const std::string& password) { | |
293 std::string relative_url = base::StringPrintf("/CreateUsers?%s=%s", | |
294 user_name.c_str(), | |
295 password.c_str()); | |
296 GURL create_user_url = | |
297 GaiaUrls::GetInstance()->gaia_url().Resolve(relative_url); | |
298 // NavigateToURL blocks until the navigation finishes. | |
299 ui_test_utils::NavigateToURL(browser(), create_user_url); | |
300 content::WebContents* contents = | |
301 browser()->tab_strip_model()->GetActiveWebContents(); | |
302 content::NavigationEntry* entry = contents->GetController().GetVisibleEntry(); | |
303 CHECK(entry) << "Could not get a hold on NavigationEntry post URL navigate."; | |
304 DVLOG(1) << "Create Gaia account request return code = " << | |
pval...(no longer on Chromium)
2015/08/26 19:26:33
i believe the trailing << here should be on the ne
shadi
2015/09/03 22:17:08
Done.
| |
305 entry->GetHttpStatusCode(); | |
306 return entry->GetHttpStatusCode() == 200; | |
307 } | |
308 | |
278 // Called when the ProfileManager has created a profile. | 309 // Called when the ProfileManager has created a profile. |
279 // static | 310 // static |
280 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, | 311 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, |
281 Profile* profile, | 312 Profile* profile, |
282 Profile::CreateStatus status) { | 313 Profile::CreateStatus status) { |
283 EXPECT_TRUE(profile); | 314 EXPECT_TRUE(profile); |
284 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); | 315 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); |
285 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); | 316 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); |
286 // This will be called multiple times. Wait until the profile is initialized | 317 // This will be called multiple times. Wait until the profile is initialized |
287 // fully to quit the loop. | 318 // fully to quit the loop. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
525 GetInvalidationService()); | 556 GetInvalidationService()); |
526 p2p_invalidation_service->UpdateCredentials(username_, password_); | 557 p2p_invalidation_service->UpdateCredentials(username_, password_); |
527 // Start listening for and emitting notifications of commits. | 558 // Start listening for and emitting notifications of commits. |
528 invalidation_forwarders_[index] = | 559 invalidation_forwarders_[index] = |
529 new P2PInvalidationForwarder(clients_[index]->service(), | 560 new P2PInvalidationForwarder(clients_[index]->service(), |
530 p2p_invalidation_service); | 561 p2p_invalidation_service); |
531 } | 562 } |
532 } | 563 } |
533 | 564 |
534 bool SyncTest::SetupSync() { | 565 bool SyncTest::SetupSync() { |
566 if (create_gaia_account_at_runtime_) { | |
567 CHECK(UsingExternalServers()) << | |
568 "Cannot create Gaia accounts without external authentication servers"; | |
569 if (!CreateGaiaAccount(username_, password_)) | |
570 LOG(FATAL) << "Could not create Gaia account."; | |
571 } | |
535 // Create sync profiles and clients if they haven't already been created. | 572 // Create sync profiles and clients if they haven't already been created. |
536 if (profiles_.empty()) { | 573 if (profiles_.empty()) { |
537 if (!SetupClients()) | 574 if (!SetupClients()) |
538 LOG(FATAL) << "SetupClients() failed."; | 575 LOG(FATAL) << "SetupClients() failed."; |
539 } | 576 } |
540 | 577 |
541 // Sync each of the profiles. | 578 // Sync each of the profiles. |
542 for (int i = 0; i < num_clients_; ++i) { | 579 for (int i = 0; i < num_clients_; ++i) { |
543 if (!GetClient(i)->SetupSync()) | 580 if (!GetClient(i)->SetupSync()) |
544 LOG(FATAL) << "SetupSync() failed."; | 581 LOG(FATAL) << "SetupSync() failed."; |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1061 content::NotificationService::current()->Notify( | 1098 content::NotificationService::current()->Notify( |
1062 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 1099 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
1063 content::Source<Profile>(GetProfile(index)), | 1100 content::Source<Profile>(GetProfile(index)), |
1064 content::Details<const syncer::ModelTypeSet>(&model_types)); | 1101 content::Details<const syncer::ModelTypeSet>(&model_types)); |
1065 } | 1102 } |
1066 | 1103 |
1067 void SyncTest::SetPreexistingPreferencesFileContents( | 1104 void SyncTest::SetPreexistingPreferencesFileContents( |
1068 const std::string& contents) { | 1105 const std::string& contents) { |
1069 preexisting_preferences_file_contents_ = contents; | 1106 preexisting_preferences_file_contents_ = contents; |
1070 } | 1107 } |
OLD | NEW |