| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/profiles/profile_info_cache.h" | 6 #include "chrome/browser/profiles/profile_info_cache.h" |
| 6 #include "chrome/browser/profiles/profile_manager.h" | 7 #include "chrome/browser/profiles/profile_manager.h" |
| 7 #include "chrome/test/base/in_process_browser_test.h" | 8 #include "chrome/test/base/in_process_browser_test.h" |
| 8 #include "chrome/test/base/testing_browser_process.h" | 9 #include "chrome/test/base/testing_browser_process.h" |
| 9 #include "chrome/test/base/ui_test_utils.h" | 10 #include "chrome/test/base/ui_test_utils.h" |
| 10 | 11 |
| 12 namespace { |
| 13 |
| 14 // An observer that returns back to test code after a new profile is |
| 15 // initialized. |
| 16 void OnUnblockOnProfileCreation(Profile* profile, |
| 17 Profile::CreateStatus status) { |
| 18 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| 19 MessageLoop::current()->Quit(); |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 11 // This file contains tests for the ProfileManager that require a heavyweight | 24 // This file contains tests for the ProfileManager that require a heavyweight |
| 12 // InProcessBrowserTest. These include tests involving profile deletion. | 25 // InProcessBrowserTest. These include tests involving profile deletion. |
| 13 | 26 |
| 14 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all | 27 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all |
| 15 // platforms. | 28 // platforms. |
| 16 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
| 17 class ProfileManagerBrowserTest : public InProcessBrowserTest { | 30 class ProfileManagerBrowserTest : public InProcessBrowserTest { |
| 18 protected: | |
| 19 // An observer that returns back to test code after a new profile | |
| 20 // is initialized. | |
| 21 class BlockOnProfileInitObserver : public ProfileManagerObserver { | |
| 22 public: | |
| 23 void OnProfileCreated(Profile* profile, Status status) { | |
| 24 if (status == ProfileManagerObserver::STATUS_INITIALIZED) { | |
| 25 MessageLoop::current()->Quit(); | |
| 26 } | |
| 27 } | |
| 28 }; | |
| 29 }; | 31 }; |
| 30 | 32 |
| 31 // Delete single profile and make sure a new one is created. | 33 // Delete single profile and make sure a new one is created. |
| 32 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { | 34 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { |
| 33 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 35 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 34 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 36 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 35 | 37 |
| 36 // We should start out with 1 profile. | 38 // We should start out with 1 profile. |
| 37 ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); | 39 ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); |
| 38 | 40 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 #define MAYBE_DeleteAllProfiles DISABLED_DeleteAllProfiles | 64 #define MAYBE_DeleteAllProfiles DISABLED_DeleteAllProfiles |
| 63 #else | 65 #else |
| 64 #define MAYBE_DeleteAllProfiles DeleteAllProfiles | 66 #define MAYBE_DeleteAllProfiles DeleteAllProfiles |
| 65 #endif | 67 #endif |
| 66 | 68 |
| 67 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_DeleteAllProfiles) { | 69 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_DeleteAllProfiles) { |
| 68 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 70 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 69 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 71 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 70 | 72 |
| 71 // Create an additional profile. | 73 // Create an additional profile. |
| 72 BlockOnProfileInitObserver observer; | |
| 73 FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 74 FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
| 74 profile_manager->CreateProfileAsync(new_path, &observer); | 75 profile_manager->CreateProfileAsync(new_path, |
| 76 base::Bind(&OnUnblockOnProfileCreation)); |
| 75 | 77 |
| 76 // Spin to allow profile creation to take place, loop is terminated | 78 // Spin to allow profile creation to take place, loop is terminated |
| 77 // by BlockOnProfileInitObserver when the profile is created. | 79 // by OnUnblockOnProfileCreation when the profile is created. |
| 78 ui_test_utils::RunMessageLoop(); | 80 ui_test_utils::RunMessageLoop(); |
| 79 | 81 |
| 80 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); | 82 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); |
| 81 | 83 |
| 82 // Delete all profiles. | 84 // Delete all profiles. |
| 83 FilePath profile_path1 = cache.GetPathOfProfileAtIndex(0); | 85 FilePath profile_path1 = cache.GetPathOfProfileAtIndex(0); |
| 84 FilePath profile_path2 = cache.GetPathOfProfileAtIndex(1); | 86 FilePath profile_path2 = cache.GetPathOfProfileAtIndex(1); |
| 85 EXPECT_FALSE(profile_path1.empty()); | 87 EXPECT_FALSE(profile_path1.empty()); |
| 86 EXPECT_FALSE(profile_path2.empty()); | 88 EXPECT_FALSE(profile_path2.empty()); |
| 87 profile_manager->ScheduleProfileForDeletion(profile_path1); | 89 profile_manager->ScheduleProfileForDeletion(profile_path1); |
| 88 profile_manager->ScheduleProfileForDeletion(profile_path2); | 90 profile_manager->ScheduleProfileForDeletion(profile_path2); |
| 89 | 91 |
| 90 // Spin things so deletion can take place. | 92 // Spin things so deletion can take place. |
| 91 ui_test_utils::RunAllPendingInMessageLoop(); | 93 ui_test_utils::RunAllPendingInMessageLoop(); |
| 92 | 94 |
| 93 // Make sure a new profile was created automatically. | 95 // Make sure a new profile was created automatically. |
| 94 EXPECT_EQ(cache.GetNumberOfProfiles(), 1U); | 96 EXPECT_EQ(cache.GetNumberOfProfiles(), 1U); |
| 95 FilePath new_profile_path = cache.GetPathOfProfileAtIndex(0); | 97 FilePath new_profile_path = cache.GetPathOfProfileAtIndex(0); |
| 96 EXPECT_NE(new_profile_path, profile_path1); | 98 EXPECT_NE(new_profile_path, profile_path1); |
| 97 EXPECT_NE(new_profile_path, profile_path2); | 99 EXPECT_NE(new_profile_path, profile_path2); |
| 98 | 100 |
| 99 // Make sure that last used profile preference is set correctly. | 101 // Make sure that last used profile preference is set correctly. |
| 100 Profile* last_used = ProfileManager::GetLastUsedProfile(); | 102 Profile* last_used = ProfileManager::GetLastUsedProfile(); |
| 101 EXPECT_EQ(new_profile_path, last_used->GetPath()); | 103 EXPECT_EQ(new_profile_path, last_used->GetPath()); |
| 102 } | 104 } |
| 103 #endif // OS_MACOSX | 105 #endif // OS_MACOSX |
| OLD | NEW |