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