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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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" |
67 #include "components/sync_driver/sync_driver_switches.h" | 68 #include "components/sync_driver/sync_driver_switches.h" |
| 69 #include "content/public/browser/navigation_entry.h" |
68 #include "content/public/browser/notification_service.h" | 70 #include "content/public/browser/notification_service.h" |
69 #include "content/public/browser/web_contents.h" | 71 #include "content/public/browser/web_contents.h" |
70 #include "content/public/test/test_browser_thread.h" | 72 #include "content/public/test/test_browser_thread.h" |
71 #include "google_apis/gaia/gaia_urls.h" | 73 #include "google_apis/gaia/gaia_urls.h" |
72 #include "net/base/escape.h" | 74 #include "net/base/escape.h" |
73 #include "net/base/load_flags.h" | 75 #include "net/base/load_flags.h" |
74 #include "net/base/network_change_notifier.h" | 76 #include "net/base/network_change_notifier.h" |
75 #include "net/base/port_util.h" | 77 #include "net/base/port_util.h" |
76 #include "net/cookies/cookie_monster.h" | 78 #include "net/cookies/cookie_monster.h" |
77 #include "net/test/spawned_test_server/spawned_test_server.h" | 79 #include "net/test/spawned_test_server/spawned_test_server.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 return BuildP2PProfileInvalidationProvider(context, syncer::NOTIFY_OTHERS); | 180 return BuildP2PProfileInvalidationProvider(context, syncer::NOTIFY_OTHERS); |
179 } | 181 } |
180 | 182 |
181 } // namespace | 183 } // namespace |
182 | 184 |
183 SyncTest::SyncTest(TestType test_type) | 185 SyncTest::SyncTest(TestType test_type) |
184 : test_type_(test_type), | 186 : test_type_(test_type), |
185 server_type_(SERVER_TYPE_UNDECIDED), | 187 server_type_(SERVER_TYPE_UNDECIDED), |
186 num_clients_(-1), | 188 num_clients_(-1), |
187 use_verifier_(true), | 189 use_verifier_(true), |
188 notifications_enabled_(true) { | 190 notifications_enabled_(true), |
| 191 create_gaia_account_at_runtime_(false) { |
189 sync_datatype_helper::AssociateWithTest(this); | 192 sync_datatype_helper::AssociateWithTest(this); |
190 switch (test_type_) { | 193 switch (test_type_) { |
191 case SINGLE_CLIENT: | 194 case SINGLE_CLIENT: |
192 case SINGLE_CLIENT_LEGACY: { | 195 case SINGLE_CLIENT_LEGACY: { |
193 num_clients_ = 1; | 196 num_clients_ = 1; |
194 break; | 197 break; |
195 } | 198 } |
196 case TWO_CLIENT: | 199 case TWO_CLIENT: |
197 case TWO_CLIENT_LEGACY: { | 200 case TWO_CLIENT_LEGACY: { |
198 num_clients_ = 2; | 201 num_clients_ = 2; |
199 break; | 202 break; |
200 } | 203 } |
201 case MULTIPLE_CLIENT: { | 204 case MULTIPLE_CLIENT: { |
202 num_clients_ = 3; | 205 num_clients_ = 3; |
203 break; | 206 break; |
204 } | 207 } |
205 } | 208 } |
206 } | 209 } |
207 | 210 |
208 SyncTest::~SyncTest() {} | 211 SyncTest::~SyncTest() {} |
209 | 212 |
210 void SyncTest::SetUp() { | 213 void SyncTest::SetUp() { |
| 214 // Sets |server_type_| if it wasn't specified by the test. |
| 215 DecideServerType(); |
| 216 |
211 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 217 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
212 if (cl->HasSwitch(switches::kPasswordFileForTest)) { | 218 if (cl->HasSwitch(switches::kPasswordFileForTest)) { |
213 ReadPasswordFile(); | 219 ReadPasswordFile(); |
214 } else if (cl->HasSwitch(switches::kSyncUserForTest) && | |
215 cl->HasSwitch(switches::kSyncPasswordForTest)) { | |
216 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); | |
217 password_ = cl->GetSwitchValueASCII(switches::kSyncPasswordForTest); | |
218 } else { | 220 } else { |
219 username_ = "user@gmail.com"; | 221 // Decide on username to use or create one. |
220 password_ = "password"; | 222 if (cl->HasSwitch(switches::kSyncUserForTest)) { |
| 223 username_ = cl->GetSwitchValueASCII(switches::kSyncUserForTest); |
| 224 } else if (UsingExternalServers()) { |
| 225 // We assume the need to automatically create a Gaia account which |
| 226 // requires URL navigation and needs to be done outside SetUp() function. |
| 227 create_gaia_account_at_runtime_ = true; |
| 228 username_ = base::GenerateGUID(); |
| 229 } else { |
| 230 username_ = "user@gmail.com"; |
| 231 } |
| 232 // Decide on password to use. |
| 233 password_ = cl->HasSwitch(switches::kSyncPasswordForTest) |
| 234 ? cl->GetSwitchValueASCII(switches::kSyncPasswordForTest) |
| 235 : "password"; |
221 } | 236 } |
222 | 237 |
223 if (username_.empty() || password_.empty()) | 238 if (username_.empty() || password_.empty()) |
224 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; | 239 LOG(FATAL) << "Cannot run sync tests without GAIA credentials."; |
225 | 240 |
226 // Sets |server_type_| if it wasn't specified by the test. | |
227 DecideServerType(); | |
228 | |
229 // 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. |
230 #if defined(OS_MACOSX) | 242 #if defined(OS_MACOSX) |
231 OSCrypt::UseMockKeychain(true); | 243 OSCrypt::UseMockKeychain(true); |
232 #endif | 244 #endif |
233 | 245 |
234 // 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. |
235 // 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 |
236 // the mock gaia responses to be available before GaiaUrls is initialized. | 248 // the mock gaia responses to be available before GaiaUrls is initialized. |
237 SetUpTestServerIfRequired(); | 249 SetUpTestServerIfRequired(); |
238 | 250 |
(...skipping 30 matching lines...) Expand all Loading... |
269 // Disable non-essential access of external network resources. | 281 // Disable non-essential access of external network resources. |
270 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) | 282 if (!cl->HasSwitch(switches::kDisableBackgroundNetworking)) |
271 cl->AppendSwitch(switches::kDisableBackgroundNetworking); | 283 cl->AppendSwitch(switches::kDisableBackgroundNetworking); |
272 | 284 |
273 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) | 285 if (!cl->HasSwitch(switches::kSyncShortInitialRetryOverride)) |
274 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); | 286 cl->AppendSwitch(switches::kSyncShortInitialRetryOverride); |
275 } | 287 } |
276 | 288 |
277 void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {} | 289 void SyncTest::AddOptionalTypesToCommandLine(base::CommandLine* cl) {} |
278 | 290 |
| 291 bool SyncTest::CreateGaiaAccount(const std::string& username, |
| 292 const std::string& password) { |
| 293 std::string relative_url = base::StringPrintf("/CreateUsers?%s=%s", |
| 294 username.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 = " |
| 305 << entry->GetHttpStatusCode(); |
| 306 return entry->GetHttpStatusCode() == 200; |
| 307 } |
| 308 |
279 // Called when the ProfileManager has created a profile. | 309 // Called when the ProfileManager has created a profile. |
280 // static | 310 // static |
281 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, | 311 void SyncTest::CreateProfileCallback(const base::Closure& quit_closure, |
282 Profile* profile, | 312 Profile* profile, |
283 Profile::CreateStatus status) { | 313 Profile::CreateStatus status) { |
284 EXPECT_TRUE(profile); | 314 EXPECT_TRUE(profile); |
285 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); | 315 EXPECT_NE(Profile::CREATE_STATUS_LOCAL_FAIL, status); |
286 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); | 316 EXPECT_NE(Profile::CREATE_STATUS_REMOTE_FAIL, status); |
287 // 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 |
288 // fully to quit the loop. | 318 // fully to quit the loop. |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 GetInvalidationService()); | 556 GetInvalidationService()); |
527 p2p_invalidation_service->UpdateCredentials(username_, password_); | 557 p2p_invalidation_service->UpdateCredentials(username_, password_); |
528 // Start listening for and emitting notifications of commits. | 558 // Start listening for and emitting notifications of commits. |
529 invalidation_forwarders_[index] = | 559 invalidation_forwarders_[index] = |
530 new P2PInvalidationForwarder(clients_[index]->service(), | 560 new P2PInvalidationForwarder(clients_[index]->service(), |
531 p2p_invalidation_service); | 561 p2p_invalidation_service); |
532 } | 562 } |
533 } | 563 } |
534 | 564 |
535 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 } |
536 // 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. |
537 if (profiles_.empty()) { | 573 if (profiles_.empty()) { |
538 if (!SetupClients()) | 574 if (!SetupClients()) |
539 LOG(FATAL) << "SetupClients() failed."; | 575 LOG(FATAL) << "SetupClients() failed."; |
540 } | 576 } |
541 | 577 |
542 // Sync each of the profiles. | 578 // Sync each of the profiles. |
543 for (int i = 0; i < num_clients_; ++i) { | 579 for (int i = 0; i < num_clients_; ++i) { |
544 if (!GetClient(i)->SetupSync()) | 580 if (!GetClient(i)->SetupSync()) |
545 LOG(FATAL) << "SetupSync() failed."; | 581 LOG(FATAL) << "SetupSync() failed."; |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 content::NotificationService::current()->Notify( | 1098 content::NotificationService::current()->Notify( |
1063 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, | 1099 chrome::NOTIFICATION_SYNC_REFRESH_LOCAL, |
1064 content::Source<Profile>(GetProfile(index)), | 1100 content::Source<Profile>(GetProfile(index)), |
1065 content::Details<const syncer::ModelTypeSet>(&model_types)); | 1101 content::Details<const syncer::ModelTypeSet>(&model_types)); |
1066 } | 1102 } |
1067 | 1103 |
1068 void SyncTest::SetPreexistingPreferencesFileContents( | 1104 void SyncTest::SetPreexistingPreferencesFileContents( |
1069 const std::string& contents) { | 1105 const std::string& contents) { |
1070 preexisting_preferences_file_contents_ = contents; | 1106 preexisting_preferences_file_contents_ = contents; |
1071 } | 1107 } |
OLD | NEW |