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

Side by Side Diff: chrome/browser/signin/signin_tracker_unittest.cc

Issue 14691004: [sync] Separate sign in from sync on Desktop Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 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 "chrome/browser/signin/signin_tracker.h" 5 #include "chrome/browser/signin/signin_tracker.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 content::Source<Profile>(profile_.get()), 102 content::Source<Profile>(profile_.get()),
103 content::Details<const GoogleServiceAuthError>(&error)); 103 content::Details<const GoogleServiceAuthError>(&error));
104 } 104 }
105 105
106 TEST_F(SigninTrackerTest, GaiaSignInSucceeded) { 106 TEST_F(SigninTrackerTest, GaiaSignInSucceeded) {
107 // SIGNIN_SUCCEEDED notification should lead us to get a GaiCredentialsValid() 107 // SIGNIN_SUCCEEDED notification should lead us to get a GaiCredentialsValid()
108 // callback. 108 // callback.
109 EXPECT_CALL(observer_, GaiaCredentialsValid()); 109 EXPECT_CALL(observer_, GaiaCredentialsValid());
110 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()) 110 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn())
111 .WillRepeatedly(Return(false)); 111 .WillRepeatedly(Return(false));
112 const GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
113 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
112 EXPECT_CALL(*mock_token_service_, HasTokenForService(_)) 114 EXPECT_CALL(*mock_token_service_, HasTokenForService(_))
113 .WillRepeatedly(Return(false)); 115 .WillRepeatedly(Return(false));
114 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password"); 116 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password");
115 content::NotificationService::current()->Notify( 117 content::NotificationService::current()->Notify(
116 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 118 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
117 content::Source<Profile>(profile_.get()), 119 content::Source<Profile>(profile_.get()),
118 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 120 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
119 } 121 }
120 122
121 static void ExpectSignedInSyncService(ProfileSyncServiceMock* sync_service, 123 static void ExpectSignedInSyncService(ProfileSyncServiceMock* sync_service,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 TEST_F(SigninTrackerTest, NoGaiaSigninWhenServicesNotRunning) { 234 TEST_F(SigninTrackerTest, NoGaiaSigninWhenServicesNotRunning) {
233 // SIGNIN_SUCCEEDED notification should not result in a SigninSuccess() 235 // SIGNIN_SUCCEEDED notification should not result in a SigninSuccess()
234 // callback if we're not already signed in. 236 // callback if we're not already signed in.
235 EXPECT_CALL(observer_, GaiaCredentialsValid()); 237 EXPECT_CALL(observer_, GaiaCredentialsValid());
236 EXPECT_CALL(*mock_token_service_, HasTokenForService(_)) 238 EXPECT_CALL(*mock_token_service_, HasTokenForService(_))
237 .WillRepeatedly(Return(true)); 239 .WillRepeatedly(Return(true));
238 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly( 240 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly(
239 Return(false)); 241 Return(false));
240 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()).WillRepeatedly( 242 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()).WillRepeatedly(
241 Return(false)); 243 Return(false));
244 const GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
245 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
242 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password"); 246 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password");
243 content::NotificationService::current()->Notify( 247 content::NotificationService::current()->Notify(
244 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 248 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
245 content::Source<Profile>(profile_.get()), 249 content::Source<Profile>(profile_.get()),
246 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 250 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
247 } 251 }
248 252
249 TEST_F(SigninTrackerTest, GaiaSigninAfterSyncStarts) { 253 TEST_F(SigninTrackerTest, GaiaSigninAfterSyncStarts) {
250 // Make sure that we don't get a SigninSuccess() callback until after the 254 // Make sure that we don't get a SigninSuccess() callback until after the
251 // sync service reports that it's signed in. 255 // sync service reports that it's signed in.
252 EXPECT_CALL(observer_, GaiaCredentialsValid()); 256 EXPECT_CALL(observer_, GaiaCredentialsValid());
253 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillOnce( 257 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillOnce(
254 Return(false)); 258 Return(false));
259 const GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
260 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
255 EXPECT_CALL(*mock_token_service_, HasTokenForService(_)) 261 EXPECT_CALL(*mock_token_service_, HasTokenForService(_))
256 .WillRepeatedly(Return(true)); 262 .WillRepeatedly(Return(true));
257 mock_signin_manager_->SetAuthenticatedUsername("username@gmail.com"); 263 mock_signin_manager_->SetAuthenticatedUsername("username@gmail.com");
258 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password"); 264 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password");
259 content::NotificationService::current()->Notify( 265 content::NotificationService::current()->Notify(
260 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 266 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
261 content::Source<Profile>(profile_.get()), 267 content::Source<Profile>(profile_.get()),
262 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 268 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
263 Mock::VerifyAndClearExpectations(mock_pss_); 269 Mock::VerifyAndClearExpectations(mock_pss_);
264 // Mimic the sync engine getting credentials. 270 // Mimic the sync engine getting credentials.
265 EXPECT_CALL(observer_, SigninSuccess()); 271 EXPECT_CALL(observer_, SigninSuccess());
266 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
267 ExpectSignedInSyncService(mock_pss_, mock_token_service_, error); 272 ExpectSignedInSyncService(mock_pss_, mock_token_service_, error);
268 tracker_->OnStateChanged(); 273 tracker_->OnStateChanged();
269 } 274 }
270 275
271 TEST_F(SigninTrackerTest, SyncSigninError) { 276 TEST_F(SigninTrackerTest, SyncSigninError) {
272 // Make sure that we get a SigninFailed() callback if sync gets an error after 277 // Make sure that we get a SigninFailed() callback if sync gets an error after
273 // initializaiton. 278 // initialization.
274 EXPECT_CALL(observer_, GaiaCredentialsValid()); 279 EXPECT_CALL(observer_, GaiaCredentialsValid());
275 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly( 280 EXPECT_CALL(*mock_pss_, IsSyncEnabledAndLoggedIn()).WillRepeatedly(
276 Return(false)); 281 Return(false));
277 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()).WillRepeatedly( 282 EXPECT_CALL(*mock_pss_, IsSyncTokenAvailable()).WillRepeatedly(
278 Return(false)); 283 Return(false));
284 const GoogleServiceAuthError no_error(GoogleServiceAuthError::NONE);
285 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(no_error));
279 EXPECT_CALL(*mock_token_service_, HasTokenForService(_)) 286 EXPECT_CALL(*mock_token_service_, HasTokenForService(_))
280 .WillRepeatedly(Return(true)); 287 .WillRepeatedly(Return(true));
281 mock_signin_manager_->SetAuthenticatedUsername("username@gmail.com"); 288 mock_signin_manager_->SetAuthenticatedUsername("username@gmail.com");
282 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password"); 289 GoogleServiceSigninSuccessDetails details("username@gmail.com", "password");
283 content::NotificationService::current()->Notify( 290 content::NotificationService::current()->Notify(
284 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL, 291 chrome::NOTIFICATION_GOOGLE_SIGNIN_SUCCESSFUL,
285 content::Source<Profile>(profile_.get()), 292 content::Source<Profile>(profile_.get()),
286 content::Details<const GoogleServiceSigninSuccessDetails>(&details)); 293 content::Details<const GoogleServiceSigninSuccessDetails>(&details));
287 294
288 // Still waiting for auth, so sync state changes should be ignored. 295 // Still waiting for auth, so sync state changes should be ignored.
289 EXPECT_CALL(*mock_pss_, waiting_for_auth()).WillOnce(Return(true)); 296 EXPECT_CALL(*mock_pss_, waiting_for_auth()).WillOnce(Return(true));
290 tracker_->OnStateChanged(); 297 tracker_->OnStateChanged();
291 // Now mimic an auth error - this should cause us to fail (not waiting for 298 // Now mimic an auth error - this should cause us to fail (not waiting for
292 // auth, but still have no credentials). 299 // auth, but still have no credentials).
293 GoogleServiceAuthError error( 300 GoogleServiceAuthError error(
294 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 301 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
295 FakeAuthStatusProvider provider(mock_signin_manager_->signin_global_error()); 302 FakeAuthStatusProvider provider(mock_signin_manager_->signin_global_error());
296 provider.SetAuthError(error); 303 provider.SetAuthError(error);
297 EXPECT_CALL(*mock_pss_, waiting_for_auth()).WillRepeatedly(Return(false)); 304 EXPECT_CALL(*mock_pss_, waiting_for_auth()).WillRepeatedly(Return(false));
305 EXPECT_CALL(*mock_pss_, GetAuthError()).WillRepeatedly(ReturnRef(error));
298 EXPECT_CALL(observer_, SigninFailed(error)); 306 EXPECT_CALL(observer_, SigninFailed(error));
299 tracker_->OnStateChanged(); 307 tracker_->OnStateChanged();
300 } 308 }
301 309
302 // Test cases for initial state = SERVICES_INITIALIZING. 310 // Test cases for initial state = SERVICES_INITIALIZING.
303 TEST_F(SigninTrackerTest, SigninSuccess) { 311 TEST_F(SigninTrackerTest, SigninSuccess) {
304 // Reset the |tracker_| and restart with initial state parameter for its 312 // Reset the |tracker_| and restart with initial state parameter for its
305 // constructor later. 313 // constructor later.
306 tracker_.reset(); 314 tracker_.reset();
307 GoogleServiceAuthError error(GoogleServiceAuthError::NONE); 315 GoogleServiceAuthError error(GoogleServiceAuthError::NONE);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
362 370
363 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) { 371 TEST_F(SigninTrackerTest, SigninFailedWhenInitializing) {
364 tracker_.reset(); 372 tracker_.reset();
365 // SigninFailed() should be called. 373 // SigninFailed() should be called.
366 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 374 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
367 EXPECT_CALL(observer_, SigninFailed(error)); 375 EXPECT_CALL(observer_, SigninFailed(error));
368 tracker_.reset(new SigninTracker(profile_.get(), &observer_, 376 tracker_.reset(new SigninTracker(profile_.get(), &observer_,
369 SigninTracker::SERVICES_INITIALIZING)); 377 SigninTracker::SERVICES_INITIALIZING));
370 tracker_->OnStateChanged(); 378 tracker_->OnStateChanged();
371 } 379 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698