OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/profiles/profile_info_cache_unittest.h" | 5 #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 AppendASCII(base_name); | 115 AppendASCII(base_name); |
116 } | 116 } |
117 | 117 |
118 void ProfileInfoCacheTest::ResetCache() { | 118 void ProfileInfoCacheTest::ResetCache() { |
119 testing_profile_manager_.DeleteProfileInfoCache(); | 119 testing_profile_manager_.DeleteProfileInfoCache(); |
120 } | 120 } |
121 | 121 |
122 TEST_F(ProfileInfoCacheTest, AddProfiles) { | 122 TEST_F(ProfileInfoCacheTest, AddProfiles) { |
123 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 123 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
124 | 124 |
125 // A bitmap for the high res avatar cache. Icon-sized bitmap of green pixels. | |
126 SkBitmap bitmap; | |
127 bitmap.allocN32Pixels(38, 31); | |
128 bitmap.eraseColor(SK_ColorGREEN); | |
129 | |
125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 130 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
126 for (uint32 i = 0; i < 4; ++i) { | 131 for (uint32 i = 0; i < 4; ++i) { |
127 base::FilePath profile_path = | 132 base::FilePath profile_path = |
128 GetProfilePath(base::StringPrintf("path_%ud", i)); | 133 GetProfilePath(base::StringPrintf("path_%ud", i)); |
129 base::string16 profile_name = | 134 base::string16 profile_name = |
130 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); | 135 ASCIIToUTF16(base::StringPrintf("name_%ud", i)); |
131 const SkBitmap* icon = rb.GetImageNamed( | 136 const SkBitmap* icon = rb.GetImageNamed( |
132 profiles::GetDefaultAvatarIconResourceIDAtIndex( | 137 profiles::GetDefaultAvatarIconResourceIDAtIndex( |
133 i)).ToSkBitmap(); | 138 i)).ToSkBitmap(); |
134 std::string supervised_user_id = i == 3 ? "TEST_ID" : ""; | 139 std::string supervised_user_id = i == 3 ? "TEST_ID" : ""; |
135 | 140 |
136 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), | 141 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(), |
137 i, supervised_user_id); | 142 i, supervised_user_id); |
138 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); | 143 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
139 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); | 144 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); |
140 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); | 145 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
141 | 146 |
142 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); | 147 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
143 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); | 148 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
144 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); | 149 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
150 | |
151 ProfileAvatarDownloader avatar_downloader( | |
152 GetCache()->GetAvatarIconIndexOfProfileAtIndex(i), | |
153 profile_path, GetCache()); | |
154 avatar_downloader.OnFetchComplete( | |
155 GURL("http://www.google.com/avatar.png"), &bitmap); | |
145 const SkBitmap* actual_icon = | 156 const SkBitmap* actual_icon = |
146 GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); | 157 GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); |
147 EXPECT_EQ(icon->width(), actual_icon->width()); | 158 EXPECT_EQ(icon->width(), actual_icon->width()); |
148 EXPECT_EQ(icon->height(), actual_icon->height()); | 159 EXPECT_EQ(icon->height(), actual_icon->height()); |
149 EXPECT_EQ(i == 3, GetCache()->ProfileIsSupervisedAtIndex(i)); | 160 EXPECT_EQ(i == 3, GetCache()->ProfileIsSupervisedAtIndex(i)); |
150 EXPECT_EQ(i == 3, GetCache()->IsOmittedProfileAtIndex(i)); | 161 EXPECT_EQ(i == 3, GetCache()->IsOmittedProfileAtIndex(i)); |
151 EXPECT_EQ(supervised_user_id, | 162 EXPECT_EQ(supervised_user_id, |
152 GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); | 163 GetCache()->GetSupervisedUserIdOfProfileAtIndex(i)); |
153 } | 164 } |
154 | 165 |
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
539 for (size_t i = 0; i < 4; i++) | 550 for (size_t i = 0; i < 4; i++) |
540 ASSERT_FALSE(names[i].empty()); | 551 ASSERT_FALSE(names[i].empty()); |
541 } | 552 } |
542 | 553 |
543 // High res avatar downloading is only supported on desktop. | 554 // High res avatar downloading is only supported on desktop. |
544 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) | 555 #if !defined(OS_ANDROID) && !defined(OS_IOS) && !defined(OS_CHROMEOS) |
545 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) { | 556 TEST_F(ProfileInfoCacheTest, DownloadHighResAvatarTest) { |
546 switches::EnableNewAvatarMenuForTesting( | 557 switches::EnableNewAvatarMenuForTesting( |
547 base::CommandLine::ForCurrentProcess()); | 558 base::CommandLine::ForCurrentProcess()); |
548 | 559 |
549 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | 560 // The TestingProfileManager's ProfileInfoCache auto-downloads avatars. |
561 ProfileInfoCache profile_info_cache(g_browser_process->local_state(), | |
562 testing_profile_manager_.profile_manager()->user_data_dir()); | |
563 | |
564 // // Make sure there are no avatars already on disk. | |
565 const size_t kIconIndex = 0; | |
566 base::FilePath icon_path = | |
567 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); | |
568 EXPECT_TRUE(base::PathExists(icon_path)); | |
569 EXPECT_TRUE(base::DeleteFile(icon_path, true)); | |
570 EXPECT_FALSE(base::PathExists(icon_path)); | |
571 | |
572 EXPECT_EQ(0U, profile_info_cache.GetNumberOfProfiles()); | |
550 base::FilePath path_1 = GetProfilePath("path_1"); | 573 base::FilePath path_1 = GetProfilePath("path_1"); |
551 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), | 574 profile_info_cache.AddProfileToCache(path_1, ASCIIToUTF16("name_1"), |
552 base::string16(), 0, std::string()); | 575 base::string16(), kIconIndex, std::string()); |
noms (inactive)
2015/03/17 14:26:30
nit: alignment here is whack :)
Mike Lerman
2015/03/18 19:29:48
Done.
| |
553 EXPECT_EQ(1U, GetCache()->GetNumberOfProfiles()); | 576 EXPECT_EQ(1U, profile_info_cache.GetNumberOfProfiles()); |
554 base::RunLoop().RunUntilIdle(); | 577 base::RunLoop().RunUntilIdle(); |
555 | 578 |
556 // We haven't downloaded any high-res avatars yet. | 579 // We haven't downloaded any high-res avatars yet. |
557 EXPECT_EQ(0U, GetCache()->cached_avatar_images_.size()); | 580 EXPECT_EQ(0U, profile_info_cache.cached_avatar_images_.size()); |
558 | 581 |
559 // After adding a new profile, the download of high-res avatar will be | 582 // After adding a new profile, the download of high-res avatar will be |
560 // triggered if the flag kNewAvatarMenu has been set. But the downloader | 583 // triggered if the flag kNewAvatarMenu has been set. But the downloader |
561 // won't ever call OnFetchComplete in the test. | 584 // won't ever call OnFetchComplete in the test. |
562 EXPECT_EQ(1U, GetCache()->avatar_images_downloads_in_progress_.size()); | 585 EXPECT_EQ(1U, profile_info_cache.avatar_images_downloads_in_progress_.size()); |
563 | 586 |
564 EXPECT_FALSE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); | 587 EXPECT_FALSE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0)); |
565 | 588 |
566 // Simulate downloading a high-res avatar. | 589 // Simulate downloading a high-res avatar. |
567 const size_t kIconIndex = 0; | |
568 ProfileAvatarDownloader avatar_downloader( | 590 ProfileAvatarDownloader avatar_downloader( |
569 kIconIndex, GetCache()->GetPathOfProfileAtIndex(0), GetCache()); | 591 kIconIndex, profile_info_cache.GetPathOfProfileAtIndex(0), |
592 &profile_info_cache); | |
570 | 593 |
571 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. | 594 // Put a real bitmap into "bitmap". 2x2 bitmap of green 32 bit pixels. |
572 SkBitmap bitmap; | 595 SkBitmap bitmap; |
573 bitmap.allocN32Pixels(2, 2); | 596 bitmap.allocN32Pixels(2, 2); |
574 bitmap.eraseColor(SK_ColorGREEN); | 597 bitmap.eraseColor(SK_ColorGREEN); |
575 | 598 |
576 avatar_downloader.OnFetchComplete( | 599 avatar_downloader.OnFetchComplete( |
577 GURL("http://www.google.com/avatar.png"), &bitmap); | 600 GURL("http://www.google.com/avatar.png"), &bitmap); |
578 | 601 |
579 // Now the download should not be in progress anymore. | 602 // Now the download should not be in progress anymore. |
580 EXPECT_EQ(0U, GetCache()->avatar_images_downloads_in_progress_.size()); | 603 EXPECT_EQ(0U, profile_info_cache.avatar_images_downloads_in_progress_.size()); |
581 | 604 |
582 std::string file_name = | 605 std::string file_name = |
583 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex); | 606 profiles::GetDefaultAvatarIconFileNameAtIndex(kIconIndex); |
584 | 607 |
585 // The file should have been cached and saved. | 608 // The file should have been cached and saved. |
586 EXPECT_EQ(1U, GetCache()->cached_avatar_images_.size()); | 609 EXPECT_EQ(1U, profile_info_cache.cached_avatar_images_.size()); |
587 EXPECT_TRUE(GetCache()->GetHighResAvatarOfProfileAtIndex(0)); | 610 EXPECT_TRUE(profile_info_cache.GetHighResAvatarOfProfileAtIndex(0)); |
588 EXPECT_EQ(GetCache()->cached_avatar_images_[file_name], | 611 EXPECT_EQ(profile_info_cache.cached_avatar_images_[file_name], |
589 GetCache()->GetHighResAvatarOfProfileAtIndex(0)); | 612 profile_info_cache.GetHighResAvatarOfProfileAtIndex(0)); |
590 | 613 |
591 // Make sure everything has completed, and the file has been written to disk. | 614 // Make sure everything has completed, and the file has been written to disk. |
592 base::RunLoop().RunUntilIdle(); | 615 base::RunLoop().RunUntilIdle(); |
593 | 616 |
594 // Clean up. | 617 // Clean up. |
595 base::FilePath icon_path = | |
596 profiles::GetPathOfHighResAvatarAtIndex(kIconIndex); | |
597 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); | 618 EXPECT_NE(std::string::npos, icon_path.MaybeAsASCII().find(file_name)); |
598 EXPECT_TRUE(base::PathExists(icon_path)); | 619 EXPECT_TRUE(base::PathExists(icon_path)); |
599 EXPECT_TRUE(base::DeleteFile(icon_path, true)); | 620 EXPECT_TRUE(base::DeleteFile(icon_path, true)); |
600 EXPECT_FALSE(base::PathExists(icon_path)); | 621 EXPECT_FALSE(base::PathExists(icon_path)); |
601 } | 622 } |
602 | 623 |
603 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { | 624 TEST_F(ProfileInfoCacheTest, MigrateLegacyProfileNamesWithNewAvatarMenu) { |
604 switches::EnableNewAvatarMenuForTesting( | 625 switches::EnableNewAvatarMenuForTesting( |
605 base::CommandLine::ForCurrentProcess()); | 626 base::CommandLine::ForCurrentProcess()); |
606 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); | 627 EXPECT_EQ(0U, GetCache()->GetNumberOfProfiles()); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 // Profile names should have been preserved. | 698 // Profile names should have been preserved. |
678 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( | 699 EXPECT_EQ(name_1, GetCache()->GetNameOfProfileAtIndex( |
679 GetCache()->GetIndexOfProfileWithPath(path_1))); | 700 GetCache()->GetIndexOfProfileWithPath(path_1))); |
680 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( | 701 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex( |
681 GetCache()->GetIndexOfProfileWithPath(path_2))); | 702 GetCache()->GetIndexOfProfileWithPath(path_2))); |
682 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( | 703 EXPECT_EQ(name_3, GetCache()->GetNameOfProfileAtIndex( |
683 GetCache()->GetIndexOfProfileWithPath(path_3))); | 704 GetCache()->GetIndexOfProfileWithPath(path_3))); |
684 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( | 705 EXPECT_EQ(name_4, GetCache()->GetNameOfProfileAtIndex( |
685 GetCache()->GetIndexOfProfileWithPath(path_4))); | 706 GetCache()->GetIndexOfProfileWithPath(path_4))); |
686 } | 707 } |
OLD | NEW |