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 <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 Loading... |
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 base::UTF8ToUTF16(profile_name1), 0, std::string()); |
| 889 cache.SetProfileIsEphemeralAtIndex(0, true); |
| 890 ASSERT_TRUE(base::CreateDirectory(path1)); |
| 891 |
| 892 const std::string profile_name2 = "Marge"; |
| 893 base::FilePath path2 = temp_dir_.path().AppendASCII(profile_name2); |
| 894 cache.AddProfileToCache(path2, base::UTF8ToUTF16(profile_name2), |
| 895 base::UTF8ToUTF16(profile_name2), 0, std::string()); |
| 896 ASSERT_EQ(2u, cache.GetNumberOfProfiles()); |
| 897 ASSERT_TRUE(base::CreateDirectory(path2)); |
| 898 |
| 899 // Set the active profile. |
| 900 PrefService* local_state = g_browser_process->local_state(); |
| 901 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 902 |
| 903 profile_manager->CleanUpEphemeralProfiles(); |
| 904 base::RunLoop().RunUntilIdle(); |
| 905 |
| 906 // The ephemeral profile should be deleted, and the last used profile set to |
| 907 // the other one. |
| 908 EXPECT_FALSE(base::DirectoryExists(path1)); |
| 909 EXPECT_TRUE(base::DirectoryExists(path2)); |
| 910 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 911 ASSERT_EQ(1u, cache.GetNumberOfProfiles()); |
| 912 |
| 913 // Mark the remaining profile ephemeral and clean up. |
| 914 cache.SetProfileIsEphemeralAtIndex(0, true); |
| 915 profile_manager->CleanUpEphemeralProfiles(); |
| 916 base::RunLoop().RunUntilIdle(); |
| 917 |
| 918 // The profile should be deleted, and the last used profile set to a new one. |
| 919 EXPECT_FALSE(base::DirectoryExists(path2)); |
| 920 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
| 921 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); |
| 922 } |
| 923 |
879 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { | 924 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { |
880 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 925 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
881 ASSERT_TRUE(profile_manager); | 926 ASSERT_TRUE(profile_manager); |
882 | 927 |
883 // Create and load two profiles. | 928 // Create and load two profiles. |
884 const std::string profile_name1 = "New Profile 1"; | 929 const std::string profile_name1 = "New Profile 1"; |
885 const std::string profile_name2 = "New Profile 2"; | 930 const std::string profile_name2 = "New Profile 2"; |
886 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 931 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); |
887 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 932 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); |
888 | 933 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 dest_path2.BaseName().MaybeAsASCII()); | 1350 dest_path2.BaseName().MaybeAsASCII()); |
1306 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1351 profile_manager->ScheduleProfileForDeletion(dest_path2, |
1307 ProfileManager::CreateCallback()); | 1352 ProfileManager::CreateCallback()); |
1308 // Spin the message loop so that all the callbacks can finish running. | 1353 // Spin the message loop so that all the callbacks can finish running. |
1309 base::RunLoop().RunUntilIdle(); | 1354 base::RunLoop().RunUntilIdle(); |
1310 | 1355 |
1311 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1356 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
1312 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1357 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
1313 } | 1358 } |
1314 #endif // !defined(OS_MACOSX) | 1359 #endif // !defined(OS_MACOSX) |
OLD | NEW |