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