diff options
author | nkostylev <nkostylev@chromium.org> | 2015-02-05 05:57:39 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-05 13:59:01 +0000 |
commit | 393309fdf609591e8b3225728992011b0c772cfa (patch) | |
tree | 3760d9233c8fca8857dbe5e23c9f35583f7884d0 | |
parent | 36d358e0cdff201a99501e9c986a8a26f8965a40 (diff) | |
download | chromium_src-393309fdf609591e8b3225728992011b0c772cfa.zip chromium_src-393309fdf609591e8b3225728992011b0c772cfa.tar.gz chromium_src-393309fdf609591e8b3225728992011b0c772cfa.tar.bz2 |
[cros] Cleanup: remove LoginUtils
Introduced UserSessionManagerTestApi:
* InjectStubUserContext() to configure predefined user credentials (StubAuthenticator)
* SetShouldLaunchBrowserInTests() to control whether browser instance should be created in tests. Some tests don't really need that and were not designed to handle it properly.
LoginUtils methods:
* IsWhitelisted() is moved to CrosSettings
* CreateAuthenticator() is moved to UserSessionManager
* PrepareProfile() and DoBrowserLaunch() were already just a thin wrappers around corresponding methods of UserSessionManager.
Tests changes:
* MockAuthenticator > StubAuthenticator
* Now tests that were using MockLoginUtils to inject their own test profile are using regular profile init code with a stub user_context.
BUG=435094
TBR=stevenjb@chromium.org
Review URL: https://codereview.chromium.org/745613002
Cr-Commit-Position: refs/heads/master@{#314798}
54 files changed, 416 insertions, 768 deletions
diff --git a/chrome/browser/BUILD.gn b/chrome/browser/BUILD.gn index 5a65805..e6f54cd 100644 --- a/chrome/browser/BUILD.gn +++ b/chrome/browser/BUILD.gn @@ -1000,12 +1000,10 @@ source_set("test_support") { "chromeos/input_method/mock_input_method_engine.h", "chromeos/input_method/mock_input_method_manager.cc", "chromeos/input_method/mock_input_method_manager.h", - "chromeos/login/fake_login_utils.cc", - "chromeos/login/fake_login_utils.h", - "chromeos/login/mock_login_utils.cc", - "chromeos/login/mock_login_utils.h", "chromeos/login/screens/mock_device_disabled_screen_actor.cc", "chromeos/login/screens/mock_device_disabled_screen_actor.h", + "chromeos/login/session/user_session_manager_test_api.cc", + "chromeos/login/session/user_session_manager_test_api.h", "chromeos/login/test/oobe_screen_waiter.cc", "chromeos/login/test/oobe_screen_waiter.h", "chromeos/login/test/js_checker.cc", diff --git a/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc b/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc index 3778614..2537a1c 100644 --- a/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc +++ b/chrome/browser/chromeos/accessibility/accessibility_manager_browsertest.cc @@ -12,7 +12,6 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/preferences.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" diff --git a/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc b/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc index 2e05a87..970973c 100644 --- a/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc +++ b/chrome/browser/chromeos/accessibility/magnification_manager_browsertest.cc @@ -13,7 +13,6 @@ #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/profiles/profile.h" #include "chrome/browser/profiles/profile_manager.h" #include "chrome/common/chrome_switches.h" diff --git a/chrome/browser/chromeos/app_mode/kiosk_profile_loader.cc b/chrome/browser/chromeos/app_mode/kiosk_profile_loader.cc index 689ab68..2bfe2e2 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_profile_loader.cc +++ b/chrome/browser/chromeos/app_mode/kiosk_profile_loader.cc @@ -12,7 +12,6 @@ #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h" #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/lifetime/application_lifetime.h" @@ -160,10 +159,11 @@ void KioskProfileLoader::OnAuthSuccess(const UserContext& user_context) { UserContext context = user_context; if (context.GetUserID() == chromeos::login::kGuestUserName) context.SetUserID(DemoAppLauncher::kDemoUserName); - LoginUtils::Get()->PrepareProfile(context, - false, // has_auth_cookies - false, // has_active_session - this); + UserSessionManager::GetInstance()->StartSession( + context, UserSessionManager::PRIMARY_USER_SESSION, + false, // has_auth_cookies + false, // Start session for user. + this); } void KioskProfileLoader::OnAuthFailure(const AuthFailure& error) { @@ -186,8 +186,8 @@ void KioskProfileLoader::OnOnlineChecked( void KioskProfileLoader::OnProfilePrepared(Profile* profile, bool browser_launched) { // This object could be deleted any time after successfully reporting - // a profile load, so invalidate the LoginUtils delegate now. - LoginUtils::Get()->DelegateDeleted(this); + // a profile load, so invalidate the delegate now. + UserSessionManager::GetInstance()->DelegateDeleted(this); delegate_->OnProfileLoaded(profile); ReportLaunchResult(KioskAppLaunchError::NONE); diff --git a/chrome/browser/chromeos/app_mode/kiosk_profile_loader.h b/chrome/browser/chromeos/app_mode/kiosk_profile_loader.h index 9dee387..42796e3 100644 --- a/chrome/browser/chromeos/app_mode/kiosk_profile_loader.h +++ b/chrome/browser/chromeos/app_mode/kiosk_profile_loader.h @@ -11,7 +11,7 @@ #include "base/callback.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_launch_error.h" -#include "chrome/browser/chromeos/login/login_utils.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chromeos/login/auth/login_performer.h" class Profile; @@ -22,7 +22,7 @@ namespace chromeos { // attempts to login for the app's generated user id. If the login is // successful, it prepares app profile then calls the delegate. class KioskProfileLoader : public LoginPerformer::Delegate, - public LoginUtils::Delegate { + public UserSessionManagerDelegate { public: class Delegate { public: @@ -55,7 +55,7 @@ class KioskProfileLoader : public LoginPerformer::Delegate, void PolicyLoadFailed() override; void OnOnlineChecked(const std::string& email, bool success) override; - // LoginUtils::Delegate implementation: + // UserSessionManagerDelegate implementation: void OnProfilePrepared(Profile* profile, bool browser_launched) override; std::string user_id_; diff --git a/chrome/browser/chromeos/login/app_launch_signin_screen.cc b/chrome/browser/chromeos/login/app_launch_signin_screen.cc index 983ca77..f6c87f7 100644 --- a/chrome/browser/chromeos/login/app_launch_signin_screen.cc +++ b/chrome/browser/chromeos/login/app_launch_signin_screen.cc @@ -6,8 +6,8 @@ #include "base/values.h" #include "chrome/browser/chromeos/login/help_app_launcher.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/screens/user_selection_screen.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/signin/screenlock_bridge.h" #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" #include "chrome/grit/generated_resources.h" @@ -85,9 +85,9 @@ void AppLaunchSigninScreen::CompleteLogin(const UserContext& user_context) { void AppLaunchSigninScreen::Login(const UserContext& user_context, const SigninSpecifics& specifics) { - // Note: LoginUtils::CreateAuthenticator doesn't necessarily create + // Note: CreateAuthenticator doesn't necessarily create // a new Authenticator object, and could reuse an existing one. - authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); + authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::Bind(&Authenticator::AuthenticateToUnlock, diff --git a/chrome/browser/chromeos/login/auth/chrome_login_performer.cc b/chrome/browser/chromeos/login/auth/chrome_login_performer.cc index 0d1bc62..b8ba6b4 100644 --- a/chrome/browser/chromeos/login/auth/chrome_login_performer.cc +++ b/chrome/browser/chromeos/login/auth/chrome_login_performer.cc @@ -8,7 +8,7 @@ #include "base/thread_task_runner_handle.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_user_login_flow.h" -#include "chrome/browser/chromeos/login/login_utils.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_authentication.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_login_flow.h" @@ -85,7 +85,7 @@ void ChromeLoginPerformer::DidRunTrustedCheck(const base::Closure& callback) { bool ChromeLoginPerformer::IsUserWhitelisted(const std::string& user_id, bool* wildcard_match) { - return LoginUtils::IsWhitelisted(user_id, wildcard_match); + return CrosSettings::IsWhitelisted(user_id, wildcard_match); } void ChromeLoginPerformer::RunOnlineWhitelistCheck( @@ -111,7 +111,7 @@ void ChromeLoginPerformer::RunOnlineWhitelistCheck( } scoped_refptr<Authenticator> ChromeLoginPerformer::CreateAuthenticator() { - return LoginUtils::Get()->CreateAuthenticator(this); + return UserSessionManager::GetInstance()->CreateAuthenticator(this); } bool ChromeLoginPerformer::AreSupervisedUsersAllowed() { diff --git a/chrome/browser/chromeos/login/existing_user_controller.cc b/chrome/browser/chromeos/login/existing_user_controller.cc index 70f0d5a..b74e2ed 100644 --- a/chrome/browser/chromeos/login/existing_user_controller.cc +++ b/chrome/browser/chromeos/login/existing_user_controller.cc @@ -26,11 +26,11 @@ #include "chrome/browser/chromeos/customization/customization_document.h" #include "chrome/browser/chromeos/login/auth/chrome_login_performer.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/signin_specifics.h" #include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h" +#include "chrome/browser/chromeos/login/ui/user_adding_screen.h" #include "chrome/browser/chromeos/login/user_flow.h" #include "chrome/browser/chromeos/login/users/chrome_user_manager.h" #include "chrome/browser/chromeos/login/wizard_controller.h" @@ -224,7 +224,7 @@ void ExistingUserController::UpdateLoginDisplay( (*it)->GetType() != user_manager::USER_TYPE_SUPERVISED || user_manager::UserManager::Get()->AreSupervisedUsersAllowed(); bool meets_whitelist_requirements = - LoginUtils::IsWhitelisted((*it)->email(), NULL) || + CrosSettings::IsWhitelisted((*it)->email(), NULL) || !(*it)->HasGaiaAccount(); // Public session accounts are always shown on login screen. @@ -302,7 +302,7 @@ void ExistingUserController::Observe( // ExistingUserController, private: ExistingUserController::~ExistingUserController() { - LoginUtils::Get()->DelegateDeleted(this); + UserSessionManager::GetInstance()->DelegateDeleted(this); if (current_controller_ == this) { current_controller_ = NULL; @@ -690,11 +690,14 @@ void ExistingUserController::OnAuthSuccess(const UserContext& user_context) { login_performer_->set_delegate(NULL); ignore_result(login_performer_.release()); - // Will call OnProfilePrepared() in the end. - LoginUtils::Get()->PrepareProfile(user_context, - has_auth_cookies, - false, // Start session for user. - this); + UserSessionManager::StartSessionType start_session_type = + UserAddingScreen::Get()->IsRunning() + ? UserSessionManager::SECONDARY_USER_SESSION + : UserSessionManager::PRIMARY_USER_SESSION; + UserSessionManager::GetInstance()->StartSession( + user_context, start_session_type, has_auth_cookies, + false, // Start session for user. + this); // Update user's displayed email. if (!display_email_.empty()) { diff --git a/chrome/browser/chromeos/login/existing_user_controller.h b/chrome/browser/chromeos/login/existing_user_controller.h index 6db8746..a699fdc 100644 --- a/chrome/browser/chromeos/login/existing_user_controller.h +++ b/chrome/browser/chromeos/login/existing_user_controller.h @@ -16,7 +16,7 @@ #include "base/time/time.h" #include "base/timer/timer.h" #include "chrome/browser/chromeos/app_mode/kiosk_app_manager.h" -#include "chrome/browser/chromeos/login/login_utils.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/ui/login_display.h" #include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/chromeos/settings/device_settings_service.h" @@ -51,7 +51,7 @@ class NetworkStateHelper; class ExistingUserController : public LoginDisplay::Delegate, public content::NotificationObserver, public LoginPerformer::Delegate, - public LoginUtils::Delegate { + public UserSessionManagerDelegate { public: // All UI initialization is deferred till Init() call. explicit ExistingUserController(LoginDisplayHost* host); @@ -146,7 +146,7 @@ class ExistingUserController : public LoginDisplay::Delegate, void PolicyLoadFailed() override; void OnOnlineChecked(const std::string& username, bool success) override; - // LoginUtils::Delegate implementation: + // UserSessionManagerDelegate implementation: void OnProfilePrepared(Profile* profile, bool browser_launched) override; // Called when device settings change. diff --git a/chrome/browser/chromeos/login/existing_user_controller_auto_login_unittest.cc b/chrome/browser/chromeos/login/existing_user_controller_auto_login_unittest.cc index 638aa0d..f59b399 100644 --- a/chrome/browser/chromeos/login/existing_user_controller_auto_login_unittest.cc +++ b/chrome/browser/chromeos/login/existing_user_controller_auto_login_unittest.cc @@ -7,7 +7,6 @@ #include "base/message_loop/message_loop.h" #include "base/values.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" -#include "chrome/browser/chromeos/login/mock_login_utils.h" #include "chrome/browser/chromeos/login/ui/mock_login_display.h" #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h" #include "chrome/browser/chromeos/login/users/mock_user_manager.h" @@ -54,15 +53,11 @@ class ExistingUserControllerAutoLoginTest : public ::testing::Test { void SetUp() override { mock_login_display_host_.reset(new MockLoginDisplayHost); mock_login_display_ = new MockLoginDisplay(); - mock_login_utils_ = new MockLoginUtils(); - LoginUtils::Set(mock_login_utils_); EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) .Times(1) .WillOnce(Return(mock_login_display_)); - EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)).Times(AnyNumber()); - EXPECT_CALL(*mock_user_manager_, Shutdown()).Times(AnyNumber()); EXPECT_CALL(*mock_user_manager_, FindUser(_)) .WillRepeatedly(ReturnNull()); @@ -141,9 +136,6 @@ class ExistingUserControllerAutoLoginTest : public ::testing::Test { const std::string auto_login_user_id_; private: - // Owned by LoginUtilsWrapper. - MockLoginUtils* mock_login_utils_; - // |mock_login_display_| is owned by the ExistingUserController, which calls // CreateLoginDisplay() on the |mock_login_display_host_| to get it. MockLoginDisplay* mock_login_display_; diff --git a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc index 3be3904..406fd03 100644 --- a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc +++ b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc @@ -11,19 +11,19 @@ #include "base/command_line.h" #include "base/location.h" #include "base/memory/ref_counted.h" +#include "base/prefs/pref_service.h" +#include "base/prefs/scoped_user_pref_update.h" #include "base/run_loop.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/help_app_launcher.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/mock_login_utils.h" #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" +#include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_screen.h" #include "chrome/browser/chromeos/login/ui/mock_login_display.h" #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h" -#include "chrome/browser/chromeos/login/user_flow.h" -#include "chrome/browser/chromeos/login/users/mock_user_manager.h" -#include "chrome/browser/chromeos/login/users/scoped_user_manager_enabler.h" #include "chrome/browser/chromeos/login/wizard_controller.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/device_local_account.h" @@ -34,12 +34,9 @@ #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen_handler.h" #include "chrome/grit/generated_resources.h" #include "chrome/test/base/testing_browser_process.h" -#include "chrome/test/base/testing_profile.h" #include "chromeos/chromeos_switches.h" #include "chromeos/dbus/fake_session_manager_client.h" -#include "chromeos/login/auth/authenticator.h" #include "chromeos/login/auth/key.h" -#include "chromeos/login/auth/mock_authenticator.h" #include "chromeos/login/auth/mock_url_fetchers.h" #include "chromeos/login/auth/user_context.h" #include "chromeos/login/user_names.h" @@ -75,7 +72,6 @@ namespace chromeos { namespace { const char kUsername[] = "test_user@gmail.com"; -const char kNewUsername[] = "test_new_user@gmail.com"; const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost"; const char kPassword[] = "test_password"; @@ -84,14 +80,6 @@ const int kAutoLoginNoDelay = 0; const int kAutoLoginShortDelay = 1; const int kAutoLoginLongDelay = 10000; -ACTION_P(CreateAuthenticator, user_context) { - return new MockAuthenticator(arg0, user_context); -} - -void DeleteUserFlow(UserFlow* user_flow) { - delete user_flow; -} - // Wait for cros settings to become permanently untrusted and run |callback|. void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) { while (true) { @@ -116,8 +104,7 @@ void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) { class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { protected: - ExistingUserControllerTest() - : mock_login_display_(NULL), mock_user_manager_(NULL) {} + ExistingUserControllerTest() : mock_login_display_(NULL) {} ExistingUserController* existing_user_controller() { return ExistingUserController::current_controller(); @@ -132,11 +119,6 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); - mock_login_utils_ = new MockLoginUtils(); - LoginUtils::Set(mock_login_utils_); - EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) - .Times(1); - mock_login_display_host_.reset(new MockLoginDisplayHost()); mock_login_display_ = new MockLoginDisplay(); SetUpLoginDisplay(); @@ -160,53 +142,14 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { void SetUpCommandLine(base::CommandLine* command_line) override { command_line->AppendSwitch(switches::kLoginManager); - } - - virtual void SetUpUserManager() { - // Replace the UserManager singleton with a mock. - mock_user_manager_ = new MockUserManager; - user_manager_enabler_.reset( - new ScopedUserManagerEnabler(mock_user_manager_)); - EXPECT_CALL(*mock_user_manager_, IsKnownUser(kUsername)) - .Times(AnyNumber()) - .WillRepeatedly(Return(true)); - EXPECT_CALL(*mock_user_manager_, IsKnownUser(kNewUsername)) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_user_manager_, IsLoggedInAsGuest()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_user_manager_, IsLoggedInAsPublicAccount()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_user_manager_, IsSessionStarted()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); - EXPECT_CALL(*mock_user_manager_, Shutdown()) - .Times(1); - EXPECT_CALL(*mock_user_manager_, FindUser(_)) - .Times(AnyNumber()) - .WillRepeatedly(ReturnNull()); + command_line->AppendSwitch(switches::kForceLoginManagerInTests); } void SetUpOnMainThread() override { - testing_profile_.reset(new TestingProfile()); - SetUpUserManager(); existing_user_controller_.reset( new ExistingUserController(mock_login_display_host_.get())); ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); existing_user_controller_->Init(user_manager::UserList()); - profile_prepared_cb_ = - base::Bind(&ExistingUserController::OnProfilePrepared, - base::Unretained(existing_user_controller()), - testing_profile_.get(), - false); } void TearDownOnMainThread() override { @@ -217,8 +160,14 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { // be deleted on the UI thread. existing_user_controller_.reset(); DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread(); - testing_profile_.reset(NULL); - user_manager_enabler_.reset(); + + // Test case may be configured with the real user manager but empty user + // list initially. So network OOBE screen is initialized. + // Need to reset it manually so that we don't end up with CrosSettings + // observer that wasn't removed. + WizardController* controller = WizardController::default_controller(); + if (controller && controller->current_screen()) + controller->current_screen()->Hide(); } void ExpectLoginFailure() { @@ -233,6 +182,12 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { .Times(1); } + void RegisterUser(const std::string& user_id) { + ListPrefUpdate users_pref(g_browser_process->local_state(), + "LoggedInUsers"); + users_pref->AppendIfNotPresent(new base::StringValue(user_id)); + } + // ExistingUserController private member accessors. base::OneShotTimer<ExistingUserController>* auto_login_timer() { return existing_user_controller()->auto_login_timer_.get(); @@ -257,45 +212,38 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { MockLoginDisplay* mock_login_display_; scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; - // Owned by LoginUtilsWrapper. - MockLoginUtils* mock_login_utils_; - - MockUserManager* mock_user_manager_; // Not owned. - scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_; - - scoped_ptr<TestingProfile> testing_profile_; - // Mock URLFetcher. MockURLFetcherFactory<SuccessFetcher> factory_; - base::Callback<void(void)> profile_prepared_cb_; - private: DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); }; +IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, PRE_ExistingUserLogin) { + RegisterUser(kUsername); +} + IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) .Times(2); UserContext user_context(kUsername); user_context.SetKey(Key(kPassword)); user_context.SetUserIDHash(kUsername); - EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) - .Times(1) - .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); - EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) - .Times(1) - .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, - &base::Callback<void(void)>::Run)); + test::UserSessionManagerTestApi session_manager_test_api( + UserSessionManager::GetInstance()); + session_manager_test_api.InjectStubUserContext(user_context); EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) .Times(1); EXPECT_CALL(*mock_login_display_host_, StartWizard(WizardController::kTermsOfServiceScreenName)) .Times(0); - EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) - .Times(AnyNumber()) - .WillRepeatedly(Return(false)); + + content::WindowedNotificationObserver profile_prepared_observer( + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, + content::NotificationService::AllSources()); existing_user_controller()->Login(user_context, SigninSpecifics()); + + profile_prepared_observer.Wait(); content::RunAllPendingInMessageLoop(); } @@ -361,9 +309,6 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, SupervisedUserCreationScreen supervised_user_creation_screen( &mock_base_screen_delegate, &supervised_user_creation_screen_handler); - EXPECT_CALL(*mock_user_manager_, SetUserFlow(kUsername, _)) - .Times(1) - .WillOnce(WithArg<1>(Invoke(DeleteUserFlow))); supervised_user_creation_screen.AuthenticateManager(kUsername, kPassword); } @@ -454,23 +399,27 @@ class ExistingUserControllerPublicSessionTest .Times(AnyNumber()); } - void SetUpUserManager() override {} + void TearDownOnMainThread() override { + ExistingUserControllerTest::TearDownOnMainThread(); + + // Test case may be configured with the real user manager but empty user + // list initially. So network OOBE screen is initialized. + // Need to reset it manually so that we don't end up with CrosSettings + // observer that wasn't removed. + WizardController* controller = WizardController::default_controller(); + if (controller && controller->current_screen()) + controller->current_screen()->Hide(); + } void ExpectSuccessfulLogin(const UserContext& user_context) { - EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) - .Times(AnyNumber()); - EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) - .Times(1) - .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); - EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) - .Times(1) - .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, - &base::Callback<void(void)>::Run)); - EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) - .Times(1); + test::UserSessionManagerTestApi session_manager_test_api( + UserSessionManager::GetInstance()); + session_manager_test_api.InjectStubUserContext(user_context); EXPECT_CALL(*mock_login_display_host_, StartWizard(WizardController::kTermsOfServiceScreenName)) .Times(0); + EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)).Times(AnyNumber()); + EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)).Times(AnyNumber()); } void SetAutoLoginPolicy(const std::string& username, int delay) { @@ -583,6 +532,11 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, user_context.SetUserIDHash(user_context.GetUserID()); ExpectSuccessfulLogin(user_context); existing_user_controller()->OnSigninScreenReady(); + + content::WindowedNotificationObserver profile_prepared_observer( + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, + content::NotificationService::AllSources()); + SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay); ASSERT_TRUE(auto_login_timer()); // Don't assert that timer is running: with the short delay sometimes @@ -597,6 +551,8 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, runner.QuitClosure()); runner.Run(); + profile_prepared_observer.Wait(); + // Wait for login tasks to complete. content::RunAllPendingInMessageLoop(); } @@ -613,12 +569,18 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); EXPECT_TRUE(auto_login_timer()); + content::WindowedNotificationObserver profile_prepared_observer( + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, + content::NotificationService::AllSources()); + // Log in and check that it stopped the timer. existing_user_controller()->Login(user_context, SigninSpecifics()); EXPECT_TRUE(is_login_in_progress()); ASSERT_TRUE(auto_login_timer()); EXPECT_FALSE(auto_login_timer()->IsRunning()); + profile_prepared_observer.Wait(); + // Wait for login tasks to complete. content::RunAllPendingInMessageLoop(); @@ -633,9 +595,9 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, .Times(2); UserContext user_context(kUsername); user_context.SetKey(Key(kPassword)); - EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) - .Times(1) - .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); + test::UserSessionManagerTestApi session_manager_test_api( + UserSessionManager::GetInstance()); + session_manager_test_api.InjectStubUserContext(user_context); existing_user_controller()->OnSigninScreenReady(); SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); @@ -671,11 +633,17 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); EXPECT_TRUE(auto_login_timer()); + content::WindowedNotificationObserver profile_prepared_observer( + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, + content::NotificationService::AllSources()); + // Check that login completes and stops the timer. existing_user_controller()->CompleteLogin(user_context); ASSERT_TRUE(auto_login_timer()); EXPECT_FALSE(auto_login_timer()->IsRunning()); + profile_prepared_observer.Wait(); + // Wait for login tasks to complete. content::RunAllPendingInMessageLoop(); @@ -695,6 +663,10 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); EXPECT_TRUE(auto_login_timer()); + content::WindowedNotificationObserver profile_prepared_observer( + chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, + content::NotificationService::AllSources()); + // Login and check that it stopped the timer. existing_user_controller()->Login( UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT, @@ -705,6 +677,8 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, ASSERT_TRUE(auto_login_timer()); EXPECT_FALSE(auto_login_timer()->IsRunning()); + profile_prepared_observer.Wait(); + // Wait for login tasks to complete. content::RunAllPendingInMessageLoop(); diff --git a/chrome/browser/chromeos/login/fake_login_utils.cc b/chrome/browser/chromeos/login/fake_login_utils.cc deleted file mode 100644 index 21df5b0..0000000 --- a/chrome/browser/chromeos/login/fake_login_utils.cc +++ /dev/null @@ -1,126 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/login/fake_login_utils.h" - -#include "base/callback.h" -#include "base/command_line.h" -#include "base/prefs/pref_service.h" -#include "chrome/browser/chrome_notification_types.h" -#include "chrome/browser/chromeos/login/ui/login_display_host.h" -#include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" -#include "chrome/browser/chromeos/login/user_flow.h" -#include "chrome/browser/chromeos/login/users/chrome_user_manager.h" -#include "chrome/browser/chromeos/login/users/supervised_user_manager.h" -#include "chrome/browser/chromeos/profiles/profile_helper.h" -#include "chrome/browser/first_run/first_run.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/signin/signin_manager_factory.h" -#include "chrome/browser/ui/startup/startup_browser_creator.h" -#include "chrome/common/pref_names.h" -#include "chrome/test/base/testing_profile.h" -#include "chromeos/login/auth/mock_authenticator.h" -#include "chromeos/login/auth/user_context.h" -#include "components/signin/core/browser/signin_manager.h" -#include "components/user_manager/user.h" -#include "components/user_manager/user_manager.h" -#include "content/public/browser/notification_service.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace chromeos { - -FakeLoginUtils::FakeLoginUtils() : should_launch_browser_(false) {} - -FakeLoginUtils::~FakeLoginUtils() {} - -void FakeLoginUtils::DoBrowserLaunch(Profile* profile, - LoginDisplayHost* login_host) { - if (!ChromeUserManager::Get()->GetCurrentUserFlow()->ShouldLaunchBrowser()) { - ChromeUserManager::Get()->GetCurrentUserFlow()->LaunchExtraSteps(profile); - return; - } - login_host->BeforeSessionStart(); - if (should_launch_browser_) { - StartupBrowserCreator browser_creator; - chrome::startup::IsFirstRun first_run = - first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN - : chrome::startup::IS_NOT_FIRST_RUN; - ASSERT_TRUE(browser_creator.LaunchBrowser( - *base::CommandLine::ForCurrentProcess(), profile, base::FilePath(), - chrome::startup::IS_PROCESS_STARTUP, first_run, NULL)); - } - if (login_host) - login_host->Finalize(); - user_manager::UserManager::Get()->SessionStarted(); -} - -void FakeLoginUtils::PrepareProfile(const UserContext& user_context, - bool has_cookies, - bool has_active_session, - LoginUtils::Delegate* delegate) { - user_manager::UserManager* user_manager = user_manager::UserManager::Get(); - user_manager->UserLoggedIn( - user_context.GetUserID(), user_context.GetUserIDHash(), false); - user_manager::User* user = - user_manager->FindUserAndModify(user_context.GetUserID()); - DCHECK(user); - - // Make sure that we get the real Profile instead of the login Profile. - user->set_profile_is_created(); - Profile* profile = ProfileHelper::Get()->GetProfileByUserUnsafe(user); - SigninManagerFactory::GetForProfile(profile)->SetAuthenticatedUsername( - user_context.GetUserID()); - - if (user_manager->IsLoggedInAsSupervisedUser()) { - user_manager::User* active_user = user_manager->GetActiveUser(); - std::string supervised_user_sync_id = - ChromeUserManager::Get()->GetSupervisedUserManager()->GetUserSyncId( - active_user->email()); - if (supervised_user_sync_id.empty()) - supervised_user_sync_id = "DUMMY ID"; - profile->GetPrefs()->SetString(prefs::kSupervisedUserId, - supervised_user_sync_id); - } - - content::NotificationService::current()->Notify( - chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, - content::NotificationService::AllSources(), - content::Details<Profile>(profile)); - - // Emulate UserSessionManager::InitializeUserSession() for now till - // FakeLoginUtils are deprecated. - bool browser_launched = false; - if (!user_manager->IsLoggedInAsKioskApp()) { - if (user_manager->IsCurrentUserNew()) { - NOTREACHED() << "Method not implemented."; - } else { - browser_launched = true; - LoginUtils::Get()->DoBrowserLaunch(profile, - LoginDisplayHostImpl::default_host()); - } - } - - if (delegate) - delegate->OnProfilePrepared(profile, browser_launched); -} - -void FakeLoginUtils::DelegateDeleted(LoginUtils::Delegate* delegate) { - NOTREACHED() << "Method not implemented."; -} - -scoped_refptr<Authenticator> FakeLoginUtils::CreateAuthenticator( - AuthStatusConsumer* consumer) { - authenticator_ = new MockAuthenticator(consumer, expected_user_context_); - return authenticator_; -} - -void FakeLoginUtils::SetExpectedCredentials(const UserContext& user_context) { - expected_user_context_ = user_context; - if (authenticator_.get()) { - static_cast<MockAuthenticator*>(authenticator_.get())-> - SetExpectedCredentials(user_context); - } -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/login/fake_login_utils.h b/chrome/browser/chromeos/login/fake_login_utils.h deleted file mode 100644 index 0696faf..0000000 --- a/chrome/browser/chromeos/login/fake_login_utils.h +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_LOGIN_UTILS_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_LOGIN_UTILS_H_ - -#include "chrome/browser/chromeos/login/login_utils.h" -#include "chromeos/login/auth/user_context.h" - -namespace chromeos { - -// This class emulates behavior of LoginUtils for browser tests. -// It provides: -// * Fake authentication. You can configure expected usernames and password for -// next auth attempt. -// * Preparing of profiles for authenticated users. -// * Launching browser for user, if |should_launch_browser_| set. -// * Correct communication with LoginDisplayHost and UserManager. -class FakeLoginUtils : public LoginUtils { - public: - FakeLoginUtils(); - ~FakeLoginUtils() override; - void DoBrowserLaunch(Profile* profile, LoginDisplayHost* login_host) override; - void PrepareProfile(const UserContext& user_context, - bool has_cookies, - bool has_active_session, - LoginUtils::Delegate* delegate) override; - void DelegateDeleted(LoginUtils::Delegate* delegate) override; - scoped_refptr<Authenticator> CreateAuthenticator( - AuthStatusConsumer* consumer) override; - - void SetExpectedCredentials(const UserContext& user_context); - void set_should_launch_browser(bool should_launch_browser) { - should_launch_browser_ = should_launch_browser; - } - - private: - scoped_refptr<Authenticator> authenticator_; - UserContext expected_user_context_; - bool should_launch_browser_; - - DISALLOW_COPY_AND_ASSIGN(FakeLoginUtils); -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_FAKE_LOGIN_UTILS_H_ diff --git a/chrome/browser/chromeos/login/lock/screen_locker.cc b/chrome/browser/chromeos/login/lock/screen_locker.cc index 3f3b08c..5fceb28 100644 --- a/chrome/browser/chromeos/login/lock/screen_locker.cc +++ b/chrome/browser/chromeos/login/lock/screen_locker.cc @@ -25,7 +25,6 @@ #include "base/strings/string_util.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_authentication.h" #include "chrome/browser/chromeos/login/ui/user_adding_screen.h" @@ -157,7 +156,7 @@ void ScreenLocker::Init() { saved_ime_state_ = imm->GetActiveIMEState(); imm->SetState(saved_ime_state_->Clone()); - authenticator_ = LoginUtils::Get()->CreateAuthenticator(this); + authenticator_ = UserSessionManager::GetInstance()->CreateAuthenticator(this); extended_authenticator_ = ExtendedAuthenticator::Create(this); delegate_.reset(new WebUIScreenLocker(this)); delegate_->LockScreen(); diff --git a/chrome/browser/chromeos/login/lock/screen_locker_browsertest.cc b/chrome/browser/chromeos/login/lock/screen_locker_browsertest.cc index 8de336e..d4c218c 100644 --- a/chrome/browser/chromeos/login/lock/screen_locker_browsertest.cc +++ b/chrome/browser/chromeos/login/lock/screen_locker_browsertest.cc @@ -21,7 +21,7 @@ #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/fake_session_manager_client.h" #include "chromeos/login/auth/key.h" -#include "chromeos/login/auth/mock_authenticator.h" +#include "chromeos/login/auth/stub_authenticator.h" #include "chromeos/login/auth/user_context.h" #include "chromeos/login/user_names.h" #include "content/public/browser/notification_service.h" @@ -156,7 +156,7 @@ IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestBasic) { UserContext user_context(chromeos::login::kStubUser); user_context.SetKey(Key("pass")); - tester->InjectMockAuthenticator(user_context); + tester->InjectStubUserContext(user_context); EXPECT_TRUE(tester->IsLocked()); tester->EnterPassword("fail"); content::RunAllPendingInMessageLoop(); @@ -205,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(ScreenLockerTest, TestFullscreenExit) { } UserContext user_context(chromeos::login::kStubUser); user_context.SetKey(Key("pass")); - tester->InjectMockAuthenticator(user_context); + tester->InjectStubUserContext(user_context); tester->EnterPassword("pass"); content::RunAllPendingInMessageLoop(); EXPECT_FALSE(tester->IsLocked()); diff --git a/chrome/browser/chromeos/login/lock/screen_locker_tester.cc b/chrome/browser/chromeos/login/lock/screen_locker_tester.cc index f51d88c..bdbe613 100644 --- a/chrome/browser/chromeos/login/lock/screen_locker_tester.cc +++ b/chrome/browser/chromeos/login/lock/screen_locker_tester.cc @@ -14,12 +14,13 @@ #include "chrome/browser/chromeos/login/lock/webui_screen_locker.h" #include "chromeos/login/auth/auth_status_consumer.h" #include "chromeos/login/auth/fake_extended_authenticator.h" -#include "chromeos/login/auth/mock_authenticator.h" +#include "chromeos/login/auth/stub_authenticator.h" #include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_view_host.h" #include "content/public/browser/web_contents.h" #include "content/public/browser/web_ui.h" #include "content/public/test/test_utils.h" +#include "testing/gtest/include/gtest/gtest.h" #include "ui/views/controls/button/button.h" #include "ui/views/controls/label.h" #include "ui/views/controls/textfield/textfield.h" @@ -199,11 +200,11 @@ bool ScreenLockerTester::IsLocked() { ScreenLocker::screen_locker_->locked_; } -void ScreenLockerTester::InjectMockAuthenticator( +void ScreenLockerTester::InjectStubUserContext( const UserContext& user_context) { DCHECK(ScreenLocker::screen_locker_); ScreenLocker::screen_locker_->SetAuthenticator( - new MockAuthenticator(ScreenLocker::screen_locker_, user_context)); + new StubAuthenticator(ScreenLocker::screen_locker_, user_context)); ScreenLocker::screen_locker_->extended_authenticator_ = new FakeExtendedAuthenticator(ScreenLocker::screen_locker_, user_context); } diff --git a/chrome/browser/chromeos/login/lock/screen_locker_tester.h b/chrome/browser/chromeos/login/lock/screen_locker_tester.h index 868a14c..a6e4014 100644 --- a/chrome/browser/chromeos/login/lock/screen_locker_tester.h +++ b/chrome/browser/chromeos/login/lock/screen_locker_tester.h @@ -29,8 +29,8 @@ class ScreenLockerTester { // Returns true if the screen is locked. virtual bool IsLocked(); - // Injects MockAuthenticator that uses the credentials in |user_context|. - virtual void InjectMockAuthenticator(const UserContext& user_context); + // Injects StubAuthenticator that uses the credentials in |user_context|. + virtual void InjectStubUserContext(const UserContext& user_context); // Sets the password text. virtual void SetPassword(const std::string& password) = 0; diff --git a/chrome/browser/chromeos/login/login_manager_test.cc b/chrome/browser/chromeos/login/login_manager_test.cc index add5d60..64ea06a 100644 --- a/chrome/browser/chromeos/login/login_manager_test.cc +++ b/chrome/browser/chromeos/login/login_manager_test.cc @@ -8,6 +8,8 @@ #include "chrome/browser/browser_process.h" #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" +#include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" #include "chrome/browser/chromeos/login/ui/login_display_host_impl.h" #include "chrome/browser/chromeos/login/ui/webui_login_view.h" #include "chromeos/chromeos_switches.h" @@ -44,11 +46,6 @@ void LoginManagerTest::SetUpCommandLine(base::CommandLine* command_line) { void LoginManagerTest::SetUpInProcessBrowserTestFixture() { MixinBasedBrowserTest::SetUpInProcessBrowserTestFixture(); - mock_login_utils_ = new testing::NiceMock<MockLoginUtils>(); - mock_login_utils_->DelegateToFake(); - mock_login_utils_->GetFakeLoginUtils()->set_should_launch_browser( - should_launch_browser_); - LoginUtils::Set(mock_login_utils_); } void LoginManagerTest::SetUpOnMainThread() { @@ -57,6 +54,10 @@ void LoginManagerTest::SetUpOnMainThread() { chrome::NOTIFICATION_LOGIN_OR_LOCK_WEBUI_VISIBLE, content::NotificationService::AllSources()).Wait(); InitializeWebContents(); + test::UserSessionManagerTestApi session_manager_test_api( + UserSessionManager::GetInstance()); + session_manager_test_api.SetShouldLaunchBrowserInTests( + should_launch_browser_); } void LoginManagerTest::RegisterUser(const std::string& user_id) { @@ -65,7 +66,9 @@ void LoginManagerTest::RegisterUser(const std::string& user_id) { } void LoginManagerTest::SetExpectedCredentials(const UserContext& user_context) { - login_utils().GetFakeLoginUtils()->SetExpectedCredentials(user_context); + test::UserSessionManagerTestApi session_manager_test_api( + UserSessionManager::GetInstance()); + session_manager_test_api.InjectStubUserContext(user_context); } bool LoginManagerTest::TryToLogin(const UserContext& user_context) { diff --git a/chrome/browser/chromeos/login/login_manager_test.h b/chrome/browser/chromeos/login/login_manager_test.h index 3fc5103..e2b6921 100644 --- a/chrome/browser/chromeos/login/login_manager_test.h +++ b/chrome/browser/chromeos/login/login_manager_test.h @@ -8,7 +8,6 @@ #include <string> #include "chrome/browser/chromeos/login/mixin_based_browser_test.h" -#include "chrome/browser/chromeos/login/mock_login_utils.h" #include "chrome/browser/chromeos/login/test/js_checker.h" namespace content { @@ -63,8 +62,6 @@ class LoginManagerTest : public MixinBasedBrowserTest { // that it is true. void JSExpect(const std::string& expression); - MockLoginUtils& login_utils() { return *mock_login_utils_; } - content::WebContents* web_contents() { return web_contents_; } test::JSChecker& js_checker() { return js_checker_; } @@ -76,7 +73,6 @@ class LoginManagerTest : public MixinBasedBrowserTest { web_contents_ = web_contents; } - MockLoginUtils* mock_login_utils_; bool should_launch_browser_; content::WebContents* web_contents_; test::JSChecker js_checker_; diff --git a/chrome/browser/chromeos/login/login_utils.cc b/chrome/browser/chromeos/login/login_utils.cc deleted file mode 100644 index 4ab088a..0000000 --- a/chrome/browser/chromeos/login/login_utils.cc +++ /dev/null @@ -1,170 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/login/login_utils.h" - -#include "base/command_line.h" -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "base/memory/scoped_ptr.h" -#include "base/memory/singleton.h" -#include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" -#include "chrome/browser/chromeos/login/lock/screen_locker.h" -#include "chrome/browser/chromeos/login/session/user_session_manager.h" -#include "chrome/browser/chromeos/login/ui/user_adding_screen.h" -#include "chrome/browser/chromeos/settings/cros_settings.h" -#include "chromeos/chromeos_switches.h" -#include "chromeos/settings/cros_settings_names.h" - -namespace chromeos { - -class LoginUtilsImpl : public LoginUtils, - public UserSessionManagerDelegate { - public: - LoginUtilsImpl() - : delegate_(NULL) { - } - - ~LoginUtilsImpl() override {} - - // LoginUtils implementation: - void DoBrowserLaunch(Profile* profile, LoginDisplayHost* login_host) override; - void PrepareProfile(const UserContext& user_context, - bool has_auth_cookies, - bool has_active_session, - LoginUtils::Delegate* delegate) override; - void DelegateDeleted(LoginUtils::Delegate* delegate) override; - scoped_refptr<Authenticator> CreateAuthenticator( - AuthStatusConsumer* consumer) override; - - // UserSessionManager::Delegate implementation: - void OnProfilePrepared(Profile* profile, bool browser_launched) override; - - private: - // Has to be scoped_refptr, see comment for CreateAuthenticator(...). - scoped_refptr<Authenticator> authenticator_; - - // Delegate to be fired when the profile will be prepared. - LoginUtils::Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(LoginUtilsImpl); -}; - -class LoginUtilsWrapper { - public: - static LoginUtilsWrapper* GetInstance() { - return Singleton<LoginUtilsWrapper>::get(); - } - - LoginUtils* get() { - base::AutoLock create(create_lock_); - if (!ptr_.get()) - reset(new LoginUtilsImpl); - return ptr_.get(); - } - - void reset(LoginUtils* ptr) { - ptr_.reset(ptr); - } - - private: - friend struct DefaultSingletonTraits<LoginUtilsWrapper>; - - LoginUtilsWrapper() {} - - base::Lock create_lock_; - scoped_ptr<LoginUtils> ptr_; - - DISALLOW_COPY_AND_ASSIGN(LoginUtilsWrapper); -}; - -void LoginUtilsImpl::DoBrowserLaunch(Profile* profile, - LoginDisplayHost* login_host) { - UserSessionManager::GetInstance()->DoBrowserLaunch(profile, login_host); -} - -void LoginUtilsImpl::PrepareProfile( - const UserContext& user_context, - bool has_auth_cookies, - bool has_active_session, - LoginUtils::Delegate* delegate) { - // TODO(nkostylev): We have to initialize LoginUtils delegate as long - // as it coexist with SessionManager. - delegate_ = delegate; - - UserSessionManager::StartSessionType start_session_type = - UserAddingScreen::Get()->IsRunning() ? - UserSessionManager::SECONDARY_USER_SESSION : - UserSessionManager::PRIMARY_USER_SESSION; - - // For the transition part LoginUtils will just delegate profile - // creation and initialization to SessionManager. Later LoginUtils will be - // removed and all LoginUtils clients will just work with SessionManager - // directly. - UserSessionManager::GetInstance()->StartSession(user_context, - start_session_type, - authenticator_, - has_auth_cookies, - has_active_session, - this); -} - -void LoginUtilsImpl::DelegateDeleted(LoginUtils::Delegate* delegate) { - if (delegate_ == delegate) - delegate_ = NULL; -} - -scoped_refptr<Authenticator> LoginUtilsImpl::CreateAuthenticator( - AuthStatusConsumer* consumer) { - // Screen locker needs new Authenticator instance each time. - if (ScreenLocker::default_screen_locker()) { - if (authenticator_.get()) - authenticator_->SetConsumer(NULL); - authenticator_ = NULL; - } - - if (authenticator_.get() == NULL) { - authenticator_ = new ChromeCryptohomeAuthenticator(consumer); - } else { - // TODO(nkostylev): Fix this hack by improving Authenticator dependencies. - authenticator_->SetConsumer(consumer); - } - return authenticator_; -} - -void LoginUtilsImpl::OnProfilePrepared(Profile* profile, - bool browser_launched) { - if (delegate_) - delegate_->OnProfilePrepared(profile, browser_launched); -} - -// static -LoginUtils* LoginUtils::Get() { - return LoginUtilsWrapper::GetInstance()->get(); -} - -// static -void LoginUtils::Set(LoginUtils* mock) { - LoginUtilsWrapper::GetInstance()->reset(mock); -} - -// static -bool LoginUtils::IsWhitelisted(const std::string& username, - bool* wildcard_match) { - // Skip whitelist check for tests. - if (base::CommandLine::ForCurrentProcess()->HasSwitch( - chromeos::switches::kOobeSkipPostLogin)) { - return true; - } - - CrosSettings* cros_settings = CrosSettings::Get(); - bool allow_new_user = false; - cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); - if (allow_new_user) - return true; - return cros_settings->FindEmailInList( - kAccountsPrefUsers, username, wildcard_match); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/login/login_utils.h b/chrome/browser/chromeos/login/login_utils.h deleted file mode 100644 index e532d0f..0000000 --- a/chrome/browser/chromeos/login/login_utils.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ - -#include <string> - -#include "base/callback_forward.h" -#include "base/memory/ref_counted.h" - -class PrefService; -class Profile; - -namespace base { -class CommandLine; -} - -namespace chromeos { - -class Authenticator; -class LoginDisplayHost; -class AuthStatusConsumer; -class UserContext; - -class LoginUtils { - public: - class Delegate { - public: - // Called after profile is loaded and prepared for the session. - // |browser_launched| will be true is browser has been launched, otherwise - // it will return false and client is responsible on launching browser. - virtual void OnProfilePrepared(Profile* profile, - bool browser_launched) = 0; - - protected: - virtual ~Delegate() {} - }; - - // Get LoginUtils singleton object. If it was not set before, new default - // instance will be created. - static LoginUtils* Get(); - - // Set LoginUtils singleton object for test purpose only! - static void Set(LoginUtils* ptr); - - // Checks if the given username is whitelisted and allowed to sign-in to - // this device. |wildcard_match| may be NULL. If it's present, it'll be set to - // true if the whitelist check was satisfied via a wildcard. - static bool IsWhitelisted(const std::string& username, bool* wildcard_match); - - virtual ~LoginUtils() {} - - // Thin wrapper around StartupBrowserCreator::LaunchBrowser(). Meant to be - // used in a Task posted to the UI thread. Once the browser is launched the - // login host is deleted. - virtual void DoBrowserLaunch(Profile* profile, - LoginDisplayHost* login_host) = 0; - - // Loads and prepares profile for the session. Fires |delegate| in the end. - // |user_context.username_hash| defines when user homedir is mounted. - // Also see DelegateDeleted method. - // If |has_active_session| is true than this is a case of restoring user - // session after browser crash so no need to start new session. - virtual void PrepareProfile( - const UserContext& user_context, - bool has_auth_cookies, - bool has_active_session, - Delegate* delegate) = 0; - - // Invalidates |delegate|, which was passed to PrepareProfile method call. - virtual void DelegateDeleted(Delegate* delegate) = 0; - - // Creates and returns the authenticator to use. - // Before WebUI login (Up to R14) the caller owned the returned - // Authenticator instance and had to delete it when done. - // New instance was created on each new login attempt. - // Starting with WebUI login (R15) single Authenticator instance is used for - // entire login process, even for multiple retries. Authenticator instance - // holds reference to login profile and is later used during fetching of - // OAuth tokens. - // TODO(nkostylev): Cleanup after WebUI login migration is complete. - virtual scoped_refptr<Authenticator> CreateAuthenticator( - AuthStatusConsumer* consumer) = 0; -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_UTILS_H_ diff --git a/chrome/browser/chromeos/login/mock_login_utils.cc b/chrome/browser/chromeos/login/mock_login_utils.cc deleted file mode 100644 index 23e6a95..0000000 --- a/chrome/browser/chromeos/login/mock_login_utils.cc +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "chrome/browser/chromeos/login/mock_login_utils.h" - -#include "chromeos/login/auth/user_context.h" - -using namespace testing; - -namespace chromeos { - -MockLoginUtils::MockLoginUtils() {} - -MockLoginUtils::~MockLoginUtils() {} - -void MockLoginUtils::DelegateToFake() { - if (fake_login_utils_.get()) - return; - fake_login_utils_.reset(new FakeLoginUtils()); - FakeLoginUtils* fake = fake_login_utils_.get(); - ON_CALL(*this, DoBrowserLaunch(_, _)) - .WillByDefault(Invoke(fake, &FakeLoginUtils::DoBrowserLaunch)); - ON_CALL(*this, PrepareProfile(_, _, _, _)) - .WillByDefault(Invoke(fake, &FakeLoginUtils::PrepareProfile)); - ON_CALL(*this, CreateAuthenticator(_)) - .WillByDefault(Invoke(fake, &FakeLoginUtils::CreateAuthenticator)); -} - -FakeLoginUtils* MockLoginUtils::GetFakeLoginUtils() { - return fake_login_utils_.get(); -} - -} // namespace chromeos diff --git a/chrome/browser/chromeos/login/mock_login_utils.h b/chrome/browser/chromeos/login/mock_login_utils.h deleted file mode 100644 index 5c6dd88..0000000 --- a/chrome/browser/chromeos/login/mock_login_utils.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_UTILS_H_ -#define CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_UTILS_H_ - -#include <string> - -#include "base/command_line.h" -#include "base/memory/ref_counted.h" -#include "chrome/browser/chromeos/login/fake_login_utils.h" -#include "chrome/browser/chromeos/login/login_utils.h" -#include "chrome/browser/chromeos/login/ui/login_display_host.h" -#include "chromeos/login/auth/authenticator.h" -#include "google_apis/gaia/gaia_auth_consumer.h" -#include "testing/gmock/include/gmock/gmock.h" -#include "url/gurl.h" - -class Profile; - -namespace chromeos { - -class AuthStatusConsumer; -class UserContext; - -class MockLoginUtils : public LoginUtils { - public: - MockLoginUtils(); - virtual ~MockLoginUtils(); - - MOCK_METHOD2(DoBrowserLaunch, void(Profile*, LoginDisplayHost*)); - MOCK_METHOD4(PrepareProfile, - void(const UserContext&, - bool, bool, LoginUtils::Delegate*)); - MOCK_METHOD1(DelegateDeleted, void(LoginUtils::Delegate*)); - MOCK_METHOD1(CreateAuthenticator, - scoped_refptr<Authenticator>(AuthStatusConsumer*)); - - void DelegateToFake(); - FakeLoginUtils* GetFakeLoginUtils(); - - private: - scoped_ptr<FakeLoginUtils> fake_login_utils_; -}; - -} // namespace chromeos - -#endif // CHROME_BROWSER_CHROMEOS_LOGIN_MOCK_LOGIN_UTILS_H_ diff --git a/chrome/browser/chromeos/login/screens/network_screen.cc b/chrome/browser/chromeos/login/screens/network_screen.cc index 5c65da6..f451b52 100644 --- a/chrome/browser/chromeos/login/screens/network_screen.cc +++ b/chrome/browser/chromeos/login/screens/network_screen.cc @@ -14,7 +14,6 @@ #include "chrome/browser/chromeos/customization/customization_document.h" #include "chrome/browser/chromeos/login/help_app_launcher.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/screen_manager.h" #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" #include "chrome/browser/chromeos/login/screens/network_view.h" @@ -61,7 +60,10 @@ NetworkScreen::NetworkScreen(BaseScreenDelegate* base_screen_delegate, view_->Bind(*this); input_method::InputMethodManager::Get()->AddObserver(this); + InitializeTimezoneObserver(); +} +void NetworkScreen::InitializeTimezoneObserver() { timezone_subscription_ = CrosSettings::Get()->AddSettingsObserver( kSystemTimezone, base::Bind(&NetworkScreen::OnSystemTimezoneChanged, base::Unretained(this))); @@ -96,11 +98,15 @@ void NetworkScreen::Show() { SetApplicationLocale(startup_manifest->initial_locale_default()); } + if (!timezone_subscription_) + InitializeTimezoneObserver(); + if (view_) view_->Show(); } void NetworkScreen::Hide() { + timezone_subscription_.reset(); if (view_) view_->Hide(); } diff --git a/chrome/browser/chromeos/login/screens/network_screen.h b/chrome/browser/chromeos/login/screens/network_screen.h index 8350d06..5c8cc2d 100644 --- a/chrome/browser/chromeos/login/screens/network_screen.h +++ b/chrome/browser/chromeos/login/screens/network_screen.h @@ -96,6 +96,9 @@ class NetworkScreen : public NetworkModel, FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, Timeout); FRIEND_TEST_ALL_PREFIXES(NetworkScreenTest, CanConnect); + // Subscribe to timezone changes. + void InitializeTimezoneObserver(); + // Subscribes NetworkScreen to the network change notification, // forces refresh of current network state. void Refresh(); diff --git a/chrome/browser/chromeos/login/screens/user_image_screen.cc b/chrome/browser/chromeos/login/screens/user_image_screen.cc index 5d968b2..5ca1b54 100644 --- a/chrome/browser/chromeos/login/screens/user_image_screen.cc +++ b/chrome/browser/chromeos/login/screens/user_image_screen.cc @@ -18,7 +18,6 @@ #include "chrome/browser/chrome_notification_types.h" #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/camera_presence_notifier.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/screen_manager.h" #include "chrome/browser/chromeos/login/screens/base_screen_delegate.h" #include "chrome/browser/chromeos/login/screens/user_image_view.h" @@ -300,6 +299,10 @@ void UserImageScreen::Show() { void UserImageScreen::Hide() { CameraPresenceNotifier::GetInstance()->RemoveObserver(this); notification_registrar_.RemoveAll(); + policy_registrar_.reset(); + sync_timer_.reset(); + if (UserImageSyncObserver* sync_observer = GetSyncObserver()) + sync_observer->RemoveObserver(this); if (view_) view_->Hide(); } diff --git a/chrome/browser/chromeos/login/session/user_session_manager.cc b/chrome/browser/chromeos/login/session/user_session_manager.cc index e042830..598cd9c 100644 --- a/chrome/browser/chromeos/login/session/user_session_manager.cc +++ b/chrome/browser/chromeos/login/session/user_session_manager.cc @@ -30,9 +30,11 @@ #include "chrome/browser/chromeos/boot_times_recorder.h" #include "chrome/browser/chromeos/first_run/first_run.h" #include "chrome/browser/chromeos/input_method/input_method_util.h" +#include "chrome/browser/chromeos/login/auth/chrome_cryptohome_authenticator.h" #include "chrome/browser/chromeos/login/chrome_restart_request.h" #include "chrome/browser/chromeos/login/demo_mode/demo_app_launcher.h" #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" +#include "chrome/browser/chromeos/login/lock/screen_locker.h" #include "chrome/browser/chromeos/login/profile_auth_data.h" #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter_factory.h" @@ -75,6 +77,7 @@ #include "chromeos/dbus/cryptohome_client.h" #include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/session_manager_client.h" +#include "chromeos/login/auth/stub_authenticator.h" #include "chromeos/login/user_names.h" #include "chromeos/network/portal_detector/network_portal_detector.h" #include "chromeos/network/portal_detector/network_portal_detector_strategy.h" @@ -313,14 +316,16 @@ void UserSessionManager::RegisterPrefs(PrefRegistrySimple* registry) { } UserSessionManager::UserSessionManager() - : delegate_(NULL), + : delegate_(nullptr), + authenticator_(nullptr), has_auth_cookies_(false), user_sessions_restored_(false), user_sessions_restore_in_progress_(false), exit_after_session_restore_(false), session_restore_strategy_( OAuth2LoginManager::RESTORE_FROM_SAVED_OAUTH2_REFRESH_TOKEN), - running_easy_unlock_key_ops_(false) { + running_easy_unlock_key_ops_(false), + should_launch_browser_(true) { net::NetworkChangeNotifier::AddConnectionTypeObserver(this); user_manager::UserManager::Get()->AddSessionStateObserver(this); } @@ -365,14 +370,35 @@ void UserSessionManager::CompleteGuestSessionLogin(const GURL& start_url) { RestartChrome(cmd_line_str); } +scoped_refptr<Authenticator> UserSessionManager::CreateAuthenticator( + AuthStatusConsumer* consumer) { + // Screen locker needs new Authenticator instance each time. + if (ScreenLocker::default_screen_locker()) { + if (authenticator_.get()) + authenticator_->SetConsumer(NULL); + authenticator_ = NULL; + } + + if (authenticator_.get() == NULL) { + if (injected_user_context_) { + authenticator_ = + new StubAuthenticator(consumer, *injected_user_context_.get()); + } else { + authenticator_ = new ChromeCryptohomeAuthenticator(consumer); + } + } else { + // TODO(nkostylev): Fix this hack by improving Authenticator dependencies. + authenticator_->SetConsumer(consumer); + } + return authenticator_; +} + void UserSessionManager::StartSession( const UserContext& user_context, StartSessionType start_session_type, - scoped_refptr<Authenticator> authenticator, bool has_auth_cookies, bool has_active_session, UserSessionManagerDelegate* delegate) { - authenticator_ = authenticator; delegate_ = delegate; start_session_type_ = start_session_type; @@ -390,6 +416,11 @@ void UserSessionManager::StartSession( PrepareProfile(); } +void UserSessionManager::DelegateDeleted(UserSessionManagerDelegate* delegate) { + if (delegate_ == delegate) + delegate_ = nullptr; +} + void UserSessionManager::PerformPostUserLoggedInActions() { user_manager::UserManager* user_manager = user_manager::UserManager::Get(); if (user_manager->GetLoggedInUsers().size() == 1) { @@ -989,7 +1020,7 @@ void UserSessionManager::FinalizePrepareProfile(Profile* profile) { bool browser_launched = InitializeUserSession(profile); // TODO(nkostylev): This pointer should probably never be NULL, but it looks - // like LoginUtilsImpl::OnProfileCreated() may be getting called before + // like OnProfileCreated() may be getting called before // UserSessionManager::PrepareProfile() has set |delegate_| when Chrome is // killed during shutdown in tests -- see http://crosbug.com/18269. Replace // this 'if' statement with a CHECK(delegate_) once the underlying issue is @@ -1074,8 +1105,7 @@ bool UserSessionManager::InitializeUserSession(Profile* profile) { } } - LoginUtils::Get()->DoBrowserLaunch(profile, - LoginDisplayHostImpl::default_host()); + DoBrowserLaunch(profile, LoginDisplayHostImpl::default_host()); return true; } @@ -1288,7 +1318,6 @@ void UserSessionManager::RestorePendingUserSessions() { // (and session) has been loaded on Chrome startup. StartSession(user_context, SECONDARY_USER_SESSION_AFTER_CRASH, - NULL, // authenticator false, // has_auth_cookies true, // has_active_session, this is restart after crash this); @@ -1451,18 +1480,23 @@ void UserSessionManager::DoBrowserLaunchInternal(Profile* profile, VLOG(1) << "Launching browser..."; TRACE_EVENT0("login", "LaunchBrowser"); - StartupBrowserCreator browser_creator; - int return_code; - chrome::startup::IsFirstRun first_run = - ::first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN - : chrome::startup::IS_NOT_FIRST_RUN; + if (should_launch_browser_) { + StartupBrowserCreator browser_creator; + int return_code; + chrome::startup::IsFirstRun first_run = + ::first_run::IsChromeFirstRun() ? chrome::startup::IS_FIRST_RUN + : chrome::startup::IS_NOT_FIRST_RUN; - browser_creator.LaunchBrowser( - *base::CommandLine::ForCurrentProcess(), profile, base::FilePath(), - chrome::startup::IS_PROCESS_STARTUP, first_run, &return_code); + browser_creator.LaunchBrowser( + *base::CommandLine::ForCurrentProcess(), profile, base::FilePath(), + chrome::startup::IS_PROCESS_STARTUP, first_run, &return_code); - // Triggers app launcher start page service to load start page web contents. - app_list::StartPageService::Get(profile); + // Triggers app launcher start page service to load start page web contents. + app_list::StartPageService::Get(profile); + } else { + LOG(WARNING) << "Browser hasn't been launched, should_launch_browser_" + << " is false. This is normal in some tests."; + } // Mark login host for deletion after browser starts. This // guarantees that the message loop will be referenced by the @@ -1503,4 +1537,10 @@ void UserSessionManager::RemoveProfileForTesting(Profile* profile) { default_ime_states_.erase(profile); } +void UserSessionManager::InjectStubUserContext( + const UserContext& user_context) { + injected_user_context_.reset(new UserContext(user_context)); + authenticator_ = NULL; +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/session/user_session_manager.h b/chrome/browser/chromeos/login/session/user_session_manager.h index 3d47ce53..88f9118 100644 --- a/chrome/browser/chromeos/login/session/user_session_manager.h +++ b/chrome/browser/chromeos/login/session/user_session_manager.h @@ -29,13 +29,15 @@ class PrefService; class Profile; namespace user_manager { - class User; - } // namespace user_manager namespace chromeos { +namespace test { +class UserSessionManagerTestApi; +} // namespace test + class EasyUnlockKeyManager; class InputEventsBlocker; class LoginDisplayHost; @@ -104,15 +106,24 @@ class UserSessionManager // |start_url| is an optional URL to be opened in Guest session browser. void CompleteGuestSessionLogin(const GURL& start_url); - // Start user session given |user_context| and |authenticator| which holds - // authentication context (profile). + // Creates and returns the authenticator to use. + // Single Authenticator instance is used for entire login process, + // even for multiple retries. Authenticator instance holds reference to + // login profile and is later used during fetching of OAuth tokens. + scoped_refptr<Authenticator> CreateAuthenticator( + AuthStatusConsumer* consumer); + + // Start user session given |user_context|. + // OnProfilePrepared() will be called on |delegate| once Profile is ready. void StartSession(const UserContext& user_context, StartSessionType start_session_type, - scoped_refptr<Authenticator> authenticator, bool has_auth_cookies, bool has_active_session, UserSessionManagerDelegate* delegate); + // Invalidates |delegate|, which was passed to StartSession method call. + void DelegateDeleted(UserSessionManagerDelegate* delegate); + // Perform additional actions once system wide notification // "UserLoggedIn" has been sent. void PerformPostUserLoggedInActions(); @@ -213,6 +224,7 @@ class UserSessionManager void RemoveProfileForTesting(Profile* profile); private: + friend class test::UserSessionManagerTestApi; friend struct DefaultSingletonTraits<UserSessionManager>; typedef std::set<std::string> SigninSessionRestoreStateSet; @@ -328,6 +340,18 @@ class UserSessionManager InputEventsBlocker* input_events_blocker, const locale_util::LanguageSwitchResult& result); + // Test API methods. + + // Injects |user_context| that will be used to create StubAuthenticator + // instance when CreateAuthenticator() is called. + void InjectStubUserContext(const UserContext& user_context); + + // Controls whether browser instance should be launched after sign in + // (used in tests). + void set_should_launch_browser_in_tests(bool should_launch_browser) { + should_launch_browser_ = should_launch_browser; + } + UserSessionManagerDelegate* delegate_; // Authentication/user context. @@ -335,6 +359,9 @@ class UserSessionManager scoped_refptr<Authenticator> authenticator_; StartSessionType start_session_type_; + // Injected user context for stub authenticator. + scoped_ptr<UserContext> injected_user_context_; + // True if the authentication context's cookie jar contains authentication // cookies from the authentication extension login flow. bool has_auth_cookies_; @@ -383,6 +410,9 @@ class UserSessionManager bool running_easy_unlock_key_ops_; base::Closure easy_unlock_key_ops_finished_callback_; + // Whether should launch browser, tests may override this value. + bool should_launch_browser_; + DISALLOW_COPY_AND_ASSIGN(UserSessionManager); }; diff --git a/chrome/browser/chromeos/login/session/user_session_manager_test_api.cc b/chrome/browser/chromeos/login/session/user_session_manager_test_api.cc new file mode 100644 index 0000000..6f5ae21 --- /dev/null +++ b/chrome/browser/chromeos/login/session/user_session_manager_test_api.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h" + +namespace chromeos { +namespace test { + +UserSessionManagerTestApi::UserSessionManagerTestApi( + UserSessionManager* session_manager) + : session_manager_(session_manager) { +} + +void UserSessionManagerTestApi::InjectStubUserContext( + const UserContext& user_context) { + session_manager_->InjectStubUserContext(user_context); +} + +void UserSessionManagerTestApi::SetShouldLaunchBrowserInTests( + bool should_launch_browser) { + session_manager_->set_should_launch_browser_in_tests(should_launch_browser); +} + +} // namespace test +} // namespace chromeos diff --git a/chrome/browser/chromeos/login/session/user_session_manager_test_api.h b/chrome/browser/chromeos/login/session/user_session_manager_test_api.h new file mode 100644 index 0000000..d811470 --- /dev/null +++ b/chrome/browser/chromeos/login/session/user_session_manager_test_api.h @@ -0,0 +1,36 @@ +// Copyright (c) 2015 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_TEST_API_H_ +#define CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_TEST_API_H_ + +#include "base/basictypes.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" + +namespace chromeos { +namespace test { + +// Accesses private data from a UserSessionManager for testing. +class UserSessionManagerTestApi { + public: + explicit UserSessionManagerTestApi(UserSessionManager* session_manager); + + // Injects |user_context| that will be used to create StubAuthenticator + // instance when UserSessionManager::CreateAuthenticator() is called. + void InjectStubUserContext(const UserContext& user_context); + + // Controls whether browser instance should be launched after sign in + // (used in tests). + void SetShouldLaunchBrowserInTests(bool should_launch_browser); + + private: + UserSessionManager* session_manager_; // not owned + + DISALLOW_COPY_AND_ASSIGN(UserSessionManagerTestApi); +}; + +} // namespace test +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_LOGIN_SESSION_USER_SESSION_MANAGER_TEST_API_H_ diff --git a/chrome/browser/chromeos/login/session_login_browsertest.cc b/chrome/browser/chromeos/login/session_login_browsertest.cc index e04c0dd..bdfdb1c 100644 --- a/chrome/browser/chromeos/login/session_login_browsertest.cc +++ b/chrome/browser/chromeos/login/session_login_browsertest.cc @@ -4,6 +4,7 @@ #include "ash/session/session_state_delegate.h" #include "ash/shell.h" +#include "base/command_line.h" #include "chrome/browser/chromeos/login/login_manager_test.h" #include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/profiles/profile_manager.h" diff --git a/chrome/browser/chromeos/login/supervised/supervised_user_login_flow.cc b/chrome/browser/chromeos/login/supervised/supervised_user_login_flow.cc index 39d5e41..cbbbc6e 100644 --- a/chrome/browser/chromeos/login/supervised/supervised_user_login_flow.cc +++ b/chrome/browser/chromeos/login/supervised/supervised_user_login_flow.cc @@ -11,7 +11,7 @@ #include "base/prefs/pref_registry_simple.h" #include "base/prefs/pref_service.h" #include "base/values.h" -#include "chrome/browser/chromeos/login/login_utils.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_authentication.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_constants.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_screen.h" @@ -252,7 +252,7 @@ void SupervisedUserLoginFlow::OnPasswordUpdated( } void SupervisedUserLoginFlow::Finish() { - LoginUtils::Get()->DoBrowserLaunch(profile_, host()); + UserSessionManager::GetInstance()->DoBrowserLaunch(profile_, host()); profile_ = NULL; UnregisterFlowSoon(); } diff --git a/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc b/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc index c5efa20..64bec8af0 100644 --- a/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc +++ b/chrome/browser/chromeos/login/supervised/supervised_user_test_base.cc @@ -368,7 +368,6 @@ void SupervisedUserTestBase::SigninAsSupervisedUser( user_manager::UserManager::Get()->GetUsers().at(user_index); ASSERT_EQ(base::UTF8ToUTF16(expected_display_name), user->display_name()); - // Currently FakeLoginUtils do not support first-run use cases. // Clean first run flag before logging in. static_cast<SupervisedUserManagerImpl*>( ChromeUserManager::Get()->GetSupervisedUserManager()) diff --git a/chrome/browser/chromeos/login/ui/login_display_host_impl.cc b/chrome/browser/chromeos/login/ui/login_display_host_impl.cc index c6b8cfe..a6b62ce 100644 --- a/chrome/browser/chromeos/login/ui/login_display_host_impl.cc +++ b/chrome/browser/chromeos/login/ui/login_display_host_impl.cc @@ -35,7 +35,6 @@ #include "chrome/browser/chromeos/login/enrollment/auto_enrollment_controller.h" #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/login_wizard.h" #include "chrome/browser/chromeos/login/screens/core_oobe_actor.h" #include "chrome/browser/chromeos/login/startup_utils.h" diff --git a/chrome/browser/chromeos/login/ui/user_adding_screen_browsertest.cc b/chrome/browser/chromeos/login/ui/user_adding_screen_browsertest.cc index 39a1ebc2..e406267 100644 --- a/chrome/browser/chromeos/login/ui/user_adding_screen_browsertest.cc +++ b/chrome/browser/chromeos/login/ui/user_adding_screen_browsertest.cc @@ -91,7 +91,6 @@ IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, PRE_CancelAdding) { } IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, CancelAdding) { - EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); EXPECT_EQ(3u, user_manager::UserManager::Get()->GetUsers().size()); EXPECT_EQ(0u, user_manager::UserManager::Get()->GetLoggedInUsers().size()); @@ -136,7 +135,6 @@ IN_PROC_BROWSER_TEST_F(UserAddingScreenTest, AddingSeveralUsers) { EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_LOGIN_PRIMARY, ash::Shell::GetInstance()->session_state_delegate()-> GetSessionState()); - EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(3); LoginUser(kTestUsers[0]); EXPECT_EQ(ash::SessionStateDelegate::SESSION_STATE_ACTIVE, ash::Shell::GetInstance()->session_state_delegate()-> diff --git a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc index 48309e4..e0213a6 100644 --- a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc +++ b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.cc @@ -81,17 +81,29 @@ UserImageManager* FakeChromeUserManager::GetUserImageManager( void FakeChromeUserManager::SetUserFlow(const std::string& email, UserFlow* flow) { + ResetUserFlow(email); + specific_flows_[email] = flow; } UserFlow* FakeChromeUserManager::GetCurrentUserFlow() const { - return nullptr; + if (!IsUserLoggedIn()) + return GetDefaultUserFlow(); + return GetUserFlow(GetLoggedInUser()->email()); } UserFlow* FakeChromeUserManager::GetUserFlow(const std::string& email) const { - return nullptr; + FlowMap::const_iterator it = specific_flows_.find(email); + if (it != specific_flows_.end()) + return it->second; + return GetDefaultUserFlow(); } void FakeChromeUserManager::ResetUserFlow(const std::string& email) { + FlowMap::iterator it = specific_flows_.find(email); + if (it != specific_flows_.end()) { + delete it->second; + specific_flows_.erase(it); + } } void FakeChromeUserManager::SwitchActiveUser(const std::string& email) { @@ -150,4 +162,10 @@ user_manager::UserList FakeChromeUserManager::GetUsersAllowedForMultiProfile() return result; } +UserFlow* FakeChromeUserManager::GetDefaultUserFlow() const { + if (!default_flow_.get()) + default_flow_.reset(new DefaultUserFlow()); + return default_flow_.get(); +} + } // namespace chromeos diff --git a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h index 3a51cf4..d43ae334 100644 --- a/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h +++ b/chrome/browser/chromeos/login/users/fake_chrome_user_manager.h @@ -69,11 +69,23 @@ class FakeChromeUserManager : public user_manager::FakeUserManager, } private: + // Lazily creates default user flow. + UserFlow* GetDefaultUserFlow() const; + scoped_ptr<FakeSupervisedUserManager> supervised_user_manager_; std::string owner_email_; MultiProfileUserController* multi_profile_user_controller_; + typedef std::map<std::string, UserFlow*> FlowMap; + + // Lazy-initialized default flow. + mutable scoped_ptr<UserFlow> default_flow_; + + // Specific flows by user e-mail. + // Keys should be canonicalized before access. + FlowMap specific_flows_; + DISALLOW_COPY_AND_ASSIGN(FakeChromeUserManager); }; diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index b48c7d8..55b0d60 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -30,7 +30,6 @@ #include "chrome/browser/chromeos/login/existing_user_controller.h" #include "chrome/browser/chromeos/login/helper.h" #include "chrome/browser/chromeos/login/hwid_checker.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/screens/device_disabled_screen.h" #include "chrome/browser/chromeos/login/screens/enable_debugging_screen.h" #include "chrome/browser/chromeos/login/screens/error_screen.h" @@ -44,6 +43,7 @@ #include "chrome/browser/chromeos/login/screens/update_screen.h" #include "chrome/browser/chromeos/login/screens/user_image_screen.h" #include "chrome/browser/chromeos/login/screens/wrong_hwid_screen.h" +#include "chrome/browser/chromeos/login/session/user_session_manager.h" #include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_screen.h" #include "chrome/browser/chromeos/login/ui/login_display_host.h" @@ -647,8 +647,8 @@ void WizardController::OnUserImageSelected() { // Launch browser and delete login host controller. BrowserThread::PostTask( BrowserThread::UI, FROM_HERE, - base::Bind(&LoginUtils::DoBrowserLaunch, - base::Unretained(LoginUtils::Get()), + base::Bind(&UserSessionManager::DoBrowserLaunch, + base::Unretained(UserSessionManager::GetInstance()), ProfileManager::GetActiveUserProfile(), host_)); host_ = NULL; } diff --git a/chrome/browser/chromeos/net/network_portal_detector_impl_browsertest.cc b/chrome/browser/chromeos/net/network_portal_detector_impl_browsertest.cc index 491b80a1..a33dd88 100644 --- a/chrome/browser/chromeos/net/network_portal_detector_impl_browsertest.cc +++ b/chrome/browser/chromeos/net/network_portal_detector_impl_browsertest.cc @@ -19,6 +19,7 @@ #include "components/captive_portal/captive_portal_testing_utils.h" #include "content/public/test/test_utils.h" #include "dbus/object_path.h" +#include "net/base/net_errors.h" #include "third_party/cros_system_api/dbus/service_constants.h" #include "ui/message_center/message_center.h" #include "ui/message_center/message_center_observer.h" diff --git a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc index a187585..264692d 100644 --- a/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc +++ b/chrome/browser/chromeos/policy/user_cloud_policy_manager_factory_chromeos.cc @@ -15,12 +15,12 @@ #include "base/threading/sequenced_worker_pool.h" #include "base/time/time.h" #include "chrome/browser/browser_process.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" #include "chrome/browser/chromeos/policy/user_cloud_external_data_manager.h" #include "chrome/browser/chromeos/policy/user_cloud_policy_manager_chromeos.h" #include "chrome/browser/chromeos/policy/user_cloud_policy_store_chromeos.h" #include "chrome/browser/chromeos/profiles/profile_helper.h" +#include "chrome/browser/chromeos/settings/cros_settings.h" #include "chrome/browser/policy/schema_registry_service.h" #include "chrome/browser/policy/schema_registry_service_factory.h" #include "chrome/browser/profiles/profile.h" @@ -212,9 +212,8 @@ scoped_ptr<UserCloudPolicyManagerChromeOS> bool wildcard_match = false; if (connector->IsEnterpriseManaged() && - chromeos::LoginUtils::IsWhitelisted(username, &wildcard_match) && - wildcard_match && - !connector->IsNonEnterpriseUser(username)) { + chromeos::CrosSettings::IsWhitelisted(username, &wildcard_match) && + wildcard_match && !connector->IsNonEnterpriseUser(username)) { manager->EnableWildcardLoginCheck(username); } diff --git a/chrome/browser/chromeos/preferences_browsertest.cc b/chrome/browser/chromeos/preferences_browsertest.cc index b68b2be..ef44d88 100644 --- a/chrome/browser/chromeos/preferences_browsertest.cc +++ b/chrome/browser/chromeos/preferences_browsertest.cc @@ -5,6 +5,7 @@ #include <sys/types.h> #include "ash/shell.h" +#include "base/command_line.h" #include "base/compiler_specific.h" #include "base/macros.h" #include "base/prefs/pref_service.h" diff --git a/chrome/browser/chromeos/profiles/profile_helper.h b/chrome/browser/chromeos/profiles/profile_helper.h index cac7855..e15475f 100644 --- a/chrome/browser/chromeos/profiles/profile_helper.h +++ b/chrome/browser/chromeos/profiles/profile_helper.h @@ -123,8 +123,11 @@ class ProfileHelper const std::string& user_id); private: + // TODO(nkostylev): Create a test API class that will be the only one allowed + // to access private test methods. friend class CryptohomeAuthenticatorTest; friend class DeviceSettingsTestBase; + friend class ExistingUserControllerTest; friend class extensions::ExtensionGarbageCollectorChromeOSUnitTest; friend class FakeChromeUserManager; friend class KioskTest; diff --git a/chrome/browser/chromeos/settings/cros_settings.cc b/chrome/browser/chromeos/settings/cros_settings.cc index 96427d2..016b33a 100644 --- a/chrome/browser/chromeos/settings/cros_settings.cc +++ b/chrome/browser/chromeos/settings/cros_settings.cc @@ -15,6 +15,7 @@ #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" #include "chrome/browser/chromeos/settings/system_settings_provider.h" #include "chromeos/chromeos_switches.h" +#include "chromeos/settings/cros_settings_names.h" #include "google_apis/gaia/gaia_auth_util.h" namespace chromeos { @@ -45,6 +46,24 @@ CrosSettings* CrosSettings::Get() { return g_cros_settings; } +// static +bool CrosSettings::IsWhitelisted(const std::string& username, + bool* wildcard_match) { + // Skip whitelist check for tests. + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + chromeos::switches::kOobeSkipPostLogin)) { + return true; + } + + CrosSettings* cros_settings = CrosSettings::Get(); + bool allow_new_user = false; + cros_settings->GetBoolean(kAccountsPrefAllowNewUser, &allow_new_user); + if (allow_new_user) + return true; + return cros_settings->FindEmailInList(kAccountsPrefUsers, username, + wildcard_match); +} + CrosSettings::CrosSettings(DeviceSettingsService* device_settings_service) { CrosSettingsProvider::NotifyObserversCallback notify_cb( base::Bind(&CrosSettings::FireObservers, diff --git a/chrome/browser/chromeos/settings/cros_settings.h b/chrome/browser/chromeos/settings/cros_settings.h index f7becbe..366e15c 100644 --- a/chrome/browser/chromeos/settings/cros_settings.h +++ b/chrome/browser/chromeos/settings/cros_settings.h @@ -35,6 +35,11 @@ class CrosSettings : public base::NonThreadSafe { static void Shutdown(); static CrosSettings* Get(); + // Checks if the given username is whitelisted and allowed to sign-in to + // this device. |wildcard_match| may be NULL. If it's present, it'll be set to + // true if the whitelist check was satisfied via a wildcard. + static bool IsWhitelisted(const std::string& username, bool* wildcard_match); + // Creates a device settings service instance. This is meant for unit tests, // production code uses the singleton returned by Get() above. explicit CrosSettings(DeviceSettingsService* device_settings_service); diff --git a/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc b/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc index 5944a9f..3181d35 100644 --- a/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc +++ b/chrome/browser/chromeos/system/tray_accessibility_browsertest.cc @@ -18,7 +18,6 @@ #include "chrome/browser/chromeos/accessibility/accessibility_manager.h" #include "chrome/browser/chromeos/accessibility/magnification_manager.h" #include "chrome/browser/chromeos/login/helper.h" -#include "chrome/browser/chromeos/login/login_utils.h" #include "chrome/browser/chromeos/login/startup_utils.h" #include "chrome/browser/extensions/api/braille_display_private/mock_braille_controller.h" #include "chrome/browser/profiles/profile.h" diff --git a/chrome/browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc b/chrome/browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc index 469f0a3..23f09c3 100644 --- a/chrome/browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc +++ b/chrome/browser/notifications/login_state_notification_blocker_chromeos_browsertest.cc @@ -87,7 +87,6 @@ IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, message_center::NotifierId::APPLICATION, "test-notifier"); // Logged in as a normal user. - EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); LoginUser(kTestUsers[0]); EXPECT_EQ(1, GetStateChangedCountAndReset()); EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); @@ -122,7 +121,6 @@ IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest, ash::system_notifier::kNotifierDisplay); // Logged in as a normal user. - EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1); LoginUser(kTestUsers[0]); EXPECT_EQ(1, GetStateChangedCountAndReset()); EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id)); diff --git a/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc b/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc index 7603c06..33c6c55 100644 --- a/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc +++ b/chrome/browser/ui/webui/options/chromeos/accounts_options_browsertest.cc @@ -3,6 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" +#include "base/command_line.h" #include "base/compiler_specific.h" #include "base/prefs/pref_service.h" #include "chrome/browser/chromeos/login/login_manager_test.h" diff --git a/chrome/chrome_browser_chromeos.gypi b/chrome/chrome_browser_chromeos.gypi index 473f554..415932e 100644 --- a/chrome/chrome_browser_chromeos.gypi +++ b/chrome/chrome_browser_chromeos.gypi @@ -475,8 +475,6 @@ 'browser/chromeos/login/lock/screen_locker_delegate.h', 'browser/chromeos/login/lock/webui_screen_locker.cc', 'browser/chromeos/login/lock/webui_screen_locker.h', - 'browser/chromeos/login/login_utils.cc', - 'browser/chromeos/login/login_utils.h', 'browser/chromeos/login/login_wizard.h', 'browser/chromeos/login/profile_auth_data.cc', 'browser/chromeos/login/profile_auth_data.h', @@ -1088,6 +1086,7 @@ '../breakpad/breakpad.gyp:breakpad_client', '../build/linux/system.gyp:dbus', '../chromeos/chromeos.gyp:chromeos', + '../chromeos/chromeos.gyp:chromeos_test_support', '../chromeos/chromeos.gyp:cryptohome_proto', # browser_chromeos #includes signed_secret.pb.h directly. '../chromeos/chromeos.gyp:cryptohome_signkey_proto', diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index b1eda9a..d461eb8 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1803,12 +1803,10 @@ 'browser/chromeos/input_method/mock_input_method_engine.h', 'browser/chromeos/input_method/mock_input_method_manager.cc', 'browser/chromeos/input_method/mock_input_method_manager.h', - 'browser/chromeos/login/fake_login_utils.cc', - 'browser/chromeos/login/fake_login_utils.h', - 'browser/chromeos/login/mock_login_utils.cc', - 'browser/chromeos/login/mock_login_utils.h', 'browser/chromeos/login/screens/mock_device_disabled_screen_actor.cc', 'browser/chromeos/login/screens/mock_device_disabled_screen_actor.h', + 'browser/chromeos/login/session/user_session_manager_test_api.cc', + 'browser/chromeos/login/session/user_session_manager_test_api.h', 'browser/chromeos/login/test/oobe_screen_waiter.cc', 'browser/chromeos/login/test/oobe_screen_waiter.h', 'browser/chromeos/login/test/js_checker.cc', diff --git a/chromeos/BUILD.gn b/chromeos/BUILD.gn index 6b7bad4..f2c24af 100644 --- a/chromeos/BUILD.gn +++ b/chromeos/BUILD.gn @@ -84,8 +84,6 @@ static_library("test_support") { "login/auth/mock_auth_attempt_state_resolver.h", "login/auth/mock_auth_status_consumer.cc", "login/auth/mock_auth_status_consumer.h", - "login/auth/mock_authenticator.cc", - "login/auth/mock_authenticator.h", "login/auth/mock_url_fetchers.cc", "login/auth/mock_url_fetchers.h", "network/fake_network_device_handler.cc", diff --git a/chromeos/chromeos.gyp b/chromeos/chromeos.gyp index 7175ebf..841b17e 100644 --- a/chromeos/chromeos.gyp +++ b/chromeos/chromeos.gyp @@ -294,6 +294,8 @@ 'login/auth/online_attempt.h', 'login/auth/online_attempt_host.cc', 'login/auth/online_attempt_host.h', + 'login/auth/stub_authenticator.cc', + 'login/auth/stub_authenticator.h', 'login/auth/test_attempt_state.cc', 'login/auth/test_attempt_state.h', 'login/auth/user_context.cc', @@ -578,8 +580,6 @@ 'login/auth/mock_auth_attempt_state_resolver.h', 'login/auth/mock_auth_status_consumer.cc', 'login/auth/mock_auth_status_consumer.h', - 'login/auth/mock_authenticator.cc', - 'login/auth/mock_authenticator.h', 'login/auth/mock_url_fetchers.cc', 'login/auth/mock_url_fetchers.h', 'network/fake_network_device_handler.cc', diff --git a/chromeos/login/auth/mock_authenticator.cc b/chromeos/login/auth/stub_authenticator.cc index fdd9429..8a3e30f 100644 --- a/chromeos/login/auth/mock_authenticator.cc +++ b/chromeos/login/auth/stub_authenticator.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chromeos/login/auth/mock_authenticator.h" +#include "chromeos/login/auth/stub_authenticator.h" #include "base/bind.h" #include "base/location.h" @@ -10,87 +10,99 @@ namespace chromeos { -MockAuthenticator::MockAuthenticator(AuthStatusConsumer* consumer, +namespace { + +// As defined in /chromeos/dbus/cryptohome_client.cc. +static const char kUserIdHashSuffix[] = "-hash"; + +} // anonymous namespace + +StubAuthenticator::StubAuthenticator(AuthStatusConsumer* consumer, const UserContext& expected_user_context) : Authenticator(consumer), expected_user_context_(expected_user_context), message_loop_(base::MessageLoopProxy::current()) { } -void MockAuthenticator::CompleteLogin(content::BrowserContext* ignored, +void StubAuthenticator::CompleteLogin(content::BrowserContext* context, const UserContext& user_context) { + authentication_context_ = context; if (expected_user_context_ != user_context) NOTREACHED(); OnAuthSuccess(); } -void MockAuthenticator::AuthenticateToLogin(content::BrowserContext* ignored, +void StubAuthenticator::AuthenticateToLogin(content::BrowserContext* context, const UserContext& user_context) { + authentication_context_ = context; if (user_context == expected_user_context_) { message_loop_->PostTask( - FROM_HERE, base::Bind(&MockAuthenticator::OnAuthSuccess, this)); + FROM_HERE, base::Bind(&StubAuthenticator::OnAuthSuccess, this)); return; } GoogleServiceAuthError error( GoogleServiceAuthError::INVALID_GAIA_CREDENTIALS); message_loop_->PostTask( - FROM_HERE, - base::Bind(&MockAuthenticator::OnAuthFailure, - this, - AuthFailure::FromNetworkAuthFailure(error))); + FROM_HERE, base::Bind(&StubAuthenticator::OnAuthFailure, this, + AuthFailure::FromNetworkAuthFailure(error))); } -void MockAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { +void StubAuthenticator::AuthenticateToUnlock(const UserContext& user_context) { AuthenticateToLogin(NULL /* not used */, user_context); } -void MockAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { +void StubAuthenticator::LoginAsSupervisedUser(const UserContext& user_context) { UserContext new_user_context = user_context; - new_user_context.SetUserIDHash(user_context.GetUserID()); + new_user_context.SetUserIDHash(user_context.GetUserID() + kUserIdHashSuffix); consumer_->OnAuthSuccess(new_user_context); } -void MockAuthenticator::LoginOffTheRecord() { +void StubAuthenticator::LoginOffTheRecord() { consumer_->OnOffTheRecordAuthSuccess(); } -void MockAuthenticator::LoginAsPublicSession(const UserContext& user_context) { +void StubAuthenticator::LoginAsPublicSession(const UserContext& user_context) { UserContext logged_in_user_context = user_context; - logged_in_user_context.SetUserIDHash(logged_in_user_context.GetUserID()); + logged_in_user_context.SetIsUsingOAuth(false); + logged_in_user_context.SetUserIDHash(logged_in_user_context.GetUserID() + + kUserIdHashSuffix); consumer_->OnAuthSuccess(logged_in_user_context); } -void MockAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, +void StubAuthenticator::LoginAsKioskAccount(const std::string& app_user_id, bool use_guest_mount) { UserContext user_context(expected_user_context_.GetUserID()); - user_context.SetUserIDHash(expected_user_context_.GetUserID()); + user_context.SetIsUsingOAuth(false); + user_context.SetUserIDHash(expected_user_context_.GetUserID() + + kUserIdHashSuffix); consumer_->OnAuthSuccess(user_context); } -void MockAuthenticator::OnAuthSuccess() { +void StubAuthenticator::OnAuthSuccess() { // If we want to be more like the real thing, we could save the user ID // in AuthenticateToLogin, but there's not much of a point. UserContext user_context(expected_user_context_); - user_context.SetUserIDHash(expected_user_context_.GetUserID()); + user_context.SetUserIDHash(expected_user_context_.GetUserID() + + kUserIdHashSuffix); consumer_->OnAuthSuccess(user_context); } -void MockAuthenticator::OnAuthFailure(const AuthFailure& failure) { +void StubAuthenticator::OnAuthFailure(const AuthFailure& failure) { consumer_->OnAuthFailure(failure); } -void MockAuthenticator::RecoverEncryptedData(const std::string& old_password) { +void StubAuthenticator::RecoverEncryptedData(const std::string& old_password) { } -void MockAuthenticator::ResyncEncryptedData() { +void StubAuthenticator::ResyncEncryptedData() { } -void MockAuthenticator::SetExpectedCredentials( +void StubAuthenticator::SetExpectedCredentials( const UserContext& user_context) { expected_user_context_ = user_context; } -MockAuthenticator::~MockAuthenticator() { +StubAuthenticator::~StubAuthenticator() { } } // namespace chromeos diff --git a/chromeos/login/auth/mock_authenticator.h b/chromeos/login/auth/stub_authenticator.h index e36eb6c..0fa11c4 100644 --- a/chromeos/login/auth/mock_authenticator.h +++ b/chromeos/login/auth/stub_authenticator.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROMEOS_LOGIN_AUTH_MOCK_AUTHENTICATOR_H_ -#define CHROMEOS_LOGIN_AUTH_MOCK_AUTHENTICATOR_H_ +#ifndef CHROMEOS_LOGIN_AUTH_STUB_AUTHENTICATOR_H_ +#define CHROMEOS_LOGIN_AUTH_STUB_AUTHENTICATOR_H_ #include <string> @@ -11,7 +11,6 @@ #include "chromeos/chromeos_export.h" #include "chromeos/login/auth/authenticator.h" #include "chromeos/login/auth/user_context.h" -#include "testing/gtest/include/gtest/gtest.h" namespace content { class BrowserContext; @@ -21,9 +20,9 @@ namespace chromeos { class AuthStatusConsumer; -class CHROMEOS_EXPORT MockAuthenticator : public Authenticator { +class CHROMEOS_EXPORT StubAuthenticator : public Authenticator { public: - MockAuthenticator(AuthStatusConsumer* consumer, + StubAuthenticator(AuthStatusConsumer* consumer, const UserContext& expected_user_context); // Authenticator: @@ -45,15 +44,15 @@ class CHROMEOS_EXPORT MockAuthenticator : public Authenticator { virtual void SetExpectedCredentials(const UserContext& user_context); protected: - ~MockAuthenticator() override; + ~StubAuthenticator() override; private: UserContext expected_user_context_; scoped_refptr<base::MessageLoopProxy> message_loop_; - DISALLOW_COPY_AND_ASSIGN(MockAuthenticator); + DISALLOW_COPY_AND_ASSIGN(StubAuthenticator); }; } // namespace chromeos -#endif // CHROMEOS_LOGIN_AUTH_MOCK_AUTHENTICATOR_H_ +#endif // CHROMEOS_LOGIN_AUTH_STUB_AUTHENTICATOR_H_ diff --git a/components/user_manager/user.h b/components/user_manager/user.h index 684a003..a413cce 100644 --- a/components/user_manager/user.h +++ b/components/user_manager/user.h @@ -19,7 +19,6 @@ namespace chromeos { class ChromeUserManagerImpl; -class FakeLoginUtils; class FakeChromeUserManager; class MockUserManager; class SupervisedUserManagerImpl; @@ -173,7 +172,6 @@ class USER_MANAGER_EXPORT User : public UserInfo { friend class FakeUserManager; friend class chromeos::FakeChromeUserManager; friend class chromeos::MockUserManager; - friend class chromeos::FakeLoginUtils; friend class chromeos::UserAddingScreenTest; // Do not allow anyone else to create new User instances. |