Commit c5dd68a2 authored by Antonio Gomes's avatar Antonio Gomes Committed by Commit Bot

[s13n] Convert c/b/signin/dice_response_handler_unittest.cc to IdentityManager

This CL is a follow up of [1], where production code was migrated away
from using SigninManager APIs directly, in favor of IdentityManager
(//services/identity). This is done as part of the servicification effort.

After this CL, the last remaining step will be converting DiceResponseHandler
(production code) away from using ProfileOAuth2TokenService directly,
blocked of crbug.com/887870.

[1] https://crrev.com/c/1318550

BUG=890790

Change-Id: Ifc54410bd7112c1e2fae01d6770ab6afa002481d
Reviewed-on: https://chromium-review.googlesource.com/c/1316927
Commit-Queue: Antonio Gomes <tonikitoo@igalia.com>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608684}
parent 5cddb472
...@@ -45,7 +45,9 @@ namespace { ...@@ -45,7 +45,9 @@ namespace {
const char kAuthorizationCode[] = "authorization_code"; const char kAuthorizationCode[] = "authorization_code";
const char kEmail[] = "email"; const char kEmail[] = "email";
const char kGaiaID[] = "gaia_id"; const char kGaiaID[] = "gaia_id_for_email"; // This matches the gaia_id value
// to be used by
// IdentityTestEnvironment.
const int kSessionIndex = 42; const int kSessionIndex = 42;
// TestSigninClient implementation that intercepts the GaiaAuthConsumer and // TestSigninClient implementation that intercepts the GaiaAuthConsumer and
...@@ -224,6 +226,10 @@ class DiceResponseHandlerTest : public testing::Test, ...@@ -224,6 +226,10 @@ class DiceResponseHandlerTest : public testing::Test,
void OnBlockReconcile() override { ++reconcilor_blocked_count_; } void OnBlockReconcile() override { ++reconcilor_blocked_count_; }
void OnUnblockReconcile() override { ++reconcilor_unblocked_count_; } void OnUnblockReconcile() override { ++reconcilor_unblocked_count_; }
identity::IdentityManager* identity_manager() {
return identity_test_env_.identity_manager();
}
base::MessageLoop loop_; base::MessageLoop loop_;
base::ScopedTempDir temp_dir_; base::ScopedTempDir temp_dir_;
scoped_refptr<base::TestMockTimeTaskRunner> task_runner_; scoped_refptr<base::TestMockTimeTaskRunner> task_runner_;
...@@ -274,7 +280,7 @@ TEST_F(DiceResponseHandlerTest, Signin) { ...@@ -274,7 +280,7 @@ TEST_F(DiceResponseHandlerTest, Signin) {
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
...@@ -287,7 +293,7 @@ TEST_F(DiceResponseHandlerTest, Signin) { ...@@ -287,7 +293,7 @@ TEST_F(DiceResponseHandlerTest, Signin) {
false /* is_child_account */, false /* is_child_account */,
true /* is_advanced_protection*/)); true /* is_advanced_protection*/));
// Check that the token has been inserted in the token service. // Check that the token has been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_TRUE(auth_error_email_.empty()); EXPECT_TRUE(auth_error_email_.empty());
EXPECT_EQ(GoogleServiceAuthError::NONE, auth_error_.state()); EXPECT_EQ(GoogleServiceAuthError::NONE, auth_error_.state());
// Check that the reconcilor was blocked and unblocked exactly once. // Check that the reconcilor was blocked and unblocked exactly once.
...@@ -305,7 +311,7 @@ TEST_F(DiceResponseHandlerTest, SigninFailure) { ...@@ -305,7 +311,7 @@ TEST_F(DiceResponseHandlerTest, SigninFailure) {
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
...@@ -320,7 +326,7 @@ TEST_F(DiceResponseHandlerTest, SigninFailure) { ...@@ -320,7 +326,7 @@ TEST_F(DiceResponseHandlerTest, SigninFailure) {
EXPECT_EQ( EXPECT_EQ(
0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting()); 0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting());
// Check that the token has not been inserted in the token service. // Check that the token has not been inserted in the token service.
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_EQ(account_info.email, auth_error_email_); EXPECT_EQ(account_info.email, auth_error_email_);
EXPECT_EQ(error_state, auth_error_.state()); EXPECT_EQ(error_state, auth_error_.state());
} }
...@@ -333,7 +339,7 @@ TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) { ...@@ -333,7 +339,7 @@ TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) {
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
...@@ -350,7 +356,7 @@ TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) { ...@@ -350,7 +356,7 @@ TEST_F(DiceResponseHandlerTest, SigninRepeatedWithSameAccount) {
"refresh_token", "access_token", 10, false /* is_child_account */, "refresh_token", "access_token", 10, false /* is_child_account */,
false /* is_advanced_protection*/)); false /* is_advanced_protection*/));
// Check that the token has been inserted in the token service. // Check that the token has been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_FALSE(account_tracker_service_.GetAccountInfo(account_id) EXPECT_FALSE(account_tracker_service_.GetAccountInfo(account_id)
.is_under_advanced_protection); .is_under_advanced_protection);
} }
...@@ -368,8 +374,8 @@ TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) { ...@@ -368,8 +374,8 @@ TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) {
account_info_1.gaia_id, account_info_1.email); account_info_1.gaia_id, account_info_1.email);
std::string account_id_2 = account_tracker_service_.PickAccountIdForAccount( std::string account_id_2 = account_tracker_service_.PickAccountIdForAccount(
account_info_2.gaia_id, account_info_2.email); account_info_2.gaia_id, account_info_2.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id_1)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id_1));
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id_2)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id_2));
// Start first request. // Start first request.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params_1, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params_1, std::make_unique<TestProcessDiceHeaderDelegate>(this));
...@@ -389,7 +395,7 @@ TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) { ...@@ -389,7 +395,7 @@ TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) {
"refresh_token", "access_token", 10, false /* is_child_account */, "refresh_token", "access_token", 10, false /* is_child_account */,
true /* is_advanced_protection*/)); true /* is_advanced_protection*/));
// Check that the token has been inserted in the token service. // Check that the token has been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id_1)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id_1));
EXPECT_TRUE(account_tracker_service_.GetAccountInfo(account_id_1) EXPECT_TRUE(account_tracker_service_.GetAccountInfo(account_id_1)
.is_under_advanced_protection); .is_under_advanced_protection);
// Simulate GaiaAuthFetcher success for the second request. // Simulate GaiaAuthFetcher success for the second request.
...@@ -397,7 +403,7 @@ TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) { ...@@ -397,7 +403,7 @@ TEST_F(DiceResponseHandlerTest, SigninWithTwoAccounts) {
"refresh_token", "access_token", 10, false /* is_child_account */, "refresh_token", "access_token", 10, false /* is_child_account */,
false /* is_advanced_protection*/)); false /* is_advanced_protection*/));
// Check that the token has been inserted in the token service. // Check that the token has been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id_2)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id_2));
EXPECT_FALSE(account_tracker_service_.GetAccountInfo(account_id_2) EXPECT_FALSE(account_tracker_service_.GetAccountInfo(account_id_2)
.is_under_advanced_protection); .is_under_advanced_protection);
// Check that the reconcilor was blocked and unblocked exactly once. // Check that the reconcilor was blocked and unblocked exactly once.
...@@ -413,7 +419,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncAfterRefreshTokenFetched) { ...@@ -413,7 +419,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncAfterRefreshTokenFetched) {
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
...@@ -424,7 +430,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncAfterRefreshTokenFetched) { ...@@ -424,7 +430,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncAfterRefreshTokenFetched) {
false /* is_child_account */, false /* is_child_account */,
false /* is_advanced_protection*/)); false /* is_advanced_protection*/));
// Check that the token has been inserted in the token service. // Check that the token has been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id));
// Check that delegate was not called to enable sync. // Check that delegate was not called to enable sync.
EXPECT_EQ("", enable_sync_account_id_); EXPECT_EQ("", enable_sync_account_id_);
...@@ -445,7 +451,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncBeforeRefreshTokenFetched) { ...@@ -445,7 +451,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncBeforeRefreshTokenFetched) {
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
...@@ -464,7 +470,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncBeforeRefreshTokenFetched) { ...@@ -464,7 +470,7 @@ TEST_F(DiceResponseHandlerTest, SigninEnableSyncBeforeRefreshTokenFetched) {
false /* is_child_account */, false /* is_child_account */,
false /* is_advanced_protection*/)); false /* is_advanced_protection*/));
// Check that the token has been inserted in the token service. // Check that the token has been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id));
// Check that delegate was called to enable sync. // Check that delegate was called to enable sync.
EXPECT_EQ(account_id, enable_sync_account_id_); EXPECT_EQ(account_id, enable_sync_account_id_);
} }
...@@ -475,7 +481,7 @@ TEST_F(DiceResponseHandlerTest, Timeout) { ...@@ -475,7 +481,7 @@ TEST_F(DiceResponseHandlerTest, Timeout) {
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
...@@ -488,7 +494,7 @@ TEST_F(DiceResponseHandlerTest, Timeout) { ...@@ -488,7 +494,7 @@ TEST_F(DiceResponseHandlerTest, Timeout) {
EXPECT_EQ( EXPECT_EQ(
0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting()); 0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting());
// Check that the token has not been inserted in the token service. // Check that the token has not been inserted in the token service.
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
// Check that the reconcilor was blocked and unblocked exactly once. // Check that the reconcilor was blocked and unblocked exactly once.
EXPECT_EQ(1, reconcilor_blocked_count_); EXPECT_EQ(1, reconcilor_blocked_count_);
EXPECT_EQ(1, reconcilor_unblocked_count_); EXPECT_EQ(1, reconcilor_unblocked_count_);
...@@ -499,31 +505,34 @@ TEST_F(DiceResponseHandlerTest, SignoutMainAccount) { ...@@ -499,31 +505,34 @@ TEST_F(DiceResponseHandlerTest, SignoutMainAccount) {
const char kSecondaryGaiaID[] = "secondary_account"; const char kSecondaryGaiaID[] = "secondary_account";
const char kSecondaryEmail[] = "other@gmail.com"; const char kSecondaryEmail[] = "other@gmail.com";
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT);
const auto& account_info = dice_params.signout_info->account_infos[0]; const auto& dice_account_info = dice_params.signout_info->account_infos[0];
std::string account_id = account_tracker_service_.SeedAccountInfo(
account_info.gaia_id, account_info.email);
std::string secondary_account_id = account_tracker_service_.SeedAccountInfo( std::string secondary_account_id = account_tracker_service_.SeedAccountInfo(
kSecondaryGaiaID, kSecondaryEmail); kSecondaryGaiaID, kSecondaryEmail);
// User is signed in to Chrome, and has some refresh token for a secondary // User is signed in to Chrome, and has some refresh token for a secondary
// account. // account.
signin_manager_.SignIn(account_info.gaia_id, account_info.email, "password"); AccountInfo account_info =
token_service_.UpdateCredentials(account_id, "token1"); identity_test_env_.MakePrimaryAccountAvailable(dice_account_info.email);
token_service_.UpdateCredentials(secondary_account_id, "token2"); identity_test_env_.SetRefreshTokenForAccount(secondary_account_id);
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(kSecondaryGaiaID)); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(signin_manager_.IsAuthenticated()); EXPECT_TRUE(
identity_manager()->HasAccountWithRefreshToken(secondary_account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
// Receive signout response for the main account. // Receive signout response for the main account.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// User is not signed out, token for the main account is now invalid, // User is not signed out, token for the main account is now invalid,
// secondary account is untouched. // secondary account is untouched.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_EQ(MutableProfileOAuth2TokenServiceDelegate::kInvalidRefreshToken, EXPECT_EQ(MutableProfileOAuth2TokenServiceDelegate::kInvalidRefreshToken,
GetRefreshToken(account_id)); GetRefreshToken(account_info.account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(kSecondaryGaiaID)); EXPECT_TRUE(
EXPECT_EQ("token2", GetRefreshToken(kSecondaryGaiaID)); identity_manager()->HasAccountWithRefreshToken(secondary_account_id));
EXPECT_TRUE(signin_manager_.IsAuthenticated()); EXPECT_EQ(std::string("refresh_token_for_") + secondary_account_id,
GetRefreshToken(secondary_account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
// Check that the reconcilor was not blocked. // Check that the reconcilor was not blocked.
EXPECT_EQ(0, reconcilor_blocked_count_); EXPECT_EQ(0, reconcilor_blocked_count_);
EXPECT_EQ(0, reconcilor_unblocked_count_); EXPECT_EQ(0, reconcilor_unblocked_count_);
...@@ -538,29 +547,30 @@ TEST_F(DiceResponseHandlerTest, MigrationSignout) { ...@@ -538,29 +547,30 @@ TEST_F(DiceResponseHandlerTest, MigrationSignout) {
dice_params.signout_info->account_infos.emplace_back(kSecondaryGaiaID, dice_params.signout_info->account_infos.emplace_back(kSecondaryGaiaID,
kSecondaryEmail, 1); kSecondaryEmail, 1);
const auto& main_account_info = dice_params.signout_info->account_infos[0]; const auto& main_account_info = dice_params.signout_info->account_infos[0];
std::string account_id = account_tracker_service_.SeedAccountInfo(
main_account_info.gaia_id, main_account_info.email);
std::string secondary_account_id = account_tracker_service_.SeedAccountInfo( std::string secondary_account_id = account_tracker_service_.SeedAccountInfo(
kSecondaryGaiaID, kSecondaryEmail); kSecondaryGaiaID, kSecondaryEmail);
// User is signed in to Chrome, and has some refresh token for a secondary // User is signed in to Chrome, and has some refresh token for a secondary
// account. // account.
signin_manager_.SignIn(main_account_info.gaia_id, main_account_info.email, AccountInfo account_info =
"password"); identity_test_env_.MakePrimaryAccountAvailable(main_account_info.email);
token_service_.UpdateCredentials(account_id, "token1"); identity_test_env_.SetRefreshTokenForAccount(secondary_account_id);
token_service_.UpdateCredentials(secondary_account_id, "token2"); EXPECT_TRUE(
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(secondary_account_id)); EXPECT_TRUE(
EXPECT_TRUE(signin_manager_.IsAuthenticated()); identity_manager()->HasAccountWithRefreshToken(secondary_account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
// Receive signout response for all accounts. // Receive signout response for all accounts.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// User is not signed out from Chrome, only the secondary token is deleted. // User is not signed out from Chrome, only the secondary token is deleted.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(secondary_account_id)); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(signin_manager_.IsAuthenticated()); EXPECT_FALSE(
identity_manager()->HasAccountWithRefreshToken(secondary_account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
// Check that the reconcilor was not blocked. // Check that the reconcilor was not blocked.
EXPECT_EQ(0, reconcilor_blocked_count_); EXPECT_EQ(0, reconcilor_blocked_count_);
EXPECT_EQ(0, reconcilor_unblocked_count_); EXPECT_EQ(0, reconcilor_unblocked_count_);
...@@ -568,71 +578,74 @@ TEST_F(DiceResponseHandlerTest, MigrationSignout) { ...@@ -568,71 +578,74 @@ TEST_F(DiceResponseHandlerTest, MigrationSignout) {
TEST_F(DiceResponseHandlerTest, SignoutSecondaryAccount) { TEST_F(DiceResponseHandlerTest, SignoutSecondaryAccount) {
InitializeDiceResponseHandler(signin::AccountConsistencyMethod::kDice); InitializeDiceResponseHandler(signin::AccountConsistencyMethod::kDice);
const char kMainGaiaID[] = "main_account";
const char kMainEmail[] = "main@gmail.com"; const char kMainEmail[] = "main@gmail.com";
std::string main_account_id =
account_tracker_service_.SeedAccountInfo(kMainGaiaID, kMainEmail);
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT);
const auto& account_info = dice_params.signout_info->account_infos[0]; const auto& account_info = dice_params.signout_info->account_infos[0];
std::string account_id = account_tracker_service_.SeedAccountInfo( std::string account_id = account_tracker_service_.SeedAccountInfo(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
// User is signed in to Chrome, and has some refresh token for a secondary // User is signed in to Chrome, and has some refresh token for a secondary
// account. // account.
signin_manager_.SignIn(kMainGaiaID, "user", "password"); auto main_account_info =
token_service_.UpdateCredentials(main_account_id, "token2"); identity_test_env_.MakePrimaryAccountAvailable(kMainEmail);
token_service_.UpdateCredentials(account_id, "token1"); identity_test_env_.SetRefreshTokenForAccount(account_id);
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(main_account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(
EXPECT_TRUE(signin_manager_.IsAuthenticated()); main_account_info.account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
// Receive signout response for the secondary account. // Receive signout response for the secondary account.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Only the token corresponding the the Dice parameter has been removed, and // Only the token corresponding the the Dice parameter has been removed, and
// the user is still signed in. // the user is still signed in.
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(main_account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(
EXPECT_TRUE(signin_manager_.IsAuthenticated()); main_account_info.account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
} }
TEST_F(DiceResponseHandlerTest, SignoutWebOnly) { TEST_F(DiceResponseHandlerTest, SignoutWebOnly) {
InitializeDiceResponseHandler(signin::AccountConsistencyMethod::kDice); InitializeDiceResponseHandler(signin::AccountConsistencyMethod::kDice);
const char kSecondaryAccountID[] = "secondary_account"; const char kSecondaryGaiaID[] = "secondary_account";
const char kSecondaryEmail[] = "other@gmail.com"; const char kSecondaryEmail[] = "other@gmail.com";
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT);
const auto& account_info = dice_params.signout_info->account_infos[0]; const auto& account_info = dice_params.signout_info->account_infos[0];
std::string account_id = account_tracker_service_.SeedAccountInfo( std::string account_id = account_tracker_service_.SeedAccountInfo(
account_info.gaia_id, account_info.email); account_info.gaia_id, account_info.email);
std::string secondary_account_id = account_tracker_service_.SeedAccountInfo( std::string secondary_account_id = account_tracker_service_.SeedAccountInfo(
kSecondaryAccountID, kSecondaryEmail); kSecondaryGaiaID, kSecondaryEmail);
// User is NOT signed in to Chrome, and has some refresh tokens for two // User is NOT signed in to Chrome, and has some refresh tokens for two
// accounts. // accounts.
token_service_.UpdateCredentials(account_id, "refresh_token"); identity_test_env_.SetRefreshTokenForAccount(account_id);
token_service_.UpdateCredentials(secondary_account_id, "refresh_token"); identity_test_env_.SetRefreshTokenForAccount(secondary_account_id);
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(kSecondaryAccountID)); EXPECT_TRUE(
EXPECT_FALSE(signin_manager_.IsAuthenticated()); identity_manager()->HasAccountWithRefreshToken(secondary_account_id));
EXPECT_FALSE(identity_manager()->HasPrimaryAccount());
// Receive signout response. // Receive signout response.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Only the token corresponding the the Dice parameter has been removed. // Only the token corresponding the the Dice parameter has been removed.
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(kSecondaryAccountID)); EXPECT_TRUE(
EXPECT_FALSE(signin_manager_.IsAuthenticated()); identity_manager()->HasAccountWithRefreshToken(secondary_account_id));
EXPECT_FALSE(identity_manager()->HasPrimaryAccount());
} }
// Checks that signin in progress is canceled by a signout. // Checks that signin in progress is canceled by a signout.
TEST_F(DiceResponseHandlerTest, SigninSignoutSameAccount) { TEST_F(DiceResponseHandlerTest, SigninSignoutSameAccount) {
InitializeDiceResponseHandler(signin::AccountConsistencyMethod::kDice); InitializeDiceResponseHandler(signin::AccountConsistencyMethod::kDice);
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT);
const auto& account_info = dice_params.signout_info->account_infos[0]; const auto& dice_account_info = dice_params.signout_info->account_infos[0];
std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email);
// User is signed in to Chrome. // User is signed in to Chrome.
signin_manager_.SignIn(account_info.gaia_id, account_info.email, "password"); AccountInfo account_info =
token_service_.UpdateCredentials(account_id, "token"); identity_test_env_.MakePrimaryAccountAvailable(dice_account_info.email);
ASSERT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
ASSERT_FALSE(token_service_.RefreshTokenHasError(account_id)); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_FALSE(
identity_manager()->HasAccountWithRefreshTokenInPersistentErrorState(
account_info.account_id));
// Start Dice signin (reauth). // Start Dice signin (reauth).
DiceResponseParams dice_params_2 = MakeDiceParams(DiceAction::SIGNIN); DiceResponseParams dice_params_2 = MakeDiceParams(DiceAction::SIGNIN);
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
...@@ -647,9 +660,10 @@ TEST_F(DiceResponseHandlerTest, SigninSignoutSameAccount) { ...@@ -647,9 +660,10 @@ TEST_F(DiceResponseHandlerTest, SigninSignoutSameAccount) {
// Check that the token fetcher has been canceled and the token is invalid. // Check that the token fetcher has been canceled and the token is invalid.
EXPECT_EQ( EXPECT_EQ(
0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting()); 0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting());
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_EQ(MutableProfileOAuth2TokenServiceDelegate::kInvalidRefreshToken, EXPECT_EQ(MutableProfileOAuth2TokenServiceDelegate::kInvalidRefreshToken,
GetRefreshToken(account_id)); GetRefreshToken(account_info.account_id));
} }
// Checks that signin in progress is not canceled by a signout for a different // Checks that signin in progress is not canceled by a signout for a different
...@@ -677,10 +691,14 @@ TEST_F(DiceResponseHandlerTest, SigninSignoutDifferentAccount) { ...@@ -677,10 +691,14 @@ TEST_F(DiceResponseHandlerTest, SigninSignoutDifferentAccount) {
ASSERT_THAT(signin_client_.consumer_, testing::NotNull()); ASSERT_THAT(signin_client_.consumer_, testing::NotNull());
EXPECT_EQ( EXPECT_EQ(
2u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting()); 2u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting());
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id_1)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id_1));
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable(account_id_2)); ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id_2));
ASSERT_FALSE(token_service_.RefreshTokenHasError(account_id_1)); ASSERT_FALSE(
ASSERT_FALSE(token_service_.RefreshTokenHasError(account_id_2)); identity_manager()->HasAccountWithRefreshTokenInPersistentErrorState(
account_id_1));
ASSERT_FALSE(
identity_manager()->HasAccountWithRefreshTokenInPersistentErrorState(
account_id_2));
// Signout from one of the accounts while signin is in flight. // Signout from one of the accounts while signin is in flight.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
signout_params_1, std::make_unique<TestProcessDiceHeaderDelegate>(this)); signout_params_1, std::make_unique<TestProcessDiceHeaderDelegate>(this));
...@@ -695,8 +713,8 @@ TEST_F(DiceResponseHandlerTest, SigninSignoutDifferentAccount) { ...@@ -695,8 +713,8 @@ TEST_F(DiceResponseHandlerTest, SigninSignoutDifferentAccount) {
EXPECT_EQ( EXPECT_EQ(
0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting()); 0u, dice_response_handler_->GetPendingDiceTokenFetchersCountForTesting());
// Check that the right token is available. // Check that the right token is available.
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(account_id_1)); EXPECT_FALSE(identity_manager()->HasAccountWithRefreshToken(account_id_1));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id_2)); EXPECT_TRUE(identity_manager()->HasAccountWithRefreshToken(account_id_2));
EXPECT_EQ("refresh_token", GetRefreshToken(account_id_2)); EXPECT_EQ("refresh_token", GetRefreshToken(account_id_2));
} }
...@@ -706,7 +724,7 @@ TEST_F(DiceResponseHandlerTest, FixAuthErrorSignedOut) { ...@@ -706,7 +724,7 @@ TEST_F(DiceResponseHandlerTest, FixAuthErrorSignedOut) {
signin::AccountConsistencyMethod::kDiceFixAuthErrors); signin::AccountConsistencyMethod::kDiceFixAuthErrors);
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN);
const auto& account_info = dice_params.signin_info->account_info; const auto& account_info = dice_params.signin_info->account_info;
ASSERT_FALSE(token_service_.RefreshTokenIsAvailable( ASSERT_FALSE(identity_manager()->HasAccountWithRefreshToken(
account_tracker_service_.PickAccountIdForAccount(account_info.gaia_id, account_tracker_service_.PickAccountIdForAccount(account_info.gaia_id,
account_info.email))); account_info.email)));
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
...@@ -722,27 +740,27 @@ TEST_F(DiceResponseHandlerTest, FixAuthErrorSignOutDuringRequest) { ...@@ -722,27 +740,27 @@ TEST_F(DiceResponseHandlerTest, FixAuthErrorSignOutDuringRequest) {
signin::AccountConsistencyMethod::kDiceFixAuthErrors); signin::AccountConsistencyMethod::kDiceFixAuthErrors);
// User is signed in to Chrome. // User is signed in to Chrome.
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN);
const auto& account_info = dice_params.signin_info->account_info; const auto& dice_account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( AccountInfo account_info =
account_info.gaia_id, account_info.email); identity_test_env_.MakePrimaryAccountAvailable(dice_account_info.email);
signin_manager_.SignIn(account_info.gaia_id, account_info.email, "password"); EXPECT_TRUE(
token_service_.UpdateCredentials(account_id, "token1"); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
EXPECT_TRUE(signin_manager_.IsAuthenticated());
// Start re-authentication on the web. // Start re-authentication on the web.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// Check that a GaiaAuthFetcher has been created. // Check that a GaiaAuthFetcher has been created.
ASSERT_THAT(signin_client_.consumer_, testing::NotNull()); ASSERT_THAT(signin_client_.consumer_, testing::NotNull());
// Sign out. // Sign out.
signin_manager_.ForceSignOut(); identity_test_env_.ClearPrimaryAccount();
// Simulate GaiaAuthFetcher success. // Simulate GaiaAuthFetcher success.
signin_client_.consumer_->OnClientOAuthSuccess( signin_client_.consumer_->OnClientOAuthSuccess(
GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10, GaiaAuthConsumer::ClientOAuthResult("refresh_token", "access_token", 10,
false /* is_child_account */, false /* is_child_account */,
false /* is_advanced_protection*/)); false /* is_advanced_protection*/));
// Check that the token has not been inserted in the token service. // Check that the token has not been inserted in the token service.
EXPECT_FALSE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_FALSE(
identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
} }
// Checks that the token is fixed if the Chrome account matches the web account. // Checks that the token is fixed if the Chrome account matches the web account.
...@@ -751,13 +769,12 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) { ...@@ -751,13 +769,12 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) {
signin::AccountConsistencyMethod::kDiceFixAuthErrors); signin::AccountConsistencyMethod::kDiceFixAuthErrors);
// User is signed in to Chrome. // User is signed in to Chrome.
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNIN);
const auto& account_info = dice_params.signin_info->account_info; const auto& dice_account_info = dice_params.signin_info->account_info;
std::string account_id = account_tracker_service_.PickAccountIdForAccount( AccountInfo account_info =
account_info.gaia_id, account_info.email); identity_test_env_.MakePrimaryAccountAvailable(dice_account_info.email);
signin_manager_.SignIn(account_info.gaia_id, account_info.email, "password"); EXPECT_TRUE(
token_service_.UpdateCredentials(account_id, "token1"); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
EXPECT_TRUE(signin_manager_.IsAuthenticated());
// Start re-authentication on the web. // Start re-authentication on the web.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
...@@ -766,7 +783,7 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) { ...@@ -766,7 +783,7 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) {
// We need to listen for new token notifications, since there is no way to // We need to listen for new token notifications, since there is no way to
// check the actual value of the token in the token service. // check the actual value of the token in the token service.
std::unique_ptr<DiceTestTokenServiceObserver> token_service_observer = std::unique_ptr<DiceTestTokenServiceObserver> token_service_observer =
std::make_unique<DiceTestTokenServiceObserver>(account_info.gaia_id); std::make_unique<DiceTestTokenServiceObserver>(account_info.gaia);
ScopedObserver<ProfileOAuth2TokenService, DiceTestTokenServiceObserver> ScopedObserver<ProfileOAuth2TokenService, DiceTestTokenServiceObserver>
scoped_token_service_observer(token_service_observer.get()); scoped_token_service_observer(token_service_observer.get());
scoped_token_service_observer.Add(&token_service_); scoped_token_service_observer.Add(&token_service_);
...@@ -776,7 +793,8 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) { ...@@ -776,7 +793,8 @@ TEST_F(DiceResponseHandlerTest, FixAuthError) {
false /* is_child_account */, false /* is_child_account */,
false /* is_advanced_protection*/)); false /* is_advanced_protection*/));
// Check that the token has not been inserted in the token service. // Check that the token has not been inserted in the token service.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(token_service_observer->token_received()); EXPECT_TRUE(token_service_observer->token_received());
// Check that the reconcilor was blocked and unblocked. // Check that the reconcilor was blocked and unblocked.
EXPECT_EQ(1, reconcilor_blocked_count_); EXPECT_EQ(1, reconcilor_blocked_count_);
...@@ -789,21 +807,21 @@ TEST_F(DiceResponseHandlerTest, FixAuthErroDoesNotSignout) { ...@@ -789,21 +807,21 @@ TEST_F(DiceResponseHandlerTest, FixAuthErroDoesNotSignout) {
InitializeDiceResponseHandler( InitializeDiceResponseHandler(
signin::AccountConsistencyMethod::kDiceFixAuthErrors); signin::AccountConsistencyMethod::kDiceFixAuthErrors);
DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT); DiceResponseParams dice_params = MakeDiceParams(DiceAction::SIGNOUT);
const auto& account_info = dice_params.signout_info->account_infos[0]; const auto& dice_account_info = dice_params.signout_info->account_infos[0];
std::string account_id = account_tracker_service_.PickAccountIdForAccount(
account_info.gaia_id, account_info.email);
// User is signed in to Chrome, and has some refresh token for a secondary // User is signed in to Chrome, and has some refresh token for a secondary
// account. // account.
signin_manager_.SignIn(account_info.gaia_id, account_info.email, "password"); AccountInfo account_info =
token_service_.UpdateCredentials(account_id, "token1"); identity_test_env_.MakePrimaryAccountAvailable(dice_account_info.email);
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
EXPECT_TRUE(signin_manager_.IsAuthenticated()); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
// Receive signout response for the main account. // Receive signout response for the main account.
dice_response_handler_->ProcessDiceHeader( dice_response_handler_->ProcessDiceHeader(
dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this)); dice_params, std::make_unique<TestProcessDiceHeaderDelegate>(this));
// User is not signed out from Chrome. // User is not signed out from Chrome.
EXPECT_TRUE(token_service_.RefreshTokenIsAvailable(account_id)); EXPECT_TRUE(
EXPECT_TRUE(signin_manager_.IsAuthenticated()); identity_manager()->HasAccountWithRefreshToken(account_info.account_id));
EXPECT_TRUE(identity_manager()->HasPrimaryAccount());
} }
// Tests that the DiceResponseHandler is created for a normal profile but not // Tests that the DiceResponseHandler is created for a normal profile but not
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment