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..ca1371b20759a5621a8a42dde91e462abbbce3a7 100644 |
--- a/chrome/browser/profiles/profile_manager_unittest.cc |
+++ b/chrome/browser/profiles/profile_manager_unittest.cc |
@@ -7,6 +7,7 @@ |
#include <string> |
#include "base/command_line.h" |
+#include "base/files/file_path.h" |
#include "base/files/file_util.h" |
#include "base/files/scoped_temp_dir.h" |
#include "base/macros.h" |
@@ -93,6 +94,27 @@ class UnittestProfileManager : public ::ProfileManagerWithoutInit { |
} |
}; |
+void ExpectNullProfile(base::Closure closure, Profile* profile) { |
+ EXPECT_EQ(nullptr, profile); |
+ closure.Run(); |
+} |
+ |
+void ExpectProfileWithName(const std::string& profile_name, |
+ bool incognito, |
+ base::Closure closure, |
+ Profile* profile) { |
+ EXPECT_NE(nullptr, profile); |
+ EXPECT_EQ(incognito, profile->IsOffTheRecord()); |
+ if (incognito) |
+ profile = profile->GetOriginalProfile(); |
+ |
+ // Create a profile on the fly so the the same comparison |
+ // can be used in Windows and other platforms. |
+ EXPECT_EQ(base::FilePath().AppendASCII(profile_name), |
+ profile->GetPath().BaseName()); |
+ closure.Run(); |
+} |
+ |
} // namespace |
class ProfileManagerTest : public testing::Test { |
@@ -293,6 +315,60 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) { |
base::RunLoop().RunUntilIdle(); |
} |
+TEST_F(ProfileManagerTest, LoadNonExistingProfile) { |
+ const std::string profile_name = "NonExistingProfile"; |
+ base::RunLoop run_loop_1; |
+ base::RunLoop run_loop_2; |
+ |
+ ProfileManager* profile_manager = g_browser_process->profile_manager(); |
+ profile_manager->LoadProfile( |
+ profile_name, false /* incognito */, |
+ base::Bind(&ExpectNullProfile, run_loop_1.QuitClosure())); |
+ run_loop_1.Run(); |
+ |
+ profile_manager->LoadProfile( |
+ profile_name, true /* incognito */, |
+ base::Bind(&ExpectNullProfile, run_loop_2.QuitClosure())); |
+ run_loop_2.Run(); |
+} |
+ |
+TEST_F(ProfileManagerTest, LoadExistingProfile) { |
+ 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(); |
+ |
+ base::RunLoop load_profile; |
+ bool incognito = false; |
+ profile_manager->LoadProfile( |
+ profile_name, incognito, |
+ base::Bind(&ExpectProfileWithName, profile_name, incognito, |
+ load_profile.QuitClosure())); |
+ load_profile.Run(); |
+ |
+ base::RunLoop load_profile_incognito; |
+ incognito = true; |
+ profile_manager->LoadProfile( |
+ profile_name, incognito, |
+ base::Bind(&ExpectProfileWithName, profile_name, incognito, |
+ load_profile_incognito.QuitClosure())); |
+ load_profile_incognito.Run(); |
+ |
+ // Loading some other non existing profile should still return null. |
+ base::RunLoop load_other_profile; |
+ profile_manager->LoadProfile( |
+ other_name, false, |
+ base::Bind(&ExpectNullProfile, load_other_profile.QuitClosure())); |
+ load_other_profile.Run(); |
+} |
+ |
TEST_F(ProfileManagerTest, CreateProfileAsyncMultipleRequests) { |
g_created_profile = NULL; |