| 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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/process/launch.h" | 15 #include "base/process/launch.h" |
| 16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/synchronization/waitable_event.h" | 19 #include "base/synchronization/waitable_event.h" |
| 20 #include "base/test/test_timeouts.h" | 20 #include "base/test/test_timeouts.h" |
| 21 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
| 22 #include "base/values.h" | 22 #include "base/values.h" |
| 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 23 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
| 24 #include "chrome/browser/history/history_service_factory.h" | 24 #include "chrome/browser/history/history_service_factory.h" |
| 25 #include "chrome/browser/invalidation/invalidation_service_factory.h" | 25 #include "chrome/browser/invalidation/profile_invalidation_provider.h" |
| 26 #include "chrome/browser/invalidation/profile_invalidation_provider_factory.h" |
| 26 #include "chrome/browser/lifetime/application_lifetime.h" | 27 #include "chrome/browser/lifetime/application_lifetime.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/profiles/profile_manager.h" | 29 #include "chrome/browser/profiles/profile_manager.h" |
| 29 #include "chrome/browser/search_engines/template_url_service.h" | 30 #include "chrome/browser/search_engines/template_url_service.h" |
| 30 #include "chrome/browser/search_engines/template_url_service_factory.h" | 31 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 31 #include "chrome/browser/signin/profile_identity_provider.h" | 32 #include "chrome/browser/signin/profile_identity_provider.h" |
| 32 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 33 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 33 #include "chrome/browser/signin/signin_manager_factory.h" | 34 #include "chrome/browser/signin/signin_manager_factory.h" |
| 34 #include "chrome/browser/sync/profile_sync_service.h" | 35 #include "chrome/browser/sync/profile_sync_service.h" |
| 35 #include "chrome/browser/sync/profile_sync_service_factory.h" | 36 #include "chrome/browser/sync/profile_sync_service_factory.h" |
| 36 #include "chrome/browser/sync/test/integration/fake_server_invalidation_service.
h" | 37 #include "chrome/browser/sync/test/integration/fake_server_invalidation_service.
h" |
| 37 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h" | 38 #include "chrome/browser/sync/test/integration/p2p_invalidation_forwarder.h" |
| 38 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" | 39 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| 39 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" | 40 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
| 40 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" | 41 #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| 41 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 42 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
| 42 #include "chrome/browser/ui/browser.h" | 43 #include "chrome/browser/ui/browser.h" |
| 43 #include "chrome/browser/ui/browser_finder.h" | 44 #include "chrome/browser/ui/browser_finder.h" |
| 44 #include "chrome/browser/ui/host_desktop.h" | 45 #include "chrome/browser/ui/host_desktop.h" |
| 45 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 46 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 46 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" | 47 #include "chrome/browser/ui/webui/signin/login_ui_service_factory.h" |
| 47 #include "chrome/common/chrome_paths.h" | 48 #include "chrome/common/chrome_paths.h" |
| 48 #include "chrome/common/chrome_switches.h" | 49 #include "chrome/common/chrome_switches.h" |
| 49 #include "chrome/test/base/testing_browser_process.h" | 50 #include "chrome/test/base/testing_browser_process.h" |
| 50 #include "chrome/test/base/ui_test_utils.h" | 51 #include "chrome/test/base/ui_test_utils.h" |
| 51 #include "components/bookmarks/test/bookmark_test_helpers.h" | 52 #include "components/bookmarks/test/bookmark_test_helpers.h" |
| 52 #include "components/google/core/browser/google_url_tracker.h" | 53 #include "components/google/core/browser/google_url_tracker.h" |
| 54 #include "components/invalidation/invalidation_service.h" |
| 53 #include "components/invalidation/invalidation_switches.h" | 55 #include "components/invalidation/invalidation_switches.h" |
| 54 #include "components/invalidation/p2p_invalidation_service.h" | 56 #include "components/invalidation/p2p_invalidation_service.h" |
| 55 #include "components/invalidation/p2p_invalidator.h" | 57 #include "components/invalidation/p2p_invalidator.h" |
| 58 #include "components/keyed_service/core/keyed_service.h" |
| 56 #include "components/os_crypt/os_crypt.h" | 59 #include "components/os_crypt/os_crypt.h" |
| 57 #include "components/signin/core/browser/signin_manager.h" | 60 #include "components/signin/core/browser/signin_manager.h" |
| 58 #include "content/public/browser/web_contents.h" | 61 #include "content/public/browser/web_contents.h" |
| 59 #include "content/public/test/test_browser_thread.h" | 62 #include "content/public/test/test_browser_thread.h" |
| 60 #include "google_apis/gaia/gaia_urls.h" | 63 #include "google_apis/gaia/gaia_urls.h" |
| 61 #include "net/base/escape.h" | 64 #include "net/base/escape.h" |
| 62 #include "net/base/load_flags.h" | 65 #include "net/base/load_flags.h" |
| 63 #include "net/base/network_change_notifier.h" | 66 #include "net/base/network_change_notifier.h" |
| 64 #include "net/proxy/proxy_config.h" | 67 #include "net/proxy/proxy_config.h" |
| 65 #include "net/proxy/proxy_config_service_fixed.h" | 68 #include "net/proxy/proxy_config_service_fixed.h" |
| 66 #include "net/proxy/proxy_service.h" | 69 #include "net/proxy/proxy_service.h" |
| 67 #include "net/test/spawned_test_server/spawned_test_server.h" | 70 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 68 #include "net/url_request/test_url_fetcher_factory.h" | 71 #include "net/url_request/test_url_fetcher_factory.h" |
| 69 #include "net/url_request/url_fetcher.h" | 72 #include "net/url_request/url_fetcher.h" |
| 70 #include "net/url_request/url_fetcher_delegate.h" | 73 #include "net/url_request/url_fetcher_delegate.h" |
| 71 #include "net/url_request/url_request_context.h" | 74 #include "net/url_request/url_request_context.h" |
| 72 #include "net/url_request/url_request_context_getter.h" | 75 #include "net/url_request/url_request_context_getter.h" |
| 73 #include "sync/engine/sync_scheduler_impl.h" | 76 #include "sync/engine/sync_scheduler_impl.h" |
| 74 #include "sync/protocol/sync.pb.h" | 77 #include "sync/protocol/sync.pb.h" |
| 75 #include "sync/test/fake_server/fake_server.h" | 78 #include "sync/test/fake_server/fake_server.h" |
| 76 #include "sync/test/fake_server/fake_server_network_resources.h" | 79 #include "sync/test/fake_server/fake_server_network_resources.h" |
| 77 #include "url/gurl.h" | 80 #include "url/gurl.h" |
| 78 | 81 |
| 79 #if defined(OS_CHROMEOS) | 82 #if defined(OS_CHROMEOS) |
| 80 #include "chromeos/chromeos_switches.h" | 83 #include "chromeos/chromeos_switches.h" |
| 81 #endif | 84 #endif |
| 82 | 85 |
| 83 using content::BrowserThread; | 86 using content::BrowserThread; |
| 84 using invalidation::InvalidationServiceFactory; | |
| 85 | 87 |
| 86 namespace switches { | 88 namespace switches { |
| 87 const char kPasswordFileForTest[] = "password-file-for-test"; | 89 const char kPasswordFileForTest[] = "password-file-for-test"; |
| 88 const char kSyncUserForTest[] = "sync-user-for-test"; | 90 const char kSyncUserForTest[] = "sync-user-for-test"; |
| 89 const char kSyncPasswordForTest[] = "sync-password-for-test"; | 91 const char kSyncPasswordForTest[] = "sync-password-for-test"; |
| 90 const char kSyncServerCommandLine[] = "sync-server-command-line"; | 92 const char kSyncServerCommandLine[] = "sync-server-command-line"; |
| 91 } | 93 } |
| 92 | 94 |
| 93 namespace { | 95 namespace { |
| 94 | 96 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 base::WaitableEvent* done, | 137 base::WaitableEvent* done, |
| 136 net::URLRequestContextGetter* url_request_context_getter, | 138 net::URLRequestContextGetter* url_request_context_getter, |
| 137 const net::ProxyConfig& proxy_config) { | 139 const net::ProxyConfig& proxy_config) { |
| 138 net::ProxyService* proxy_service = | 140 net::ProxyService* proxy_service = |
| 139 url_request_context_getter->GetURLRequestContext()->proxy_service(); | 141 url_request_context_getter->GetURLRequestContext()->proxy_service(); |
| 140 proxy_service->ResetConfigService( | 142 proxy_service->ResetConfigService( |
| 141 new net::ProxyConfigServiceFixed(proxy_config)); | 143 new net::ProxyConfigServiceFixed(proxy_config)); |
| 142 done->Signal(); | 144 done->Signal(); |
| 143 } | 145 } |
| 144 | 146 |
| 145 KeyedService* BuildP2PInvalidationService( | 147 KeyedService* BuildFakeServerProfileInvalidationProvider( |
| 148 content::BrowserContext* context) { |
| 149 return new invalidation::ProfileInvalidationProvider( |
| 150 scoped_ptr<invalidation::InvalidationService>( |
| 151 new fake_server::FakeServerInvalidationService)); |
| 152 } |
| 153 |
| 154 KeyedService* BuildP2PProfileInvalidationProvider( |
| 146 content::BrowserContext* context, | 155 content::BrowserContext* context, |
| 147 syncer::P2PNotificationTarget notification_target) { | 156 syncer::P2PNotificationTarget notification_target) { |
| 148 Profile* profile = static_cast<Profile*>(context); | 157 Profile* profile = static_cast<Profile*>(context); |
| 149 return new invalidation::P2PInvalidationService( | 158 return new invalidation::ProfileInvalidationProvider( |
| 150 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( | 159 scoped_ptr<invalidation::InvalidationService>( |
| 151 SigninManagerFactory::GetForProfile(profile), | 160 new invalidation::P2PInvalidationService( |
| 152 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 161 scoped_ptr<IdentityProvider>(new ProfileIdentityProvider( |
| 153 LoginUIServiceFactory::GetForProfile(profile))), | 162 SigninManagerFactory::GetForProfile(profile), |
| 154 profile->GetRequestContext(), | 163 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 155 notification_target); | 164 LoginUIServiceFactory::GetForProfile(profile))), |
| 165 profile->GetRequestContext(), |
| 166 notification_target))); |
| 156 } | 167 } |
| 157 | 168 |
| 158 KeyedService* BuildSelfNotifyingP2PInvalidationService( | 169 KeyedService* BuildSelfNotifyingP2PProfileInvalidationProvider( |
| 159 content::BrowserContext* context) { | 170 content::BrowserContext* context) { |
| 160 return BuildP2PInvalidationService(context, syncer::NOTIFY_ALL); | 171 return BuildP2PProfileInvalidationProvider(context, syncer::NOTIFY_ALL); |
| 161 } | 172 } |
| 162 | 173 |
| 163 KeyedService* BuildRealisticP2PInvalidationService( | 174 KeyedService* BuildRealisticP2PProfileInvalidationProvider( |
| 164 content::BrowserContext* context) { | 175 content::BrowserContext* context) { |
| 165 return BuildP2PInvalidationService(context, syncer::NOTIFY_OTHERS); | 176 return BuildP2PProfileInvalidationProvider(context, syncer::NOTIFY_OTHERS); |
| 166 } | 177 } |
| 167 | 178 |
| 168 } // namespace | 179 } // namespace |
| 169 | 180 |
| 170 SyncTest::SyncTest(TestType test_type) | 181 SyncTest::SyncTest(TestType test_type) |
| 171 : test_type_(test_type), | 182 : test_type_(test_type), |
| 172 server_type_(SERVER_TYPE_UNDECIDED), | 183 server_type_(SERVER_TYPE_UNDECIDED), |
| 173 num_clients_(-1), | 184 num_clients_(-1), |
| 174 use_verifier_(true), | 185 use_verifier_(true), |
| 175 notifications_enabled_(true), | 186 notifications_enabled_(true), |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 GetProfile(index), Profile::EXPLICIT_ACCESS)); | 405 GetProfile(index), Profile::EXPLICIT_ACCESS)); |
| 395 ui_test_utils::WaitForTemplateURLServiceToLoad( | 406 ui_test_utils::WaitForTemplateURLServiceToLoad( |
| 396 TemplateURLServiceFactory::GetForProfile(GetProfile(index))); | 407 TemplateURLServiceFactory::GetForProfile(GetProfile(index))); |
| 397 } | 408 } |
| 398 | 409 |
| 399 void SyncTest::InitializeInvalidations(int index) { | 410 void SyncTest::InitializeInvalidations(int index) { |
| 400 if (server_type_ == IN_PROCESS_FAKE_SERVER) { | 411 if (server_type_ == IN_PROCESS_FAKE_SERVER) { |
| 401 CHECK(fake_server_.get()); | 412 CHECK(fake_server_.get()); |
| 402 fake_server::FakeServerInvalidationService* invalidation_service = | 413 fake_server::FakeServerInvalidationService* invalidation_service = |
| 403 static_cast<fake_server::FakeServerInvalidationService*>( | 414 static_cast<fake_server::FakeServerInvalidationService*>( |
| 404 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 415 static_cast<invalidation::ProfileInvalidationProvider*>( |
| 405 GetProfile(index), | 416 invalidation::ProfileInvalidationProviderFactory:: |
| 406 fake_server::FakeServerInvalidationService::Build)); | 417 GetInstance()->SetTestingFactoryAndUse( |
| 418 GetProfile(index), |
| 419 BuildFakeServerProfileInvalidationProvider))-> |
| 420 GetInvalidationService()); |
| 407 fake_server_->AddObserver(invalidation_service); | 421 fake_server_->AddObserver(invalidation_service); |
| 408 if (TestUsesSelfNotifications()) { | 422 if (TestUsesSelfNotifications()) { |
| 409 invalidation_service->EnableSelfNotifications(); | 423 invalidation_service->EnableSelfNotifications(); |
| 410 } else { | 424 } else { |
| 411 invalidation_service->DisableSelfNotifications(); | 425 invalidation_service->DisableSelfNotifications(); |
| 412 } | 426 } |
| 413 fake_server_invalidation_services_[index] = invalidation_service; | 427 fake_server_invalidation_services_[index] = invalidation_service; |
| 414 } else { | 428 } else { |
| 415 invalidation::P2PInvalidationService* p2p_invalidation_service = | 429 invalidation::P2PInvalidationService* p2p_invalidation_service = |
| 416 static_cast<invalidation::P2PInvalidationService*>( | 430 static_cast<invalidation::P2PInvalidationService*>( |
| 417 InvalidationServiceFactory::GetInstance()->SetTestingFactoryAndUse( | 431 static_cast<invalidation::ProfileInvalidationProvider*>( |
| 418 GetProfile(index), | 432 invalidation::ProfileInvalidationProviderFactory:: |
| 419 TestUsesSelfNotifications() ? | 433 GetInstance()->SetTestingFactoryAndUse( |
| 420 BuildSelfNotifyingP2PInvalidationService | 434 GetProfile(index), |
| 421 : BuildRealisticP2PInvalidationService)); | 435 TestUsesSelfNotifications() ? |
| 436 BuildSelfNotifyingP2PProfileInvalidationProvider : |
| 437 BuildRealisticP2PProfileInvalidationProvider))-> |
| 438 GetInvalidationService()); |
| 422 p2p_invalidation_service->UpdateCredentials(username_, password_); | 439 p2p_invalidation_service->UpdateCredentials(username_, password_); |
| 423 // Start listening for and emitting notifications of commits. | 440 // Start listening for and emitting notifications of commits. |
| 424 invalidation_forwarders_[index] = | 441 invalidation_forwarders_[index] = |
| 425 new P2PInvalidationForwarder(clients_[index]->service(), | 442 new P2PInvalidationForwarder(clients_[index]->service(), |
| 426 p2p_invalidation_service); | 443 p2p_invalidation_service); |
| 427 } | 444 } |
| 428 } | 445 } |
| 429 | 446 |
| 430 bool SyncTest::SetupSync() { | 447 bool SyncTest::SetupSync() { |
| 431 // Create sync profiles and clients if they haven't already been created. | 448 // Create sync profiles and clients if they haven't already been created. |
| (...skipping 599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 BrowserThread::PostTask( | 1048 BrowserThread::PostTask( |
| 1032 BrowserThread::IO, FROM_HERE, | 1049 BrowserThread::IO, FROM_HERE, |
| 1033 base::Bind(&SetProxyConfigCallback, &done, | 1050 base::Bind(&SetProxyConfigCallback, &done, |
| 1034 make_scoped_refptr(context_getter), proxy_config)); | 1051 make_scoped_refptr(context_getter), proxy_config)); |
| 1035 done.Wait(); | 1052 done.Wait(); |
| 1036 } | 1053 } |
| 1037 | 1054 |
| 1038 fake_server::FakeServer* SyncTest::GetFakeServer() const { | 1055 fake_server::FakeServer* SyncTest::GetFakeServer() const { |
| 1039 return fake_server_.get(); | 1056 return fake_server_.get(); |
| 1040 } | 1057 } |
| OLD | NEW |