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 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 ProfileAttributesStorage& storage = | 171 ProfileAttributesStorage& storage = |
172 profile_manager->GetProfileAttributesStorage(); | 172 profile_manager->GetProfileAttributesStorage(); |
173 size_t num_profiles = storage.GetNumberOfProfiles(); | 173 size_t num_profiles = storage.GetNumberOfProfiles(); |
174 base::FilePath path = temp_dir_.GetPath().AppendASCII(path_suffix); | 174 base::FilePath path = temp_dir_.GetPath().AppendASCII(path_suffix); |
175 storage.AddProfile(path, profile_name, std::string(), base::string16(), 0, | 175 storage.AddProfile(path, profile_name, std::string(), base::string16(), 0, |
176 std::string()); | 176 std::string()); |
177 EXPECT_EQ(num_profiles + 1u, storage.GetNumberOfProfiles()); | 177 EXPECT_EQ(num_profiles + 1u, storage.GetNumberOfProfiles()); |
178 return profile_manager->GetProfile(path); | 178 return profile_manager->GetProfile(path); |
179 } | 179 } |
180 | 180 |
| 181 // Helper function to set profile ephemeral at prefs and attributes storage. |
| 182 void SetProfileEphemeral(Profile* profile) { |
| 183 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); |
| 184 |
| 185 // Update IsEphemeral in attributes storage, normally it happened via |
| 186 // kForceEphemeralProfiles pref change event routed to |
| 187 // ProfileImpl::UpdateIsEphemeralInStorage(). |
| 188 ProfileAttributesEntry* entry; |
| 189 ProfileAttributesStorage& storage = |
| 190 g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| 191 EXPECT_TRUE( |
| 192 storage.GetProfileAttributesWithPath(profile->GetPath(), &entry)); |
| 193 entry->SetIsEphemeral(true); |
| 194 } |
| 195 |
181 #if defined(OS_CHROMEOS) | 196 #if defined(OS_CHROMEOS) |
182 // Helper function to register an user with id |user_id| and create profile | 197 // Helper function to register an user with id |user_id| and create profile |
183 // with a correct path. | 198 // with a correct path. |
184 void RegisterUser(const std::string& user_id) { | 199 void RegisterUser(const std::string& user_id) { |
185 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); | 200 chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); |
186 const std::string user_id_hash = | 201 const std::string user_id_hash = |
187 profile_helper->GetUserIdHashByUserIdForTesting(user_id); | 202 profile_helper->GetUserIdHashByUserIdForTesting(user_id); |
188 user_manager::UserManager::Get()->UserLoggedIn( | 203 user_manager::UserManager::Get()->UserLoggedIn( |
189 AccountId::FromUserEmail(user_id), user_id_hash, false); | 204 AccountId::FromUserEmail(user_id), user_id_hash, false); |
190 g_browser_process->profile_manager()->GetProfile( | 205 g_browser_process->profile_manager()->GetProfile( |
(...skipping 679 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 // There's no Browser object on Android and there's no multi-profiles on Chrome. | 885 // There's no Browser object on Android and there's no multi-profiles on Chrome. |
871 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastProfile) { | 886 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastProfile) { |
872 base::FilePath dest_path = temp_dir_.GetPath(); | 887 base::FilePath dest_path = temp_dir_.GetPath(); |
873 dest_path = dest_path.Append(FILE_PATH_LITERAL("Ephemeral Profile")); | 888 dest_path = dest_path.Append(FILE_PATH_LITERAL("Ephemeral Profile")); |
874 | 889 |
875 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 890 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
876 | 891 |
877 TestingProfile* profile = | 892 TestingProfile* profile = |
878 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); | 893 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); |
879 ASSERT_TRUE(profile); | 894 ASSERT_TRUE(profile); |
880 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); | 895 SetProfileEphemeral(profile); |
881 | 896 |
882 // Here the last used profile is still the "Default" profile. | 897 // Here the last used profile is still the "Default" profile. |
883 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); | 898 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); |
884 EXPECT_NE(profile, last_used_profile); | 899 EXPECT_NE(profile, last_used_profile); |
885 | 900 |
886 // Create a browser for the profile. | 901 // Create a browser for the profile. |
887 Browser::CreateParams profile_params(profile); | 902 Browser::CreateParams profile_params(profile); |
888 std::unique_ptr<Browser> browser( | 903 std::unique_ptr<Browser> browser( |
889 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 904 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
890 last_used_profile = profile_manager->GetLastUsedProfile(); | 905 last_used_profile = profile_manager->GetLastUsedProfile(); |
(...skipping 19 matching lines...) Expand all Loading... |
910 | 925 |
911 // Successfully create the profiles. | 926 // Successfully create the profiles. |
912 TestingProfile* normal_profile = | 927 TestingProfile* normal_profile = |
913 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 928 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
914 ASSERT_TRUE(normal_profile); | 929 ASSERT_TRUE(normal_profile); |
915 | 930 |
916 // Add one ephemeral profile which should not end up in this list. | 931 // Add one ephemeral profile which should not end up in this list. |
917 TestingProfile* ephemeral_profile1 = | 932 TestingProfile* ephemeral_profile1 = |
918 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); | 933 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); |
919 ASSERT_TRUE(ephemeral_profile1); | 934 ASSERT_TRUE(ephemeral_profile1); |
920 ephemeral_profile1->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, | 935 SetProfileEphemeral(ephemeral_profile1); |
921 true); | |
922 | 936 |
923 // Add second ephemeral profile but don't mark it as such yet. | 937 // Add second ephemeral profile but don't mark it as such yet. |
924 TestingProfile* ephemeral_profile2 = | 938 TestingProfile* ephemeral_profile2 = |
925 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path3)); | 939 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path3)); |
926 ASSERT_TRUE(ephemeral_profile2); | 940 ASSERT_TRUE(ephemeral_profile2); |
927 | 941 |
928 // Create a browser for profile1. | 942 // Create a browser for profile1. |
929 Browser::CreateParams profile1_params(normal_profile); | 943 Browser::CreateParams profile1_params(normal_profile); |
930 std::unique_ptr<Browser> browser1( | 944 std::unique_ptr<Browser> browser1( |
931 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); | 945 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); |
932 | 946 |
933 // Create browsers for the ephemeral profile. | 947 // Create browsers for the ephemeral profile. |
934 Browser::CreateParams profile2_params(ephemeral_profile1); | 948 Browser::CreateParams profile2_params(ephemeral_profile1); |
935 std::unique_ptr<Browser> browser2( | 949 std::unique_ptr<Browser> browser2( |
936 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 950 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
937 | 951 |
938 Browser::CreateParams profile3_params(ephemeral_profile2); | 952 Browser::CreateParams profile3_params(ephemeral_profile2); |
939 std::unique_ptr<Browser> browser3( | 953 std::unique_ptr<Browser> browser3( |
940 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); | 954 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); |
941 | 955 |
942 std::vector<Profile*> last_opened_profiles = | 956 std::vector<Profile*> last_opened_profiles = |
943 profile_manager->GetLastOpenedProfiles(); | 957 profile_manager->GetLastOpenedProfiles(); |
944 ASSERT_EQ(2U, last_opened_profiles.size()); | 958 ASSERT_EQ(2U, last_opened_profiles.size()); |
945 EXPECT_EQ(normal_profile, last_opened_profiles[0]); | 959 EXPECT_EQ(normal_profile, last_opened_profiles[0]); |
946 EXPECT_EQ(ephemeral_profile2, last_opened_profiles[1]); | 960 EXPECT_EQ(ephemeral_profile2, last_opened_profiles[1]); |
947 | 961 |
948 // Mark the second profile ephemeral. | 962 // Mark the second profile ephemeral. |
949 ephemeral_profile2->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, | 963 SetProfileEphemeral(ephemeral_profile2); |
950 true); | |
951 | 964 |
952 // Simulate a shutdown. | 965 // Simulate a shutdown. |
953 content::NotificationService::current()->Notify( | 966 content::NotificationService::current()->Notify( |
954 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 967 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
955 content::NotificationService::AllSources(), | 968 content::NotificationService::AllSources(), |
956 content::NotificationService::NoDetails()); | 969 content::NotificationService::NoDetails()); |
957 browser1.reset(); | 970 browser1.reset(); |
958 browser2.reset(); | 971 browser2.reset(); |
959 browser3.reset(); | 972 browser3.reset(); |
960 | 973 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 dest_path2.BaseName().MaybeAsASCII()); | 1455 dest_path2.BaseName().MaybeAsASCII()); |
1443 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1456 profile_manager->ScheduleProfileForDeletion(dest_path2, |
1444 ProfileManager::CreateCallback()); | 1457 ProfileManager::CreateCallback()); |
1445 // Spin the message loop so that all the callbacks can finish running. | 1458 // Spin the message loop so that all the callbacks can finish running. |
1446 base::RunLoop().RunUntilIdle(); | 1459 base::RunLoop().RunUntilIdle(); |
1447 | 1460 |
1448 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1461 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
1449 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1462 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
1450 } | 1463 } |
1451 #endif // !defined(OS_MACOSX) | 1464 #endif // !defined(OS_MACOSX) |
OLD | NEW |