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