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

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

Issue 1113333003: Don't create a new profile when cleaning up stale ephemeral profiles. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: fix Created 5 years, 7 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
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/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 content::NotificationService::NoDetails()); 869 content::NotificationService::NoDetails());
870 browser1.reset(); 870 browser1.reset();
871 browser2.reset(); 871 browser2.reset();
872 browser3.reset(); 872 browser3.reset();
873 873
874 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); 874 last_opened_profiles = profile_manager->GetLastOpenedProfiles();
875 ASSERT_EQ(1U, last_opened_profiles.size()); 875 ASSERT_EQ(1U, last_opened_profiles.size());
876 EXPECT_EQ(normal_profile, last_opened_profiles[0]); 876 EXPECT_EQ(normal_profile, last_opened_profiles[0]);
877 } 877 }
878 878
879 TEST_F(ProfileManagerTest, CleanUpEphemeralProfiles) {
880 // Create two profiles, one of them ephemeral.
881 ProfileManager* profile_manager = g_browser_process->profile_manager();
882 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache();
883 ASSERT_EQ(0u, cache.GetNumberOfProfiles());
884
885 const std::string profile_name1 = "Homer";
886 base::FilePath path1 = temp_dir_.path().AppendASCII(profile_name1);
887 cache.AddProfileToCache(path1, base::UTF8ToUTF16(profile_name1),
888 std::string(), base::UTF8ToUTF16(profile_name1), 0,
889 std::string());
890 cache.SetProfileIsEphemeralAtIndex(0, true);
891 ASSERT_TRUE(base::CreateDirectory(path1));
892
893 const std::string profile_name2 = "Marge";
894 base::FilePath path2 = temp_dir_.path().AppendASCII(profile_name2);
895 cache.AddProfileToCache(path2, base::UTF8ToUTF16(profile_name2),
896 std::string(), base::UTF8ToUTF16(profile_name2), 0,
897 std::string());
898 ASSERT_EQ(2u, cache.GetNumberOfProfiles());
899 ASSERT_TRUE(base::CreateDirectory(path2));
900
901 // Set the active profile.
902 PrefService* local_state = g_browser_process->local_state();
903 local_state->SetString(prefs::kProfileLastUsed, profile_name1);
904
905 profile_manager->CleanUpEphemeralProfiles();
906 base::RunLoop().RunUntilIdle();
907
908 // The ephemeral profile should be deleted, and the last used profile set to
909 // the other one.
910 EXPECT_FALSE(base::DirectoryExists(path1));
911 EXPECT_TRUE(base::DirectoryExists(path2));
912 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed));
913 ASSERT_EQ(1u, cache.GetNumberOfProfiles());
914
915 // Mark the remaining profile ephemeral and clean up.
916 cache.SetProfileIsEphemeralAtIndex(0, true);
917 profile_manager->CleanUpEphemeralProfiles();
918 base::RunLoop().RunUntilIdle();
919
920 // The profile should be deleted, and the last used profile set to a new one.
921 EXPECT_FALSE(base::DirectoryExists(path2));
922 EXPECT_EQ(0u, cache.GetNumberOfProfiles());
923 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed));
924 }
925
879 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { 926 TEST_F(ProfileManagerTest, ActiveProfileDeleted) {
880 ProfileManager* profile_manager = g_browser_process->profile_manager(); 927 ProfileManager* profile_manager = g_browser_process->profile_manager();
881 ASSERT_TRUE(profile_manager); 928 ASSERT_TRUE(profile_manager);
882 929
883 // Create and load two profiles. 930 // Create and load two profiles.
884 const std::string profile_name1 = "New Profile 1"; 931 const std::string profile_name1 = "New Profile 1";
885 const std::string profile_name2 = "New Profile 2"; 932 const std::string profile_name2 = "New Profile 2";
886 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); 933 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1);
887 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); 934 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2);
888 935
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 dest_path2.BaseName().MaybeAsASCII()); 1354 dest_path2.BaseName().MaybeAsASCII());
1308 profile_manager->ScheduleProfileForDeletion(dest_path2, 1355 profile_manager->ScheduleProfileForDeletion(dest_path2,
1309 ProfileManager::CreateCallback()); 1356 ProfileManager::CreateCallback());
1310 // Spin the message loop so that all the callbacks can finish running. 1357 // Spin the message loop so that all the callbacks can finish running.
1311 base::RunLoop().RunUntilIdle(); 1358 base::RunLoop().RunUntilIdle();
1312 1359
1313 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); 1360 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath());
1314 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); 1361 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed));
1315 } 1362 }
1316 #endif // !defined(OS_MACOSX) 1363 #endif // !defined(OS_MACOSX)
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | chrome/browser/ui/app_list/app_list_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698