| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 MockObserver* mock_observer) { | 135 MockObserver* mock_observer) { |
| 136 manager->CreateProfileAsync( | 136 manager->CreateProfileAsync( |
| 137 temp_dir_.path().AppendASCII(name), | 137 temp_dir_.path().AppendASCII(name), |
| 138 base::Bind(&MockObserver::OnProfileCreated, | 138 base::Bind(&MockObserver::OnProfileCreated, |
| 139 base::Unretained(mock_observer)), | 139 base::Unretained(mock_observer)), |
| 140 base::UTF8ToUTF16(name), | 140 base::UTF8ToUTF16(name), |
| 141 profiles::GetDefaultAvatarIconUrl(0), | 141 profiles::GetDefaultAvatarIconUrl(0), |
| 142 is_supervised ? "Dummy ID" : std::string()); | 142 is_supervised ? "Dummy ID" : std::string()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Helper function to add a profile with |profile_name| to | 145 // Helper function to add a profile with |profile_name| to |profile_manager|'s |
| 146 // |profile_manager|'s ProfileInfoCache, and return the profile created. | 146 // ProfileAttributesStorage, and return the profile created. |
| 147 Profile* AddProfileToCache(ProfileManager* profile_manager, | 147 Profile* AddProfileToStorage(ProfileManager* profile_manager, |
| 148 const std::string& path_suffix, | 148 const std::string& path_suffix, |
| 149 const base::string16& profile_name) { | 149 const base::string16& profile_name) { |
| 150 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 150 ProfileAttributesStorage& storage = |
| 151 size_t num_profiles = cache.GetNumberOfProfiles(); | 151 profile_manager->GetProfileAttributesStorage(); |
| 152 size_t num_profiles = storage.GetNumberOfProfiles(); |
| 152 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); | 153 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); |
| 153 cache.AddProfileToCache(path, profile_name, | 154 storage.AddProfile(path, profile_name, std::string(), base::string16(), 0, |
| 154 std::string(), base::string16(), 0, std::string()); | 155 std::string()); |
| 155 EXPECT_EQ(num_profiles + 1, cache.GetNumberOfProfiles()); | 156 EXPECT_EQ(num_profiles + 1u, storage.GetNumberOfProfiles()); |
| 156 return profile_manager->GetProfile(path); | 157 return profile_manager->GetProfile(path); |
| 157 } | 158 } |
| 158 | 159 |
| 159 #if defined(OS_CHROMEOS) | 160 #if defined(OS_CHROMEOS) |
| 160 // Helper function to register an user with id |user_id| and create profile | 161 // Helper function to register an user with id |user_id| and create profile |
| 161 // with a correct path. | 162 // with a correct path. |
| 162 void RegisterUser(const std::string& user_id) { | 163 void RegisterUser(const std::string& user_id) { |
| 163 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); | 164 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); |
| 164 const std::string user_id_hash = | 165 const std::string user_id_hash = |
| 165 profile_helper->GetUserIdHashByUserIdForTesting(user_id); | 166 profile_helper->GetUserIdHashByUserIdForTesting(user_id); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 } | 333 } |
| 333 | 334 |
| 334 TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { | 335 TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { |
| 335 std::string name = "0 Supervised Profile"; | 336 std::string name = "0 Supervised Profile"; |
| 336 | 337 |
| 337 MockObserver mock_observer; | 338 MockObserver mock_observer; |
| 338 EXPECT_CALL(mock_observer, OnProfileCreated( | 339 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 339 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 340 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 340 | 341 |
| 341 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 342 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 342 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 343 ProfileAttributesStorage& storage = |
| 343 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 344 profile_manager->GetProfileAttributesStorage(); |
| 345 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 344 | 346 |
| 345 CreateProfileAsync(profile_manager, name, true, &mock_observer); | 347 CreateProfileAsync(profile_manager, name, true, &mock_observer); |
| 346 base::RunLoop().RunUntilIdle(); | 348 base::RunLoop().RunUntilIdle(); |
| 347 | 349 |
| 348 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); | 350 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 349 // Supervised profiles should start out omitted from the profile list. | 351 // Supervised profiles should start out omitted from the profile list. |
| 350 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); | 352 EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0u]->IsOmitted()); |
| 351 | 353 |
| 352 name = "1 Regular Profile"; | 354 name = "1 Regular Profile"; |
| 353 CreateProfileAsync(profile_manager, name, false, &mock_observer); | 355 CreateProfileAsync(profile_manager, name, false, &mock_observer); |
| 354 base::RunLoop().RunUntilIdle(); | 356 base::RunLoop().RunUntilIdle(); |
| 355 | 357 |
| 356 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 358 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 357 // Non-supervised profiles should be included in the profile list. | 359 // Non-supervised profiles should be included in the profile list. |
| 358 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(1)); | 360 EXPECT_FALSE(storage.GetAllProfilesAttributesSortedByName()[1u]->IsOmitted()); |
| 359 } | 361 } |
| 360 | 362 |
| 361 TEST_F(ProfileManagerTest, AddProfileToCacheCheckOmitted) { | 363 TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { |
| 362 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 364 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 363 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 365 ProfileAttributesStorage& storage = |
| 364 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 366 profile_manager->GetProfileAttributesStorage(); |
| 367 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 365 | 368 |
| 366 const base::FilePath supervised_path = | 369 const base::FilePath supervised_path = |
| 367 temp_dir_.path().AppendASCII("Supervised"); | 370 temp_dir_.path().AppendASCII("Supervised"); |
| 368 TestingProfile* supervised_profile = | 371 TestingProfile* supervised_profile = |
| 369 new TestingProfile(supervised_path, NULL); | 372 new TestingProfile(supervised_path, NULL); |
| 370 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); | 373 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); |
| 371 | 374 |
| 372 // RegisterTestingProfile adds the profile to the cache and takes ownership. | 375 // RegisterTestingProfile adds the profile to the cache and takes ownership. |
| 373 profile_manager->RegisterTestingProfile(supervised_profile, true, false); | 376 profile_manager->RegisterTestingProfile(supervised_profile, true, false); |
| 374 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); | 377 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 375 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); | 378 EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0u]->IsOmitted()); |
| 376 | 379 |
| 377 const base::FilePath nonsupervised_path = temp_dir_.path().AppendASCII( | 380 const base::FilePath nonsupervised_path = temp_dir_.path().AppendASCII( |
| 378 "Non-Supervised"); | 381 "Non-Supervised"); |
| 379 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, | 382 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, |
| 380 NULL); | 383 NULL); |
| 381 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); | 384 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); |
| 382 | 385 |
| 383 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 386 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 384 size_t supervised_index = cache.GetIndexOfProfileWithPath(supervised_path); | 387 ProfileAttributesEntry* entry; |
| 385 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(supervised_index)); | 388 ASSERT_TRUE(storage.GetProfileAttributesWithPath(supervised_path, &entry)); |
| 386 size_t nonsupervised_index = | 389 EXPECT_TRUE(entry->IsOmitted()); |
| 387 cache.GetIndexOfProfileWithPath(nonsupervised_path); | 390 |
| 388 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(nonsupervised_index)); | 391 ASSERT_TRUE(storage.GetProfileAttributesWithPath(nonsupervised_path, &entry)); |
| 392 EXPECT_FALSE(entry->IsOmitted()); |
| 389 } | 393 } |
| 390 | 394 |
| 391 TEST_F(ProfileManagerTest, GetGuestProfilePath) { | 395 TEST_F(ProfileManagerTest, GetGuestProfilePath) { |
| 392 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); | 396 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); |
| 393 base::FilePath expected_path = temp_dir_.path(); | 397 base::FilePath expected_path = temp_dir_.path(); |
| 394 expected_path = expected_path.Append(chrome::kGuestProfileDir); | 398 expected_path = expected_path.Append(chrome::kGuestProfileDir); |
| 395 EXPECT_EQ(expected_path, guest_path); | 399 EXPECT_EQ(expected_path, guest_path); |
| 396 } | 400 } |
| 397 | 401 |
| 398 TEST_F(ProfileManagerTest, GetSystemProfilePath) { | 402 TEST_F(ProfileManagerTest, GetSystemProfilePath) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 461 | 465 |
| 462 Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); | 466 Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); |
| 463 EXPECT_TRUE(last_used_profile->IsOffTheRecord()); | 467 EXPECT_TRUE(last_used_profile->IsOffTheRecord()); |
| 464 | 468 |
| 465 EXPECT_TRUE(last_used_profile->IsSameProfile(active_profile)); | 469 EXPECT_TRUE(last_used_profile->IsSameProfile(active_profile)); |
| 466 } | 470 } |
| 467 #endif | 471 #endif |
| 468 | 472 |
| 469 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 473 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
| 470 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 474 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 471 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 475 ProfileAttributesStorage& storage = |
| 476 profile_manager->GetProfileAttributesStorage(); |
| 472 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 477 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
| 473 new base::FundamentalValue(true)); | 478 new base::FundamentalValue(true)); |
| 474 | 479 |
| 475 // Setting a pref which is not applicable to a system (i.e., Android in this | 480 // Setting a pref which is not applicable to a system (i.e., Android in this |
| 476 // case) does not necessarily create it. Don't bother continuing with the | 481 // case) does not necessarily create it. Don't bother continuing with the |
| 477 // test if this pref doesn't exist because it will not load the profiles if | 482 // test if this pref doesn't exist because it will not load the profiles if |
| 478 // it cannot verify that the pref for background mode is enabled. | 483 // it cannot verify that the pref for background mode is enabled. |
| 479 if (!local_state_.Get()->HasPrefPath(prefs::kBackgroundModeEnabled)) | 484 if (!local_state_.Get()->HasPrefPath(prefs::kBackgroundModeEnabled)) |
| 480 return; | 485 return; |
| 481 | 486 |
| 482 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 487 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 483 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 488 |
| 484 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, | 489 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_1"), |
| 485 std::string()); | 490 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, std::string()); |
| 486 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 491 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_2"), |
| 487 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, | 492 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, std::string()); |
| 488 std::string()); | 493 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_3"), |
| 489 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), | 494 ASCIIToUTF16("name_3"), "34567", base::string16(), 0, std::string()); |
| 490 ASCIIToUTF16("name_3"), "34567", base::string16(), 0, | 495 |
| 491 std::string()); | 496 EXPECT_EQ(3u, storage.GetNumberOfProfiles()); |
| 492 cache.SetBackgroundStatusOfProfileAtIndex(0, true); | 497 |
| 493 cache.SetBackgroundStatusOfProfileAtIndex(2, true); | 498 std::vector<ProfileAttributesEntry*> entries = |
| 494 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 499 storage.GetAllProfilesAttributes(); |
| 500 entries[0u]->SetBackgroundStatus(true); |
| 501 entries[2u]->SetBackgroundStatus(true); |
| 495 | 502 |
| 496 profile_manager->AutoloadProfiles(); | 503 profile_manager->AutoloadProfiles(); |
| 497 | 504 |
| 498 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 505 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 499 } | 506 } |
| 500 | 507 |
| 501 TEST_F(ProfileManagerTest, DoNotAutoloadProfilesIfBackgroundModeOff) { | 508 TEST_F(ProfileManagerTest, DoNotAutoloadProfilesIfBackgroundModeOff) { |
| 502 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 509 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 503 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 510 ProfileAttributesStorage& storage = |
| 511 profile_manager->GetProfileAttributesStorage(); |
| 504 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 512 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
| 505 new base::FundamentalValue(false)); | 513 new base::FundamentalValue(false)); |
| 506 | 514 |
| 507 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 515 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 508 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 516 |
| 509 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, | 517 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_1"), |
| 510 std::string()); | 518 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, std::string()); |
| 511 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 519 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_2"), |
| 512 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, | 520 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, std::string()); |
| 513 std::string()); | 521 |
| 514 cache.SetBackgroundStatusOfProfileAtIndex(0, false); | 522 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 515 cache.SetBackgroundStatusOfProfileAtIndex(1, true); | 523 |
| 516 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 524 std::vector<ProfileAttributesEntry*> entries = |
| 525 storage.GetAllProfilesAttributes(); |
| 526 entries[0u]->SetBackgroundStatus(false); |
| 527 entries[1u]->SetBackgroundStatus(true); |
| 517 | 528 |
| 518 profile_manager->AutoloadProfiles(); | 529 profile_manager->AutoloadProfiles(); |
| 519 | 530 |
| 520 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); | 531 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); |
| 521 } | 532 } |
| 522 | 533 |
| 523 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { | 534 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { |
| 524 base::FilePath dest_path = temp_dir_.path(); | 535 base::FilePath dest_path = temp_dir_.path(); |
| 525 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 536 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 526 | 537 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 544 avatar_index)); | 555 avatar_index)); |
| 545 } | 556 } |
| 546 | 557 |
| 547 // Tests that a new profile's entry in the profile info cache is setup with the | 558 // Tests that a new profile's entry in the profile info cache is setup with the |
| 548 // same values that are in the profile prefs. | 559 // same values that are in the profile prefs. |
| 549 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { | 560 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { |
| 550 base::FilePath dest_path = temp_dir_.path(); | 561 base::FilePath dest_path = temp_dir_.path(); |
| 551 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 562 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 552 | 563 |
| 553 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 564 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 554 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
| 555 | 565 |
| 556 // Successfully create the profile | 566 // Successfully create the profile |
| 557 Profile* profile = profile_manager->GetProfile(dest_path); | 567 Profile* profile = profile_manager->GetProfile(dest_path); |
| 558 ASSERT_TRUE(profile); | 568 ASSERT_TRUE(profile); |
| 559 | 569 |
| 560 std::string profile_name = | 570 std::string profile_name = |
| 561 profile->GetPrefs()->GetString(prefs::kProfileName); | 571 profile->GetPrefs()->GetString(prefs::kProfileName); |
| 562 size_t avatar_index = | 572 size_t avatar_index = |
| 563 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); | 573 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 564 | 574 |
| 565 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); | 575 ProfileAttributesEntry* entry; |
| 576 ASSERT_TRUE(profile_manager->GetProfileAttributesStorage(). |
| 577 GetProfileAttributesWithPath(dest_path, &entry)); |
| 566 | 578 |
| 567 // Check if the profile prefs are the same as the cache prefs | 579 // Check if the profile prefs are the same as the cache prefs |
| 568 EXPECT_EQ(profile_name, | 580 EXPECT_EQ(profile_name, base::UTF16ToUTF8(entry->GetName())); |
| 569 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 581 EXPECT_EQ(avatar_index, entry->GetAvatarIconIndex()); |
| 570 EXPECT_EQ(avatar_index, | |
| 571 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); | |
| 572 } | 582 } |
| 573 | 583 |
| 574 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { | 584 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { |
| 575 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 585 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 576 ASSERT_TRUE(profile_manager); | 586 ASSERT_TRUE(profile_manager); |
| 577 | 587 |
| 578 #if defined(OS_CHROMEOS) | 588 #if defined(OS_CHROMEOS) |
| 579 // On CrOS, profile returned by GetLastUsedProfile is a singin profile that | 589 // On CrOS, profile returned by GetLastUsedProfile is a singin profile that |
| 580 // is forced to be incognito. That's why we need to create at least one user | 590 // is forced to be incognito. That's why we need to create at least one user |
| 581 // to get a regular profile. | 591 // to get a regular profile. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 browser3.reset(); | 883 browser3.reset(); |
| 874 | 884 |
| 875 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 885 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 876 ASSERT_EQ(1U, last_opened_profiles.size()); | 886 ASSERT_EQ(1U, last_opened_profiles.size()); |
| 877 EXPECT_EQ(normal_profile, last_opened_profiles[0]); | 887 EXPECT_EQ(normal_profile, last_opened_profiles[0]); |
| 878 } | 888 } |
| 879 | 889 |
| 880 TEST_F(ProfileManagerTest, CleanUpEphemeralProfiles) { | 890 TEST_F(ProfileManagerTest, CleanUpEphemeralProfiles) { |
| 881 // Create two profiles, one of them ephemeral. | 891 // Create two profiles, one of them ephemeral. |
| 882 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 892 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 883 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 893 ProfileAttributesStorage& storage = |
| 884 ASSERT_EQ(0u, cache.GetNumberOfProfiles()); | 894 profile_manager->GetProfileAttributesStorage(); |
| 895 ASSERT_EQ(0u, storage.GetNumberOfProfiles()); |
| 885 | 896 |
| 886 const std::string profile_name1 = "Homer"; | 897 const std::string profile_name1 = "Homer"; |
| 887 base::FilePath path1 = temp_dir_.path().AppendASCII(profile_name1); | 898 base::FilePath path1 = |
| 888 cache.AddProfileToCache(path1, base::UTF8ToUTF16(profile_name1), | 899 profile_manager->user_data_dir().AppendASCII(profile_name1); |
| 889 std::string(), base::UTF8ToUTF16(profile_name1), 0, | 900 storage.AddProfile(path1, base::UTF8ToUTF16(profile_name1), std::string(), |
| 890 std::string()); | 901 base::UTF8ToUTF16(profile_name1), 0, std::string()); |
| 891 cache.SetProfileIsEphemeralAtIndex(0, true); | 902 storage.GetAllProfilesAttributes()[0u]->SetIsEphemeral(true); |
| 892 ASSERT_TRUE(base::CreateDirectory(path1)); | 903 ASSERT_TRUE(base::CreateDirectory(path1)); |
| 893 | 904 |
| 894 const std::string profile_name2 = "Marge"; | 905 const std::string profile_name2 = "Marge"; |
| 895 base::FilePath path2 = temp_dir_.path().AppendASCII(profile_name2); | 906 base::FilePath path2 = |
| 896 cache.AddProfileToCache(path2, base::UTF8ToUTF16(profile_name2), | 907 profile_manager->user_data_dir().AppendASCII(profile_name2); |
| 897 std::string(), base::UTF8ToUTF16(profile_name2), 0, | 908 storage.AddProfile(path2, base::UTF8ToUTF16(profile_name2), std::string(), |
| 898 std::string()); | 909 base::UTF8ToUTF16(profile_name2), 0, std::string()); |
| 899 ASSERT_EQ(2u, cache.GetNumberOfProfiles()); | 910 ASSERT_EQ(2u, storage.GetNumberOfProfiles()); |
| 900 ASSERT_TRUE(base::CreateDirectory(path2)); | 911 ASSERT_TRUE(base::CreateDirectory(path2)); |
| 901 | 912 |
| 902 // Set the active profile. | 913 // Set the active profile. |
| 903 PrefService* local_state = g_browser_process->local_state(); | 914 PrefService* local_state = g_browser_process->local_state(); |
| 904 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 915 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 905 | 916 |
| 906 profile_manager->CleanUpEphemeralProfiles(); | 917 profile_manager->CleanUpEphemeralProfiles(); |
| 907 base::RunLoop().RunUntilIdle(); | 918 base::RunLoop().RunUntilIdle(); |
| 908 | 919 |
| 909 // The ephemeral profile should be deleted, and the last used profile set to | 920 // The ephemeral profile should be deleted, and the last used profile set to |
| 910 // the other one. | 921 // the other one. |
| 911 EXPECT_FALSE(base::DirectoryExists(path1)); | 922 EXPECT_FALSE(base::DirectoryExists(path1)); |
| 912 EXPECT_TRUE(base::DirectoryExists(path2)); | 923 EXPECT_TRUE(base::DirectoryExists(path2)); |
| 913 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 924 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 914 ASSERT_EQ(1u, cache.GetNumberOfProfiles()); | 925 ASSERT_EQ(1u, storage.GetNumberOfProfiles()); |
| 915 | 926 |
| 916 // Mark the remaining profile ephemeral and clean up. | 927 // Mark the remaining profile ephemeral and clean up. |
| 917 cache.SetProfileIsEphemeralAtIndex(0, true); | 928 storage.GetAllProfilesAttributes()[0u]->SetIsEphemeral(true); |
| 918 profile_manager->CleanUpEphemeralProfiles(); | 929 profile_manager->CleanUpEphemeralProfiles(); |
| 919 base::RunLoop().RunUntilIdle(); | 930 base::RunLoop().RunUntilIdle(); |
| 920 | 931 |
| 921 // The profile should be deleted, and the last used profile set to a new one. | 932 // The profile should be deleted, and the last used profile set to a new one. |
| 922 EXPECT_FALSE(base::DirectoryExists(path2)); | 933 EXPECT_FALSE(base::DirectoryExists(path2)); |
| 923 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 934 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 924 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); | 935 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); |
| 925 } | 936 } |
| 926 | 937 |
| 927 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { | 938 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { |
| 928 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 939 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 929 ASSERT_TRUE(profile_manager); | 940 ASSERT_TRUE(profile_manager); |
| 930 | 941 |
| 931 // Create and load two profiles. | 942 // Create and load two profiles. |
| 932 const std::string profile_name1 = "New Profile 1"; | 943 const std::string profile_name1 = "New Profile 1"; |
| 933 const std::string profile_name2 = "New Profile 2"; | 944 const std::string profile_name2 = "New Profile 2"; |
| 934 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 945 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 935 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 946 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 936 | 947 |
| 937 MockObserver mock_observer; | 948 MockObserver mock_observer; |
| 938 EXPECT_CALL(mock_observer, OnProfileCreated( | 949 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 939 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 950 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 940 | 951 |
| 941 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 952 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 942 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); | 953 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); |
| 943 base::RunLoop().RunUntilIdle(); | 954 base::RunLoop().RunUntilIdle(); |
| 944 | 955 |
| 945 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 956 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 946 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 957 EXPECT_EQ(2u, profile_manager->GetProfileAttributesStorage(). |
| 958 GetNumberOfProfiles()); |
| 947 | 959 |
| 948 // Set the active profile. | 960 // Set the active profile. |
| 949 PrefService* local_state = g_browser_process->local_state(); | 961 PrefService* local_state = g_browser_process->local_state(); |
| 950 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 962 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 951 | 963 |
| 952 // Delete the active profile. | 964 // Delete the active profile. |
| 953 profile_manager->ScheduleProfileForDeletion(dest_path1, | 965 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 954 ProfileManager::CreateCallback()); | 966 ProfileManager::CreateCallback()); |
| 955 // Spin the message loop so that all the callbacks can finish running. | 967 // Spin the message loop so that all the callbacks can finish running. |
| 956 base::RunLoop().RunUntilIdle(); | 968 base::RunLoop().RunUntilIdle(); |
| 957 | 969 |
| 958 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 970 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 959 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 971 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 960 } | 972 } |
| 961 | 973 |
| 962 TEST_F(ProfileManagerTest, LastProfileDeleted) { | 974 TEST_F(ProfileManagerTest, LastProfileDeleted) { |
| 963 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 975 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 964 ASSERT_TRUE(profile_manager); | 976 ASSERT_TRUE(profile_manager); |
| 977 ProfileAttributesStorage& storage = |
| 978 profile_manager->GetProfileAttributesStorage(); |
| 965 | 979 |
| 966 // Create and load a profile. | 980 // Create and load a profile. |
| 967 const std::string profile_name1 = "New Profile 1"; | 981 const std::string profile_name1 = "New Profile 1"; |
| 968 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 982 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 969 | 983 |
| 970 MockObserver mock_observer; | 984 MockObserver mock_observer; |
| 971 EXPECT_CALL(mock_observer, OnProfileCreated( | 985 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 972 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 986 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 973 | 987 |
| 974 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 988 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 975 base::RunLoop().RunUntilIdle(); | 989 base::RunLoop().RunUntilIdle(); |
| 976 | 990 |
| 977 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 991 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 978 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 992 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 979 | 993 |
| 980 // Set it as the active profile. | 994 // Set it as the active profile. |
| 981 PrefService* local_state = g_browser_process->local_state(); | 995 PrefService* local_state = g_browser_process->local_state(); |
| 982 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 996 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 983 | 997 |
| 984 // Delete the active profile. | 998 // Delete the active profile. |
| 985 profile_manager->ScheduleProfileForDeletion(dest_path1, | 999 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 986 ProfileManager::CreateCallback()); | 1000 ProfileManager::CreateCallback()); |
| 987 // Spin the message loop so that all the callbacks can finish running. | 1001 // Spin the message loop so that all the callbacks can finish running. |
| 988 base::RunLoop().RunUntilIdle(); | 1002 base::RunLoop().RunUntilIdle(); |
| 989 | 1003 |
| 990 // A new profile should have been created | 1004 // A new profile should have been created |
| 991 const std::string profile_name2 = "Profile 1"; | 1005 const std::string profile_name2 = "Profile 1"; |
| 992 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1006 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 993 | 1007 |
| 994 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 1008 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 995 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 1009 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 996 EXPECT_EQ(dest_path2, | 1010 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); |
| 997 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0)); | |
| 998 } | 1011 } |
| 999 | 1012 |
| 1000 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { | 1013 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { |
| 1001 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1014 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1002 ASSERT_TRUE(profile_manager); | 1015 ASSERT_TRUE(profile_manager); |
| 1016 ProfileAttributesStorage& storage = |
| 1017 profile_manager->GetProfileAttributesStorage(); |
| 1003 | 1018 |
| 1004 // Create and load a profile. | 1019 // Create and load a profile. |
| 1005 const std::string profile_name1 = "New Profile 1"; | 1020 const std::string profile_name1 = "New Profile 1"; |
| 1006 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1021 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 1007 | 1022 |
| 1008 MockObserver mock_observer; | 1023 MockObserver mock_observer; |
| 1009 EXPECT_CALL(mock_observer, OnProfileCreated( | 1024 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1010 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1025 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1011 | 1026 |
| 1012 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1027 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1013 base::RunLoop().RunUntilIdle(); | 1028 base::RunLoop().RunUntilIdle(); |
| 1014 | 1029 |
| 1015 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1030 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1016 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1031 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1017 | 1032 |
| 1018 // Create the profile and register it. | 1033 // Create the profile and register it. |
| 1019 const std::string guest_profile_name = | 1034 const std::string guest_profile_name = |
| 1020 ProfileManager::GetGuestProfilePath().BaseName().MaybeAsASCII(); | 1035 ProfileManager::GetGuestProfilePath().BaseName().MaybeAsASCII(); |
| 1021 | 1036 |
| 1022 TestingProfile::Builder builder; | 1037 TestingProfile::Builder builder; |
| 1023 builder.SetGuestSession(); | 1038 builder.SetGuestSession(); |
| 1024 builder.SetPath(ProfileManager::GetGuestProfilePath()); | 1039 builder.SetPath(ProfileManager::GetGuestProfilePath()); |
| 1025 TestingProfile* guest_profile = builder.Build().release(); | 1040 TestingProfile* guest_profile = builder.Build().release(); |
| 1026 guest_profile->set_profile_name(guest_profile_name); | 1041 guest_profile->set_profile_name(guest_profile_name); |
| 1027 // Registering the profile passes ownership to the ProfileManager. | 1042 // Registering the profile passes ownership to the ProfileManager. |
| 1028 profile_manager->RegisterTestingProfile(guest_profile, false, false); | 1043 profile_manager->RegisterTestingProfile(guest_profile, false, false); |
| 1029 | 1044 |
| 1030 // The Guest profile does not get added to the ProfileInfoCache. | 1045 // The Guest profile does not get added to the ProfileAttributesStorage. |
| 1031 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 1046 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 1032 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1047 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1033 | 1048 |
| 1034 // Set the Guest profile as the active profile. | 1049 // Set the Guest profile as the active profile. |
| 1035 PrefService* local_state = g_browser_process->local_state(); | 1050 PrefService* local_state = g_browser_process->local_state(); |
| 1036 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name); | 1051 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name); |
| 1037 | 1052 |
| 1038 // Delete the other profile. | 1053 // Delete the other profile. |
| 1039 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1054 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1040 ProfileManager::CreateCallback()); | 1055 ProfileManager::CreateCallback()); |
| 1041 // Spin the message loop so that all the callbacks can finish running. | 1056 // Spin the message loop so that all the callbacks can finish running. |
| 1042 base::RunLoop().RunUntilIdle(); | 1057 base::RunLoop().RunUntilIdle(); |
| 1043 | 1058 |
| 1044 // A new profile should have been created. | 1059 // A new profile should have been created. |
| 1045 const std::string profile_name2 = "Profile 1"; | 1060 const std::string profile_name2 = "Profile 1"; |
| 1046 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1061 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1047 | 1062 |
| 1048 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size()); | 1063 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size()); |
| 1049 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1064 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1050 EXPECT_EQ(dest_path2, | 1065 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); |
| 1051 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0)); | |
| 1052 } | 1066 } |
| 1053 | 1067 |
| 1054 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { | 1068 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { |
| 1055 if (!profiles::IsMultipleProfilesEnabled()) | 1069 if (!profiles::IsMultipleProfilesEnabled()) |
| 1056 return; | 1070 return; |
| 1057 | 1071 |
| 1058 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1072 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1059 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1073 ProfileAttributesStorage& storage = |
| 1060 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1074 profile_manager->GetProfileAttributesStorage(); |
| 1075 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1061 | 1076 |
| 1062 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1077 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1063 const base::string16 default_profile_name = | 1078 const base::string16 default_profile_name = |
| 1064 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1079 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 1065 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1080 const base::string16 profile_name1 = storage.ChooseNameForNewProfile(0u); |
| 1066 Profile* profile1 = AddProfileToCache(profile_manager, | 1081 Profile* profile1 = AddProfileToStorage(profile_manager, |
| 1067 "path_1", profile_name1); | 1082 "path_1", profile_name1); |
| 1068 EXPECT_EQ(default_profile_name, | 1083 EXPECT_EQ(default_profile_name, |
| 1069 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1084 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1070 | 1085 |
| 1071 // Multiple profiles means displaying the actual profile names. | 1086 // Multiple profiles means displaying the actual profile names. |
| 1072 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1087 const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u); |
| 1073 Profile* profile2 = AddProfileToCache(profile_manager, | 1088 Profile* profile2 = AddProfileToStorage(profile_manager, |
| 1074 "path_2", profile_name2); | 1089 "path_2", profile_name2); |
| 1075 EXPECT_EQ(profile_name1, | 1090 EXPECT_EQ(profile_name1, |
| 1076 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1091 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1077 EXPECT_EQ(profile_name2, | 1092 EXPECT_EQ(profile_name2, |
| 1078 profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1093 profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1079 | 1094 |
| 1080 // Deleting a profile means returning to the default name. | 1095 // Deleting a profile means returning to the default name. |
| 1081 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), | 1096 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), |
| 1082 ProfileManager::CreateCallback()); | 1097 ProfileManager::CreateCallback()); |
| 1083 // Spin the message loop so that all the callbacks can finish running. | 1098 // Spin the message loop so that all the callbacks can finish running. |
| 1084 base::RunLoop().RunUntilIdle(); | 1099 base::RunLoop().RunUntilIdle(); |
| 1085 EXPECT_EQ(default_profile_name, | 1100 EXPECT_EQ(default_profile_name, |
| 1086 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1101 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1087 } | 1102 } |
| 1088 | 1103 |
| 1089 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { | 1104 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { |
| 1090 if (!profiles::IsMultipleProfilesEnabled()) | 1105 if (!profiles::IsMultipleProfilesEnabled()) |
| 1091 return; | 1106 return; |
| 1092 | 1107 |
| 1093 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1108 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1094 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1109 ProfileAttributesStorage& storage = |
| 1095 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1110 profile_manager->GetProfileAttributesStorage(); |
| 1111 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1096 | 1112 |
| 1097 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1113 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1098 const base::string16 default_profile_name = | 1114 const base::string16 default_profile_name = |
| 1099 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1115 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 1100 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1116 const base::string16 profile_name1 = storage.ChooseNameForNewProfile(0u); |
| 1101 Profile* profile1 = AddProfileToCache(profile_manager, | 1117 Profile* profile1 = AddProfileToStorage(profile_manager, |
| 1102 "path_1", profile_name1); | 1118 "path_1", profile_name1); |
| 1103 EXPECT_EQ(default_profile_name, | 1119 EXPECT_EQ(default_profile_name, |
| 1104 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1120 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1121 ASSERT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1105 | 1122 |
| 1106 // We should display custom names for local profiles. | 1123 // We should display custom names for local profiles. |
| 1107 const base::string16 custom_profile_name = ASCIIToUTF16("Batman"); | 1124 const base::string16 custom_profile_name = ASCIIToUTF16("Batman"); |
| 1108 cache.SetNameOfProfileAtIndex(0, custom_profile_name); | 1125 ProfileAttributesEntry* entry = storage.GetAllProfilesAttributes()[0u]; |
| 1109 cache.SetProfileIsUsingDefaultNameAtIndex(0, false); | 1126 entry->SetName(custom_profile_name); |
| 1110 EXPECT_EQ(custom_profile_name, cache.GetNameOfProfileAtIndex(0)); | 1127 entry->SetIsUsingDefaultName(false); |
| 1128 EXPECT_EQ(custom_profile_name, entry->GetName()); |
| 1111 EXPECT_EQ(custom_profile_name, | 1129 EXPECT_EQ(custom_profile_name, |
| 1112 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1130 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1113 | 1131 |
| 1114 // Multiple profiles means displaying the actual profile names. | 1132 // Multiple profiles means displaying the actual profile names. |
| 1115 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1133 const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u); |
| 1116 Profile* profile2 = AddProfileToCache(profile_manager, | 1134 Profile* profile2 = AddProfileToStorage(profile_manager, |
| 1117 "path_2", profile_name2); | 1135 "path_2", profile_name2); |
| 1118 EXPECT_EQ(custom_profile_name, | 1136 EXPECT_EQ(custom_profile_name, |
| 1119 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1137 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1120 EXPECT_EQ(profile_name2, | 1138 EXPECT_EQ(profile_name2, |
| 1121 profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1139 profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1122 | 1140 |
| 1123 // Deleting a profile means returning to the original, custom name. | 1141 // Deleting a profile means returning to the original, custom name. |
| 1124 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), | 1142 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), |
| 1125 ProfileManager::CreateCallback()); | 1143 ProfileManager::CreateCallback()); |
| 1126 // Spin the message loop so that all the callbacks can finish running. | 1144 // Spin the message loop so that all the callbacks can finish running. |
| 1127 base::RunLoop().RunUntilIdle(); | 1145 base::RunLoop().RunUntilIdle(); |
| 1128 EXPECT_EQ(custom_profile_name, | 1146 EXPECT_EQ(custom_profile_name, |
| 1129 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1147 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1130 } | 1148 } |
| 1131 | 1149 |
| 1132 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { | 1150 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { |
| 1133 if (!profiles::IsMultipleProfilesEnabled()) | 1151 if (!profiles::IsMultipleProfilesEnabled()) |
| 1134 return; | 1152 return; |
| 1135 | 1153 |
| 1136 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1154 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1137 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1155 ProfileAttributesStorage& storage = |
| 1138 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1156 profile_manager->GetProfileAttributesStorage(); |
| 1157 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1139 | 1158 |
| 1140 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1159 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1141 const base::string16 default_profile_name = | 1160 const base::string16 default_profile_name = |
| 1142 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1161 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 1143 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1162 const base::string16 profile_name1 = storage.ChooseNameForNewProfile(0u); |
| 1144 Profile* profile1 = AddProfileToCache(profile_manager, | 1163 Profile* profile1 = AddProfileToStorage(profile_manager, |
| 1145 "path_1", profile_name1); | 1164 "path_1", profile_name1); |
| 1146 EXPECT_EQ(default_profile_name, | 1165 EXPECT_EQ(default_profile_name, |
| 1147 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1166 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1148 | 1167 |
| 1168 ProfileAttributesEntry* entry = storage.GetAllProfilesAttributes()[0u]; |
| 1149 // For a signed in profile with a default name we still display | 1169 // For a signed in profile with a default name we still display |
| 1150 // IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1170 // IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1151 cache.SetAuthInfoOfProfileAtIndex(0, "12345", ASCIIToUTF16("user@gmail.com")); | 1171 entry->SetAuthInfo("12345", ASCIIToUTF16("user@gmail.com")); |
| 1152 EXPECT_EQ(profile_name1, cache.GetNameOfProfileAtIndex(0)); | 1172 EXPECT_EQ(profile_name1, entry->GetName()); |
| 1153 EXPECT_EQ(default_profile_name, | 1173 EXPECT_EQ(default_profile_name, |
| 1154 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1174 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1155 | 1175 |
| 1156 // For a signed in profile with a non-default Gaia given name we display the | 1176 // For a signed in profile with a non-default Gaia given name we display the |
| 1157 // Gaia given name. | 1177 // Gaia given name. |
| 1158 cache.SetAuthInfoOfProfileAtIndex(0, "12345", ASCIIToUTF16("user@gmail.com")); | 1178 entry->SetAuthInfo("12345", ASCIIToUTF16("user@gmail.com")); |
| 1159 const base::string16 gaia_given_name(ASCIIToUTF16("given name")); | 1179 const base::string16 gaia_given_name(ASCIIToUTF16("given name")); |
| 1160 cache.SetGAIAGivenNameOfProfileAtIndex(0, gaia_given_name); | 1180 entry->SetGAIAGivenName(gaia_given_name); |
| 1161 EXPECT_EQ(gaia_given_name, cache.GetNameOfProfileAtIndex(0)); | 1181 EXPECT_EQ(gaia_given_name, entry->GetName()); |
| 1162 EXPECT_EQ(gaia_given_name, | 1182 EXPECT_EQ(gaia_given_name, |
| 1163 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1183 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1164 | 1184 |
| 1165 // Multiple profiles means displaying the actual profile names. | 1185 // Multiple profiles means displaying the actual profile names. |
| 1166 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1186 const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u); |
| 1167 Profile* profile2 = AddProfileToCache(profile_manager, | 1187 Profile* profile2 = AddProfileToStorage(profile_manager, |
| 1168 "path_2", profile_name2); | 1188 "path_2", profile_name2); |
| 1169 EXPECT_EQ(gaia_given_name, | 1189 EXPECT_EQ(gaia_given_name, |
| 1170 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1190 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1171 EXPECT_EQ(profile_name2, | 1191 EXPECT_EQ(profile_name2, |
| 1172 profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1192 profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1173 | 1193 |
| 1174 // Deleting a profile means returning to the original, actual profile name. | 1194 // Deleting a profile means returning to the original, actual profile name. |
| 1175 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), | 1195 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), |
| 1176 ProfileManager::CreateCallback()); | 1196 ProfileManager::CreateCallback()); |
| 1177 // Spin the message loop so that all the callbacks can finish running. | 1197 // Spin the message loop so that all the callbacks can finish running. |
| 1178 base::RunLoop().RunUntilIdle(); | 1198 base::RunLoop().RunUntilIdle(); |
| 1179 EXPECT_EQ(gaia_given_name, | 1199 EXPECT_EQ(gaia_given_name, |
| 1180 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1200 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1181 } | 1201 } |
| 1182 | 1202 |
| 1183 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) { | 1203 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) { |
| 1184 if (!profiles::IsMultipleProfilesEnabled()) | 1204 if (!profiles::IsMultipleProfilesEnabled()) |
| 1185 return; | 1205 return; |
| 1186 | 1206 |
| 1187 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1207 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1188 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1208 ProfileAttributesStorage& storage = |
| 1189 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1209 profile_manager->GetProfileAttributesStorage(); |
| 1210 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1190 | 1211 |
| 1191 // Create two signed in profiles, with both new and legacy default names, and | 1212 // Create two signed in profiles, with both new and legacy default names, and |
| 1192 // a profile with a custom name. | 1213 // a profile with a custom name. |
| 1193 Profile* profile1 = AddProfileToCache( | 1214 Profile* profile1 = AddProfileToStorage(profile_manager, "path_1", |
| 1194 profile_manager, "path_1", ASCIIToUTF16("Person 1")); | 1215 ASCIIToUTF16("Person 1")); |
| 1195 Profile* profile2 = AddProfileToCache( | 1216 Profile* profile2 = AddProfileToStorage(profile_manager, "path_2", |
| 1196 profile_manager, "path_2", ASCIIToUTF16("Default Profile")); | 1217 ASCIIToUTF16("Default Profile")); |
| 1197 const base::string16 profile_name3(ASCIIToUTF16("Batman")); | 1218 const base::string16 profile_name3(ASCIIToUTF16("Batman")); |
| 1198 Profile* profile3 = AddProfileToCache( | 1219 Profile* profile3 = AddProfileToStorage(profile_manager, "path_3", |
| 1199 profile_manager, "path_3", profile_name3); | 1220 profile_name3); |
| 1200 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 1221 EXPECT_EQ(3u, storage.GetNumberOfProfiles()); |
| 1201 | 1222 |
| 1202 // Sign in all profiles, and make sure they do not have a Gaia name set. | 1223 // Sign in all profiles, and make sure they do not have a Gaia name set. |
| 1203 const base::string16 email1(ASCIIToUTF16("user1@gmail.com")); | 1224 const base::string16 email1(ASCIIToUTF16("user1@gmail.com")); |
| 1204 const base::string16 email2(ASCIIToUTF16("user2@gmail.com")); | 1225 const base::string16 email2(ASCIIToUTF16("user2@gmail.com")); |
| 1205 const base::string16 email3(ASCIIToUTF16("user3@gmail.com")); | 1226 const base::string16 email3(ASCIIToUTF16("user3@gmail.com")); |
| 1206 | 1227 |
| 1207 int index = cache.GetIndexOfProfileWithPath(profile1->GetPath()); | 1228 ProfileAttributesEntry* entry; |
| 1208 cache.SetAuthInfoOfProfileAtIndex(index, "12345", email1); | 1229 |
| 1209 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1230 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile1->GetPath(), |
| 1210 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1231 &entry)); |
| 1232 entry->SetAuthInfo("12345", email1); |
| 1233 entry->SetGAIAGivenName(base::string16()); |
| 1234 entry->SetGAIAName(base::string16()); |
| 1211 | 1235 |
| 1212 // This may resort the cache, so be extra cautious to use the right profile. | 1236 // This may resort the cache, so be extra cautious to use the right profile. |
| 1213 index = cache.GetIndexOfProfileWithPath(profile2->GetPath()); | 1237 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile2->GetPath(), |
| 1214 cache.SetAuthInfoOfProfileAtIndex(index, "23456", email2); | 1238 &entry)); |
| 1215 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1239 entry->SetAuthInfo("23456", email2); |
| 1216 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1240 entry->SetGAIAGivenName(base::string16()); |
| 1241 entry->SetGAIAName(base::string16()); |
| 1217 | 1242 |
| 1218 index = cache.GetIndexOfProfileWithPath(profile3->GetPath()); | 1243 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile3->GetPath(), |
| 1219 cache.SetAuthInfoOfProfileAtIndex(index, "34567", email3); | 1244 &entry)); |
| 1220 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1245 entry->SetAuthInfo("34567", email3); |
| 1221 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1246 entry->SetGAIAGivenName(base::string16()); |
| 1247 entry->SetGAIAName(base::string16()); |
| 1222 | 1248 |
| 1223 // The profiles with default names should display the email address. | 1249 // The profiles with default names should display the email address. |
| 1224 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1250 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1225 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1251 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1226 | 1252 |
| 1227 // The profile with the custom name should display that. | 1253 // The profile with the custom name should display that. |
| 1228 EXPECT_EQ(profile_name3, | 1254 EXPECT_EQ(profile_name3, |
| 1229 profiles::GetAvatarNameForProfile(profile3->GetPath())); | 1255 profiles::GetAvatarNameForProfile(profile3->GetPath())); |
| 1230 | 1256 |
| 1231 // Adding a Gaia name to a profile that previously had a default name should | 1257 // Adding a Gaia name to a profile that previously had a default name should |
| 1232 // start displaying it. | 1258 // start displaying it. |
| 1233 const base::string16 gaia_given_name(ASCIIToUTF16("Robin")); | 1259 const base::string16 gaia_given_name(ASCIIToUTF16("Robin")); |
| 1234 cache.SetGAIAGivenNameOfProfileAtIndex( | 1260 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile1->GetPath(), |
| 1235 cache.GetIndexOfProfileWithPath(profile1->GetPath()), gaia_given_name); | 1261 &entry)); |
| 1262 entry->SetGAIAGivenName(gaia_given_name); |
| 1236 EXPECT_EQ(gaia_given_name, | 1263 EXPECT_EQ(gaia_given_name, |
| 1237 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1264 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1238 } | 1265 } |
| 1239 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 1266 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 1240 | 1267 |
| 1241 #if defined(OS_MACOSX) | 1268 #if defined(OS_MACOSX) |
| 1242 // These tests are for a Mac-only code path that assumes the browser | 1269 // These tests are for a Mac-only code path that assumes the browser |
| 1243 // process isn't killed when all browser windows are closed. | 1270 // process isn't killed when all browser windows are closed. |
| 1244 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { | 1271 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { |
| 1245 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1272 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1246 ASSERT_TRUE(profile_manager); | 1273 ASSERT_TRUE(profile_manager); |
| 1247 | 1274 |
| 1248 // Create and load one profile, and just create a second profile. | 1275 // Create and load one profile, and just create a second profile. |
| 1249 const std::string profile_name1 = "New Profile 1"; | 1276 const std::string profile_name1 = "New Profile 1"; |
| 1250 const std::string profile_name2 = "New Profile 2"; | 1277 const std::string profile_name2 = "New Profile 2"; |
| 1251 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1278 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 1252 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1279 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1253 | 1280 |
| 1254 MockObserver mock_observer; | 1281 MockObserver mock_observer; |
| 1255 EXPECT_CALL(mock_observer, OnProfileCreated( | 1282 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1256 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1283 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1257 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1284 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1258 base::RunLoop().RunUntilIdle(); | 1285 base::RunLoop().RunUntilIdle(); |
| 1259 | 1286 |
| 1260 // Track the profile, but don't load it. | 1287 // Track the profile, but don't load it. |
| 1261 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1288 ProfileAttributesStorage& storage = |
| 1262 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), "23456", | 1289 profile_manager->GetProfileAttributesStorage(); |
| 1263 base::string16(), 0, std::string()); | 1290 storage.AddProfile(dest_path2, ASCIIToUTF16(profile_name2), "23456", |
| 1291 base::string16(), 0, std::string()); |
| 1264 base::RunLoop().RunUntilIdle(); | 1292 base::RunLoop().RunUntilIdle(); |
| 1265 | 1293 |
| 1266 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1294 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1267 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 1295 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 1268 | 1296 |
| 1269 // Set the active profile. | 1297 // Set the active profile. |
| 1270 PrefService* local_state = g_browser_process->local_state(); | 1298 PrefService* local_state = g_browser_process->local_state(); |
| 1271 local_state->SetString(prefs::kProfileLastUsed, | 1299 local_state->SetString(prefs::kProfileLastUsed, |
| 1272 dest_path1.BaseName().MaybeAsASCII()); | 1300 dest_path1.BaseName().MaybeAsASCII()); |
| 1273 | 1301 |
| 1274 // Delete the active profile. This should switch and load the unloaded | 1302 // Delete the active profile. This should switch and load the unloaded |
| 1275 // profile. | 1303 // profile. |
| 1276 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1304 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1277 ProfileManager::CreateCallback()); | 1305 ProfileManager::CreateCallback()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1299 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1327 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1300 base::FilePath dest_path3 = temp_dir_.path().AppendASCII(profile_name3); | 1328 base::FilePath dest_path3 = temp_dir_.path().AppendASCII(profile_name3); |
| 1301 | 1329 |
| 1302 MockObserver mock_observer; | 1330 MockObserver mock_observer; |
| 1303 EXPECT_CALL(mock_observer, OnProfileCreated( | 1331 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1304 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1332 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1305 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1333 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1306 base::RunLoop().RunUntilIdle(); | 1334 base::RunLoop().RunUntilIdle(); |
| 1307 | 1335 |
| 1308 // Create the other profiles, but don't load them. Assign a fake avatar icon | 1336 // Create the other profiles, but don't load them. Assign a fake avatar icon |
| 1309 // to ensure that profiles in the info cache are sorted by the profile name, | 1337 // to ensure that profiles in the profile attributes storage are sorted by the |
| 1310 // and not randomly by the avatar name. | 1338 // profile name, and not randomly by the avatar name. |
| 1311 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1339 ProfileAttributesStorage& storage = |
| 1312 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | 1340 profile_manager->GetProfileAttributesStorage(); |
| 1313 "23456", ASCIIToUTF16(profile_name2), 1, | 1341 storage.AddProfilee(dest_path2, ASCIIToUTF16(profile_name2), "23456", |
| 1314 std::string()); | 1342 ASCIIToUTF16(profile_name2), 1, std::string()); |
| 1315 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), | 1343 storage.AddProfile(dest_path3, ASCIIToUTF16(profile_name3), "34567", |
| 1316 "34567", ASCIIToUTF16(profile_name3), 2, | 1344 ASCIIToUTF16(profile_name3), 2, std::string()); |
| 1317 std::string()); | |
| 1318 | 1345 |
| 1319 base::RunLoop().RunUntilIdle(); | 1346 base::RunLoop().RunUntilIdle(); |
| 1320 | 1347 |
| 1321 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1348 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1322 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 1349 EXPECT_EQ(3u, storage.GetNumberOfProfiles()); |
| 1323 | 1350 |
| 1324 // Set the active profile. | 1351 // Set the active profile. |
| 1325 PrefService* local_state = g_browser_process->local_state(); | 1352 PrefService* local_state = g_browser_process->local_state(); |
| 1326 local_state->SetString(prefs::kProfileLastUsed, | 1353 local_state->SetString(prefs::kProfileLastUsed, |
| 1327 dest_path1.BaseName().MaybeAsASCII()); | 1354 dest_path1.BaseName().MaybeAsASCII()); |
| 1328 | 1355 |
| 1329 // Delete the active profile, Profile1. | 1356 // Delete the active profile, Profile1. |
| 1330 // This will post a CreateProfileAsync message, that tries to load Profile2, | 1357 // This will post a CreateProfileAsync message, that tries to load Profile2, |
| 1331 // which checks that the profile is not being deleted, and then calls back | 1358 // which checks that the profile is not being deleted, and then calls back |
| 1332 // FinishDeletingProfile for Profile1. | 1359 // FinishDeletingProfile for Profile1. |
| 1333 // Try to break this flow by setting the active profile to Profile2 in the | 1360 // Try to break this flow by setting the active profile to Profile2 in the |
| 1334 // middle (so after the first posted message), and trying to delete Profile2, | 1361 // middle (so after the first posted message), and trying to delete Profile2, |
| 1335 // so that the ProfileManager has to look for a different profile to load. | 1362 // so that the ProfileManager has to look for a different profile to load. |
| 1336 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1363 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1337 ProfileManager::CreateCallback()); | 1364 ProfileManager::CreateCallback()); |
| 1338 local_state->SetString(prefs::kProfileLastUsed, | 1365 local_state->SetString(prefs::kProfileLastUsed, |
| 1339 dest_path2.BaseName().MaybeAsASCII()); | 1366 dest_path2.BaseName().MaybeAsASCII()); |
| 1340 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1367 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1341 ProfileManager::CreateCallback()); | 1368 ProfileManager::CreateCallback()); |
| 1342 // Spin the message loop so that all the callbacks can finish running. | 1369 // Spin the message loop so that all the callbacks can finish running. |
| 1343 base::RunLoop().RunUntilIdle(); | 1370 base::RunLoop().RunUntilIdle(); |
| 1344 | 1371 |
| 1345 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1372 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1346 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1373 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1347 } | 1374 } |
| 1348 #endif // !defined(OS_MACOSX) | 1375 #endif // !defined(OS_MACOSX) |
| OLD | NEW |