| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "chrome/test/base/testing_browser_process.h" | 28 #include "chrome/test/base/testing_browser_process.h" |
| 29 #include "chrome/test/base/testing_profile.h" | 29 #include "chrome/test/base/testing_profile.h" |
| 30 #include "chrome/test/base/testing_profile_manager.h" | 30 #include "chrome/test/base/testing_profile_manager.h" |
| 31 #include "components/browser_sync/browser/profile_sync_service.h" | 31 #include "components/browser_sync/browser/profile_sync_service.h" |
| 32 #include "components/browser_sync/common/browser_sync_switches.h" | 32 #include "components/browser_sync/common/browser_sync_switches.h" |
| 33 #include "components/invalidation/impl/profile_invalidation_provider.h" | 33 #include "components/invalidation/impl/profile_invalidation_provider.h" |
| 34 #include "components/invalidation/public/invalidation_service.h" | 34 #include "components/invalidation/public/invalidation_service.h" |
| 35 #include "components/signin/core/browser/account_tracker_service.h" | 35 #include "components/signin/core/browser/account_tracker_service.h" |
| 36 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" | 36 #include "components/signin/core/browser/fake_profile_oauth2_token_service.h" |
| 37 #include "components/signin/core/browser/signin_manager.h" | 37 #include "components/signin/core/browser/signin_manager.h" |
| 38 #include "components/signin/core/browser/signin_manager.h" |
| 38 #include "components/strings/grit/components_strings.h" | 39 #include "components/strings/grit/components_strings.h" |
| 39 #include "components/sync_driver/data_type_manager.h" | 40 #include "components/sync_driver/data_type_manager.h" |
| 40 #include "components/sync_driver/data_type_manager_observer.h" | 41 #include "components/sync_driver/data_type_manager_observer.h" |
| 41 #include "components/sync_driver/fake_data_type_controller.h" | 42 #include "components/sync_driver/fake_data_type_controller.h" |
| 42 #include "components/sync_driver/glue/sync_backend_host_mock.h" | 43 #include "components/sync_driver/glue/sync_backend_host_mock.h" |
| 43 #include "components/sync_driver/pref_names.h" | 44 #include "components/sync_driver/pref_names.h" |
| 44 #include "components/sync_driver/signin_manager_wrapper.h" | 45 #include "components/sync_driver/signin_manager_wrapper.h" |
| 45 #include "components/sync_driver/sync_api_component_factory_mock.h" | 46 #include "components/sync_driver/sync_api_component_factory_mock.h" |
| 46 #include "components/sync_driver/sync_driver_switches.h" | 47 #include "components/sync_driver/sync_driver_switches.h" |
| 47 #include "components/sync_driver/sync_prefs.h" | 48 #include "components/sync_driver/sync_prefs.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 return new FakeDataTypeManager(configure_called); | 99 return new FakeDataTypeManager(configure_called); |
| 99 } | 100 } |
| 100 | 101 |
| 101 using testing::Return; | 102 using testing::Return; |
| 102 using testing::StrictMock; | 103 using testing::StrictMock; |
| 103 using testing::_; | 104 using testing::_; |
| 104 | 105 |
| 105 class TestChromeSyncClient : public ChromeSyncClient { | 106 class TestChromeSyncClient : public ChromeSyncClient { |
| 106 public: | 107 public: |
| 107 TestChromeSyncClient( | 108 TestChromeSyncClient( |
| 109 Profile* profile, |
| 108 scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory, | 110 scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory, |
| 109 Profile* profile, | |
| 110 sync_driver::ClearBrowsingDataCallback callback) | 111 sync_driver::ClearBrowsingDataCallback callback) |
| 111 : ChromeSyncClient(profile), | 112 : ChromeSyncClient(profile, component_factory.Pass()), |
| 112 callback_(callback), | 113 callback_(callback) {} |
| 113 component_factory_(component_factory.Pass()) {} | |
| 114 ~TestChromeSyncClient() override {} | 114 ~TestChromeSyncClient() override {} |
| 115 | 115 |
| 116 private: | 116 private: |
| 117 // SyncClient: | 117 // SyncClient: |
| 118 sync_driver::ClearBrowsingDataCallback GetClearBrowsingDataCallback() | 118 sync_driver::ClearBrowsingDataCallback GetClearBrowsingDataCallback() |
| 119 override { | 119 override { |
| 120 return callback_; | 120 return callback_; |
| 121 } | 121 } |
| 122 sync_driver::SyncApiComponentFactory* GetSyncApiComponentFactory() override { | |
| 123 return component_factory_.get(); | |
| 124 } | |
| 125 | 122 |
| 126 sync_driver::ClearBrowsingDataCallback callback_; | 123 sync_driver::ClearBrowsingDataCallback callback_; |
| 127 scoped_ptr<sync_driver::SyncApiComponentFactory> component_factory_; | |
| 128 }; | 124 }; |
| 129 | 125 |
| 130 class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { | 126 class TestSyncServiceObserver : public sync_driver::SyncServiceObserver { |
| 131 public: | 127 public: |
| 132 explicit TestSyncServiceObserver(ProfileSyncService* service) | 128 explicit TestSyncServiceObserver(ProfileSyncService* service) |
| 133 : service_(service), first_setup_in_progress_(false) {} | 129 : service_(service), first_setup_in_progress_(false) {} |
| 134 void OnStateChanged() override { | 130 void OnStateChanged() override { |
| 135 first_setup_in_progress_ = service_->IsFirstSetupInProgress(); | 131 first_setup_in_progress_ = service_->IsFirstSetupInProgress(); |
| 136 } | 132 } |
| 137 bool first_setup_in_progress() const { return first_setup_in_progress_; } | 133 bool first_setup_in_progress() const { return first_setup_in_progress_; } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 248 |
| 253 // A test harness that uses a real ProfileSyncService and in most cases a | 249 // A test harness that uses a real ProfileSyncService and in most cases a |
| 254 // MockSyncBackendHost. | 250 // MockSyncBackendHost. |
| 255 // | 251 // |
| 256 // This is useful if we want to test the ProfileSyncService and don't care about | 252 // This is useful if we want to test the ProfileSyncService and don't care about |
| 257 // testing the SyncBackendHost. | 253 // testing the SyncBackendHost. |
| 258 class ProfileSyncServiceTest : public ::testing::Test { | 254 class ProfileSyncServiceTest : public ::testing::Test { |
| 259 protected: | 255 protected: |
| 260 ProfileSyncServiceTest() | 256 ProfileSyncServiceTest() |
| 261 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), | 257 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), |
| 262 profile_manager_(TestingBrowserProcess::GetGlobal()), | 258 profile_manager_(TestingBrowserProcess::GetGlobal()) {} |
| 263 profile_(NULL), | |
| 264 components_factory_(NULL) {} | |
| 265 ~ProfileSyncServiceTest() override {} | 259 ~ProfileSyncServiceTest() override {} |
| 266 | 260 |
| 267 void SetUp() override { | 261 void SetUp() override { |
| 268 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 262 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 269 switches::kSyncDeferredStartupTimeoutSeconds, "0"); | 263 switches::kSyncDeferredStartupTimeoutSeconds, "0"); |
| 270 | 264 |
| 271 CHECK(profile_manager_.SetUp()); | 265 CHECK(profile_manager_.SetUp()); |
| 272 | 266 |
| 273 TestingProfile::TestingFactories testing_factories; | 267 TestingProfile::TestingFactories testing_factories; |
| 274 testing_factories.push_back( | 268 testing_factories.push_back( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 303 void CreateService(ProfileSyncServiceStartBehavior behavior) { | 297 void CreateService(ProfileSyncServiceStartBehavior behavior) { |
| 304 SigninManagerBase* signin = | 298 SigninManagerBase* signin = |
| 305 SigninManagerFactory::GetForProfile(profile_); | 299 SigninManagerFactory::GetForProfile(profile_); |
| 306 signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); | 300 signin->SetAuthenticatedAccountInfo(kGaiaId, kEmail); |
| 307 ProfileOAuth2TokenService* oauth2_token_service = | 301 ProfileOAuth2TokenService* oauth2_token_service = |
| 308 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 302 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 309 scoped_ptr<SyncApiComponentFactoryMock> components_factory( | 303 scoped_ptr<SyncApiComponentFactoryMock> components_factory( |
| 310 new SyncApiComponentFactoryMock()); | 304 new SyncApiComponentFactoryMock()); |
| 311 components_factory_ = components_factory.get(); | 305 components_factory_ = components_factory.get(); |
| 312 scoped_ptr<ChromeSyncClient> sync_client(new TestChromeSyncClient( | 306 scoped_ptr<ChromeSyncClient> sync_client(new TestChromeSyncClient( |
| 313 components_factory.Pass(), profile_, | 307 profile_, components_factory.Pass(), |
| 314 base::Bind(&ProfileSyncServiceTest::ClearBrowsingDataCallback, | 308 base::Bind(&ProfileSyncServiceTest::ClearBrowsingDataCallback, |
| 315 base::Unretained(this)))); | 309 base::Unretained(this)))); |
| 316 service_.reset(new ProfileSyncService( | 310 service_.reset(new ProfileSyncService( |
| 317 sync_client.Pass(), | 311 sync_client.Pass(), |
| 318 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, | 312 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, |
| 319 behavior, base::Bind(&EmptyNetworkTimeUpdate), profile_->GetPath(), | 313 behavior, base::Bind(&EmptyNetworkTimeUpdate), profile_->GetPath(), |
| 320 profile_->GetRequestContext(), profile_->GetDebugName(), | 314 profile_->GetRequestContext(), profile_->GetDebugName(), |
| 321 chrome::GetChannel(), | 315 chrome::GetChannel(), |
| 322 content::BrowserThread::GetMessageLoopProxyForThread( | 316 content::BrowserThread::GetMessageLoopProxyForThread( |
| 323 content::BrowserThread::DB), | 317 content::BrowserThread::DB), |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 | 384 |
| 391 void ExpectDataTypeManagerCreation( | 385 void ExpectDataTypeManagerCreation( |
| 392 int times, | 386 int times, |
| 393 const FakeDataTypeManager::ConfigureCalled& callback) { | 387 const FakeDataTypeManager::ConfigureCalled& callback) { |
| 394 EXPECT_CALL(*components_factory_, CreateDataTypeManager(_, _, _, _, _)) | 388 EXPECT_CALL(*components_factory_, CreateDataTypeManager(_, _, _, _, _)) |
| 395 .Times(times) | 389 .Times(times) |
| 396 .WillRepeatedly(ReturnNewDataTypeManager(callback)); | 390 .WillRepeatedly(ReturnNewDataTypeManager(callback)); |
| 397 } | 391 } |
| 398 | 392 |
| 399 void ExpectSyncBackendHostCreation(int times) { | 393 void ExpectSyncBackendHostCreation(int times) { |
| 400 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) | 394 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) |
| 401 .Times(times) | 395 .Times(times) |
| 402 .WillRepeatedly(ReturnNewSyncBackendHostMock()); | 396 .WillRepeatedly(ReturnNewSyncBackendHostMock()); |
| 403 } | 397 } |
| 404 | 398 |
| 405 void ExpectSyncBackendHostCreationCollectDeleteDir( | 399 void ExpectSyncBackendHostCreationCollectDeleteDir( |
| 406 int times, std::vector<bool> *delete_dir_param) { | 400 int times, std::vector<bool> *delete_dir_param) { |
| 407 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) | 401 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) |
| 408 .Times(times) | 402 .Times(times) |
| 409 .WillRepeatedly( | 403 .WillRepeatedly( |
| 410 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); | 404 ReturnNewMockHostCollectDeleteDirParam(delete_dir_param)); |
| 411 } | 405 } |
| 412 | 406 |
| 413 void ExpectSyncBackendHostCreationCaptureClearServerData( | 407 void ExpectSyncBackendHostCreationCaptureClearServerData( |
| 414 syncer::SyncManager::ClearServerDataCallback* captured_callback) { | 408 syncer::SyncManager::ClearServerDataCallback* captured_callback) { |
| 415 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) | 409 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) |
| 416 .Times(1) | 410 .Times(1) |
| 417 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback)); | 411 .WillOnce(ReturnNewMockHostCaptureClearServerData(captured_callback)); |
| 418 } | 412 } |
| 419 | 413 |
| 420 void PrepareDelayedInitSyncBackendHost() { | 414 void PrepareDelayedInitSyncBackendHost() { |
| 421 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _)) | 415 EXPECT_CALL(*components_factory_, CreateSyncBackendHost(_, _, _, _, _)) |
| 422 .WillOnce(ReturnNewSyncBackendHostNoReturn()); | 416 .WillOnce(ReturnNewSyncBackendHostNoReturn()); |
| 423 } | 417 } |
| 424 | 418 |
| 425 TestingProfile* profile() { | 419 TestingProfile* profile() { |
| 426 return profile_; | 420 return profile_; |
| 427 } | 421 } |
| 428 | 422 |
| 429 ProfileSyncService* service() { | 423 ProfileSyncService* service() { |
| 430 return service_.get(); | 424 return service_.get(); |
| 431 } | 425 } |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 InitializeForNthSync(); | 1055 InitializeForNthSync(); |
| 1062 | 1056 |
| 1063 syncer::SyncProtocolError client_cmd; | 1057 syncer::SyncProtocolError client_cmd; |
| 1064 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; | 1058 client_cmd.action = syncer::RESET_LOCAL_SYNC_DATA; |
| 1065 service()->OnActionableError(client_cmd); | 1059 service()->OnActionableError(client_cmd); |
| 1066 EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); | 1060 EXPECT_EQ(ProfileSyncService::SYNC, service()->backend_mode()); |
| 1067 } | 1061 } |
| 1068 | 1062 |
| 1069 } // namespace | 1063 } // namespace |
| 1070 } // namespace browser_sync | 1064 } // namespace browser_sync |
| OLD | NEW |