Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 396773002: [Profiles] Create a profile moar better after deleting the only existing profile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: undo changes to TestingProfile because they broke everything Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 5 #include <string>
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after
879 // Delete the active profile. 879 // Delete the active profile.
880 profile_manager->ScheduleProfileForDeletion(dest_path1, 880 profile_manager->ScheduleProfileForDeletion(dest_path1,
881 ProfileManager::CreateCallback()); 881 ProfileManager::CreateCallback());
882 // Spin the message loop so that all the callbacks can finish running. 882 // Spin the message loop so that all the callbacks can finish running.
883 base::RunLoop().RunUntilIdle(); 883 base::RunLoop().RunUntilIdle();
884 884
885 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); 885 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath());
886 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); 886 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
887 } 887 }
888 888
889 TEST_F(ProfileManagerTest, LastProfileDeleted) {
890 ProfileManager* profile_manager = g_browser_process->profile_manager();
891 ASSERT_TRUE(profile_manager);
892
893 // Create and load a profile.
894 const std::string profile_name1 = "New Profile 1";
895 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1);
896
897 MockObserver mock_observer;
898 EXPECT_CALL(mock_observer, OnProfileCreated(
899 testing::NotNull(), NotFail())).Times(testing::AtLeast(1));
900
901 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer);
902 base::RunLoop().RunUntilIdle();
903
904 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size());
905 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
906
907 // Set it as the active profile.
908 PrefService* local_state = g_browser_process->local_state();
909 local_state->SetString(prefs::kProfileLastUsed, profile_name1);
910
911 // Delete the active profile.
912 profile_manager->ScheduleProfileForDeletion(dest_path1,
913 ProfileManager::CreateCallback());
914 // Spin the message loop so that all the callbacks can finish running.
915 base::RunLoop().RunUntilIdle();
916
917 // A new profile should have been created
918 const std::string profile_name2 = "Profile 1";
919 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2);
920
921 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath());
922 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
923 EXPECT_EQ(dest_path2,
924 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0));
925 }
926
927 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) {
928 ProfileManager* profile_manager = g_browser_process->profile_manager();
929 ASSERT_TRUE(profile_manager);
930
931 // Create and load a profile.
932 const std::string profile_name1 = "New Profile 1";
933 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1);
934
935 MockObserver mock_observer;
936 EXPECT_CALL(mock_observer, OnProfileCreated(
937 testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
938
939 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer);
940 base::RunLoop().RunUntilIdle();
941
942 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size());
943 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
944
945 // Create the profile and register it.
946 const std::string guest_profile_name =
947 ProfileManager::GetGuestProfilePath().BaseName().MaybeAsASCII();
948
949 TestingProfile::Builder builder;
950 builder.SetGuestSession();
951 builder.SetPath(ProfileManager::GetGuestProfilePath());
952 TestingProfile* guest_profile = builder.Build().release();
953 guest_profile->set_profile_name(guest_profile_name);
954 // Registering the profile passes ownership to the ProfileManager.
955 profile_manager->RegisterTestingProfile(guest_profile, false, false);
956
957 // The Guest profile does not get added to the ProfileInfoCache.
958 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size());
959 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
960
961 // Set the Guest profile as the active profile.
962 PrefService* local_state = g_browser_process->local_state();
963 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name);
964
965 // Delete the other profile.
966 profile_manager->ScheduleProfileForDeletion(dest_path1,
967 ProfileManager::CreateCallback());
968 // Spin the message loop so that all the callbacks can finish running.
969 base::RunLoop().RunUntilIdle();
970
971 // A new profile should have been created.
972 const std::string profile_name2 = "Profile 1";
973 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2);
974
975 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size());
976 EXPECT_EQ(1u, profile_manager->GetProfileInfoCache().GetNumberOfProfiles());
977 EXPECT_EQ(dest_path2,
978 profile_manager->GetProfileInfoCache().GetPathOfProfileAtIndex(0));
979 }
980
889 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { 981 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) {
890 if (!profiles::IsMultipleProfilesEnabled()) 982 if (!profiles::IsMultipleProfilesEnabled())
891 return; 983 return;
892 984
893 // The command line is reset at the end of every test by the test suite. 985 // The command line is reset at the end of every test by the test suite.
894 switches::EnableNewProfileManagementForTesting( 986 switches::EnableNewProfileManagementForTesting(
895 CommandLine::ForCurrentProcess()); 987 CommandLine::ForCurrentProcess());
896 988
897 ProfileManager* profile_manager = g_browser_process->profile_manager(); 989 ProfileManager* profile_manager = g_browser_process->profile_manager();
898 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); 990 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 dest_path2.BaseName().MaybeAsASCII()); 1208 dest_path2.BaseName().MaybeAsASCII());
1117 profile_manager->ScheduleProfileForDeletion(dest_path2, 1209 profile_manager->ScheduleProfileForDeletion(dest_path2,
1118 ProfileManager::CreateCallback()); 1210 ProfileManager::CreateCallback());
1119 // Spin the message loop so that all the callbacks can finish running. 1211 // Spin the message loop so that all the callbacks can finish running.
1120 base::RunLoop().RunUntilIdle(); 1212 base::RunLoop().RunUntilIdle();
1121 1213
1122 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 1214 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
1123 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 1215 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
1124 } 1216 }
1125 #endif // !defined(OS_MACOSX) 1217 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698