| 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/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
| 16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/test/test_timeouts.h" | 17 #include "base/test/test_timeouts.h" |
| 18 #include "base/threading/platform_thread.h" | 18 #include "base/threading/platform_thread.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 21 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 22 #include "chrome/browser/google/google_url_tracker.h" | 22 #include "chrome/browser/google/google_url_tracker.h" |
| 23 #include "chrome/browser/history/history_service_factory.h" | 23 #include "chrome/browser/history/history_service_factory.h" |
| 24 #include "chrome/browser/invalidation_service_factory.h" |
| 24 #include "chrome/browser/lifetime/application_lifetime.h" | 25 #include "chrome/browser/lifetime/application_lifetime.h" |
| 26 #include "chrome/browser/p2p_invalidation_service.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/profiles/profile_manager.h" | 28 #include "chrome/browser/profiles/profile_manager.h" |
| 27 #include "chrome/browser/search_engines/template_url_service.h" | 29 #include "chrome/browser/search_engines/template_url_service.h" |
| 28 #include "chrome/browser/search_engines/template_url_service_factory.h" | 30 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 29 #include "chrome/browser/sync/profile_sync_service_factory.h" | 31 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 30 #include "chrome/browser/sync/profile_sync_service_harness.h" | 32 #include "chrome/browser/sync/profile_sync_service_harness.h" |
| 31 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 33 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 32 #include "chrome/browser/ui/browser.h" | 34 #include "chrome/browser/ui/browser.h" |
| 33 #include "chrome/browser/ui/browser_finder.h" | 35 #include "chrome/browser/ui/browser_finder.h" |
| 34 #include "chrome/browser/ui/host_desktop.h" | 36 #include "chrome/browser/ui/host_desktop.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 profiles_[index] = MakeProfile( | 303 profiles_[index] = MakeProfile( |
| 302 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), index)); | 304 base::StringPrintf(FILE_PATH_LITERAL("Profile%d"), index)); |
| 303 EXPECT_FALSE(GetProfile(index) == NULL) << "Could not create Profile " | 305 EXPECT_FALSE(GetProfile(index) == NULL) << "Could not create Profile " |
| 304 << index << "."; | 306 << index << "."; |
| 305 | 307 |
| 306 browsers_[index] = new Browser(Browser::CreateParams( | 308 browsers_[index] = new Browser(Browser::CreateParams( |
| 307 GetProfile(index), chrome::HOST_DESKTOP_TYPE_NATIVE)); | 309 GetProfile(index), chrome::HOST_DESKTOP_TYPE_NATIVE)); |
| 308 EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser " | 310 EXPECT_FALSE(GetBrowser(index) == NULL) << "Could not create Browser " |
| 309 << index << "."; | 311 << index << "."; |
| 310 | 312 |
| 313 P2PInvalidationService* p2p_invalidation_service = |
| 314 static_cast<P2PInvalidationService*>( |
| 315 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse( |
| 316 GetProfile(index), |
| 317 InvalidationServiceFactory::BuildP2PInvalidationServiceFor)); |
| 318 p2p_invalidation_service->UpdateCredentials(username_, password_); |
| 319 |
| 311 // Make sure the ProfileSyncService has been created before creating the | 320 // Make sure the ProfileSyncService has been created before creating the |
| 312 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to | 321 // ProfileSyncServiceHarness - some tests expect the ProfileSyncService to |
| 313 // already exist. | 322 // already exist. |
| 314 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); | 323 ProfileSyncServiceFactory::GetForProfile(GetProfile(index)); |
| 315 | 324 |
| 316 clients_[index] = new ProfileSyncServiceHarness(GetProfile(index), | 325 clients_[index] = new ProfileSyncServiceHarness(GetProfile(index), |
| 326 p2p_invalidation_service, |
| 317 username_, | 327 username_, |
| 318 password_); | 328 password_); |
| 319 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " | 329 EXPECT_FALSE(GetClient(index) == NULL) << "Could not create Client " |
| 320 << index << "."; | 330 << index << "."; |
| 321 | 331 |
| 322 ui_test_utils::WaitForBookmarkModelToLoad( | 332 ui_test_utils::WaitForBookmarkModelToLoad( |
| 323 BookmarkModelFactory::GetForProfile(GetProfile(index))); | 333 BookmarkModelFactory::GetForProfile(GetProfile(index))); |
| 324 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( | 334 ui_test_utils::WaitForHistoryToLoad(HistoryServiceFactory::GetForProfile( |
| 325 GetProfile(index), Profile::EXPLICIT_ACCESS)); | 335 GetProfile(index), Profile::EXPLICIT_ACCESS)); |
| 326 ui_test_utils::WaitForTemplateURLServiceToLoad( | 336 ui_test_utils::WaitForTemplateURLServiceToLoad( |
| 327 TemplateURLServiceFactory::GetForProfile(GetProfile(index))); | 337 TemplateURLServiceFactory::GetForProfile(GetProfile(index))); |
| 328 } | 338 } |
| 329 | 339 |
| 330 void SyncTest::RestartSyncService(int index) { | |
| 331 DVLOG(1) << "Restarting profile sync service for profile " << index << "."; | |
| 332 delete clients_[index]; | |
| 333 Profile* profile = GetProfile(index); | |
| 334 ProfileSyncService* service = | |
| 335 ProfileSyncServiceFactory::GetForProfile(profile); | |
| 336 service->ResetForTest(); | |
| 337 clients_[index] = new ProfileSyncServiceHarness(profile, | |
| 338 username_, | |
| 339 password_); | |
| 340 service->Initialize(); | |
| 341 GetClient(index)->AwaitSyncRestart(); | |
| 342 } | |
| 343 | |
| 344 bool SyncTest::SetupSync() { | 340 bool SyncTest::SetupSync() { |
| 345 // Create sync profiles and clients if they haven't already been created. | 341 // Create sync profiles and clients if they haven't already been created. |
| 346 if (profiles_.empty()) { | 342 if (profiles_.empty()) { |
| 347 if (!SetupClients()) | 343 if (!SetupClients()) |
| 348 LOG(FATAL) << "SetupClients() failed."; | 344 LOG(FATAL) << "SetupClients() failed."; |
| 349 } | 345 } |
| 350 | 346 |
| 351 // Sync each of the profiles. | 347 // Sync each of the profiles. |
| 352 for (int i = 0; i < num_clients_; ++i) { | 348 for (int i = 0; i < num_clients_; ++i) { |
| 353 if (!GetClient(i)->SetupSync()) | 349 if (!GetClient(i)->SetupSync()) |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 | 842 |
| 847 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, | 843 void SyncTest::SetProxyConfig(net::URLRequestContextGetter* context_getter, |
| 848 const net::ProxyConfig& proxy_config) { | 844 const net::ProxyConfig& proxy_config) { |
| 849 base::WaitableEvent done(false, false); | 845 base::WaitableEvent done(false, false); |
| 850 BrowserThread::PostTask( | 846 BrowserThread::PostTask( |
| 851 BrowserThread::IO, FROM_HERE, | 847 BrowserThread::IO, FROM_HERE, |
| 852 base::Bind(&SetProxyConfigCallback, &done, | 848 base::Bind(&SetProxyConfigCallback, &done, |
| 853 make_scoped_refptr(context_getter), proxy_config)); | 849 make_scoped_refptr(context_getter), proxy_config)); |
| 854 done.Wait(); | 850 done.Wait(); |
| 855 } | 851 } |
| OLD | NEW |