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. 4 5 #include "chrome/browser/profiles/profile_info_cache_unittest.h" 6 7 #include "base/prefs/testing_pref_service.h" 8 #include "base/strings/stringprintf.h" 9 #include "base/strings/utf_string_conversions.h" 10 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/chrome_notification_types.h" 12 #include "chrome/browser/prefs/pref_service_syncable.h" 13 #include "chrome/browser/profiles/profile_info_cache.h" 14 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/test/base/testing_browser_process.h" 16 #include "content/public/browser/notification_observer.h" 17 #include "content/public/browser/notification_registrar.h" 18 #include "content/public/browser/notification_service.h" 19 #include "content/public/test/test_utils.h" 20 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/gfx/image/image.h" 23 #include "ui/gfx/image/image_unittest_util.h" 24 25 using content::BrowserThread; 26 27 ProfileNameVerifierObserver::ProfileNameVerifierObserver( 28 TestingProfileManager* testing_profile_manager) 29 : testing_profile_manager_(testing_profile_manager) { 30 DCHECK(testing_profile_manager_); 31 } 32 33 ProfileNameVerifierObserver::~ProfileNameVerifierObserver() { 34 } 35 36 void ProfileNameVerifierObserver::OnProfileAdded( 37 const base::FilePath& profile_path) { 38 string16 profile_name = GetCache()->GetNameOfProfileAtIndex( 39 GetCache()->GetIndexOfProfileWithPath(profile_path)); 40 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); 41 profile_names_.insert(profile_name); 42 } 43 44 void ProfileNameVerifierObserver::OnProfileWillBeRemoved( 45 const base::FilePath& profile_path) { 46 string16 profile_name = GetCache()->GetNameOfProfileAtIndex( 47 GetCache()->GetIndexOfProfileWithPath(profile_path)); 48 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); 49 profile_names_.erase(profile_name); 50 } 51 52 void ProfileNameVerifierObserver::OnProfileWasRemoved( 53 const base::FilePath& profile_path, 54 const string16& profile_name) { 55 EXPECT_TRUE(profile_names_.find(profile_name) == profile_names_.end()); 56 } 57 58 void ProfileNameVerifierObserver::OnProfileNameChanged( 59 const base::FilePath& profile_path, 60 const string16& old_profile_name) { 61 string16 new_profile_name = GetCache()->GetNameOfProfileAtIndex( 62 GetCache()->GetIndexOfProfileWithPath(profile_path)); 63 EXPECT_TRUE(profile_names_.find(old_profile_name) != profile_names_.end()); 64 EXPECT_TRUE(profile_names_.find(new_profile_name) == profile_names_.end()); 65 profile_names_.erase(old_profile_name); 66 profile_names_.insert(new_profile_name); 67 } 68 69 void ProfileNameVerifierObserver::OnProfileAvatarChanged( 70 const base::FilePath& profile_path) { 71 string16 profile_name = GetCache()->GetNameOfProfileAtIndex( 72 GetCache()->GetIndexOfProfileWithPath(profile_path)); 73 EXPECT_TRUE(profile_names_.find(profile_name) != profile_names_.end()); 74 } 75 76 ProfileInfoCache* ProfileNameVerifierObserver::GetCache() { 77 return testing_profile_manager_->profile_info_cache(); 78 } 79 80 ProfileInfoCacheTest::ProfileInfoCacheTest() 81 : testing_profile_manager_(TestingBrowserProcess::GetGlobal()), 82 name_observer_(&testing_profile_manager_) { 83 } 84 85 ProfileInfoCacheTest::~ProfileInfoCacheTest() { 86 } 87 88 void ProfileInfoCacheTest::SetUp() { 89 ASSERT_TRUE(testing_profile_manager_.SetUp()); 90 testing_profile_manager_.profile_info_cache()->AddObserver(&name_observer_); 91 } 92 93 void ProfileInfoCacheTest::TearDown() { 94 // Drain the UI thread to make sure all tasks are completed. This prevents 95 // memory leaks. 96 base::RunLoop().RunUntilIdle(); 97 } 98 99 ProfileInfoCache* ProfileInfoCacheTest::GetCache() { 100 return testing_profile_manager_.profile_info_cache(); 101 } 102 103 base::FilePath ProfileInfoCacheTest::GetProfilePath( 104 const std::string& base_name) { 105 return testing_profile_manager_.profile_manager()->user_data_dir(). 106 AppendASCII(base_name); 107 } 108 109 void ProfileInfoCacheTest::ResetCache() { 110 testing_profile_manager_.DeleteProfileInfoCache(); 111 } 112 113 namespace { 114 115 TEST_F(ProfileInfoCacheTest, AddProfiles) { 116 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); 117 118 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 119 for (uint32 i = 0; i < 4; ++i) { 120 base::FilePath profile_path = 121 GetProfilePath(base::StringPrintf("path_%ud", i)); 122 string16 profile_name = ASCIIToUTF16(base::StringPrintf("name_%ud", i)); 123 const SkBitmap* icon = rb.GetImageNamed( 124 ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex( 125 i)).ToSkBitmap(); 126 std::string managed_user_id = i == 3 ? "TEST_ID" : ""; 127 128 GetCache()->AddProfileToCache(profile_path, profile_name, string16(), i, 129 managed_user_id); 130 GetCache()->SetBackgroundStatusOfProfileAtIndex(i, true); 131 string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); 132 GetCache()->SetGAIANameOfProfileAtIndex(i, gaia_name); 133 134 EXPECT_EQ(i + 1, GetCache()->GetNumberOfProfiles()); 135 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); 136 EXPECT_EQ(profile_path, GetCache()->GetPathOfProfileAtIndex(i)); 137 const SkBitmap* actual_icon = 138 GetCache()->GetAvatarIconOfProfileAtIndex(i).ToSkBitmap(); 139 EXPECT_EQ(icon->width(), actual_icon->width()); 140 EXPECT_EQ(icon->height(), actual_icon->height()); 141 EXPECT_EQ(i == 3, GetCache()->ProfileIsManagedAtIndex(i)); 142 EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); 143 } 144 145 // Reset the cache and test the it reloads correctly. 146 ResetCache(); 147 148 EXPECT_EQ(4u, GetCache()->GetNumberOfProfiles()); 149 for (uint32 i = 0; i < 4; ++i) { 150 base::FilePath profile_path = 151 GetProfilePath(base::StringPrintf("path_%ud", i)); 152 EXPECT_EQ(i, GetCache()->GetIndexOfProfileWithPath(profile_path)); 153 string16 profile_name = ASCIIToUTF16(base::StringPrintf("name_%ud", i)); 154 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(i)); 155 EXPECT_EQ(i, GetCache()->GetAvatarIconIndexOfProfileAtIndex(i)); 156 EXPECT_EQ(true, GetCache()->GetBackgroundStatusOfProfileAtIndex(i)); 157 string16 gaia_name = ASCIIToUTF16(base::StringPrintf("gaia_%ud", i)); 158 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(i)); 159 } 160 } 161 162 TEST_F(ProfileInfoCacheTest, DeleteProfile) { 163 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); 164 165 base::FilePath path_1 = GetProfilePath("path_1"); 166 GetCache()->AddProfileToCache(path_1, ASCIIToUTF16("name_1"), string16(), 167 0, std::string()); 168 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); 169 170 base::FilePath path_2 = GetProfilePath("path_2"); 171 string16 name_2 = ASCIIToUTF16("name_2"); 172 GetCache()->AddProfileToCache(path_2, name_2, string16(), 0, std::string()); 173 EXPECT_EQ(2u, GetCache()->GetNumberOfProfiles()); 174 175 GetCache()->DeleteProfileFromCache(path_1); 176 EXPECT_EQ(1u, GetCache()->GetNumberOfProfiles()); 177 EXPECT_EQ(name_2, GetCache()->GetNameOfProfileAtIndex(0)); 178 179 GetCache()->DeleteProfileFromCache(path_2); 180 EXPECT_EQ(0u, GetCache()->GetNumberOfProfiles()); 181 } 182 183 TEST_F(ProfileInfoCacheTest, MutateProfile) { 184 GetCache()->AddProfileToCache( 185 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 186 string16(), 0, std::string()); 187 GetCache()->AddProfileToCache( 188 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), 189 string16(), 0, std::string()); 190 191 string16 new_name = ASCIIToUTF16("new_name"); 192 GetCache()->SetNameOfProfileAtIndex(1, new_name); 193 EXPECT_EQ(new_name, GetCache()->GetNameOfProfileAtIndex(1)); 194 EXPECT_NE(new_name, GetCache()->GetNameOfProfileAtIndex(0)); 195 196 string16 new_user_name = ASCIIToUTF16("user_name"); 197 GetCache()->SetUserNameOfProfileAtIndex(1, new_user_name); 198 EXPECT_EQ(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(1)); 199 EXPECT_NE(new_user_name, GetCache()->GetUserNameOfProfileAtIndex(0)); 200 201 size_t new_icon_index = 3; 202 GetCache()->SetAvatarIconOfProfileAtIndex(1, new_icon_index); 203 // Not much to test. 204 GetCache()->GetAvatarIconOfProfileAtIndex(1); 205 } 206 207 TEST_F(ProfileInfoCacheTest, Sort) { 208 string16 name_a = ASCIIToUTF16("apple"); 209 GetCache()->AddProfileToCache( 210 GetProfilePath("path_a"), name_a, string16(), 0, std::string()); 211 212 string16 name_c = ASCIIToUTF16("cat"); 213 GetCache()->AddProfileToCache( 214 GetProfilePath("path_c"), name_c, string16(), 0, std::string()); 215 216 // Sanity check the initial order. 217 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); 218 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); 219 220 // Add a new profile (start with a capital to test case insensitive sorting. 221 string16 name_b = ASCIIToUTF16("Banana"); 222 GetCache()->AddProfileToCache( 223 GetProfilePath("path_b"), name_b, string16(), 0, std::string()); 224 225 // Verify the new order. 226 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(0)); 227 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(1)); 228 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(2)); 229 230 // Change the name of an existing profile. 231 name_a = UTF8ToUTF16("dog"); 232 GetCache()->SetNameOfProfileAtIndex(0, name_a); 233 234 // Verify the new order. 235 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); 236 EXPECT_EQ(name_c, GetCache()->GetNameOfProfileAtIndex(1)); 237 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(2)); 238 239 // Delete a profile. 240 GetCache()->DeleteProfileFromCache(GetProfilePath("path_c")); 241 242 // Verify the new order. 243 EXPECT_EQ(name_b, GetCache()->GetNameOfProfileAtIndex(0)); 244 EXPECT_EQ(name_a, GetCache()->GetNameOfProfileAtIndex(1)); 245 } 246 247 TEST_F(ProfileInfoCacheTest, BackgroundModeStatus) { 248 GetCache()->AddProfileToCache( 249 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 250 string16(), 0, std::string()); 251 GetCache()->AddProfileToCache( 252 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), 253 string16(), 0, std::string()); 254 255 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); 256 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); 257 258 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, true); 259 260 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); 261 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); 262 263 GetCache()->SetBackgroundStatusOfProfileAtIndex(0, true); 264 265 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); 266 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); 267 268 GetCache()->SetBackgroundStatusOfProfileAtIndex(1, false); 269 270 EXPECT_TRUE(GetCache()->GetBackgroundStatusOfProfileAtIndex(0)); 271 EXPECT_FALSE(GetCache()->GetBackgroundStatusOfProfileAtIndex(1)); 272 } 273 274 TEST_F(ProfileInfoCacheTest, HasMigrated) { 275 GetCache()->AddProfileToCache( 276 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 277 string16(), 0, std::string()); 278 GetCache()->AddProfileToCache( 279 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), 280 string16(), 0, std::string()); 281 282 // Sanity check. 283 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); 284 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); 285 286 // Set migrated state for 2nd profile. 287 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, true); 288 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); 289 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); 290 291 // Set migrated state for 1st profile. 292 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(0, true); 293 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); 294 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); 295 296 // Unset migrated state for 2nd profile. 297 GetCache()->SetHasMigratedToGAIAInfoOfProfileAtIndex(1, false); 298 EXPECT_TRUE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(0)); 299 EXPECT_FALSE(GetCache()->GetHasMigratedToGAIAInfoOfProfileAtIndex(1)); 300 } 301 302 TEST_F(ProfileInfoCacheTest, GAIAName) { 303 GetCache()->AddProfileToCache( 304 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 305 string16(), 0, std::string()); 306 string16 profile_name(ASCIIToUTF16("profile name 2")); 307 GetCache()->AddProfileToCache( 308 GetProfilePath("path_2"), profile_name, string16(), 0, std::string()); 309 310 // Sanity check. 311 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); 312 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(1).empty()); 313 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(0)); 314 EXPECT_FALSE(GetCache()->IsUsingGAIANameOfProfileAtIndex(1)); 315 316 // Set GAIA name. 317 string16 gaia_name(ASCIIToUTF16("Pat Smith")); 318 GetCache()->SetGAIANameOfProfileAtIndex(1, gaia_name); 319 EXPECT_TRUE(GetCache()->GetGAIANameOfProfileAtIndex(0).empty()); 320 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); 321 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); 322 323 // Use GAIA name as profile name. 324 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, true); 325 326 EXPECT_EQ(gaia_name, GetCache()->GetNameOfProfileAtIndex(1)); 327 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); 328 329 // Don't use GAIA name as profile name. 330 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(1, false); 331 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(1)); 332 EXPECT_EQ(gaia_name, GetCache()->GetGAIANameOfProfileAtIndex(1)); 333 } 334 335 TEST_F(ProfileInfoCacheTest, GAIAPicture) { 336 GetCache()->AddProfileToCache( 337 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 338 string16(), 0, std::string()); 339 GetCache()->AddProfileToCache( 340 GetProfilePath("path_2"), ASCIIToUTF16("name_2"), 341 string16(), 0, std::string()); 342 343 // Sanity check. 344 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); 345 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(1)); 346 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(0)); 347 EXPECT_FALSE(GetCache()->IsUsingGAIAPictureOfProfileAtIndex(1)); 348 349 // The profile icon should be the default one. 350 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); 351 const gfx::Image& profile_image( 352 ResourceBundle::GetSharedInstance().GetImageNamed(id)); 353 EXPECT_TRUE(gfx::test::IsEqual( 354 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); 355 356 // Set GAIA picture. 357 gfx::Image gaia_image(gfx::test::CreateImage()); 358 GetCache()->SetGAIAPictureOfProfileAtIndex(1, &gaia_image); 359 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); 360 EXPECT_TRUE(gfx::test::IsEqual( 361 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); 362 EXPECT_TRUE(gfx::test::IsEqual( 363 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); 364 365 // Use GAIA picture as profile picture. 366 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, true); 367 EXPECT_TRUE(gfx::test::IsEqual( 368 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); 369 EXPECT_TRUE(gfx::test::IsEqual( 370 gaia_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); 371 372 // Don't use GAIA picture as profile picture. 373 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(1, false); 374 EXPECT_TRUE(gfx::test::IsEqual( 375 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(1))); 376 EXPECT_TRUE(gfx::test::IsEqual( 377 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(1))); 378 } 379 380 TEST_F(ProfileInfoCacheTest, PersistGAIAPicture) { 381 GetCache()->AddProfileToCache( 382 GetProfilePath("path_1"), ASCIIToUTF16("name_1"), 383 string16(), 0, std::string()); 384 gfx::Image gaia_image(gfx::test::CreateImage()); 385 386 content::WindowedNotificationObserver save_observer( 387 chrome::NOTIFICATION_PROFILE_CACHE_PICTURE_SAVED, 388 content::NotificationService::AllSources()); 389 GetCache()->SetGAIAPictureOfProfileAtIndex(0, &gaia_image); 390 EXPECT_TRUE(gfx::test::IsEqual( 391 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); 392 393 // Wait for the file to be written to disk then reset the cache. 394 save_observer.Wait(); 395 ResetCache(); 396 397 // Try to get the GAIA picture. This should return NULL until the read from 398 // disk is done. 399 content::WindowedNotificationObserver read_observer( 400 chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, 401 content::NotificationService::AllSources()); 402 EXPECT_EQ(NULL, GetCache()->GetGAIAPictureOfProfileAtIndex(0)); 403 read_observer.Wait(); 404 EXPECT_TRUE(gfx::test::IsEqual( 405 gaia_image, *GetCache()->GetGAIAPictureOfProfileAtIndex(0))); 406 } 407 408 TEST_F(ProfileInfoCacheTest, SetManagedUserId) { 409 GetCache()->AddProfileToCache( 410 GetProfilePath("test"), ASCIIToUTF16("Test"), 411 string16(), 0, std::string()); 412 EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0)); 413 414 GetCache()->SetManagedUserIdOfProfileAtIndex(0, "TEST_ID"); 415 EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0)); 416 EXPECT_EQ("TEST_ID", GetCache()->GetManagedUserIdOfProfileAtIndex(0)); 417 418 ResetCache(); 419 EXPECT_TRUE(GetCache()->ProfileIsManagedAtIndex(0)); 420 421 GetCache()->SetManagedUserIdOfProfileAtIndex(0, std::string()); 422 EXPECT_FALSE(GetCache()->ProfileIsManagedAtIndex(0)); 423 EXPECT_EQ("", GetCache()->GetManagedUserIdOfProfileAtIndex(0)); 424 } 425 426 TEST_F(ProfileInfoCacheTest, EmptyGAIAInfo) { 427 string16 profile_name = ASCIIToUTF16("name_1"); 428 int id = ProfileInfoCache::GetDefaultAvatarIconResourceIDAtIndex(0); 429 const gfx::Image& profile_image( 430 ResourceBundle::GetSharedInstance().GetImageNamed(id)); 431 432 GetCache()->AddProfileToCache( 433 GetProfilePath("path_1"), profile_name, string16(), 0, std::string()); 434 435 // Set empty GAIA info. 436 GetCache()->SetGAIANameOfProfileAtIndex(0, string16()); 437 GetCache()->SetGAIAPictureOfProfileAtIndex(0, NULL); 438 GetCache()->SetIsUsingGAIANameOfProfileAtIndex(0, true); 439 GetCache()->SetIsUsingGAIAPictureOfProfileAtIndex(0, true); 440 441 // Verify that the profile name and picture are not empty. 442 EXPECT_EQ(profile_name, GetCache()->GetNameOfProfileAtIndex(0)); 443 EXPECT_TRUE(gfx::test::IsEqual( 444 profile_image, GetCache()->GetAvatarIconOfProfileAtIndex(0))); 445 } 446 447 TEST_F(ProfileInfoCacheTest, CreateManagedTestingProfile) { 448 testing_profile_manager_.CreateTestingProfile("default"); 449 string16 managed_user_name = ASCIIToUTF16("Supervised User"); 450 testing_profile_manager_.CreateTestingProfile( 451 "test1", scoped_ptr<PrefServiceSyncable>(), 452 managed_user_name, 0, "TEST_ID"); 453 for (size_t i = 0; i < GetCache()->GetNumberOfProfiles(); i++) { 454 bool is_managed = 455 GetCache()->GetNameOfProfileAtIndex(i) == managed_user_name; 456 EXPECT_EQ(is_managed, GetCache()->ProfileIsManagedAtIndex(i)); 457 std::string managed_user_id = is_managed ? "TEST_ID" : ""; 458 EXPECT_EQ(managed_user_id, GetCache()->GetManagedUserIdOfProfileAtIndex(i)); 459 } 460 } 461 462 } // namespace 463