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