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

Unified Diff: chrome/browser/profiles/gaia_info_update_service_unittest.cc

Issue 1794353003: Refactor ProfileInfoCache in c/b/profiles (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/profiles/gaia_info_update_service_unittest.cc
diff --git a/chrome/browser/profiles/gaia_info_update_service_unittest.cc b/chrome/browser/profiles/gaia_info_update_service_unittest.cc
index a24346338e6142a3053d2eda6e724a1bd9f775e8..54567a48ba383ae2b7cd78d18f3cd869ad3b9bce 100644
--- a/chrome/browser/profiles/gaia_info_update_service_unittest.cc
+++ b/chrome/browser/profiles/gaia_info_update_service_unittest.cc
@@ -11,8 +11,9 @@
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/profiles/profile_attributes_entry.h"
+#include "chrome/browser/profiles/profile_attributes_storage.h"
#include "chrome/browser/profiles/profile_downloader.h"
-#include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/profiles/profile_info_cache_unittest.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/signin/account_tracker_service_factory.h"
@@ -77,6 +78,10 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest {
return profile_;
}
+ ProfileAttributesStorage* storage() {
+ return testing_profile_manager_.profile_attributes_storage();
+ }
+
NiceMock<GAIAInfoUpdateServiceMock>* service() { return service_.get(); }
NiceMock<ProfileDownloaderMock>* downloader() { return downloader_.get(); }
@@ -91,24 +96,14 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest {
// The testing manager sets the profile name manually, which counts as
// a user-customized profile name. Reset this to match the default name
// we are actually using.
- size_t index = GetCache()->GetIndexOfProfileWithPath(profile->GetPath());
- GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
+ ProfileAttributesEntry* entry = nullptr;
+ // TODO(anthonyvd) : refactor the function so the following assertion can be
+ // changed to ASSERT_TRUE.
+ DCHECK(storage()->GetProfileAttributesWithPath(profile->GetPath(), &entry));
+ entry->SetIsUsingDefaultName(true);
return profile;
}
- static std::string GivenName(const std::string& id) {
- return id + "first";
- }
- static std::string FullName(const std::string& id) {
- return GivenName(id) + " " + id + "last";
- }
- static base::string16 GivenName16(const std::string& id) {
- return base::UTF8ToUTF16(GivenName(id));
- }
- static base::string16 FullName16(const std::string& id) {
- return base::UTF8ToUTF16(FullName(id));
- }
-
void ProfileDownloadSuccess(
const base::string16& full_name,
const base::string16& given_name,
@@ -130,18 +125,6 @@ class GAIAInfoUpdateServiceTest : public ProfileInfoCacheTest {
service()->OnProfileDownloadSuccess(downloader());
}
- void RenameProfile(const base::string16& full_name,
- const base::string16& given_name) {
- gfx::Image image = gfx::test::CreateImage(256, 256);
- std::string url("foo.com");
- ProfileDownloadSuccess(full_name, given_name, image, url, base::string16());
-
- // Make sure the right profile was updated correctly.
- size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
- EXPECT_EQ(full_name, GetCache()->GetGAIANameOfProfileAtIndex(index));
- EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index));
- }
-
private:
void SetUp() override;
void TearDown() override;
@@ -180,20 +163,23 @@ TEST_F(GAIAInfoUpdateServiceTest, DownloadSuccess) {
ProfileDownloadSuccess(name, given_name, image, url, hosted_domain);
// On success the GAIA info should be updated.
- size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
- EXPECT_EQ(name, GetCache()->GetGAIANameOfProfileAtIndex(index));
- EXPECT_EQ(given_name, GetCache()->GetGAIAGivenNameOfProfileAtIndex(index));
- EXPECT_TRUE(gfx::test::AreImagesEqual(
- image, *GetCache()->GetGAIAPictureOfProfileAtIndex(index)));
+ ProfileAttributesEntry* entry;
+ ASSERT_TRUE(storage()->GetProfileAttributesWithPath(profile()->GetPath(),
+ &entry));
+ EXPECT_EQ(name, entry->GetGAIAName());
+ EXPECT_EQ(given_name, entry->GetGAIAGivenName());
+ EXPECT_TRUE(gfx::test::AreImagesEqual(image, *entry->GetGAIAPicture()));
EXPECT_EQ(url, service()->GetCachedPictureURL());
EXPECT_EQ(Profile::kNoHostedDomainFound, profile()->GetPrefs()->
GetString(prefs::kGoogleServicesHostedDomain));
}
TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) {
- size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
- base::string16 old_name = GetCache()->GetNameOfProfileAtIndex(index);
- gfx::Image old_image = GetCache()->GetAvatarIconOfProfileAtIndex(index);
+ ProfileAttributesEntry* entry;
+ ASSERT_TRUE(storage()->GetProfileAttributesWithPath(profile()->GetPath(),
+ &entry));
+ base::string16 old_name = entry->GetName();
+ gfx::Image old_image = entry->GetAvatarIcon();
EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
@@ -201,13 +187,11 @@ TEST_F(GAIAInfoUpdateServiceTest, DownloadFailure) {
ProfileDownloaderDelegate::SERVICE_ERROR);
// On failure nothing should be updated.
- EXPECT_EQ(old_name, GetCache()->GetNameOfProfileAtIndex(index));
- EXPECT_EQ(base::string16(), GetCache()->GetGAIANameOfProfileAtIndex(index));
- EXPECT_EQ(base::string16(),
- GetCache()->GetGAIAGivenNameOfProfileAtIndex(index));
- EXPECT_TRUE(gfx::test::AreImagesEqual(
- old_image, GetCache()->GetAvatarIconOfProfileAtIndex(index)));
- EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(index));
+ EXPECT_EQ(old_name, entry->GetName());
+ EXPECT_EQ(base::string16(), entry->GetGAIAName());
+ EXPECT_EQ(base::string16(), entry->GetGAIAGivenName());
+ EXPECT_TRUE(gfx::test::AreImagesEqual(old_image, entry->GetAvatarIcon()));
+ EXPECT_EQ(nullptr, entry->GetGAIAPicture());
EXPECT_EQ(std::string(), service()->GetCachedPictureURL());
EXPECT_EQ(std::string(),
profile()->GetPrefs()->GetString(prefs::kGoogleServicesHostedDomain));
@@ -228,46 +212,6 @@ TEST_F(GAIAInfoUpdateServiceTest, ProfileLockEnabledForWhitelist) {
GetString(prefs::kGoogleServicesHostedDomain));
}
-TEST_F(GAIAInfoUpdateServiceTest, HandlesProfileReordering) {
Mike Lerman 2016/03/18 17:10:44 I'd almost prefer to leave this in until we've ful
lwchkg 2016/03/19 18:48:46 Acknowledged.
- size_t index = GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
- GetCache()->SetNameOfProfileAtIndex(index, FullName16("B"));
- GetCache()->SetProfileIsUsingDefaultNameAtIndex(index, true);
-
- CreateProfile(FullName("A"));
- CreateProfile(FullName("C"));
- CreateProfile(FullName("E"));
-
- size_t index_before =
- GetCache()->GetIndexOfProfileWithPath(profile()->GetPath());
-
- // Rename our profile.
- RenameProfile(FullName16("D"), GivenName16("D"));
- // Profiles should have been reordered in the cache.
- EXPECT_NE(index_before,
- GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()));
- // Rename the profile back to the original name, it should go back to its
- // original position.
- RenameProfile(FullName16("B"), GivenName16("B"));
- EXPECT_EQ(index_before,
- GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()));
-
- // Rename only the given name of our profile.
- RenameProfile(FullName16("B"), GivenName16("D"));
- // Rename the profile back to the original name, it should go back to its
- // original position.
- RenameProfile(FullName16("B"), GivenName16("B"));
- EXPECT_EQ(index_before,
- GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()));
-
- // Rename only the full name of our profile.
- RenameProfile(FullName16("D"), GivenName16("B"));
- // Rename the profile back to the original name, it should go back to its
- // original position.
- RenameProfile(FullName16("B"), GivenName16("B"));
- EXPECT_EQ(index_before,
- GetCache()->GetIndexOfProfileWithPath(profile()->GetPath()));
-}
-
TEST_F(GAIAInfoUpdateServiceTest, ShouldUseGAIAProfileInfo) {
#if defined(OS_CHROMEOS)
// This feature should never be enabled on ChromeOS.
@@ -290,9 +234,12 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
SigninManagerFactory::GetForProfile(profile());
signin_manager->SetAuthenticatedAccountInfo("gaia_id", "pat@example.com");
base::string16 gaia_name = base::UTF8ToUTF16("Pat Foo");
- GetCache()->SetGAIANameOfProfileAtIndex(0, gaia_name);
+
+ ASSERT_EQ(1u, storage()->GetNumberOfProfiles());
+ ProfileAttributesEntry* entry = storage()->GetAllProfilesAttributes().front();
+ entry->SetGAIAName(gaia_name);
gfx::Image gaia_picture = gfx::test::CreateImage(256, 256);
- GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_picture);
+ entry->SetGAIAPicture(&gaia_picture);
// Set a fake picture URL.
profile()->GetPrefs()->SetString(prefs::kProfileGAIAInfoPictureURL,
@@ -304,8 +251,8 @@ TEST_F(GAIAInfoUpdateServiceTest, LogOut) {
signin_manager->SignOut(signin_metrics::SIGNOUT_TEST,
signin_metrics::SignoutDelete::IGNORE_METRIC);
// Verify that the GAIA name and picture, and picture URL are unset.
- EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
- EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
+ EXPECT_TRUE(entry->GetGAIAName().empty());
+ EXPECT_EQ(nullptr, entry->GetGAIAPicture());
EXPECT_TRUE(service()->GetCachedPictureURL().empty());
}

Powered by Google App Engine
This is Rietveld 408576698