Chromium Code Reviews| 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/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/prefs/pref_service.h" | 7 #include "base/prefs/pref_service.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile_info_cache.h" | 9 #include "chrome/browser/profiles/profile_info_cache.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 10 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/profiles/profile_window.h" | 12 #include "chrome/browser/profiles/profile_window.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | |
| 16 #include "chrome/browser/ui/host_desktop.h" | 17 #include "chrome/browser/ui/host_desktop.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 19 #include "chrome/test/base/test_switches.h" | 20 #include "chrome/test/base/test_switches.h" |
| 20 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 21 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 // An observer that returns back to test code after a new profile is | 26 // An observer that returns back to test code after a new profile is |
| 26 // initialized. | 27 // initialized. |
| 27 void OnUnblockOnProfileCreation(Profile* profile, | 28 void OnUnblockOnProfileCreation(Profile* profile, |
| 28 Profile::CreateStatus status) { | 29 Profile::CreateStatus status) { |
| 29 if (status == Profile::CREATE_STATUS_INITIALIZED) | 30 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 30 base::MessageLoop::current()->Quit(); | 31 base::MessageLoop::current()->Quit(); |
| 31 } | 32 } |
| 32 | 33 |
| 33 void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { | 34 void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { |
| 34 ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL); | 35 ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL); |
| 35 ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL); | 36 ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL); |
| 36 // No browser should have been created for this profile yet. | 37 // No browser should have been created for this profile yet. |
| 37 EXPECT_EQ(chrome::GetTotalBrowserCountForProfile(profile), 0U); | 38 EXPECT_EQ(chrome::GetTotalBrowserCountForProfile(profile), 0U); |
| 38 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 39 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| 39 if (status == Profile::CREATE_STATUS_INITIALIZED) | 40 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 40 base::MessageLoop::current()->Quit(); | 41 base::MessageLoop::current()->Quit(); |
| 41 } | 42 } |
| 42 | 43 |
| 44 void EphemeralProfileCreationComplete(Profile* profile, | |
| 45 Profile::CreateStatus status) { | |
| 46 ProfileCreationComplete(profile, status); | |
| 47 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); | |
| 48 } | |
| 49 | |
| 43 class ProfileRemovalObserver : public ProfileInfoCacheObserver { | 50 class ProfileRemovalObserver : public ProfileInfoCacheObserver { |
| 44 public: | 51 public: |
| 45 ProfileRemovalObserver() { | 52 ProfileRemovalObserver() { |
| 46 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver( | 53 g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver( |
| 47 this); | 54 this); |
| 48 } | 55 } |
| 49 | 56 |
| 50 virtual ~ProfileRemovalObserver() { | 57 virtual ~ProfileRemovalObserver() { |
| 51 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( | 58 g_browser_process->profile_manager()->GetProfileInfoCache().RemoveObserver( |
| 52 this); | 59 this); |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 233 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 240 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 234 | 241 |
| 235 // Switch to the first profile without opening a new window. | 242 // Switch to the first profile without opening a new window. |
| 236 profiles::SwitchToProfile(path_profile1, desktop_type, false); | 243 profiles::SwitchToProfile(path_profile1, desktop_type, false); |
| 237 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | 244 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
| 238 EXPECT_EQ(2U, browser_list->size()); | 245 EXPECT_EQ(2U, browser_list->size()); |
| 239 | 246 |
| 240 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 247 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 241 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 248 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 242 } | 249 } |
| 250 | |
| 251 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, EphemeralProfile) { | |
| 252 #if defined(OS_WIN) && defined(USE_ASH) | |
| 253 // Disable this test in Metro+Ash for now (http://crbug.com/262796). | |
| 254 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kAshBrowserTests)) | |
| 255 return; | |
| 256 #endif | |
| 257 | |
| 258 // If multiprofile mode is not enabled, you can't switch between profiles. | |
| 259 if (!profiles::IsMultipleProfilesEnabled()) | |
|
rpetterson
2013/10/04 19:42:20
When would you not have multi profiles enabled? I
pastarmovj
2013/10/10 11:46:32
TBH I just copied this check from the other tests
rpetterson
2013/10/10 17:40:19
Got it. That makes sense.
| |
| 260 return; | |
| 261 | |
| 262 ProfileManager* profile_manager = g_browser_process->profile_manager(); | |
| 263 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | |
| 264 base::FilePath path_profile1 = cache.GetPathOfProfileAtIndex(0); | |
| 265 | |
| 266 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); | |
| 267 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | |
| 268 | |
| 269 // Create an ephemeral profile. | |
| 270 base::FilePath path_profile2 = | |
| 271 profile_manager->GenerateNextProfileDirectoryPath(); | |
| 272 profile_manager->CreateProfileAsync( | |
| 273 path_profile2, | |
| 274 base::Bind(&EphemeralProfileCreationComplete), | |
| 275 string16(), string16(), std::string()); | |
| 276 | |
| 277 // Spin to allow profile creation to take place. | |
| 278 content::RunMessageLoop(); | |
| 279 | |
| 280 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | |
| 281 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); | |
| 282 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); | |
| 283 EXPECT_EQ(1U, browser_list->size()); | |
| 284 | |
| 285 // Open a browser window for the second profile. | |
| 286 profiles::SwitchToProfile(path_profile2, desktop_type, false); | |
| 287 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | |
| 288 EXPECT_EQ(2U, browser_list->size()); | |
| 289 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | |
| 290 | |
| 291 // Create a second window for the ephemeral profile. | |
| 292 profiles::SwitchToProfile(path_profile2, desktop_type, true); | |
| 293 EXPECT_EQ(chrome::GetTotalBrowserCount(), 3U); | |
| 294 EXPECT_EQ(3U, browser_list->size()); | |
| 295 | |
| 296 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | |
| 297 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | |
|
rpetterson
2013/10/04 19:42:20
You did this check earlier. Did you mean to check
pastarmovj
2013/10/10 11:46:32
Done.
| |
| 298 | |
| 299 // Closing the first window of the ephemeral profile should not delete it. | |
| 300 browser_list->GetLastActive()->window()->Close(); | |
| 301 content::RunAllPendingInMessageLoop(); | |
| 302 EXPECT_EQ(2U, browser_list->size()); | |
| 303 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); | |
| 304 | |
| 305 // The second should though. | |
| 306 browser_list->GetLastActive()->window()->Close(); | |
| 307 content::RunAllPendingInMessageLoop(); | |
| 308 EXPECT_EQ(1U, browser_list->size()); | |
| 309 ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); | |
| 310 | |
| 311 // Closing the last window should not reduce the number of profiles. | |
| 312 browser_list->GetLastActive()->window()->Close(); | |
| 313 content::RunAllPendingInMessageLoop(); | |
| 314 EXPECT_EQ(0U, browser_list->size()); | |
| 315 ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); | |
| 316 } | |
| OLD | NEW |