Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7731)

Unified Diff: chrome/browser/profiles/profile_manager_unittest.cc

Issue 1782443006: Create LoadProfile method in profile_manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
« no previous file with comments | « chrome/browser/profiles/profile_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698