1 // Copyright (c) 2012 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.
5 #include "chrome/browser/profiles/profile_info_cache_unittest.h"
9 #include "base/prefs/testing_pref_service.h"
10 #include "base/strings/stringprintf.h"
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/time/time.h"
13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/prefs/pref_service_syncable.h"
16 #include "chrome/browser/profiles/profile_info_cache.h"
17 #include "chrome/browser/profiles/profile_manager.h"
18 #include "chrome/test/base/testing_browser_process.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "content/public/browser/notification_service.h"
22 #include "content/public/test/test_browser_thread_bundle.h"
23 #include "content/public/test/test_utils.h"
24 #include "third_party/skia/include/core/SkBitmap.h"
25 #include "ui/base/resource/resource_bundle.h"
26 #include "ui/gfx/image/image.h"
27 #include "ui/gfx/image/image_unittest_util.h"
29 using base::ASCIIToUTF16;
30 using base::UTF8ToUTF16;
31 using content::BrowserThread;
33 ProfileNameVerifierObserver::ProfileNameVerifierObserver(
34 TestingProfileManager* testing_profile_manager)
35 : testing_profile_manager_(testing_profile_manager) {
36 DCHECK(testing_profile_manager_);
39 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() {
42 void ProfileNameVerifierObserver::OnProfileAdded(
43 const base::FilePath& profile_path) {
44 base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
45 GetCache()->GetIndexOfProfileWithPath(profile_path));
46 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
47 profile_names_.insert(profile_name);
50 void ProfileNameVerifierObserver::OnProfileWillBeRemoved(
51 const base::FilePath& profile_path) {
52 base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
53 GetCache()->GetIndexOfProfileWithPath(profile_path));
54 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
55 profile_names_.erase(profile_name);
58 void ProfileNameVerifierObserver::OnProfileWasRemoved(
59 const base::FilePath& profile_path,
60 const base::string16& profile_name) {
61 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end());
64 void ProfileNameVerifierObserver::OnProfileNameChanged(
65 const base::FilePath& profile_path,
66 const base::string16& old_profile_name) {
67 base::string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex(
68 GetCache()->GetIndexOfProfileWithPath(profile_path));
69 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end());
70 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end());
71 profile_names_.erase(old_profile_name);
72 profile_names_.insert(new_profile_name);
75 void ProfileNameVerifierObserver::OnProfileAvatarChanged(
76 const base::FilePath& profile_path) {
77 base::string16 profile_name = GetCache()->GetNameOfProfileAtIndex(
78 GetCache()->GetIndexOfProfileWithPath(profile_path));
79 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end());
82 ProfileInfoCache* ProfileNameVerifierObserver::GetCache() {
83 return testing_profile_manager_->profile_info_cache();
86 ProfileInfoCacheTest::ProfileInfoCacheTest()
87 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()),
88 name_observer_(&testing_profile_manager_) {
91 ProfileInfoCacheTest::~ProfileInfoCacheTest() {
94 void ProfileInfoCacheTest::SetUp() {
95 ASSERT_TRUE(testing_profile_manager_.SetUp());
96 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_);
99 void ProfileInfoCacheTest::TearDown() {
100 // Drain the UI thread to make sure all tasks are completed. This prevents
102 base::RunLoop().RunUntilIdle();
105 ProfileInfoCache* ProfileInfoCacheTest::GetCache() {
106 return testing_profile_manager_.profile_info_cache();
109 base::FilePath ProfileInfoCacheTest::GetProfilePath(
110 const std::string& base_name) {
111 return testing_profile_manager_.profile_manager()->user_data_dir().
112 AppendASCII(base_name);
115 void ProfileInfoCacheTest::ResetCache() {
116 testing_profile_manager_.DeleteProfileInfoCache();
121 TEST_F(ProfileInfoCacheTest, AddProfiles) {
122 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
124 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
125 for (uint32 i = 0; i < 4; ++i) {
126 base::FilePath profile_path =
127 GetProfilePath(base::StringPrintf("path_%ud", i));
128 base::string16 profile_name =
129 ASCIIToUTF16(base::StringPrintf("name_%ud", i));
130 const SkBitmap* icon = rb.GetImageNamed(
131 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(
133 std::string managed_user_id = i == 3 ? "TEST_ID" : "";
135 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(),
137 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true);
138 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i));
139 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name);
141 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles());
142 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
143 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i));
144 const SkBitmap* actual_icon =
145 GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap();
146 EXPECT_EQ(icon->width(), actual_icon->width());
147 EXPECT_EQ(icon->height(), actual_icon->height());
148 EXPECT_EQ(i == 3, GetCache()->ProfileIsManagedAtIndex(i));
149 EXPECT_EQ(i == 3, GetCache()->IsOmittedProfileAtIndex(i));
150 EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i));
153 // Reset the cache and test the it reloads correctly.
156 EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles());
157 for (uint32 i = 0; i < 4; ++i) {
158 base::FilePath profile_path =
159 GetProfilePath(base::StringPrintf("path_%ud", i));
160 EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path));
161 base::string16 profile_name =
162 ASCIIToUTF16(base::StringPrintf("name_%ud", i));
163 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
164 EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i));
165 EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i));
166 base::string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i));
167 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i));
171 TEST_F(ProfileInfoCacheTest, DeleteProfile) {
172 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
174 base::FilePath path_1 = GetProfilePath("path_1");
175 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"),
176 base::string16(), 0, std::string());
177 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles());
179 base::FilePath path_2 = GetProfilePath("path_2");
180 base::string16 name_2 = ASCIIToUTF16("name_2");
181 GetCache()->AddProfileToCache(path_2, name_2, base::string16(), 0,
183 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles());
185 GetCache()->DeleteProfileFromCache(path_1);
186 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles());
187 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0));
189 GetCache()->DeleteProfileFromCache(path_2);
190 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
193 TEST_F(ProfileInfoCacheTest, MutateProfile) {
194 GetCache()->AddProfileToCache(
195 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
196 base::string16(), 0, std::string());
197 GetCache()->AddProfileToCache(
198 GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
199 base::string16(), 0, std::string());
201 base::string16 new_name = ASCIIToUTF16("new_name");
202 GetCache()->SetNameOfProfileAtIndex(1, new_name);
203 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1));
204 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0));
206 base::string16 new_user_name = ASCIIToUTF16("user_name");
207 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name);
208 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1));
209 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0));
211 size_t new_icon_index = 3;
212 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index);
214 GetCache()->GetAvatarIconOfProfileAtIndex(1);
217 TEST_F(ProfileInfoCacheTest, Sort) {
218 base::string16 name_a = ASCIIToUTF16("apple");
219 GetCache()->AddProfileToCache(
220 GetProfilePath("path_a"), name_a, base::string16(), 0, std::string());
222 base::string16 name_c = ASCIIToUTF16("cat");
223 GetCache()->AddProfileToCache(
224 GetProfilePath("path_c"), name_c, base::string16(), 0, std::string());
226 // Sanity check the initial order.
227 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0));
228 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1));
230 // Add a new profile (start with a capital to test case insensitive sorting.
231 base::string16 name_b = ASCIIToUTF16("Banana");
232 GetCache()->AddProfileToCache(
233 GetProfilePath("path_b"), name_b, base::string16(), 0, std::string());
235 // Verify the new order.
236 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0));
237 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1));
238 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2));
240 // Change the name of an existing profile.
241 name_a = UTF8ToUTF16("dog");
242 GetCache()->SetNameOfProfileAtIndex(0, name_a);
244 // Verify the new order.
245 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0));
246 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1));
247 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2));
250 GetCache()->DeleteProfileFromCache(GetProfilePath("path_c"));
252 // Verify the new order.
253 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0));
254 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1));
257 TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) {
258 GetCache()->AddProfileToCache(
259 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
260 base::string16(), 0, std::string());
261 GetCache()->AddProfileToCache(
262 GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
263 base::string16(), 0, std::string());
265 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
266 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
268 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true);
270 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
271 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
273 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true);
275 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
276 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
278 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false);
280 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0));
281 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1));
284 TEST_F(ProfileInfoCacheTest, HasMigrated) {
285 GetCache()->AddProfileToCache(
286 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
287 base::string16(), 0, std::string());
288 GetCache()->AddProfileToCache(
289 GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
290 base::string16(), 0, std::string());
293 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
294 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
296 // Set migrated state for 2nd profile.
297 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true);
298 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
299 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
301 // Set migrated state for 1st profile.
302 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true);
303 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
304 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
306 // Unset migrated state for 2nd profile.
307 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false);
308 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0));
309 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1));
312 TEST_F(ProfileInfoCacheTest, ProfileActiveTime) {
313 GetCache()->AddProfileToCache(
314 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
315 base::string16(), 0, std::string());
316 EXPECT_EQ(base::Time(), GetCache()->GetProfileActiveTimeAtIndex(0));
317 base::Time before = base::Time::Now();
318 GetCache()->SetProfileActiveTimeAtIndex(0);
319 base::Time after = base::Time::Now();
320 EXPECT_LE(before, GetCache()->GetProfileActiveTimeAtIndex(0));
321 EXPECT_GE(after, GetCache()->GetProfileActiveTimeAtIndex(0));
324 TEST_F(ProfileInfoCacheTest, GAIAName) {
325 GetCache()->AddProfileToCache(
326 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
327 base::string16(), 0, std::string());
328 base::string16 profile_name(ASCIIToUTF16("profile name 2"));
329 GetCache()->AddProfileToCache(
330 GetProfilePath("path_2"), profile_name, base::string16(), 0,
334 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
335 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty());
336 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0));
337 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1));
340 base::string16 gaia_name(ASCIIToUTF16("Pat Smith"));
341 GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name);
342 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty());
343 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
344 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1));
346 // Use GAIA name as profile name.
347 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true);
349 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1));
350 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
352 // Don't use GAIA name as profile name.
353 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false);
354 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1));
355 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1));
358 TEST_F(ProfileInfoCacheTest, GAIAPicture) {
359 GetCache()->AddProfileToCache(
360 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
361 base::string16(), 0, std::string());
362 GetCache()->AddProfileToCache(
363 GetProfilePath("path_2"), ASCIIToUTF16("name_2"),
364 base::string16(), 0, std::string());
367 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
368 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1));
369 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0));
370 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1));
372 // The profile icon should be the default one.
373 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0);
374 const gfx::Image& profile_image(
375 ResourceBundle::GetSharedInstance().GetImageNamed(id));
376 EXPECT_TRUE(gfx::test::IsEqual(
377 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
380 gfx::Image gaia_image(gfx::test::CreateImage());
381 GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image);
382 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
383 EXPECT_TRUE(gfx::test::IsEqual(
384 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
385 EXPECT_TRUE(gfx::test::IsEqual(
386 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
388 // Use GAIA picture as profile picture.
389 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true);
390 EXPECT_TRUE(gfx::test::IsEqual(
391 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
392 EXPECT_TRUE(gfx::test::IsEqual(
393 gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
395 // Don't use GAIA picture as profile picture.
396 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false);
397 EXPECT_TRUE(gfx::test::IsEqual(
398 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1)));
399 EXPECT_TRUE(gfx::test::IsEqual(
400 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1)));
403 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) {
404 GetCache()->AddProfileToCache(
405 GetProfilePath("path_1"), ASCIIToUTF16("name_1"),
406 base::string16(), 0, std::string());
407 gfx::Image gaia_image(gfx::test::CreateImage());
409 content::WindowedNotificationObserver save_observer(
410 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED,
411 content::NotificationService::AllSources());
412 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image);
413 EXPECT_TRUE(gfx::test::IsEqual(
414 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
416 // Wait for the file to be written to disk then reset the cache.
417 save_observer.Wait();
420 // Try to get the GAIA picture. This should return NULL until the read from
422 content::WindowedNotificationObserver read_observer(
423 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED,
424 content::NotificationService::AllSources());
425 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0));
426 read_observer.Wait();
427 EXPECT_TRUE(gfx::test::IsEqual(
428 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0)));
431 TEST_F(ProfileInfoCacheTest, SetManagedUserId) {
432 GetCache()->AddProfileToCache(
433 GetProfilePath("test"), ASCIIToUTF16("Test"),
434 base::string16(), 0, std::string());
435 EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0));
437 GetCache()->SetManagedUserIdOfProfileAtIndex(0, "TEST_ID");
438 EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0));
439 EXPECT_EQ("TEST_ID", GetCache()->GetManagedUserIdOfProfileAtIndex(0));
442 EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0));
444 GetCache()->SetManagedUserIdOfProfileAtIndex(0, std::string());
445 EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0));
446 EXPECT_EQ("", GetCache()->GetManagedUserIdOfProfileAtIndex(0));
449 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) {
450 base::string16 profile_name = ASCIIToUTF16("name_1");
451 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0);
452 const gfx::Image& profile_image(
453 ResourceBundle::GetSharedInstance().GetImageNamed(id));
455 GetCache()->AddProfileToCache(
456 GetProfilePath("path_1"), profile_name, base::string16(), 0,
459 // Set empty GAIA info.
460 GetCache()->SetGAIANameOfProfileAtIndex(0, base::string16());
461 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL);
462 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true);
463 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true);
465 // Verify that the profile name and picture are not empty.
466 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0));
467 EXPECT_TRUE(gfx::test::IsEqual(
468 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0)));
471 TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) {
472 testing_profile_manager_.CreateTestingProfile("default");
473 base::string16 managed_user_name = ASCIIToUTF16("Supervised User");
474 testing_profile_manager_.CreateTestingProfile(
475 "test1", scoped_ptr<PrefServiceSyncable>(),
476 managed_user_name, 0, "TEST_ID", TestingProfile::TestingFactories());
477 for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) {
479 GetCache()->GetNameOfProfileAtIndex(i) == managed_user_name;
480 EXPECT_EQ(is_managed, GetCache()->ProfileIsManagedAtIndex(i));
481 std::string managed_user_id = is_managed ? "TEST_ID" : "";
482 EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i));
485 // Managed profiles have a custom theme, which needs to be deleted on the FILE
486 // thread. Reset the profile manager now so everything is deleted while we
487 // still have a FILE thread.
488 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL);
491 TEST_F(ProfileInfoCacheTest, AddStubProfile) {
492 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles());
494 // Add some profiles with and without a '.' in their paths.
496 const char* profile_path;
497 const char* profile_name;
499 { "path.test0", "name_0" },
500 { "path_test1", "name_1" },
501 { "path.test2", "name_2" },
502 { "path_test3", "name_3" },
505 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kTestCases); ++i) {
506 base::FilePath profile_path = GetProfilePath(kTestCases[i].profile_path);
507 base::string16 profile_name = ASCIIToUTF16(kTestCases[i].profile_name);
509 GetCache()->AddProfileToCache(profile_path, profile_name, base::string16(),
512 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i));
513 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i));
516 ASSERT_EQ(4U, GetCache()->GetNumberOfProfiles());
518 // Check that the profiles can be extracted from the local state.
519 std::vector<base::string16> names = ProfileInfoCache::GetProfileNames();
520 for (size_t i = 0; i < 4; i++)
521 ASSERT_FALSE(names[i].empty());