| 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_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 MockObserver* mock_observer) { | 157 MockObserver* mock_observer) { |
| 158 manager->CreateProfileAsync( | 158 manager->CreateProfileAsync( |
| 159 temp_dir_.path().AppendASCII(name), | 159 temp_dir_.path().AppendASCII(name), |
| 160 base::Bind(&MockObserver::OnProfileCreated, | 160 base::Bind(&MockObserver::OnProfileCreated, |
| 161 base::Unretained(mock_observer)), | 161 base::Unretained(mock_observer)), |
| 162 base::UTF8ToUTF16(name), | 162 base::UTF8ToUTF16(name), |
| 163 profiles::GetDefaultAvatarIconUrl(0), | 163 profiles::GetDefaultAvatarIconUrl(0), |
| 164 is_supervised ? "Dummy ID" : std::string()); | 164 is_supervised ? "Dummy ID" : std::string()); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Helper function to add a profile with |profile_name| to | 167 // Helper function to add a profile with |profile_name| to |profile_manager|'s |
| 168 // |profile_manager|'s ProfileInfoCache, and return the profile created. | 168 // ProfileAttributesStorage, and return the profile created. |
| 169 Profile* AddProfileToCache(ProfileManager* profile_manager, | 169 Profile* AddProfileToStorage(ProfileManager* profile_manager, |
| 170 const std::string& path_suffix, | 170 const std::string& path_suffix, |
| 171 const base::string16& profile_name) { | 171 const base::string16& profile_name) { |
| 172 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 172 ProfileAttributesStorage& storage = |
| 173 size_t num_profiles = cache.GetNumberOfProfiles(); | 173 profile_manager->GetProfileAttributesStorage(); |
| 174 size_t num_profiles = storage.GetNumberOfProfiles(); |
| 174 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); | 175 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); |
| 175 cache.AddProfileToCache(path, profile_name, | 176 storage.AddProfile(path, profile_name, std::string(), base::string16(), 0, |
| 176 std::string(), base::string16(), 0, std::string()); | 177 std::string()); |
| 177 EXPECT_EQ(num_profiles + 1, cache.GetNumberOfProfiles()); | 178 EXPECT_EQ(num_profiles + 1u, storage.GetNumberOfProfiles()); |
| 178 return profile_manager->GetProfile(path); | 179 return profile_manager->GetProfile(path); |
| 179 } | 180 } |
| 180 | 181 |
| 181 #if defined(OS_CHROMEOS) | 182 #if defined(OS_CHROMEOS) |
| 182 // Helper function to register an user with id |user_id| and create profile | 183 // Helper function to register an user with id |user_id| and create profile |
| 183 // with a correct path. | 184 // with a correct path. |
| 184 void RegisterUser(const std::string& user_id) { | 185 void RegisterUser(const std::string& user_id) { |
| 185 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); | 186 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); |
| 186 const std::string user_id_hash = | 187 const std::string user_id_hash = |
| 187 profile_helper->GetUserIdHashByUserIdForTesting(user_id); | 188 profile_helper->GetUserIdHashByUserIdForTesting(user_id); |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 } | 409 } |
| 409 | 410 |
| 410 TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { | 411 TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { |
| 411 std::string name = "0 Supervised Profile"; | 412 std::string name = "0 Supervised Profile"; |
| 412 | 413 |
| 413 MockObserver mock_observer; | 414 MockObserver mock_observer; |
| 414 EXPECT_CALL(mock_observer, OnProfileCreated( | 415 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 415 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 416 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 416 | 417 |
| 417 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 418 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 418 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 419 ProfileAttributesStorage& storage = |
| 419 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 420 profile_manager->GetProfileAttributesStorage(); |
| 421 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 420 | 422 |
| 421 CreateProfileAsync(profile_manager, name, true, &mock_observer); | 423 CreateProfileAsync(profile_manager, name, true, &mock_observer); |
| 422 base::RunLoop().RunUntilIdle(); | 424 base::RunLoop().RunUntilIdle(); |
| 423 | 425 |
| 424 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); | 426 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 425 // Supervised profiles should start out omitted from the profile list. | 427 // Supervised profiles should start out omitted from the profile list. |
| 426 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); | 428 EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0u]->IsOmitted()); |
| 427 | 429 |
| 428 name = "1 Regular Profile"; | 430 name = "1 Regular Profile"; |
| 429 CreateProfileAsync(profile_manager, name, false, &mock_observer); | 431 CreateProfileAsync(profile_manager, name, false, &mock_observer); |
| 430 base::RunLoop().RunUntilIdle(); | 432 base::RunLoop().RunUntilIdle(); |
| 431 | 433 |
| 432 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 434 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 433 // Non-supervised profiles should be included in the profile list. | 435 // Non-supervised profiles should be included in the profile list. |
| 434 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(1)); | 436 EXPECT_FALSE(storage.GetAllProfilesAttributesSortedByName()[1u]->IsOmitted()); |
| 435 } | 437 } |
| 436 | 438 |
| 437 TEST_F(ProfileManagerTest, AddProfileToCacheCheckOmitted) { | 439 TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { |
| 438 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 440 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 439 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 441 ProfileAttributesStorage& storage = |
| 440 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 442 profile_manager->GetProfileAttributesStorage(); |
| 443 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 441 | 444 |
| 442 const base::FilePath supervised_path = | 445 const base::FilePath supervised_path = |
| 443 temp_dir_.path().AppendASCII("Supervised"); | 446 temp_dir_.path().AppendASCII("Supervised"); |
| 444 TestingProfile* supervised_profile = | 447 TestingProfile* supervised_profile = |
| 445 new TestingProfile(supervised_path, NULL); | 448 new TestingProfile(supervised_path, NULL); |
| 446 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); | 449 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); |
| 447 | 450 |
| 448 // RegisterTestingProfile adds the profile to the cache and takes ownership. | 451 // RegisterTestingProfile adds the profile to the cache and takes ownership. |
| 449 profile_manager->RegisterTestingProfile(supervised_profile, true, false); | 452 profile_manager->RegisterTestingProfile(supervised_profile, true, false); |
| 450 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); | 453 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 451 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); | 454 EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0u]->IsOmitted()); |
| 452 | 455 |
| 453 const base::FilePath nonsupervised_path = temp_dir_.path().AppendASCII( | 456 const base::FilePath nonsupervised_path = temp_dir_.path().AppendASCII( |
| 454 "Non-Supervised"); | 457 "Non-Supervised"); |
| 455 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, | 458 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, |
| 456 NULL); | 459 NULL); |
| 457 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); | 460 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); |
| 458 | 461 |
| 459 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 462 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 460 size_t supervised_index = cache.GetIndexOfProfileWithPath(supervised_path); | 463 ProfileAttributesEntry* entry; |
| 461 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(supervised_index)); | 464 ASSERT_TRUE(storage.GetProfileAttributesWithPath(supervised_path, &entry)); |
| 462 size_t nonsupervised_index = | 465 EXPECT_TRUE(entry->IsOmitted()); |
| 463 cache.GetIndexOfProfileWithPath(nonsupervised_path); | 466 |
| 464 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(nonsupervised_index)); | 467 ASSERT_TRUE(storage.GetProfileAttributesWithPath(nonsupervised_path, &entry)); |
| 468 EXPECT_FALSE(entry->IsOmitted()); |
| 465 } | 469 } |
| 466 | 470 |
| 467 TEST_F(ProfileManagerTest, GetGuestProfilePath) { | 471 TEST_F(ProfileManagerTest, GetGuestProfilePath) { |
| 468 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); | 472 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); |
| 469 base::FilePath expected_path = temp_dir_.path(); | 473 base::FilePath expected_path = temp_dir_.path(); |
| 470 expected_path = expected_path.Append(chrome::kGuestProfileDir); | 474 expected_path = expected_path.Append(chrome::kGuestProfileDir); |
| 471 EXPECT_EQ(expected_path, guest_path); | 475 EXPECT_EQ(expected_path, guest_path); |
| 472 } | 476 } |
| 473 | 477 |
| 474 TEST_F(ProfileManagerTest, GetSystemProfilePath) { | 478 TEST_F(ProfileManagerTest, GetSystemProfilePath) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 541 |
| 538 Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); | 542 Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); |
| 539 EXPECT_TRUE(last_used_profile->IsOffTheRecord()); | 543 EXPECT_TRUE(last_used_profile->IsOffTheRecord()); |
| 540 | 544 |
| 541 EXPECT_TRUE(last_used_profile->IsSameProfile(active_profile)); | 545 EXPECT_TRUE(last_used_profile->IsSameProfile(active_profile)); |
| 542 } | 546 } |
| 543 #endif | 547 #endif |
| 544 | 548 |
| 545 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { | 549 TEST_F(ProfileManagerTest, AutoloadProfilesWithBackgroundApps) { |
| 546 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 550 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 547 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 551 ProfileAttributesStorage& storage = |
| 552 profile_manager->GetProfileAttributesStorage(); |
| 548 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 553 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
| 549 new base::FundamentalValue(true)); | 554 new base::FundamentalValue(true)); |
| 550 | 555 |
| 551 // Setting a pref which is not applicable to a system (i.e., Android in this | 556 // Setting a pref which is not applicable to a system (i.e., Android in this |
| 552 // case) does not necessarily create it. Don't bother continuing with the | 557 // case) does not necessarily create it. Don't bother continuing with the |
| 553 // test if this pref doesn't exist because it will not load the profiles if | 558 // test if this pref doesn't exist because it will not load the profiles if |
| 554 // it cannot verify that the pref for background mode is enabled. | 559 // it cannot verify that the pref for background mode is enabled. |
| 555 if (!local_state_.Get()->HasPrefPath(prefs::kBackgroundModeEnabled)) | 560 if (!local_state_.Get()->HasPrefPath(prefs::kBackgroundModeEnabled)) |
| 556 return; | 561 return; |
| 557 | 562 |
| 558 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 563 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 559 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 564 |
| 560 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, | 565 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_1"), |
| 561 std::string()); | 566 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, std::string()); |
| 562 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 567 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_2"), |
| 563 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, | 568 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, std::string()); |
| 564 std::string()); | 569 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_3"), |
| 565 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_3"), | 570 ASCIIToUTF16("name_3"), "34567", base::string16(), 0, std::string()); |
| 566 ASCIIToUTF16("name_3"), "34567", base::string16(), 0, | 571 |
| 567 std::string()); | 572 EXPECT_EQ(3u, storage.GetNumberOfProfiles()); |
| 568 cache.SetBackgroundStatusOfProfileAtIndex(0, true); | 573 |
| 569 cache.SetBackgroundStatusOfProfileAtIndex(2, true); | 574 std::vector<ProfileAttributesEntry*> entries = |
| 570 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 575 storage.GetAllProfilesAttributes(); |
| 576 entries[0u]->SetBackgroundStatus(true); |
| 577 entries[2u]->SetBackgroundStatus(true); |
| 571 | 578 |
| 572 profile_manager->AutoloadProfiles(); | 579 profile_manager->AutoloadProfiles(); |
| 573 | 580 |
| 574 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 581 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 575 } | 582 } |
| 576 | 583 |
| 577 TEST_F(ProfileManagerTest, DoNotAutoloadProfilesIfBackgroundModeOff) { | 584 TEST_F(ProfileManagerTest, DoNotAutoloadProfilesIfBackgroundModeOff) { |
| 578 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 585 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 579 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 586 ProfileAttributesStorage& storage = |
| 587 profile_manager->GetProfileAttributesStorage(); |
| 580 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, | 588 local_state_.Get()->SetUserPref(prefs::kBackgroundModeEnabled, |
| 581 new base::FundamentalValue(false)); | 589 new base::FundamentalValue(false)); |
| 582 | 590 |
| 583 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 591 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 584 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_1"), | 592 |
| 585 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, | 593 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_1"), |
| 586 std::string()); | 594 ASCIIToUTF16("name_1"), "12345", base::string16(), 0, std::string()); |
| 587 cache.AddProfileToCache(cache.GetUserDataDir().AppendASCII("path_2"), | 595 storage.AddProfile(profile_manager->user_data_dir().AppendASCII("path_2"), |
| 588 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, | 596 ASCIIToUTF16("name_2"), "23456", base::string16(), 0, std::string()); |
| 589 std::string()); | 597 |
| 590 cache.SetBackgroundStatusOfProfileAtIndex(0, false); | 598 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 591 cache.SetBackgroundStatusOfProfileAtIndex(1, true); | 599 |
| 592 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 600 std::vector<ProfileAttributesEntry*> entries = |
| 601 storage.GetAllProfilesAttributes(); |
| 602 entries[0u]->SetBackgroundStatus(false); |
| 603 entries[1u]->SetBackgroundStatus(true); |
| 593 | 604 |
| 594 profile_manager->AutoloadProfiles(); | 605 profile_manager->AutoloadProfiles(); |
| 595 | 606 |
| 596 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); | 607 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); |
| 597 } | 608 } |
| 598 | 609 |
| 599 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { | 610 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { |
| 600 base::FilePath dest_path = temp_dir_.path(); | 611 base::FilePath dest_path = temp_dir_.path(); |
| 601 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 612 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 602 | 613 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 620 avatar_index)); | 631 avatar_index)); |
| 621 } | 632 } |
| 622 | 633 |
| 623 // Tests that a new profile's entry in the profile info cache is setup with the | 634 // Tests that a new profile's entry in the profile info cache is setup with the |
| 624 // same values that are in the profile prefs. | 635 // same values that are in the profile prefs. |
| 625 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { | 636 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { |
| 626 base::FilePath dest_path = temp_dir_.path(); | 637 base::FilePath dest_path = temp_dir_.path(); |
| 627 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 638 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 628 | 639 |
| 629 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 640 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 630 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
| 631 | 641 |
| 632 // Successfully create the profile | 642 // Successfully create the profile |
| 633 Profile* profile = profile_manager->GetProfile(dest_path); | 643 Profile* profile = profile_manager->GetProfile(dest_path); |
| 634 ASSERT_TRUE(profile); | 644 ASSERT_TRUE(profile); |
| 635 | 645 |
| 636 std::string profile_name = | 646 std::string profile_name = |
| 637 profile->GetPrefs()->GetString(prefs::kProfileName); | 647 profile->GetPrefs()->GetString(prefs::kProfileName); |
| 638 size_t avatar_index = | 648 size_t avatar_index = |
| 639 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); | 649 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 640 | 650 |
| 641 size_t profile_index = cache.GetIndexOfProfileWithPath(dest_path); | 651 ProfileAttributesEntry* entry; |
| 652 ASSERT_TRUE(profile_manager->GetProfileAttributesStorage(). |
| 653 GetProfileAttributesWithPath(dest_path, &entry)); |
| 642 | 654 |
| 643 // Check if the profile prefs are the same as the cache prefs | 655 // Check if the profile prefs are the same as the cache prefs |
| 644 EXPECT_EQ(profile_name, | 656 EXPECT_EQ(profile_name, base::UTF16ToUTF8(entry->GetName())); |
| 645 base::UTF16ToUTF8(cache.GetNameOfProfileAtIndex(profile_index))); | 657 EXPECT_EQ(avatar_index, entry->GetAvatarIconIndex()); |
| 646 EXPECT_EQ(avatar_index, | |
| 647 cache.GetAvatarIconIndexOfProfileAtIndex(profile_index)); | |
| 648 } | 658 } |
| 649 | 659 |
| 650 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { | 660 TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { |
| 651 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 661 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 652 ASSERT_TRUE(profile_manager); | 662 ASSERT_TRUE(profile_manager); |
| 653 | 663 |
| 654 #if defined(OS_CHROMEOS) | 664 #if defined(OS_CHROMEOS) |
| 655 // On CrOS, profile returned by GetLastUsedProfile is a singin profile that | 665 // On CrOS, profile returned by GetLastUsedProfile is a singin profile that |
| 656 // is forced to be incognito. That's why we need to create at least one user | 666 // is forced to be incognito. That's why we need to create at least one user |
| 657 // to get a regular profile. | 667 // to get a regular profile. |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 browser3.reset(); | 959 browser3.reset(); |
| 950 | 960 |
| 951 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 961 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 952 ASSERT_EQ(1U, last_opened_profiles.size()); | 962 ASSERT_EQ(1U, last_opened_profiles.size()); |
| 953 EXPECT_EQ(normal_profile, last_opened_profiles[0]); | 963 EXPECT_EQ(normal_profile, last_opened_profiles[0]); |
| 954 } | 964 } |
| 955 | 965 |
| 956 TEST_F(ProfileManagerTest, CleanUpEphemeralProfiles) { | 966 TEST_F(ProfileManagerTest, CleanUpEphemeralProfiles) { |
| 957 // Create two profiles, one of them ephemeral. | 967 // Create two profiles, one of them ephemeral. |
| 958 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 968 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 959 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 969 ProfileAttributesStorage& storage = |
| 960 ASSERT_EQ(0u, cache.GetNumberOfProfiles()); | 970 profile_manager->GetProfileAttributesStorage(); |
| 971 ASSERT_EQ(0u, storage.GetNumberOfProfiles()); |
| 961 | 972 |
| 962 const std::string profile_name1 = "Homer"; | 973 const std::string profile_name1 = "Homer"; |
| 963 base::FilePath path1 = temp_dir_.path().AppendASCII(profile_name1); | 974 base::FilePath path1 = |
| 964 cache.AddProfileToCache(path1, base::UTF8ToUTF16(profile_name1), | 975 profile_manager->user_data_dir().AppendASCII(profile_name1); |
| 965 std::string(), base::UTF8ToUTF16(profile_name1), 0, | 976 storage.AddProfile(path1, base::UTF8ToUTF16(profile_name1), std::string(), |
| 966 std::string()); | 977 base::UTF8ToUTF16(profile_name1), 0, std::string()); |
| 967 cache.SetProfileIsEphemeralAtIndex(0, true); | 978 storage.GetAllProfilesAttributes()[0u]->SetIsEphemeral(true); |
| 968 ASSERT_TRUE(base::CreateDirectory(path1)); | 979 ASSERT_TRUE(base::CreateDirectory(path1)); |
| 969 | 980 |
| 970 const std::string profile_name2 = "Marge"; | 981 const std::string profile_name2 = "Marge"; |
| 971 base::FilePath path2 = temp_dir_.path().AppendASCII(profile_name2); | 982 base::FilePath path2 = |
| 972 cache.AddProfileToCache(path2, base::UTF8ToUTF16(profile_name2), | 983 profile_manager->user_data_dir().AppendASCII(profile_name2); |
| 973 std::string(), base::UTF8ToUTF16(profile_name2), 0, | 984 storage.AddProfile(path2, base::UTF8ToUTF16(profile_name2), std::string(), |
| 974 std::string()); | 985 base::UTF8ToUTF16(profile_name2), 0, std::string()); |
| 975 ASSERT_EQ(2u, cache.GetNumberOfProfiles()); | 986 ASSERT_EQ(2u, storage.GetNumberOfProfiles()); |
| 976 ASSERT_TRUE(base::CreateDirectory(path2)); | 987 ASSERT_TRUE(base::CreateDirectory(path2)); |
| 977 | 988 |
| 978 // Set the active profile. | 989 // Set the active profile. |
| 979 PrefService* local_state = g_browser_process->local_state(); | 990 PrefService* local_state = g_browser_process->local_state(); |
| 980 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 991 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 981 | 992 |
| 982 profile_manager->CleanUpEphemeralProfiles(); | 993 profile_manager->CleanUpEphemeralProfiles(); |
| 983 base::RunLoop().RunUntilIdle(); | 994 base::RunLoop().RunUntilIdle(); |
| 984 | 995 |
| 985 // The ephemeral profile should be deleted, and the last used profile set to | 996 // The ephemeral profile should be deleted, and the last used profile set to |
| 986 // the other one. | 997 // the other one. |
| 987 EXPECT_FALSE(base::DirectoryExists(path1)); | 998 EXPECT_FALSE(base::DirectoryExists(path1)); |
| 988 EXPECT_TRUE(base::DirectoryExists(path2)); | 999 EXPECT_TRUE(base::DirectoryExists(path2)); |
| 989 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 1000 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 990 ASSERT_EQ(1u, cache.GetNumberOfProfiles()); | 1001 ASSERT_EQ(1u, storage.GetNumberOfProfiles()); |
| 991 | 1002 |
| 992 // Mark the remaining profile ephemeral and clean up. | 1003 // Mark the remaining profile ephemeral and clean up. |
| 993 cache.SetProfileIsEphemeralAtIndex(0, true); | 1004 storage.GetAllProfilesAttributes()[0u]->SetIsEphemeral(true); |
| 994 profile_manager->CleanUpEphemeralProfiles(); | 1005 profile_manager->CleanUpEphemeralProfiles(); |
| 995 base::RunLoop().RunUntilIdle(); | 1006 base::RunLoop().RunUntilIdle(); |
| 996 | 1007 |
| 997 // The profile should be deleted, and the last used profile set to a new one. | 1008 // The profile should be deleted, and the last used profile set to a new one. |
| 998 EXPECT_FALSE(base::DirectoryExists(path2)); | 1009 EXPECT_FALSE(base::DirectoryExists(path2)); |
| 999 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1010 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1000 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); | 1011 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); |
| 1001 } | 1012 } |
| 1002 | 1013 |
| 1003 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { | 1014 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { |
| 1004 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1015 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1005 ASSERT_TRUE(profile_manager); | 1016 ASSERT_TRUE(profile_manager); |
| 1006 | 1017 |
| 1007 // Create and load two profiles. | 1018 // Create and load two profiles. |
| 1008 const std::string profile_name1 = "New Profile 1"; | 1019 const std::string profile_name1 = "New Profile 1"; |
| 1009 const std::string profile_name2 = "New Profile 2"; | 1020 const std::string profile_name2 = "New Profile 2"; |
| 1010 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1021 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 1011 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1022 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1012 | 1023 |
| 1013 MockObserver mock_observer; | 1024 MockObserver mock_observer; |
| 1014 EXPECT_CALL(mock_observer, OnProfileCreated( | 1025 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1015 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 1026 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 1016 | 1027 |
| 1017 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1028 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1018 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); | 1029 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); |
| 1019 base::RunLoop().RunUntilIdle(); | 1030 base::RunLoop().RunUntilIdle(); |
| 1020 | 1031 |
| 1021 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 1032 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 1022 EXPECT_EQ(2u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1033 EXPECT_EQ(2u, profile_manager->GetProfileAttributesStorage(). |
| 1034 GetNumberOfProfiles()); |
| 1023 | 1035 |
| 1024 // Set the active profile. | 1036 // Set the active profile. |
| 1025 PrefService* local_state = g_browser_process->local_state(); | 1037 PrefService* local_state = g_browser_process->local_state(); |
| 1026 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 1038 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 1027 | 1039 |
| 1028 // Delete the active profile. | 1040 // Delete the active profile. |
| 1029 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1041 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1030 ProfileManager::CreateCallback()); | 1042 ProfileManager::CreateCallback()); |
| 1031 // Spin the message loop so that all the callbacks can finish running. | 1043 // Spin the message loop so that all the callbacks can finish running. |
| 1032 base::RunLoop().RunUntilIdle(); | 1044 base::RunLoop().RunUntilIdle(); |
| 1033 | 1045 |
| 1034 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 1046 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1035 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 1047 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 1036 } | 1048 } |
| 1037 | 1049 |
| 1038 TEST_F(ProfileManagerTest, LastProfileDeleted) { | 1050 TEST_F(ProfileManagerTest, LastProfileDeleted) { |
| 1039 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1051 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1040 ASSERT_TRUE(profile_manager); | 1052 ASSERT_TRUE(profile_manager); |
| 1053 ProfileAttributesStorage& storage = |
| 1054 profile_manager->GetProfileAttributesStorage(); |
| 1041 | 1055 |
| 1042 // Create and load a profile. | 1056 // Create and load a profile. |
| 1043 const std::string profile_name1 = "New Profile 1"; | 1057 const std::string profile_name1 = "New Profile 1"; |
| 1044 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1058 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 1045 | 1059 |
| 1046 MockObserver mock_observer; | 1060 MockObserver mock_observer; |
| 1047 EXPECT_CALL(mock_observer, OnProfileCreated( | 1061 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1048 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 1062 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 1049 | 1063 |
| 1050 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1064 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1051 base::RunLoop().RunUntilIdle(); | 1065 base::RunLoop().RunUntilIdle(); |
| 1052 | 1066 |
| 1053 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1067 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1054 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1068 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1055 | 1069 |
| 1056 // Set it as the active profile. | 1070 // Set it as the active profile. |
| 1057 PrefService* local_state = g_browser_process->local_state(); | 1071 PrefService* local_state = g_browser_process->local_state(); |
| 1058 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 1072 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 1059 | 1073 |
| 1060 // Delete the active profile. | 1074 // Delete the active profile. |
| 1061 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1075 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1062 ProfileManager::CreateCallback()); | 1076 ProfileManager::CreateCallback()); |
| 1063 // Spin the message loop so that all the callbacks can finish running. | 1077 // Spin the message loop so that all the callbacks can finish running. |
| 1064 base::RunLoop().RunUntilIdle(); | 1078 base::RunLoop().RunUntilIdle(); |
| 1065 | 1079 |
| 1066 // A new profile should have been created | 1080 // A new profile should have been created |
| 1067 const std::string profile_name2 = "Profile 1"; | 1081 const std::string profile_name2 = "Profile 1"; |
| 1068 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1082 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1069 | 1083 |
| 1070 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 1084 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1071 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 1085 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 1072 EXPECT_EQ(dest_path2, | 1086 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); |
| 1073 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0)); | |
| 1074 } | 1087 } |
| 1075 | 1088 |
| 1076 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { | 1089 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { |
| 1077 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1090 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1078 ASSERT_TRUE(profile_manager); | 1091 ASSERT_TRUE(profile_manager); |
| 1092 ProfileAttributesStorage& storage = |
| 1093 profile_manager->GetProfileAttributesStorage(); |
| 1079 | 1094 |
| 1080 // Create and load a profile. | 1095 // Create and load a profile. |
| 1081 const std::string profile_name1 = "New Profile 1"; | 1096 const std::string profile_name1 = "New Profile 1"; |
| 1082 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1097 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 1083 | 1098 |
| 1084 MockObserver mock_observer; | 1099 MockObserver mock_observer; |
| 1085 EXPECT_CALL(mock_observer, OnProfileCreated( | 1100 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1086 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1101 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1087 | 1102 |
| 1088 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1103 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1089 base::RunLoop().RunUntilIdle(); | 1104 base::RunLoop().RunUntilIdle(); |
| 1090 | 1105 |
| 1091 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1106 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1092 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1107 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1093 | 1108 |
| 1094 // Create the profile and register it. | 1109 // Create the profile and register it. |
| 1095 const std::string guest_profile_name = | 1110 const std::string guest_profile_name = |
| 1096 ProfileManager::GetGuestProfilePath().BaseName().MaybeAsASCII(); | 1111 ProfileManager::GetGuestProfilePath().BaseName().MaybeAsASCII(); |
| 1097 | 1112 |
| 1098 TestingProfile::Builder builder; | 1113 TestingProfile::Builder builder; |
| 1099 builder.SetGuestSession(); | 1114 builder.SetGuestSession(); |
| 1100 builder.SetPath(ProfileManager::GetGuestProfilePath()); | 1115 builder.SetPath(ProfileManager::GetGuestProfilePath()); |
| 1101 TestingProfile* guest_profile = builder.Build().release(); | 1116 TestingProfile* guest_profile = builder.Build().release(); |
| 1102 guest_profile->set_profile_name(guest_profile_name); | 1117 guest_profile->set_profile_name(guest_profile_name); |
| 1103 // Registering the profile passes ownership to the ProfileManager. | 1118 // Registering the profile passes ownership to the ProfileManager. |
| 1104 profile_manager->RegisterTestingProfile(guest_profile, false, false); | 1119 profile_manager->RegisterTestingProfile(guest_profile, false, false); |
| 1105 | 1120 |
| 1106 // The Guest profile does not get added to the ProfileInfoCache. | 1121 // The Guest profile does not get added to the ProfileAttributesStorage. |
| 1107 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 1122 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| 1108 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1123 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1109 | 1124 |
| 1110 // Set the Guest profile as the active profile. | 1125 // Set the Guest profile as the active profile. |
| 1111 PrefService* local_state = g_browser_process->local_state(); | 1126 PrefService* local_state = g_browser_process->local_state(); |
| 1112 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name); | 1127 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name); |
| 1113 | 1128 |
| 1114 // Delete the other profile. | 1129 // Delete the other profile. |
| 1115 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1130 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1116 ProfileManager::CreateCallback()); | 1131 ProfileManager::CreateCallback()); |
| 1117 // Spin the message loop so that all the callbacks can finish running. | 1132 // Spin the message loop so that all the callbacks can finish running. |
| 1118 base::RunLoop().RunUntilIdle(); | 1133 base::RunLoop().RunUntilIdle(); |
| 1119 | 1134 |
| 1120 // A new profile should have been created. | 1135 // A new profile should have been created. |
| 1121 const std::string profile_name2 = "Profile 1"; | 1136 const std::string profile_name2 = "Profile 1"; |
| 1122 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1137 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1123 | 1138 |
| 1124 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size()); | 1139 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size()); |
| 1125 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles()); | 1140 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1126 EXPECT_EQ(dest_path2, | 1141 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); |
| 1127 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0)); | |
| 1128 } | 1142 } |
| 1129 | 1143 |
| 1130 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { | 1144 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { |
| 1131 if (!profiles::IsMultipleProfilesEnabled()) | 1145 if (!profiles::IsMultipleProfilesEnabled()) |
| 1132 return; | 1146 return; |
| 1133 | 1147 |
| 1134 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1148 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1135 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1149 ProfileAttributesStorage& storage = |
| 1136 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1150 profile_manager->GetProfileAttributesStorage(); |
| 1151 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1137 | 1152 |
| 1138 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1153 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1139 const base::string16 default_profile_name = | 1154 const base::string16 default_profile_name = |
| 1140 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1155 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 1141 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1156 const base::string16 profile_name1 = storage.ChooseNameForNewProfile(0u); |
| 1142 Profile* profile1 = AddProfileToCache(profile_manager, | 1157 Profile* profile1 = AddProfileToStorage(profile_manager, |
| 1143 "path_1", profile_name1); | 1158 "path_1", profile_name1); |
| 1144 EXPECT_EQ(default_profile_name, | 1159 EXPECT_EQ(default_profile_name, |
| 1145 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1160 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1146 | 1161 |
| 1147 // Multiple profiles means displaying the actual profile names. | 1162 // Multiple profiles means displaying the actual profile names. |
| 1148 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1163 const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u); |
| 1149 Profile* profile2 = AddProfileToCache(profile_manager, | 1164 Profile* profile2 = AddProfileToStorage(profile_manager, |
| 1150 "path_2", profile_name2); | 1165 "path_2", profile_name2); |
| 1151 EXPECT_EQ(profile_name1, | 1166 EXPECT_EQ(profile_name1, |
| 1152 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1167 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1153 EXPECT_EQ(profile_name2, | 1168 EXPECT_EQ(profile_name2, |
| 1154 profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1169 profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1155 | 1170 |
| 1156 // Deleting a profile means returning to the default name. | 1171 // Deleting a profile means returning to the default name. |
| 1157 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), | 1172 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), |
| 1158 ProfileManager::CreateCallback()); | 1173 ProfileManager::CreateCallback()); |
| 1159 // Spin the message loop so that all the callbacks can finish running. | 1174 // Spin the message loop so that all the callbacks can finish running. |
| 1160 base::RunLoop().RunUntilIdle(); | 1175 base::RunLoop().RunUntilIdle(); |
| 1161 EXPECT_EQ(default_profile_name, | 1176 EXPECT_EQ(default_profile_name, |
| 1162 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1177 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1163 } | 1178 } |
| 1164 | 1179 |
| 1165 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { | 1180 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesCustomName) { |
| 1166 if (!profiles::IsMultipleProfilesEnabled()) | 1181 if (!profiles::IsMultipleProfilesEnabled()) |
| 1167 return; | 1182 return; |
| 1168 | 1183 |
| 1169 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1184 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1170 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1185 ProfileAttributesStorage& storage = |
| 1171 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1186 profile_manager->GetProfileAttributesStorage(); |
| 1187 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1172 | 1188 |
| 1173 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1189 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1174 const base::string16 default_profile_name = | 1190 const base::string16 default_profile_name = |
| 1175 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1191 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 1176 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1192 const base::string16 profile_name1 = storage.ChooseNameForNewProfile(0u); |
| 1177 Profile* profile1 = AddProfileToCache(profile_manager, | 1193 Profile* profile1 = AddProfileToStorage(profile_manager, |
| 1178 "path_1", profile_name1); | 1194 "path_1", profile_name1); |
| 1179 EXPECT_EQ(default_profile_name, | 1195 EXPECT_EQ(default_profile_name, |
| 1180 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1196 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1197 ASSERT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1181 | 1198 |
| 1182 // We should display custom names for local profiles. | 1199 // We should display custom names for local profiles. |
| 1183 const base::string16 custom_profile_name = ASCIIToUTF16("Batman"); | 1200 const base::string16 custom_profile_name = ASCIIToUTF16("Batman"); |
| 1184 cache.SetNameOfProfileAtIndex(0, custom_profile_name); | 1201 ProfileAttributesEntry* entry = storage.GetAllProfilesAttributes()[0u]; |
| 1185 cache.SetProfileIsUsingDefaultNameAtIndex(0, false); | 1202 entry->SetName(custom_profile_name); |
| 1186 EXPECT_EQ(custom_profile_name, cache.GetNameOfProfileAtIndex(0)); | 1203 entry->SetIsUsingDefaultName(false); |
| 1204 EXPECT_EQ(custom_profile_name, entry->GetName()); |
| 1187 EXPECT_EQ(custom_profile_name, | 1205 EXPECT_EQ(custom_profile_name, |
| 1188 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1206 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1189 | 1207 |
| 1190 // Multiple profiles means displaying the actual profile names. | 1208 // Multiple profiles means displaying the actual profile names. |
| 1191 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1209 const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u); |
| 1192 Profile* profile2 = AddProfileToCache(profile_manager, | 1210 Profile* profile2 = AddProfileToStorage(profile_manager, |
| 1193 "path_2", profile_name2); | 1211 "path_2", profile_name2); |
| 1194 EXPECT_EQ(custom_profile_name, | 1212 EXPECT_EQ(custom_profile_name, |
| 1195 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1213 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1196 EXPECT_EQ(profile_name2, | 1214 EXPECT_EQ(profile_name2, |
| 1197 profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1215 profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1198 | 1216 |
| 1199 // Deleting a profile means returning to the original, custom name. | 1217 // Deleting a profile means returning to the original, custom name. |
| 1200 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), | 1218 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), |
| 1201 ProfileManager::CreateCallback()); | 1219 ProfileManager::CreateCallback()); |
| 1202 // Spin the message loop so that all the callbacks can finish running. | 1220 // Spin the message loop so that all the callbacks can finish running. |
| 1203 base::RunLoop().RunUntilIdle(); | 1221 base::RunLoop().RunUntilIdle(); |
| 1204 EXPECT_EQ(custom_profile_name, | 1222 EXPECT_EQ(custom_profile_name, |
| 1205 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1223 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1206 } | 1224 } |
| 1207 | 1225 |
| 1208 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { | 1226 TEST_F(ProfileManagerTest, ProfileDisplayNamePreservesSignedInName) { |
| 1209 if (!profiles::IsMultipleProfilesEnabled()) | 1227 if (!profiles::IsMultipleProfilesEnabled()) |
| 1210 return; | 1228 return; |
| 1211 | 1229 |
| 1212 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1230 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1213 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1231 ProfileAttributesStorage& storage = |
| 1214 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1232 profile_manager->GetProfileAttributesStorage(); |
| 1233 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1215 | 1234 |
| 1216 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1235 // Only one local profile means we display IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1217 const base::string16 default_profile_name = | 1236 const base::string16 default_profile_name = |
| 1218 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); | 1237 l10n_util::GetStringUTF16(IDS_SINGLE_PROFILE_DISPLAY_NAME); |
| 1219 const base::string16 profile_name1 = cache.ChooseNameForNewProfile(0); | 1238 const base::string16 profile_name1 = storage.ChooseNameForNewProfile(0u); |
| 1220 Profile* profile1 = AddProfileToCache(profile_manager, | 1239 Profile* profile1 = AddProfileToStorage(profile_manager, |
| 1221 "path_1", profile_name1); | 1240 "path_1", profile_name1); |
| 1222 EXPECT_EQ(default_profile_name, | 1241 EXPECT_EQ(default_profile_name, |
| 1223 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1242 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1224 | 1243 |
| 1244 ProfileAttributesEntry* entry = storage.GetAllProfilesAttributes()[0u]; |
| 1225 // For a signed in profile with a default name we still display | 1245 // For a signed in profile with a default name we still display |
| 1226 // IDS_SINGLE_PROFILE_DISPLAY_NAME. | 1246 // IDS_SINGLE_PROFILE_DISPLAY_NAME. |
| 1227 cache.SetAuthInfoOfProfileAtIndex(0, "12345", ASCIIToUTF16("user@gmail.com")); | 1247 entry->SetAuthInfo("12345", ASCIIToUTF16("user@gmail.com")); |
| 1228 EXPECT_EQ(profile_name1, cache.GetNameOfProfileAtIndex(0)); | 1248 EXPECT_EQ(profile_name1, entry->GetName()); |
| 1229 EXPECT_EQ(default_profile_name, | 1249 EXPECT_EQ(default_profile_name, |
| 1230 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1250 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1231 | 1251 |
| 1232 // For a signed in profile with a non-default Gaia given name we display the | 1252 // For a signed in profile with a non-default Gaia given name we display the |
| 1233 // Gaia given name. | 1253 // Gaia given name. |
| 1234 cache.SetAuthInfoOfProfileAtIndex(0, "12345", ASCIIToUTF16("user@gmail.com")); | 1254 entry->SetAuthInfo("12345", ASCIIToUTF16("user@gmail.com")); |
| 1235 const base::string16 gaia_given_name(ASCIIToUTF16("given name")); | 1255 const base::string16 gaia_given_name(ASCIIToUTF16("given name")); |
| 1236 cache.SetGAIAGivenNameOfProfileAtIndex(0, gaia_given_name); | 1256 entry->SetGAIAGivenName(gaia_given_name); |
| 1237 EXPECT_EQ(gaia_given_name, cache.GetNameOfProfileAtIndex(0)); | 1257 EXPECT_EQ(gaia_given_name, entry->GetName()); |
| 1238 EXPECT_EQ(gaia_given_name, | 1258 EXPECT_EQ(gaia_given_name, |
| 1239 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1259 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1240 | 1260 |
| 1241 // Multiple profiles means displaying the actual profile names. | 1261 // Multiple profiles means displaying the actual profile names. |
| 1242 const base::string16 profile_name2 = cache.ChooseNameForNewProfile(1); | 1262 const base::string16 profile_name2 = storage.ChooseNameForNewProfile(1u); |
| 1243 Profile* profile2 = AddProfileToCache(profile_manager, | 1263 Profile* profile2 = AddProfileToStorage(profile_manager, |
| 1244 "path_2", profile_name2); | 1264 "path_2", profile_name2); |
| 1245 EXPECT_EQ(gaia_given_name, | 1265 EXPECT_EQ(gaia_given_name, |
| 1246 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1266 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1247 EXPECT_EQ(profile_name2, | 1267 EXPECT_EQ(profile_name2, |
| 1248 profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1268 profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1249 | 1269 |
| 1250 // Deleting a profile means returning to the original, actual profile name. | 1270 // Deleting a profile means returning to the original, actual profile name. |
| 1251 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), | 1271 profile_manager->ScheduleProfileForDeletion(profile2->GetPath(), |
| 1252 ProfileManager::CreateCallback()); | 1272 ProfileManager::CreateCallback()); |
| 1253 // Spin the message loop so that all the callbacks can finish running. | 1273 // Spin the message loop so that all the callbacks can finish running. |
| 1254 base::RunLoop().RunUntilIdle(); | 1274 base::RunLoop().RunUntilIdle(); |
| 1255 EXPECT_EQ(gaia_given_name, | 1275 EXPECT_EQ(gaia_given_name, |
| 1256 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1276 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1257 } | 1277 } |
| 1258 | 1278 |
| 1259 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) { | 1279 TEST_F(ProfileManagerTest, ProfileDisplayNameIsEmailIfDefaultName) { |
| 1260 if (!profiles::IsMultipleProfilesEnabled()) | 1280 if (!profiles::IsMultipleProfilesEnabled()) |
| 1261 return; | 1281 return; |
| 1262 | 1282 |
| 1263 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1283 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1264 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1284 ProfileAttributesStorage& storage = |
| 1265 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 1285 profile_manager->GetProfileAttributesStorage(); |
| 1286 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 1266 | 1287 |
| 1267 // Create two signed in profiles, with both new and legacy default names, and | 1288 // Create two signed in profiles, with both new and legacy default names, and |
| 1268 // a profile with a custom name. | 1289 // a profile with a custom name. |
| 1269 Profile* profile1 = AddProfileToCache( | 1290 Profile* profile1 = AddProfileToStorage(profile_manager, "path_1", |
| 1270 profile_manager, "path_1", ASCIIToUTF16("Person 1")); | 1291 ASCIIToUTF16("Person 1")); |
| 1271 Profile* profile2 = AddProfileToCache( | 1292 Profile* profile2 = AddProfileToStorage(profile_manager, "path_2", |
| 1272 profile_manager, "path_2", ASCIIToUTF16("Default Profile")); | 1293 ASCIIToUTF16("Default Profile")); |
| 1273 const base::string16 profile_name3(ASCIIToUTF16("Batman")); | 1294 const base::string16 profile_name3(ASCIIToUTF16("Batman")); |
| 1274 Profile* profile3 = AddProfileToCache( | 1295 Profile* profile3 = AddProfileToStorage(profile_manager, "path_3", |
| 1275 profile_manager, "path_3", profile_name3); | 1296 profile_name3); |
| 1276 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 1297 EXPECT_EQ(3u, storage.GetNumberOfProfiles()); |
| 1277 | 1298 |
| 1278 // Sign in all profiles, and make sure they do not have a Gaia name set. | 1299 // Sign in all profiles, and make sure they do not have a Gaia name set. |
| 1279 const base::string16 email1(ASCIIToUTF16("user1@gmail.com")); | 1300 const base::string16 email1(ASCIIToUTF16("user1@gmail.com")); |
| 1280 const base::string16 email2(ASCIIToUTF16("user2@gmail.com")); | 1301 const base::string16 email2(ASCIIToUTF16("user2@gmail.com")); |
| 1281 const base::string16 email3(ASCIIToUTF16("user3@gmail.com")); | 1302 const base::string16 email3(ASCIIToUTF16("user3@gmail.com")); |
| 1282 | 1303 |
| 1283 int index = cache.GetIndexOfProfileWithPath(profile1->GetPath()); | 1304 ProfileAttributesEntry* entry; |
| 1284 cache.SetAuthInfoOfProfileAtIndex(index, "12345", email1); | 1305 |
| 1285 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1306 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile1->GetPath(), |
| 1286 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1307 &entry)); |
| 1308 entry->SetAuthInfo("12345", email1); |
| 1309 entry->SetGAIAGivenName(base::string16()); |
| 1310 entry->SetGAIAName(base::string16()); |
| 1287 | 1311 |
| 1288 // This may resort the cache, so be extra cautious to use the right profile. | 1312 // This may resort the cache, so be extra cautious to use the right profile. |
| 1289 index = cache.GetIndexOfProfileWithPath(profile2->GetPath()); | 1313 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile2->GetPath(), |
| 1290 cache.SetAuthInfoOfProfileAtIndex(index, "23456", email2); | 1314 &entry)); |
| 1291 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1315 entry->SetAuthInfo("23456", email2); |
| 1292 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1316 entry->SetGAIAGivenName(base::string16()); |
| 1317 entry->SetGAIAName(base::string16()); |
| 1293 | 1318 |
| 1294 index = cache.GetIndexOfProfileWithPath(profile3->GetPath()); | 1319 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile3->GetPath(), |
| 1295 cache.SetAuthInfoOfProfileAtIndex(index, "34567", email3); | 1320 &entry)); |
| 1296 cache.SetGAIAGivenNameOfProfileAtIndex(index, base::string16()); | 1321 entry->SetAuthInfo("34567", email3); |
| 1297 cache.SetGAIANameOfProfileAtIndex(index, base::string16()); | 1322 entry->SetGAIAGivenName(base::string16()); |
| 1323 entry->SetGAIAName(base::string16()); |
| 1298 | 1324 |
| 1299 // The profiles with default names should display the email address. | 1325 // The profiles with default names should display the email address. |
| 1300 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1326 EXPECT_EQ(email1, profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1301 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath())); | 1327 EXPECT_EQ(email2, profiles::GetAvatarNameForProfile(profile2->GetPath())); |
| 1302 | 1328 |
| 1303 // The profile with the custom name should display that. | 1329 // The profile with the custom name should display that. |
| 1304 EXPECT_EQ(profile_name3, | 1330 EXPECT_EQ(profile_name3, |
| 1305 profiles::GetAvatarNameForProfile(profile3->GetPath())); | 1331 profiles::GetAvatarNameForProfile(profile3->GetPath())); |
| 1306 | 1332 |
| 1307 // Adding a Gaia name to a profile that previously had a default name should | 1333 // Adding a Gaia name to a profile that previously had a default name should |
| 1308 // start displaying it. | 1334 // start displaying it. |
| 1309 const base::string16 gaia_given_name(ASCIIToUTF16("Robin")); | 1335 const base::string16 gaia_given_name(ASCIIToUTF16("Robin")); |
| 1310 cache.SetGAIAGivenNameOfProfileAtIndex( | 1336 ASSERT_TRUE(storage.GetProfileAttributesWithPath(profile1->GetPath(), |
| 1311 cache.GetIndexOfProfileWithPath(profile1->GetPath()), gaia_given_name); | 1337 &entry)); |
| 1338 entry->SetGAIAGivenName(gaia_given_name); |
| 1312 EXPECT_EQ(gaia_given_name, | 1339 EXPECT_EQ(gaia_given_name, |
| 1313 profiles::GetAvatarNameForProfile(profile1->GetPath())); | 1340 profiles::GetAvatarNameForProfile(profile1->GetPath())); |
| 1314 } | 1341 } |
| 1315 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 1342 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 1316 | 1343 |
| 1317 #if defined(OS_MACOSX) | 1344 #if defined(OS_MACOSX) |
| 1318 // These tests are for a Mac-only code path that assumes the browser | 1345 // These tests are for a Mac-only code path that assumes the browser |
| 1319 // process isn't killed when all browser windows are closed. | 1346 // process isn't killed when all browser windows are closed. |
| 1320 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { | 1347 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { |
| 1321 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1348 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1322 ASSERT_TRUE(profile_manager); | 1349 ASSERT_TRUE(profile_manager); |
| 1323 | 1350 |
| 1324 // Create and load one profile, and just create a second profile. | 1351 // Create and load one profile, and just create a second profile. |
| 1325 const std::string profile_name1 = "New Profile 1"; | 1352 const std::string profile_name1 = "New Profile 1"; |
| 1326 const std::string profile_name2 = "New Profile 2"; | 1353 const std::string profile_name2 = "New Profile 2"; |
| 1327 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1354 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
| 1328 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1355 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1329 | 1356 |
| 1330 MockObserver mock_observer; | 1357 MockObserver mock_observer; |
| 1331 EXPECT_CALL(mock_observer, OnProfileCreated( | 1358 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1332 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1359 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1333 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1360 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1334 base::RunLoop().RunUntilIdle(); | 1361 base::RunLoop().RunUntilIdle(); |
| 1335 | 1362 |
| 1336 // Track the profile, but don't load it. | 1363 // Track the profile, but don't load it. |
| 1337 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1364 ProfileAttributesStorage& storage = |
| 1338 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), "23456", | 1365 profile_manager->GetProfileAttributesStorage(); |
| 1339 base::string16(), 0, std::string()); | 1366 storage.AddProfile(dest_path2, ASCIIToUTF16(profile_name2), "23456", |
| 1367 base::string16(), 0, std::string()); |
| 1340 base::RunLoop().RunUntilIdle(); | 1368 base::RunLoop().RunUntilIdle(); |
| 1341 | 1369 |
| 1342 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1370 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1343 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 1371 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 1344 | 1372 |
| 1345 // Set the active profile. | 1373 // Set the active profile. |
| 1346 PrefService* local_state = g_browser_process->local_state(); | 1374 PrefService* local_state = g_browser_process->local_state(); |
| 1347 local_state->SetString(prefs::kProfileLastUsed, | 1375 local_state->SetString(prefs::kProfileLastUsed, |
| 1348 dest_path1.BaseName().MaybeAsASCII()); | 1376 dest_path1.BaseName().MaybeAsASCII()); |
| 1349 | 1377 |
| 1350 // Delete the active profile. This should switch and load the unloaded | 1378 // Delete the active profile. This should switch and load the unloaded |
| 1351 // profile. | 1379 // profile. |
| 1352 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1380 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1353 ProfileManager::CreateCallback()); | 1381 ProfileManager::CreateCallback()); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1375 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1403 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 1376 base::FilePath dest_path3 = temp_dir_.path().AppendASCII(profile_name3); | 1404 base::FilePath dest_path3 = temp_dir_.path().AppendASCII(profile_name3); |
| 1377 | 1405 |
| 1378 MockObserver mock_observer; | 1406 MockObserver mock_observer; |
| 1379 EXPECT_CALL(mock_observer, OnProfileCreated( | 1407 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1380 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1408 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1381 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1409 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1382 base::RunLoop().RunUntilIdle(); | 1410 base::RunLoop().RunUntilIdle(); |
| 1383 | 1411 |
| 1384 // Create the other profiles, but don't load them. Assign a fake avatar icon | 1412 // Create the other profiles, but don't load them. Assign a fake avatar icon |
| 1385 // to ensure that profiles in the info cache are sorted by the profile name, | 1413 // to ensure that profiles in the profile attributes storage are sorted by the |
| 1386 // and not randomly by the avatar name. | 1414 // profile name, and not randomly by the avatar name. |
| 1387 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 1415 ProfileAttributesStorage& storage = |
| 1388 cache.AddProfileToCache(dest_path2, ASCIIToUTF16(profile_name2), | 1416 profile_manager->GetProfileAttributesStorage(); |
| 1389 "23456", ASCIIToUTF16(profile_name2), 1, | 1417 storage.AddProfile(dest_path2, ASCIIToUTF16(profile_name2), "23456", |
| 1390 std::string()); | 1418 ASCIIToUTF16(profile_name2), 1, std::string()); |
| 1391 cache.AddProfileToCache(dest_path3, ASCIIToUTF16(profile_name3), | 1419 storage.AddProfile(dest_path3, ASCIIToUTF16(profile_name3), "34567", |
| 1392 "34567", ASCIIToUTF16(profile_name3), 2, | 1420 ASCIIToUTF16(profile_name3), 2, std::string()); |
| 1393 std::string()); | |
| 1394 | 1421 |
| 1395 base::RunLoop().RunUntilIdle(); | 1422 base::RunLoop().RunUntilIdle(); |
| 1396 | 1423 |
| 1397 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1424 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1398 EXPECT_EQ(3u, cache.GetNumberOfProfiles()); | 1425 EXPECT_EQ(3u, storage.GetNumberOfProfiles()); |
| 1399 | 1426 |
| 1400 // Set the active profile. | 1427 // Set the active profile. |
| 1401 PrefService* local_state = g_browser_process->local_state(); | 1428 PrefService* local_state = g_browser_process->local_state(); |
| 1402 local_state->SetString(prefs::kProfileLastUsed, | 1429 local_state->SetString(prefs::kProfileLastUsed, |
| 1403 dest_path1.BaseName().MaybeAsASCII()); | 1430 dest_path1.BaseName().MaybeAsASCII()); |
| 1404 | 1431 |
| 1405 // Delete the active profile, Profile1. | 1432 // Delete the active profile, Profile1. |
| 1406 // This will post a CreateProfileAsync message, that tries to load Profile2, | 1433 // This will post a CreateProfileAsync message, that tries to load Profile2, |
| 1407 // which checks that the profile is not being deleted, and then calls back | 1434 // which checks that the profile is not being deleted, and then calls back |
| 1408 // FinishDeletingProfile for Profile1. | 1435 // FinishDeletingProfile for Profile1. |
| 1409 // Try to break this flow by setting the active profile to Profile2 in the | 1436 // Try to break this flow by setting the active profile to Profile2 in the |
| 1410 // middle (so after the first posted message), and trying to delete Profile2, | 1437 // middle (so after the first posted message), and trying to delete Profile2, |
| 1411 // so that the ProfileManager has to look for a different profile to load. | 1438 // so that the ProfileManager has to look for a different profile to load. |
| 1412 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1439 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1413 ProfileManager::CreateCallback()); | 1440 ProfileManager::CreateCallback()); |
| 1414 local_state->SetString(prefs::kProfileLastUsed, | 1441 local_state->SetString(prefs::kProfileLastUsed, |
| 1415 dest_path2.BaseName().MaybeAsASCII()); | 1442 dest_path2.BaseName().MaybeAsASCII()); |
| 1416 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1443 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1417 ProfileManager::CreateCallback()); | 1444 ProfileManager::CreateCallback()); |
| 1418 // Spin the message loop so that all the callbacks can finish running. | 1445 // Spin the message loop so that all the callbacks can finish running. |
| 1419 base::RunLoop().RunUntilIdle(); | 1446 base::RunLoop().RunUntilIdle(); |
| 1420 | 1447 |
| 1421 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1448 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1422 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1449 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1423 } | 1450 } |
| 1424 #endif // !defined(OS_MACOSX) | 1451 #endif // !defined(OS_MACOSX) |
| OLD | NEW |