| 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 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 871 // There's no Browser object on Android and there's no multi-profiles on Chrome. | 886 // There's no Browser object on Android and there's no multi-profiles on Chrome. |
| 872 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastProfile) { | 887 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastProfile) { |
| 873 base::FilePath dest_path = temp_dir_.GetPath(); | 888 base::FilePath dest_path = temp_dir_.GetPath(); |
| 874 dest_path = dest_path.Append(FILE_PATH_LITERAL("Ephemeral Profile")); | 889 dest_path = dest_path.Append(FILE_PATH_LITERAL("Ephemeral Profile")); |
| 875 | 890 |
| 876 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 891 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 877 | 892 |
| 878 TestingProfile* profile = | 893 TestingProfile* profile = |
| 879 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); | 894 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); |
| 880 ASSERT_TRUE(profile); | 895 ASSERT_TRUE(profile); |
| 881 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); | 896 SetProfileEphemeral(profile); |
| 882 | 897 |
| 883 // Here the last used profile is still the "Default" profile. | 898 // Here the last used profile is still the "Default" profile. |
| 884 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); | 899 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); |
| 885 EXPECT_NE(profile, last_used_profile); | 900 EXPECT_NE(profile, last_used_profile); |
| 886 | 901 |
| 887 // Create a browser for the profile. | 902 // Create a browser for the profile. |
| 888 Browser::CreateParams profile_params(profile, true); | 903 Browser::CreateParams profile_params(profile, true); |
| 889 std::unique_ptr<Browser> browser( | 904 std::unique_ptr<Browser> browser( |
| 890 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 905 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
| 891 last_used_profile = profile_manager->GetLastUsedProfile(); | 906 last_used_profile = profile_manager->GetLastUsedProfile(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 911 | 926 |
| 912 // Successfully create the profiles. | 927 // Successfully create the profiles. |
| 913 TestingProfile* normal_profile = | 928 TestingProfile* normal_profile = |
| 914 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 929 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 915 ASSERT_TRUE(normal_profile); | 930 ASSERT_TRUE(normal_profile); |
| 916 | 931 |
| 917 // Add one ephemeral profile which should not end up in this list. | 932 // Add one ephemeral profile which should not end up in this list. |
| 918 TestingProfile* ephemeral_profile1 = | 933 TestingProfile* ephemeral_profile1 = |
| 919 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); | 934 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path2)); |
| 920 ASSERT_TRUE(ephemeral_profile1); | 935 ASSERT_TRUE(ephemeral_profile1); |
| 921 ephemeral_profile1->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, | 936 SetProfileEphemeral(ephemeral_profile1); |
| 922 true); | |
| 923 | 937 |
| 924 // Add second ephemeral profile but don't mark it as such yet. | 938 // Add second ephemeral profile but don't mark it as such yet. |
| 925 TestingProfile* ephemeral_profile2 = | 939 TestingProfile* ephemeral_profile2 = |
| 926 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path3)); | 940 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path3)); |
| 927 ASSERT_TRUE(ephemeral_profile2); | 941 ASSERT_TRUE(ephemeral_profile2); |
| 928 | 942 |
| 929 // Create a browser for profile1. | 943 // Create a browser for profile1. |
| 930 Browser::CreateParams profile1_params(normal_profile, true); | 944 Browser::CreateParams profile1_params(normal_profile, true); |
| 931 std::unique_ptr<Browser> browser1( | 945 std::unique_ptr<Browser> browser1( |
| 932 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); | 946 chrome::CreateBrowserWithTestWindowForParams(&profile1_params)); |
| 933 | 947 |
| 934 // Create browsers for the ephemeral profile. | 948 // Create browsers for the ephemeral profile. |
| 935 Browser::CreateParams profile2_params(ephemeral_profile1, true); | 949 Browser::CreateParams profile2_params(ephemeral_profile1, true); |
| 936 std::unique_ptr<Browser> browser2( | 950 std::unique_ptr<Browser> browser2( |
| 937 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); | 951 chrome::CreateBrowserWithTestWindowForParams(&profile2_params)); |
| 938 | 952 |
| 939 Browser::CreateParams profile3_params(ephemeral_profile2, true); | 953 Browser::CreateParams profile3_params(ephemeral_profile2, true); |
| 940 std::unique_ptr<Browser> browser3( | 954 std::unique_ptr<Browser> browser3( |
| 941 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); | 955 chrome::CreateBrowserWithTestWindowForParams(&profile3_params)); |
| 942 | 956 |
| 943 std::vector<Profile*> last_opened_profiles = | 957 std::vector<Profile*> last_opened_profiles = |
| 944 profile_manager->GetLastOpenedProfiles(); | 958 profile_manager->GetLastOpenedProfiles(); |
| 945 ASSERT_EQ(2U, last_opened_profiles.size()); | 959 ASSERT_EQ(2U, last_opened_profiles.size()); |
| 946 EXPECT_EQ(normal_profile, last_opened_profiles[0]); | 960 EXPECT_EQ(normal_profile, last_opened_profiles[0]); |
| 947 EXPECT_EQ(ephemeral_profile2, last_opened_profiles[1]); | 961 EXPECT_EQ(ephemeral_profile2, last_opened_profiles[1]); |
| 948 | 962 |
| 949 // Mark the second profile ephemeral. | 963 // Mark the second profile ephemeral. |
| 950 ephemeral_profile2->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, | 964 SetProfileEphemeral(ephemeral_profile2); |
| 951 true); | |
| 952 | 965 |
| 953 // Simulate a shutdown. | 966 // Simulate a shutdown. |
| 954 content::NotificationService::current()->Notify( | 967 content::NotificationService::current()->Notify( |
| 955 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, | 968 chrome::NOTIFICATION_CLOSE_ALL_BROWSERS_REQUEST, |
| 956 content::NotificationService::AllSources(), | 969 content::NotificationService::AllSources(), |
| 957 content::NotificationService::NoDetails()); | 970 content::NotificationService::NoDetails()); |
| 958 browser1.reset(); | 971 browser1.reset(); |
| 959 browser2.reset(); | 972 browser2.reset(); |
| 960 browser3.reset(); | 973 browser3.reset(); |
| 961 | 974 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 dest_path2.BaseName().MaybeAsASCII()); | 1456 dest_path2.BaseName().MaybeAsASCII()); |
| 1444 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1457 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1445 ProfileManager::CreateCallback()); | 1458 ProfileManager::CreateCallback()); |
| 1446 // Spin the message loop so that all the callbacks can finish running. | 1459 // Spin the message loop so that all the callbacks can finish running. |
| 1447 base::RunLoop().RunUntilIdle(); | 1460 base::RunLoop().RunUntilIdle(); |
| 1448 | 1461 |
| 1449 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1462 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1450 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1463 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1451 } | 1464 } |
| 1452 #endif // !defined(OS_MACOSX) | 1465 #endif // !defined(OS_MACOSX) |
| OLD | NEW |