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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 } | 113 } |
114 | 114 |
115 virtual void TearDown() { | 115 virtual void TearDown() { |
116 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 116 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
117 base::RunLoop().RunUntilIdle(); | 117 base::RunLoop().RunUntilIdle(); |
118 } | 118 } |
119 | 119 |
120 // Helper function to create a profile with |name| for a profile |manager|. | 120 // Helper function to create a profile with |name| for a profile |manager|. |
121 void CreateProfileAsync(ProfileManager* manager, | 121 void CreateProfileAsync(ProfileManager* manager, |
122 const std::string& name, | 122 const std::string& name, |
123 bool is_managed, | 123 bool is_supervised, |
124 MockObserver* mock_observer) { | 124 MockObserver* mock_observer) { |
125 manager->CreateProfileAsync( | 125 manager->CreateProfileAsync( |
126 temp_dir_.path().AppendASCII(name), | 126 temp_dir_.path().AppendASCII(name), |
127 base::Bind(&MockObserver::OnProfileCreated, | 127 base::Bind(&MockObserver::OnProfileCreated, |
128 base::Unretained(mock_observer)), | 128 base::Unretained(mock_observer)), |
129 base::UTF8ToUTF16(name), | 129 base::UTF8ToUTF16(name), |
130 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(0)), | 130 base::UTF8ToUTF16(profiles::GetDefaultAvatarIconUrl(0)), |
131 is_managed ? "Dummy ID" : std::string()); | 131 is_supervised ? "Dummy ID" : std::string()); |
132 } | 132 } |
133 | 133 |
134 // Helper function to add a profile with |profile_name| to | 134 // Helper function to add a profile with |profile_name| to |
135 // |profile_manager|'s ProfileInfoCache, and return the profile created. | 135 // |profile_manager|'s ProfileInfoCache, and return the profile created. |
136 Profile* AddProfileToCache(ProfileManager* profile_manager, | 136 Profile* AddProfileToCache(ProfileManager* profile_manager, |
137 const std::string& path_suffix, | 137 const std::string& path_suffix, |
138 const base::string16& profile_name) { | 138 const base::string16& profile_name) { |
139 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 139 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
140 size_t num_profiles = cache.GetNumberOfProfiles(); | 140 size_t num_profiles = cache.GetNumberOfProfiles(); |
141 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); | 141 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 296 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
297 | 297 |
298 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 298 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
299 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); | 299 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); |
300 | 300 |
301 base::RunLoop().RunUntilIdle(); | 301 base::RunLoop().RunUntilIdle(); |
302 } | 302 } |
303 | 303 |
304 TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { | 304 TEST_F(ProfileManagerTest, CreateProfileAsyncCheckOmitted) { |
305 std::string name = "Managed Profile"; | 305 std::string name = "0 Supervised Profile"; |
306 | 306 |
307 MockObserver mock_observer; | 307 MockObserver mock_observer; |
308 EXPECT_CALL(mock_observer, OnProfileCreated( | 308 EXPECT_CALL(mock_observer, OnProfileCreated( |
309 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 309 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
310 | 310 |
311 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 311 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
312 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 312 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
313 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 313 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
314 | 314 |
315 CreateProfileAsync(profile_manager, name, true, &mock_observer); | 315 CreateProfileAsync(profile_manager, name, true, &mock_observer); |
316 base::RunLoop().RunUntilIdle(); | 316 base::RunLoop().RunUntilIdle(); |
317 | 317 |
318 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); | 318 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); |
319 // Managed profiles should start out omitted from the profile list. | 319 // Supervised profiles should start out omitted from the profile list. |
320 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); | 320 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); |
321 | 321 |
322 name = "Regular Profile"; | 322 name = "1 Regular Profile"; |
323 CreateProfileAsync(profile_manager, name, false, &mock_observer); | 323 CreateProfileAsync(profile_manager, name, false, &mock_observer); |
324 base::RunLoop().RunUntilIdle(); | 324 base::RunLoop().RunUntilIdle(); |
325 | 325 |
326 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 326 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); |
327 // Non-managed profiles should be included in the profile list. | 327 // Non-supervised profiles should be included in the profile list. |
328 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(1)); | 328 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(1)); |
329 } | 329 } |
330 | 330 |
331 TEST_F(ProfileManagerTest, AddProfileToCacheCheckOmitted) { | 331 TEST_F(ProfileManagerTest, AddProfileToCacheCheckOmitted) { |
332 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 332 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
333 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); | 333 ProfileInfoCache& cache = profile_manager->GetProfileInfoCache(); |
334 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); | 334 EXPECT_EQ(0u, cache.GetNumberOfProfiles()); |
335 | 335 |
336 const base::FilePath managed_path = temp_dir_.path().AppendASCII("Managed"); | 336 const base::FilePath supervised_path = |
337 TestingProfile* managed_profile = new TestingProfile(managed_path, NULL); | 337 temp_dir_.path().AppendASCII("Supervised"); |
338 managed_profile->GetPrefs()->SetString(prefs::kManagedUserId, "An ID"); | 338 TestingProfile* supervised_profile = |
| 339 new TestingProfile(supervised_path, NULL); |
| 340 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); |
339 | 341 |
340 // RegisterTestingProfile adds the profile to the cache and takes ownership. | 342 // RegisterTestingProfile adds the profile to the cache and takes ownership. |
341 profile_manager->RegisterTestingProfile(managed_profile, true, false); | 343 profile_manager->RegisterTestingProfile(supervised_profile, true, false); |
342 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); | 344 EXPECT_EQ(1u, cache.GetNumberOfProfiles()); |
343 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); | 345 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(0)); |
344 | 346 |
345 const base::FilePath nonmanaged_path = temp_dir_.path().AppendASCII( | 347 const base::FilePath nonsupervised_path = temp_dir_.path().AppendASCII( |
346 "Non-Managed"); | 348 "Non-Supervised"); |
347 TestingProfile* nonmanaged_profile = new TestingProfile(nonmanaged_path, | 349 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, |
348 NULL); | 350 NULL); |
349 profile_manager->RegisterTestingProfile(nonmanaged_profile, true, false); | 351 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); |
350 | 352 |
351 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); | 353 EXPECT_EQ(2u, cache.GetNumberOfProfiles()); |
352 size_t managed_index = cache.GetIndexOfProfileWithPath(managed_path); | 354 size_t supervised_index = cache.GetIndexOfProfileWithPath(supervised_path); |
353 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(managed_index)); | 355 EXPECT_TRUE(cache.IsOmittedProfileAtIndex(supervised_index)); |
354 size_t nonmanaged_index = cache.GetIndexOfProfileWithPath(nonmanaged_path); | 356 size_t nonsupervised_index = |
355 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(nonmanaged_index)); | 357 cache.GetIndexOfProfileWithPath(nonsupervised_path); |
| 358 EXPECT_FALSE(cache.IsOmittedProfileAtIndex(nonsupervised_index)); |
356 } | 359 } |
357 | 360 |
358 TEST_F(ProfileManagerTest, GetGuestProfilePath) { | 361 TEST_F(ProfileManagerTest, GetGuestProfilePath) { |
359 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); | 362 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); |
360 base::FilePath expected_path = temp_dir_.path(); | 363 base::FilePath expected_path = temp_dir_.path(); |
361 expected_path = expected_path.Append(chrome::kGuestProfileDir); | 364 expected_path = expected_path.Append(chrome::kGuestProfileDir); |
362 EXPECT_EQ(expected_path, guest_path); | 365 EXPECT_EQ(expected_path, guest_path); |
363 } | 366 } |
364 | 367 |
365 class UnittestGuestProfileManager : public UnittestProfileManager { | 368 class UnittestGuestProfileManager : public UnittestProfileManager { |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1098 dest_path2.BaseName().MaybeAsASCII()); | 1101 dest_path2.BaseName().MaybeAsASCII()); |
1099 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1102 profile_manager->ScheduleProfileForDeletion(dest_path2, |
1100 ProfileManager::CreateCallback()); | 1103 ProfileManager::CreateCallback()); |
1101 // Spin the message loop so that all the callbacks can finish running. | 1104 // Spin the message loop so that all the callbacks can finish running. |
1102 base::RunLoop().RunUntilIdle(); | 1105 base::RunLoop().RunUntilIdle(); |
1103 | 1106 |
1104 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1107 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
1105 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1108 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
1106 } | 1109 } |
1107 #endif // !defined(OS_MACOSX) | 1110 #endif // !defined(OS_MACOSX) |
OLD | NEW |