Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(201)

Side by Side Diff: chrome/browser/sync/profile_sync_service_startup_unittest.cc

Issue 1421003007: [Sync] Componentize ProfileSyncComponentsFactoryImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix sessions api test Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_facotries; 121 TestingProfile::TestingFactories testing_factories;
122 testing_facotries.push_back(std::make_pair( 122 testing_factories.push_back(std::make_pair(
123 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase)); 123 SigninManagerFactory::GetInstance(), BuildFakeSigninManagerBase));
124 testing_facotries.push_back( 124 testing_factories.push_back(
125 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(), 125 std::make_pair(ProfileOAuth2TokenServiceFactory::GetInstance(),
126 BuildAutoIssuingFakeProfileOAuth2TokenService)); 126 BuildAutoIssuingFakeProfileOAuth2TokenService));
127 testing_facotries.push_back( 127 testing_factories.push_back(
128 std::make_pair(ProfileSyncServiceFactory::GetInstance(), 128 std::make_pair(ProfileSyncServiceFactory::GetInstance(), BuildService));
129 BuildService));
130 129
131 profile_ = profile_manager_.CreateTestingProfile( 130 profile_ = profile_manager_.CreateTestingProfile(
132 "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(), 131 "sync-startup-test", scoped_ptr<syncable_prefs::PrefServiceSyncable>(),
133 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(), 132 base::UTF8ToUTF16("sync-startup-test"), 0, std::string(),
134 testing_facotries); 133 testing_factories);
135 } 134 }
136 135
137 void TearDown() override { sync_->RemoveObserver(&observer_); } 136 void TearDown() override { sync_->RemoveObserver(&observer_); }
138 137
139 static scoped_ptr<KeyedService> BuildService( 138 static scoped_ptr<KeyedService> BuildService(
140 content::BrowserContext* browser_context) { 139 content::BrowserContext* browser_context) {
141 Profile* profile = static_cast<Profile*>(browser_context); 140 Profile* profile = static_cast<Profile*>(browser_context);
142 scoped_ptr<browser_sync::ChromeSyncClient> sync_client( 141 scoped_ptr<browser_sync::ChromeSyncClient> sync_client(
143 new browser_sync::ChromeSyncClient( 142 new browser_sync::ChromeSyncClient(profile));
144 profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); 143 sync_client->SetSyncApiComponentFactoryForTesting(
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
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
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( 249 new browser_sync::ChromeSyncClient(profile));
250 profile, make_scoped_ptr(new SyncApiComponentFactoryMock()))); 250 sync_client->SetSyncApiComponentFactoryForTesting(
251 make_scoped_ptr(new SyncApiComponentFactoryMock()));
251 return make_scoped_ptr(new TestProfileSyncServiceNoBackup( 252 return make_scoped_ptr(new TestProfileSyncServiceNoBackup(
252 sync_client.Pass(), profile, 253 sync_client.Pass(), profile,
253 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service, 254 make_scoped_ptr(new SigninManagerWrapper(signin)), oauth2_token_service,
254 browser_sync::AUTO_START)); 255 browser_sync::AUTO_START));
255 } 256 }
256 }; 257 };
257 258
258 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) { 259 TEST_F(ProfileSyncServiceStartupTest, StartFirstTime) {
259 // We've never completed startup. 260 // We've never completed startup.
260 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); 261 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 372
372 // Verify we successfully finish startup and configuration. 373 // Verify we successfully finish startup and configuration.
373 EXPECT_TRUE(sync_->IsSyncActive()); 374 EXPECT_TRUE(sync_->IsSyncActive());
374 } 375 }
375 376
376 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { 377 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
377 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), 378 EXPECT_CALL(*GetSyncApiComponentFactoryMock(),
378 CreateDataTypeManager(_, _, _, _, _)) 379 CreateDataTypeManager(_, _, _, _, _))
379 .Times(0); 380 .Times(0);
380 EXPECT_CALL(*GetSyncApiComponentFactoryMock(), 381 EXPECT_CALL(*GetSyncApiComponentFactoryMock(),
381 CreateSyncBackendHost(_, _, _, _, _)) 382 CreateSyncBackendHost(_, _, _, _))
382 .Times(0); 383 .Times(0);
383 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); 384 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
384 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 385 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
385 386
386 sync_->Initialize(); 387 sync_->Initialize();
387 // Sync should not start because there are no tokens yet. 388 // Sync should not start because there are no tokens yet.
388 EXPECT_FALSE(sync_->IsSyncActive()); 389 EXPECT_FALSE(sync_->IsSyncActive());
389 sync_->SetSetupInProgress(false); 390 sync_->SetSetupInProgress(false);
390 391
391 // Sync should not start because there are still no tokens. 392 // Sync should not start because there are still no tokens.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted); 573 profile_->GetPrefs()->ClearPref(sync_driver::prefs::kSyncHasSetupCompleted);
573 574
574 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 575 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
575 sync_->Initialize(); 576 sync_->Initialize();
576 577
577 sync_->SetSetupInProgress(true); 578 sync_->SetSetupInProgress(true);
578 IssueTestTokens(account_id); 579 IssueTestTokens(account_id);
579 sync_->SetSetupInProgress(false); 580 sync_->SetSetupInProgress(false);
580 EXPECT_FALSE(sync_->IsSyncActive()); 581 EXPECT_FALSE(sync_->IsSyncActive());
581 } 582 }
OLDNEW
« no previous file with comments | « chrome/browser/sync/profile_sync_service_mock.cc ('k') | chrome/browser/sync/profile_sync_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698