| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/prefs/pref_service.h" | 6 #include "base/prefs/pref_service.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/profiles/profile_info_cache.h" | 8 #include "chrome/browser/profiles/profile_info_cache.h" |
| 9 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 9 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 EXPECT_EQ(profile_manager->GetNumberOfProfiles(), 2U); | 174 EXPECT_EQ(profile_manager->GetNumberOfProfiles(), 2U); |
| 175 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | 175 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
| 176 | 176 |
| 177 // Now close all browser windows. | 177 // Now close all browser windows. |
| 178 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 178 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 179 for (std::vector<Profile*>::const_iterator it = profiles.begin(); | 179 for (std::vector<Profile*>::const_iterator it = profiles.begin(); |
| 180 it != profiles.end(); ++it) { | 180 it != profiles.end(); ++it) { |
| 181 BrowserList::CloseAllBrowsersWithProfile(*it); | 181 BrowserList::CloseAllBrowsersWithProfile(*it); |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 |
| 185 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, |
| 186 SwitchToProfile) { |
| 187 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 188 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 189 base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); |
| 190 |
| 191 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); |
| 192 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| 193 |
| 194 // Create an additional profile. |
| 195 base::FilePath path_profile2 = |
| 196 profile_manager->GenerateNextProfileDirectoryPath(); |
| 197 profile_manager->CreateProfileAsync(path_profile2, |
| 198 base::Bind(&OnUnblockOnProfileCreation), |
| 199 string16(), string16(), false); |
| 200 |
| 201 // Spin to allow profile creation to take place, loop is terminated |
| 202 // by OnUnblockOnProfileCreation when the profile is created. |
| 203 content::RunMessageLoop(); |
| 204 |
| 205 chrome::HostDesktopType desktop_type = chrome::HOST_DESKTOP_TYPE_NATIVE; |
| 206 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); |
| 207 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); |
| 208 EXPECT_EQ(1U, browser_list->size()); |
| 209 |
| 210 // Open a browser window for the first profile. |
| 211 ProfileManager::SwitchToProfile(path_profile1, desktop_type, false); |
| 212 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| 213 EXPECT_EQ(1U, browser_list->size()); |
| 214 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 215 |
| 216 // Open a browser window for the second profile. |
| 217 ProfileManager::SwitchToProfile(path_profile2, desktop_type, false); |
| 218 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
| 219 EXPECT_EQ(2U, browser_list->size()); |
| 220 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 221 |
| 222 // Switch to the first profile without opening a new window. |
| 223 ProfileManager::SwitchToProfile(path_profile1, desktop_type, false); |
| 224 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
| 225 EXPECT_EQ(2U, browser_list->size()); |
| 226 |
| 227 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 228 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 229 |
| 230 } |
| OLD | NEW |