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

Side by Side Diff: chrome/browser/policy/cloud/user_policy_signin_service_unittest.cc

Issue 964563002: Replace SetAuthenticatedUsername with SetAuthenticatedAccountId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@priv
Patch Set: rebased Created 5 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
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_path.h" 5 #include "base/files/file_path.h"
6 #include "base/message_loop/message_loop.h" 6 #include "base/message_loop/message_loop.h"
7 #include "base/message_loop/message_loop_proxy.h" 7 #include "base/message_loop/message_loop_proxy.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 namespace em = enterprise_management; 58 namespace em = enterprise_management;
59 59
60 using testing::AnyNumber; 60 using testing::AnyNumber;
61 using testing::Mock; 61 using testing::Mock;
62 using testing::_; 62 using testing::_;
63 63
64 namespace policy { 64 namespace policy {
65 65
66 namespace { 66 namespace {
67 67
68 const char kTestGaiaId[] = "gaia-id-testuser@test.com";
68 const char kTestUser[] = "testuser@test.com"; 69 const char kTestUser[] = "testuser@test.com";
69 70
70 #if !defined(OS_ANDROID) 71 #if !defined(OS_ANDROID)
71 const char kValidTokenResponse[] = 72 const char kValidTokenResponse[] =
72 "{" 73 "{"
73 " \"access_token\": \"at1\"," 74 " \"access_token\": \"at1\","
74 " \"expires_in\": 3600," 75 " \"expires_in\": 3600,"
75 " \"token_type\": \"Bearer\"" 76 " \"token_type\": \"Bearer\""
76 "}"; 77 "}";
77 #endif 78 #endif
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
127 register_completed_ = true; 128 register_completed_ = true;
128 dm_token_ = dm_token; 129 dm_token_ = dm_token;
129 client_id_ = client_id; 130 client_id_ = client_id;
130 } 131 }
131 132
132 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) { 133 void RegisterPolicyClientWithCallback(UserPolicySigninService* service) {
133 // Policy client registration on Android depends on Token Service having 134 // Policy client registration on Android depends on Token Service having
134 // a valid login token, while on other platforms, the login refresh token 135 // a valid login token, while on other platforms, the login refresh token
135 // is specified directly. 136 // is specified directly.
136 #if defined(OS_ANDROID) 137 #if defined(OS_ANDROID)
137 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 138 GetTokenService()->IssueRefreshTokenForUser(
138 "oauth2_login_refresh_token"); 139 SigninManagerFactory::GetForProfile(profile_.get())
140 ->GetAuthenticatedAccountId(),
141 "oauth2_login_refresh_token");
139 #endif 142 #endif
140 service->RegisterForPolicy( 143 service->RegisterForPolicy(
141 kTestUser, 144 kTestUser,
142 #if !defined(OS_ANDROID) 145 #if !defined(OS_ANDROID)
143 "mock_oauth_token", 146 "mock_oauth_token",
144 #endif 147 #endif
145 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted, 148 base::Bind(&UserPolicySigninServiceTest::OnRegisterCompleted,
146 base::Unretained(this))); 149 base::Unretained(this)));
147 ASSERT_TRUE(IsRequestActive()); 150 ASSERT_TRUE(IsRequestActive());
148 } 151 }
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 }; 386 };
384 387
385 class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest { 388 class UserPolicySigninServiceSignedInTest : public UserPolicySigninServiceTest {
386 public: 389 public:
387 void AddProfile() override { 390 void AddProfile() override {
388 // UserCloudPolicyManager should not be initialized. 391 // UserCloudPolicyManager should not be initialized.
389 ASSERT_FALSE(manager_->core()->service()); 392 ASSERT_FALSE(manager_->core()->service());
390 393
391 // Set the user as signed in. 394 // Set the user as signed in.
392 SigninManagerFactory::GetForProfile(profile_.get())-> 395 SigninManagerFactory::GetForProfile(profile_.get())->
393 SetAuthenticatedUsername(kTestUser); 396 SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
394 397
395 // Let the SigninService know that the profile has been created. 398 // Let the SigninService know that the profile has been created.
396 content::NotificationService::current()->Notify( 399 content::NotificationService::current()->Notify(
397 chrome::NOTIFICATION_PROFILE_ADDED, 400 chrome::NOTIFICATION_PROFILE_ADDED,
398 content::Source<Profile>(profile_.get()), 401 content::Source<Profile>(profile_.get()),
399 content::NotificationService::NoDetails()); 402 content::NotificationService::NoDetails());
400 } 403 }
401 }; 404 };
402 405
403 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) { 406 TEST_F(UserPolicySigninServiceTest, InitWhileSignedOut) {
(...skipping 14 matching lines...) Expand all
418 // UserCloudPolicyManager should be initialized. 421 // UserCloudPolicyManager should be initialized.
419 ASSERT_TRUE(manager_->core()->service()); 422 ASSERT_TRUE(manager_->core()->service());
420 423
421 // Complete initialization of the store. 424 // Complete initialization of the store.
422 mock_store_->NotifyStoreLoaded(); 425 mock_store_->NotifyStoreLoaded();
423 426
424 // No oauth access token yet, so client registration should be deferred. 427 // No oauth access token yet, so client registration should be deferred.
425 ASSERT_FALSE(IsRequestActive()); 428 ASSERT_FALSE(IsRequestActive());
426 429
427 // Make oauth token available. 430 // Make oauth token available.
428 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 431 GetTokenService()->IssueRefreshTokenForUser(
429 "oauth_login_refresh_token"); 432 SigninManagerFactory::GetForProfile(profile_.get())
433 ->GetAuthenticatedAccountId(),
434 "oauth_login_refresh_token");
430 435
431 // Client registration should be in progress since we now have an oauth token. 436 // Client registration should be in progress since we now have an oauth token.
432 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 437 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
433 ASSERT_TRUE(IsRequestActive()); 438 ASSERT_TRUE(IsRequestActive());
434 } 439 }
435 440
436 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) { 441 TEST_F(UserPolicySigninServiceSignedInTest, InitWhileSignedInOAuthError) {
437 // UserCloudPolicyManager should be initialized. 442 // UserCloudPolicyManager should be initialized.
438 ASSERT_TRUE(manager_->core()->service()); 443 ASSERT_TRUE(manager_->core()->service());
439 444
440 // Complete initialization of the store. 445 // Complete initialization of the store.
441 mock_store_->NotifyStoreLoaded(); 446 mock_store_->NotifyStoreLoaded();
442 447
443 // No oauth access token yet, so client registration should be deferred. 448 // No oauth access token yet, so client registration should be deferred.
444 ASSERT_FALSE(IsRequestActive()); 449 ASSERT_FALSE(IsRequestActive());
445 450
446 // Make oauth token available. 451 // Make oauth token available.
447 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 452 GetTokenService()->IssueRefreshTokenForUser(
448 "oauth_login_refresh_token"); 453 SigninManagerFactory::GetForProfile(profile_.get())
454 ->GetAuthenticatedAccountId(),
455 "oauth_login_refresh_token");
449 456
450 // Client registration should be in progress since we now have an oauth token. 457 // Client registration should be in progress since we now have an oauth token.
451 ASSERT_TRUE(IsRequestActive()); 458 ASSERT_TRUE(IsRequestActive());
452 459
453 // Now fail the access token fetch. 460 // Now fail the access token fetch.
454 GoogleServiceAuthError error( 461 GoogleServiceAuthError error(
455 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); 462 GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS);
456 GetTokenService()->IssueErrorForAllPendingRequests(error); 463 GetTokenService()->IssueErrorForAllPendingRequests(error);
457 ASSERT_FALSE(IsRequestActive()); 464 ASSERT_FALSE(IsRequestActive());
458 } 465 }
459 466
460 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) { 467 TEST_F(UserPolicySigninServiceTest, SignInAfterInit) {
461 // UserCloudPolicyManager should not be initialized since there is no 468 // UserCloudPolicyManager should not be initialized since there is no
462 // signed-in user. 469 // signed-in user.
463 ASSERT_FALSE(manager_->core()->service()); 470 ASSERT_FALSE(manager_->core()->service());
464 471
465 // Now sign in the user. 472 // Now sign in the user.
466 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 473 SigninManagerFactory::GetForProfile(profile_.get())
467 kTestUser); 474 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
468 475
469 // Complete initialization of the store. 476 // Complete initialization of the store.
470 mock_store_->NotifyStoreLoaded(); 477 mock_store_->NotifyStoreLoaded();
471 478
472 // Make oauth token available. 479 // Make oauth token available.
473 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 480 GetTokenService()->IssueRefreshTokenForUser(
474 "oauth_login_refresh_token"); 481 SigninManagerFactory::GetForProfile(profile_.get())
482 ->GetAuthenticatedAccountId(),
483 "oauth_login_refresh_token");
475 484
476 // UserCloudPolicyManager should be initialized. 485 // UserCloudPolicyManager should be initialized.
477 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 486 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
478 ASSERT_TRUE(manager_->core()->service()); 487 ASSERT_TRUE(manager_->core()->service());
479 488
480 // Client registration should be in progress since we have an oauth token. 489 // Client registration should be in progress since we have an oauth token.
481 ASSERT_TRUE(IsRequestActive()); 490 ASSERT_TRUE(IsRequestActive());
482 } 491 }
483 492
484 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) { 493 TEST_F(UserPolicySigninServiceTest, SignInWithNonEnterpriseUser) {
485 // UserCloudPolicyManager should not be initialized since there is no 494 // UserCloudPolicyManager should not be initialized since there is no
486 // signed-in user. 495 // signed-in user.
487 ASSERT_FALSE(manager_->core()->service()); 496 ASSERT_FALSE(manager_->core()->service());
488 497
489 // Now sign in a non-enterprise user (blacklisted gmail.com domain). 498 // Now sign in a non-enterprise user (blacklisted gmail.com domain).
490 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 499 SigninManagerFactory::GetForProfile(profile_.get())
491 "non_enterprise_user@gmail.com"); 500 ->SetAuthenticatedAccountInfo("gaia-id-non_enterprise_user@gmail.com",
501 "non_enterprise_user@gmail.com");
492 502
493 // Complete initialization of the store. 503 // Complete initialization of the store.
494 mock_store_->NotifyStoreLoaded(); 504 mock_store_->NotifyStoreLoaded();
495 505
496 // Make oauth token available. 506 // Make oauth token available.
497 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 507 GetTokenService()->IssueRefreshTokenForUser(
498 "oauth_login_refresh_token"); 508 SigninManagerFactory::GetForProfile(profile_.get())
509 ->GetAuthenticatedAccountId(),
510 "oauth_login_refresh_token");
499 511
500 // UserCloudPolicyManager should not be initialized and there should be no 512 // UserCloudPolicyManager should not be initialized and there should be no
501 // DMToken request active. 513 // DMToken request active.
502 ASSERT_TRUE(!manager_->core()->service()); 514 ASSERT_TRUE(!manager_->core()->service());
503 ASSERT_FALSE(IsRequestActive()); 515 ASSERT_FALSE(IsRequestActive());
504 } 516 }
505 517
506 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) { 518 TEST_F(UserPolicySigninServiceTest, UnregisteredClient) {
507 // UserCloudPolicyManager should not be initialized since there is no 519 // UserCloudPolicyManager should not be initialized since there is no
508 // signed-in user. 520 // signed-in user.
509 ASSERT_FALSE(manager_->core()->service()); 521 ASSERT_FALSE(manager_->core()->service());
510 522
511 // Now sign in the user. 523 // Now sign in the user.
512 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 524 SigninManagerFactory::GetForProfile(profile_.get())
513 kTestUser); 525 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
514 526
515 // Make oauth token available. 527 // Make oauth token available.
516 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 528 GetTokenService()->IssueRefreshTokenForUser(
517 "oauth_login_refresh_token"); 529 SigninManagerFactory::GetForProfile(profile_.get())
530 ->GetAuthenticatedAccountId(),
531 "oauth_login_refresh_token");
518 532
519 // UserCloudPolicyManager should be initialized. 533 // UserCloudPolicyManager should be initialized.
520 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 534 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
521 ASSERT_TRUE(manager_->core()->service()); 535 ASSERT_TRUE(manager_->core()->service());
522 536
523 // Client registration should not be in progress since the store is not 537 // Client registration should not be in progress since the store is not
524 // yet initialized. 538 // yet initialized.
525 ASSERT_FALSE(IsRequestActive()); 539 ASSERT_FALSE(IsRequestActive());
526 540
527 // Complete initialization of the store with no policy (unregistered client). 541 // Complete initialization of the store with no policy (unregistered client).
528 mock_store_->NotifyStoreLoaded(); 542 mock_store_->NotifyStoreLoaded();
529 543
530 // Client registration should be in progress since we have an oauth token. 544 // Client registration should be in progress since we have an oauth token.
531 ASSERT_TRUE(IsRequestActive()); 545 ASSERT_TRUE(IsRequestActive());
532 } 546 }
533 547
534 TEST_F(UserPolicySigninServiceTest, RegisteredClient) { 548 TEST_F(UserPolicySigninServiceTest, RegisteredClient) {
535 // UserCloudPolicyManager should not be initialized since there is no 549 // UserCloudPolicyManager should not be initialized since there is no
536 // signed-in user. 550 // signed-in user.
537 ASSERT_FALSE(manager_->core()->service()); 551 ASSERT_FALSE(manager_->core()->service());
538 552
539 // Now sign in the user. 553 // Now sign in the user.
540 SigninManagerFactory::GetForProfile(profile_.get())->SetAuthenticatedUsername( 554 SigninManagerFactory::GetForProfile(profile_.get())
541 kTestUser); 555 ->SetAuthenticatedAccountInfo(kTestGaiaId, kTestUser);
542 556
543 // Make oauth token available. 557 // Make oauth token available.
544 GetTokenService()->IssueRefreshTokenForUser(kTestUser, 558 GetTokenService()->IssueRefreshTokenForUser(
545 "oauth_login_refresh_token"); 559 SigninManagerFactory::GetForProfile(profile_.get())
560 ->GetAuthenticatedAccountId(),
561 "oauth_login_refresh_token");
546 562
547 // UserCloudPolicyManager should be initialized. 563 // UserCloudPolicyManager should be initialized.
548 EXPECT_EQ(mock_store_->signin_username_, kTestUser); 564 EXPECT_EQ(mock_store_->signin_username_, kTestUser);
549 ASSERT_TRUE(manager_->core()->service()); 565 ASSERT_TRUE(manager_->core()->service());
550 566
551 // Client registration should not be in progress since the store is not 567 // Client registration should not be in progress since the store is not
552 // yet initialized. 568 // yet initialized.
553 ASSERT_FALSE(manager_->IsClientRegistered()); 569 ASSERT_FALSE(manager_->IsClientRegistered());
554 ASSERT_FALSE(IsRequestActive()); 570 ASSERT_FALSE(IsRequestActive());
555 571
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 base::RunLoop().RunUntilIdle(); 830 base::RunLoop().RunUntilIdle();
815 EXPECT_FALSE(manager_->IsClientRegistered()); 831 EXPECT_FALSE(manager_->IsClientRegistered());
816 #if !defined(OS_ANDROID) 832 #if !defined(OS_ANDROID)
817 EXPECT_FALSE(signin_manager_->IsSignoutProhibited()); 833 EXPECT_FALSE(signin_manager_->IsSignoutProhibited());
818 #endif 834 #endif
819 } 835 }
820 836
821 } // namespace 837 } // namespace
822 838
823 } // namespace policy 839 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698