OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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.h" | 5 #include "chrome/browser/profiles/profile_info_cache.h" |
6 | 6 |
7 #include "base/stringprintf.h" | 7 #include "base/stringprintf.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| 11 #include "chrome/common/chrome_notification_types.h" |
11 #include "chrome/test/base/testing_browser_process.h" | 12 #include "chrome/test/base/testing_browser_process.h" |
12 #include "chrome/test/base/testing_pref_service.h" | 13 #include "chrome/test/base/testing_pref_service.h" |
13 #include "chrome/test/base/testing_profile_manager.h" | 14 #include "chrome/test/base/testing_profile_manager.h" |
| 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" |
14 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
15 #include "third_party/skia/include/core/SkBitmap.h" | 20 #include "third_party/skia/include/core/SkBitmap.h" |
16 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
18 | 23 |
| 24 using content::BrowserThread; |
| 25 |
19 namespace { | 26 namespace { |
20 | 27 |
| 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 |
21 class ProfileInfoCacheUnittests : public testing::Test { | 63 class ProfileInfoCacheUnittests : public testing::Test { |
22 protected: | 64 protected: |
23 ProfileInfoCacheUnittests() | 65 ProfileInfoCacheUnittests() |
24 : testing_profile_manager_( | 66 : testing_profile_manager_( |
25 static_cast<TestingBrowserProcess*>(g_browser_process)) { | 67 static_cast<TestingBrowserProcess*>(g_browser_process)), |
| 68 ui_thread_(BrowserThread::UI, &ui_loop_), |
| 69 file_thread_(BrowserThread::FILE) { |
26 } | 70 } |
27 | 71 |
28 virtual void SetUp() OVERRIDE { | 72 virtual void SetUp() OVERRIDE { |
29 ASSERT_TRUE(testing_profile_manager_.SetUp()); | 73 ASSERT_TRUE(testing_profile_manager_.SetUp()); |
| 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(); |
30 } | 83 } |
31 | 84 |
32 ProfileInfoCache* GetCache() { | 85 ProfileInfoCache* GetCache() { |
33 return testing_profile_manager_.profile_info_cache(); | 86 return testing_profile_manager_.profile_info_cache(); |
34 } | 87 } |
35 | 88 |
36 const FilePath& GetUserDataDir() { | 89 const FilePath& GetUserDataDir() { |
37 return testing_profile_manager_.profile_manager()->user_data_dir(); | 90 return testing_profile_manager_.profile_manager()->user_data_dir(); |
38 } | 91 } |
39 | 92 |
40 FilePath StringToFilePath(std::string string_path) { | 93 FilePath StringToFilePath(std::string string_path) { |
41 #if defined(OS_POSIX) | 94 #if defined(OS_POSIX) |
42 return FilePath(string_path); | 95 return FilePath(string_path); |
43 #elif defined(OS_WIN) | 96 #elif defined(OS_WIN) |
44 return FilePath(ASCIIToWide(string_path)); | 97 return FilePath(ASCIIToWide(string_path)); |
45 #endif | 98 #endif |
46 } | 99 } |
47 | 100 |
| 101 void ResetCache() { |
| 102 testing_profile_manager_.DeleteProfileInfoCache(); |
| 103 } |
| 104 |
48 private: | 105 private: |
| 106 MessageLoopForUI ui_loop_; |
49 TestingProfileManager testing_profile_manager_; | 107 TestingProfileManager testing_profile_manager_; |
| 108 content::TestBrowserThread ui_thread_; |
| 109 content::TestBrowserThread file_thread_; |
50 }; | 110 }; |
51 | 111 |
52 TEST_F(ProfileInfoCacheUnittests, AddProfiles) { | 112 TEST_F(ProfileInfoCacheUnittests, AddProfiles) { |
53 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 113 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
54 | 114 |
55 for (uint32 i = 0; i < 4; ++i) { | 115 for (uint32 i = 0; i < 4; ++i) { |
56 std::string base_name = StringPrintf("path_%ud", i); | 116 std::string base_name = StringPrintf("path_%ud", i); |
57 FilePath profile_path = | 117 FilePath profile_path = |
58 GetUserDataDir().Append(StringToFilePath(base_name)); | 118 GetUserDataDir().Append(StringToFilePath(base_name)); |
59 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); | 119 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i)); |
60 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( | 120 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed( |
61 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); | 121 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i)); |
62 | 122 |
63 GetCache()->AddProfileToCache(profile_path, profile_name, string16(), 0); | 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); |
64 | 127 |
65 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); | 128 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); |
66 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); | 129 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); |
67 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); | 130 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); |
68 const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); | 131 const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i); |
69 EXPECT_EQ(icon.width(), actual_icon.width()); | 132 EXPECT_EQ(icon.width(), actual_icon.width()); |
70 EXPECT_EQ(icon.height(), actual_icon.height()); | 133 EXPECT_EQ(icon.height(), actual_icon.height()); |
71 } | 134 } |
| 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 } |
72 } | 152 } |
73 | 153 |
74 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { | 154 TEST_F(ProfileInfoCacheUnittests, DeleteProfile) { |
75 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); | 155 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); |
76 | 156 |
77 FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); | 157 FilePath path_1 = GetUserDataDir().Append(StringToFilePath("path_1")); |
78 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), | 158 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), |
79 0); | 159 0); |
80 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); | 160 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); |
81 | 161 |
(...skipping 25 matching lines...) Expand all Loading... |
107 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); | 187 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); |
108 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); | 188 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); |
109 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); | 189 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); |
110 | 190 |
111 size_t new_icon_index = 3; | 191 size_t new_icon_index = 3; |
112 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); | 192 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); |
113 // Not much to test. | 193 // Not much to test. |
114 GetCache()->GetAvatarIconOfProfileAtIndex(1); | 194 GetCache()->GetAvatarIconOfProfileAtIndex(1); |
115 } | 195 } |
116 | 196 |
| 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 |
117 TEST_F(ProfileInfoCacheUnittests, BackgroundModeStatus) { | 238 TEST_F(ProfileInfoCacheUnittests, BackgroundModeStatus) { |
118 GetCache()->AddProfileToCache( | 239 GetCache()->AddProfileToCache( |
119 GetUserDataDir().Append(StringToFilePath("path_1")), | 240 GetUserDataDir().Append(StringToFilePath("path_1")), |
120 ASCIIToUTF16("name_1"), string16(), 0); | 241 ASCIIToUTF16("name_1"), string16(), 0); |
121 GetCache()->AddProfileToCache( | 242 GetCache()->AddProfileToCache( |
122 GetUserDataDir().Append(StringToFilePath("path_2")), | 243 GetUserDataDir().Append(StringToFilePath("path_2")), |
123 ASCIIToUTF16("name_2"), string16(), 0); | 244 ASCIIToUTF16("name_2"), string16(), 0); |
124 | 245 |
125 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 246 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
126 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 247 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
127 | 248 |
128 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); | 249 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); |
129 | 250 |
130 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 251 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
131 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 252 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
132 | 253 |
133 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); | 254 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); |
134 | 255 |
135 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 256 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
136 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 257 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
137 | 258 |
138 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); | 259 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); |
139 | 260 |
140 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); | 261 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); |
141 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); | 262 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); |
142 } | 263 } |
143 | 264 |
| 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 |
| 375 TEST_F(ProfileInfoCacheUnittests, PersistGAIAPicture) { |
| 376 GetCache()->AddProfileToCache( |
| 377 GetUserDataDir().Append(StringToFilePath("path_1")), |
| 378 ASCIIToUTF16("name_1"), string16(), 0); |
| 379 gfx::Image gaia_image(CreateTestImage()); |
| 380 |
| 381 ui_test_utils::WindowedNotificationObserver save_observer( |
| 382 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, |
| 383 content::NotificationService::AllSources()); |
| 384 GetCache()->SetGAIAPictureOfProfileAtIndex(0, gaia_image); |
| 385 EXPECT_TRUE(IsEqual( |
| 386 gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 387 |
| 388 // Wait for the file to be written to disk then reset the cache. |
| 389 save_observer.Wait(); |
| 390 ResetCache(); |
| 391 |
| 392 // Try to get the GAIA picture. This should return NULL until the read from |
| 393 // disk is done. |
| 394 ui_test_utils::WindowedNotificationObserver read_observer( |
| 395 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
| 396 content::NotificationService::AllSources()); |
| 397 EXPECT_TRUE( |
| 398 GetCache()->GetGAIAPictureOfProfileAtIndex(0).ToSkBitmap()->isNull()); |
| 399 read_observer.Wait(); |
| 400 EXPECT_TRUE(IsEqual( |
| 401 gaia_image, GetCache()->GetGAIAPictureOfProfileAtIndex(0))); |
| 402 } |
| 403 |
144 } // namespace | 404 } // namespace |
OLD | NEW |