| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 ProfileManagerTest() | 128 ProfileManagerTest() |
| 129 : local_state_(TestingBrowserProcess::GetGlobal()) { | 129 : local_state_(TestingBrowserProcess::GetGlobal()) { |
| 130 } | 130 } |
| 131 | 131 |
| 132 void SetUp() override { | 132 void SetUp() override { |
| 133 // Create a new temporary directory, and store the path | 133 // Create a new temporary directory, and store the path |
| 134 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 134 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 135 TestingBrowserProcess::GetGlobal()->SetProfileManager( | 135 TestingBrowserProcess::GetGlobal()->SetProfileManager( |
| 136 new UnittestProfileManager(temp_dir_.path())); | 136 new UnittestProfileManager(temp_dir_.GetPath())); |
| 137 | 137 |
| 138 #if defined(OS_CHROMEOS) | 138 #if defined(OS_CHROMEOS) |
| 139 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 139 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 140 cl->AppendSwitch(switches::kTestType); | 140 cl->AppendSwitch(switches::kTestType); |
| 141 chromeos::WallpaperManager::Initialize(); | 141 chromeos::WallpaperManager::Initialize(); |
| 142 #endif | 142 #endif |
| 143 } | 143 } |
| 144 | 144 |
| 145 void TearDown() override { | 145 void TearDown() override { |
| 146 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); | 146 TestingBrowserProcess::GetGlobal()->SetProfileManager(NULL); |
| 147 base::RunLoop().RunUntilIdle(); | 147 base::RunLoop().RunUntilIdle(); |
| 148 #if defined(OS_CHROMEOS) | 148 #if defined(OS_CHROMEOS) |
| 149 chromeos::WallpaperManager::Shutdown(); | 149 chromeos::WallpaperManager::Shutdown(); |
| 150 #endif | 150 #endif |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Helper function to create a profile with |name| for a profile |manager|. | 153 // Helper function to create a profile with |name| for a profile |manager|. |
| 154 void CreateProfileAsync(ProfileManager* manager, | 154 void CreateProfileAsync(ProfileManager* manager, |
| 155 const std::string& name, | 155 const std::string& name, |
| 156 bool is_supervised, | 156 bool is_supervised, |
| 157 MockObserver* mock_observer) { | 157 MockObserver* mock_observer) { |
| 158 manager->CreateProfileAsync( | 158 manager->CreateProfileAsync(temp_dir_.GetPath().AppendASCII(name), |
| 159 temp_dir_.path().AppendASCII(name), | 159 base::Bind(&MockObserver::OnProfileCreated, |
| 160 base::Bind(&MockObserver::OnProfileCreated, | 160 base::Unretained(mock_observer)), |
| 161 base::Unretained(mock_observer)), | 161 base::UTF8ToUTF16(name), |
| 162 base::UTF8ToUTF16(name), | 162 profiles::GetDefaultAvatarIconUrl(0), |
| 163 profiles::GetDefaultAvatarIconUrl(0), | 163 is_supervised ? "Dummy ID" : std::string()); |
| 164 is_supervised ? "Dummy ID" : std::string()); | |
| 165 } | 164 } |
| 166 | 165 |
| 167 // Helper function to add a profile with |profile_name| to |profile_manager|'s | 166 // Helper function to add a profile with |profile_name| to |profile_manager|'s |
| 168 // ProfileAttributesStorage, and return the profile created. | 167 // ProfileAttributesStorage, and return the profile created. |
| 169 Profile* AddProfileToStorage(ProfileManager* profile_manager, | 168 Profile* AddProfileToStorage(ProfileManager* profile_manager, |
| 170 const std::string& path_suffix, | 169 const std::string& path_suffix, |
| 171 const base::string16& profile_name) { | 170 const base::string16& profile_name) { |
| 172 ProfileAttributesStorage& storage = | 171 ProfileAttributesStorage& storage = |
| 173 profile_manager->GetProfileAttributesStorage(); | 172 profile_manager->GetProfileAttributesStorage(); |
| 174 size_t num_profiles = storage.GetNumberOfProfiles(); | 173 size_t num_profiles = storage.GetNumberOfProfiles(); |
| 175 base::FilePath path = temp_dir_.path().AppendASCII(path_suffix); | 174 base::FilePath path = temp_dir_.GetPath().AppendASCII(path_suffix); |
| 176 storage.AddProfile(path, profile_name, std::string(), base::string16(), 0, | 175 storage.AddProfile(path, profile_name, std::string(), base::string16(), 0, |
| 177 std::string()); | 176 std::string()); |
| 178 EXPECT_EQ(num_profiles + 1u, storage.GetNumberOfProfiles()); | 177 EXPECT_EQ(num_profiles + 1u, storage.GetNumberOfProfiles()); |
| 179 return profile_manager->GetProfile(path); | 178 return profile_manager->GetProfile(path); |
| 180 } | 179 } |
| 181 | 180 |
| 182 #if defined(OS_CHROMEOS) | 181 #if defined(OS_CHROMEOS) |
| 183 // Helper function to register an user with id |user_id| and create profile | 182 // Helper function to register an user with id |user_id| and create profile |
| 184 // with a correct path. | 183 // with a correct path. |
| 185 void RegisterUser(const std::string& user_id) { | 184 void RegisterUser(const std::string& user_id) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 203 content::TestBrowserThreadBundle thread_bundle_; | 202 content::TestBrowserThreadBundle thread_bundle_; |
| 204 | 203 |
| 205 #if defined(OS_CHROMEOS) | 204 #if defined(OS_CHROMEOS) |
| 206 chromeos::ScopedTestUserManager test_user_manager_; | 205 chromeos::ScopedTestUserManager test_user_manager_; |
| 207 #endif | 206 #endif |
| 208 | 207 |
| 209 DISALLOW_COPY_AND_ASSIGN(ProfileManagerTest); | 208 DISALLOW_COPY_AND_ASSIGN(ProfileManagerTest); |
| 210 }; | 209 }; |
| 211 | 210 |
| 212 TEST_F(ProfileManagerTest, GetProfile) { | 211 TEST_F(ProfileManagerTest, GetProfile) { |
| 213 base::FilePath dest_path = temp_dir_.path(); | 212 base::FilePath dest_path = temp_dir_.GetPath(); |
| 214 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 213 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 215 | 214 |
| 216 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 215 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 217 | 216 |
| 218 // Successfully create a profile. | 217 // Successfully create a profile. |
| 219 Profile* profile = profile_manager->GetProfile(dest_path); | 218 Profile* profile = profile_manager->GetProfile(dest_path); |
| 220 EXPECT_TRUE(profile); | 219 EXPECT_TRUE(profile); |
| 221 | 220 |
| 222 // The profile already exists when we call GetProfile. Just load it. | 221 // The profile already exists when we call GetProfile. Just load it. |
| 223 EXPECT_EQ(profile, profile_manager->GetProfile(dest_path)); | 222 EXPECT_EQ(profile, profile_manager->GetProfile(dest_path)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 user_manager->SwitchActiveUser(test_account_id); | 263 user_manager->SwitchActiveUser(test_account_id); |
| 265 | 264 |
| 266 profile_manager->Observe( | 265 profile_manager->Observe( |
| 267 chrome::NOTIFICATION_LOGIN_USER_CHANGED, | 266 chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
| 268 content::NotificationService::AllSources(), | 267 content::NotificationService::AllSources(), |
| 269 content::Details<const user_manager::User>(active_user)); | 268 content::Details<const user_manager::User>(active_user)); |
| 270 base::FilePath expected_logged_in( | 269 base::FilePath expected_logged_in( |
| 271 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); | 270 chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); |
| 272 EXPECT_EQ(expected_logged_in.value(), | 271 EXPECT_EQ(expected_logged_in.value(), |
| 273 profile_manager->GetInitialProfileDir().value()); | 272 profile_manager->GetInitialProfileDir().value()); |
| 274 VLOG(1) << temp_dir_.path().Append( | 273 VLOG(1) << temp_dir_.GetPath() |
| 275 profile_manager->GetInitialProfileDir()).value(); | 274 .Append(profile_manager->GetInitialProfileDir()) |
| 275 .value(); |
| 276 } | 276 } |
| 277 | 277 |
| 278 #endif | 278 #endif |
| 279 | 279 |
| 280 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { | 280 TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
| 281 base::FilePath dest_path1 = temp_dir_.path(); | 281 base::FilePath dest_path1 = temp_dir_.GetPath(); |
| 282 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 282 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 283 | 283 |
| 284 base::FilePath dest_path2 = temp_dir_.path(); | 284 base::FilePath dest_path2 = temp_dir_.GetPath(); |
| 285 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 285 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 286 | 286 |
| 287 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 287 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 288 | 288 |
| 289 // Successfully create the profiles. | 289 // Successfully create the profiles. |
| 290 TestingProfile* profile1 = | 290 TestingProfile* profile1 = |
| 291 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 291 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 292 ASSERT_TRUE(profile1); | 292 ASSERT_TRUE(profile1); |
| 293 | 293 |
| 294 TestingProfile* profile2 = | 294 TestingProfile* profile2 = |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 EXPECT_FALSE(storage.GetAllProfilesAttributesSortedByName()[1u]->IsOmitted()); | 436 EXPECT_FALSE(storage.GetAllProfilesAttributesSortedByName()[1u]->IsOmitted()); |
| 437 } | 437 } |
| 438 | 438 |
| 439 TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { | 439 TEST_F(ProfileManagerTest, AddProfileToStorageCheckOmitted) { |
| 440 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 440 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 441 ProfileAttributesStorage& storage = | 441 ProfileAttributesStorage& storage = |
| 442 profile_manager->GetProfileAttributesStorage(); | 442 profile_manager->GetProfileAttributesStorage(); |
| 443 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); | 443 EXPECT_EQ(0u, storage.GetNumberOfProfiles()); |
| 444 | 444 |
| 445 const base::FilePath supervised_path = | 445 const base::FilePath supervised_path = |
| 446 temp_dir_.path().AppendASCII("Supervised"); | 446 temp_dir_.GetPath().AppendASCII("Supervised"); |
| 447 TestingProfile* supervised_profile = | 447 TestingProfile* supervised_profile = |
| 448 new TestingProfile(supervised_path, NULL); | 448 new TestingProfile(supervised_path, NULL); |
| 449 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); | 449 supervised_profile->GetPrefs()->SetString(prefs::kSupervisedUserId, "An ID"); |
| 450 | 450 |
| 451 // RegisterTestingProfile adds the profile to the cache and takes ownership. | 451 // RegisterTestingProfile adds the profile to the cache and takes ownership. |
| 452 profile_manager->RegisterTestingProfile(supervised_profile, true, false); | 452 profile_manager->RegisterTestingProfile(supervised_profile, true, false); |
| 453 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); | 453 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 454 EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0u]->IsOmitted()); | 454 EXPECT_TRUE(storage.GetAllProfilesAttributesSortedByName()[0u]->IsOmitted()); |
| 455 | 455 |
| 456 const base::FilePath nonsupervised_path = temp_dir_.path().AppendASCII( | 456 const base::FilePath nonsupervised_path = |
| 457 "Non-Supervised"); | 457 temp_dir_.GetPath().AppendASCII("Non-Supervised"); |
| 458 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, | 458 TestingProfile* nonsupervised_profile = new TestingProfile(nonsupervised_path, |
| 459 NULL); | 459 NULL); |
| 460 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); | 460 profile_manager->RegisterTestingProfile(nonsupervised_profile, true, false); |
| 461 | 461 |
| 462 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); | 462 EXPECT_EQ(2u, storage.GetNumberOfProfiles()); |
| 463 ProfileAttributesEntry* entry; | 463 ProfileAttributesEntry* entry; |
| 464 ASSERT_TRUE(storage.GetProfileAttributesWithPath(supervised_path, &entry)); | 464 ASSERT_TRUE(storage.GetProfileAttributesWithPath(supervised_path, &entry)); |
| 465 EXPECT_TRUE(entry->IsOmitted()); | 465 EXPECT_TRUE(entry->IsOmitted()); |
| 466 | 466 |
| 467 ASSERT_TRUE(storage.GetProfileAttributesWithPath(nonsupervised_path, &entry)); | 467 ASSERT_TRUE(storage.GetProfileAttributesWithPath(nonsupervised_path, &entry)); |
| 468 EXPECT_FALSE(entry->IsOmitted()); | 468 EXPECT_FALSE(entry->IsOmitted()); |
| 469 } | 469 } |
| 470 | 470 |
| 471 TEST_F(ProfileManagerTest, GetGuestProfilePath) { | 471 TEST_F(ProfileManagerTest, GetGuestProfilePath) { |
| 472 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); | 472 base::FilePath guest_path = ProfileManager::GetGuestProfilePath(); |
| 473 base::FilePath expected_path = temp_dir_.path(); | 473 base::FilePath expected_path = temp_dir_.GetPath(); |
| 474 expected_path = expected_path.Append(chrome::kGuestProfileDir); | 474 expected_path = expected_path.Append(chrome::kGuestProfileDir); |
| 475 EXPECT_EQ(expected_path, guest_path); | 475 EXPECT_EQ(expected_path, guest_path); |
| 476 } | 476 } |
| 477 | 477 |
| 478 TEST_F(ProfileManagerTest, GetSystemProfilePath) { | 478 TEST_F(ProfileManagerTest, GetSystemProfilePath) { |
| 479 base::FilePath system_profile_path = ProfileManager::GetSystemProfilePath(); | 479 base::FilePath system_profile_path = ProfileManager::GetSystemProfilePath(); |
| 480 base::FilePath expected_path = temp_dir_.path(); | 480 base::FilePath expected_path = temp_dir_.GetPath(); |
| 481 expected_path = expected_path.Append(chrome::kSystemProfileDir); | 481 expected_path = expected_path.Append(chrome::kSystemProfileDir); |
| 482 EXPECT_EQ(expected_path, system_profile_path); | 482 EXPECT_EQ(expected_path, system_profile_path); |
| 483 } | 483 } |
| 484 | 484 |
| 485 class UnittestGuestProfileManager : public UnittestProfileManager { | 485 class UnittestGuestProfileManager : public UnittestProfileManager { |
| 486 public: | 486 public: |
| 487 explicit UnittestGuestProfileManager(const base::FilePath& user_data_dir) | 487 explicit UnittestGuestProfileManager(const base::FilePath& user_data_dir) |
| 488 : UnittestProfileManager(user_data_dir) {} | 488 : UnittestProfileManager(user_data_dir) {} |
| 489 | 489 |
| 490 protected: | 490 protected: |
| 491 Profile* CreateProfileHelper(const base::FilePath& file_path) override { | 491 Profile* CreateProfileHelper(const base::FilePath& file_path) override { |
| 492 TestingProfile::Builder builder; | 492 TestingProfile::Builder builder; |
| 493 builder.SetGuestSession(); | 493 builder.SetGuestSession(); |
| 494 builder.SetPath(file_path); | 494 builder.SetPath(file_path); |
| 495 TestingProfile* testing_profile = builder.Build().release(); | 495 TestingProfile* testing_profile = builder.Build().release(); |
| 496 return testing_profile; | 496 return testing_profile; |
| 497 } | 497 } |
| 498 }; | 498 }; |
| 499 | 499 |
| 500 class ProfileManagerGuestTest : public ProfileManagerTest { | 500 class ProfileManagerGuestTest : public ProfileManagerTest { |
| 501 protected: | 501 protected: |
| 502 void SetUp() override { | 502 void SetUp() override { |
| 503 // Create a new temporary directory, and store the path | 503 // Create a new temporary directory, and store the path |
| 504 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 504 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 505 TestingBrowserProcess::GetGlobal()->SetProfileManager( | 505 TestingBrowserProcess::GetGlobal()->SetProfileManager( |
| 506 new UnittestGuestProfileManager(temp_dir_.path())); | 506 new UnittestGuestProfileManager(temp_dir_.GetPath())); |
| 507 | 507 |
| 508 #if defined(OS_CHROMEOS) | 508 #if defined(OS_CHROMEOS) |
| 509 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); | 509 base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
| 510 // This switch is needed to skip non-test specific behavior in | 510 // This switch is needed to skip non-test specific behavior in |
| 511 // ProfileManager (accessing DBusThreadManager). | 511 // ProfileManager (accessing DBusThreadManager). |
| 512 cl->AppendSwitch(switches::kTestType); | 512 cl->AppendSwitch(switches::kTestType); |
| 513 | 513 |
| 514 cl->AppendSwitch(chromeos::switches::kGuestSession); | 514 cl->AppendSwitch(chromeos::switches::kGuestSession); |
| 515 cl->AppendSwitch(::switches::kIncognito); | 515 cl->AppendSwitch(::switches::kIncognito); |
| 516 | 516 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 storage.GetAllProfilesAttributes(); | 601 storage.GetAllProfilesAttributes(); |
| 602 entries[0u]->SetBackgroundStatus(false); | 602 entries[0u]->SetBackgroundStatus(false); |
| 603 entries[1u]->SetBackgroundStatus(true); | 603 entries[1u]->SetBackgroundStatus(true); |
| 604 | 604 |
| 605 profile_manager->AutoloadProfiles(); | 605 profile_manager->AutoloadProfiles(); |
| 606 | 606 |
| 607 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); | 607 EXPECT_EQ(0u, profile_manager->GetLoadedProfiles().size()); |
| 608 } | 608 } |
| 609 | 609 |
| 610 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { | 610 TEST_F(ProfileManagerTest, InitProfileUserPrefs) { |
| 611 base::FilePath dest_path = temp_dir_.path(); | 611 base::FilePath dest_path = temp_dir_.GetPath(); |
| 612 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 612 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 613 | 613 |
| 614 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 614 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 615 | 615 |
| 616 Profile* profile; | 616 Profile* profile; |
| 617 | 617 |
| 618 // Successfully create the profile | 618 // Successfully create the profile |
| 619 profile = profile_manager->GetProfile(dest_path); | 619 profile = profile_manager->GetProfile(dest_path); |
| 620 ASSERT_TRUE(profile); | 620 ASSERT_TRUE(profile); |
| 621 | 621 |
| 622 // Check that the profile name is non empty | 622 // Check that the profile name is non empty |
| 623 std::string profile_name = | 623 std::string profile_name = |
| 624 profile->GetPrefs()->GetString(prefs::kProfileName); | 624 profile->GetPrefs()->GetString(prefs::kProfileName); |
| 625 EXPECT_FALSE(profile_name.empty()); | 625 EXPECT_FALSE(profile_name.empty()); |
| 626 | 626 |
| 627 // Check that the profile avatar index is valid | 627 // Check that the profile avatar index is valid |
| 628 size_t avatar_index = | 628 size_t avatar_index = |
| 629 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); | 629 profile->GetPrefs()->GetInteger(prefs::kProfileAvatarIndex); |
| 630 EXPECT_TRUE(profiles::IsDefaultAvatarIconIndex( | 630 EXPECT_TRUE(profiles::IsDefaultAvatarIconIndex( |
| 631 avatar_index)); | 631 avatar_index)); |
| 632 } | 632 } |
| 633 | 633 |
| 634 // Tests that a new profile's entry in the profile info cache is setup with the | 634 // Tests that a new profile's entry in the profile info cache is setup with the |
| 635 // same values that are in the profile prefs. | 635 // same values that are in the profile prefs. |
| 636 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { | 636 TEST_F(ProfileManagerTest, InitProfileInfoCacheForAProfile) { |
| 637 base::FilePath dest_path = temp_dir_.path(); | 637 base::FilePath dest_path = temp_dir_.GetPath(); |
| 638 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); | 638 dest_path = dest_path.Append(FILE_PATH_LITERAL("New Profile")); |
| 639 | 639 |
| 640 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 640 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 641 | 641 |
| 642 // Successfully create the profile | 642 // Successfully create the profile |
| 643 Profile* profile = profile_manager->GetProfile(dest_path); | 643 Profile* profile = profile_manager->GetProfile(dest_path); |
| 644 ASSERT_TRUE(profile); | 644 ASSERT_TRUE(profile); |
| 645 | 645 |
| 646 std::string profile_name = | 646 std::string profile_name = |
| 647 profile->GetPrefs()->GetString(prefs::kProfileName); | 647 profile->GetPrefs()->GetString(prefs::kProfileName); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when | 684 // GetLastUsedProfileAllowedByPolicy() returns the incognito Profile when |
| 685 // incognito mode is forced. | 685 // incognito mode is forced. |
| 686 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); | 686 IncognitoModePrefs::SetAvailability(prefs, IncognitoModePrefs::FORCED); |
| 687 EXPECT_TRUE( | 687 EXPECT_TRUE( |
| 688 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); | 688 profile_manager->GetLastUsedProfileAllowedByPolicy()->IsOffTheRecord()); |
| 689 } | 689 } |
| 690 | 690 |
| 691 #if !defined(OS_ANDROID) | 691 #if !defined(OS_ANDROID) |
| 692 // There's no Browser object on Android. | 692 // There's no Browser object on Android. |
| 693 TEST_F(ProfileManagerTest, LastOpenedProfiles) { | 693 TEST_F(ProfileManagerTest, LastOpenedProfiles) { |
| 694 base::FilePath dest_path1 = temp_dir_.path(); | 694 base::FilePath dest_path1 = temp_dir_.GetPath(); |
| 695 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 695 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 696 | 696 |
| 697 base::FilePath dest_path2 = temp_dir_.path(); | 697 base::FilePath dest_path2 = temp_dir_.GetPath(); |
| 698 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 698 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 699 | 699 |
| 700 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 700 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 701 | 701 |
| 702 // Successfully create the profiles. | 702 // Successfully create the profiles. |
| 703 TestingProfile* profile1 = | 703 TestingProfile* profile1 = |
| 704 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 704 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 705 ASSERT_TRUE(profile1); | 705 ASSERT_TRUE(profile1); |
| 706 | 706 |
| 707 TestingProfile* profile2 = | 707 TestingProfile* profile2 = |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 750 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 751 ASSERT_EQ(1U, last_opened_profiles.size()); | 751 ASSERT_EQ(1U, last_opened_profiles.size()); |
| 752 EXPECT_EQ(profile2, last_opened_profiles[0]); | 752 EXPECT_EQ(profile2, last_opened_profiles[0]); |
| 753 | 753 |
| 754 browser2.reset(); | 754 browser2.reset(); |
| 755 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 755 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 756 ASSERT_EQ(0U, last_opened_profiles.size()); | 756 ASSERT_EQ(0U, last_opened_profiles.size()); |
| 757 } | 757 } |
| 758 | 758 |
| 759 TEST_F(ProfileManagerTest, LastOpenedProfilesAtShutdown) { | 759 TEST_F(ProfileManagerTest, LastOpenedProfilesAtShutdown) { |
| 760 base::FilePath dest_path1 = temp_dir_.path(); | 760 base::FilePath dest_path1 = temp_dir_.GetPath(); |
| 761 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 761 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 762 | 762 |
| 763 base::FilePath dest_path2 = temp_dir_.path(); | 763 base::FilePath dest_path2 = temp_dir_.GetPath(); |
| 764 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 764 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 765 | 765 |
| 766 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 766 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 767 | 767 |
| 768 // Successfully create the profiles. | 768 // Successfully create the profiles. |
| 769 TestingProfile* profile1 = | 769 TestingProfile* profile1 = |
| 770 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 770 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 771 ASSERT_TRUE(profile1); | 771 ASSERT_TRUE(profile1); |
| 772 | 772 |
| 773 TestingProfile* profile2 = | 773 TestingProfile* profile2 = |
| (...skipping 27 matching lines...) Expand all Loading... |
| 801 browser1.reset(); | 801 browser1.reset(); |
| 802 browser2.reset(); | 802 browser2.reset(); |
| 803 | 803 |
| 804 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 804 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 805 ASSERT_EQ(2U, last_opened_profiles.size()); | 805 ASSERT_EQ(2U, last_opened_profiles.size()); |
| 806 EXPECT_EQ(profile1, last_opened_profiles[0]); | 806 EXPECT_EQ(profile1, last_opened_profiles[0]); |
| 807 EXPECT_EQ(profile2, last_opened_profiles[1]); | 807 EXPECT_EQ(profile2, last_opened_profiles[1]); |
| 808 } | 808 } |
| 809 | 809 |
| 810 TEST_F(ProfileManagerTest, LastOpenedProfilesDoesNotContainIncognito) { | 810 TEST_F(ProfileManagerTest, LastOpenedProfilesDoesNotContainIncognito) { |
| 811 base::FilePath dest_path1 = temp_dir_.path(); | 811 base::FilePath dest_path1 = temp_dir_.GetPath(); |
| 812 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); | 812 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("New Profile 1")); |
| 813 base::FilePath dest_path2 = temp_dir_.path(); | 813 base::FilePath dest_path2 = temp_dir_.GetPath(); |
| 814 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); | 814 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("New Profile 2")); |
| 815 | 815 |
| 816 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 816 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 817 | 817 |
| 818 // Successfully create the profiles. | 818 // Successfully create the profiles. |
| 819 TestingProfile* profile1 = | 819 TestingProfile* profile1 = |
| 820 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 820 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 821 ASSERT_TRUE(profile1); | 821 ASSERT_TRUE(profile1); |
| 822 | 822 |
| 823 std::vector<Profile*> last_opened_profiles = | 823 std::vector<Profile*> last_opened_profiles = |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 | 862 |
| 863 browser1.reset(); | 863 browser1.reset(); |
| 864 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); | 864 last_opened_profiles = profile_manager->GetLastOpenedProfiles(); |
| 865 ASSERT_EQ(0U, last_opened_profiles.size()); | 865 ASSERT_EQ(0U, last_opened_profiles.size()); |
| 866 } | 866 } |
| 867 #endif // !defined(OS_ANDROID) | 867 #endif // !defined(OS_ANDROID) |
| 868 | 868 |
| 869 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) | 869 #if !defined(OS_ANDROID) && !defined(OS_CHROMEOS) |
| 870 // There's no Browser object on Android and there's no multi-profiles on Chrome. | 870 // There's no Browser object on Android and there's no multi-profiles on Chrome. |
| 871 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastProfile) { | 871 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastProfile) { |
| 872 base::FilePath dest_path = temp_dir_.path(); | 872 base::FilePath dest_path = temp_dir_.GetPath(); |
| 873 dest_path = dest_path.Append(FILE_PATH_LITERAL("Ephemeral Profile")); | 873 dest_path = dest_path.Append(FILE_PATH_LITERAL("Ephemeral Profile")); |
| 874 | 874 |
| 875 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 875 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 876 | 876 |
| 877 TestingProfile* profile = | 877 TestingProfile* profile = |
| 878 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); | 878 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path)); |
| 879 ASSERT_TRUE(profile); | 879 ASSERT_TRUE(profile); |
| 880 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); | 880 profile->GetPrefs()->SetBoolean(prefs::kForceEphemeralProfiles, true); |
| 881 | 881 |
| 882 // Here the last used profile is still the "Default" profile. | 882 // Here the last used profile is still the "Default" profile. |
| 883 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); | 883 Profile* last_used_profile = profile_manager->GetLastUsedProfile(); |
| 884 EXPECT_NE(profile, last_used_profile); | 884 EXPECT_NE(profile, last_used_profile); |
| 885 | 885 |
| 886 // Create a browser for the profile. | 886 // Create a browser for the profile. |
| 887 Browser::CreateParams profile_params(profile); | 887 Browser::CreateParams profile_params(profile); |
| 888 std::unique_ptr<Browser> browser( | 888 std::unique_ptr<Browser> browser( |
| 889 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); | 889 chrome::CreateBrowserWithTestWindowForParams(&profile_params)); |
| 890 last_used_profile = profile_manager->GetLastUsedProfile(); | 890 last_used_profile = profile_manager->GetLastUsedProfile(); |
| 891 EXPECT_NE(profile, last_used_profile); | 891 EXPECT_NE(profile, last_used_profile); |
| 892 | 892 |
| 893 // Close the browser. | 893 // Close the browser. |
| 894 browser.reset(); | 894 browser.reset(); |
| 895 last_used_profile = profile_manager->GetLastUsedProfile(); | 895 last_used_profile = profile_manager->GetLastUsedProfile(); |
| 896 EXPECT_NE(profile, last_used_profile); | 896 EXPECT_NE(profile, last_used_profile); |
| 897 } | 897 } |
| 898 | 898 |
| 899 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastOpenedAtShutdown) { | 899 TEST_F(ProfileManagerTest, EphemeralProfilesDontEndUpAsLastOpenedAtShutdown) { |
| 900 base::FilePath dest_path1 = temp_dir_.path(); | 900 base::FilePath dest_path1 = temp_dir_.GetPath(); |
| 901 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("Normal Profile")); | 901 dest_path1 = dest_path1.Append(FILE_PATH_LITERAL("Normal Profile")); |
| 902 | 902 |
| 903 base::FilePath dest_path2 = temp_dir_.path(); | 903 base::FilePath dest_path2 = temp_dir_.GetPath(); |
| 904 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("Ephemeral Profile 1")); | 904 dest_path2 = dest_path2.Append(FILE_PATH_LITERAL("Ephemeral Profile 1")); |
| 905 | 905 |
| 906 base::FilePath dest_path3 = temp_dir_.path(); | 906 base::FilePath dest_path3 = temp_dir_.GetPath(); |
| 907 dest_path3 = dest_path3.Append(FILE_PATH_LITERAL("Ephemeral Profile 2")); | 907 dest_path3 = dest_path3.Append(FILE_PATH_LITERAL("Ephemeral Profile 2")); |
| 908 | 908 |
| 909 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 909 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 910 | 910 |
| 911 // Successfully create the profiles. | 911 // Successfully create the profiles. |
| 912 TestingProfile* normal_profile = | 912 TestingProfile* normal_profile = |
| 913 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); | 913 static_cast<TestingProfile*>(profile_manager->GetProfile(dest_path1)); |
| 914 ASSERT_TRUE(normal_profile); | 914 ASSERT_TRUE(normal_profile); |
| 915 | 915 |
| 916 // Add one ephemeral profile which should not end up in this list. | 916 // Add one ephemeral profile which should not end up in this list. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1011 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); | 1011 EXPECT_EQ("Profile 1", local_state->GetString(prefs::kProfileLastUsed)); |
| 1012 } | 1012 } |
| 1013 | 1013 |
| 1014 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { | 1014 TEST_F(ProfileManagerTest, ActiveProfileDeleted) { |
| 1015 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1015 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1016 ASSERT_TRUE(profile_manager); | 1016 ASSERT_TRUE(profile_manager); |
| 1017 | 1017 |
| 1018 // Create and load two profiles. | 1018 // Create and load two profiles. |
| 1019 const std::string profile_name1 = "New Profile 1"; | 1019 const std::string profile_name1 = "New Profile 1"; |
| 1020 const std::string profile_name2 = "New Profile 2"; | 1020 const std::string profile_name2 = "New Profile 2"; |
| 1021 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1021 base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1); |
| 1022 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1022 base::FilePath dest_path2 = temp_dir_.GetPath().AppendASCII(profile_name2); |
| 1023 | 1023 |
| 1024 MockObserver mock_observer; | 1024 MockObserver mock_observer; |
| 1025 EXPECT_CALL(mock_observer, OnProfileCreated( | 1025 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1026 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); | 1026 testing::NotNull(), NotFail())).Times(testing::AtLeast(3)); |
| 1027 | 1027 |
| 1028 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1028 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1029 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); | 1029 CreateProfileAsync(profile_manager, profile_name2, false, &mock_observer); |
| 1030 base::RunLoop().RunUntilIdle(); | 1030 base::RunLoop().RunUntilIdle(); |
| 1031 | 1031 |
| 1032 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); | 1032 EXPECT_EQ(2u, profile_manager->GetLoadedProfiles().size()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1048 } | 1048 } |
| 1049 | 1049 |
| 1050 TEST_F(ProfileManagerTest, LastProfileDeleted) { | 1050 TEST_F(ProfileManagerTest, LastProfileDeleted) { |
| 1051 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1051 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1052 ASSERT_TRUE(profile_manager); | 1052 ASSERT_TRUE(profile_manager); |
| 1053 ProfileAttributesStorage& storage = | 1053 ProfileAttributesStorage& storage = |
| 1054 profile_manager->GetProfileAttributesStorage(); | 1054 profile_manager->GetProfileAttributesStorage(); |
| 1055 | 1055 |
| 1056 // Create and load a profile. | 1056 // Create and load a profile. |
| 1057 const std::string profile_name1 = "New Profile 1"; | 1057 const std::string profile_name1 = "New Profile 1"; |
| 1058 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1058 base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1); |
| 1059 | 1059 |
| 1060 MockObserver mock_observer; | 1060 MockObserver mock_observer; |
| 1061 EXPECT_CALL(mock_observer, OnProfileCreated( | 1061 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1062 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); | 1062 testing::NotNull(), NotFail())).Times(testing::AtLeast(1)); |
| 1063 | 1063 |
| 1064 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1064 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1065 base::RunLoop().RunUntilIdle(); | 1065 base::RunLoop().RunUntilIdle(); |
| 1066 | 1066 |
| 1067 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1067 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1068 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); | 1068 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1069 | 1069 |
| 1070 // Set it as the active profile. | 1070 // Set it as the active profile. |
| 1071 PrefService* local_state = g_browser_process->local_state(); | 1071 PrefService* local_state = g_browser_process->local_state(); |
| 1072 local_state->SetString(prefs::kProfileLastUsed, profile_name1); | 1072 local_state->SetString(prefs::kProfileLastUsed, profile_name1); |
| 1073 | 1073 |
| 1074 // Delete the active profile. | 1074 // Delete the active profile. |
| 1075 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1075 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1076 ProfileManager::CreateCallback()); | 1076 ProfileManager::CreateCallback()); |
| 1077 // Spin the message loop so that all the callbacks can finish running. | 1077 // Spin the message loop so that all the callbacks can finish running. |
| 1078 base::RunLoop().RunUntilIdle(); | 1078 base::RunLoop().RunUntilIdle(); |
| 1079 | 1079 |
| 1080 // A new profile should have been created | 1080 // A new profile should have been created |
| 1081 const std::string profile_name2 = "Profile 1"; | 1081 const std::string profile_name2 = "Profile 1"; |
| 1082 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1082 base::FilePath dest_path2 = temp_dir_.GetPath().AppendASCII(profile_name2); |
| 1083 | 1083 |
| 1084 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); | 1084 EXPECT_EQ(dest_path2, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1085 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); | 1085 EXPECT_EQ(profile_name2, local_state->GetString(prefs::kProfileLastUsed)); |
| 1086 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); | 1086 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { | 1089 TEST_F(ProfileManagerTest, LastProfileDeletedWithGuestActiveProfile) { |
| 1090 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1090 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1091 ASSERT_TRUE(profile_manager); | 1091 ASSERT_TRUE(profile_manager); |
| 1092 ProfileAttributesStorage& storage = | 1092 ProfileAttributesStorage& storage = |
| 1093 profile_manager->GetProfileAttributesStorage(); | 1093 profile_manager->GetProfileAttributesStorage(); |
| 1094 | 1094 |
| 1095 // Create and load a profile. | 1095 // Create and load a profile. |
| 1096 const std::string profile_name1 = "New Profile 1"; | 1096 const std::string profile_name1 = "New Profile 1"; |
| 1097 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1097 base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1); |
| 1098 | 1098 |
| 1099 MockObserver mock_observer; | 1099 MockObserver mock_observer; |
| 1100 EXPECT_CALL(mock_observer, OnProfileCreated( | 1100 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1101 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1101 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1102 | 1102 |
| 1103 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1103 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1104 base::RunLoop().RunUntilIdle(); | 1104 base::RunLoop().RunUntilIdle(); |
| 1105 | 1105 |
| 1106 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); | 1106 EXPECT_EQ(1u, profile_manager->GetLoadedProfiles().size()); |
| 1107 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); | 1107 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1127 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name); | 1127 local_state->SetString(prefs::kProfileLastUsed, guest_profile_name); |
| 1128 | 1128 |
| 1129 // Delete the other profile. | 1129 // Delete the other profile. |
| 1130 profile_manager->ScheduleProfileForDeletion(dest_path1, | 1130 profile_manager->ScheduleProfileForDeletion(dest_path1, |
| 1131 ProfileManager::CreateCallback()); | 1131 ProfileManager::CreateCallback()); |
| 1132 // Spin the message loop so that all the callbacks can finish running. | 1132 // Spin the message loop so that all the callbacks can finish running. |
| 1133 base::RunLoop().RunUntilIdle(); | 1133 base::RunLoop().RunUntilIdle(); |
| 1134 | 1134 |
| 1135 // A new profile should have been created. | 1135 // A new profile should have been created. |
| 1136 const std::string profile_name2 = "Profile 1"; | 1136 const std::string profile_name2 = "Profile 1"; |
| 1137 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1137 base::FilePath dest_path2 = temp_dir_.GetPath().AppendASCII(profile_name2); |
| 1138 | 1138 |
| 1139 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size()); | 1139 EXPECT_EQ(3u, profile_manager->GetLoadedProfiles().size()); |
| 1140 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); | 1140 EXPECT_EQ(1u, storage.GetNumberOfProfiles()); |
| 1141 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); | 1141 EXPECT_EQ(dest_path2, storage.GetAllProfilesAttributes()[0u]->GetPath()); |
| 1142 } | 1142 } |
| 1143 | 1143 |
| 1144 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { | 1144 TEST_F(ProfileManagerTest, ProfileDisplayNameResetsDefaultName) { |
| 1145 if (!profiles::IsMultipleProfilesEnabled()) | 1145 if (!profiles::IsMultipleProfilesEnabled()) |
| 1146 return; | 1146 return; |
| 1147 | 1147 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1344 #if defined(OS_MACOSX) | 1344 #if defined(OS_MACOSX) |
| 1345 // These tests are for a Mac-only code path that assumes the browser | 1345 // These tests are for a Mac-only code path that assumes the browser |
| 1346 // process isn't killed when all browser windows are closed. | 1346 // process isn't killed when all browser windows are closed. |
| 1347 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { | 1347 TEST_F(ProfileManagerTest, ActiveProfileDeletedNeedsToLoadNextProfile) { |
| 1348 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1348 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1349 ASSERT_TRUE(profile_manager); | 1349 ASSERT_TRUE(profile_manager); |
| 1350 | 1350 |
| 1351 // Create and load one profile, and just create a second profile. | 1351 // Create and load one profile, and just create a second profile. |
| 1352 const std::string profile_name1 = "New Profile 1"; | 1352 const std::string profile_name1 = "New Profile 1"; |
| 1353 const std::string profile_name2 = "New Profile 2"; | 1353 const std::string profile_name2 = "New Profile 2"; |
| 1354 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1354 base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1); |
| 1355 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1355 base::FilePath dest_path2 = temp_dir_.GetPath().AppendASCII(profile_name2); |
| 1356 | 1356 |
| 1357 MockObserver mock_observer; | 1357 MockObserver mock_observer; |
| 1358 EXPECT_CALL(mock_observer, OnProfileCreated( | 1358 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1359 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1359 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1360 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1360 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1361 base::RunLoop().RunUntilIdle(); | 1361 base::RunLoop().RunUntilIdle(); |
| 1362 | 1362 |
| 1363 // Track the profile, but don't load it. | 1363 // Track the profile, but don't load it. |
| 1364 ProfileAttributesStorage& storage = | 1364 ProfileAttributesStorage& storage = |
| 1365 profile_manager->GetProfileAttributesStorage(); | 1365 profile_manager->GetProfileAttributesStorage(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1392 // the next active profile has also been marked for deletion, so the | 1392 // the next active profile has also been marked for deletion, so the |
| 1393 // ProfileManager needs to recursively select a different next profile. | 1393 // ProfileManager needs to recursively select a different next profile. |
| 1394 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) { | 1394 TEST_F(ProfileManagerTest, ActiveProfileDeletedNextProfileDeletedToo) { |
| 1395 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 1395 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 1396 ASSERT_TRUE(profile_manager); | 1396 ASSERT_TRUE(profile_manager); |
| 1397 | 1397 |
| 1398 // Create and load one profile, and create two more profiles. | 1398 // Create and load one profile, and create two more profiles. |
| 1399 const std::string profile_name1 = "New Profile 1"; | 1399 const std::string profile_name1 = "New Profile 1"; |
| 1400 const std::string profile_name2 = "New Profile 2"; | 1400 const std::string profile_name2 = "New Profile 2"; |
| 1401 const std::string profile_name3 = "New Profile 3"; | 1401 const std::string profile_name3 = "New Profile 3"; |
| 1402 base::FilePath dest_path1 = temp_dir_.path().AppendASCII(profile_name1); | 1402 base::FilePath dest_path1 = temp_dir_.GetPath().AppendASCII(profile_name1); |
| 1403 base::FilePath dest_path2 = temp_dir_.path().AppendASCII(profile_name2); | 1403 base::FilePath dest_path2 = temp_dir_.GetPath().AppendASCII(profile_name2); |
| 1404 base::FilePath dest_path3 = temp_dir_.path().AppendASCII(profile_name3); | 1404 base::FilePath dest_path3 = temp_dir_.GetPath().AppendASCII(profile_name3); |
| 1405 | 1405 |
| 1406 MockObserver mock_observer; | 1406 MockObserver mock_observer; |
| 1407 EXPECT_CALL(mock_observer, OnProfileCreated( | 1407 EXPECT_CALL(mock_observer, OnProfileCreated( |
| 1408 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); | 1408 testing::NotNull(), NotFail())).Times(testing::AtLeast(2)); |
| 1409 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); | 1409 CreateProfileAsync(profile_manager, profile_name1, false, &mock_observer); |
| 1410 base::RunLoop().RunUntilIdle(); | 1410 base::RunLoop().RunUntilIdle(); |
| 1411 | 1411 |
| 1412 // Create the other profiles, but don't load them. Assign a fake avatar icon | 1412 // Create the other profiles, but don't load them. Assign a fake avatar icon |
| 1413 // to ensure that profiles in the profile attributes storage are sorted by the | 1413 // to ensure that profiles in the profile attributes storage are sorted by the |
| 1414 // profile name, and not randomly by the avatar name. | 1414 // profile name, and not randomly by the avatar name. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1442 dest_path2.BaseName().MaybeAsASCII()); | 1442 dest_path2.BaseName().MaybeAsASCII()); |
| 1443 profile_manager->ScheduleProfileForDeletion(dest_path2, | 1443 profile_manager->ScheduleProfileForDeletion(dest_path2, |
| 1444 ProfileManager::CreateCallback()); | 1444 ProfileManager::CreateCallback()); |
| 1445 // Spin the message loop so that all the callbacks can finish running. | 1445 // Spin the message loop so that all the callbacks can finish running. |
| 1446 base::RunLoop().RunUntilIdle(); | 1446 base::RunLoop().RunUntilIdle(); |
| 1447 | 1447 |
| 1448 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); | 1448 EXPECT_EQ(dest_path3, profile_manager->GetLastUsedProfile()->GetPath()); |
| 1449 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); | 1449 EXPECT_EQ(profile_name3, local_state->GetString(prefs::kProfileLastUsed)); |
| 1450 } | 1450 } |
| 1451 #endif // !defined(OS_MACOSX) | 1451 #endif // !defined(OS_MACOSX) |
| OLD | NEW |