Chromium Code Reviews| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 | 6 |
| 7 #include "base/base_switches.h" | |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 9 #include "base/macros.h" | 10 #include "base/macros.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 12 #include "chrome/browser/password_manager/password_store_factory.h" | 13 #include "chrome/browser/password_manager/password_store_factory.h" |
| 13 #include "chrome/browser/profiles/profile_attributes_entry.h" | 14 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 14 #include "chrome/browser/profiles/profile_attributes_storage.h" | 15 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 15 #include "chrome/browser/profiles/profile_manager.h" | 16 #include "chrome/browser/profiles/profile_manager.h" |
| 16 #include "chrome/browser/profiles/profile_window.h" | 17 #include "chrome/browser/profiles/profile_window.h" |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 29 | 30 |
| 30 #if defined(OS_CHROMEOS) | 31 #if defined(OS_CHROMEOS) |
| 31 #include "base/path_service.h" | 32 #include "base/path_service.h" |
| 32 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 33 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 33 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
| 34 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
| 35 #include "chromeos/chromeos_switches.h" | 36 #include "chromeos/chromeos_switches.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 37 #include "testing/gtest/include/gtest/gtest.h" |
| 37 #endif | 38 #endif |
| 38 | 39 |
| 40 #if defined(OS_WIN) | |
| 41 #include <windows.h> | |
| 42 #include "base/test/test_file_util.h" | |
| 43 #endif | |
| 44 | |
| 39 namespace { | 45 namespace { |
| 40 | 46 |
| 41 const ProfileManager::CreateCallback kOnProfileSwitchDoNothing; | 47 const ProfileManager::CreateCallback kOnProfileSwitchDoNothing; |
| 42 | 48 |
| 43 // An observer that returns back to test code after a new profile is | 49 // An observer that returns back to test code after a new profile is |
| 44 // initialized. | 50 // initialized. |
| 45 void OnUnblockOnProfileCreation(base::RunLoop* run_loop, | 51 void OnUnblockOnProfileCreation(base::RunLoop* run_loop, |
| 46 Profile* profile, | 52 Profile* profile, |
| 47 Profile::CreateStatus status) { | 53 Profile::CreateStatus status) { |
| 48 if (status == Profile::CREATE_STATUS_INITIALIZED) | 54 if (status == Profile::CREATE_STATUS_INITIALIZED) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 | 147 |
| 142 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all | 148 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all |
| 143 // platforms. | 149 // platforms. |
| 144 class ProfileManagerBrowserTest : public InProcessBrowserTest { | 150 class ProfileManagerBrowserTest : public InProcessBrowserTest { |
| 145 protected: | 151 protected: |
| 146 void SetUpCommandLine(base::CommandLine* command_line) override { | 152 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 147 #if defined(OS_CHROMEOS) | 153 #if defined(OS_CHROMEOS) |
| 148 command_line->AppendSwitch( | 154 command_line->AppendSwitch( |
| 149 chromeos::switches::kIgnoreUserProfileMappingForTests); | 155 chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 150 #endif | 156 #endif |
| 157 command_line->AppendSwitch(switches::kNoErrorDialogs); | |
| 151 } | 158 } |
| 152 }; | 159 }; |
| 153 | 160 |
| 154 #if defined(OS_MACOSX) | 161 #if defined(OS_MACOSX) |
| 155 | 162 |
| 156 // Delete single profile and make sure a new one is created. | 163 // Delete single profile and make sure a new one is created. |
| 157 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { | 164 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { |
| 158 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 165 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 159 ProfileAttributesStorage& storage = | 166 ProfileAttributesStorage& storage = |
| 160 profile_manager->GetProfileAttributesStorage(); | 167 profile_manager->GetProfileAttributesStorage(); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); | 297 EXPECT_EQ(chrome::GetTotalBrowserCount(), 2U); |
| 291 | 298 |
| 292 // Now close all browser windows. | 299 // Now close all browser windows. |
| 293 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); | 300 std::vector<Profile*> profiles = profile_manager->GetLoadedProfiles(); |
| 294 for (std::vector<Profile*>::const_iterator it = profiles.begin(); | 301 for (std::vector<Profile*>::const_iterator it = profiles.begin(); |
| 295 it != profiles.end(); ++it) { | 302 it != profiles.end(); ++it) { |
| 296 BrowserList::CloseAllBrowsersWithProfile(*it); | 303 BrowserList::CloseAllBrowsersWithProfile(*it); |
| 297 } | 304 } |
| 298 } | 305 } |
| 299 | 306 |
| 300 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, | 307 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, SwitchToProfile) { |
| 301 SwitchToProfile) { | |
| 302 // If multiprofile mode is not enabled, you can't switch between profiles. | 308 // If multiprofile mode is not enabled, you can't switch between profiles. |
| 303 if (!profiles::IsMultipleProfilesEnabled()) | 309 if (!profiles::IsMultipleProfilesEnabled()) |
| 304 return; | 310 return; |
| 305 | 311 |
| 306 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 312 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 307 ProfileAttributesStorage& storage = | 313 ProfileAttributesStorage& storage = |
| 308 profile_manager->GetProfileAttributesStorage(); | 314 profile_manager->GetProfileAttributesStorage(); |
| 309 size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); | 315 size_t initial_profile_count = profile_manager->GetNumberOfProfiles(); |
| 310 base::FilePath path_profile1 = GetFirstNonSigninProfile(storage); | 316 base::FilePath path_profile1 = GetFirstNonSigninProfile(storage); |
| 311 | 317 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 345 // Switch to the first profile without opening a new window. | 351 // Switch to the first profile without opening a new window. |
| 346 profiles::SwitchToProfile(path_profile1, false, kOnProfileSwitchDoNothing, | 352 profiles::SwitchToProfile(path_profile1, false, kOnProfileSwitchDoNothing, |
| 347 ProfileMetrics::SWITCH_PROFILE_ICON); | 353 ProfileMetrics::SWITCH_PROFILE_ICON); |
| 348 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); | 354 EXPECT_EQ(2U, chrome::GetTotalBrowserCount()); |
| 349 EXPECT_EQ(2U, browser_list->size()); | 355 EXPECT_EQ(2U, browser_list->size()); |
| 350 | 356 |
| 351 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); | 357 EXPECT_EQ(path_profile1, browser_list->get(0)->profile()->GetPath()); |
| 352 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); | 358 EXPECT_EQ(path_profile2, browser_list->get(1)->profile()->GetPath()); |
| 353 } | 359 } |
| 354 | 360 |
| 361 #if defined(OS_WIN) | |
|
Peter Kasting
2016/06/13 04:43:20
It would be nice to be able to run this test on al
WC Leung
2016/06/13 08:06:45
Sadly I don't think that is possible. I've done a
WC Leung
2016/06/15 13:08:39
I mean confirm with the crash logs (I don't have a
| |
| 362 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, SwitchToProfileFails) { | |
| 363 base::FilePath user_data_dir = | |
| 364 g_browser_process->profile_manager()->user_data_dir(); | |
| 365 base::DenyFilePermission(user_data_dir, FILE_ADD_SUBDIRECTORY); | |
| 366 // Switch to a profile that cannot be loaded or created. This must fail | |
| 367 // gracefully with no crash. | |
| 368 profiles::SwitchToProfile(user_data_dir.AppendASCII("Profile 1"), | |
| 369 false, | |
| 370 kOnProfileSwitchDoNothing, | |
| 371 ProfileMetrics::SWITCH_PROFILE_ICON); | |
| 372 } | |
| 373 #endif // defined(OS_WIN) | |
| 374 | |
| 355 // Flakes on Windows: http://crbug.com/314905 | 375 // Flakes on Windows: http://crbug.com/314905 |
| 356 #if defined(OS_WIN) | 376 #if defined(OS_WIN) |
| 357 #define MAYBE_EphemeralProfile DISABLED_EphemeralProfile | 377 #define MAYBE_EphemeralProfile DISABLED_EphemeralProfile |
| 358 #else | 378 #else |
| 359 #define MAYBE_EphemeralProfile EphemeralProfile | 379 #define MAYBE_EphemeralProfile EphemeralProfile |
| 360 #endif | 380 #endif |
| 361 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { | 381 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, MAYBE_EphemeralProfile) { |
| 362 // If multiprofile mode is not enabled, you can't switch between profiles. | 382 // If multiprofile mode is not enabled, you can't switch between profiles. |
| 363 if (!profiles::IsMultipleProfilesEnabled()) | 383 if (!profiles::IsMultipleProfilesEnabled()) |
| 364 return; | 384 return; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 492 | 512 |
| 493 EXPECT_FALSE(profile->HasOffTheRecordProfile()); | 513 EXPECT_FALSE(profile->HasOffTheRecordProfile()); |
| 494 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); | 514 EXPECT_FALSE(profile_manager->IsValidProfile(incognito_profile)); |
| 495 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); | 515 EXPECT_EQ(initial_profile_count, profile_manager->GetNumberOfProfiles()); |
| 496 // After destroying the incognito profile incognito preferences should be | 516 // After destroying the incognito profile incognito preferences should be |
| 497 // cleared so the default save path should be taken from the main profile. | 517 // cleared so the default save path should be taken from the main profile. |
| 498 EXPECT_FALSE(profile->GetOffTheRecordPrefs() | 518 EXPECT_FALSE(profile->GetOffTheRecordPrefs() |
| 499 ->GetFilePath(prefs::kSaveFileDefaultDirectory) | 519 ->GetFilePath(prefs::kSaveFileDefaultDirectory) |
| 500 .empty()); | 520 .empty()); |
| 501 } | 521 } |
| OLD | NEW |