blob: 5c75656fe92f71c219283cfa0ef22119ea7444fb [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]c0b030902011-12-19 16:21:0518#include "content/public/browser/notification_service.h"
[email protected]dee810e2011-06-27 19:43:3919#include "third_party/skia/include/core/SkBitmap.h"
20#include "ui/base/resource/resource_bundle.h"
21#include "ui/gfx/image/image.h"
[email protected]d4f5d1162011-11-30 01:41:5222#include "ui/gfx/image/image_unittest_util.h"
[email protected]dee810e2011-06-27 19:43:3923
[email protected]cb114f142011-11-23 20:18:0424using content::BrowserThread;
25
[email protected]6a460662011-12-22 22:05:1626ProfileNameVerifierObserver::ProfileNameVerifierObserver(
27 TestingProfileManager* testing_profile_manager)
28 : testing_profile_manager_(testing_profile_manager) {
29 DCHECK(testing_profile_manager_);
[email protected]590e189b2011-12-13 22:07:0330}
31
32ProfileNameVerifierObserver::~ProfileNameVerifierObserver() {
33}
34
35void ProfileNameVerifierObserver::OnProfileAdded(
[email protected]6a460662011-12-22 22:05:1636 const FilePath& profile_path) {
37 string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
38 GetCache()->GetIndexOfProfileWithPath(profile_path));
[email protected]590e189b2011-12-13 22:07:0339 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
40 profile_names_.insert(profile_name);
41}
42
[email protected]7b0af152011-12-16 17:02:0643void ProfileNameVerifierObserver::OnProfileWillBeRemoved(
[email protected]6a460662011-12-22 22:05:1644 const FilePath& profile_path) {
45 string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
46 GetCache()->GetIndexOfProfileWithPath(profile_path));
[email protected]590e189b2011-12-13 22:07:0347 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
48 profile_names_.erase(profile_name);
49}
50
[email protected]7b0af152011-12-16 17:02:0651void ProfileNameVerifierObserver::OnProfileWasRemoved(
[email protected]6a460662011-12-22 22:05:1652 const FilePath& profile_path,
[email protected]7b0af152011-12-16 17:02:0653 const string16& profile_name) {
54 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
55}
56
[email protected]590e189b2011-12-13 22:07:0357void ProfileNameVerifierObserver::OnProfileNameChanged(
[email protected]6a460662011-12-22 22:05:1658 const FilePath& profile_path,
59 const string16& old_profile_name) {
60 string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex(
61 GetCache()->GetIndexOfProfileWithPath(profile_path));
[email protected]590e189b2011-12-13 22:07:0362 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end());
63 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end());
64 profile_names_.erase(old_profile_name);
65 profile_names_.insert(new_profile_name);
66}
67
68void ProfileNameVerifierObserver::OnProfileAvatarChanged(
[email protected]6a460662011-12-22 22:05:1669 const FilePath& profile_path) {
70 string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
71 GetCache()->GetIndexOfProfileWithPath(profile_path));
[email protected]590e189b2011-12-13 22:07:0372 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
73}
74
[email protected]6a460662011-12-22 22:05:1675ProfileInfoCache* ProfileNameVerifierObserver::GetCache() {
76 return testing_profile_manager_->profile_info_cache();
77}
78
[email protected]d4f5d1162011-11-30 01:41:5279ProfileInfoCacheTest::ProfileInfoCacheTest()
80 : testing_profile_manager_(
81 static_cast<TestingBrowserProcess*>(g_browser_process)),
82 ui_thread_(BrowserThread::UI, &ui_loop_),
[email protected]6a460662011-12-22 22:05:1683 file_thread_(BrowserThread::FILE, &ui_loop_),
84 name_observer_(&testing_profile_manager_) {
[email protected]d4f5d1162011-11-30 01:41:5285}
86
87ProfileInfoCacheTest::~ProfileInfoCacheTest() {
88}
89
90void ProfileInfoCacheTest::SetUp() {
91 ASSERT_TRUE(testing_profile_manager_.SetUp());
[email protected]590e189b2011-12-13 22:07:0392 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_);
[email protected]d4f5d1162011-11-30 01:41:5293}
94
[email protected]1302dcf2011-11-30 21:47:0595void ProfileInfoCacheTest::TearDown() {
96 // Drain the UI thread to make sure all tasks are completed. This prevents
97 // memory leaks.
98 ui_loop_.RunAllPending();
99}
100
[email protected]d4f5d1162011-11-30 01:41:52101ProfileInfoCache* ProfileInfoCacheTest::GetCache() {
102 return testing_profile_manager_.profile_info_cache();
103}
104
105FilePath ProfileInfoCacheTest::GetProfilePath(
106 const std::string& base_name) {
107 return testing_profile_manager_.profile_manager()->user_data_dir().
108 AppendASCII(base_name);
109}
110
111void ProfileInfoCacheTest::ResetCache() {
112 testing_profile_manager_.DeleteProfileInfoCache();
113}
114
[email protected]dee810e2011-06-27 19:43:39115namespace {
116
[email protected]d4f5d1162011-11-30 01:41:52117TEST_F(ProfileInfoCacheTest, AddProfiles) {
[email protected]6730b1e2011-09-29 05:23:52118 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39119
120 for (uint32 i = 0; i < 4; ++i) {
[email protected]d4f5d1162011-11-30 01:41:52121 FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i));
[email protected]dee810e2011-06-27 19:43:39122 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i));
123 const SkBitmap& icon = ResourceBundle::GetSharedInstance().GetImageNamed(
124 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(i));
125
[email protected]cb114f142011-11-23 20:18:04126 GetCache()->AddProfileToCache(profile_path, profile_name, string16(), i);
127 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true);
128 string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i));
129 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name);
[email protected]dee810e2011-06-27 19:43:39130
[email protected]6730b1e2011-09-29 05:23:52131 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles());
132 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
133 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i));
134 const SkBitmap& actual_icon = GetCache()->GetAvatarIconOfProfileAtIndex(i);
[email protected]dee810e2011-06-27 19:43:39135 EXPECT_EQ(icon.width(), actual_icon.width());
136 EXPECT_EQ(icon.height(), actual_icon.height());
137 }
[email protected]cb114f142011-11-23 20:18:04138
139 // Reset the cache and test the it reloads correctly.
140 ResetCache();
141
142 EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles());
143 for (uint32 i = 0; i < 4; ++i) {
[email protected]d4f5d1162011-11-30 01:41:52144 FilePath profile_path = GetProfilePath(StringPrintf("path_%ud", i));
[email protected]cb114f142011-11-23 20:18:04145 EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path));
146 string16 profile_name = ASCIIToUTF16(StringPrintf("name_%ud", i));
147 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
148 EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i));
149 EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i));
150 string16 gaia_name = ASCIIToUTF16(StringPrintf("gaia_%ud", i));
151 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i));
152 }
[email protected]dee810e2011-06-27 19:43:39153}
154
[email protected]d4f5d1162011-11-30 01:41:52155TEST_F(ProfileInfoCacheTest, DeleteProfile) {
[email protected]6730b1e2011-09-29 05:23:52156 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39157
[email protected]d4f5d1162011-11-30 01:41:52158 FilePath path_1 = GetProfilePath("path_1");
[email protected]73cb3722011-10-11 18:12:13159 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(),
[email protected]dee810e2011-06-27 19:43:39160 0);
[email protected]6730b1e2011-09-29 05:23:52161 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39162
[email protected]d4f5d1162011-11-30 01:41:52163 FilePath path_2 = GetProfilePath("path_2");
[email protected]dee810e2011-06-27 19:43:39164 string16 name_2 = ASCIIToUTF16("name_2");
[email protected]73cb3722011-10-11 18:12:13165 GetCache()->AddProfileToCache(path_2, name_2, string16(), 0);
[email protected]6730b1e2011-09-29 05:23:52166 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39167
[email protected]6730b1e2011-09-29 05:23:52168 GetCache()->DeleteProfileFromCache(path_1);
169 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles());
170 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0));
[email protected]dee810e2011-06-27 19:43:39171
[email protected]6730b1e2011-09-29 05:23:52172 GetCache()->DeleteProfileFromCache(path_2);
173 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
[email protected]dee810e2011-06-27 19:43:39174}
175
[email protected]d4f5d1162011-11-30 01:41:52176TEST_F(ProfileInfoCacheTest, MutateProfile) {
177 GetCache()->AddProfileToCache(
178 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
179 GetCache()->AddProfileToCache(
180 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]dee810e2011-06-27 19:43:39181
182 string16 new_name = ASCIIToUTF16("new_name");
[email protected]6730b1e2011-09-29 05:23:52183 GetCache()->SetNameOfProfileAtIndex(1, new_name);
184 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1));
185 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0));
[email protected]dee810e2011-06-27 19:43:39186
[email protected]e8e78092011-09-29 18:15:38187 string16 new_user_name = ASCIIToUTF16("user_name");
188 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name);
189 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1));
190 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0));
191
[email protected]dee810e2011-06-27 19:43:39192 size_t new_icon_index = 3;
[email protected]6730b1e2011-09-29 05:23:52193 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index);
[email protected]dee810e2011-06-27 19:43:39194 // Not much to test.
[email protected]6730b1e2011-09-29 05:23:52195 GetCache()->GetAvatarIconOfProfileAtIndex(1);
[email protected]dee810e2011-06-27 19:43:39196}
197
[email protected]d4f5d1162011-11-30 01:41:52198TEST_F(ProfileInfoCacheTest, Sort) {
[email protected]cb114f142011-11-23 20:18:04199 string16 name_a = ASCIIToUTF16("apple");
[email protected]d4f5d1162011-11-30 01:41:52200 GetCache()->AddProfileToCache(
201 GetProfilePath("path_a"), name_a, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04202
203 string16 name_c = ASCIIToUTF16("cat");
[email protected]d4f5d1162011-11-30 01:41:52204 GetCache()->AddProfileToCache(
205 GetProfilePath("path_c"), name_c, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04206
207 // Sanity check the initial order.
208 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0));
209 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1));
210
211 // Add a new profile (start with a capital to test case insensitive sorting.
212 string16 name_b = ASCIIToUTF16("Banana");
[email protected]d4f5d1162011-11-30 01:41:52213 GetCache()->AddProfileToCache(
214 GetProfilePath("path_b"), name_b, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04215
216 // Verify the new order.
217 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0));
218 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1));
219 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2));
220
221 // Change the name of an existing profile.
222 name_a = UTF8ToUTF16("dog");
223 GetCache()->SetNameOfProfileAtIndex(0, name_a);
224
225 // Verify the new order.
226 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0));
227 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1));
228 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2));
229
230 // Delete a profile.
[email protected]d4f5d1162011-11-30 01:41:52231 GetCache()->DeleteProfileFromCache(GetProfilePath("path_c"));
[email protected]cb114f142011-11-23 20:18:04232
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]d4f5d1162011-11-30 01:41:52238TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) {
[email protected]279170832011-10-12 23:38:03239 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52240 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]279170832011-10-12 23:38:03241 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52242 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]279170832011-10-12 23:38:03243
244 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
245 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
246
247 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true);
248
249 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
250 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
251
252 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true);
253
254 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
255 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
256
257 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false);
258
259 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
260 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
261}
262
[email protected]d4f5d1162011-11-30 01:41:52263TEST_F(ProfileInfoCacheTest, HasMigrated) {
[email protected]cb114f142011-11-23 20:18:04264 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52265 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04266 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52267 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04268
269 // Sanity check.
270 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
271 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
272
273 // Set migrated state for 2nd profile.
274 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true);
275 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
276 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
277
278 // Set migrated state for 1st profile.
279 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true);
280 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
281 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
282
283 // Unset migrated state for 2nd profile.
284 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false);
285 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
286 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
287}
288
[email protected]d4f5d1162011-11-30 01:41:52289TEST_F(ProfileInfoCacheTest, GAIAName) {
[email protected]cb114f142011-11-23 20:18:04290 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52291 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04292 string16 profile_name(ASCIIToUTF16("profile name 2"));
293 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52294 GetProfilePath("path_2"), profile_name, string16(), 0);
[email protected]cb114f142011-11-23 20:18:04295
296 // Sanity check.
297 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
298 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty());
299 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0));
300 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1));
301
302 // Set GAIA name.
303 string16 gaia_name(ASCIIToUTF16("Pat Smith"));
304 GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name);
305 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
306 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
307 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1));
308
309 // Use GAIA name as profile name.
310 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true);
311
312 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1));
313 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
314
315 // Don't use GAIA name as profile name.
316 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false);
317 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1));
318 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
319}
320
[email protected]d4f5d1162011-11-30 01:41:52321TEST_F(ProfileInfoCacheTest, GAIAPicture) {
[email protected]cb114f142011-11-23 20:18:04322 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52323 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04324 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52325 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), string16(), 0);
[email protected]cb114f142011-11-23 20:18:04326
327 // Sanity check.
[email protected]2f3c00f2011-11-30 04:36:22328 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
329 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1));
[email protected]cb114f142011-11-23 20:18:04330 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0));
331 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1));
332
333 // The profile icon should be the default one.
334 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0);
335 const gfx::Image& profile_image(
336 ResourceBundle::GetSharedInstance().GetImageNamed(id));
[email protected]d4f5d1162011-11-30 01:41:52337 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04338 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
339
340 // Set GAIA picture.
[email protected]d4f5d1162011-11-30 01:41:52341 gfx::Image gaia_image(gfx::test::CreateImage());
[email protected]2f3c00f2011-11-30 04:36:22342 GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image);
343 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
[email protected]d4f5d1162011-11-30 01:41:52344 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22345 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
[email protected]d4f5d1162011-11-30 01:41:52346 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04347 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
348
349 // Use GAIA picture as profile picture.
350 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true);
[email protected]d4f5d1162011-11-30 01:41:52351 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22352 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
[email protected]d4f5d1162011-11-30 01:41:52353 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04354 gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
355
356 // Don't use GAIA picture as profile picture.
357 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false);
[email protected]d4f5d1162011-11-30 01:41:52358 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22359 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
[email protected]d4f5d1162011-11-30 01:41:52360 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]cb114f142011-11-23 20:18:04361 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
362}
363
[email protected]754bebc2011-12-01 16:42:16364TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) {
[email protected]cb114f142011-11-23 20:18:04365 GetCache()->AddProfileToCache(
[email protected]d4f5d1162011-11-30 01:41:52366 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), string16(), 0);
367 gfx::Image gaia_image(gfx::test::CreateImage());
[email protected]cb114f142011-11-23 20:18:04368
369 ui_test_utils::WindowedNotificationObserver save_observer(
370 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED,
371 content::NotificationService::AllSources());
[email protected]2f3c00f2011-11-30 04:36:22372 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image);
[email protected]d4f5d1162011-11-30 01:41:52373 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22374 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
[email protected]cb114f142011-11-23 20:18:04375
376 // Wait for the file to be written to disk then reset the cache.
377 save_observer.Wait();
378 ResetCache();
379
380 // Try to get the GAIA picture. This should return NULL until the read from
381 // disk is done.
382 ui_test_utils::WindowedNotificationObserver read_observer(
383 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
384 content::NotificationService::AllSources());
[email protected]2f3c00f2011-11-30 04:36:22385 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
[email protected]cb114f142011-11-23 20:18:04386 read_observer.Wait();
[email protected]d4f5d1162011-11-30 01:41:52387 EXPECT_TRUE(gfx::test::IsEqual(
[email protected]2f3c00f2011-11-30 04:36:22388 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
389}
390
391TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) {
392 string16 profile_name = ASCIIToUTF16("name_1");
393 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0);
394 const gfx::Image& profile_image(
395 ResourceBundle::GetSharedInstance().GetImageNamed(id));
396
397 GetCache()->AddProfileToCache(
398 GetProfilePath("path_1"), profile_name, string16(), 0);
399
400 // Set empty GAIA info.
401 GetCache()->SetGAIANameOfProfileAtIndex(0, string16());
402 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL);
403 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true);
404 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true);
405
406 // Verify that the profile name and picture are not empty.
407 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0));
408 EXPECT_TRUE(gfx::test::IsEqual(
409 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0)));
[email protected]cb114f142011-11-23 20:18:04410}
411
[email protected]6730b1e2011-09-29 05:23:52412} // namespace