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; |