Commit d683ff68 authored by Mihai Sardarescu's avatar Mihai Sardarescu Committed by Commit Bot

Clear GAIA related information from profile entry on start-up.

When loading the primary account, the SigninManager may decide to
force sign-out (e.g if the user disallowed signed in). In this case,
the GAIAInfoUpdateService is not notified (as it is created only after
the SigninManager), so it fails to clear the GAIA name, given name and
picture from the profile entry cache.

This CL clears the GAIA name, given name and picture from the profile
entry cache when the GAIAInfoUpdateService is created if the profile
does not have any primary account.

Bug: 890309

Change-Id: I21211cc355672e4ecdc4e911a56187c63b97b8f1
Reviewed-on: https://chromium-review.googlesource.com/1251442Reviewed-by: default avatarThomas Tangl <tangltom@chromium.org>
Commit-Queue: Mihai Sardarescu <msarda@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595076}
parent d94921c0
...@@ -43,6 +43,12 @@ GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile) ...@@ -43,6 +43,12 @@ GAIAInfoUpdateService::GAIAInfoUpdateService(Profile* profile)
IdentityManagerFactory::GetForProfile(profile_); IdentityManagerFactory::GetForProfile(profile_);
identity_manager->AddObserver(this); identity_manager->AddObserver(this);
if (!identity_manager->HasPrimaryAccount()) {
// Handle the case when the primary account was cleared while loading the
// profile, before the |GAIAInfoUpdateService| is created.
OnUsernameChanged(std::string());
}
PrefService* prefs = profile_->GetPrefs(); PrefService* prefs = profile_->GetPrefs();
last_updated_ = base::Time::FromInternalValue( last_updated_ = base::Time::FromInternalValue(
prefs->GetInt64(prefs::kProfileGAIAInfoUpdateTime)); prefs->GetInt64(prefs::kProfileGAIAInfoUpdateTime));
......
...@@ -70,9 +70,28 @@ class GAIAInfoUpdateServiceMock : public GAIAInfoUpdateService { ...@@ -70,9 +70,28 @@ class GAIAInfoUpdateServiceMock : public GAIAInfoUpdateService {
}; };
// TODO(anthonyvd) : remove ProfileInfoCacheTest from the test fixture. // TODO(anthonyvd) : remove ProfileInfoCacheTest from the test fixture.
class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest { class GAIAInfoUpdateServiceTestBase : public ProfileInfoCacheTest {
protected: protected:
GAIAInfoUpdateServiceTest() : profile_(NULL) { explicit GAIAInfoUpdateServiceTestBase(bool create_gaia_info_service_on_setup)
: create_gaia_info_service_on_setup_(create_gaia_info_service_on_setup) {}
~GAIAInfoUpdateServiceTestBase() override = default;
void SetUp() override {
ProfileInfoCacheTest::SetUp();
if (create_gaia_info_service_on_setup_) {
service_.reset(new NiceMock<GAIAInfoUpdateServiceMock>(profile()));
downloader_.reset(new NiceMock<ProfileDownloaderMock>(service()));
}
};
void TearDown() override {
if (downloader_)
downloader_.reset();
if (service_) {
service_->Shutdown();
service_.reset();
}
ProfileInfoCacheTest::TearDown();
} }
Profile* profile() { Profile* profile() {
...@@ -157,27 +176,36 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest { ...@@ -157,27 +176,36 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest {
EXPECT_EQ(given_name, entry->GetGAIAGivenName()); EXPECT_EQ(given_name, entry->GetGAIAGivenName());
} }
private: const bool create_gaia_info_service_on_setup_;
void SetUp() override; Profile* profile_ = nullptr;
void TearDown() override;
Profile* profile_;
std::unique_ptr<NiceMock<GAIAInfoUpdateServiceMock>> service_; std::unique_ptr<NiceMock<GAIAInfoUpdateServiceMock>> service_;
std::unique_ptr<NiceMock<ProfileDownloaderMock>> downloader_; std::unique_ptr<NiceMock<ProfileDownloaderMock>> downloader_;
private:
DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateServiceTestBase);
}; };
void GAIAInfoUpdateServiceTest::SetUp() { class GAIAInfoUpdateServiceTest : public GAIAInfoUpdateServiceTestBase {
ProfileInfoCacheTest::SetUp(); public:
service_.reset(new NiceMock<GAIAInfoUpdateServiceMock>(profile())); GAIAInfoUpdateServiceTest()
downloader_.reset(new NiceMock<ProfileDownloaderMock>(service())); : GAIAInfoUpdateServiceTestBase(
} /*create_gaia_info_service_on_setup_=*/true) {}
~GAIAInfoUpdateServiceTest() override = default;
void GAIAInfoUpdateServiceTest::TearDown() { private:
downloader_.reset(); DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateServiceTest);
service_->Shutdown(); };
service_.reset();
ProfileInfoCacheTest::TearDown(); class GAIAInfoUpdateServiceMiscTest : public GAIAInfoUpdateServiceTestBase {
} public:
GAIAInfoUpdateServiceMiscTest()
: GAIAInfoUpdateServiceTestBase(
/*create_gaia_info_service_on_setup_=*/false) {}
~GAIAInfoUpdateServiceMiscTest() override = default;
private:
DISALLOW_COPY_AND_ASSIGN(GAIAInfoUpdateServiceMiscTest);
};
} // namespace } // namespace
...@@ -363,4 +391,23 @@ TEST_F(GAIAInfoUpdateServiceTest, RestoreAvatarIndexOnLogout) { ...@@ -363,4 +391,23 @@ TEST_F(GAIAInfoUpdateServiceTest, RestoreAvatarIndexOnLogout) {
EXPECT_EQ(kLocalAvatarIndex, entry->GetAvatarIconIndex()); EXPECT_EQ(kLocalAvatarIndex, entry->GetAvatarIconIndex());
} }
TEST_F(GAIAInfoUpdateServiceMiscTest, ClearGaiaInfoOnStartup) {
// Simulate a state where the profile entry has GAIA related information
// when there is not primary account set.
EXPECT_FALSE(
IdentityManagerFactory::GetForProfile(profile())->HasPrimaryAccount());
ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
ProfileAttributesEntry* entry = storage()->GetAllProfilesAttributes().front();
entry->SetGAIAName(base::UTF8ToUTF16("foo"));
entry->SetGAIAGivenName(base::UTF8ToUTF16("Pat Foo"));
gfx::Image gaia_picture = gfx::test::CreateImage(256, 256);
entry->SetGAIAPicture(&gaia_picture);
// Verify that creating the GAIAInfoUpdateService resets the GAIA related
// profile attributes if the profile no longer has a primary account.
service_.reset(new NiceMock<GAIAInfoUpdateServiceMock>(profile()));
EXPECT_TRUE(entry->GetGAIAName().empty());
EXPECT_TRUE(entry->GetGAIAGivenName().empty());
EXPECT_FALSE(entry->GetGAIAPicture());
}
#endif #endif
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