[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 | |
| 5 | #include "chrome/browser/profiles/profile_info_cache.h" |
| 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] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 10 | #include "chrome/browser/profiles/profile_manager.h" |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 11 | #include "chrome/common/chrome_notification_types.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 12 | #include "chrome/test/base/testing_browser_process.h" |
[email protected] | 8ad3636e | 2011-08-01 22:31:40 | [diff] [blame] | 13 | #include "chrome/test/base/testing_pref_service.h" |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 14 | #include "chrome/test/base/testing_profile_manager.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" |
| 18 | #include "content/test/test_browser_thread.h" |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 19 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 20 | #include "third_party/skia/include/core/SkBitmap.h" |
| 21 | #include "ui/base/resource/resource_bundle.h" |
| 22 | #include "ui/gfx/image/image.h" |
| 23 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 24 | using content::BrowserThread; |
| 25 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 26 | namespace { |
| 27 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 28 | bool IsEqual(const gfx::Image& image1, |
| 29 | const gfx::Image& image2) { |
| 30 | const SkBitmap& bmp1 = *image1.ToSkBitmap(); |
| 31 | const SkBitmap& bmp2 = *image2.ToSkBitmap(); |
| 32 | |
| 33 | if (bmp1.width() != bmp2.width() || |
| 34 | bmp1.height() != bmp2.height() || |
| 35 | bmp1.config() != SkBitmap::kARGB_8888_Config || |
| 36 | bmp2.config() != SkBitmap::kARGB_8888_Config) { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | SkAutoLockPixels lock1(bmp1); |
| 41 | SkAutoLockPixels lock2(bmp2); |
| 42 | if (!bmp1.getPixels() || !bmp2.getPixels()) |
| 43 | return false; |
| 44 | |
| 45 | for (int y = 0; y < bmp1.height(); ++y) { |
| 46 | for (int x = 0; x < bmp1.width(); ++x) { |
| 47 | if (*bmp1.getAddr32(x,y) != *bmp2.getAddr32(x,y)) |
| 48 | return false; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return true; |
| 53 | } |
| 54 | |
| 55 | gfx::Image CreateTestImage() { |
| 56 | SkBitmap bitmap; |
| 57 | bitmap.setConfig(SkBitmap::kARGB_8888_Config, 100, 50); |
| 58 | bitmap.allocPixels(); |
| 59 | bitmap.eraseRGB(0xff, 0, 0); |
| 60 | return gfx::Image(new SkBitmap(bitmap)); |
| 61 | } |
| 62 | |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 63 | class ProfileInfoCacheUnittests : public testing::Test { |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 64 | protected: |
[email protected] | 583844c | 2011-08-27 00:38:35 | [diff] [blame] | 65 | ProfileInfoCacheUnittests() |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 66 | : testing_profile_manager_( |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 67 | static_cast<TestingBrowserProcess*>(g_browser_process)), |
| 68 | ui_thread_(BrowserThread::UI, &ui_loop_), |
| 69 | file_thread_(BrowserThread::FILE) { |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 70 | } |
| 71 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 72 | virtual void SetUp() OVERRIDE { |
| 73 | ASSERT_TRUE(testing_profile_manager_.SetUp()); |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 74 | file_thread_.Start(); |
| 75 | } |
| 76 | |
| 77 | virtual void TearDown() OVERRIDE { |
| 78 | // Process all tasks on the FILE thread. |
| 79 | file_thread_.Stop(); |
| 80 | // The FILE thread might post tasks back to the UI thread so drain the UI |
| 81 | // thread too. |
| 82 | ui_loop_.RunAllPending(); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | ProfileInfoCache* GetCache() { |
| 86 | return testing_profile_manager_.profile_info_cache(); |
| 87 | } |
| 88 | |
| 89 | const FilePath& GetUserDataDir() { |
| 90 | return testing_profile_manager_.profile_manager()->user_data_dir(); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | FilePath StringToFilePath(std::string string_path) { |
| 94 | #if defined(OS_POSIX) |
| 95 | return FilePath(string_path); |
| 96 | #elif defined(OS_WIN) |
| 97 | return FilePath(ASCIIToWide(string_path)); |
| 98 | #endif |
| 99 | } |
| 100 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 101 | void ResetCache() { |
| 102 | testing_profile_manager_.DeleteProfileInfoCache(); |
| 103 | } |
| 104 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 105 | private: |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 106 | MessageLoopForUI ui_loop_; |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 107 | TestingProfileManager testing_profile_manager_; |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 108 | content::TestBrowserThread ui_thread_; |
| 109 | content::TestBrowserThread file_thread_; |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 110 | }; |
| 111 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 112 | TEST_F(ProfileInfoCacheUnittests, AddProfiles) { |
| 113 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 114 | |
| 115 | for (uint32 i = 0; i < 4; ++i) { |
| 116 | std::string base_name = StringPrintf("path_%ud", i); |
| 117 | FilePath profile_path = |
| 118 | GetUserDataDir().Append(StringToFilePath(base_name)); |
| 119 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 120 | const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
| 121 | ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
| 122 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 123 | GetCache()->AddProfileToCache(profile_path, profile_name, string16(), i); |
| 124 | GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); |
| 125 | string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i)); |
| 126 | GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 127 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 128 | EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
| 129 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 130 | EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
| 131 | const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 132 | EXPECT_EQ(icon.width(), actual_icon.width()); |
| 133 | EXPECT_EQ(icon.height(), actual_icon.height()); |
| 134 | } |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 135 | |
| 136 | // Reset the cache and test the it reloads correctly. |
| 137 | ResetCache(); |
| 138 | |
| 139 | EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); |
| 140 | for (uint32 i = 0; i < 4; ++i) { |
| 141 | std::string base_name = StringPrintf("path_%ud", i); |
| 142 | FilePath profile_path = |
| 143 | GetUserDataDir().Append(StringToFilePath(base_name)); |
| 144 | EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); |
| 145 | string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
| 146 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
| 147 | EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i)); |
| 148 | EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i)); |
| 149 | string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i)); |
| 150 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); |
| 151 | } |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 152 | } |
| 153 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 154 | TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { |
| 155 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 156 | |
| 157 | FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 158 | GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 159 | 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 160 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 161 | |
| 162 | FilePath path_2 = GetUserDataDir().Append(StringToFilePath("path_2")); |
| 163 | string16 name_2 = ASCIIToUTF16("name_2"); |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 164 | GetCache()->AddProfileToCache(path_2, name_2, string16(), 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 165 | EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 166 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 167 | GetCache()->DeleteProfileFromCache(path_1); |
| 168 | EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
| 169 | EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 170 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 171 | GetCache()->DeleteProfileFromCache(path_2); |
| 172 | EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 173 | } |
| 174 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 175 | TEST_F(ProfileInfoCacheUnittests, MutateProfile) { |
| 176 | GetCache()->AddProfileToCache(GetUserDataDir().Append( |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 177 | StringToFilePath("path_1")), ASCIIToUTF16("name_1"), string16(), 0); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 178 | GetCache()->AddProfileToCache(GetUserDataDir().Append( |
[email protected] | 73cb372 | 2011-10-11 18:12:13 | [diff] [blame] | 179 | StringToFilePath("path_2")), ASCIIToUTF16("name_2"), string16(), 0); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 180 | |
| 181 | string16 new_name = ASCIIToUTF16("new_name"); |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 182 | GetCache()->SetNameOfProfileAtIndex(1, new_name); |
| 183 | EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 184 | EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 185 | |
[email protected] | e8e7809 | 2011-09-29 18:15:38 | [diff] [blame] | 186 | string16 new_user_name = ASCIIToUTF16("user_name"); |
| 187 | GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); |
| 188 | EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
| 189 | EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
| 190 | |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 191 | size_t new_icon_index = 3; |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 192 | GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 193 | // Not much to test. |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 194 | GetCache()->GetAvatarIconOfProfileAtIndex(1); |
[email protected] | dee810e | 2011-06-27 19:43:39 | [diff] [blame] | 195 | } |
| 196 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 197 | TEST_F(ProfileInfoCacheUnittests, Sort) { |
| 198 | string16 name_a = ASCIIToUTF16("apple"); |
| 199 | GetCache()->AddProfileToCache(GetUserDataDir().Append( |
| 200 | StringToFilePath("path_a")), name_a, string16(), 0); |
| 201 | |
| 202 | string16 name_c = ASCIIToUTF16("cat"); |
| 203 | GetCache()->AddProfileToCache(GetUserDataDir().Append( |
| 204 | StringToFilePath("path_c")), name_c, string16(), 0); |
| 205 | |
| 206 | // Sanity check the initial order. |
| 207 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 208 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 209 | |
| 210 | // Add a new profile (start with a capital to test case insensitive sorting. |
| 211 | string16 name_b = ASCIIToUTF16("Banana"); |
| 212 | GetCache()->AddProfileToCache(GetUserDataDir().Append( |
| 213 | StringToFilePath("path_b")), name_b, string16(), 0); |
| 214 | |
| 215 | // Verify the new order. |
| 216 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); |
| 217 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); |
| 218 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); |
| 219 | |
| 220 | // Change the name of an existing profile. |
| 221 | name_a = UTF8ToUTF16("dog"); |
| 222 | GetCache()->SetNameOfProfileAtIndex(0, name_a); |
| 223 | |
| 224 | // Verify the new order. |
| 225 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 226 | EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); |
| 227 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); |
| 228 | |
| 229 | // Delete a profile. |
| 230 | GetCache()->DeleteProfileFromCache(GetUserDataDir().Append( |
| 231 | StringToFilePath("path_c"))); |
| 232 | |
| 233 | // Verify the new order. |
| 234 | EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); |
| 235 | EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); |
| 236 | } |
| 237 | |
[email protected] | 27917083 | 2011-10-12 23:38:03 | [diff] [blame] | 238 | TEST_F(ProfileInfoCacheUnittests, BackgroundModeStatus) { |
| 239 | GetCache()->AddProfileToCache( |
| 240 | GetUserDataDir().Append(StringToFilePath("path_1")), |
| 241 | ASCIIToUTF16("name_1"), string16(), 0); |
| 242 | GetCache()->AddProfileToCache( |
| 243 | GetUserDataDir().Append(StringToFilePath("path_2")), |
| 244 | ASCIIToUTF16("name_2"), string16(), 0); |
| 245 | |
| 246 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 247 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 248 | |
| 249 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
| 250 | |
| 251 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 252 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 253 | |
| 254 | GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
| 255 | |
| 256 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 257 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 258 | |
| 259 | GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
| 260 | |
| 261 | EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
| 262 | EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
| 263 | } |
| 264 | |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 265 | TEST_F(ProfileInfoCacheUnittests, HasMigrated) { |
| 266 | GetCache()->AddProfileToCache( |
| 267 | GetUserDataDir().Append(StringToFilePath("path_1")), |
| 268 | ASCIIToUTF16("name_1"), string16(), 0); |
| 269 | GetCache()->AddProfileToCache( |
| 270 | GetUserDataDir().Append(StringToFilePath("path_2")), |
| 271 | ASCIIToUTF16("name_2"), string16(), 0); |
| 272 | |
| 273 | // Sanity check. |
| 274 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 275 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 276 | |
| 277 | // Set migrated state for 2nd profile. |
| 278 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true); |
| 279 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 280 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 281 | |
| 282 | // Set migrated state for 1st profile. |
| 283 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true); |
| 284 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 285 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 286 | |
| 287 | // Unset migrated state for 2nd profile. |
| 288 | GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false); |
| 289 | EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); |
| 290 | EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); |
| 291 | } |
| 292 | |
| 293 | TEST_F(ProfileInfoCacheUnittests, GAIAName) { |
| 294 | GetCache()->AddProfileToCache( |
| 295 | GetUserDataDir().Append(StringToFilePath("path_1")), |
| 296 | ASCIIToUTF16("name_1"), string16(), 0); |
| 297 | string16 profile_name(ASCIIToUTF16("profile name 2")); |
| 298 | GetCache()->AddProfileToCache( |
| 299 | GetUserDataDir().Append(StringToFilePath("path_2")), |
| 300 | profile_name, string16(), 0); |
| 301 | |
| 302 | // Sanity check. |
| 303 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 304 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty()); |
| 305 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0)); |
| 306 | EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1)); |
| 307 | |
| 308 | // Set GAIA name. |
| 309 | string16 gaia_name(ASCIIToUTF16("Pat Smith")); |
| 310 | GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name); |
| 311 | EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); |
| 312 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 313 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 314 | |
| 315 | // Use GAIA name as profile name. |
| 316 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true); |
| 317 | |
| 318 | EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 319 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 320 | |
| 321 | // Don't use GAIA name as profile name. |
| 322 | GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false); |
| 323 | EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); |
| 324 | EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); |
| 325 | } |
| 326 | |
| 327 | TEST_F(ProfileInfoCacheUnittests, GAIAPicture) { |
| 328 | GetCache()->AddProfileToCache( |
| 329 | GetUserDataDir().Append(StringToFilePath("path_1")), |
| 330 | ASCIIToUTF16("name_1"), string16(), 0); |
| 331 | GetCache()->AddProfileToCache( |
| 332 | GetUserDataDir().Append(StringToFilePath("path_2")), |
| 333 | ASCIIToUTF16("name_2"), string16(), 0); |
| 334 | |
| 335 | // Sanity check. |
| 336 | EXPECT_TRUE( |
| 337 | GetCache()->GetGAIAPictureOfProfileAtIndex(0).ToSkBitmap()->isNull()); |
| 338 | EXPECT_TRUE( |
| 339 | GetCache()->GetGAIAPictureOfProfileAtIndex(1).ToSkBitmap()->isNull()); |
| 340 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); |
| 341 | EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); |
| 342 | |
| 343 | // The profile icon should be the default one. |
| 344 | int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); |
| 345 | const gfx::Image& profile_image( |
| 346 | ResourceBundle::GetSharedInstance().GetImageNamed(id)); |
| 347 | EXPECT_TRUE(IsEqual( |
| 348 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 349 | |
| 350 | // Set GAIA picture. |
| 351 | gfx::Image gaia_image(CreateTestImage()); |
| 352 | GetCache()->SetGAIAPictureOfProfileAtIndex(1, gaia_image); |
| 353 | EXPECT_TRUE( |
| 354 | GetCache()->GetGAIAPictureOfProfileAtIndex(0).ToSkBitmap()->isNull()); |
| 355 | EXPECT_TRUE(IsEqual( |
| 356 | gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
| 357 | EXPECT_TRUE(IsEqual( |
| 358 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 359 | |
| 360 | // Use GAIA picture as profile picture. |
| 361 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); |
| 362 | EXPECT_TRUE(IsEqual( |
| 363 | gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
| 364 | EXPECT_TRUE(IsEqual( |
| 365 | gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 366 | |
| 367 | // Don't use GAIA picture as profile picture. |
| 368 | GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); |
| 369 | EXPECT_TRUE(IsEqual( |
| 370 | gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(1))); |
| 371 | EXPECT_TRUE(IsEqual( |
| 372 | profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); |
| 373 | } |
| 374 | |
[email protected] | e6a43b29 | 2011-11-29 02:22:59 | [diff] [blame^] | 375 | #if defined(USE_AURA) |
| 376 | #define MAYBE_PersistGAIAPicture DISABLED_PersistGAIAPicture |
| 377 | #else |
| 378 | #define MAYBE_PersistGAIAPicture PersistGAIAPicture |
| 379 | #endif |
| 380 | |
| 381 | TEST_F(ProfileInfoCacheUnittests, MAYBE_PersistGAIAPicture) { |
[email protected] | cb114f14 | 2011-11-23 20:18:04 | [diff] [blame] | 382 | GetCache()->AddProfileToCache( |
| 383 | GetUserDataDir().Append(StringToFilePath("path_1")), |
| 384 | ASCIIToUTF16("name_1"), string16(), 0); |
| 385 | gfx::Image gaia_image(CreateTestImage()); |
| 386 | |
| 387 | ui_test_utils::WindowedNotificationObserver save_observer( |
| 388 | chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 389 | content::NotificationService::AllSources()); |
| 390 | GetCache()->SetGAIAPictureOfProfileAtIndex(0, gaia_image); |
| 391 | EXPECT_TRUE(IsEqual( |
| 392 | gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 393 | |
| 394 | // Wait for the file to be written to disk then reset the cache. |
| 395 | save_observer.Wait(); |
| 396 | ResetCache(); |
| 397 | |
| 398 | // Try to get the GAIA picture. This should return NULL until the read from |
| 399 | // disk is done. |
| 400 | ui_test_utils::WindowedNotificationObserver read_observer( |
| 401 | chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 402 | content::NotificationService::AllSources()); |
| 403 | EXPECT_TRUE( |
| 404 | GetCache()->GetGAIAPictureOfProfileAtIndex(0).ToSkBitmap()->isNull()); |
| 405 | read_observer.Wait(); |
| 406 | EXPECT_TRUE(IsEqual( |
| 407 | gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 408 | } |
| 409 | |
[email protected] | 6730b1e | 2011-09-29 05:23:52 | [diff] [blame] | 410 | } // namespace |