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

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

Issue 15024007: Eliminate BrowserProcess dependency from sign-in production code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge LKGR 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_manager.h" 5 #include "chrome/browser/signin/signin_manager.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 "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 // Should go into token service and stop. 205 // Should go into token service and stop.
206 EXPECT_EQ(1U, google_login_success_.size()); 206 EXPECT_EQ(1U, google_login_success_.size());
207 EXPECT_EQ(0U, google_login_failure_.size()); 207 EXPECT_EQ(0U, google_login_failure_.size());
208 208
209 // Should persist across resets. 209 // Should persist across resets.
210 manager_->Shutdown(); 210 manager_->Shutdown();
211 manager_.reset(new SigninManager( 211 manager_.reset(new SigninManager(
212 scoped_ptr<SigninManagerDelegate>( 212 scoped_ptr<SigninManagerDelegate>(
213 new ChromeSigninManagerDelegate(profile_.get())))); 213 new ChromeSigninManagerDelegate(profile_.get()))));
214 manager_->Initialize(profile_.get()); 214 manager_->Initialize(profile_.get(), NULL);
215 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 215 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
216 } 216 }
217 217
218 // Helper method that wraps the logic when signin with credentials 218 // Helper method that wraps the logic when signin with credentials
219 // should fail. If |requestSent| is true, then simulate valid resopnse. 219 // should fail. If |requestSent| is true, then simulate valid resopnse.
220 // Otherwise the sign-in is aborted before any request is sent, thus no need 220 // Otherwise the sign-in is aborted before any request is sent, thus no need
221 // to simulatate response. 221 // to simulatate response.
222 void ExpectSignInWithCredentialsFail(bool requestSent) { 222 void ExpectSignInWithCredentialsFail(bool requestSent) {
223 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 223 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
224 224
(...skipping 25 matching lines...) Expand all
250 content::TestNotificationTracker google_login_failure_; 250 content::TestNotificationTracker google_login_failure_;
251 std::vector<std::string> oauth_tokens_fetched_; 251 std::vector<std::string> oauth_tokens_fetched_;
252 scoped_ptr<TestingPrefServiceSimple> prefs_; 252 scoped_ptr<TestingPrefServiceSimple> prefs_;
253 scoped_ptr<content::TestBrowserThread> io_thread_; 253 scoped_ptr<content::TestBrowserThread> io_thread_;
254 std::vector<std::string> cookies_; 254 std::vector<std::string> cookies_;
255 }; 255 };
256 256
257 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials 257 // NOTE: ClientLogin's "StartSignin" is called after collecting credentials
258 // from the user. 258 // from the user.
259 TEST_F(SigninManagerTest, SignInClientLogin) { 259 TEST_F(SigninManagerTest, SignInClientLogin) {
260 manager_->Initialize(profile_.get()); 260 manager_->Initialize(profile_.get(), NULL);
261 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 261 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
262 262
263 manager_->StartSignIn( 263 manager_->StartSignIn(
264 "user@gmail.com", "password", std::string(), std::string()); 264 "user@gmail.com", "password", std::string(), std::string());
265 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 265 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
266 266
267 SimulateValidResponseClientLogin(true); 267 SimulateValidResponseClientLogin(true);
268 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 268 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
269 269
270 // Should go into token service and stop. 270 // Should go into token service and stop.
271 EXPECT_EQ(1U, google_login_success_.size()); 271 EXPECT_EQ(1U, google_login_success_.size());
272 EXPECT_EQ(0U, google_login_failure_.size()); 272 EXPECT_EQ(0U, google_login_failure_.size());
273 273
274 service_->OnIssueAuthTokenSuccess(GaiaConstants::kGaiaOAuth2LoginRefreshToken, 274 service_->OnIssueAuthTokenSuccess(GaiaConstants::kGaiaOAuth2LoginRefreshToken,
275 "oauth2Token"); 275 "oauth2Token");
276 SimulateValidUberToken(); 276 SimulateValidUberToken();
277 // Check that the login cookie has been sent. 277 // Check that the login cookie has been sent.
278 ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"), 278 ASSERT_NE(std::find(cookies_.begin(), cookies_.end(), "checkCookie = true"),
279 cookies_.end()); 279 cookies_.end());
280 280
281 // Should persist across resets. 281 // Should persist across resets.
282 manager_->Shutdown(); 282 manager_->Shutdown();
283 manager_.reset(new SigninManager( 283 manager_.reset(new SigninManager(
284 scoped_ptr<SigninManagerDelegate>( 284 scoped_ptr<SigninManagerDelegate>(
285 new ChromeSigninManagerDelegate(profile_.get())))); 285 new ChromeSigninManagerDelegate(profile_.get()))));
286 manager_->Initialize(profile_.get()); 286 manager_->Initialize(profile_.get(), NULL);
287 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 287 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
288 } 288 }
289 289
290 TEST_F(SigninManagerTest, SignInWithCredentials) { 290 TEST_F(SigninManagerTest, SignInWithCredentials) {
291 manager_->Initialize(profile_.get()); 291 manager_->Initialize(profile_.get(), NULL);
292 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 292 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
293 293
294 manager_->StartSignInWithCredentials( 294 manager_->StartSignInWithCredentials(
295 "0", 295 "0",
296 "user@gmail.com", 296 "user@gmail.com",
297 "password", 297 "password",
298 SigninManager::OAuthTokenFetchedCallback()); 298 SigninManager::OAuthTokenFetchedCallback());
299 299
300 ExpectSignInWithCredentialsSuccess(); 300 ExpectSignInWithCredentialsSuccess();
301 } 301 }
302 302
303 TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) { 303 TEST_F(SigninManagerTest, SignInWithCredentialsNonCanonicalEmail) {
304 manager_->Initialize(profile_.get()); 304 manager_->Initialize(profile_.get(), NULL);
305 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 305 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
306 306
307 manager_->StartSignInWithCredentials( 307 manager_->StartSignInWithCredentials(
308 "0", 308 "0",
309 "user", 309 "user",
310 "password", 310 "password",
311 SigninManager::OAuthTokenFetchedCallback()); 311 SigninManager::OAuthTokenFetchedCallback());
312 312
313 ExpectSignInWithCredentialsSuccess(); 313 ExpectSignInWithCredentialsSuccess();
314 } 314 }
315 315
316 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) { 316 TEST_F(SigninManagerTest, SignInWithCredentialsWrongEmail) {
317 manager_->Initialize(profile_.get()); 317 manager_->Initialize(profile_.get(), NULL);
318 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 318 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
319 319
320 // If the email address used to start the sign in does not match the 320 // If the email address used to start the sign in does not match the
321 // email address returned by /GetUserInfo, the sign in should fail. 321 // email address returned by /GetUserInfo, the sign in should fail.
322 manager_->StartSignInWithCredentials( 322 manager_->StartSignInWithCredentials(
323 "0", 323 "0",
324 "user2@gmail.com", 324 "user2@gmail.com",
325 "password", 325 "password",
326 SigninManager::OAuthTokenFetchedCallback()); 326 SigninManager::OAuthTokenFetchedCallback());
327 327
328 ExpectSignInWithCredentialsFail(true /* requestSent */); 328 ExpectSignInWithCredentialsFail(true /* requestSent */);
329 } 329 }
330 330
331 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) { 331 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordValidCookie) {
332 manager_->Initialize(profile_.get()); 332 manager_->Initialize(profile_.get(), NULL);
333 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 333 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
334 334
335 // Set a valid LSID cookie in the test cookie store. 335 // Set a valid LSID cookie in the test cookie store.
336 scoped_refptr<net::CookieMonster> cookie_monster = 336 scoped_refptr<net::CookieMonster> cookie_monster =
337 profile_->GetCookieMonster(); 337 profile_->GetCookieMonster();
338 net::CookieOptions options; 338 net::CookieOptions options;
339 options.set_include_httponly(); 339 options.set_include_httponly();
340 cookie_monster->SetCookieWithOptionsAsync( 340 cookie_monster->SetCookieWithOptionsAsync(
341 GURL("https://accounts.google.com"), 341 GURL("https://accounts.google.com"),
342 "LSID=1234; secure; httponly", options, 342 "LSID=1234; secure; httponly", options,
343 net::CookieMonster::SetCookiesCallback()); 343 net::CookieMonster::SetCookiesCallback());
344 344
345 // Since the password is empty, will verify the gaia cookies first. 345 // Since the password is empty, will verify the gaia cookies first.
346 manager_->StartSignInWithCredentials( 346 manager_->StartSignInWithCredentials(
347 "0", 347 "0",
348 "user@gmail.com", 348 "user@gmail.com",
349 std::string(), 349 std::string(),
350 SigninManager::OAuthTokenFetchedCallback()); 350 SigninManager::OAuthTokenFetchedCallback());
351 351
352 WaitUntilUIDone(); 352 WaitUntilUIDone();
353 353
354 // Verification should succeed and continue with auto signin. 354 // Verification should succeed and continue with auto signin.
355 ExpectSignInWithCredentialsSuccess(); 355 ExpectSignInWithCredentialsSuccess();
356 } 356 }
357 357
358 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) { 358 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordNoValidCookie) {
359 manager_->Initialize(profile_.get()); 359 manager_->Initialize(profile_.get(), NULL);
360 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 360 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
361 361
362 // Since the password is empty, will verify the gaia cookies first. 362 // Since the password is empty, will verify the gaia cookies first.
363 manager_->StartSignInWithCredentials( 363 manager_->StartSignInWithCredentials(
364 "0", 364 "0",
365 "user@gmail.com", 365 "user@gmail.com",
366 std::string(), 366 std::string(),
367 SigninManager::OAuthTokenFetchedCallback()); 367 SigninManager::OAuthTokenFetchedCallback());
368 368
369 WaitUntilUIDone(); 369 WaitUntilUIDone();
370 370
371 // Since the test cookie store is empty, verification should fail and throws 371 // Since the test cookie store is empty, verification should fail and throws
372 // a login error. 372 // a login error.
373 ExpectSignInWithCredentialsFail(false /* requestSent */); 373 ExpectSignInWithCredentialsFail(false /* requestSent */);
374 } 374 }
375 375
376 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) { 376 TEST_F(SigninManagerTest, SignInWithCredentialsEmptyPasswordInValidCookie) {
377 manager_->Initialize(profile_.get()); 377 manager_->Initialize(profile_.get(), NULL);
378 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 378 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
379 379
380 // Set an invalid LSID cookie in the test cookie store. 380 // Set an invalid LSID cookie in the test cookie store.
381 scoped_refptr<net::CookieMonster> cookie_monster = 381 scoped_refptr<net::CookieMonster> cookie_monster =
382 profile_->GetCookieMonster(); 382 profile_->GetCookieMonster();
383 net::CookieOptions options; 383 net::CookieOptions options;
384 options.set_include_httponly(); 384 options.set_include_httponly();
385 cookie_monster->SetCookieWithOptionsAsync( 385 cookie_monster->SetCookieWithOptionsAsync(
386 GURL("https://accounts.google.com"), 386 GURL("https://accounts.google.com"),
387 "LSID=1234; domain=google.com; secure; httponly", options, 387 "LSID=1234; domain=google.com; secure; httponly", options,
388 net::CookieMonster::SetCookiesCallback()); 388 net::CookieMonster::SetCookiesCallback());
389 389
390 // Since the password is empty, must verify the gaia cookies first. 390 // Since the password is empty, must verify the gaia cookies first.
391 manager_->StartSignInWithCredentials( 391 manager_->StartSignInWithCredentials(
392 "0", 392 "0",
393 "user@gmail.com", 393 "user@gmail.com",
394 std::string(), 394 std::string(),
395 SigninManager::OAuthTokenFetchedCallback()); 395 SigninManager::OAuthTokenFetchedCallback());
396 396
397 WaitUntilUIDone(); 397 WaitUntilUIDone();
398 398
399 // Since the LSID cookie is invalid, verification should fail and throws 399 // Since the LSID cookie is invalid, verification should fail and throws
400 // a login error. 400 // a login error.
401 ExpectSignInWithCredentialsFail(false /* requestSent */); 401 ExpectSignInWithCredentialsFail(false /* requestSent */);
402 } 402 }
403 403
404 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackComplete) { 404 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackComplete) {
405 manager_->Initialize(profile_.get()); 405 manager_->Initialize(profile_.get(), NULL);
406 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 406 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
407 407
408 // Since the password is empty, must verify the gaia cookies first. 408 // Since the password is empty, must verify the gaia cookies first.
409 SigninManager::OAuthTokenFetchedCallback callback = 409 SigninManager::OAuthTokenFetchedCallback callback =
410 base::Bind(&SigninManagerTest::CompleteSigninCallback, 410 base::Bind(&SigninManagerTest::CompleteSigninCallback,
411 base::Unretained(this)); 411 base::Unretained(this));
412 manager_->StartSignInWithCredentials( 412 manager_->StartSignInWithCredentials(
413 "0", 413 "0",
414 "user@gmail.com", 414 "user@gmail.com",
415 "password", 415 "password",
416 callback); 416 callback);
417 417
418 ExpectSignInWithCredentialsSuccess(); 418 ExpectSignInWithCredentialsSuccess();
419 ASSERT_EQ(1U, oauth_tokens_fetched_.size()); 419 ASSERT_EQ(1U, oauth_tokens_fetched_.size());
420 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1"); 420 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1");
421 } 421 }
422 422
423 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackCancel) { 423 TEST_F(SigninManagerTest, SignInWithCredentialsCallbackCancel) {
424 manager_->Initialize(profile_.get()); 424 manager_->Initialize(profile_.get(), NULL);
425 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 425 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
426 426
427 // Since the password is empty, must verify the gaia cookies first. 427 // Since the password is empty, must verify the gaia cookies first.
428 SigninManager::OAuthTokenFetchedCallback callback = 428 SigninManager::OAuthTokenFetchedCallback callback =
429 base::Bind(&SigninManagerTest::CancelSigninCallback, 429 base::Bind(&SigninManagerTest::CancelSigninCallback,
430 base::Unretained(this)); 430 base::Unretained(this));
431 manager_->StartSignInWithCredentials( 431 manager_->StartSignInWithCredentials(
432 "0", 432 "0",
433 "user@gmail.com", 433 "user@gmail.com",
434 "password", 434 "password",
435 callback); 435 callback);
436 436
437 // Signin should fail since it would be cancelled by the callback. 437 // Signin should fail since it would be cancelled by the callback.
438 ExpectSignInWithCredentialsFail(true); 438 ExpectSignInWithCredentialsFail(true);
439 ASSERT_EQ(1U, oauth_tokens_fetched_.size()); 439 ASSERT_EQ(1U, oauth_tokens_fetched_.size());
440 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1"); 440 EXPECT_EQ(oauth_tokens_fetched_[0], "rt1");
441 } 441 }
442 442
443 TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) { 443 TEST_F(SigninManagerTest, SignInClientLoginNoGPlus) {
444 manager_->Initialize(profile_.get()); 444 manager_->Initialize(profile_.get(), NULL);
445 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 445 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
446 446
447 manager_->StartSignIn("username", "password", std::string(), std::string()); 447 manager_->StartSignIn("username", "password", std::string(), std::string());
448 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 448 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
449 449
450 SimulateValidResponseClientLogin(false); 450 SimulateValidResponseClientLogin(false);
451 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 451 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
452 } 452 }
453 453
454 TEST_F(SigninManagerTest, ClearTransientSigninData) { 454 TEST_F(SigninManagerTest, ClearTransientSigninData) {
455 manager_->Initialize(profile_.get()); 455 manager_->Initialize(profile_.get(), NULL);
456 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 456 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
457 457
458 manager_->StartSignIn("username", "password", std::string(), std::string()); 458 manager_->StartSignIn("username", "password", std::string(), std::string());
459 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 459 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
460 460
461 SimulateValidResponseClientLogin(false); 461 SimulateValidResponseClientLogin(false);
462 462
463 // Should go into token service and stop. 463 // Should go into token service and stop.
464 EXPECT_EQ(1U, google_login_success_.size()); 464 EXPECT_EQ(1U, google_login_success_.size());
465 EXPECT_EQ(0U, google_login_failure_.size()); 465 EXPECT_EQ(0U, google_login_failure_.size());
466 466
467 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 467 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
468 468
469 // Now clear the in memory data. 469 // Now clear the in memory data.
470 manager_->ClearTransientSigninData(); 470 manager_->ClearTransientSigninData();
471 EXPECT_TRUE(manager_->last_result_.data.empty()); 471 EXPECT_TRUE(manager_->last_result_.data.empty());
472 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 472 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
473 473
474 // Ensure preferences are not modified. 474 // Ensure preferences are not modified.
475 EXPECT_FALSE( 475 EXPECT_FALSE(
476 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty()); 476 profile_->GetPrefs()->GetString(prefs::kGoogleServicesUsername).empty());
477 477
478 // On reset it should be regenerated. 478 // On reset it should be regenerated.
479 manager_->Shutdown(); 479 manager_->Shutdown();
480 manager_.reset(new SigninManager( 480 manager_.reset(new SigninManager(
481 scoped_ptr<SigninManagerDelegate>( 481 scoped_ptr<SigninManagerDelegate>(
482 new ChromeSigninManagerDelegate(profile_.get())))); 482 new ChromeSigninManagerDelegate(profile_.get()))));
483 manager_->Initialize(profile_.get()); 483 manager_->Initialize(profile_.get(), NULL);
484 484
485 // Now make sure we have the right user name. 485 // Now make sure we have the right user name.
486 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 486 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
487 } 487 }
488 488
489 TEST_F(SigninManagerTest, SignOutClientLogin) { 489 TEST_F(SigninManagerTest, SignOutClientLogin) {
490 manager_->Initialize(profile_.get()); 490 manager_->Initialize(profile_.get(), NULL);
491 manager_->StartSignIn("username", "password", std::string(), std::string()); 491 manager_->StartSignIn("username", "password", std::string(), std::string());
492 SimulateValidResponseClientLogin(false); 492 SimulateValidResponseClientLogin(false);
493 manager_->OnClientLoginSuccess(credentials_); 493 manager_->OnClientLoginSuccess(credentials_);
494 494
495 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername()); 495 EXPECT_EQ("user@gmail.com", manager_->GetAuthenticatedUsername());
496 manager_->SignOut(); 496 manager_->SignOut();
497 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 497 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
498 // Should not be persisted anymore 498 // Should not be persisted anymore
499 manager_->Shutdown(); 499 manager_->Shutdown();
500 manager_.reset(new SigninManager( 500 manager_.reset(new SigninManager(
501 scoped_ptr<SigninManagerDelegate>( 501 scoped_ptr<SigninManagerDelegate>(
502 new ChromeSigninManagerDelegate(profile_.get())))); 502 new ChromeSigninManagerDelegate(profile_.get()))));
503 manager_->Initialize(profile_.get()); 503 manager_->Initialize(profile_.get(), NULL);
504 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 504 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
505 } 505 }
506 506
507 TEST_F(SigninManagerTest, SignInFailureClientLogin) { 507 TEST_F(SigninManagerTest, SignInFailureClientLogin) {
508 manager_->Initialize(profile_.get()); 508 manager_->Initialize(profile_.get(), NULL);
509 manager_->StartSignIn("username", "password", std::string(), std::string()); 509 manager_->StartSignIn("username", "password", std::string(), std::string());
510 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED); 510 GoogleServiceAuthError error(GoogleServiceAuthError::REQUEST_CANCELED);
511 manager_->OnClientLoginFailure(error); 511 manager_->OnClientLoginFailure(error);
512 512
513 EXPECT_EQ(0U, google_login_success_.size()); 513 EXPECT_EQ(0U, google_login_success_.size());
514 EXPECT_EQ(1U, google_login_failure_.size()); 514 EXPECT_EQ(1U, google_login_failure_.size());
515 515
516 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 516 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
517 517
518 // Should not be persisted 518 // Should not be persisted
519 manager_->Shutdown(); 519 manager_->Shutdown();
520 manager_.reset(new SigninManager( 520 manager_.reset(new SigninManager(
521 scoped_ptr<SigninManagerDelegate>( 521 scoped_ptr<SigninManagerDelegate>(
522 new ChromeSigninManagerDelegate(profile_.get())))); 522 new ChromeSigninManagerDelegate(profile_.get()))));
523 manager_->Initialize(profile_.get()); 523 manager_->Initialize(profile_.get(), NULL);
524 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 524 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
525 } 525 }
526 526
527 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) { 527 TEST_F(SigninManagerTest, ProvideSecondFactorSuccess) {
528 manager_->Initialize(profile_.get()); 528 manager_->Initialize(profile_.get(), NULL);
529 manager_->StartSignIn("username", "password", std::string(), std::string()); 529 manager_->StartSignIn("username", "password", std::string(), std::string());
530 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR); 530 GoogleServiceAuthError error(GoogleServiceAuthError::TWO_FACTOR);
531 manager_->OnClientLoginFailure(error); 531 manager_->OnClientLoginFailure(error);
532 532
533 EXPECT_EQ(0U, google_login_success_.size()); 533 EXPECT_EQ(0U, google_login_success_.size());
534 EXPECT_EQ(1U, google_login_failure_.size()); 534 EXPECT_EQ(1U, google_login_failure_.size());
535 535
536 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 536 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
537 EXPECT_FALSE(manager_->possibly_invalid_username_.empty()); 537 EXPECT_FALSE(manager_->possibly_invalid_username_.empty());
538 538
539 manager_->ProvideSecondFactorAccessCode("access"); 539 manager_->ProvideSecondFactorAccessCode("access");
540 SimulateValidResponseClientLogin(false); 540 SimulateValidResponseClientLogin(false);
541 541
542 EXPECT_EQ(1U, google_login_success_.size()); 542 EXPECT_EQ(1U, google_login_success_.size());
543 EXPECT_EQ(1U, google_login_failure_.size()); 543 EXPECT_EQ(1U, google_login_failure_.size());
544 } 544 }
545 545
546 TEST_F(SigninManagerTest, ProvideSecondFactorFailure) { 546 TEST_F(SigninManagerTest, ProvideSecondFactorFailure) {
547 manager_->Initialize(profile_.get()); 547 manager_->Initialize(profile_.get(), NULL);
548 manager_->StartSignIn("username", "password", std::string(), std::string()); 548 manager_->StartSignIn("username", "password", std::string(), std::string());
549 GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR); 549 GoogleServiceAuthError error1(GoogleServiceAuthError::TWO_FACTOR);
550 manager_->OnClientLoginFailure(error1); 550 manager_->OnClientLoginFailure(error1);
551 551
552 EXPECT_EQ(0U, google_login_success_.size()); 552 EXPECT_EQ(0U, google_login_success_.size());
553 EXPECT_EQ(1U, google_login_failure_.size()); 553 EXPECT_EQ(1U, google_login_failure_.size());
554 554
555 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 555 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
556 EXPECT_FALSE(manager_->possibly_invalid_username_.empty()); 556 EXPECT_FALSE(manager_->possibly_invalid_username_.empty());
557 557
558 manager_->ProvideSecondFactorAccessCode("badaccess"); 558 manager_->ProvideSecondFactorAccessCode("badaccess");
559 GoogleServiceAuthError error2( 559 GoogleServiceAuthError error2(
560 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 560 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
561 manager_->OnClientLoginFailure(error2); 561 manager_->OnClientLoginFailure(error2);
562 562
563 EXPECT_EQ(0U, google_login_success_.size()); 563 EXPECT_EQ(0U, google_login_success_.size());
564 EXPECT_EQ(2U, google_login_failure_.size()); 564 EXPECT_EQ(2U, google_login_failure_.size());
565 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 565 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
566 566
567 manager_->ProvideSecondFactorAccessCode("badaccess"); 567 manager_->ProvideSecondFactorAccessCode("badaccess");
568 GoogleServiceAuthError error3(GoogleServiceAuthError::CONNECTION_FAILED); 568 GoogleServiceAuthError error3(GoogleServiceAuthError::CONNECTION_FAILED);
569 manager_->OnClientLoginFailure(error3); 569 manager_->OnClientLoginFailure(error3);
570 570
571 EXPECT_EQ(0U, google_login_success_.size()); 571 EXPECT_EQ(0U, google_login_success_.size());
572 EXPECT_EQ(3U, google_login_failure_.size()); 572 EXPECT_EQ(3U, google_login_failure_.size());
573 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 573 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
574 } 574 }
575 575
576 TEST_F(SigninManagerTest, SignOutMidConnect) { 576 TEST_F(SigninManagerTest, SignOutMidConnect) {
577 manager_->Initialize(profile_.get()); 577 manager_->Initialize(profile_.get(), NULL);
578 manager_->StartSignIn("username", "password", std::string(), std::string()); 578 manager_->StartSignIn("username", "password", std::string(), std::string());
579 EXPECT_EQ("username", manager_->GetUsernameForAuthInProgress()); 579 EXPECT_EQ("username", manager_->GetUsernameForAuthInProgress());
580 manager_->SignOut(); 580 manager_->SignOut();
581 EXPECT_EQ(0U, google_login_success_.size()); 581 EXPECT_EQ(0U, google_login_success_.size());
582 EXPECT_EQ(1U, google_login_failure_.size()); 582 EXPECT_EQ(1U, google_login_failure_.size());
583 583
584 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 584 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
585 EXPECT_TRUE(manager_->GetUsernameForAuthInProgress().empty()); 585 EXPECT_TRUE(manager_->GetUsernameForAuthInProgress().empty());
586 } 586 }
587 587
588 TEST_F(SigninManagerTest, SignOutWhileProhibited) { 588 TEST_F(SigninManagerTest, SignOutWhileProhibited) {
589 manager_->Initialize(profile_.get()); 589 manager_->Initialize(profile_.get(), NULL);
590 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 590 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
591 591
592 manager_->SetAuthenticatedUsername("user@gmail.com"); 592 manager_->SetAuthenticatedUsername("user@gmail.com");
593 manager_->ProhibitSignout(true); 593 manager_->ProhibitSignout(true);
594 manager_->SignOut(); 594 manager_->SignOut();
595 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty()); 595 EXPECT_FALSE(manager_->GetAuthenticatedUsername().empty());
596 manager_->ProhibitSignout(false); 596 manager_->ProhibitSignout(false);
597 manager_->SignOut(); 597 manager_->SignOut();
598 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty()); 598 EXPECT_TRUE(manager_->GetAuthenticatedUsername().empty());
599 } 599 }
(...skipping 11 matching lines...) Expand all
611 // chromiumsync is double-embedded in a continue query param. 611 // chromiumsync is double-embedded in a continue query param.
612 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL( 612 EXPECT_TRUE(SigninManager::IsWebBasedSigninFlowURL(
613 GURL("https://accounts.google.com/CheckCookie?" 613 GURL("https://accounts.google.com/CheckCookie?"
614 "continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen-US%2Fchrome" 614 "continue=https%3A%2F%2Fwww.google.com%2Fintl%2Fen-US%2Fchrome"
615 "%2Fblank.html%3Fsource%3D3%26nonadv%3D1&service=chromiumsync"))); 615 "%2Fblank.html%3Fsource%3D3%26nonadv%3D1&service=chromiumsync")));
616 } 616 }
617 617
618 TEST_F(SigninManagerTest, Prohibited) { 618 TEST_F(SigninManagerTest, Prohibited) {
619 g_browser_process->local_state()->SetString( 619 g_browser_process->local_state()->SetString(
620 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 620 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
621 manager_->Initialize(profile_.get()); 621 manager_->Initialize(profile_.get(), g_browser_process->local_state());
622 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); 622 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
623 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com")); 623 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com"));
624 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com")); 624 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com"));
625 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com")); 625 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com"));
626 EXPECT_FALSE(manager_->IsAllowedUsername(std::string())); 626 EXPECT_FALSE(manager_->IsAllowedUsername(std::string()));
627 } 627 }
628 628
629 TEST_F(SigninManagerTest, TestAlternateWildcard) { 629 TEST_F(SigninManagerTest, TestAlternateWildcard) {
630 // Test to make sure we accept "*@google.com" as a pattern (treat it as if 630 // Test to make sure we accept "*@google.com" as a pattern (treat it as if
631 // the admin entered ".*@google.com"). 631 // the admin entered ".*@google.com").
632 g_browser_process->local_state()->SetString( 632 g_browser_process->local_state()->SetString(
633 prefs::kGoogleServicesUsernamePattern, "*@google.com"); 633 prefs::kGoogleServicesUsernamePattern, "*@google.com");
634 manager_->Initialize(profile_.get()); 634 manager_->Initialize(profile_.get(), g_browser_process->local_state());
635 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com")); 635 EXPECT_TRUE(manager_->IsAllowedUsername("test@google.com"));
636 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com")); 636 EXPECT_TRUE(manager_->IsAllowedUsername("happy@google.com"));
637 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com")); 637 EXPECT_FALSE(manager_->IsAllowedUsername("test@invalid.com"));
638 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com")); 638 EXPECT_FALSE(manager_->IsAllowedUsername("test@notgoogle.com"));
639 EXPECT_FALSE(manager_->IsAllowedUsername(std::string())); 639 EXPECT_FALSE(manager_->IsAllowedUsername(std::string()));
640 } 640 }
641 641
642 TEST_F(SigninManagerTest, ProhibitedAtStartup) { 642 TEST_F(SigninManagerTest, ProhibitedAtStartup) {
643 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, 643 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername,
644 "monkey@invalid.com"); 644 "monkey@invalid.com");
645 g_browser_process->local_state()->SetString( 645 g_browser_process->local_state()->SetString(
646 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 646 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
647 manager_->Initialize(profile_.get()); 647 manager_->Initialize(profile_.get(), g_browser_process->local_state());
648 // Currently signed in user is prohibited by policy, so should be signed out. 648 // Currently signed in user is prohibited by policy, so should be signed out.
649 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); 649 EXPECT_EQ("", manager_->GetAuthenticatedUsername());
650 } 650 }
651 651
652 TEST_F(SigninManagerTest, ProhibitedAfterStartup) { 652 TEST_F(SigninManagerTest, ProhibitedAfterStartup) {
653 std::string user("monkey@invalid.com"); 653 std::string user("monkey@invalid.com");
654 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user); 654 profile_->GetPrefs()->SetString(prefs::kGoogleServicesUsername, user);
655 manager_->Initialize(profile_.get()); 655 manager_->Initialize(profile_.get(), g_browser_process->local_state());
656 EXPECT_EQ(user, manager_->GetAuthenticatedUsername()); 656 EXPECT_EQ(user, manager_->GetAuthenticatedUsername());
657 // Update the profile - user should be signed out. 657 // Update the profile - user should be signed out.
658 g_browser_process->local_state()->SetString( 658 g_browser_process->local_state()->SetString(
659 prefs::kGoogleServicesUsernamePattern, ".*@google.com"); 659 prefs::kGoogleServicesUsernamePattern, ".*@google.com");
660 EXPECT_EQ("", manager_->GetAuthenticatedUsername()); 660 EXPECT_EQ("", manager_->GetAuthenticatedUsername());
661 } 661 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/signin_manager_factory.cc ('k') | chrome/browser/signin/signin_tracker_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698