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

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

Issue 544383003: Fixing problem that after a browser crash in multi user mode, an incorrect user might show up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving function declaration into conditional section Created 6 years, 3 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 b98362821d89a734de3e2556fffc60a92cd89a18..4685581b5ad358d1bf932b468480bff2b720f862 100644
--- a/chrome/browser/profiles/profile_manager_unittest.cc
+++ b/chrome/browser/profiles/profile_manager_unittest.cc
@@ -202,6 +202,17 @@ TEST_F(ProfileManagerTest, DefaultProfileDir) {
g_browser_process->profile_manager()->GetInitialProfileDir().value());
}
+MATCHER(NotFail, "Profile creation failure status is not reported.") {
+ return arg == Profile::CREATE_STATUS_CREATED ||
+ arg == Profile::CREATE_STATUS_INITIALIZED;
+}
+
+MATCHER(SameNotNull, "The same non-NULL value for all calls.") {
+ if (!g_created_profile)
+ g_created_profile = arg;
+ return arg != NULL && arg == g_created_profile;
+}
+
#if defined(OS_CHROMEOS)
// This functionality only exists on Chrome OS.
@@ -232,6 +243,48 @@ TEST_F(ProfileManagerTest, LoggedInProfileDir) {
profile_manager->GetInitialProfileDir()).value();
}
+// Switching the user should switch also the last used user.
+TEST_F(ProfileManagerTest, ActiveProfileChanged) {
+ ProfileManager* profile_manager = g_browser_process->profile_manager();
+ ASSERT_TRUE(profile_manager);
+
+ // Create and load two profiles.
+ const std::string user_name1 = "user1@example.com";
+ base::FilePath dest_path1 = temp_dir_.path().AppendASCII(user_name1);
+
+ MockObserver mock_observer;
+ EXPECT_CALL(mock_observer, OnProfileCreated(
+ testing::NotNull(), NotFail())).Times(testing::AtLeast(2));
+
+ CreateProfileAsync(profile_manager, user_name1, false, &mock_observer);
+ base::RunLoop().RunUntilIdle();
+
+ chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager();
+ chromeos::ScopedUserManagerEnabler enabler(user_manager);
+
+ PrefService* local_state = g_browser_process->local_state();
+ local_state->SetString(prefs::kProfileLastUsed, "");
+
+ const user_manager::User* active_user = user_manager->AddUser(user_name1);
+ user_manager->LoginUser(user_name1);
+
+ // None of the calls above should have changed the last user.
+ EXPECT_EQ("", local_state->GetString(prefs::kProfileLastUsed));
+
+ // The FakeUserManager will not switch the user either.
+ user_manager->SwitchActiveUser(user_name1);
+ EXPECT_EQ("", local_state->GetString(prefs::kProfileLastUsed));
+
+ // After triggering the LOGIN_USER_CHANGED observer call ourselves, the user
+ // has changed.
+ profile_manager->Observe(
+ chrome::NOTIFICATION_LOGIN_USER_CHANGED,
+ content::NotificationService::AllSources(),
+ content::Details<const user_manager::User>(active_user));
+ EXPECT_EQ("u-" + user_name1 + "-hash",
+ local_state->GetString(prefs::kProfileLastUsed));
+}
+
#endif
TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
@@ -273,17 +326,6 @@ TEST_F(ProfileManagerTest, CreateAndUseTwoProfiles) {
base::RunLoop().RunUntilIdle();
}
-MATCHER(NotFail, "Profile creation failure status is not reported.") {
- return arg == Profile::CREATE_STATUS_CREATED ||
- arg == Profile::CREATE_STATUS_INITIALIZED;
-}
-
-MATCHER(SameNotNull, "The same non-NULL value for all calls.") {
- if (!g_created_profile)
- g_created_profile = arg;
- return arg != NULL && arg == g_created_profile;
-}
-
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