[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 5 | #include "chrome/browser/profiles/profile_info_cache_unittest.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 6 | |
| 7 | #include "base/stringprintf.h" |
| 8 | #include "base/utf_string_conversions.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 9 | #include "chrome/browser/browser_process.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile_info_cache.h" |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 11 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 12 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 13 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame] | 14 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 15 | #include "chrome/test/base/ui_test_utils.h" |
| 16 | #include "content/public/browser/notification_observer.h" |
| 17 | #include "content/public/browser/notification_registrar.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 18 | #include "third_party/skia/include/core/SkBitmap.h" |
| 19 | #include "ui/base/resource/resource_bundle.h" |
| 20 | #include "ui/gfx/image/image.h" |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 21 | #include "ui/gfx/image/image_unittest_util.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 22 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 23 | using content::BrowserThread; |
| 24 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 25 | ProfileInfoCacheTest::ProfileInfoCacheTest() |
| 26 | : testing_profile_manager_( |
| 27 | static_cast<TestingBrowserProcess*>(g_browser_process)), |
| 28 | ui_thread_(BrowserThread::UI, &ui_loop_), |
| 29 | file_thread_(BrowserThread::FILE, &ui_loop_) { |
| 30 | } |
| 31 | |
| 32 | ProfileInfoCacheTest::~ProfileInfoCacheTest() { |
| 33 | } |
| 34 | |
| 35 | void ProfileInfoCacheTest::SetUp() { |
| 36 | ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 37 | } |
| 38 | |
[email protected] | 1302dcf | 2011-11-30 21:47:05 | [diff] [blame] | 39 | void ProfileInfoCacheTest::TearDown() { |
| 40 | // Drain the UI thread to make sure all tasks are completed. This prevents |
| 41 | // memory leaks. |
| 42 | ui_loop_.RunAllPending(); |
| 43 | } |
| 44 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 45 | ProfileInfoCache* ProfileInfoCacheTest::GetCache() { |
| 46 | return testing_profile_manager_.profile_info_cache(); |
| 47 | } |
| 48 | |
| 49 | FilePath ProfileInfoCacheTest::GetProfilePath( |
| 50 | const std::string& base_name) { |
| 51 | return testing_profile_manager_.profile_manager()->user_data_dir(). |
| 52 | AppendASCII(base_name); |
| 53 | } |
| 54 | |
| 55 | void ProfileInfoCacheTest::ResetCache() { |
| 56 | testing_profile_manager_.DeleteProfileInfoCache(); |
| 57 | } |
| 58 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 59 | namespace { |
| 60 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 61 | TEST_F(ProfileInfoCacheTest, AddProfiles) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 62 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 63 | |
| 64 | for (uint32 i = 0; i < 4; ++i) { |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 65 | FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 66 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 67 | const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
| 68 | ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
| 69 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 70 | GetCache()->AddProfileToCache(profile_path, profile_name, string16(), i); |
| 71 | GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
| 72 | string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i)); |
| 73 | GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 74 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 75 | EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 76 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 77 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 78 | const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 79 | EXPECT_EQ(icon.width(), actual_icon.width()); |
| 80 | EXPECT_EQ(icon.height(), actual_icon.height()); |
| 81 | } |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 82 | |
| 83 | // Reset the cache and test the it reloads correctly. |
| 84 | ResetCache(); |
| 85 | |
| 86 | EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
| 87 | for (uint32 i = 0; i < 4; ++i) { |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 88 | FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 89 | EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 90 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 91 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 92 | EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i)); |
| 93 | EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i)); |
| 94 | string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i)); |
| 95 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); |
| 96 | } |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 97 | } |
| 98 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 99 | TEST_F(ProfileInfoCacheTest, DeleteProfile) { |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 100 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 101 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 102 | FilePath path_1 = GetProfilePath("path_1"); |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 103 | GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 104 | 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 105 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 106 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 107 | FilePath path_2 = GetProfilePath("path_2"); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 108 | string16 name_2 = ASCIIToUTF16("name_2"); |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 109 | GetCache()->AddProfileToCache(path_2, name_2, string16(), 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 110 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 111 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 112 | GetCache()->DeleteProfileFromCache(path_1); |
| 113 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 114 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 115 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 116 | GetCache()->DeleteProfileFromCache(path_2); |
| 117 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 118 | } |
| 119 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 120 | TEST_F(ProfileInfoCacheTest, MutateProfile) { |
| 121 | GetCache()->AddProfileToCache( |
| 122 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
| 123 | GetCache()->AddProfileToCache( |
| 124 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 125 | |
| 126 | string16 new_name = ASCIIToUTF16("new_name"); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 127 | GetCache()->SetNameOfProfileAtIndex(1, new_name); |
| 128 | EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 129 | EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 130 | |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 131 | string16 new_user_name = ASCIIToUTF16("user_name"); |
| 132 | GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); |
| 133 | EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
| 134 | EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
| 135 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 136 | size_t new_icon_index = 3; |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 137 | GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 138 | // Not much to test. |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 139 | GetCache()->GetAvatarIconOfProfileAtIndex(1); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 140 | } |
| 141 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 142 | TEST_F(ProfileInfoCacheTest, Sort) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 143 | string16 name_a = ASCIIToUTF16("apple"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 144 | GetCache()->AddProfileToCache( |
| 145 | GetProfilePath("path_a"), name_a, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 146 | |
| 147 | string16 name_c = ASCIIToUTF16("cat"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 148 | GetCache()->AddProfileToCache( |
| 149 | GetProfilePath("path_c"), name_c, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 150 | |
| 151 | // Sanity check the initial order. |
| 152 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 153 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 154 | |
| 155 | // Add a new profile (start with a capital to test case insensitive sorting. |
| 156 | string16 name_b = ASCIIToUTF16("Banana"); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 157 | GetCache()->AddProfileToCache( |
| 158 | GetProfilePath("path_b"), name_b, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 159 | |
| 160 | // Verify the new order. |
| 161 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 162 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); |
| 163 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); |
| 164 | |
| 165 | // Change the name of an existing profile. |
| 166 | name_a = UTF8ToUTF16("dog"); |
| 167 | GetCache()->SetNameOfProfileAtIndex(0, name_a); |
| 168 | |
| 169 | // Verify the new order. |
| 170 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 171 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 172 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); |
| 173 | |
| 174 | // Delete a profile. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 175 | GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 176 | |
| 177 | // Verify the new order. |
| 178 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 179 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); |
| 180 | } |
| 181 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 182 | TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 183 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 184 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 185 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 186 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 187 | |
| 188 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 189 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 190 | |
| 191 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
| 192 | |
| 193 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 194 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 195 | |
| 196 | GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
| 197 | |
| 198 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 199 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 200 | |
| 201 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
| 202 | |
| 203 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 204 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 205 | } |
| 206 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 207 | TEST_F(ProfileInfoCacheTest, HasMigrated) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 208 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 209 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 210 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 211 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 212 | |
| 213 | // Sanity check. |
| 214 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 215 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 216 | |
| 217 | // Set migrated state for 2nd profile. |
| 218 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true); |
| 219 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 220 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 221 | |
| 222 | // Set migrated state for 1st profile. |
| 223 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true); |
| 224 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 225 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 226 | |
| 227 | // Unset migrated state for 2nd profile. |
| 228 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false); |
| 229 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 230 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 231 | } |
| 232 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 233 | TEST_F(ProfileInfoCacheTest, GAIAName) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 234 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 235 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 236 | string16 profile_name(ASCIIToUTF16("profile name 2")); |
| 237 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 238 | GetProfilePath("path_2"), profile_name, string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 239 | |
| 240 | // Sanity check. |
| 241 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 242 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty()); |
| 243 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0)); |
| 244 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1)); |
| 245 | |
| 246 | // Set GAIA name. |
| 247 | string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
| 248 | GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name); |
| 249 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 250 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 251 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 252 | |
| 253 | // Use GAIA name as profile name. |
| 254 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true); |
| 255 | |
| 256 | EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 257 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 258 | |
| 259 | // Don't use GAIA name as profile name. |
| 260 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false); |
| 261 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 262 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 263 | } |
| 264 | |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 265 | TEST_F(ProfileInfoCacheTest, GAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 266 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 267 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 268 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 269 | GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 270 | |
| 271 | // Sanity check. |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 272 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
| 273 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 274 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 275 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
| 276 | |
| 277 | // The profile icon should be the default one. |
| 278 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 279 | const gfx::Image& profile_image( |
| 280 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 281 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 282 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 283 | |
| 284 | // Set GAIA picture. |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 285 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 286 | GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image); |
| 287 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 288 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 289 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 290 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 291 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 292 | |
| 293 | // Use GAIA picture as profile picture. |
| 294 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 295 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 296 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 297 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 298 | gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 299 | |
| 300 | // Don't use GAIA picture as profile picture. |
| 301 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 302 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 303 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 304 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 305 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 306 | } |
| 307 | |
[email protected] | 754bebc | 2011-12-01 16:42:16 | [diff] [blame^] | 308 | TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 309 | GetCache()->AddProfileToCache( |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 310 | GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0); |
| 311 | gfx::Image gaia_image(gfx::test::CreateImage()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 312 | |
| 313 | ui_test_utils::WindowedNotificationObserver save_observer( |
| 314 | chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 315 | content::NotificationService::AllSources()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 316 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 317 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 318 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 319 | |
| 320 | // Wait for the file to be written to disk then reset the cache. |
| 321 | save_observer.Wait(); |
| 322 | ResetCache(); |
| 323 | |
| 324 | // Try to get the GAIA picture. This should return NULL until the read from |
| 325 | // disk is done. |
| 326 | ui_test_utils::WindowedNotificationObserver read_observer( |
| 327 | chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 328 | content::NotificationService::AllSources()); |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 329 | EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 330 | read_observer.Wait(); |
[email protected] | d4f5d116 | 2011-11-30 01:41:52 | [diff] [blame] | 331 | EXPECT_TRUE(gfx::test::IsEqual( |
[email protected] | 2f3c00f | 2011-11-30 04:36:22 | [diff] [blame] | 332 | gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 333 | } |
| 334 | |
| 335 | TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { |
| 336 | string16 profile_name = ASCIIToUTF16("name_1"); |
| 337 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 338 | const gfx::Image& profile_image( |
| 339 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
| 340 | |
| 341 | GetCache()->AddProfileToCache( |
| 342 | GetProfilePath("path_1"), profile_name, string16(), 0); |
| 343 | |
| 344 | // Set empty GAIA info. |
| 345 | GetCache()->SetGAIANameOfProfileAtIndex(0, string16()); |
| 346 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); |
| 347 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); |
| 348 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); |
| 349 | |
| 350 | // Verify that the profile name and picture are not empty. |
| 351 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); |
| 352 | EXPECT_TRUE(gfx::test::IsEqual( |
| 353 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 356 | } // namespace |