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/device_local_account.h"
27 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
28 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
29 #include "chrome/browser/chromeos/settings/cros_settings.h"
30 #include "chrome/browser/policy/browser_policy_connector.h"
31 #include "chrome/browser/policy/cloud/cloud_policy_constants.h"
32 #include "chrome/browser/policy/cloud/cloud_policy_core.h"
33 #include "chrome/browser/policy/cloud/cloud_policy_store.h"
34 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h"
35 #include "chrome/browser/policy/cloud/policy_builder.h"
36 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h"
37 #include "chrome/common/chrome_switches.h"
38 #include "chrome/test/base/testing_browser_process.h"
39 #include "chrome/test/base/testing_profile.h"
40 #include "chrome/test/base/ui_test_utils.h"
41 #include "chromeos/chromeos_switches.h"
42 #include "chromeos/dbus/fake_session_manager_client.h"
43 #include "chromeos/settings/cros_settings_names.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())
167 virtual void SetUpOnMainThread() OVERRIDE {
169 testing_profile_.reset(new TestingProfile());
170 existing_user_controller_.reset(
171 new ExistingUserController(mock_login_display_host_.get()));
172 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get());
173 existing_user_controller_->Init(UserList());
174 profile_prepared_cb_ =
175 base::Bind(&ExistingUserController::OnProfilePrepared,
176 base::Unretained(existing_user_controller()),
177 testing_profile_.get());
180 virtual void CleanUpOnMainThread() OVERRIDE {
181 // ExistingUserController must be deleted before the thread is cleaned up:
182 // If there is an outstanding login attempt when ExistingUserController is
183 // deleted, its LoginPerformer instance will be deleted, which in turn
184 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
185 // be deleted on the UI thread.
186 existing_user_controller_.reset();
187 DevicePolicyCrosBrowserTest::InProcessBrowserTest::CleanUpOnMainThread();
188 testing_profile_.reset(NULL);
189 user_manager_enabler_.reset();
192 // ExistingUserController private member accessors.
193 base::OneShotTimer<ExistingUserController>* auto_login_timer() {
194 return existing_user_controller()->auto_login_timer_.get();
197 const std::string& auto_login_username() const {
198 return existing_user_controller()->public_session_auto_login_username_;
201 int auto_login_delay() const {
202 return existing_user_controller()->public_session_auto_login_delay_;
205 bool is_login_in_progress() const {
206 return existing_user_controller()->is_login_in_progress_;
209 scoped_ptr<ExistingUserController> existing_user_controller_;
211 // |mock_login_display_| is owned by the ExistingUserController, which calls
212 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
213 MockLoginDisplay* mock_login_display_;
214 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_;
216 // Owned by LoginUtilsWrapper.
217 MockLoginUtils* mock_login_utils_;
219 MockUserManager* mock_user_manager_; // Not owned.
220 scoped_ptr<ScopedUserManagerEnabler> user_manager_enabler_;
222 scoped_ptr<TestingProfile> testing_profile_;
225 MockURLFetcherFactory<SuccessFetcher> factory_;
227 base::Callback<void(void)> profile_prepared_cb_;
230 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest);
233 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) {
234 // This is disabled twice: once right after signin but before checking for
235 // auto-enrollment, and again after doing an ownership status check.
236 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
238 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
240 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
241 EXPECT_CALL(*mock_login_utils_,
242 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername),
245 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
246 &base::Callback<void(void)>::Run));
247 EXPECT_CALL(*mock_login_utils_,
248 DoBrowserLaunch(testing_profile_.get(),
249 mock_login_display_host_.get()))
251 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername))
253 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
255 EXPECT_CALL(*mock_login_display_, OnFadeOut())
257 EXPECT_CALL(*mock_login_display_host_,
258 StartWizardPtr(WizardController::kTermsOfServiceScreenName, NULL))
260 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
262 .WillRepeatedly(Return(false));
263 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
264 content::RunAllPendingInMessageLoop();
267 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, AutoEnrollAfterSignIn) {
268 EXPECT_CALL(*mock_login_display_host_,
269 StartWizardPtr(WizardController::kEnrollmentScreenName,
272 EXPECT_CALL(*mock_login_display_, OnFadeOut())
274 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
276 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
278 .WillRepeatedly(Return(false));
279 // The order of these expected calls matters: the UI if first disabled
280 // during the login sequence, and is enabled again for the enrollment screen.
281 Sequence uiEnabledSequence;
282 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
284 .InSequence(uiEnabledSequence);
285 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
287 .InSequence(uiEnabledSequence);
288 existing_user_controller()->DoAutoEnrollment();
289 existing_user_controller()->CompleteLogin(
290 UserContext(kUsername, kPassword, ""));
291 content::RunAllPendingInMessageLoop();
294 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest,
295 NewUserDontAutoEnrollAfterSignIn) {
296 EXPECT_CALL(*mock_login_display_host_,
297 StartWizardPtr(WizardController::kEnrollmentScreenName,
300 EXPECT_CALL(*mock_login_display_host_,
301 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
304 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
306 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword)));
307 EXPECT_CALL(*mock_login_utils_,
308 PrepareProfile(UserContext(kNewUsername,
314 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
315 &base::Callback<void(void)>::Run));
316 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
318 EXPECT_CALL(*mock_login_display_, OnFadeOut())
320 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin())
322 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew())
324 .WillRepeatedly(Return(true));
326 // The order of these expected calls matters: the UI if first disabled
327 // during the login sequence, and is enabled again after login completion.
328 Sequence uiEnabledSequence;
329 // This is disabled twice: once right after signin but before checking for
330 // auto-enrollment, and again after doing an ownership status check.
331 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
333 .InSequence(uiEnabledSequence);
334 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
336 .InSequence(uiEnabledSequence);
338 existing_user_controller()->CompleteLogin(
339 UserContext(kNewUsername, kPassword, ""));
340 content::RunAllPendingInMessageLoop();
343 MATCHER_P(HasDetails, expected, "") {
344 return expected == *content::Details<const std::string>(arg).ptr();
347 class ExistingUserControllerPublicSessionTest
348 : public ExistingUserControllerTest {
350 ExistingUserControllerPublicSessionTest()
351 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
352 kPublicSessionAccountId,
353 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {
356 virtual void SetUpOnMainThread() OVERRIDE {
357 ExistingUserControllerTest::SetUpOnMainThread();
359 // Wait for the public session user to be created.
360 if (!chromeos::UserManager::Get()->IsKnownUser(public_session_user_id_)) {
361 content::WindowedNotificationObserver(
362 chrome::NOTIFICATION_USER_LIST_CHANGED,
363 base::Bind(&chromeos::UserManager::IsKnownUser,
364 base::Unretained(chromeos::UserManager::Get()),
365 public_session_user_id_)).Wait();
368 // Wait for the device local account policy to be installed.
369 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()->
370 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
371 GetBrokerForUser(public_session_user_id_)->core()->store();
372 if (!store->has_policy()) {
373 policy::MockCloudPolicyStoreObserver observer;
376 store->AddObserver(&observer);
377 EXPECT_CALL(observer, OnStoreLoaded(store))
379 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit));
381 store->RemoveObserver(&observer);
385 virtual void SetUpSessionManager() OVERRIDE {
388 // Setup the device policy.
389 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
390 em::DeviceLocalAccountInfoProto* account =
391 proto.mutable_device_local_accounts()->add_account();
392 account->set_account_id(kPublicSessionAccountId);
394 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
395 RefreshDevicePolicy();
397 // Setup the device local account policy.
398 policy::UserPolicyBuilder device_local_account_policy;
399 device_local_account_policy.policy_data().set_username(
400 kPublicSessionAccountId);
401 device_local_account_policy.policy_data().set_policy_type(
402 policy::dm_protocol::kChromePublicAccountPolicyType);
403 device_local_account_policy.policy_data().set_settings_entity_id(
404 kPublicSessionAccountId);
405 device_local_account_policy.Build();
406 session_manager_client()->set_device_local_account_policy(
407 kPublicSessionAccountId,
408 device_local_account_policy.GetBlob());
411 virtual void SetUpLoginDisplay() OVERRIDE {
412 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
414 .WillOnce(Return(mock_login_display_));
415 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
417 .WillRepeatedly(ReturnNull());
418 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
420 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
424 virtual void SetUpUserManager() OVERRIDE {
427 void ExpectSuccessfulLogin(const std::string& username,
428 const std::string& password) {
429 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
431 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
433 .WillOnce(WithArg<0>(CreateAuthenticator(username, password)));
434 EXPECT_CALL(*mock_login_utils_,
435 PrepareProfile(UserContext(username, password, "", username),
438 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
439 &base::Callback<void(void)>::Run));
440 EXPECT_CALL(*mock_login_utils_,
441 DoBrowserLaunch(testing_profile_.get(),
442 mock_login_display_host_.get()))
444 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username))
446 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true))
448 EXPECT_CALL(*mock_login_display_, OnFadeOut())
450 EXPECT_CALL(*mock_login_display_host_,
451 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
456 void SetAutoLoginPolicy(const std::string& username, int delay) {
457 // Wait until ExistingUserController has finished auto-login
458 // configuration by observing the same settings that trigger
459 // ConfigurePublicSessionAutoLogin.
461 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
463 // If both settings have changed we need to wait for both to
464 // propagate, so check the new values against the old ones.
465 scoped_refptr<content::MessageLoopRunner> runner1;
466 scoped_ptr<CrosSettings::ObserverSubscription> subscription1;
467 if (!proto.has_device_local_accounts() ||
468 !proto.device_local_accounts().has_auto_login_id() ||
469 proto.device_local_accounts().auto_login_id() != username) {
470 runner1 = new content::MessageLoopRunner;
471 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
472 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId,
473 runner1->QuitClosure());
475 scoped_refptr<content::MessageLoopRunner> runner2;
476 scoped_ptr<CrosSettings::ObserverSubscription> subscription2;
477 if (!proto.has_device_local_accounts() ||
478 !proto.device_local_accounts().has_auto_login_delay() ||
479 proto.device_local_accounts().auto_login_delay() != delay) {
480 runner1 = new content::MessageLoopRunner;
481 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver(
482 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay,
483 runner1->QuitClosure());
486 // Update the policy.
487 proto.mutable_device_local_accounts()->set_auto_login_id(username);
488 proto.mutable_device_local_accounts()->set_auto_login_delay(delay);
489 RefreshDevicePolicy();
491 // Wait for ExistingUserController to read the updated settings.
498 void ConfigureAutoLogin() {
499 existing_user_controller()->ConfigurePublicSessionAutoLogin();
502 void FireAutoLogin() {
503 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
506 const std::string public_session_user_id_;
509 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
512 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
513 ConfigureAutoLoginUsingPolicy) {
514 existing_user_controller()->OnSigninScreenReady();
515 EXPECT_EQ("", auto_login_username());
516 EXPECT_EQ(0, auto_login_delay());
517 EXPECT_FALSE(auto_login_timer());
520 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
521 EXPECT_EQ(public_session_user_id_, auto_login_username());
522 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
523 ASSERT_TRUE(auto_login_timer());
524 EXPECT_TRUE(auto_login_timer()->IsRunning());
527 SetAutoLoginPolicy("", 0);
528 EXPECT_EQ("", auto_login_username());
529 EXPECT_EQ(0, auto_login_delay());
530 ASSERT_TRUE(auto_login_timer());
531 EXPECT_FALSE(auto_login_timer()->IsRunning());
534 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
536 // Set up mocks to check login success.
537 ExpectSuccessfulLogin(public_session_user_id_, "");
538 existing_user_controller()->OnSigninScreenReady();
540 // Start auto-login and wait for login tasks to complete.
541 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginNoDelay);
542 content::RunAllPendingInMessageLoop();
545 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
546 AutoLoginShortDelay) {
547 // Set up mocks to check login success.
548 ExpectSuccessfulLogin(public_session_user_id_, "");
549 existing_user_controller()->OnSigninScreenReady();
550 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay);
551 ASSERT_TRUE(auto_login_timer());
552 // Don't assert that timer is running: with the short delay sometimes
553 // the trigger happens before the assert. We've already tested that
554 // the timer starts when it should.
556 // Wait for the timer to fire.
557 base::RunLoop runner;
558 base::OneShotTimer<base::RunLoop> timer;
559 timer.Start(FROM_HERE,
560 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1),
561 runner.QuitClosure());
564 // Wait for login tasks to complete.
565 content::RunAllPendingInMessageLoop();
568 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
569 LoginStopsAutoLogin) {
570 // Set up mocks to check login success.
571 ExpectSuccessfulLogin(kUsername, kPassword);
573 existing_user_controller()->OnSigninScreenReady();
574 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
575 ASSERT_TRUE(auto_login_timer());
577 // Login and check that it stopped the timer.
578 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
579 EXPECT_TRUE(is_login_in_progress());
580 ASSERT_TRUE(auto_login_timer());
581 EXPECT_FALSE(auto_login_timer()->IsRunning());
583 // Wait for login tasks to complete.
584 content::RunAllPendingInMessageLoop();
586 // Timer should still be stopped after login completes.
587 ASSERT_TRUE(auto_login_timer());
588 EXPECT_FALSE(auto_login_timer()->IsRunning());
591 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
592 GuestModeLoginStopsAutoLogin) {
593 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
595 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
597 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
598 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
601 existing_user_controller()->OnSigninScreenReady();
602 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
603 ASSERT_TRUE(auto_login_timer());
605 // Login and check that it stopped the timer.
606 existing_user_controller()->LoginAsGuest();
607 EXPECT_TRUE(is_login_in_progress());
608 ASSERT_TRUE(auto_login_timer());
609 EXPECT_FALSE(auto_login_timer()->IsRunning());
611 // Wait for login tasks to complete.
612 content::RunAllPendingInMessageLoop();
614 // Timer should still be stopped after login completes.
615 ASSERT_TRUE(auto_login_timer());
616 EXPECT_FALSE(auto_login_timer()->IsRunning());
619 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
620 CompleteLoginStopsAutoLogin) {
621 // Set up mocks to check login success.
622 ExpectSuccessfulLogin(kUsername, kPassword);
623 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
626 existing_user_controller()->OnSigninScreenReady();
627 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
628 ASSERT_TRUE(auto_login_timer());
630 // Check that login completes and stops the timer.
631 existing_user_controller()->CompleteLogin(
632 UserContext(kUsername, kPassword, ""));
633 ASSERT_TRUE(auto_login_timer());
634 EXPECT_FALSE(auto_login_timer()->IsRunning());
636 // Wait for login tasks to complete.
637 content::RunAllPendingInMessageLoop();
639 // Timer should still be stopped after login completes.
640 ASSERT_TRUE(auto_login_timer());
641 EXPECT_FALSE(auto_login_timer()->IsRunning());
644 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
645 PublicSessionLoginStopsAutoLogin) {
646 // Set up mocks to check login success.
647 ExpectSuccessfulLogin(public_session_user_id_, "");
648 existing_user_controller()->OnSigninScreenReady();
649 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
650 ASSERT_TRUE(auto_login_timer());
652 // Login and check that it stopped the timer.
653 existing_user_controller()->LoginAsPublicAccount(public_session_user_id_);
654 EXPECT_TRUE(is_login_in_progress());
655 ASSERT_TRUE(auto_login_timer());
656 EXPECT_FALSE(auto_login_timer()->IsRunning());
658 // Wait for login tasks to complete.
659 content::RunAllPendingInMessageLoop();
661 // Timer should still be stopped after login completes.
662 ASSERT_TRUE(auto_login_timer());
663 EXPECT_FALSE(auto_login_timer()->IsRunning());
666 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation,
667 ExistingUserControllerTest,
670 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation,
671 ExistingUserControllerPublicSessionTest,
674 } // namespace chromeos