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/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
10 #include "chrome/browser/profiles/profile_info_cache.h" | 10 #include "chrome/browser/profiles/profile_info_cache.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
35 #endif | 35 #endif |
36 | 36 |
37 namespace { | 37 namespace { |
38 | 38 |
39 const ProfileManager::CreateCallback kOnProfileSwitchDoNothing; | 39 const ProfileManager::CreateCallback kOnProfileSwitchDoNothing; |
40 | 40 |
41 // An observer that returns back to test code after a new profile is | 41 // An observer that returns back to test code after a new profile is |
42 // initialized. | 42 // initialized. |
43 void OnUnblockOnProfileCreation(Profile* profile, | 43 void OnUnblockOnProfileCreation(base::RunLoop* run_loop, |
| 44 Profile* profile, |
44 Profile::CreateStatus status) { | 45 Profile::CreateStatus status) { |
45 if (status == Profile::CREATE_STATUS_INITIALIZED) | 46 if (status == Profile::CREATE_STATUS_INITIALIZED) |
46 base::MessageLoop::current()->Quit(); | 47 run_loop->Quit(); |
47 } | 48 } |
48 | 49 |
49 void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { | 50 void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { |
50 ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL); | 51 ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL); |
51 ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL); | 52 ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL); |
52 // No browser should have been created for this profile yet. | 53 // No browser should have been created for this profile yet. |
53 EXPECT_EQ(chrome::GetTotalBrowserCountForProfile(profile), 0U); | 54 EXPECT_EQ(chrome::GetTotalBrowserCountForProfile(profile), 0U); |
54 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 55 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
55 if (status == Profile::CREATE_STATUS_INITIALIZED) | 56 if (status == Profile::CREATE_STATUS_INITIALIZED) |
56 base::MessageLoop::current()->Quit(); | 57 base::MessageLoop::current()->Quit(); |
(...skipping 27 matching lines...) Expand all Loading... |
84 } | 85 } |
85 | 86 |
86 private: | 87 private: |
87 std::string last_used_profile_name_; | 88 std::string last_used_profile_name_; |
88 | 89 |
89 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); | 90 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); |
90 }; | 91 }; |
91 | 92 |
92 // The class serves to retrieve passwords from PasswordStore asynchronously. It | 93 // The class serves to retrieve passwords from PasswordStore asynchronously. It |
93 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms. | 94 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms. |
94 class PasswordStoreConsumerVerifier : | 95 class PasswordStoreConsumerVerifier |
95 public password_manager::PasswordStoreConsumer { | 96 : public password_manager::PasswordStoreConsumer { |
96 public: | 97 public: |
97 PasswordStoreConsumerVerifier() : called_(false) {} | |
98 | |
99 void OnGetPasswordStoreResults( | 98 void OnGetPasswordStoreResults( |
100 ScopedVector<autofill::PasswordForm> results) override { | 99 ScopedVector<autofill::PasswordForm> results) override { |
101 EXPECT_FALSE(called_); | |
102 called_ = true; | |
103 password_entries_.swap(results); | 100 password_entries_.swap(results); |
| 101 run_loop_.Quit(); |
104 } | 102 } |
105 | 103 |
106 bool IsCalled() const { return called_; } | 104 void Wait() { |
| 105 run_loop_.Run(); |
| 106 } |
107 | 107 |
108 const std::vector<autofill::PasswordForm*>& GetPasswords() const { | 108 const std::vector<autofill::PasswordForm*>& GetPasswords() const { |
109 return password_entries_.get(); | 109 return password_entries_.get(); |
110 } | 110 } |
| 111 |
111 private: | 112 private: |
| 113 base::RunLoop run_loop_; |
112 ScopedVector<autofill::PasswordForm> password_entries_; | 114 ScopedVector<autofill::PasswordForm> password_entries_; |
113 bool called_; | |
114 }; | 115 }; |
115 | 116 |
116 static base::FilePath GetFirstNonSigninProfile(const ProfileInfoCache& cache) { | 117 static base::FilePath GetFirstNonSigninProfile(const ProfileInfoCache& cache) { |
117 #if defined(OS_CHROMEOS) | 118 #if defined(OS_CHROMEOS) |
118 const base::FilePath signin_path = | 119 const base::FilePath signin_path = |
119 chromeos::ProfileHelper::GetSigninProfileDir(); | 120 chromeos::ProfileHelper::GetSigninProfileDir(); |
120 size_t i, profile_num = cache.GetNumberOfProfiles(); | 121 size_t i, profile_num = cache.GetNumberOfProfiles(); |
121 for (i = 0; i != profile_num; ++i) { | 122 for (i = 0; i != profile_num; ++i) { |
122 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i); | 123 base::FilePath profile_path = cache.GetPathOfProfileAtIndex(i); |
123 if (profile_path != signin_path) | 124 if (profile_path != signin_path) |
(...skipping 29 matching lines...) Expand all Loading... |
153 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 154 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
154 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 155 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
155 ProfileRemovalObserver observer; | 156 ProfileRemovalObserver observer; |
156 | 157 |
157 // We should start out with 1 profile. | 158 // We should start out with 1 profile. |
158 ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); | 159 ASSERT_EQ(cache.GetNumberOfProfiles(), 1U); |
159 | 160 |
160 // Delete singleton profile. | 161 // Delete singleton profile. |
161 base::FilePath singleton_profile_path = cache.GetPathOfProfileAtIndex(0); | 162 base::FilePath singleton_profile_path = cache.GetPathOfProfileAtIndex(0); |
162 EXPECT_FALSE(singleton_profile_path.empty()); | 163 EXPECT_FALSE(singleton_profile_path.empty()); |
163 profile_manager->ScheduleProfileForDeletion(singleton_profile_path, | 164 base::RunLoop run_loop; |
164 ProfileManager::CreateCallback()); | 165 profile_manager->ScheduleProfileForDeletion( |
| 166 singleton_profile_path, |
| 167 base::Bind(&OnUnblockOnProfileCreation, &run_loop)); |
165 | 168 |
166 // Spin things till profile is actually deleted. | 169 // Run the message loop until the profile is actually deleted (as indicated |
167 content::RunAllPendingInMessageLoop(); | 170 // by the callback above being called). |
| 171 run_loop.Run(); |
168 | 172 |
169 // Make sure a new profile was created automatically. | 173 // Make sure a new profile was created automatically. |
170 EXPECT_EQ(cache.GetNumberOfProfiles(), 1U); | 174 EXPECT_EQ(cache.GetNumberOfProfiles(), 1U); |
171 base::FilePath new_profile_path = cache.GetPathOfProfileAtIndex(0); | 175 base::FilePath new_profile_path = cache.GetPathOfProfileAtIndex(0); |
172 EXPECT_NE(new_profile_path, singleton_profile_path); | 176 EXPECT_NE(new_profile_path.value(), singleton_profile_path.value()); |
173 | 177 |
174 // Make sure that last used profile preference is set correctly. | 178 // Make sure that last used profile preference is set correctly. |
175 Profile* last_used = ProfileManager::GetLastUsedProfile(); | 179 Profile* last_used = ProfileManager::GetLastUsedProfile(); |
176 EXPECT_EQ(new_profile_path, last_used->GetPath()); | 180 EXPECT_EQ(new_profile_path.value(), last_used->GetPath().value()); |
177 | 181 |
178 // Make sure the last used profile was set correctly before the notification | 182 // Make sure the last used profile was set correctly before the notification |
179 // was sent. | 183 // was sent. |
180 std::string last_used_profile_name = | 184 std::string last_used_profile_name = |
181 last_used->GetPath().BaseName().MaybeAsASCII(); | 185 last_used->GetPath().BaseName().MaybeAsASCII(); |
182 EXPECT_EQ(last_used_profile_name, observer.last_used_profile_name()); | 186 EXPECT_EQ(last_used_profile_name, observer.last_used_profile_name()); |
183 } | 187 } |
184 | 188 |
185 // Delete all profiles in a multi profile setup and make sure a new one is | 189 // Delete all profiles in a multi profile setup and make sure a new one is |
186 // created. | 190 // created. |
187 // Crashes/CHECKs. See crbug.com/104851 | 191 // Crashes/CHECKs. See crbug.com/104851 |
188 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DISABLED_DeleteAllProfiles) { | 192 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DISABLED_DeleteAllProfiles) { |
189 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 193 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
190 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 194 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
191 | 195 |
192 // Create an additional profile. | 196 // Create an additional profile. |
193 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); | 197 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); |
194 profile_manager->CreateProfileAsync(new_path, | 198 base::RunLoop run_loop; |
195 base::Bind(&OnUnblockOnProfileCreation), | 199 profile_manager->CreateProfileAsync( |
196 base::string16(), base::string16(), | 200 new_path, base::Bind(&OnUnblockOnProfileCreation, &run_loop), |
197 std::string()); | 201 base::string16(), base::string16(), std::string()); |
198 | 202 |
199 // Spin to allow profile creation to take place, loop is terminated | 203 // Run the message loop to allow profile creation to take place; the loop is |
200 // by OnUnblockOnProfileCreation when the profile is created. | 204 // terminated by OnUnblockOnProfileCreation when the profile is created. |
201 content::RunMessageLoop(); | 205 run_loop.Run(); |
202 | 206 |
203 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); | 207 ASSERT_EQ(cache.GetNumberOfProfiles(), 2U); |
204 | 208 |
205 // Delete all profiles. | 209 // Delete all profiles. |
206 base::FilePath profile_path1 = cache.GetPathOfProfileAtIndex(0); | 210 base::FilePath profile_path1 = cache.GetPathOfProfileAtIndex(0); |
207 base::FilePath profile_path2 = cache.GetPathOfProfileAtIndex(1); | 211 base::FilePath profile_path2 = cache.GetPathOfProfileAtIndex(1); |
208 EXPECT_FALSE(profile_path1.empty()); | 212 EXPECT_FALSE(profile_path1.empty()); |
209 EXPECT_FALSE(profile_path2.empty()); | 213 EXPECT_FALSE(profile_path2.empty()); |
210 profile_manager->ScheduleProfileForDeletion(profile_path1, | 214 profile_manager->ScheduleProfileForDeletion(profile_path1, |
211 ProfileManager::CreateCallback()); | 215 ProfileManager::CreateCallback()); |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 303 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
300 size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); | 304 size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); |
301 base::FilePath path_profile1 = GetFirstNonSigninProfile(cache); | 305 base::FilePath path_profile1 = GetFirstNonSigninProfile(cache); |
302 | 306 |
303 ASSERT_NE(0U, initial_profile_count); | 307 ASSERT_NE(0U, initial_profile_count); |
304 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); | 308 EXPECT_EQ(1U, chrome::GetTotalBrowserCount()); |
305 | 309 |
306 // Create an additional profile. | 310 // Create an additional profile. |
307 base::FilePath path_profile2 = | 311 base::FilePath path_profile2 = |
308 profile_manager->GenerateNextProfileDirectoryPath(); | 312 profile_manager->GenerateNextProfileDirectoryPath(); |
309 profile_manager->CreateProfileAsync(path_profile2, | 313 base::RunLoop run_loop; |
310 base::Bind(&OnUnblockOnProfileCreation), | 314 profile_manager->CreateProfileAsync( |
311 base::string16(), base::string16(), | 315 path_profile2, base::Bind(&OnUnblockOnProfileCreation, &run_loop), |
312 std::string()); | 316 base::string16(), base::string16(), std::string()); |
313 | 317 |
314 // Spin to allow profile creation to take place, loop is terminated | 318 // Run the message loop to allow profile creation to take place; the loop is |
315 // by OnUnblockOnProfileCreation when the profile is created. | 319 // terminated by OnUnblockOnProfileCreation when the profile is created. |
316 content::RunMessageLoop(); | 320 run_loop.Run(); |
317 | 321 |
318 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); | 322 chrome::HostDesktopType desktop_type = chrome::GetActiveDesktop(); |
319 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); | 323 BrowserList* browser_list = BrowserList::GetInstance(desktop_type); |
320 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles()); | 324 ASSERT_EQ(initial_profile_count + 1, cache.GetNumberOfProfiles()); |
321 EXPECT_EQ(1U, browser_list->size()); | 325 EXPECT_EQ(1U, browser_list->size()); |
322 | 326 |
323 // Open a browser window for the first profile. | 327 // Open a browser window for the first profile. |
324 profiles::SwitchToProfile(path_profile1, desktop_type, false, | 328 profiles::SwitchToProfile(path_profile1, desktop_type, false, |
325 kOnProfileSwitchDoNothing, | 329 kOnProfileSwitchDoNothing, |
326 ProfileMetrics::SWITCH_PROFILE_ICON); | 330 ProfileMetrics::SWITCH_PROFILE_ICON); |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 form.blacklisted_by_user = false; | 442 form.blacklisted_by_user = false; |
439 | 443 |
440 scoped_refptr<password_manager::PasswordStore> password_store = | 444 scoped_refptr<password_manager::PasswordStore> password_store = |
441 PasswordStoreFactory::GetForProfile( | 445 PasswordStoreFactory::GetForProfile( |
442 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); | 446 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); |
443 ASSERT_TRUE(password_store.get()); | 447 ASSERT_TRUE(password_store.get()); |
444 | 448 |
445 password_store->AddLogin(form); | 449 password_store->AddLogin(form); |
446 PasswordStoreConsumerVerifier verify_add; | 450 PasswordStoreConsumerVerifier verify_add; |
447 password_store->GetAutofillableLogins(&verify_add); | 451 password_store->GetAutofillableLogins(&verify_add); |
| 452 verify_add.Wait(); |
| 453 EXPECT_EQ(1u, verify_add.GetPasswords().size()); |
448 | 454 |
449 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 455 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
450 profile_manager->ScheduleProfileForDeletion(profile->GetPath(), | 456 base::RunLoop run_loop; |
451 ProfileManager::CreateCallback()); | 457 profile_manager->ScheduleProfileForDeletion( |
452 content::RunAllPendingInMessageLoop(); | 458 profile->GetPath(), base::Bind(&OnUnblockOnProfileCreation, &run_loop)); |
| 459 run_loop.Run(); |
| 460 |
453 PasswordStoreConsumerVerifier verify_delete; | 461 PasswordStoreConsumerVerifier verify_delete; |
454 password_store->GetAutofillableLogins(&verify_delete); | 462 password_store->GetAutofillableLogins(&verify_delete); |
455 | 463 verify_delete.Wait(); |
456 // Run the password background thread. | |
457 base::RunLoop run_loop; | |
458 base::Closure task = base::Bind( | |
459 base::IgnoreResult(&content::BrowserThread::PostTask), | |
460 content::BrowserThread::UI, | |
461 FROM_HERE, | |
462 run_loop.QuitClosure()); | |
463 EXPECT_TRUE(password_store->ScheduleTask(task)); | |
464 run_loop.Run(); | |
465 | |
466 EXPECT_TRUE(verify_add.IsCalled()); | |
467 EXPECT_EQ(1u, verify_add.GetPasswords().size()); | |
468 EXPECT_TRUE(verify_delete.IsCalled()); | |
469 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); | 464 EXPECT_EQ(0u, verify_delete.GetPasswords().size()); |
470 } | 465 } |
471 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 466 #endif // !defined(OS_WIN) && !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
OLD | NEW |