Commit e8eec08a authored by Monica Basta's avatar Monica Basta Committed by Commit Bot

[Signin]: Prevent clearing the profile on PA reset if a UPA exists.

The profile entry is cleared on Primary account cleared. This is broken
if the UPA still exists and has not changed. This is possible with
|reset sync|. This CL prevents clearing the profile if there is an
unconsented primary account.

Fixed: 1038499

Change-Id: I64212726eee5534c3337a7074ff20dc6dcf5993c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983175
Commit-Queue: Monica Basta <msalama@chromium.org>
Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728528}
parent 7fcb0102
...@@ -69,7 +69,7 @@ void GAIAInfoUpdateService::Update() { ...@@ -69,7 +69,7 @@ void GAIAInfoUpdateService::Update() {
auto maybe_account_info = auto maybe_account_info =
identity_manager_ identity_manager_
->FindExtendedAccountInfoForAccountWithRefreshTokenByAccountId( ->FindExtendedAccountInfoForAccountWithRefreshTokenByAccountId(
identity_manager_->GetUnconsentedPrimaryAccountInfo().account_id); unconsented_primary_account_info.account_id);
if (maybe_account_info.has_value()) if (maybe_account_info.has_value())
Update(maybe_account_info.value()); Update(maybe_account_info.value());
} }
...@@ -139,7 +139,13 @@ void GAIAInfoUpdateService::OnPrimaryAccountSet( ...@@ -139,7 +139,13 @@ void GAIAInfoUpdateService::OnPrimaryAccountSet(
void GAIAInfoUpdateService::OnPrimaryAccountCleared( void GAIAInfoUpdateService::OnPrimaryAccountCleared(
const CoreAccountInfo& previous_primary_account_info) { const CoreAccountInfo& previous_primary_account_info) {
ClearProfileEntry(); // Do not clear the profile if there is an unconsented primary account.
if (!ShouldUpdate()) {
ClearProfileEntry();
return;
}
DCHECK_EQ(identity_manager_->GetUnconsentedPrimaryAccountInfo().gaia,
previous_primary_account_info.gaia);
} }
void GAIAInfoUpdateService::OnUnconsentedPrimaryAccountChanged( void GAIAInfoUpdateService::OnUnconsentedPrimaryAccountChanged(
......
...@@ -163,6 +163,36 @@ TEST_F(GAIAInfoUpdateServiceTest, SyncOnSyncOff) { ...@@ -163,6 +163,36 @@ TEST_F(GAIAInfoUpdateServiceTest, SyncOnSyncOff) {
} }
#if !defined(ANDROID) #if !defined(ANDROID)
TEST_F(GAIAInfoUpdateServiceTest, SyncOnSyncOffKeepAllAccounts) {
AccountInfo info =
identity_test_env()->MakeAccountAvailable("pat@example.com");
base::RunLoop().RunUntilIdle();
identity_test_env()->SetPrimaryAccount(info.email);
info = GetValidAccountInfo(info.email, info.account_id, "Pat", "Pat Foo");
signin::UpdateAccountInfoForAccount(identity_test_env()->identity_manager(),
info);
base::RunLoop().RunUntilIdle();
ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
ProfileAttributesEntry* entry = storage()->GetAllProfilesAttributes().front();
gfx::Image gaia_picture = gfx::test::CreateImage(256, 256);
signin::SimulateAccountImageFetch(identity_test_env()->identity_manager(),
info.account_id, gaia_picture);
// Turn off sync but stay logged in.
identity_test_env()->ClearPrimaryAccount(
signin::ClearPrimaryAccountPolicy::KEEP_ALL_ACCOUNTS);
ASSERT_TRUE(
identity_test_env()->identity_manager()->HasUnconsentedPrimaryAccount());
// Verify that the GAIA name and picture, and picture URL are not cleared
// as unconsented primary account still exists.
EXPECT_EQ(entry->GetGAIAGivenName(), base::UTF8ToUTF16("Pat"));
EXPECT_EQ(entry->GetGAIAName(), base::UTF8ToUTF16("Pat Foo"));
EXPECT_EQ(
profile()->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain),
info.hosted_domain);
EXPECT_TRUE(gfx::test::AreImagesEqual(gaia_picture, entry->GetAvatarIcon()));
}
TEST_F(GAIAInfoUpdateServiceTest, LogInLogOut) { TEST_F(GAIAInfoUpdateServiceTest, LogInLogOut) {
std::string email = "pat@example.com"; std::string email = "pat@example.com";
AccountInfo info = identity_test_env()->MakeAccountAvailableWithCookies( AccountInfo info = identity_test_env()->MakeAccountAvailableWithCookies(
......
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