OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <algorithm> | 5 #include <algorithm> |
6 #include <string> | 6 #include <string> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/base_switches.h" | 9 #include "base/base_switches.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/test/test_file_util.h" | 17 #include "base/test/test_file_util.h" |
| 18 #include "base/threading/thread_restrictions.h" |
18 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
20 #include "chrome/browser/profiles/profile_window.h" | 21 #include "chrome/browser/profiles/profile_window.h" |
21 #include "chrome/browser/ui/browser_list.h" | 22 #include "chrome/browser/ui/browser_list.h" |
22 #include "chrome/browser/ui/user_manager.h" | 23 #include "chrome/browser/ui/user_manager.h" |
23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/test/base/in_process_browser_test.h" | 26 #include "chrome/test/base/in_process_browser_test.h" |
26 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
27 | 28 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 | 267 |
267 // LastUsedProfileFallbackToUserManager : If all last opened profiles are | 268 // LastUsedProfileFallbackToUserManager : If all last opened profiles are |
268 // missing, it should fall back to user manager. To open the user manager, both | 269 // missing, it should fall back to user manager. To open the user manager, both |
269 // the guest profile and the system profile must be creatable. | 270 // the guest profile and the system profile must be creatable. |
270 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, | 271 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, |
271 PRE_LastUsedProfileFallbackToUserManager) { | 272 PRE_LastUsedProfileFallbackToUserManager) { |
272 CreateAndSwitchToProfile("Profile 1"); | 273 CreateAndSwitchToProfile("Profile 1"); |
273 CloseBrowsersSynchronouslyForProfileBasePath("Profile 1"); | 274 CloseBrowsersSynchronouslyForProfileBasePath("Profile 1"); |
274 CreateAndSwitchToProfile("Profile 2"); | 275 CreateAndSwitchToProfile("Profile 2"); |
275 | 276 |
| 277 base::ThreadRestrictions::ScopedAllowIO allow_io; |
276 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetGuestProfilePath())); | 278 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetGuestProfilePath())); |
277 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetSystemProfilePath())); | 279 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetSystemProfilePath())); |
278 } | 280 } |
279 | 281 |
280 bool StartupBrowserCreatorCorruptProfileTest:: | 282 bool StartupBrowserCreatorCorruptProfileTest:: |
281 SetUpUserDataDirectoryForLastUsedProfileFallbackToUserManager() { | 283 SetUpUserDataDirectoryForLastUsedProfileFallbackToUserManager() { |
282 return DeleteProfileData("Default") && | 284 return DeleteProfileData("Default") && |
283 DeleteProfileData("Profile 2") && | 285 DeleteProfileData("Profile 2") && |
284 RemoveCreateDirectoryPermissionForUserDataDirectory(); | 286 RemoveCreateDirectoryPermissionForUserDataDirectory(); |
285 } | 287 } |
286 | 288 |
287 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, | 289 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, |
288 LastUsedProfileFallbackToUserManager) { | 290 LastUsedProfileFallbackToUserManager) { |
289 CheckBrowserWindows({}); | 291 CheckBrowserWindows({}); |
290 ExpectUserManagerToShow(); | 292 ExpectUserManagerToShow(); |
291 } | 293 } |
292 | 294 |
293 | 295 |
294 // CannotCreateSystemProfile : If the system profile cannot be created, the user | 296 // CannotCreateSystemProfile : If the system profile cannot be created, the user |
295 // manager should not be shown. Fallback to any other profile. | 297 // manager should not be shown. Fallback to any other profile. |
296 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, | 298 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, |
297 PRE_CannotCreateSystemProfile) { | 299 PRE_CannotCreateSystemProfile) { |
298 CreateAndSwitchToProfile("Profile 1"); | 300 CreateAndSwitchToProfile("Profile 1"); |
299 CloseBrowsersSynchronouslyForProfileBasePath("Profile 1"); | 301 CloseBrowsersSynchronouslyForProfileBasePath("Profile 1"); |
300 CreateAndSwitchToProfile("Profile 2"); | 302 CreateAndSwitchToProfile("Profile 2"); |
301 | 303 |
302 // Create the guest profile path, but not the system profile one. This will | 304 // Create the guest profile path, but not the system profile one. This will |
303 // make it impossible to create the system profile once the permissions are | 305 // make it impossible to create the system profile once the permissions are |
304 // locked down during setup. | 306 // locked down during setup. |
| 307 base::ThreadRestrictions::ScopedAllowIO allow_io; |
305 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetGuestProfilePath())); | 308 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetGuestProfilePath())); |
306 } | 309 } |
307 | 310 |
308 bool StartupBrowserCreatorCorruptProfileTest:: | 311 bool StartupBrowserCreatorCorruptProfileTest:: |
309 SetUpUserDataDirectoryForCannotCreateSystemProfile() { | 312 SetUpUserDataDirectoryForCannotCreateSystemProfile() { |
310 return DeleteProfileData("Default") && | 313 return DeleteProfileData("Default") && |
311 DeleteProfileData("Profile 2") && | 314 DeleteProfileData("Profile 2") && |
312 RemoveCreateDirectoryPermissionForUserDataDirectory(); | 315 RemoveCreateDirectoryPermissionForUserDataDirectory(); |
313 } | 316 } |
314 | 317 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
395 NoFallbackForUserSelectedProfile) { | 398 NoFallbackForUserSelectedProfile) { |
396 ADD_FAILURE() << "Test body is not expected to run."; | 399 ADD_FAILURE() << "Test body is not expected to run."; |
397 } | 400 } |
398 | 401 |
399 // DeletedProfileFallbackToUserManager : If the profile's entry in | 402 // DeletedProfileFallbackToUserManager : If the profile's entry in |
400 // ProfileAttributesStorage is missing, it means the profile is deleted. The | 403 // ProfileAttributesStorage is missing, it means the profile is deleted. The |
401 // browser should not attempt to open the profile, but should show the user | 404 // browser should not attempt to open the profile, but should show the user |
402 // manager instead. | 405 // manager instead. |
403 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, | 406 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, |
404 PRE_DeletedProfileFallbackToUserManager) { | 407 PRE_DeletedProfileFallbackToUserManager) { |
| 408 base::ThreadRestrictions::ScopedAllowIO allow_io; |
405 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetGuestProfilePath())); | 409 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetGuestProfilePath())); |
406 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetSystemProfilePath())); | 410 ASSERT_TRUE(base::CreateDirectory(ProfileManager::GetSystemProfilePath())); |
407 } | 411 } |
408 | 412 |
409 bool StartupBrowserCreatorCorruptProfileTest:: | 413 bool StartupBrowserCreatorCorruptProfileTest:: |
410 SetUpUserDataDirectoryForDeletedProfileFallbackToUserManager() { | 414 SetUpUserDataDirectoryForDeletedProfileFallbackToUserManager() { |
411 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 415 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
412 // Simulate a deleted profile by not creating the profile at the first place. | 416 // Simulate a deleted profile by not creating the profile at the first place. |
413 command_line->AppendSwitchASCII(switches::kProfileDirectory, "Not Found"); | 417 command_line->AppendSwitchASCII(switches::kProfileDirectory, "Not Found"); |
414 return RemoveCreateDirectoryPermissionForUserDataDirectory(); | 418 return RemoveCreateDirectoryPermissionForUserDataDirectory(); |
415 } | 419 } |
416 | 420 |
417 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, | 421 IN_PROC_BROWSER_TEST_F(StartupBrowserCreatorCorruptProfileTest, |
418 DeletedProfileFallbackToUserManager) { | 422 DeletedProfileFallbackToUserManager) { |
419 CheckBrowserWindows({}); | 423 CheckBrowserWindows({}); |
420 ExpectUserManagerToShow(); | 424 ExpectUserManagerToShow(); |
421 } | 425 } |
OLD | NEW |