Chromium Code Reviews| Index: chrome/browser/profiles/profile_manager_unittest.cc |
| diff --git a/chrome/browser/profiles/profile_manager_unittest.cc b/chrome/browser/profiles/profile_manager_unittest.cc |
| index 9b123393a2058816673a3bea182ce48feeea65d9..3b8f07221d9e180d56f2463ca878a7e5ec2d1737 100644 |
| --- a/chrome/browser/profiles/profile_manager_unittest.cc |
| +++ b/chrome/browser/profiles/profile_manager_unittest.cc |
| @@ -93,6 +93,25 @@ class UnittestProfileManager : public ::ProfileManagerWithoutInit { |
| } |
| }; |
| +void ExpectNullProfile(Profile* profile) { |
|
Bernhard Bauer
2016/03/14 19:05:34
Can you make this take an additional Closure to ru
Miguel Garcia
2016/03/17 20:04:07
I will look into this and fix it before submitting
|
| + EXPECT_EQ(nullptr, profile); |
| +} |
| + |
| +void ExpectProfileWithName(const std::string& profile_name, |
| + bool incognito, |
| + Profile* profile) { |
| + EXPECT_NE(nullptr, profile); |
| + EXPECT_EQ(incognito, profile->IsOffTheRecord()); |
| + if (!incognito) { |
|
Bernhard Bauer
2016/03/14 19:05:34
For incognito profiles, you could verify the name
Miguel Garcia
2016/03/17 20:04:07
Good idea!
|
| +#if defined(OS_WIN) |
| + EXPECT_EQ(base::ASCIIToUTF16(profile_name), |
|
Bernhard Bauer
2016/03/14 19:05:34
Alternatively, use FilePath().AppendASCII(profile_
Miguel Garcia
2016/03/17 20:04:07
Agreed. Done
|
| + profile->GetPath().BaseName().value()); |
| +#else |
| + EXPECT_EQ(profile_name, profile->GetPath().BaseName().value()); |
| +#endif |
| + } |
| +} |
| + |
| } // namespace |
| class ProfileManagerTest : public testing::Test { |
| @@ -293,6 +312,47 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
| base::RunLoop().RunUntilIdle(); |
| } |
| +TEST_F(ProfileManagerTest, LoadProfileDoesNotExist) { |
|
Bernhard Bauer
2016/03/14 19:05:34
Nit: "LoadNonExistingProfile" (and "LoadExistingPr
Miguel Garcia
2016/03/17 20:04:07
Done.
|
| + const std::string profile_name = "NonExistingProfile"; |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + profile_manager->LoadProfile(profile_name, false /* incognito */, |
| + base::Bind(&ExpectNullProfile)); |
| + base::RunLoop().RunUntilIdle(); |
| + profile_manager->LoadProfile(profile_name, true /* incognito */, |
| + base::Bind(&ExpectNullProfile)); |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| +TEST_F(ProfileManagerTest, LoadProfileExisting) { |
| + const std::string profile_name = "MyProfile"; |
| + const std::string other_name = "SomeOtherProfile"; |
| + MockObserver mock_observer1; |
| + EXPECT_CALL(mock_observer1, OnProfileCreated(SameNotNull(), NotFail())) |
| + .Times(testing::AtLeast(1)); |
| + |
| + ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| + CreateProfileAsync(profile_manager, profile_name, false, &mock_observer1); |
| + |
| + // Make sure a real profile is created before continuing. |
| + base::RunLoop().RunUntilIdle(); |
| + |
| + bool incognito = false; |
| + profile_manager->LoadProfile( |
| + profile_name, incognito, |
| + base::Bind(&ExpectProfileWithName, profile_name, incognito)); |
| + |
| + incognito = true; |
| + profile_manager->LoadProfile( |
| + profile_name, incognito, |
| + base::Bind(&ExpectProfileWithName, profile_name, incognito)); |
| + |
| + // Loading some other non existing profile should still return null. |
| + profile_manager->LoadProfile(other_name, false, |
| + base::Bind(&ExpectNullProfile)); |
| + base::RunLoop().RunUntilIdle(); |
| +} |
| + |
| TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
| g_created_profile = NULL; |