| 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/profiles/profile_info_cache.h" | 9 #include "chrome/browser/profiles/profile_info_cache.h" |
| 10 #include "chrome/browser/profiles/profile_info_cache_observer.h" | 10 #include "chrome/browser/profiles/profile_info_cache_observer.h" |
| 11 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
| 12 #include "chrome/browser/profiles/profile_window.h" | 12 #include "chrome/browser/profiles/profile_window.h" |
| 13 #include "chrome/browser/profiles/profiles_state.h" | 13 #include "chrome/browser/profiles/profiles_state.h" |
| 14 #include "chrome/browser/ui/browser_finder.h" | 14 #include "chrome/browser/ui/browser_finder.h" |
| 15 #include "chrome/browser/ui/browser_list.h" | 15 #include "chrome/browser/ui/browser_list.h" |
| 16 #include "chrome/browser/ui/browser_window.h" | 16 #include "chrome/browser/ui/browser_window.h" |
| 17 #include "chrome/browser/ui/host_desktop.h" | 17 #include "chrome/browser/ui/host_desktop.h" |
| 18 #include "chrome/common/chrome_switches.h" | |
| 19 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/in_process_browser_test.h" | 19 #include "chrome/test/base/in_process_browser_test.h" |
| 21 #include "chrome/test/base/test_switches.h" | 20 #include "chrome/test/base/test_switches.h" |
| 22 #include "chrome/test/base/testing_browser_process.h" | 21 #include "chrome/test/base/testing_browser_process.h" |
| 23 #include "chrome/test/base/ui_test_utils.h" | 22 #include "chrome/test/base/ui_test_utils.h" |
| 24 | 23 |
| 25 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 26 #include "base/path_service.h" | 25 #include "base/path_service.h" |
| 27 #include "chrome/common/chrome_constants.h" | 26 #include "chrome/common/chrome_constants.h" |
| 28 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 }; | 86 }; |
| 88 | 87 |
| 89 } // namespace | 88 } // namespace |
| 90 | 89 |
| 91 // This file contains tests for the ProfileManager that require a heavyweight | 90 // This file contains tests for the ProfileManager that require a heavyweight |
| 92 // InProcessBrowserTest. These include tests involving profile deletion. | 91 // InProcessBrowserTest. These include tests involving profile deletion. |
| 93 | 92 |
| 94 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all | 93 // TODO(jeremy): crbug.com/103355 - These tests should be enabled on all |
| 95 // platforms. | 94 // platforms. |
| 96 class ProfileManagerBrowserTest : public InProcessBrowserTest { | 95 class ProfileManagerBrowserTest : public InProcessBrowserTest { |
| 96 protected: |
| 97 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 98 #if defined(OS_CHROMEOS) |
| 99 command_line->AppendSwitch( |
| 100 chromeos::switches::kIgnoreUserProfileMappingForTests); |
| 101 #endif |
| 102 } |
| 97 }; | 103 }; |
| 98 | 104 |
| 99 #if defined(OS_MACOSX) | 105 #if defined(OS_MACOSX) |
| 100 | 106 |
| 101 // Delete single profile and make sure a new one is created. | 107 // Delete single profile and make sure a new one is created. |
| 102 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { | 108 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, DeleteSingletonProfile) { |
| 103 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 109 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 104 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 110 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
| 105 ProfileRemovalObserver observer; | 111 ProfileRemovalObserver observer; |
| 106 | 112 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 EXPECT_NE(new_profile_path, profile_path2); | 178 EXPECT_NE(new_profile_path, profile_path2); |
| 173 | 179 |
| 174 // Make sure that last used profile preference is set correctly. | 180 // Make sure that last used profile preference is set correctly. |
| 175 Profile* last_used = ProfileManager::GetLastUsedProfile(); | 181 Profile* last_used = ProfileManager::GetLastUsedProfile(); |
| 176 EXPECT_EQ(new_profile_path, last_used->GetPath()); | 182 EXPECT_EQ(new_profile_path, last_used->GetPath()); |
| 177 } | 183 } |
| 178 #endif // OS_MACOSX | 184 #endif // OS_MACOSX |
| 179 | 185 |
| 180 #if defined(OS_CHROMEOS) | 186 #if defined(OS_CHROMEOS) |
| 181 | 187 |
| 182 class ProfileManagerCrOSBrowserTest : public ProfileManagerBrowserTest, | 188 class ProfileManagerCrOSBrowserTest : public ProfileManagerBrowserTest { |
| 183 public testing::WithParamInterface<bool> { | |
| 184 protected: | 189 protected: |
| 185 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 190 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 186 if (GetParam()) { | 191 // Use a user hash other than the default chrome::kTestUserProfileDir |
| 187 command_line->AppendSwitch(::switches::kMultiProfiles); | 192 // so that the prefix case is tested. |
| 188 // Use a user hash other than the default chrome::kTestUserProfileDir | 193 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
| 189 // so that the prefix case is tested. | 194 "test-user-hash"); |
| 190 command_line->AppendSwitchASCII(chromeos::switches::kLoginProfile, | |
| 191 "test-user-hash"); | |
| 192 } | |
| 193 } | 195 } |
| 194 }; | 196 }; |
| 195 | 197 |
| 196 IN_PROC_BROWSER_TEST_P(ProfileManagerCrOSBrowserTest, GetLastUsedProfile) { | 198 IN_PROC_BROWSER_TEST_F(ProfileManagerCrOSBrowserTest, GetLastUsedProfile) { |
| 197 // Make sure that last used profile is correct. | 199 // Make sure that last used profile is correct. |
| 198 Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); | 200 Profile* last_used_profile = ProfileManager::GetLastUsedProfile(); |
| 199 EXPECT_TRUE(last_used_profile != NULL); | 201 EXPECT_TRUE(last_used_profile != NULL); |
| 200 | 202 |
| 201 base::FilePath profile_path; | 203 base::FilePath profile_path; |
| 202 PathService::Get(chrome::DIR_USER_DATA, &profile_path); | 204 PathService::Get(chrome::DIR_USER_DATA, &profile_path); |
| 203 | 205 |
| 204 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 206 profile_path = profile_path.AppendASCII( |
| 205 if (command_line.HasSwitch(switches::kMultiProfiles)) { | 207 std::string(chrome::kProfileDirPrefix) + "test-user-hash"); |
| 206 profile_path = profile_path.AppendASCII( | |
| 207 std::string(chrome::kProfileDirPrefix) + "test-user-hash"); | |
| 208 } else { | |
| 209 profile_path = profile_path.AppendASCII(chrome::kTestUserProfileDir); | |
| 210 } | |
| 211 EXPECT_EQ(profile_path.value(), last_used_profile->GetPath().value()); | 208 EXPECT_EQ(profile_path.value(), last_used_profile->GetPath().value()); |
| 212 } | 209 } |
| 213 | 210 |
| 214 INSTANTIATE_TEST_CASE_P(ProfileManagerCrOSBrowserTestInstantiation, | |
| 215 ProfileManagerCrOSBrowserTest, | |
| 216 testing::Bool()); | |
| 217 | |
| 218 #endif // OS_CHROMEOS | 211 #endif // OS_CHROMEOS |
| 219 | 212 |
| 220 // Times out (http://crbug.com/159002) | 213 // Times out (http://crbug.com/159002) |
| 221 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, | 214 IN_PROC_BROWSER_TEST_F(ProfileManagerBrowserTest, |
| 222 DISABLED_CreateProfileWithCallback) { | 215 DISABLED_CreateProfileWithCallback) { |
| 223 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 216 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 224 | 217 |
| 225 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); | 218 ASSERT_EQ(profile_manager->GetNumberOfProfiles(), 1U); |
| 226 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); | 219 EXPECT_EQ(chrome::GetTotalBrowserCount(), 1U); |
| 227 | 220 |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 content::RunAllPendingInMessageLoop(); | 361 content::RunAllPendingInMessageLoop(); |
| 369 EXPECT_EQ(2U, browser_list->size()); | 362 EXPECT_EQ(2U, browser_list->size()); |
| 370 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); | 363 ASSERT_EQ(2U, cache.GetNumberOfProfiles()); |
| 371 | 364 |
| 372 // The second should though. | 365 // The second should though. |
| 373 browser_list->get(1)->window()->Close(); | 366 browser_list->get(1)->window()->Close(); |
| 374 content::RunAllPendingInMessageLoop(); | 367 content::RunAllPendingInMessageLoop(); |
| 375 EXPECT_EQ(1U, browser_list->size()); | 368 EXPECT_EQ(1U, browser_list->size()); |
| 376 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); | 369 ASSERT_EQ(1U, cache.GetNumberOfProfiles()); |
| 377 } | 370 } |
| OLD | NEW |