Chromium Code Reviews| 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..8592550a0ccb589a03959a1bebe70516b6232da7 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( |
|
noms (inactive)
2015/04/07 13:55:20
nit: is this still needed? The comment on L560 say
Mike Lerman
2015/04/07 15:48:21
Good point!
|
| + 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 doesn't download 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)); |