| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/fake_login_utils.h" | 5 #include "chrome/browser/chromeos/login/fake_login_utils.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "chrome/browser/chrome_notification_types.h" | 10 #include "chrome/browser/chrome_notification_types.h" |
| 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 11 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 12 #include "chrome/browser/chromeos/login/user_flow.h" | 12 #include "chrome/browser/chromeos/login/user_flow.h" |
| 13 #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" |
| 13 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" | 14 #include "chrome/browser/chromeos/login/users/supervised_user_manager.h" |
| 14 #include "chrome/browser/chromeos/login/users/user_manager.h" | |
| 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 16 #include "chrome/browser/first_run/first_run.h" | 16 #include "chrome/browser/first_run/first_run.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/browser/ui/startup/startup_browser_creator.h" | 18 #include "chrome/browser/ui/startup/startup_browser_creator.h" |
| 19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 20 #include "chrome/test/base/testing_profile.h" | 20 #include "chrome/test/base/testing_profile.h" |
| 21 #include "chromeos/login/auth/mock_authenticator.h" | 21 #include "chromeos/login/auth/mock_authenticator.h" |
| 22 #include "chromeos/login/auth/user_context.h" | 22 #include "chromeos/login/auth/user_context.h" |
| 23 #include "components/user_manager/user.h" | 23 #include "components/user_manager/user.h" |
| 24 #include "components/user_manager/user_manager.h" |
| 24 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 namespace chromeos { | 28 namespace chromeos { |
| 28 | 29 |
| 29 FakeLoginUtils::FakeLoginUtils() : should_launch_browser_(false) {} | 30 FakeLoginUtils::FakeLoginUtils() : should_launch_browser_(false) {} |
| 30 | 31 |
| 31 FakeLoginUtils::~FakeLoginUtils() {} | 32 FakeLoginUtils::~FakeLoginUtils() {} |
| 32 | 33 |
| 33 void FakeLoginUtils::RespectLocalePreference(Profile*, | 34 void FakeLoginUtils::RespectLocalePreference(Profile*, |
| 34 const base::Closure& callback) { | 35 const base::Closure& callback) { |
| 35 callback.Run(); | 36 callback.Run(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void FakeLoginUtils::DoBrowserLaunch(Profile* profile, | 39 void FakeLoginUtils::DoBrowserLaunch(Profile* profile, |
| 39 LoginDisplayHost* login_host) { | 40 LoginDisplayHost* login_host) { |
| 40 | 41 if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { |
| 41 if (!UserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { | 42 ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); |
| 42 UserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); | |
| 43 return; | 43 return; |
| 44 } | 44 } |
| 45 login_host->BeforeSessionStart(); | 45 login_host->BeforeSessionStart(); |
| 46 if (should_launch_browser_) { | 46 if (should_launch_browser_) { |
| 47 StartupBrowserCreator browser_creator; | 47 StartupBrowserCreator browser_creator; |
| 48 chrome::startup::IsFirstRun first_run = | 48 chrome::startup::IsFirstRun first_run = |
| 49 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN | 49 first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN |
| 50 : chrome::startup::IS_NOT_FIRST_RUN; | 50 : chrome::startup::IS_NOT_FIRST_RUN; |
| 51 ASSERT_TRUE( | 51 ASSERT_TRUE( |
| 52 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), | 52 browser_creator.LaunchBrowser(*CommandLine::ForCurrentProcess(), |
| 53 profile, | 53 profile, |
| 54 base::FilePath(), | 54 base::FilePath(), |
| 55 chrome::startup::IS_PROCESS_STARTUP, | 55 chrome::startup::IS_PROCESS_STARTUP, |
| 56 first_run, | 56 first_run, |
| 57 NULL)); | 57 NULL)); |
| 58 } | 58 } |
| 59 if (login_host) | 59 if (login_host) |
| 60 login_host->Finalize(); | 60 login_host->Finalize(); |
| 61 UserManager::Get()->SessionStarted(); | 61 user_manager::UserManager::Get()->SessionStarted(); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void FakeLoginUtils::PrepareProfile(const UserContext& user_context, | 64 void FakeLoginUtils::PrepareProfile(const UserContext& user_context, |
| 65 bool has_cookies, | 65 bool has_cookies, |
| 66 bool has_active_session, | 66 bool has_active_session, |
| 67 LoginUtils::Delegate* delegate) { | 67 LoginUtils::Delegate* delegate) { |
| 68 UserManager::Get()->UserLoggedIn( | 68 user_manager::UserManager::Get()->UserLoggedIn( |
| 69 user_context.GetUserID(), user_context.GetUserIDHash(), false); | 69 user_context.GetUserID(), user_context.GetUserIDHash(), false); |
| 70 user_manager::User* user = | 70 user_manager::User* user = |
| 71 UserManager::Get()->FindUserAndModify(user_context.GetUserID()); | 71 user_manager::UserManager::Get()->FindUserAndModify( |
| 72 user_context.GetUserID()); |
| 72 DCHECK(user); | 73 DCHECK(user); |
| 73 | 74 |
| 74 // Make sure that we get the real Profile instead of the login Profile. | 75 // Make sure that we get the real Profile instead of the login Profile. |
| 75 user->set_profile_is_created(); | 76 user->set_profile_is_created(); |
| 76 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); | 77 Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); |
| 77 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, | 78 profile->GetPrefs()->SetString(prefs::kGoogleServicesUsername, |
| 78 user_context.GetUserID()); | 79 user_context.GetUserID()); |
| 79 | 80 |
| 80 if (UserManager::Get()->IsLoggedInAsSupervisedUser()) { | 81 if (user_manager::UserManager::Get()->IsLoggedInAsSupervisedUser()) { |
| 81 user_manager::User* active_user = UserManager::Get()->GetActiveUser(); | 82 user_manager::User* active_user = |
| 83 user_manager::UserManager::Get()->GetActiveUser(); |
| 82 std::string supervised_user_sync_id = | 84 std::string supervised_user_sync_id = |
| 83 UserManager::Get()->GetSupervisedUserManager()-> | 85 ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( |
| 84 GetUserSyncId(active_user->email()); | 86 active_user->email()); |
| 85 if (supervised_user_sync_id.empty()) | 87 if (supervised_user_sync_id.empty()) |
| 86 supervised_user_sync_id = "DUMMY ID"; | 88 supervised_user_sync_id = "DUMMY ID"; |
| 87 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, | 89 profile->GetPrefs()->SetString(prefs::kSupervisedUserId, |
| 88 supervised_user_sync_id); | 90 supervised_user_sync_id); |
| 89 } | 91 } |
| 90 | 92 |
| 91 content::NotificationService::current()->Notify( | 93 content::NotificationService::current()->Notify( |
| 92 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 94 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 93 content::NotificationService::AllSources(), | 95 content::NotificationService::AllSources(), |
| 94 content::Details<Profile>(profile)); | 96 content::Details<Profile>(profile)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 118 | 120 |
| 119 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { | 121 void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { |
| 120 expected_user_context_ = user_context; | 122 expected_user_context_ = user_context; |
| 121 if (authenticator_) { | 123 if (authenticator_) { |
| 122 static_cast<MockAuthenticator*>(authenticator_.get())-> | 124 static_cast<MockAuthenticator*>(authenticator_.get())-> |
| 123 SetExpectedCredentials(user_context); | 125 SetExpectedCredentials(user_context); |
| 124 } | 126 } |
| 125 } | 127 } |
| 126 | 128 |
| 127 } // namespace chromeos | 129 } // namespace chromeos |
| OLD | NEW |