| 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/files/file_util.h" | 5 #include "base/files/file_util.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/signin/account_tracker_service_factory.h" | 9 #include "chrome/browser/signin/account_tracker_service_factory.h" |
| 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" | 10 #include "chrome/browser/signin/fake_profile_oauth2_token_service_builder.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | | 111 : thread_bundle_(content::TestBrowserThreadBundle::REAL_DB_THREAD | |
| 112 content::TestBrowserThreadBundle::REAL_IO_THREAD), | 112 content::TestBrowserThreadBundle::REAL_IO_THREAD), |
| 113 profile_manager_(TestingBrowserProcess::GetGlobal()), | 113 profile_manager_(TestingBrowserProcess::GetGlobal()), |
| 114 sync_(NULL) {} | 114 sync_(NULL) {} |
| 115 | 115 |
| 116 ~ProfileSyncServiceStartupTest() override {} | 116 ~ProfileSyncServiceStartupTest() override {} |
| 117 | 117 |
| 118 void SetUp() override { | 118 void SetUp() override { |
| 119 CHECK(profile_manager_.SetUp()); | 119 CHECK(profile_manager_.SetUp()); |
| 120 | 120 |
| 121 TestingProfile::TestingFactories testing_factories; | 121 TestingProfile::TestingFactories testing_facotries; |
| 122 testing_factories.push_back(std::make_pair( | 122 testing_facotries.push_back(std::make_pair( |
| 123 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase)); | 123 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase)); |
| 124 testing_factories.push_back( | 124 testing_facotries.push_back( |
| 125 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), | 125 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), |
| 126 BuildAutoIssuingFakeProfileOAuth2TokenService)); | 126 BuildAutoIssuingFakeProfileOAuth2TokenService)); |
| 127 testing_factories.push_back( | 127 testing_facotries.push_back( |
| 128 std::make_pair(ProfileSyncServiceFactory::GetInstance(), BuildService)); | 128 std::make_pair(ProfileSyncServiceFactory::GetInstance(), |
| 129 BuildService)); |
| 129 | 130 |
| 130 profile_ = profile_manager_.CreateTestingProfile( | 131 profile_ = profile_manager_.CreateTestingProfile( |
| 131 "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), | 132 "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), |
| 132 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), | 133 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), |
| 133 testing_factories); | 134 testing_facotries); |
| 134 } | 135 } |
| 135 | 136 |
| 136 void TearDown() override { sync_->RemoveObserver(&observer_); } | 137 void TearDown() override { sync_->RemoveObserver(&observer_); } |
| 137 | 138 |
| 138 static scoped_ptr<KeyedService> BuildService( | 139 static scoped_ptr<KeyedService> BuildService( |
| 139 content::BrowserContext* browser_context) { | 140 content::BrowserContext* browser_context) { |
| 140 Profile* profile = static_cast<Profile*>(browser_context); | 141 Profile* profile = static_cast<Profile*>(browser_context); |
| 141 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 142 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( |
| 142 new browser_sync::ChromeSyncClient(profile)); | 143 new browser_sync::ChromeSyncClient( |
| 143 sync_client->SetSyncApiComponentFactoryForTesting( | 144 profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); |
| 144 make_scoped_ptr(new SyncApiComponentFactoryMock())); | |
| 145 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 145 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |
| 146 sync_client.Pass(), profile, | 146 sync_client.Pass(), profile, |
| 147 make_scoped_ptr(new SigninManagerWrapper( | 147 make_scoped_ptr(new SigninManagerWrapper( |
| 148 SigninManagerFactory::GetForProfile(profile))), | 148 SigninManagerFactory::GetForProfile(profile))), |
| 149 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), | 149 ProfileOAuth2TokenServiceFactory::GetForProfile(profile), |
| 150 browser_sync::MANUAL_START)); | 150 browser_sync::MANUAL_START)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void CreateSyncService() { | 153 void CreateSyncService() { |
| 154 sync_ = static_cast<ProfileSyncService*>( | 154 sync_ = static_cast<ProfileSyncService*>( |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 205 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), |
| 206 CreateDataTypeManager(_, _, _, _, _)) | 206 CreateDataTypeManager(_, _, _, _, _)) |
| 207 .WillOnce(Return(data_type_manager)); | 207 .WillOnce(Return(data_type_manager)); |
| 208 return data_type_manager; | 208 return data_type_manager; |
| 209 } | 209 } |
| 210 | 210 |
| 211 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { | 211 browser_sync::SyncBackendHostMock* SetUpSyncBackendHost() { |
| 212 browser_sync::SyncBackendHostMock* sync_backend_host = | 212 browser_sync::SyncBackendHostMock* sync_backend_host = |
| 213 new browser_sync::SyncBackendHostMock(); | 213 new browser_sync::SyncBackendHostMock(); |
| 214 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 214 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), |
| 215 CreateSyncBackendHost(_, _, _, _)) | 215 CreateSyncBackendHost(_, _, _, _, _)) |
| 216 .WillOnce(Return(sync_backend_host)); | 216 .WillOnce(Return(sync_backend_host)); |
| 217 return sync_backend_host; | 217 return sync_backend_host; |
| 218 } | 218 } |
| 219 | 219 |
| 220 content::TestBrowserThreadBundle thread_bundle_; | 220 content::TestBrowserThreadBundle thread_bundle_; |
| 221 TestingProfileManager profile_manager_; | 221 TestingProfileManager profile_manager_; |
| 222 TestingProfile* profile_; | 222 TestingProfile* profile_; |
| 223 ProfileSyncService* sync_; | 223 ProfileSyncService* sync_; |
| 224 SyncServiceObserverMock observer_; | 224 SyncServiceObserverMock observer_; |
| 225 sync_driver::DataTypeStatusTable data_type_status_table_; | 225 sync_driver::DataTypeStatusTable data_type_status_table_; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 239 content::BrowserContext* context) { | 239 content::BrowserContext* context) { |
| 240 Profile* profile = static_cast<Profile*>(context); | 240 Profile* profile = static_cast<Profile*>(context); |
| 241 FakeSigninManagerForTesting* signin = | 241 FakeSigninManagerForTesting* signin = |
| 242 static_cast<FakeSigninManagerForTesting*>( | 242 static_cast<FakeSigninManagerForTesting*>( |
| 243 SigninManagerFactory::GetForProfile(profile)); | 243 SigninManagerFactory::GetForProfile(profile)); |
| 244 SimulateTestUserSignin(profile, signin, nullptr); | 244 SimulateTestUserSignin(profile, signin, nullptr); |
| 245 ProfileOAuth2TokenService* oauth2_token_service = | 245 ProfileOAuth2TokenService* oauth2_token_service = |
| 246 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); | 246 ProfileOAuth2TokenServiceFactory::GetForProfile(profile); |
| 247 EXPECT_TRUE(signin->IsAuthenticated()); | 247 EXPECT_TRUE(signin->IsAuthenticated()); |
| 248 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( | 248 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( |
| 249 new browser_sync::ChromeSyncClient(profile)); | 249 new browser_sync::ChromeSyncClient( |
| 250 sync_client->SetSyncApiComponentFactoryForTesting( | 250 profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); |
| 251 make_scoped_ptr(new SyncApiComponentFactoryMock())); | |
| 252 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( | 251 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( |
| 253 sync_client.Pass(), profile, | 252 sync_client.Pass(), profile, |
| 254 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, | 253 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, |
| 255 browser_sync::AUTO_START)); | 254 browser_sync::AUTO_START)); |
| 256 } | 255 } |
| 257 }; | 256 }; |
| 258 | 257 |
| 259 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { | 258 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { |
| 260 // We've never completed startup. | 259 // We've never completed startup. |
| 261 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 260 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 | 371 |
| 373 // Verify we successfully finish startup and configuration. | 372 // Verify we successfully finish startup and configuration. |
| 374 EXPECT_TRUE(sync_->IsSyncActive()); | 373 EXPECT_TRUE(sync_->IsSyncActive()); |
| 375 } | 374 } |
| 376 | 375 |
| 377 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { | 376 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { |
| 378 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 377 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), |
| 379 CreateDataTypeManager(_, _, _, _, _)) | 378 CreateDataTypeManager(_, _, _, _, _)) |
| 380 .Times(0); | 379 .Times(0); |
| 381 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), | 380 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), |
| 382 CreateSyncBackendHost(_, _, _, _)) | 381 CreateSyncBackendHost(_, _, _, _, _)) |
| 383 .Times(0); | 382 .Times(0); |
| 384 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 383 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
| 385 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 384 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 386 | 385 |
| 387 sync_->Initialize(); | 386 sync_->Initialize(); |
| 388 // Sync should not start because there are no tokens yet. | 387 // Sync should not start because there are no tokens yet. |
| 389 EXPECT_FALSE(sync_->IsSyncActive()); | 388 EXPECT_FALSE(sync_->IsSyncActive()); |
| 390 sync_->SetSetupInProgress(false); | 389 sync_->SetSetupInProgress(false); |
| 391 | 390 |
| 392 // Sync should not start because there are still no tokens. | 391 // Sync should not start because there are still no tokens. |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); | 572 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); |
| 574 | 573 |
| 575 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); | 574 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); |
| 576 sync_->Initialize(); | 575 sync_->Initialize(); |
| 577 | 576 |
| 578 sync_->SetSetupInProgress(true); | 577 sync_->SetSetupInProgress(true); |
| 579 IssueTestTokens(account_id); | 578 IssueTestTokens(account_id); |
| 580 sync_->SetSetupInProgress(false); | 579 sync_->SetSetupInProgress(false); |
| 581 EXPECT_FALSE(sync_->IsSyncActive()); | 580 EXPECT_FALSE(sync_->IsSyncActive()); |
| 582 } | 581 } |
| OLD | NEW |