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 fe80ce21fbd7e58fdfe68bda8d43a6269107c2e2..e18ff23f9e9c8fedb2cf09ee6aa828a2f972afd5 100644 |
--- a/chrome/browser/profiles/profile_manager_unittest.cc |
+++ b/chrome/browser/profiles/profile_manager_unittest.cc |
@@ -45,14 +45,16 @@ |
#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/fake_user_manager.h" |
#include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
+#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.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" |
#include "chromeos/login/user_names.h" |
#include "components/user_manager/user_manager.h" |
-#endif |
+#endif // defined(OS_CHROMEOS) |
using base::ASCIIToUTF16; |
using content::BrowserThread; |
@@ -110,8 +112,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 |
} |
@@ -149,6 +151,18 @@ class ProfileManagerTest : public testing::Test { |
} |
#if defined(OS_CHROMEOS) |
+ // Helper function to register an user with id |user_id| and create profile |
+ // with a correct path. |
+ void RegisterUser(const std::string& user_id) { |
+ chromeos::ProfileHelper* profile_helper = chromeos::ProfileHelper::Get(); |
+ const std::string user_id_hash = |
+ profile_helper->GetUserIdHashByUserIdForTesting(user_id); |
+ user_manager::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 |
@@ -162,6 +176,8 @@ class ProfileManagerTest : public testing::Test { |
#if defined(OS_CHROMEOS) |
chromeos::ScopedTestUserManager test_user_manager_; |
#endif |
+ |
+ DISALLOW_COPY_AND_ASSIGN(ProfileManagerTest); |
}; |
TEST_F(ProfileManagerTest, GetProfile) { |
@@ -187,28 +203,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( |
@@ -399,16 +416,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); |
- user_manager::UserManager::Get()->UserLoggedIn( |
- chromeos::login::kGuestUserName, |
- chromeos::login::kGuestUserName, |
- false); |
+ RegisterUser(chromeos::login::kGuestUserName); |
#endif |
} |
}; |
@@ -548,6 +559,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 a 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()); |