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

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

Issue 845373002: Change default code flag to NewAvatarMenu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Test comment. GetAvatarIcon's no longer const. Created 5 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
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.cc ('k') | chrome/browser/profiles/profile_info_interface.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/profiles/profile_info_cache_unittest.cc
diff --git a/chrome/browser/profiles/profile_info_cache_unittest.cc b/chrome/browser/profiles/profile_info_cache_unittest.cc
index feb143a53eb293728b756495d74e292de5e58d2f..c2171e1fd72101e476e8103b4ebe83902751af75 100644
--- a/chrome/browser/profiles/profile_info_cache_unittest.cc
+++ b/chrome/browser/profiles/profile_info_cache_unittest.cc
@@ -122,6 +122,11 @@ void ProfileInfoCacheTest::ResetCache() {
TEST_F(ProfileInfoCacheTest, AddProfiles) {
EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
+ // A bitmap for the high res avatar cache. Icon-sized bitmap of green pixels.
+ SkBitmap bitmap;
+ bitmap.allocN32Pixels(38, 31);
+ bitmap.eraseColor(SK_ColorGREEN);
+
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
for (uint32 i = 0; i < 4; ++i) {
base::FilePath profile_path =
@@ -142,6 +147,12 @@ TEST_F(ProfileInfoCacheTest, AddProfiles) {
EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles());
EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i));
+
+ ProfileAvatarDownloader avatar_downloader(
+ GetCache()->GetAvatarIconIndexOfProfileAtIndex(i),
+ profile_path, GetCache());
+ avatar_downloader.OnFetchComplete(
+ GURL("http://www.google.com/avatar.png"), &bitmap);
const SkBitmap* actual_icon =
GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap();
EXPECT_EQ(icon->width(), actual_icon->width());
@@ -546,27 +557,39 @@ TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) {
switches::EnableNewAvatarMenuForTesting(
base::CommandLine::ForCurrentProcess());
- EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles());
+ // The TestingProfileManager's ProfileInfoCache auto-downloads avatars.
+ 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;
+ base::FilePath icon_path =
+ profiles::GetPathOfHighResAvatarAtIndex(kIconIndex);
+ EXPECT_TRUE(base::PathExists(icon_path));
+ EXPECT_TRUE(base::DeleteFile(icon_path, true));
+ EXPECT_FALSE(base::PathExists(icon_path));
+
+ EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles());
base::FilePath path_1 = GetProfilePath("path_1");
- GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"),
- base::string16(), 0, std::string());
- EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles());
+ profile_info_cache.AddProfileToCache(path_1, ASCIIToUTF16("name_1"),
+ base::string16(), kIconIndex, std::string());
+ EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles());
base::RunLoop().RunUntilIdle();
// We haven't downloaded any high-res avatars yet.
- EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size());
+ EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size());
// After adding a new profile, the download of high-res avatar will be
// triggered if the flag kNewAvatarMenu has been set. But the downloader
// won't ever call OnFetchComplete in the test.
- EXPECT_EQ(1U, GetCache()->avatar_images_downloads_in_progress_.size());
+ EXPECT_EQ(1U, profile_info_cache.avatar_images_downloads_in_progress_.size());
- EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
+ EXPECT_FALSE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
// Simulate downloading a high-res avatar.
- const size_t kIconIndex = 0;
ProfileAvatarDownloader avatar_downloader(
- kIconIndex, GetCache()->GetPathOfProfileAtIndex(0), GetCache());
+ kIconIndex, profile_info_cache.GetPathOfProfileAtIndex(0),
+ &profile_info_cache);
// Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels.
SkBitmap bitmap;
@@ -577,23 +600,21 @@ TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) {
GURL("http://www.google.com/avatar.png"), &bitmap);
// Now the download should not be in progress anymore.
- EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size());
+ EXPECT_EQ(0U, profile_info_cache.avatar_images_downloads_in_progress_.size());
std::string file_name =
profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex);
// The file should have been cached and saved.
- EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size());
- EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0));
- EXPECT_EQ(GetCache()->cached_avatar_images_[file_name],
- GetCache()->GetHighResAvatarOfProfileAtIndex(0));
+ EXPECT_EQ(1U, profile_info_cache.cached_avatar_images_.size());
+ EXPECT_TRUE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
+ EXPECT_EQ(profile_info_cache.cached_avatar_images_[file_name],
+ profile_info_cache.GetHighResAvatarOfProfileAtIndex(0));
// Make sure everything has completed, and the file has been written to disk.
base::RunLoop().RunUntilIdle();
// Clean up.
- base::FilePath icon_path =
- profiles::GetPathOfHighResAvatarAtIndex(kIconIndex);
EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name));
EXPECT_TRUE(base::PathExists(icon_path));
EXPECT_TRUE(base::DeleteFile(icon_path, true));
« no previous file with comments | « chrome/browser/profiles/profile_info_cache.cc ('k') | chrome/browser/profiles/profile_info_interface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698