1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "base/bind_helpers.h"
9 #include "base/callback.h"
10 #include "base/command_line.h"
11 #include "base/location.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/run_loop.h"
14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/chromeos/login/authenticator.h"
16 #include "chrome/browser/chromeos/login/existing_user_controller.h"
17 #include "chrome/browser/chromeos/login/helper.h"
18 #include "chrome/browser/chromeos/login/mock_authenticator.h"
19 #include "chrome/browser/chromeos/login/mock_login_display.h"
20 #include "chrome/browser/chromeos/login/mock_login_display_host.h"
21 #include "chrome/browser/chromeos/login/mock_login_utils.h"
22 #include "chrome/browser/chromeos/login/mock_url_fetchers.h"
23 #include "chrome/browser/chromeos/login/mock_user_manager.h"
24 #include "chrome/browser/chromeos/login/user_manager.h"
25 #include "chrome/browser/chromeos/login/wizard_controller.h"
26 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
27 #include "chrome/browser/chromeos/policy/device_local_account.h"
28 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
29 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
30 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
31 #include "chrome/browser/chromeos/settings/cros_settings.h"
32 #include "chrome/common/chrome_switches.h"
33 #include "chrome/test/base/testing_browser_process.h"
34 #include "chrome/test/base/testing_profile.h"
35 #include "chrome/test/base/ui_test_utils.h"
36 #include "chromeos/chromeos_switches.h"
37 #include "chromeos/dbus/fake_session_manager_client.h"
38 #include "chromeos/settings/cros_settings_names.h"
39 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
40 #include "components/policy/core/common/cloud/cloud_policy_core.h"
41 #include "components/policy/core/common/cloud/cloud_policy_store.h"
42 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
43 #include "components/policy/core/common/cloud/policy_builder.h"
44 #include "content/public/test/mock_notification_observer.h"
45 #include "content/public/test/test_utils.h"
46 #include "google_apis/gaia/mock_url_fetcher_factory.h"
47 #include "grit/generated_resources.h"
48 #include "testing/gmock/include/gmock/gmock.h"
49 #include "testing/gtest/include/gtest/gtest.h"
50 #include "ui/base/l10n/l10n_util.h"
52 using ::testing::AnyNumber;
53 using ::testing::Invoke;
54 using ::testing::InvokeWithoutArgs;
55 using ::testing::Return;
56 using ::testing::ReturnNull;
57 using ::testing::Sequence;
58 using ::testing::WithArg;
61 namespace em = enterprise_management;
67 const char kUsername[] = "test_user@gmail.com";
68 const char kNewUsername[] = "test_new_user@gmail.com";
69 const char kPassword[] = "test_password";
71 const char kPublicSessionAccountId[] = "public_session_user@localhost";
72 const int kAutoLoginNoDelay = 0;
73 const int kAutoLoginShortDelay = 1;
74 const int kAutoLoginLongDelay = 10000;
77 ACTION_P2(CreateAuthenticator, username, password) {
78 return new MockAuthenticator(arg0, username, password);
83 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest,
84 public testing::WithParamInterface<bool> {
86 ExistingUserControllerTest()
87 : mock_login_display_(NULL), mock_user_manager_(NULL) {}
89 ExistingUserController* existing_user_controller() {
90 return ExistingUserController::current_controller();
93 const ExistingUserController* existing_user_controller() const {
94 return ExistingUserController::current_controller();
97 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE {
98 SetUpSessionManager();
100 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
102 mock_login_utils_ = new MockLoginUtils();
103 LoginUtils::Set(mock_login_utils_);
104 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_))
107 mock_login_display_host_.reset(new MockLoginDisplayHost());
108 mock_login_display_ = new MockLoginDisplay();
112 virtual void SetUpSessionManager() {
115 virtual void SetUpLoginDisplay() {
116 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
118 .WillOnce(Return(mock_login_display_));
119 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
121 .WillOnce(ReturnNull());
122 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
124 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true))
128 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
129 command_line->AppendSwitch(switches::kLoginManager);
131 command_line->AppendSwitch(::switches::kMultiProfiles);
134 virtual void SetUpUserManager() {
135 // Replace the UserManager singleton with a mock.
136 mock_user_manager_ = new MockUserManager;
137 user_manager_enabler_.reset(
138 new ScopedUserManagerEnabler(mock_user_manager_));
139 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kUsername))
141 .WillRepeatedly(Return(true));
142 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kNewUsername))
144 .WillRepeatedly(Return(false));
145 EXPECT_CALL(*mock_user_manager_, IsUserLoggedIn())
147 .WillRepeatedly(Return(false));
148 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsGuest())
150 .WillRepeatedly(Return(false));
151 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsDemoUser())
153 .WillRepeatedly(Return(false));
154 EXPECT_CALL(*mock_user_manager_, IsLoggedInAsPublicAccount())
156 .WillRepeatedly(Return(false));
157 EXPECT_CALL(*mock_user_manager_, IsSessionStarted())
159 .WillRepeatedly(Return(false));
160 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
162 .WillRepeatedly(Return(false));
163 EXPECT_CALL(*mock_user_manager_, Shutdown())
165 EXPECT_CALL(*mock_user_manager_, GetProfileByUser(_))
167 .WillRepeatedly(Return(testing_profile_.get()));
170 virtual void SetUpOnMainThread() OVERRIDE {
171 testing_profile_.reset(new TestingProfile());
173 existing_user_controller_.reset(
174 new ExistingUserController(mock_login_display_host_.get()));
175 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
176 existing_user_controller_->Init(UserList());
177 profile_prepared_cb_ =
178 base::Bind(&ExistingUserController::OnProfilePrepared,
179 base::Unretained(existing_user_controller()),
180 testing_profile_.get());
183 virtual void CleanUpOnMainThread() OVERRIDE {
184 // ExistingUserController must be deleted before the thread is cleaned up:
185 // If there is an outstanding login attempt when ExistingUserController is
186 // deleted, its LoginPerformer instance will be deleted, which in turn
187 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
188 // be deleted on the UI thread.
189 existing_user_controller_.reset();
190 DevicePolicyCrosBrowserTest::InProcessBrowserTest::CleanUpOnMainThread();
191 testing_profile_.reset(NULL);
192 user_manager_enabler_.reset();
195 // ExistingUserController private member accessors.
196 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
197 return existing_user_controller()->auto_login_timer_.get();
200 const std::string& auto_login_username() const {
201 return existing_user_controller()->public_session_auto_login_username_;
204 int auto_login_delay() const {
205 return existing_user_controller()->public_session_auto_login_delay_;
208 bool is_login_in_progress() const {
209 return existing_user_controller()->is_login_in_progress_;
212 scoped_ptr<ExistingUserController> existing_user_controller_;
214 // |mock_login_display_| is owned by the ExistingUserController, which calls
215 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
216 MockLoginDisplay* mock_login_display_;
217 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
219 // Owned by LoginUtilsWrapper.
220 MockLoginUtils* mock_login_utils_;
222 MockUserManager* mock_user_manager_; // Not owned.
223 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
225 scoped_ptr<TestingProfile> testing_profile_;
228 MockURLFetcherFactory<SuccessFetcher> factory_;
230 base::Callback<void(void)> profile_prepared_cb_;
233 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest);
236 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) {
237 // This is disabled twice: once right after signin but before checking for
238 // auto-enrollment, and again after doing an ownership status check.
239 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
241 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
243 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
244 EXPECT_CALL(*mock_login_utils_,
245 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername),
248 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
249 &base::Callback<void(void)>::Run));
250 EXPECT_CALL(*mock_login_utils_,
251 DoBrowserLaunch(testing_profile_.get(),
252 mock_login_display_host_.get()))
254 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
256 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
258 EXPECT_CALL(*mock_login_display_, OnFadeOut())
260 EXPECT_CALL(*mock_login_display_host_,
261 StartWizardPtr(WizardController::kTermsOfServiceScreenName, NULL))
263 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
265 .WillRepeatedly(Return(false));
266 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
267 content::RunAllPendingInMessageLoop();
270 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
271 EXPECT_CALL(*mock_login_display_host_,
272 StartWizardPtr(WizardController::kEnrollmentScreenName,
275 EXPECT_CALL(*mock_login_display_, OnFadeOut())
277 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
279 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
281 .WillRepeatedly(Return(false));
282 // The order of these expected calls matters: the UI if first disabled
283 // during the login sequence, and is enabled again for the enrollment screen.
284 Sequence uiEnabledSequence;
285 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
287 .InSequence(uiEnabledSequence);
288 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
290 .InSequence(uiEnabledSequence);
291 existing_user_controller()->DoAutoEnrollment();
292 existing_user_controller()->CompleteLogin(
293 UserContext(kUsername, kPassword, ""));
294 content::RunAllPendingInMessageLoop();
297 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest,
298 NewUserDontAutoEnrollAfterSignIn) {
299 EXPECT_CALL(*mock_login_display_host_,
300 StartWizardPtr(WizardController::kEnrollmentScreenName,
303 EXPECT_CALL(*mock_login_display_host_,
304 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
307 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
309 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword)));
310 base::Callback<void(void)> add_user_cb =
311 base::Bind(&MockUserManager::AddUser,
312 base::Unretained(mock_user_manager_),
314 EXPECT_CALL(*mock_login_utils_,
315 PrepareProfile(UserContext(kNewUsername,
322 InvokeWithoutArgs(&add_user_cb,
323 &base::Callback<void(void)>::Run),
324 InvokeWithoutArgs(&profile_prepared_cb_,
325 &base::Callback<void(void)>::Run)));
326 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
328 EXPECT_CALL(*mock_login_display_, OnFadeOut())
330 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
332 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
334 .WillRepeatedly(Return(true));
336 // The order of these expected calls matters: the UI if first disabled
337 // during the login sequence, and is enabled again after login completion.
338 Sequence uiEnabledSequence;
339 // This is disabled twice: once right after signin but before checking for
340 // auto-enrollment, and again after doing an ownership status check.
341 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
343 .InSequence(uiEnabledSequence);
344 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
346 .InSequence(uiEnabledSequence);
348 existing_user_controller()->CompleteLogin(
349 UserContext(kNewUsername, kPassword, ""));
350 content::RunAllPendingInMessageLoop();
353 MATCHER_P(HasDetails, expected, "") {
354 return expected == *content::Details<const std::string>(arg).ptr();
357 class ExistingUserControllerPublicSessionTest
358 : public ExistingUserControllerTest {
360 ExistingUserControllerPublicSessionTest()
361 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
362 kPublicSessionAccountId,
363 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {
366 virtual void SetUpOnMainThread() OVERRIDE {
367 ExistingUserControllerTest::SetUpOnMainThread();
369 // Wait for the public session user to be created.
370 if (!chromeos::UserManager::Get()->IsKnownUser(public_session_user_id_)) {
371 content::WindowedNotificationObserver(
372 chrome::NOTIFICATION_USER_LIST_CHANGED,
373 base::Bind(&chromeos::UserManager::IsKnownUser,
374 base::Unretained(chromeos::UserManager::Get()),
375 public_session_user_id_)).Wait();
378 // Wait for the device local account policy to be installed.
379 policy::CloudPolicyStore* store =
380 TestingBrowserProcess::GetGlobal()
382 ->browser_policy_connector_chromeos()
383 ->GetDeviceLocalAccountPolicyService()
384 ->GetBrokerForUser(public_session_user_id_)
387 if (!store->has_policy()) {
388 policy::MockCloudPolicyStoreObserver observer;
391 store->AddObserver(&observer);
392 EXPECT_CALL(observer, OnStoreLoaded(store))
394 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit));
396 store->RemoveObserver(&observer);
400 virtual void SetUpSessionManager() OVERRIDE {
403 // Setup the device policy.
404 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
405 em::DeviceLocalAccountInfoProto* account =
406 proto.mutable_device_local_accounts()->add_account();
407 account->set_account_id(kPublicSessionAccountId);
409 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
410 RefreshDevicePolicy();
412 // Setup the device local account policy.
413 policy::UserPolicyBuilder device_local_account_policy;
414 device_local_account_policy.policy_data().set_username(
415 kPublicSessionAccountId);
416 device_local_account_policy.policy_data().set_policy_type(
417 policy::dm_protocol::kChromePublicAccountPolicyType);
418 device_local_account_policy.policy_data().set_settings_entity_id(
419 kPublicSessionAccountId);
420 device_local_account_policy.Build();
421 session_manager_client()->set_device_local_account_policy(
422 kPublicSessionAccountId,
423 device_local_account_policy.GetBlob());
426 virtual void SetUpLoginDisplay() OVERRIDE {
427 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
429 .WillOnce(Return(mock_login_display_));
430 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
432 .WillRepeatedly(ReturnNull());
433 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
435 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
439 virtual void SetUpUserManager() OVERRIDE {
442 void ExpectSuccessfulLogin(const std::string& username,
443 const std::string& password) {
444 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
446 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
448 .WillOnce(WithArg<0>(CreateAuthenticator(username, password)));
449 EXPECT_CALL(*mock_login_utils_,
450 PrepareProfile(UserContext(username, password, "", username),
453 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
454 &base::Callback<void(void)>::Run));
455 EXPECT_CALL(*mock_login_utils_,
456 DoBrowserLaunch(testing_profile_.get(),
457 mock_login_display_host_.get()))
459 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username))
461 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
463 EXPECT_CALL(*mock_login_display_, OnFadeOut())
465 EXPECT_CALL(*mock_login_display_host_,
466 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
471 void SetAutoLoginPolicy(const std::string& username, int delay) {
472 // Wait until ExistingUserController has finished auto-login
473 // configuration by observing the same settings that trigger
474 // ConfigurePublicSessionAutoLogin.
476 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
478 // If both settings have changed we need to wait for both to
479 // propagate, so check the new values against the old ones.
480 scoped_refptr<content::MessageLoopRunner> runner1;
481 scoped_ptr<CrosSettings::ObserverSubscription> subscription1;
482 if (!proto.has_device_local_accounts() ||
483 !proto.device_local_accounts().has_auto_login_id() ||
484 proto.device_local_accounts().auto_login_id() != username) {
485 runner1 = new content::MessageLoopRunner;
486 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
487 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId,
488 runner1->QuitClosure());
490 scoped_refptr<content::MessageLoopRunner> runner2;
491 scoped_ptr<CrosSettings::ObserverSubscription> subscription2;
492 if (!proto.has_device_local_accounts() ||
493 !proto.device_local_accounts().has_auto_login_delay() ||
494 proto.device_local_accounts().auto_login_delay() != delay) {
495 runner1 = new content::MessageLoopRunner;
496 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
497 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay,
498 runner1->QuitClosure());
501 // Update the policy.
502 proto.mutable_device_local_accounts()->set_auto_login_id(username);
503 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
504 RefreshDevicePolicy();
506 // Wait for ExistingUserController to read the updated settings.
513 void ConfigureAutoLogin() {
514 existing_user_controller()->ConfigurePublicSessionAutoLogin();
517 void FireAutoLogin() {
518 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
521 const std::string public_session_user_id_;
524 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
527 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
528 ConfigureAutoLoginUsingPolicy) {
529 existing_user_controller()->OnSigninScreenReady();
530 EXPECT_EQ("", auto_login_username());
531 EXPECT_EQ(0, auto_login_delay());
532 EXPECT_FALSE(auto_login_timer());
535 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
536 EXPECT_EQ(public_session_user_id_, auto_login_username());
537 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
538 ASSERT_TRUE(auto_login_timer());
539 EXPECT_TRUE(auto_login_timer()->IsRunning());
542 SetAutoLoginPolicy("", 0);
543 EXPECT_EQ("", auto_login_username());
544 EXPECT_EQ(0, auto_login_delay());
545 ASSERT_TRUE(auto_login_timer());
546 EXPECT_FALSE(auto_login_timer()->IsRunning());
549 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
551 // Set up mocks to check login success.
552 ExpectSuccessfulLogin(public_session_user_id_, "");
553 existing_user_controller()->OnSigninScreenReady();
555 // Start auto-login and wait for login tasks to complete.
556 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginNoDelay);
557 content::RunAllPendingInMessageLoop();
560 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
561 AutoLoginShortDelay) {
562 // Set up mocks to check login success.
563 ExpectSuccessfulLogin(public_session_user_id_, "");
564 existing_user_controller()->OnSigninScreenReady();
565 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay);
566 ASSERT_TRUE(auto_login_timer());
567 // Don't assert that timer is running: with the short delay sometimes
568 // the trigger happens before the assert. We've already tested that
569 // the timer starts when it should.
571 // Wait for the timer to fire.
572 base::RunLoop runner;
573 base::OneShotTimer<base::RunLoop> timer;
574 timer.Start(FROM_HERE,
575 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1),
576 runner.QuitClosure());
579 // Wait for login tasks to complete.
580 content::RunAllPendingInMessageLoop();
583 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
584 LoginStopsAutoLogin) {
585 // Set up mocks to check login success.
586 ExpectSuccessfulLogin(kUsername, kPassword);
588 existing_user_controller()->OnSigninScreenReady();
589 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
590 ASSERT_TRUE(auto_login_timer());
592 // Login and check that it stopped the timer.
593 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
594 EXPECT_TRUE(is_login_in_progress());
595 ASSERT_TRUE(auto_login_timer());
596 EXPECT_FALSE(auto_login_timer()->IsRunning());
598 // Wait for login tasks to complete.
599 content::RunAllPendingInMessageLoop();
601 // Timer should still be stopped after login completes.
602 ASSERT_TRUE(auto_login_timer());
603 EXPECT_FALSE(auto_login_timer()->IsRunning());
606 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
607 GuestModeLoginStopsAutoLogin) {
608 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
610 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
612 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
613 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
616 existing_user_controller()->OnSigninScreenReady();
617 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
618 ASSERT_TRUE(auto_login_timer());
620 // Login and check that it stopped the timer.
621 existing_user_controller()->LoginAsGuest();
622 EXPECT_TRUE(is_login_in_progress());
623 ASSERT_TRUE(auto_login_timer());
624 EXPECT_FALSE(auto_login_timer()->IsRunning());
626 // Wait for login tasks to complete.
627 content::RunAllPendingInMessageLoop();
629 // Timer should still be stopped after login completes.
630 ASSERT_TRUE(auto_login_timer());
631 EXPECT_FALSE(auto_login_timer()->IsRunning());
634 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
635 CompleteLoginStopsAutoLogin) {
636 // Set up mocks to check login success.
637 ExpectSuccessfulLogin(kUsername, kPassword);
638 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
641 existing_user_controller()->OnSigninScreenReady();
642 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
643 ASSERT_TRUE(auto_login_timer());
645 // Check that login completes and stops the timer.
646 existing_user_controller()->CompleteLogin(
647 UserContext(kUsername, kPassword, ""));
648 ASSERT_TRUE(auto_login_timer());
649 EXPECT_FALSE(auto_login_timer()->IsRunning());
651 // Wait for login tasks to complete.
652 content::RunAllPendingInMessageLoop();
654 // Timer should still be stopped after login completes.
655 ASSERT_TRUE(auto_login_timer());
656 EXPECT_FALSE(auto_login_timer()->IsRunning());
659 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
660 PublicSessionLoginStopsAutoLogin) {
661 // Set up mocks to check login success.
662 ExpectSuccessfulLogin(public_session_user_id_, "");
663 existing_user_controller()->OnSigninScreenReady();
664 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
665 ASSERT_TRUE(auto_login_timer());
667 // Login and check that it stopped the timer.
668 existing_user_controller()->LoginAsPublicAccount(public_session_user_id_);
669 EXPECT_TRUE(is_login_in_progress());
670 ASSERT_TRUE(auto_login_timer());
671 EXPECT_FALSE(auto_login_timer()->IsRunning());
673 // Wait for login tasks to complete.
674 content::RunAllPendingInMessageLoop();
676 // Timer should still be stopped after login completes.
677 ASSERT_TRUE(auto_login_timer());
678 EXPECT_FALSE(auto_login_timer()->IsRunning());
681 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
682 PRE_TestLoadingPublicUsersFromLocalState) {
683 // First run propagates public accounts and stores them in Local State.
686 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
687 TestLoadingPublicUsersFromLocalState) {
688 // Second run loads list of public accounts from Local State.
691 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation,
692 ExistingUserControllerTest,
695 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation,
696 ExistingUserControllerPublicSessionTest,
699 } // namespace chromeos