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

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

Issue 12502017: signin: pull basic SigninManager functionality into new SigninManagerBase class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix override Created 7 years, 8 months 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 | Annotate | Revision Log
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 "testing/gtest/include/gtest/gtest.h" 5 #include "testing/gtest/include/gtest/gtest.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/prefs/pref_service.h" 9 #include "base/prefs/pref_service.h"
10 #include "chrome/browser/signin/signin_manager.h" 10 #include "chrome/browser/signin/signin_manager.h"
11 #include "chrome/browser/signin/signin_manager_factory.h" 11 #include "chrome/browser/signin/signin_manager_factory.h"
12 #include "chrome/browser/signin/signin_manager_fake.h" 12 #include "chrome/browser/signin/signin_manager_fake.h"
13 #include "chrome/browser/signin/token_service.h" 13 #include "chrome/browser/signin/token_service.h"
14 #include "chrome/browser/signin/token_service_factory.h" 14 #include "chrome/browser/signin/token_service_factory.h"
15 #include "chrome/browser/sync/glue/data_type_manager.h" 15 #include "chrome/browser/sync/glue/data_type_manager.h"
16 #include "chrome/browser/sync/glue/data_type_manager_mock.h" 16 #include "chrome/browser/sync/glue/data_type_manager_mock.h"
17 #include "chrome/browser/sync/profile_sync_components_factory_mock.h" 17 #include "chrome/browser/sync/profile_sync_components_factory_mock.h"
18 #include "chrome/browser/sync/profile_sync_service_factory.h" 18 #include "chrome/browser/sync/profile_sync_service_factory.h"
19 #include "chrome/browser/sync/profile_sync_test_util.h" 19 #include "chrome/browser/sync/profile_sync_test_util.h"
20 #include "chrome/browser/sync/sync_prefs.h" 20 #include "chrome/browser/sync/sync_prefs.h"
21 #include "chrome/browser/sync/test_profile_sync_service.h" 21 #include "chrome/browser/sync/test_profile_sync_service.h"
22 #include "chrome/common/chrome_notification_types.h" 22 #include "chrome/common/chrome_notification_types.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "chrome/test/base/testing_profile.h" 24 #include "chrome/test/base/testing_profile.h"
25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_source.h"
25 #include "content/public/test/test_browser_thread.h" 27 #include "content/public/test/test_browser_thread.h"
26 #include "google_apis/gaia/gaia_auth_consumer.h" 28 #include "google_apis/gaia/gaia_auth_consumer.h"
27 #include "google_apis/gaia/gaia_constants.h" 29 #include "google_apis/gaia/gaia_constants.h"
28 #include "testing/gmock/include/gmock/gmock.h" 30 #include "testing/gmock/include/gmock/gmock.h"
29 31
30 using browser_sync::DataTypeManager; 32 using browser_sync::DataTypeManager;
31 using browser_sync::DataTypeManagerMock; 33 using browser_sync::DataTypeManagerMock;
32 using content::BrowserThread; 34 using content::BrowserThread;
33 using testing::_; 35 using testing::_;
34 using testing::AnyNumber; 36 using testing::AnyNumber;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 95
94 // Pump messages posted by the sync core thread (which may end up 96 // Pump messages posted by the sync core thread (which may end up
95 // posting on the IO thread). 97 // posting on the IO thread).
96 ui_loop_.RunUntilIdle(); 98 ui_loop_.RunUntilIdle();
97 io_thread_.Stop(); 99 io_thread_.Stop();
98 file_thread_.Stop(); 100 file_thread_.Stop();
99 ui_loop_.RunUntilIdle(); 101 ui_loop_.RunUntilIdle();
100 } 102 }
101 103
102 static ProfileKeyedService* BuildService(Profile* profile) { 104 static ProfileKeyedService* BuildService(Profile* profile) {
103 SigninManager* signin = static_cast<SigninManager*>( 105 SigninManagerBase* signin = static_cast<SigninManagerBase*>(
104 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse( 106 SigninManagerFactory::GetInstance()->SetTestingFactoryAndUse(
105 profile, FakeSigninManager::Build)); 107 profile, FakeSigninManagerBase::Build));
106 signin->SetAuthenticatedUsername("test_user"); 108 signin->SetAuthenticatedUsername("test_user");
107 return new TestProfileSyncService( 109 return new TestProfileSyncService(
108 new ProfileSyncComponentsFactoryMock(), 110 new ProfileSyncComponentsFactoryMock(),
109 profile, 111 profile,
110 signin, 112 signin,
111 ProfileSyncService::MANUAL_START, 113 ProfileSyncService::MANUAL_START,
112 true); 114 true);
113 } 115 }
114 116
115 protected: 117 protected:
(...skipping 18 matching lines...) Expand all
134 content::TestBrowserThread file_thread_; 136 content::TestBrowserThread file_thread_;
135 content::TestBrowserThread io_thread_; 137 content::TestBrowserThread io_thread_;
136 scoped_ptr<TestingProfile> profile_; 138 scoped_ptr<TestingProfile> profile_;
137 TestProfileSyncService* sync_; 139 TestProfileSyncService* sync_;
138 ProfileSyncServiceObserverMock observer_; 140 ProfileSyncServiceObserverMock observer_;
139 }; 141 };
140 142
141 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest { 143 class ProfileSyncServiceStartupCrosTest : public ProfileSyncServiceStartupTest {
142 public: 144 public:
143 static ProfileKeyedService* BuildCrosService(Profile* profile) { 145 static ProfileKeyedService* BuildCrosService(Profile* profile) {
144 SigninManager* signin = SigninManagerFactory::GetForProfile(profile); 146 SigninManagerBase* signin =
147 SigninManagerFactory::GetForProfile(profile);
145 signin->SetAuthenticatedUsername("test_user"); 148 signin->SetAuthenticatedUsername("test_user");
146 return new TestProfileSyncService( 149 return new TestProfileSyncService(
147 new ProfileSyncComponentsFactoryMock(), 150 new ProfileSyncComponentsFactoryMock(),
148 profile, 151 profile,
149 signin, 152 signin,
150 ProfileSyncService::AUTO_START, 153 ProfileSyncService::AUTO_START,
151 true); 154 true);
152 } 155 }
153 protected: 156 protected:
154 virtual void CreateSyncService() OVERRIDE { 157 virtual void CreateSyncService() OVERRIDE {
(...skipping 27 matching lines...) Expand all
182 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); 185 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
183 EXPECT_CALL(*data_type_manager, state()). 186 EXPECT_CALL(*data_type_manager, state()).
184 WillOnce(Return(DataTypeManager::CONFIGURED)). 187 WillOnce(Return(DataTypeManager::CONFIGURED)).
185 WillOnce(Return(DataTypeManager::CONFIGURED)); 188 WillOnce(Return(DataTypeManager::CONFIGURED));
186 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 189 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
187 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 190 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
188 191
189 // Create some tokens in the token service; the service will startup when 192 // Create some tokens in the token service; the service will startup when
190 // it is notified that tokens are available. 193 // it is notified that tokens are available.
191 sync_->SetSetupInProgress(true); 194 sync_->SetSetupInProgress(true);
192 sync_->signin()->StartSignIn("test_user", "", "", ""); 195 sync_->signin()->SetAuthenticatedUsername("test_user");
196 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
197 "test_user");
198 GoogleServiceSigninSuccessDetails details("test_user", "");
199 content::NotificationService::current()->Notify(
200 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
201 content::Source<Profile>(profile_.get()),
202 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
193 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 203 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
194 GaiaConstants::kSyncService, "sync_token"); 204 GaiaConstants::kSyncService, "sync_token");
195 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 205 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
196 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token"); 206 GaiaConstants::kGaiaOAuth2LoginRefreshToken, "oauth2_login_token");
197 sync_->SetSetupInProgress(false); 207 sync_->SetSetupInProgress(false);
198 EXPECT_TRUE(sync_->ShouldPushChanges()); 208 EXPECT_TRUE(sync_->ShouldPushChanges());
199 } 209 }
200 210
201 ProfileKeyedService* BuildFakeTokenService(Profile* profile) { 211 ProfileKeyedService* BuildFakeTokenService(Profile* profile) {
202 return new FakeTokenService(); 212 return new FakeTokenService();
(...skipping 25 matching lines...) Expand all
228 238
229 // Then start things up. 239 // Then start things up.
230 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1); 240 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(1);
231 EXPECT_CALL(*data_type_manager, state()). 241 EXPECT_CALL(*data_type_manager, state()).
232 WillOnce(Return(DataTypeManager::CONFIGURED)). 242 WillOnce(Return(DataTypeManager::CONFIGURED)).
233 WillOnce(Return(DataTypeManager::CONFIGURED)); 243 WillOnce(Return(DataTypeManager::CONFIGURED));
234 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 244 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
235 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 245 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
236 246
237 sync_->SetSetupInProgress(true); 247 sync_->SetSetupInProgress(true);
238 sync_->signin()->StartSignIn("test_user", "", "", ""); 248 sync_->signin()->SetAuthenticatedUsername("test_user");
249 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
250 "test_user");
251 GoogleServiceSigninSuccessDetails details("test_user", "");
252 content::NotificationService::current()->Notify(
253 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
254 content::Source<Profile>(profile_.get()),
255 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
239 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens. 256 // NOTE: Unlike StartFirstTime, this test does not issue any auth tokens.
240 token_service->LoadTokensFromDB(); 257 token_service->LoadTokensFromDB();
241 sync_->SetSetupInProgress(false); 258 sync_->SetSetupInProgress(false);
242 // Backend should initialize using a bogus GAIA token for credentials. 259 // Backend should initialize using a bogus GAIA token for credentials.
243 EXPECT_TRUE(sync_->ShouldPushChanges()); 260 EXPECT_TRUE(sync_->ShouldPushChanges());
244 } 261 }
245 262
246 TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) { 263 TEST_F(ProfileSyncServiceStartupTest, StartInvalidCredentials) {
247 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager(); 264 DataTypeManagerMock* data_type_manager = SetUpDataTypeManager();
248 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0); 265 EXPECT_CALL(*data_type_manager, Configure(_, _)).Times(0);
(...skipping 13 matching lines...) Expand all
262 EXPECT_FALSE(sync_->ShouldPushChanges()); 279 EXPECT_FALSE(sync_->ShouldPushChanges());
263 Mock::VerifyAndClearExpectations(data_type_manager); 280 Mock::VerifyAndClearExpectations(data_type_manager);
264 281
265 // Update the credentials, unstalling the backend. 282 // Update the credentials, unstalling the backend.
266 EXPECT_CALL(*data_type_manager, Configure(_, _)); 283 EXPECT_CALL(*data_type_manager, Configure(_, _));
267 EXPECT_CALL(*data_type_manager, state()). 284 EXPECT_CALL(*data_type_manager, state()).
268 WillRepeatedly(Return(DataTypeManager::CONFIGURED)); 285 WillRepeatedly(Return(DataTypeManager::CONFIGURED));
269 EXPECT_CALL(*data_type_manager, Stop()).Times(1); 286 EXPECT_CALL(*data_type_manager, Stop()).Times(1);
270 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber()); 287 EXPECT_CALL(observer_, OnStateChanged()).Times(AnyNumber());
271 sync_->SetSetupInProgress(true); 288 sync_->SetSetupInProgress(true);
272 sync_->signin()->StartSignIn("test_user", "", "", ""); 289 sync_->signin()->SetAuthenticatedUsername("test_user");
290 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
291 "test_user");
292 GoogleServiceSigninSuccessDetails details("test_user", "");
293 content::NotificationService::current()->Notify(
294 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
295 content::Source<Profile>(profile_.get()),
296 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
Roger Tawa OOO till Jul 10th 2013/04/05 20:53:57 this seems to be duped 3 times. Maybe move into a
tim (not reviewing) 2013/04/05 22:14:12 Done.
273 token_service->IssueAuthTokenForTest( 297 token_service->IssueAuthTokenForTest(
274 GaiaConstants::kSyncService, "sync_token"); 298 GaiaConstants::kSyncService, "sync_token");
275 sync_->SetSetupInProgress(false); 299 sync_->SetSetupInProgress(false);
276 MessageLoop::current()->Run(); 300 MessageLoop::current()->Run();
277 301
278 // Verify we successfully finish startup and configuration. 302 // Verify we successfully finish startup and configuration.
279 EXPECT_TRUE(sync_->ShouldPushChanges()); 303 EXPECT_TRUE(sync_->ShouldPushChanges());
280 } 304 }
281 305
282 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) { 306 TEST_F(ProfileSyncServiceStartupCrosTest, StartCrosNoCredentials) {
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 488
465 // Preload the tokens. 489 // Preload the tokens.
466 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest( 490 TokenServiceFactory::GetForProfile(profile_.get())->IssueAuthTokenForTest(
467 GaiaConstants::kSyncService, "sync_token"); 491 GaiaConstants::kSyncService, "sync_token");
468 sync_->fail_initial_download(); 492 sync_->fail_initial_download();
469 493
470 sync_->Initialize(); 494 sync_->Initialize();
471 EXPECT_FALSE(sync_->sync_initialized()); 495 EXPECT_FALSE(sync_->sync_initialized());
472 EXPECT_FALSE(sync_->GetBackendForTest()); 496 EXPECT_FALSE(sync_->GetBackendForTest());
473 } 497 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698