Commit 484920e5 authored by WC Leung's avatar WC Leung Committed by Commit Bot

Migrate avatar icon accessors to ProfileAttributesStorage

GetAvatarIcon, GetAvatarIconIndex, SetAvatarIconIndex, and
GetHighResAvatar are migrated to ProfileAttributesEntry. Old accessors
are still here (with some extra comment) because they are still used by
ProfileInfoCache tests.

Two high-res avatar tests are migrated and one test about avatar icon
index is added.

An existing observer notifier method in ProfileAttributesStorage is
changed because it was not good enough.

Bug: 305720
Change-Id: I93b3e765cd1131f7ddb905c884db6d23390786bb
Reviewed-on: https://chromium-review.googlesource.com/694062Reviewed-by: default avataranthonyvd <anthonyvd@chromium.org>
Commit-Queue: WC Leung <lwchkg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505876}
parent 56aa7a6b
...@@ -5,18 +5,22 @@ ...@@ -5,18 +5,22 @@
#include <utility> #include <utility>
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/browser/profiles/profile_attributes_entry.h" #include "chrome/browser/profiles/profile_attributes_entry.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/profiles/profile_info_cache.h" #include "chrome/browser/profiles/profile_info_cache.h"
#include "chrome/browser/signin/signin_util.h" #include "chrome/browser/signin/signin_util.h"
#include "chrome/common/pref_names.h" #include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
#include "ui/base/resource/resource_bundle.h"
namespace { namespace {
const char kShortcutNameKey[] = "shortcut_name"; const char kShortcutNameKey[] = "shortcut_name";
const char kActiveTimeKey[] = "active_time"; const char kActiveTimeKey[] = "active_time";
const char kUserNameKey[] = "user_name"; const char kUserNameKey[] = "user_name";
const char kAvatarIconKey[] = "avatar_icon";
const char kAuthCredentialsKey[] = "local_auth_credentials"; const char kAuthCredentialsKey[] = "local_auth_credentials";
const char kPasswordTokenKey[] = "gaia_password_token"; const char kPasswordTokenKey[] = "gaia_password_token";
const char kBackgroundAppsKey[] = "background_apps"; const char kBackgroundAppsKey[] = "background_apps";
...@@ -78,7 +82,23 @@ base::string16 ProfileAttributesEntry::GetUserName() const { ...@@ -78,7 +82,23 @@ base::string16 ProfileAttributesEntry::GetUserName() const {
} }
const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() const { const gfx::Image& ProfileAttributesEntry::GetAvatarIcon() const {
return profile_info_cache_->GetAvatarIconOfProfileAtIndex(profile_index()); if (IsUsingGAIAPicture()) {
const gfx::Image* image = GetGAIAPicture();
if (image)
return *image;
}
#if !defined(OS_CHROMEOS) && !defined(OS_ANDROID)
// Use the high resolution version of the avatar if it exists. Mobile and
// ChromeOS don't need the high resolution version so no need to fetch it.
const gfx::Image* image = GetHighResAvatar();
if (image)
return *image;
#endif
int resource_id =
profiles::GetDefaultAvatarIconResourceIDAtIndex(GetAvatarIconIndex());
return ResourceBundle::GetSharedInstance().GetNativeImageNamed(resource_id);
} }
std::string ProfileAttributesEntry::GetLocalAuthCredentials() const { std::string ProfileAttributesEntry::GetLocalAuthCredentials() const {
...@@ -171,8 +191,12 @@ bool ProfileAttributesEntry::IsAuthError() const { ...@@ -171,8 +191,12 @@ bool ProfileAttributesEntry::IsAuthError() const {
} }
size_t ProfileAttributesEntry::GetAvatarIconIndex() const { size_t ProfileAttributesEntry::GetAvatarIconIndex() const {
return profile_info_cache_->GetAvatarIconIndexOfProfileAtIndex( std::string icon_url = GetString(kAvatarIconKey);
profile_index()); size_t icon_index = 0;
if (!profiles::IsDefaultAvatarIconUrl(icon_url, &icon_index))
DLOG(WARNING) << "Unknown avatar icon: " << icon_url;
return icon_index;
} }
void ProfileAttributesEntry::SetName(const base::string16& name) { void ProfileAttributesEntry::SetName(const base::string16& name) {
...@@ -262,8 +286,20 @@ void ProfileAttributesEntry::SetIsAuthError(bool value) { ...@@ -262,8 +286,20 @@ void ProfileAttributesEntry::SetIsAuthError(bool value) {
} }
void ProfileAttributesEntry::SetAvatarIconIndex(size_t icon_index) { void ProfileAttributesEntry::SetAvatarIconIndex(size_t icon_index) {
profile_info_cache_->SetAvatarIconOfProfileAtIndex( if (!profiles::IsDefaultAvatarIconIndex(icon_index)) {
profile_index(), icon_index); DLOG(WARNING) << "Unknown avatar icon index: " << icon_index;
// switch to generic avatar
icon_index = 0;
}
SetString(kAvatarIconKey, profiles::GetDefaultAvatarIconUrl(icon_index));
base::FilePath profile_path = GetPath();
if (!profile_info_cache_->GetDisableAvatarDownloadForTesting())
profile_info_cache_->DownloadHighResAvatarIfNeeded(icon_index,
profile_path);
profile_info_cache_->NotifyOnProfileAvatarChanged(profile_path);
} }
void ProfileAttributesEntry::SetAuthInfo( void ProfileAttributesEntry::SetAuthInfo(
...@@ -278,6 +314,24 @@ size_t ProfileAttributesEntry::profile_index() const { ...@@ -278,6 +314,24 @@ size_t ProfileAttributesEntry::profile_index() const {
return index; return index;
} }
const gfx::Image* ProfileAttributesEntry::GetHighResAvatar() const {
const size_t avatar_index = GetAvatarIconIndex();
// If this is the placeholder avatar, it is already included in the
// resources, so it doesn't need to be downloaded.
if (avatar_index == profiles::GetPlaceholderAvatarIndex()) {
return &ui::ResourceBundle::GetSharedInstance().GetImageNamed(
profiles::GetPlaceholderAvatarIconResourceID());
}
const std::string key =
profiles::GetDefaultAvatarIconFileNameAtIndex(avatar_index);
const base::FilePath image_path =
profiles::GetPathOfHighResAvatarAtIndex(avatar_index);
return profile_info_cache_->LoadAvatarPictureFromPath(GetPath(), key,
image_path);
}
const base::Value* ProfileAttributesEntry::GetEntryData() const { const base::Value* ProfileAttributesEntry::GetEntryData() const {
const base::DictionaryValue* cache = const base::DictionaryValue* cache =
prefs_->GetDictionary(prefs::kProfileInfoCache); prefs_->GetDictionary(prefs::kProfileInfoCache);
......
...@@ -123,11 +123,17 @@ class ProfileAttributesEntry { ...@@ -123,11 +123,17 @@ class ProfileAttributesEntry {
FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
EntryInternalAccessors); EntryInternalAccessors);
FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, ProfileActiveTime); FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, ProfileActiveTime);
FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
DownloadHighResAvatarTest);
void Initialize(ProfileInfoCache* cache, void Initialize(ProfileInfoCache* cache,
const base::FilePath& path, const base::FilePath& path,
PrefService* prefs); PrefService* prefs);
// Loads or uses an already loaded high resolution image of the generic
// profile avatar.
const gfx::Image* GetHighResAvatar() const;
// Loads and saves the data to the local state. // Loads and saves the data to the local state.
const base::Value* GetEntryData() const; const base::Value* GetEntryData() const;
void SetEntryData(base::Value data); void SetEntryData(base::Value data);
......
...@@ -333,8 +333,14 @@ void ProfileAttributesStorage::RemoveObserver(Observer* obs) { ...@@ -333,8 +333,14 @@ void ProfileAttributesStorage::RemoveObserver(Observer* obs) {
observer_list_.RemoveObserver(obs); observer_list_.RemoveObserver(obs);
} }
void ProfileAttributesStorage::CallOnProfileHighResAvatarLoaded( void ProfileAttributesStorage::NotifyOnProfileAvatarChanged(
base::FilePath profile_path) const { const base::FilePath& profile_path) const {
for (auto& observer : observer_list_)
observer.OnProfileAvatarChanged(profile_path);
}
void ProfileAttributesStorage::NotifyOnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) const {
for (auto& observer : observer_list_) for (auto& observer : observer_list_)
observer.OnProfileHighResAvatarLoaded(profile_path); observer.OnProfileHighResAvatarLoaded(profile_path);
} }
...@@ -378,14 +384,14 @@ void ProfileAttributesStorage::DownloadHighResAvatar( ...@@ -378,14 +384,14 @@ void ProfileAttributesStorage::DownloadHighResAvatar(
if (avatar_images_downloads_in_progress_.count(file_name)) if (avatar_images_downloads_in_progress_.count(file_name))
return; return;
// Start the download for this file. The cache takes ownership of the // Start the download for this file. The profile attributes storage takes
// avatar downloader, which will be deleted when the download completes, or // ownership of the avatar downloader, which will be deleted when the download
// if that never happens, when the ProfileInfoCache is destroyed. // completes, or if that never happens, when the storage is destroyed.
std::unique_ptr<ProfileAvatarDownloader>& current_downloader = std::unique_ptr<ProfileAvatarDownloader>& current_downloader =
avatar_images_downloads_in_progress_[file_name]; avatar_images_downloads_in_progress_[file_name];
current_downloader.reset(new ProfileAvatarDownloader( current_downloader.reset(new ProfileAvatarDownloader(
icon_index, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath, icon_index, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath,
base::Unretained(this), profile_path))); AsWeakPtr(), profile_path)));
current_downloader->Start(); current_downloader->Start();
} }
...@@ -439,7 +445,7 @@ void ProfileAttributesStorage::OnAvatarPictureLoaded( ...@@ -439,7 +445,7 @@ void ProfileAttributesStorage::OnAvatarPictureLoaded(
} }
delete image; delete image;
CallOnProfileHighResAvatarLoaded(profile_path); NotifyOnProfileHighResAvatarLoaded(profile_path);
} }
void ProfileAttributesStorage::OnAvatarPictureSaved( void ProfileAttributesStorage::OnAvatarPictureSaved(
...@@ -447,5 +453,5 @@ void ProfileAttributesStorage::OnAvatarPictureSaved( ...@@ -447,5 +453,5 @@ void ProfileAttributesStorage::OnAvatarPictureSaved(
const base::FilePath& profile_path) const { const base::FilePath& profile_path) const {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI); DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
CallOnProfileHighResAvatarLoaded(profile_path); NotifyOnProfileHighResAvatarLoaded(profile_path);
} }
...@@ -92,14 +92,27 @@ class ProfileAttributesStorage ...@@ -92,14 +92,27 @@ class ProfileAttributesStorage
const std::string& key, const std::string& key,
const base::FilePath& image_path) const; const base::FilePath& image_path) const;
// Checks whether the high res avatar at index |icon_index| exists, and if it
// does not, calls |DownloadHighResAvatar|.
void DownloadHighResAvatarIfNeeded(size_t icon_index,
const base::FilePath& profile_path);
void AddObserver(Observer* observer); void AddObserver(Observer* observer);
void RemoveObserver(Observer* observer); void RemoveObserver(Observer* observer);
bool GetDisableAvatarDownloadForTesting() {
return disable_avatar_download_for_testing_;
}
void set_disable_avatar_download_for_testing( void set_disable_avatar_download_for_testing(
bool disable_avatar_download_for_testing) { bool disable_avatar_download_for_testing) {
disable_avatar_download_for_testing_ = disable_avatar_download_for_testing; disable_avatar_download_for_testing_ = disable_avatar_download_for_testing;
} }
// Notifies observers. The following methods are accessed by
// ProfileAttributesEntry.
void NotifyOnProfileAvatarChanged(const base::FilePath& profile_path) const;
protected: protected:
FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, EntriesInAttributesStorage); FRIEND_TEST_ALL_PREFIXES(ProfileInfoCacheTest, EntriesInAttributesStorage);
FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
...@@ -107,11 +120,6 @@ class ProfileAttributesStorage ...@@ -107,11 +120,6 @@ class ProfileAttributesStorage
FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest, FRIEND_TEST_ALL_PREFIXES(ProfileAttributesStorageTest,
NothingToDownloadHighResAvatarTest); NothingToDownloadHighResAvatarTest);
// Checks whether the high res avatar at index |icon_index| exists, and if it
// does not, calls |DownloadHighResAvatar|.
void DownloadHighResAvatarIfNeeded(size_t icon_index,
const base::FilePath& profile_path);
// Starts downloading the high res avatar at index |icon_index| for profile // Starts downloading the high res avatar at index |icon_index| for profile
// with path |profile_path|. // with path |profile_path|.
void DownloadHighResAvatar(size_t icon_index, void DownloadHighResAvatar(size_t icon_index,
...@@ -169,8 +177,9 @@ class ProfileAttributesStorage ...@@ -169,8 +177,9 @@ class ProfileAttributesStorage
void OnAvatarPictureSaved(const std::string& file_name, void OnAvatarPictureSaved(const std::string& file_name,
const base::FilePath& profile_path) const; const base::FilePath& profile_path) const;
// Calls observers. // Notifies observers.
void CallOnProfileHighResAvatarLoaded(base::FilePath profile_path) const; void NotifyOnProfileHighResAvatarLoaded(
const base::FilePath& profile_path) const;
DISALLOW_COPY_AND_ASSIGN(ProfileAttributesStorage); DISALLOW_COPY_AND_ASSIGN(ProfileAttributesStorage);
}; };
......
...@@ -643,12 +643,12 @@ TEST_F(ProfileAttributesStorageTest, ChooseAvatarIconIndexForNewProfile) { ...@@ -643,12 +643,12 @@ TEST_F(ProfileAttributesStorageTest, ChooseAvatarIconIndexForNewProfile) {
TEST_F(ProfileAttributesStorageTest, ProfileForceSigninLock) { TEST_F(ProfileAttributesStorageTest, ProfileForceSigninLock) {
signin_util::SetForceSigninForTesting(true); signin_util::SetForceSigninForTesting(true);
ProfileAttributesEntry* entry;
AddTestingProfile(); AddTestingProfile();
base::FilePath path = GetProfilePath("testing_profile_path0"); base::FilePath path = GetProfilePath("testing_profile_path0");
ProfileAttributesEntry* entry;
ASSERT_TRUE(storage()->GetProfileAttributesWithPath(path, &entry)); ASSERT_TRUE(storage()->GetProfileAttributesWithPath(path, &entry));
ASSERT_FALSE(entry->IsSigninRequired()); ASSERT_FALSE(entry->IsSigninRequired());
...@@ -666,43 +666,76 @@ TEST_F(ProfileAttributesStorageTest, ProfileForceSigninLock) { ...@@ -666,43 +666,76 @@ TEST_F(ProfileAttributesStorageTest, ProfileForceSigninLock) {
ASSERT_FALSE(entry->IsSigninRequired()); ASSERT_FALSE(entry->IsSigninRequired());
} }
TEST_F(ProfileAttributesStorageTest, AvatarIconIndex) {
AddTestingProfile();
base::FilePath profile_path = GetProfilePath("testing_profile_path0");
ProfileAttributesEntry* entry;
ASSERT_TRUE(storage()->GetProfileAttributesWithPath(profile_path, &entry));
ASSERT_EQ(0U, entry->GetAvatarIconIndex());
EXPECT_CALL(observer(), OnProfileAvatarChanged(profile_path)).Times(1);
entry->SetAvatarIconIndex(2U);
VerifyAndResetCallExpectations();
ASSERT_EQ(2U, entry->GetAvatarIconIndex());
EXPECT_CALL(observer(), OnProfileAvatarChanged(profile_path)).Times(1);
entry->SetAvatarIconIndex(3U);
VerifyAndResetCallExpectations();
ASSERT_EQ(3U, entry->GetAvatarIconIndex());
}
// High res avatar downloading is only supported on desktop. // High res avatar downloading is only supported on desktop.
#if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) { TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) {
// The TestingProfileManager's ProfileInfoCache doesn't download avatars. storage()->set_disable_avatar_download_for_testing(false);
ProfileInfoCache profile_info_cache(
g_browser_process->local_state(),
testing_profile_manager_.profile_manager()->user_data_dir());
// Make sure there are no avatars already on disk.
const size_t kIconIndex = 0; const size_t kIconIndex = 0;
base::FilePath icon_path = base::FilePath icon_path =
profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); profiles::GetPathOfHighResAvatarAtIndex(kIconIndex);
ASSERT_FALSE(base::PathExists(icon_path));
EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles()); ASSERT_EQ(0U, storage()->GetNumberOfProfiles());
base::FilePath path_1 = GetProfilePath("path_1"); base::FilePath profile_path = GetProfilePath("path_1");
profile_info_cache.AddProfile(path_1, base::ASCIIToUTF16("name_1"), EXPECT_CALL(observer(), OnProfileAdded(profile_path)).Times(1);
std::string(), base::string16(), kIconIndex, storage()->AddProfile(profile_path, base::ASCIIToUTF16("name_1"),
std::string()); std::string(), base::string16(), kIconIndex,
EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles()); std::string());
ASSERT_EQ(1U, storage()->GetNumberOfProfiles());
VerifyAndResetCallExpectations();
// Make sure there are no avatars already on disk.
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
ASSERT_FALSE(base::PathExists(icon_path));
// We haven't downloaded any high-res avatars yet. // We haven't downloaded any high-res avatars yet.
EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size()); EXPECT_EQ(0U, storage()->cached_avatar_images_.size());
// After adding a new profile, the download of high-res avatar will be // After adding a new profile, the download of high-res avatar will be
// triggered if the flag kNewAvatarMenu has been set. But the downloader // triggered. But the downloader won't ever call OnFetchComplete in the test.
// won't ever call OnFetchComplete in the test. EXPECT_EQ(1U, storage()->avatar_images_downloads_in_progress_.size());
EXPECT_EQ(1U, profile_info_cache.avatar_images_downloads_in_progress_.size());
// |GetHighResAvater| does not contain a cached avatar, so it should return
// null.
ProfileAttributesEntry* entry;
ASSERT_TRUE(storage()->GetProfileAttributesWithPath(profile_path, &entry));
EXPECT_FALSE(entry->GetHighResAvatar());
EXPECT_FALSE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0)); // The previous |GetHighResAvater| starts |LoadAvatarPictureFromPath| async.
// The async code will end up at |OnAvatarPictureLoaded| storing an empty
// image in the cache.
EXPECT_CALL(observer(), OnProfileHighResAvatarLoaded(profile_path)).Times(1);
content::RunAllTasksUntilIdle();
VerifyAndResetCallExpectations();
std::string icon_filename =
profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex);
EXPECT_EQ(1U, storage()->cached_avatar_images_.size());
EXPECT_TRUE(storage()->cached_avatar_images_[icon_filename]->IsEmpty());
// Simulate downloading a high-res avatar. // Simulate downloading a high-res avatar.
ProfileAvatarDownloader avatar_downloader( ProfileAvatarDownloader avatar_downloader(
kIconIndex, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath, kIconIndex, base::Bind(&ProfileAttributesStorage::SaveAvatarImageAtPath,
base::Unretained(&profile_info_cache), base::Unretained(storage()), entry->GetPath()));
profile_info_cache.GetPathOfProfileAtIndex(0)));
// Put a real bitmap into "bitmap": a 2x2 bitmap of green 32 bit pixels. // Put a real bitmap into "bitmap": a 2x2 bitmap of green 32 bit pixels.
SkBitmap bitmap; SkBitmap bitmap;
...@@ -713,47 +746,49 @@ TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) { ...@@ -713,47 +746,49 @@ TEST_F(ProfileAttributesStorageTest, DownloadHighResAvatarTest) {
&bitmap); &bitmap);
// Now the download should not be in progress anymore. // Now the download should not be in progress anymore.
EXPECT_EQ(0U, profile_info_cache.avatar_images_downloads_in_progress_.size()); EXPECT_EQ(0U, storage()->avatar_images_downloads_in_progress_.size());
std::string file_name = // The image should have been cached.
profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex); EXPECT_EQ(1U, storage()->cached_avatar_images_.size());
EXPECT_FALSE(storage()->cached_avatar_images_[icon_filename]->IsEmpty());
EXPECT_EQ(storage()->cached_avatar_images_[icon_filename].get(),
entry->GetHighResAvatar());
// The file should have been cached and saved. // Since we are not using GAIA image, |GetAvatarIcon| should return the same
EXPECT_EQ(1U, profile_info_cache.cached_avatar_images_.size()); // image as |GetHighResAvatar| in desktop.
EXPECT_TRUE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0)); EXPECT_EQ(storage()->cached_avatar_images_[icon_filename].get(),
EXPECT_EQ(profile_info_cache.cached_avatar_images_[file_name].get(), &entry->GetAvatarIcon());
profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
// Make sure everything has completed, and the file has been written to disk. // Finish the async calls that save the image to the disk.
EXPECT_CALL(observer(), OnProfileHighResAvatarLoaded(profile_path)).Times(1);
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
VerifyAndResetCallExpectations();
// Clean up. // Clean up.
EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(icon_filename));
EXPECT_TRUE(base::PathExists(icon_path)); ASSERT_TRUE(base::PathExists(icon_path));
EXPECT_TRUE(base::DeleteFile(icon_path, false)); EXPECT_TRUE(base::DeleteFile(icon_path, false));
EXPECT_FALSE(base::PathExists(icon_path)); EXPECT_FALSE(base::PathExists(icon_path));
} }
TEST_F(ProfileAttributesStorageTest, NothingToDownloadHighResAvatarTest) { TEST_F(ProfileAttributesStorageTest, NothingToDownloadHighResAvatarTest) {
// The TestingProfileManager's ProfileInfoCache doesn't download avatars. storage()->set_disable_avatar_download_for_testing(false);
ProfileInfoCache profile_info_cache(
g_browser_process->local_state(),
testing_profile_manager_.profile_manager()->user_data_dir());
const size_t kIconIndex = profiles::GetPlaceholderAvatarIndex(); const size_t kIconIndex = profiles::GetPlaceholderAvatarIndex();
EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles()); EXPECT_EQ(0U, storage()->GetNumberOfProfiles());
base::FilePath path_1 = GetProfilePath("path_1"); base::FilePath profile_path = GetProfilePath("path_1");
profile_info_cache.AddProfile(path_1, base::ASCIIToUTF16("name_1"), EXPECT_CALL(observer(), OnProfileAdded(profile_path)).Times(1);
std::string(), base::string16(), kIconIndex, storage()->AddProfile(profile_path, base::ASCIIToUTF16("name_1"),
std::string()); std::string(), base::string16(), kIconIndex,
EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles()); std::string());
EXPECT_EQ(1U, storage()->GetNumberOfProfiles());
content::RunAllTasksUntilIdle(); content::RunAllTasksUntilIdle();
// We haven't tried to download any high-res avatars as the specified icon is // We haven't tried to download any high-res avatars as the specified icon is
// just a placeholder. // just a placeholder.
EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size()); EXPECT_EQ(0U, storage()->cached_avatar_images_.size());
EXPECT_EQ(0U, profile_info_cache.avatar_images_downloads_in_progress_.size()); EXPECT_EQ(0U, storage()->avatar_images_downloads_in_progress_.size());
} }
TEST_F(ProfileAttributesStorageTest, LoadAvatarFromDiskTest) { TEST_F(ProfileAttributesStorageTest, LoadAvatarFromDiskTest) {
...@@ -773,11 +808,13 @@ TEST_F(ProfileAttributesStorageTest, LoadAvatarFromDiskTest) { ...@@ -773,11 +808,13 @@ TEST_F(ProfileAttributesStorageTest, LoadAvatarFromDiskTest) {
ASSERT_TRUE(base::PathExists(icon_path)); ASSERT_TRUE(base::PathExists(icon_path));
// Add a new profile. // Add a new profile.
ASSERT_EQ(0U, storage()->GetNumberOfProfiles());
base::FilePath profile_path = GetProfilePath("path_1"); base::FilePath profile_path = GetProfilePath("path_1");
EXPECT_CALL(observer(), OnProfileAdded(profile_path)).Times(1); EXPECT_CALL(observer(), OnProfileAdded(profile_path)).Times(1);
storage()->AddProfile(profile_path, base::ASCIIToUTF16("name_1"), storage()->AddProfile(profile_path, base::ASCIIToUTF16("name_1"),
std::string(), base::string16(), kIconIndex, std::string(), base::string16(), kIconIndex,
std::string()); std::string());
EXPECT_EQ(1U, storage()->GetNumberOfProfiles());
VerifyAndResetCallExpectations(); VerifyAndResetCallExpectations();
// Load the avatar image. // Load the avatar image.
...@@ -793,7 +830,7 @@ TEST_F(ProfileAttributesStorageTest, LoadAvatarFromDiskTest) { ...@@ -793,7 +830,7 @@ TEST_F(ProfileAttributesStorageTest, LoadAvatarFromDiskTest) {
VerifyAndResetCallExpectations(); VerifyAndResetCallExpectations();
// Clean up. // Clean up.
base::DeleteFile(icon_path, false); EXPECT_TRUE(base::DeleteFile(icon_path, false));
EXPECT_FALSE(base::PathExists(icon_path)); EXPECT_FALSE(base::PathExists(icon_path));
} }
#endif #endif
...@@ -76,6 +76,7 @@ class ProfileInfoCache : public ProfileInfoInterface, ...@@ -76,6 +76,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
base::FilePath GetPathOfProfileAtIndex(size_t index) const override; base::FilePath GetPathOfProfileAtIndex(size_t index) const override;
// Will be removed SOON with ProfileInfoCache tests. Do not use! // Will be removed SOON with ProfileInfoCache tests. Do not use!
base::string16 GetUserNameOfProfileAtIndex(size_t index) const override; base::string16 GetUserNameOfProfileAtIndex(size_t index) const override;
// Will be removed SOON with ProfileInfoCache tests. Do not use!
const gfx::Image& GetAvatarIconOfProfileAtIndex(size_t index) const override; const gfx::Image& GetAvatarIconOfProfileAtIndex(size_t index) const override;
// Note that a return value of false could mean an error in collection or // Note that a return value of false could mean an error in collection or
// that there are currently no background apps running. However, the action // that there are currently no background apps running. However, the action
...@@ -102,7 +103,7 @@ class ProfileInfoCache : public ProfileInfoInterface, ...@@ -102,7 +103,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
// Returns true if a GAIA picture has been loaded or has failed to load for // Returns true if a GAIA picture has been loaded or has failed to load for
// profile at |index|. // profile at |index|.
bool IsGAIAPictureOfProfileAtIndexLoaded(size_t index) const; bool IsGAIAPictureOfProfileAtIndexLoaded(size_t index) const;
// Will be removed SOON with ProfileInfoCache tests. Do not use!
size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const; size_t GetAvatarIconIndexOfProfileAtIndex(size_t index) const;
// Warning: This will re-sort profiles and thus may change indices! // Warning: This will re-sort profiles and thus may change indices!
...@@ -110,6 +111,7 @@ class ProfileInfoCache : public ProfileInfoInterface, ...@@ -110,6 +111,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
void SetAuthInfoOfProfileAtIndex(size_t index, void SetAuthInfoOfProfileAtIndex(size_t index,
const std::string& gaia_id, const std::string& gaia_id,
const base::string16& user_name); const base::string16& user_name);
// Will be removed SOON with ProfileInfoCache tests. Do not use!
void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index); void SetAvatarIconOfProfileAtIndex(size_t index, size_t icon_index);
void SetIsOmittedProfileAtIndex(size_t index, bool is_omitted); void SetIsOmittedProfileAtIndex(size_t index, bool is_omitted);
void SetSupervisedUserIdOfProfileAtIndex(size_t index, const std::string& id); void SetSupervisedUserIdOfProfileAtIndex(size_t index, const std::string& id);
...@@ -164,6 +166,7 @@ class ProfileInfoCache : public ProfileInfoInterface, ...@@ -164,6 +166,7 @@ class ProfileInfoCache : public ProfileInfoInterface,
// of profiles is still sorted. // of profiles is still sorted.
void UpdateSortForProfileIndex(size_t index); void UpdateSortForProfileIndex(size_t index);
// Will be removed SOON with ProfileInfoCache tests. Do not use!
// Loads or uses an already loaded high resolution image of the // Loads or uses an already loaded high resolution image of the
// generic profile avatar. // generic profile avatar.
const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const; const gfx::Image* GetHighResAvatarOfProfileAtIndex(size_t index) const;
......
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