Chromium Code Reviews| Index: chrome/browser/chromeos/login/existing_user_controller_browsertest.cc |
| diff --git a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc |
| index 3be3904b0f8f0559f48ae0e88e7abb0c3cc98557..69ff7f3ab4a1e1a3fa4709181092d176fe1dc7f8 100644 |
| --- a/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc |
| +++ b/chrome/browser/chromeos/login/existing_user_controller_browsertest.cc |
| @@ -11,18 +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/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/fake_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" |
| @@ -34,12 +35,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 +73,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 +81,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 +105,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,16 +120,13 @@ 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(); |
| } |
| + void TearDown() override { user_manager_enabler_.reset(); } |
| + |
| virtual void SetUpSessionManager() { |
| } |
| @@ -160,53 +145,21 @@ class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { |
| void SetUpCommandLine(base::CommandLine* command_line) override { |
| command_line->AppendSwitch(switches::kLoginManager); |
| + command_line->AppendSwitch(switches::kForceLoginManagerInTests); |
| } |
| 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()); |
| + new ScopedUserManagerEnabler(new chromeos::FakeUserManager())); |
| + GetFakeUserManager()->AddUser(kUsername); |
| } |
| 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,7 +170,6 @@ 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(); |
| } |
| @@ -257,20 +209,17 @@ 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: |
| + chromeos::FakeUserManager* GetFakeUserManager() { |
| + return static_cast<chromeos::FakeUserManager*>( |
| + user_manager::UserManager::Get()); |
| + } |
| + |
| DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); |
| }; |
| @@ -280,22 +229,21 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { |
| 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); |
| } |
| @@ -457,20 +402,14 @@ class ExistingUserControllerPublicSessionTest |
| void SetUpUserManager() override {} |
| 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) { |
| @@ -559,6 +498,14 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| EXPECT_EQ(0, auto_login_delay()); |
| ASSERT_TRUE(auto_login_timer()); |
| EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| + |
| + // This test is 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(); |
|
Dmitry Polukhin
2015/02/03 11:33:07
What do you think about moving this logic to test
Nikita (slow)
2015/02/03 13:12:26
Done.
|
| + if (controller && controller->current_screen()) |
| + controller->current_screen()->Hide(); |
| } |
| IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| @@ -583,6 +530,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 +549,16 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| runner.QuitClosure()); |
| runner.Run(); |
| + profile_prepared_observer.Wait(); |
| + |
| + // This test is 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(); |
| + |
| // Wait for login tasks to complete. |
| content::RunAllPendingInMessageLoop(); |
| } |
| @@ -613,18 +575,30 @@ 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(); |
| // Timer should still be stopped after login completes. |
| ASSERT_TRUE(auto_login_timer()); |
| EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| + |
| + // This test is configured with the real user manager but empty user list. |
| + // When logging in this test we end up on user image screen. |
| + WizardController* controller = WizardController::default_controller(); |
| + if (controller && controller->current_screen()) |
| + controller->current_screen()->Hide(); |
| } |
| IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| @@ -633,9 +607,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,17 +645,29 @@ 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(); |
| // Timer should still be stopped after login completes. |
| ASSERT_TRUE(auto_login_timer()); |
| EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| + |
| + // This test is configured with the real user manager but empty user list. |
| + // When logging in this test we end up on user image screen. |
| + WizardController* controller = WizardController::default_controller(); |
| + if (controller && controller->current_screen()) |
| + controller->current_screen()->Hide(); |
| } |
| IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| @@ -695,6 +681,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 +695,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(); |
| @@ -724,6 +716,14 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| user_context.SetKey(Key(kPassword)); |
| user_context.SetUserIDHash(user_context.GetUserID()); |
| existing_user_controller()->Login(user_context, SigninSpecifics()); |
| + |
| + // This test is 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(); |
| } |
| IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| @@ -739,6 +739,14 @@ IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| // Check that when the timer fires, auto-login fails with an error. |
| ExpectLoginFailure(); |
| FireAutoLogin(); |
| + |
| + // This test is 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(); |
| } |
| IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |