Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(46)

Side by Side Diff: chrome/browser/profiles/profile_manager_browsertest.cc

Issue 2772503003: Revert of Added profile deletion browsertests. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/ui/webui/profile_helper_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h"
12 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
13 #include "build/build_config.h" 11 #include "build/build_config.h"
14 #include "chrome/browser/lifetime/keep_alive_types.h"
15 #include "chrome/browser/lifetime/scoped_keep_alive.h"
16 #include "chrome/browser/password_manager/password_store_factory.h" 12 #include "chrome/browser/password_manager/password_store_factory.h"
17 #include "chrome/browser/profiles/profile_attributes_entry.h" 13 #include "chrome/browser/profiles/profile_attributes_entry.h"
18 #include "chrome/browser/profiles/profile_attributes_storage.h" 14 #include "chrome/browser/profiles/profile_attributes_storage.h"
19 #include "chrome/browser/profiles/profile_manager.h" 15 #include "chrome/browser/profiles/profile_manager.h"
20 #include "chrome/browser/profiles/profile_window.h" 16 #include "chrome/browser/profiles/profile_window.h"
21 #include "chrome/browser/profiles/profiles_state.h" 17 #include "chrome/browser/profiles/profiles_state.h"
22 #include "chrome/browser/ui/browser_finder.h" 18 #include "chrome/browser/ui/browser_finder.h"
23 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
24 #include "chrome/browser/ui/browser_window.h" 20 #include "chrome/browser/ui/browser_window.h"
25 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
(...skipping 30 matching lines...) Expand all
56 void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) { 52 void ProfileCreationComplete(Profile* profile, Profile::CreateStatus status) {
57 ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL); 53 ASSERT_NE(status, Profile::CREATE_STATUS_LOCAL_FAIL);
58 ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL); 54 ASSERT_NE(status, Profile::CREATE_STATUS_REMOTE_FAIL);
59 // No browser should have been created for this profile yet. 55 // No browser should have been created for this profile yet.
60 EXPECT_EQ(chrome::GetBrowserCount(profile), 0U); 56 EXPECT_EQ(chrome::GetBrowserCount(profile), 0U);
61 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); 57 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U);
62 if (status == Profile::CREATE_STATUS_INITIALIZED) 58 if (status == Profile::CREATE_STATUS_INITIALIZED)
63 base::MessageLoop::current()->QuitWhenIdle(); 59 base::MessageLoop::current()->QuitWhenIdle();
64 } 60 }
65 61
66 // An observer returns back to test code after one or more profiles was deleted.
67 // It has ScopedKeepAlive object to prevent browser shutdown started in case
68 // browser become windowless.
69 class MultipleProfileDeletionObserver {
70 public:
71 explicit MultipleProfileDeletionObserver(size_t callbacks_calls_expected)
72 : callback_calls_left_(callbacks_calls_expected) {
73 EXPECT_LT(0u, callback_calls_left_);
74 }
75 ProfileManager::CreateCallback QuitAttemptClosure() {
76 return base::Bind(&MultipleProfileDeletionObserver::QuitAttempt,
77 base::Unretained(this));
78 }
79 void Wait() {
80 keep_alive_ = base::MakeUnique<ScopedKeepAlive>(
81 KeepAliveOrigin::PROFILE_HELPER, KeepAliveRestartOption::DISABLED);
82 loop_.Run();
83 }
84
85 private:
86 void QuitAttempt(Profile* profile, Profile::CreateStatus status) {
87 EXPECT_EQ(Profile::CREATE_STATUS_INITIALIZED, status);
88 if (--callback_calls_left_)
89 return;
90 keep_alive_.reset(nullptr);
91 loop_.Quit();
92 }
93
94 base::RunLoop loop_;
95 size_t callback_calls_left_;
96 std::unique_ptr<ScopedKeepAlive> keep_alive_;
97 };
98
99 void EphemeralProfileCreationComplete(Profile* profile, 62 void EphemeralProfileCreationComplete(Profile* profile,
100 Profile::CreateStatus status) { 63 Profile::CreateStatus status) {
101 if (status == Profile::CREATE_STATUS_INITIALIZED) 64 if (status == Profile::CREATE_STATUS_INITIALIZED)
102 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); 65 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true);
103 ProfileCreationComplete(profile, status); 66 ProfileCreationComplete(profile, status);
104 } 67 }
105 68
106 class ProfileRemovalObserver : public ProfileAttributesStorage::Observer { 69 class ProfileRemovalObserver : public ProfileAttributesStorage::Observer {
107 public: 70 public:
108 ProfileRemovalObserver() { 71 ProfileRemovalObserver() {
109 g_browser_process->profile_manager()->GetProfileAttributesStorage(). 72 g_browser_process->profile_manager()->GetProfileAttributesStorage().
110 AddObserver(this); 73 AddObserver(this);
111 } 74 }
112 75
113 ~ProfileRemovalObserver() override { 76 ~ProfileRemovalObserver() override {
114 g_browser_process->profile_manager()->GetProfileAttributesStorage(). 77 g_browser_process->profile_manager()->GetProfileAttributesStorage().
115 RemoveObserver(this); 78 RemoveObserver(this);
116 } 79 }
117 80
118 std::string last_used_profile_name() { return last_used_profile_name_; } 81 std::string last_used_profile_name() { return last_used_profile_name_; }
119 82
120 void set_on_profile_removal_callback(const base::Closure& callback) {
121 on_profile_removal_callback_ = callback;
122 }
123
124 // ProfileAttributesStorage::Observer overrides: 83 // ProfileAttributesStorage::Observer overrides:
125 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override { 84 void OnProfileWillBeRemoved(const base::FilePath& profile_path) override {
126 last_used_profile_name_ = g_browser_process->local_state()->GetString( 85 last_used_profile_name_ = g_browser_process->local_state()->GetString(
127 prefs::kProfileLastUsed); 86 prefs::kProfileLastUsed);
128 if (!on_profile_removal_callback_.is_null())
129 on_profile_removal_callback_.Run();
130 } 87 }
131 88
132 private: 89 private:
133 std::string last_used_profile_name_; 90 std::string last_used_profile_name_;
134 base::Closure on_profile_removal_callback_;
135 91
136 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver); 92 DISALLOW_COPY_AND_ASSIGN(ProfileRemovalObserver);
137 }; 93 };
138 94
139 // The class serves to retrieve passwords from PasswordStore asynchronously. It 95 // The class serves to retrieve passwords from PasswordStore asynchronously. It
140 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms. 96 // used by ProfileManagerBrowserTest.DeletePasswords on some platforms.
141 class PasswordStoreConsumerVerifier 97 class PasswordStoreConsumerVerifier
142 : public password_manager::PasswordStoreConsumer { 98 : public password_manager::PasswordStoreConsumer {
143 public: 99 public:
144 void OnGetPasswordStoreResults( 100 void OnGetPasswordStoreResults(
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 class ProfileManagerBrowserTest : public InProcessBrowserTest { 145 class ProfileManagerBrowserTest : public InProcessBrowserTest {
190 protected: 146 protected:
191 void SetUpCommandLine(base::CommandLine* command_line) override { 147 void SetUpCommandLine(base::CommandLine* command_line) override {
192 #if defined(OS_CHROMEOS) 148 #if defined(OS_CHROMEOS)
193 command_line->AppendSwitch( 149 command_line->AppendSwitch(
194 chromeos::switches::kIgnoreUserProfileMappingForTests); 150 chromeos::switches::kIgnoreUserProfileMappingForTests);
195 #endif 151 #endif
196 } 152 }
197 }; 153 };
198 154
199 // Android does not support multi-profiles, and CrOS multi-profiles 155 #if defined(OS_MACOSX)
200 // implementation is too different for these tests.
201 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS)
202 156
203 // Delete single profile and make sure a new one is created. 157 // Delete single profile and make sure a new one is created.
204 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { 158 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) {
205 ProfileManager* profile_manager = g_browser_process->profile_manager(); 159 ProfileManager* profile_manager = g_browser_process->profile_manager();
206 ProfileAttributesStorage& storage = 160 ProfileAttributesStorage& storage =
207 profile_manager->GetProfileAttributesStorage(); 161 profile_manager->GetProfileAttributesStorage();
208 ProfileRemovalObserver observer; 162 ProfileRemovalObserver observer;
209 163
210 // We should start out with 1 profile. 164 // We should start out with 1 profile.
211 ASSERT_EQ(1u, storage.GetNumberOfProfiles()); 165 ASSERT_EQ(1u, storage.GetNumberOfProfiles());
212 166
213 // Delete singleton profile. 167 // Delete singleton profile.
214 base::FilePath singleton_profile_path = 168 base::FilePath singleton_profile_path =
215 storage.GetAllProfilesAttributes().front()->GetPath(); 169 storage.GetAllProfilesAttributes().front()->GetPath();
216 EXPECT_FALSE(singleton_profile_path.empty()); 170 EXPECT_FALSE(singleton_profile_path.empty());
217 MultipleProfileDeletionObserver profile_deletion_observer(1u); 171 base::RunLoop run_loop;
218 profile_manager->ScheduleProfileForDeletion( 172 profile_manager->ScheduleProfileForDeletion(
219 singleton_profile_path, profile_deletion_observer.QuitAttemptClosure()); 173 singleton_profile_path,
174 base::Bind(&OnUnblockOnProfileCreation, &run_loop));
220 175
221 // Run the message loop until the profile is actually deleted (as indicated 176 // Run the message loop until the profile is actually deleted (as indicated
222 // by the callback above being called). 177 // by the callback above being called).
223 profile_deletion_observer.Wait(); 178 run_loop.Run();
224 179
225 // Make sure a new profile was created automatically. 180 // Make sure a new profile was created automatically.
226 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); 181 EXPECT_EQ(1u, storage.GetNumberOfProfiles());
227 base::FilePath new_profile_path = 182 base::FilePath new_profile_path =
228 storage.GetAllProfilesAttributes().front()->GetPath(); 183 storage.GetAllProfilesAttributes().front()->GetPath();
229 EXPECT_NE(new_profile_path.value(), singleton_profile_path.value()); 184 EXPECT_NE(new_profile_path.value(), singleton_profile_path.value());
230 185
231 // Make sure that last used profile preference is set correctly. 186 // Make sure that last used profile preference is set correctly.
232 Profile* last_used = ProfileManager::GetLastUsedProfile(); 187 Profile* last_used = ProfileManager::GetLastUsedProfile();
233 EXPECT_EQ(new_profile_path.value(), last_used->GetPath().value()); 188 EXPECT_EQ(new_profile_path.value(), last_used->GetPath().value());
234 189
235 // Make sure the last used profile was set correctly before the notification 190 // Make sure the last used profile was set correctly before the notification
236 // was sent. 191 // was sent.
237 std::string last_used_profile_name = 192 std::string last_used_profile_name =
238 last_used->GetPath().BaseName().MaybeAsASCII(); 193 last_used->GetPath().BaseName().MaybeAsASCII();
239 EXPECT_EQ(last_used_profile_name, observer.last_used_profile_name()); 194 EXPECT_EQ(last_used_profile_name, observer.last_used_profile_name());
240 } 195 }
241 196
242 // Delete inactive profile in a multi profile setup and make sure current 197 // Delete all profiles in a multi profile setup and make sure a new one is
243 // browser is not affected. 198 // created.
244 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteInactiveProfile) { 199 // Crashes/CHECKs. See crbug.com/104851
200 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DISABLED_DeleteAllProfiles) {
245 ProfileManager* profile_manager = g_browser_process->profile_manager(); 201 ProfileManager* profile_manager = g_browser_process->profile_manager();
246 ProfileAttributesStorage& storage = 202 ProfileAttributesStorage& storage =
247 profile_manager->GetProfileAttributesStorage(); 203 profile_manager->GetProfileAttributesStorage();
248 base::FilePath current_profile_path = browser()->profile()->GetPath();
249 204
250 // Create an additional profile. 205 // Create an additional profile.
251 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath(); 206 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath();
252 base::RunLoop run_loop; 207 base::RunLoop run_loop;
253 profile_manager->CreateProfileAsync( 208 profile_manager->CreateProfileAsync(
254 new_path, base::Bind(&OnUnblockOnProfileCreation, &run_loop), 209 new_path, base::Bind(&OnUnblockOnProfileCreation, &run_loop),
255 base::string16(), std::string(), std::string()); 210 base::string16(), std::string(), std::string());
256 run_loop.Run();
257
258 ASSERT_EQ(2u, storage.GetNumberOfProfiles());
259
260 // Delete inactive profile.
261 base::RunLoop loop;
262 ProfileRemovalObserver observer;
263 observer.set_on_profile_removal_callback(loop.QuitClosure());
264 profile_manager->ScheduleProfileForDeletion(new_path,
265 ProfileManager::CreateCallback());
266 loop.Run();
267
268 // Make sure there only preexisted profile left.
269 EXPECT_EQ(1u, storage.GetNumberOfProfiles());
270 EXPECT_EQ(current_profile_path,
271 storage.GetAllProfilesAttributes().front()->GetPath());
272
273 // Make sure that last used profile preference is set correctly.
274 Profile* last_used = ProfileManager::GetLastUsedProfile();
275 EXPECT_EQ(current_profile_path, last_used->GetPath());
276 }
277
278 // Delete current profile in a multi profile setup and make sure an existing one
279 // is loaded.
280 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteCurrentProfile) {
281 ProfileManager* profile_manager = g_browser_process->profile_manager();
282 ProfileAttributesStorage& storage =
283 profile_manager->GetProfileAttributesStorage();
284
285 // Create an additional profile.
286 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath();
287 base::RunLoop run_loop;
288 profile_manager->CreateProfileAsync(
289 new_path, base::Bind(&OnUnblockOnProfileCreation, &run_loop),
290 base::string16(), std::string(), std::string());
291 run_loop.Run();
292
293 ASSERT_EQ(2u, storage.GetNumberOfProfiles());
294
295 // Delete current profile.
296 MultipleProfileDeletionObserver profile_deletion_observer(1u);
297 profile_manager->ScheduleProfileForDeletion(
298 browser()->profile()->GetPath(),
299 profile_deletion_observer.QuitAttemptClosure());
300 profile_deletion_observer.Wait();
301
302 // Make sure a profile created earlier become the only profile.
303 EXPECT_EQ(1u, storage.GetNumberOfProfiles());
304 EXPECT_EQ(new_path, storage.GetAllProfilesAttributes().front()->GetPath());
305
306 // Make sure that last used profile preference is set correctly.
307 Profile* last_used = ProfileManager::GetLastUsedProfile();
308 EXPECT_EQ(new_path, last_used->GetPath());
309 }
310
311 // Delete all profiles in a multi profile setup and make sure a new one is
312 // created.
313 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteAllProfiles) {
314 ProfileManager* profile_manager = g_browser_process->profile_manager();
315 ProfileAttributesStorage& storage =
316 profile_manager->GetProfileAttributesStorage();
317
318 // Create an additional profile.
319 base::FilePath new_path = profile_manager->GenerateNextProfileDirectoryPath();
320 base::RunLoop run_loop;
321 profile_manager->CreateProfileAsync(
322 new_path, base::Bind(&OnUnblockOnProfileCreation, &run_loop),
323 base::string16(), std::string(), std::string());
324 211
325 // Run the message loop to allow profile creation to take place; the loop is 212 // Run the message loop to allow profile creation to take place; the loop is
326 // terminated by OnUnblockOnProfileCreation when the profile is created. 213 // terminated by OnUnblockOnProfileCreation when the profile is created.
327 run_loop.Run(); 214 run_loop.Run();
328 215
329 ASSERT_EQ(2u, storage.GetNumberOfProfiles()); 216 ASSERT_EQ(2u, storage.GetNumberOfProfiles());
330 217
331 // Delete all profiles. 218 // Delete all profiles.
332 MultipleProfileDeletionObserver profile_deletion_observer(2u);
333 std::vector<ProfileAttributesEntry*> entries = 219 std::vector<ProfileAttributesEntry*> entries =
334 storage.GetAllProfilesAttributes(); 220 storage.GetAllProfilesAttributes();
335 std::vector<base::FilePath> old_profile_paths; 221 std::vector<base::FilePath> old_profile_paths;
336 for (ProfileAttributesEntry* entry : entries) { 222 for (ProfileAttributesEntry* entry : entries) {
337 base::FilePath profile_path = entry->GetPath(); 223 base::FilePath profile_path = entry->GetPath();
338 EXPECT_FALSE(profile_path.empty()); 224 EXPECT_FALSE(profile_path.empty());
339 profile_manager->ScheduleProfileForDeletion( 225 profile_manager->ScheduleProfileForDeletion(
340 profile_path, profile_deletion_observer.QuitAttemptClosure()); 226 profile_path, ProfileManager::CreateCallback());
341 old_profile_paths.push_back(profile_path); 227 old_profile_paths.push_back(profile_path);
342 } 228 }
343 profile_deletion_observer.Wait(); 229
230 // Spin things so deletion can take place.
231 content::RunAllPendingInMessageLoop();
344 232
345 // Make sure a new profile was created automatically. 233 // Make sure a new profile was created automatically.
346 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); 234 EXPECT_EQ(1u, storage.GetNumberOfProfiles());
347 base::FilePath new_profile_path = 235 base::FilePath new_profile_path =
348 storage.GetAllProfilesAttributes().front()->GetPath(); 236 storage.GetAllProfilesAttributes().front()->GetPath();
349 for (const base::FilePath& old_profile_path : old_profile_paths) 237 for (const base::FilePath& old_profile_path : old_profile_paths)
350 EXPECT_NE(old_profile_path, new_profile_path); 238 EXPECT_NE(old_profile_path, new_profile_path);
351 239
352 // Make sure that last used profile preference is set correctly. 240 // Make sure that last used profile preference is set correctly.
353 Profile* last_used = ProfileManager::GetLastUsedProfile(); 241 Profile* last_used = ProfileManager::GetLastUsedProfile();
354 EXPECT_EQ(new_profile_path, last_used->GetPath()); 242 EXPECT_EQ(new_profile_path, last_used->GetPath());
355 } 243 }
356 #endif // !defined(OS_ANDROID) && !defined(OS_CHROMEOS) 244 #endif // OS_MACOSX
357 245
358 #if defined(OS_CHROMEOS) 246 #if defined(OS_CHROMEOS)
359 247
360 class ProfileManagerCrOSBrowserTest : public ProfileManagerBrowserTest { 248 class ProfileManagerCrOSBrowserTest : public ProfileManagerBrowserTest {
361 protected: 249 protected:
362 void SetUpCommandLine(base::CommandLine* command_line) override { 250 void SetUpCommandLine(base::CommandLine* command_line) override {
363 // Use a user hash other than the default chrome::kTestUserProfileDir 251 // Use a user hash other than the default chrome::kTestUserProfileDir
364 // so that the prefix case is tested. 252 // so that the prefix case is tested.
365 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, 253 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile,
366 "test-user-hash"); 254 "test-user-hash");
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 500
613 EXPECT_FALSE(profile->HasOffTheRecordProfile()); 501 EXPECT_FALSE(profile->HasOffTheRecordProfile());
614 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); 502 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile));
615 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); 503 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles());
616 // After destroying the incognito profile incognito preferences should be 504 // After destroying the incognito profile incognito preferences should be
617 // cleared so the default save path should be taken from the main profile. 505 // cleared so the default save path should be taken from the main profile.
618 EXPECT_FALSE(profile->GetOffTheRecordPrefs() 506 EXPECT_FALSE(profile->GetOffTheRecordPrefs()
619 ->GetFilePath(prefs::kSaveFileDefaultDirectory) 507 ->GetFilePath(prefs::kSaveFileDefaultDirectory)
620 .empty()); 508 .empty());
621 } 509 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/webui/profile_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698