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 681ce384e12b5d7f8f9cdac57285d57cdb7fbf58..5147f8048113fc4830a3da3fcdc87e5b61eeaab5 100644 |
--- a/chrome/browser/profiles/profile_manager_unittest.cc |
+++ b/chrome/browser/profiles/profile_manager_unittest.cc |
@@ -45,8 +45,8 @@ |
#include "ui/base/l10n/l10n_util.h" |
#if defined(OS_CHROMEOS) |
-#include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
-#include "chrome/browser/chromeos/login/users/user_manager.h" |
+#include "chrome/browser/chromeos/login/users/fake_user_manager.h" |
+#include "chrome/browser/chromeos/profiles/profile_helper.h" |
#include "chrome/browser/chromeos/settings/cros_settings.h" |
#include "chrome/browser/chromeos/settings/device_settings_service.h" |
#include "chromeos/chromeos_switches.h" |
@@ -109,8 +109,8 @@ class ProfileManagerTest : public testing::Test { |
new UnittestProfileManager(temp_dir_.path())); |
#if defined(OS_CHROMEOS) |
- CommandLine* cl = CommandLine::ForCurrentProcess(); |
- cl->AppendSwitch(switches::kTestType); |
+ CommandLine* cl = CommandLine::ForCurrentProcess(); |
+ cl->AppendSwitch(switches::kTestType); |
#endif |
} |
@@ -148,6 +148,20 @@ class ProfileManagerTest : public testing::Test { |
} |
#if defined(OS_CHROMEOS) |
+ // Helper function to register an user with id |user_id| and create profile |
+ // for him with a correct path. |
Mr4D (OOO till 08-26)
2014/08/15 14:27:56
remove "for him".
dzhioev (left Google)
2014/08/15 16:11:25
Done.
|
+ void RegisterUser(const std::string& user_id) { |
+ chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); |
+ const std::string user_id_hash = |
+ profile_helper->GetUserIdHashByUserIdForTests(user_id); |
+ chromeos::UserManager::Get()->UserLoggedIn( |
+ user_id, |
+ user_id_hash, |
+ false); |
+ g_browser_process->profile_manager()->GetProfile( |
+ profile_helper->GetProfilePathByUserIdHash(user_id_hash)); |
+ } |
+ |
chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
chromeos::ScopedTestCrosSettings test_cros_settings_; |
#endif |
@@ -186,28 +200,29 @@ TEST_F(ProfileManagerTest, DefaultProfileDir) { |
} |
#if defined(OS_CHROMEOS) |
+ |
// This functionality only exists on Chrome OS. |
TEST_F(ProfileManagerTest, LoggedInProfileDir) { |
- CommandLine *cl = CommandLine::ForCurrentProcess(); |
- std::string profile_dir(chrome::kTestUserProfileDir); |
- |
- cl->AppendSwitchASCII(chromeos::switches::kLoginProfile, profile_dir); |
- |
base::FilePath expected_default = |
base::FilePath().AppendASCII(chrome::kInitialProfile); |
ProfileManager* profile_manager = g_browser_process->profile_manager(); |
EXPECT_EQ(expected_default.value(), |
profile_manager->GetInitialProfileDir().value()); |
- scoped_ptr<chromeos::MockUserManager> mock_user_manager; |
- mock_user_manager.reset(new chromeos::MockUserManager()); |
- mock_user_manager->SetActiveUser("user@gmail.com"); |
- user_manager::User* active_user = mock_user_manager->GetActiveUser(); |
+ const char kTestUserName[] = "test-user@example.com"; |
+ chromeos::FakeUserManager* user_manager = new chromeos::FakeUserManager(); |
+ chromeos::ScopedUserManagerEnabler enabler(user_manager); |
+ |
+ const user_manager::User* active_user = user_manager->AddUser(kTestUserName); |
+ user_manager->LoginUser(kTestUserName); |
+ user_manager->SwitchActiveUser(kTestUserName); |
+ |
profile_manager->Observe( |
chrome::NOTIFICATION_LOGIN_USER_CHANGED, |
content::NotificationService::AllSources(), |
content::Details<const user_manager::User>(active_user)); |
- base::FilePath expected_logged_in(profile_dir); |
+ base::FilePath expected_logged_in( |
+ chromeos::ProfileHelper::GetUserProfileDir(active_user->username_hash())); |
EXPECT_EQ(expected_logged_in.value(), |
profile_manager->GetInitialProfileDir().value()); |
VLOG(1) << temp_dir_.path().Append( |
@@ -398,15 +413,10 @@ class ProfileManagerGuestTest : public ProfileManagerTest { |
// ProfileManager (accessing DBusThreadManager). |
cl->AppendSwitch(switches::kTestType); |
- cl->AppendSwitchASCII(chromeos::switches::kLoginProfile, |
- std::string(chrome::kProfileDirPrefix) + |
- chromeos::login::kGuestUserName); |
cl->AppendSwitch(chromeos::switches::kGuestSession); |
cl->AppendSwitch(::switches::kIncognito); |
- chromeos::UserManager::Get()->UserLoggedIn(chromeos::login::kGuestUserName, |
- chromeos::login::kGuestUserName, |
- false); |
+ RegisterUser(chromeos::login::kGuestUserName); |
#endif |
} |
}; |
@@ -546,6 +556,13 @@ TEST_F(ProfileManagerTest, GetLastUsedProfileAllowedByPolicy) { |
ProfileManager* profile_manager = g_browser_process->profile_manager(); |
ASSERT_TRUE(profile_manager); |
+#if defined(OS_CHROMEOS) |
+ // On CrOS, profile returned by GetLastUsedProfile is an singin profile that |
+ // is forced to be incognito. That's why we need to create at least one user |
+ // to get a regular profile. |
+ RegisterUser("test-user@example.com"); |
+#endif |
+ |
Profile* profile = profile_manager->GetLastUsedProfileAllowedByPolicy(); |
ASSERT_TRUE(profile); |
EXPECT_FALSE(profile->IsOffTheRecord()); |