blob: 743ef4f7eb42f34c3e2d59aa940b6ccfb1480280 [file] [log] [blame]
[email protected]dee810e2011-06-27 19:43:391// 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]d4f5d1162011-11-30 01:41:525#include "chrome/browser/profiles/profile_info_cache_unittest.h"
[email protected]dee810e2011-06-27 19:43:396
7#include "base/stringprintf.h"
8#include "base/utf_string_conversions.h"
[email protected]583844c2011-08-27 00:38:359#include "chrome/browser/browser_process.h"
[email protected]d4f5d1162011-11-30 01:41:5210#include "chrome/browser/profiles/profile_info_cache.h"
[email protected]6730b1e2011-09-29 05:23:5211#include "chrome/browser/profiles/profile_manager.h"
[email protected]cb114f142011-11-23 20:18:0412#include "chrome/common/chrome_notification_types.h"
[email protected]583844c2011-08-27 00:38:3513#include "chrome/test/base/testing_browser_process.h"
[email protected]8ad3636e2011-08-01 22:31:4014#include "chrome/test/base/testing_pref_service.h"
[email protected]cb114f142011-11-23 20:18:0415#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]dee810e2011-06-27 19:43:3918#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]d4f5d1162011-11-30 01:41:5221#include "ui/gfx/image/image_unittest_util.h"
[email protected]dee810e2011-06-27 19:43:3922
[email protected]cb114f142011-11-23 20:18:0423using content::BrowserThread;
24
[email protected]590e189b2011-12-13 22:07:0325ProfileNameVerifierObserver::ProfileNameVerifierObserver() {
26}
27
28ProfileNameVerifierObserver::~ProfileNameVerifierObserver() {
29}
30
31void ProfileNameVerifierObserver::OnProfileAdded(
32 const string16& profile_name,
33 const string16& profile_base_dir,
34 const FilePath& profile_path,
35 const gfx::Image* avatar_image) {
36 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
37 profile_names_.insert(profile_name);
38}
39
[email protected]7b0af152011-12-16 17:02:0640void ProfileNameVerifierObserver::OnProfileWillBeRemoved(
[email protected]590e189b2011-12-13 22:07:0341 const string16& profile_name) {
42 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
43 profile_names_.erase(profile_name);
44}
45
[email protected]7b0af152011-12-16 17:02:0646void ProfileNameVerifierObserver::OnProfileWasRemoved(
47 const string16& profile_name) {
48 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
49}
50
[email protected]590e189b2011-12-13 22:07:0351void ProfileNameVerifierObserver::OnProfileNameChanged(
52 const string16& old_profile_name,
53 const string16& new_profile_name) {
54 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end());
55 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end());
56 profile_names_.erase(old_profile_name);
57 profile_names_.insert(new_profile_name);
58}
59
60void ProfileNameVerifierObserver::OnProfileAvatarChanged(
61 const string16& profile_name,
62 const string16& profile_base_dir,
63 const FilePath& profile_path,
64 const gfx::Image* avatar_image) {
65 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
66}
67
[email protected]d4f5d1162011-11-30 01:41:5268ProfileInfoCacheTest::ProfileInfoCacheTest()
69 : testing_profile_manager_(
70 static_cast<TestingBrowserProcess*>(g_browser_process)),
71 ui_thread_(BrowserThread::UI, &ui_loop_),
72 file_thread_(BrowserThread::FILE, &ui_loop_) {
73}
74
75ProfileInfoCacheTest::~ProfileInfoCacheTest() {
76}
77
78void ProfileInfoCacheTest::SetUp() {
79 ASSERT_TRUE(testing_profile_manager_.SetUp());
[email protected]590e189b2011-12-13 22:07:0380 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_);
[email protected]d4f5d1162011-11-30 01:41:5281}
82
[email protected]1302dcf2011-11-30 21:47:0583void ProfileInfoCacheTest::TearDown() {
84 // Drain the UI thread to make sure all tasks are completed. This prevents
85 // memory leaks.
86 ui_loop_.RunAllPending();
87}
88
[email protected]d4f5d1162011-11-30 01:41:5289ProfileInfoCache* ProfileInfoCacheTest::GetCache() {
90 return testing_profile_manager_.profile_info_cache();
91}
92
93FilePath ProfileInfoCacheTest::GetProfilePath(
94 const std::string& base_name) {
95 return testing_profile_manager_.profile_manager()->user_data_dir().
96 AppendASCII(base_name);
97}
98
99void ProfileInfoCacheTest::ResetCache() {
100 testing_profile_manager_.DeleteProfileInfoCache();
101}
102
[email protected]dee810e2011-06-27 19:43:39103namespace {
104
[email protected]d4f5d1162011-11-30 01:41:52105TEST_F(ProfileInfoCacheTest, AddProfiles) {
[email protected]6730b1e2011-09-29 05:23:52106 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39107
108 for (uint32 i = 0; i < 4; ++i) {
[email protected]d4f5d1162011-11-30 01:41:52109 FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i));
[email protected]dee810e2011-06-27 19:43:39110 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i));
111 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed(
112 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i));
113
[email protected]cb114f142011-11-23 20:18:04114 GetCache()->AddProfileToCache(profile_path, profile_name, string16(), i);
115 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true);
116 string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i));
117 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name);
[email protected]dee810e2011-06-27 19:43:39118
[email protected]6730b1e2011-09-29 05:23:52119 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles());
120 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
121 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i));
122 const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i);
[email protected]dee810e2011-06-27 19:43:39123 EXPECT_EQ(icon.width(), actual_icon.width());
124 EXPECT_EQ(icon.height(), actual_icon.height());
125 }
[email protected]cb114f142011-11-23 20:18:04126
127 // Reset the cache and test the it reloads correctly.
128 ResetCache();
129
130 EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles());
131 for (uint32 i = 0; i < 4; ++i) {
[email protected]d4f5d1162011-11-30 01:41:52132 FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i));
[email protected]cb114f142011-11-23 20:18:04133 EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path));
134 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i));
135 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
136 EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i));
137 EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i));
138 string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i));
139 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i));
140 }
[email protected]dee810e2011-06-27 19:43:39141}
142
[email protected]d4f5d1162011-11-30 01:41:52143TEST_F(ProfileInfoCacheTest, DeleteProfile) {
[email protected]6730b1e2011-09-29 05:23:52144 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39145
[email protected]d4f5d1162011-11-30 01:41:52146 FilePath path_1 = GetProfilePath("path_1");
[email protected]73cb3722011-10-11 18:12:13147 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(),
[email protected]dee810e2011-06-27 19:43:39148 0);
[email protected]6730b1e2011-09-29 05:23:52149 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39150
[email protected]d4f5d1162011-11-30 01:41:52151 FilePath path_2 = GetProfilePath("path_2");
[email protected]dee810e2011-06-27 19:43:39152 string16 name_2 = ASCIIToUTF16("name_2");
[email protected]73cb3722011-10-11 18:12:13153 GetCache()->AddProfileToCache(path_2, name_2, string16(), 0);
[email protected]6730b1e2011-09-29 05:23:52154 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39155
[email protected]6730b1e2011-09-29 05:23:52156 GetCache()->DeleteProfileFromCache(path_1);
157 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles());
158 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0));
[email protected]dee810e2011-06-27 19:43:39159
[email protected]6730b1e2011-09-29 05:23:52160 GetCache()->DeleteProfileFromCache(path_2);
161 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39162}
163
[email protected]d4f5d1162011-11-30 01:41:52164TEST_F(ProfileInfoCacheTest, MutateProfile) {
165 GetCache()->AddProfileToCache(
166 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
167 GetCache()->AddProfileToCache(
168 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]dee810e2011-06-27 19:43:39169
170 string16 new_name = ASCIIToUTF16("new_name");
[email protected]6730b1e2011-09-29 05:23:52171 GetCache()->SetNameOfProfileAtIndex(1, new_name);
172 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1));
173 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0));
[email protected]dee810e2011-06-27 19:43:39174
[email protected]e8e78092011-09-29 18:15:38175 string16 new_user_name = ASCIIToUTF16("user_name");
176 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name);
177 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1));
178 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0));
179
[email protected]dee810e2011-06-27 19:43:39180 size_t new_icon_index = 3;
[email protected]6730b1e2011-09-29 05:23:52181 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index);
[email protected]dee810e2011-06-27 19:43:39182 // Not much to test.
[email protected]6730b1e2011-09-29 05:23:52183 GetCache()->GetAvatarIconOfProfileAtIndex(1);
[email protected]dee810e2011-06-27 19:43:39184}
185
[email protected]d4f5d1162011-11-30 01:41:52186TEST_F(ProfileInfoCacheTest, Sort) {
[email protected]cb114f142011-11-23 20:18:04187 string16 name_a = ASCIIToUTF16("apple");
[email protected]d4f5d1162011-11-30 01:41:52188 GetCache()->AddProfileToCache(
189 GetProfilePath("path_a"), name_a, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04190
191 string16 name_c = ASCIIToUTF16("cat");
[email protected]d4f5d1162011-11-30 01:41:52192 GetCache()->AddProfileToCache(
193 GetProfilePath("path_c"), name_c, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04194
195 // Sanity check the initial order.
196 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0));
197 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1));
198
199 // Add a new profile (start with a capital to test case insensitive sorting.
200 string16 name_b = ASCIIToUTF16("Banana");
[email protected]d4f5d1162011-11-30 01:41:52201 GetCache()->AddProfileToCache(
202 GetProfilePath("path_b"), name_b, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04203
204 // Verify the new order.
205 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0));
206 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1));
207 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2));
208
209 // Change the name of an existing profile.
210 name_a = UTF8ToUTF16("dog");
211 GetCache()->SetNameOfProfileAtIndex(0, name_a);
212
213 // Verify the new order.
214 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0));
215 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1));
216 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2));
217
218 // Delete a profile.
[email protected]d4f5d1162011-11-30 01:41:52219 GetCache()->DeleteProfileFromCache(GetProfilePath("path_c"));
[email protected]cb114f142011-11-23 20:18:04220
221 // Verify the new order.
222 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0));
223 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1));
224}
225
[email protected]d4f5d1162011-11-30 01:41:52226TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) {
[email protected]279170832011-10-12 23:38:03227 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52228 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]279170832011-10-12 23:38:03229 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52230 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]279170832011-10-12 23:38:03231
232 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
233 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
234
235 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true);
236
237 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
238 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
239
240 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true);
241
242 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
243 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
244
245 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false);
246
247 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
248 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
249}
250
[email protected]d4f5d1162011-11-30 01:41:52251TEST_F(ProfileInfoCacheTest, HasMigrated) {
[email protected]cb114f142011-11-23 20:18:04252 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52253 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04254 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52255 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04256
257 // Sanity check.
258 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
259 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
260
261 // Set migrated state for 2nd profile.
262 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true);
263 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
264 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
265
266 // Set migrated state for 1st profile.
267 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true);
268 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
269 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
270
271 // Unset migrated state for 2nd profile.
272 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false);
273 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
274 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
275}
276
[email protected]d4f5d1162011-11-30 01:41:52277TEST_F(ProfileInfoCacheTest, GAIAName) {
[email protected]cb114f142011-11-23 20:18:04278 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52279 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04280 string16 profile_name(ASCIIToUTF16("profile name 2"));
281 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52282 GetProfilePath("path_2"), profile_name, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04283
284 // Sanity check.
285 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
286 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty());
287 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0));
288 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1));
289
290 // Set GAIA name.
291 string16 gaia_name(ASCIIToUTF16("Pat Smith"));
292 GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name);
293 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
294 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
295 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1));
296
297 // Use GAIA name as profile name.
298 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true);
299
300 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1));
301 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
302
303 // Don't use GAIA name as profile name.
304 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false);
305 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1));
306 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
307}
308
[email protected]d4f5d1162011-11-30 01:41:52309TEST_F(ProfileInfoCacheTest, GAIAPicture) {
[email protected]cb114f142011-11-23 20:18:04310 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52311 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04312 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52313 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04314
315 // Sanity check.
[email protected]2f3c00f2011-11-30 04:36:22316 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
317 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1));
[email protected]cb114f142011-11-23 20:18:04318 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0));
319 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1));
320
321 // The profile icon should be the default one.
322 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0);
323 const gfx::Image& profile_image(
324 ResourceBundle::GetSharedInstance().GetImageNamed(id));
[email protected]d4f5d1162011-11-30 01:41:52325 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04326 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
327
328 // Set GAIA picture.
[email protected]d4f5d1162011-11-30 01:41:52329 gfx::Image gaia_image(gfx::test::CreateImage());
[email protected]2f3c00f2011-11-30 04:36:22330 GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image);
331 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
[email protected]d4f5d1162011-11-30 01:41:52332 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22333 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
[email protected]d4f5d1162011-11-30 01:41:52334 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04335 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
336
337 // Use GAIA picture as profile picture.
338 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true);
[email protected]d4f5d1162011-11-30 01:41:52339 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22340 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
[email protected]d4f5d1162011-11-30 01:41:52341 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04342 gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
343
344 // Don't use GAIA picture as profile picture.
345 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false);
[email protected]d4f5d1162011-11-30 01:41:52346 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22347 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
[email protected]d4f5d1162011-11-30 01:41:52348 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04349 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
350}
351
[email protected]754bebc2011-12-01 16:42:16352TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) {
[email protected]cb114f142011-11-23 20:18:04353 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52354 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
355 gfx::Image gaia_image(gfx::test::CreateImage());
[email protected]cb114f142011-11-23 20:18:04356
357 ui_test_utils::WindowedNotificationObserver save_observer(
358 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED,
359 content::NotificationService::AllSources());
[email protected]2f3c00f2011-11-30 04:36:22360 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image);
[email protected]d4f5d1162011-11-30 01:41:52361 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22362 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
[email protected]cb114f142011-11-23 20:18:04363
364 // Wait for the file to be written to disk then reset the cache.
365 save_observer.Wait();
366 ResetCache();
367
368 // Try to get the GAIA picture. This should return NULL until the read from
369 // disk is done.
370 ui_test_utils::WindowedNotificationObserver read_observer(
371 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
372 content::NotificationService::AllSources());
[email protected]2f3c00f2011-11-30 04:36:22373 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
[email protected]cb114f142011-11-23 20:18:04374 read_observer.Wait();
[email protected]d4f5d1162011-11-30 01:41:52375 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22376 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
377}
378
379TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) {
380 string16 profile_name = ASCIIToUTF16("name_1");
381 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0);
382 const gfx::Image& profile_image(
383 ResourceBundle::GetSharedInstance().GetImageNamed(id));
384
385 GetCache()->AddProfileToCache(
386 GetProfilePath("path_1"), profile_name, string16(), 0);
387
388 // Set empty GAIA info.
389 GetCache()->SetGAIANameOfProfileAtIndex(0, string16());
390 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL);
391 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true);
392 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true);
393
394 // Verify that the profile name and picture are not empty.
395 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0));
396 EXPECT_TRUE(gfx::test::IsEqual(
397 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0)));
[email protected]cb114f142011-11-23 20:18:04398}
399
[email protected]6730b1e2011-09-29 05:23:52400} // namespace