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/auth/mock_url_fetchers.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_login_utils.h"
19 #include "chrome/browser/chromeos/login/ui/mock_login_display.h"
20 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h"
21 #include "chrome/browser/chromeos/login/users/mock_user_manager.h"
22 #include "chrome/browser/chromeos/login/users/user_manager.h"
23 #include "chrome/browser/chromeos/login/wizard_controller.h"
24 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
25 #include "chrome/browser/chromeos/policy/device_local_account.h"
26 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
27 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
28 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
29 #include "chrome/browser/chromeos/settings/cros_settings.h"
30 #include "chrome/test/base/testing_browser_process.h"
31 #include "chrome/test/base/testing_profile.h"
32 #include "chrome/test/base/ui_test_utils.h"
33 #include "chromeos/chromeos_switches.h"
34 #include "chromeos/dbus/fake_session_manager_client.h"
35 #include "chromeos/login/auth/authenticator.h"
36 #include "chromeos/login/auth/key.h"
37 #include "chromeos/login/auth/mock_authenticator.h"
38 #include "chromeos/login/auth/mock_authenticator.h"
39 #include "chromeos/login/auth/user_context.h"
40 #include "chromeos/settings/cros_settings_names.h"
41 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
42 #include "components/policy/core/common/cloud/cloud_policy_core.h"
43 #include "components/policy/core/common/cloud/cloud_policy_store.h"
44 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
45 #include "components/policy/core/common/cloud/policy_builder.h"
46 #include "components/user_manager/user.h"
47 #include "content/public/test/mock_notification_observer.h"
48 #include "content/public/test/test_utils.h"
49 #include "google_apis/gaia/mock_url_fetcher_factory.h"
50 #include "grit/generated_resources.h"
51 #include "testing/gmock/include/gmock/gmock.h"
52 #include "testing/gtest/include/gtest/gtest.h"
53 #include "ui/base/l10n/l10n_util.h"
55 using ::testing::AnyNumber
;
56 using ::testing::Invoke
;
57 using ::testing::InvokeWithoutArgs
;
58 using ::testing::Return
;
59 using ::testing::ReturnNull
;
60 using ::testing::Sequence
;
61 using ::testing::WithArg
;
64 namespace em
= enterprise_management
;
70 const char kUsername
[] = "test_user@gmail.com";
71 const char kNewUsername
[] = "test_new_user@gmail.com";
72 const char kPassword
[] = "test_password";
74 const char kPublicSessionAccountId
[] = "public_session_user@localhost";
75 const int kAutoLoginNoDelay
= 0;
76 const int kAutoLoginShortDelay
= 1;
77 const int kAutoLoginLongDelay
= 10000;
79 ACTION_P(CreateAuthenticator
, user_context
) {
80 return new MockAuthenticator(arg0
, user_context
);
85 class ExistingUserControllerTest
: public policy::DevicePolicyCrosBrowserTest
{
87 ExistingUserControllerTest()
88 : mock_login_display_(NULL
), mock_user_manager_(NULL
) {}
90 ExistingUserController
* existing_user_controller() {
91 return ExistingUserController::current_controller();
94 const ExistingUserController
* existing_user_controller() const {
95 return ExistingUserController::current_controller();
98 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE
{
99 SetUpSessionManager();
101 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
103 mock_login_utils_
= new MockLoginUtils();
104 LoginUtils::Set(mock_login_utils_
);
105 EXPECT_CALL(*mock_login_utils_
, DelegateDeleted(_
))
108 mock_login_display_host_
.reset(new MockLoginDisplayHost());
109 mock_login_display_
= new MockLoginDisplay();
113 virtual void SetUpSessionManager() {
116 virtual void SetUpLoginDisplay() {
117 EXPECT_CALL(*mock_login_display_host_
.get(), CreateLoginDisplay(_
))
119 .WillOnce(Return(mock_login_display_
));
120 EXPECT_CALL(*mock_login_display_host_
.get(), GetNativeWindow())
122 .WillOnce(ReturnNull());
123 EXPECT_CALL(*mock_login_display_host_
.get(), OnPreferencesChanged())
125 EXPECT_CALL(*mock_login_display_
, Init(_
, false, true, true))
129 virtual void SetUpCommandLine(CommandLine
* command_line
) OVERRIDE
{
130 command_line
->AppendSwitch(switches::kLoginManager
);
133 virtual void SetUpUserManager() {
134 // Replace the UserManager singleton with a mock.
135 mock_user_manager_
= new MockUserManager
;
136 user_manager_enabler_
.reset(
137 new ScopedUserManagerEnabler(mock_user_manager_
));
138 EXPECT_CALL(*mock_user_manager_
, IsKnownUser(kUsername
))
140 .WillRepeatedly(Return(true));
141 EXPECT_CALL(*mock_user_manager_
, IsKnownUser(kNewUsername
))
143 .WillRepeatedly(Return(false));
144 EXPECT_CALL(*mock_user_manager_
, IsUserLoggedIn())
146 .WillRepeatedly(Return(false));
147 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsGuest())
149 .WillRepeatedly(Return(false));
150 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsDemoUser())
152 .WillRepeatedly(Return(false));
153 EXPECT_CALL(*mock_user_manager_
, IsLoggedInAsPublicAccount())
155 .WillRepeatedly(Return(false));
156 EXPECT_CALL(*mock_user_manager_
, IsSessionStarted())
158 .WillRepeatedly(Return(false));
159 EXPECT_CALL(*mock_user_manager_
, IsCurrentUserNew())
161 .WillRepeatedly(Return(false));
162 EXPECT_CALL(*mock_user_manager_
, Shutdown())
166 virtual void SetUpOnMainThread() OVERRIDE
{
167 testing_profile_
.reset(new TestingProfile());
169 existing_user_controller_
.reset(
170 new ExistingUserController(mock_login_display_host_
.get()));
171 ASSERT_EQ(existing_user_controller(), existing_user_controller_
.get());
172 existing_user_controller_
->Init(user_manager::UserList());
173 profile_prepared_cb_
=
174 base::Bind(&ExistingUserController::OnProfilePrepared
,
175 base::Unretained(existing_user_controller()),
176 testing_profile_
.get());
179 virtual void CleanUpOnMainThread() OVERRIDE
{
180 // ExistingUserController must be deleted before the thread is cleaned up:
181 // If there is an outstanding login attempt when ExistingUserController is
182 // deleted, its LoginPerformer instance will be deleted, which in turn
183 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
184 // be deleted on the UI thread.
185 existing_user_controller_
.reset();
186 DevicePolicyCrosBrowserTest::InProcessBrowserTest::CleanUpOnMainThread();
187 testing_profile_
.reset(NULL
);
188 user_manager_enabler_
.reset();
191 // ExistingUserController private member accessors.
192 base::OneShotTimer
<ExistingUserController
>* auto_login_timer() {
193 return existing_user_controller()->auto_login_timer_
.get();
196 const std::string
& auto_login_username() const {
197 return existing_user_controller()->public_session_auto_login_username_
;
200 int auto_login_delay() const {
201 return existing_user_controller()->public_session_auto_login_delay_
;
204 bool is_login_in_progress() const {
205 return existing_user_controller()->is_login_in_progress_
;
208 scoped_ptr
<ExistingUserController
> existing_user_controller_
;
210 // |mock_login_display_| is owned by the ExistingUserController, which calls
211 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
212 MockLoginDisplay
* mock_login_display_
;
213 scoped_ptr
<MockLoginDisplayHost
> mock_login_display_host_
;
215 // Owned by LoginUtilsWrapper.
216 MockLoginUtils
* mock_login_utils_
;
218 MockUserManager
* mock_user_manager_
; // Not owned.
219 scoped_ptr
<ScopedUserManagerEnabler
> user_manager_enabler_
;
221 scoped_ptr
<TestingProfile
> testing_profile_
;
224 MockURLFetcherFactory
<SuccessFetcher
> factory_
;
226 base::Callback
<void(void)> profile_prepared_cb_
;
229 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest
);
232 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
, ExistingUserLogin
) {
233 // This is disabled twice: once right after signin but before checking for
234 // auto-enrollment, and again after doing an ownership status check.
235 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
237 UserContext
user_context(kUsername
);
238 user_context
.SetKey(Key(kPassword
));
239 user_context
.SetUserIDHash(kUsername
);
240 EXPECT_CALL(*mock_login_utils_
, CreateAuthenticator(_
))
242 .WillOnce(WithArg
<0>(CreateAuthenticator(user_context
)));
243 EXPECT_CALL(*mock_login_utils_
, PrepareProfile(user_context
, _
, _
, _
))
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_
, SetUIEnabled(true))
253 EXPECT_CALL(*mock_login_display_host_
,
254 StartWizardPtr(WizardController::kTermsOfServiceScreenName
, NULL
))
256 EXPECT_CALL(*mock_user_manager_
, IsCurrentUserNew())
258 .WillRepeatedly(Return(false));
259 existing_user_controller()->Login(user_context
, SigninSpecifics());
260 content::RunAllPendingInMessageLoop();
263 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
, AutoEnrollAfterSignIn
) {
264 EXPECT_CALL(*mock_login_display_host_
,
265 StartWizardPtr(WizardController::kEnrollmentScreenName
,
268 EXPECT_CALL(*mock_login_display_host_
.get(), OnCompleteLogin())
270 EXPECT_CALL(*mock_user_manager_
, IsCurrentUserNew())
272 .WillRepeatedly(Return(false));
273 // The order of these expected calls matters: the UI if first disabled
274 // during the login sequence, and is enabled again for the enrollment screen.
275 Sequence uiEnabledSequence
;
276 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
278 .InSequence(uiEnabledSequence
);
279 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
281 .InSequence(uiEnabledSequence
);
282 existing_user_controller()->DoAutoEnrollment();
283 UserContext
user_context(kUsername
);
284 user_context
.SetKey(Key(kPassword
));
285 existing_user_controller()->CompleteLogin(user_context
);
286 content::RunAllPendingInMessageLoop();
289 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
,
290 NewUserDontAutoEnrollAfterSignIn
) {
291 EXPECT_CALL(*mock_login_display_host_
,
292 StartWizardPtr(WizardController::kEnrollmentScreenName
,
295 EXPECT_CALL(*mock_login_display_host_
,
296 StartWizardPtr(WizardController::kTermsOfServiceScreenName
,
299 UserContext
user_context(kNewUsername
);
300 user_context
.SetKey(Key(kPassword
));
301 user_context
.SetUserIDHash(kNewUsername
);
302 EXPECT_CALL(*mock_login_utils_
, CreateAuthenticator(_
))
304 .WillOnce(WithArg
<0>(CreateAuthenticator(user_context
)));
305 base::Callback
<void(void)> add_user_cb
=
306 base::Bind(&MockUserManager::AddUser
,
307 base::Unretained(mock_user_manager_
),
309 EXPECT_CALL(*mock_login_utils_
, PrepareProfile(user_context
, _
, _
, _
))
312 InvokeWithoutArgs(&add_user_cb
,
313 &base::Callback
<void(void)>::Run
),
314 InvokeWithoutArgs(&profile_prepared_cb_
,
315 &base::Callback
<void(void)>::Run
)));
316 EXPECT_CALL(*mock_login_display_host_
.get(), OnCompleteLogin())
318 EXPECT_CALL(*mock_user_manager_
, IsCurrentUserNew())
320 .WillRepeatedly(Return(true));
322 // The order of these expected calls matters: the UI if first disabled
323 // during the login sequence, and is enabled again after login completion.
324 Sequence uiEnabledSequence
;
325 // This is disabled twice: once right after signin but before checking for
326 // auto-enrollment, and again after doing an ownership status check.
327 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
329 .InSequence(uiEnabledSequence
);
330 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
332 .InSequence(uiEnabledSequence
);
334 existing_user_controller()->CompleteLogin(user_context
);
335 content::RunAllPendingInMessageLoop();
338 MATCHER_P(HasDetails
, expected
, "") {
339 return expected
== *content::Details
<const std::string
>(arg
).ptr();
342 class ExistingUserControllerPublicSessionTest
343 : public ExistingUserControllerTest
{
345 ExistingUserControllerPublicSessionTest()
346 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
347 kPublicSessionAccountId
,
348 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION
)) {
351 virtual void SetUpOnMainThread() OVERRIDE
{
352 ExistingUserControllerTest::SetUpOnMainThread();
354 // Wait for the public session user to be created.
355 if (!chromeos::UserManager::Get()->IsKnownUser(public_session_user_id_
)) {
356 content::WindowedNotificationObserver(
357 chrome::NOTIFICATION_USER_LIST_CHANGED
,
358 base::Bind(&chromeos::UserManager::IsKnownUser
,
359 base::Unretained(chromeos::UserManager::Get()),
360 public_session_user_id_
)).Wait();
363 // Wait for the device local account policy to be installed.
364 policy::CloudPolicyStore
* store
=
365 TestingBrowserProcess::GetGlobal()
367 ->browser_policy_connector_chromeos()
368 ->GetDeviceLocalAccountPolicyService()
369 ->GetBrokerForUser(public_session_user_id_
)
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 UserContext
& user_context
) {
428 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
430 EXPECT_CALL(*mock_login_utils_
, CreateAuthenticator(_
))
432 .WillOnce(WithArg
<0>(CreateAuthenticator(user_context
)));
433 EXPECT_CALL(*mock_login_utils_
, PrepareProfile(user_context
, _
, _
, _
))
435 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_
,
436 &base::Callback
<void(void)>::Run
));
437 EXPECT_CALL(*mock_login_utils_
,
438 DoBrowserLaunch(testing_profile_
.get(),
439 mock_login_display_host_
.get()))
441 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
443 EXPECT_CALL(*mock_login_display_host_
,
444 StartWizardPtr(WizardController::kTermsOfServiceScreenName
,
449 void SetAutoLoginPolicy(const std::string
& username
, int delay
) {
450 // Wait until ExistingUserController has finished auto-login
451 // configuration by observing the same settings that trigger
452 // ConfigurePublicSessionAutoLogin.
454 em::ChromeDeviceSettingsProto
& proto(device_policy()->payload());
456 // If both settings have changed we need to wait for both to
457 // propagate, so check the new values against the old ones.
458 scoped_refptr
<content::MessageLoopRunner
> runner1
;
459 scoped_ptr
<CrosSettings::ObserverSubscription
> subscription1
;
460 if (!proto
.has_device_local_accounts() ||
461 !proto
.device_local_accounts().has_auto_login_id() ||
462 proto
.device_local_accounts().auto_login_id() != username
) {
463 runner1
= new content::MessageLoopRunner
;
464 subscription1
= chromeos::CrosSettings::Get()->AddSettingsObserver(
465 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId
,
466 runner1
->QuitClosure());
468 scoped_refptr
<content::MessageLoopRunner
> runner2
;
469 scoped_ptr
<CrosSettings::ObserverSubscription
> subscription2
;
470 if (!proto
.has_device_local_accounts() ||
471 !proto
.device_local_accounts().has_auto_login_delay() ||
472 proto
.device_local_accounts().auto_login_delay() != delay
) {
473 runner1
= new content::MessageLoopRunner
;
474 subscription1
= chromeos::CrosSettings::Get()->AddSettingsObserver(
475 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay
,
476 runner1
->QuitClosure());
479 // Update the policy.
480 proto
.mutable_device_local_accounts()->set_auto_login_id(username
);
481 proto
.mutable_device_local_accounts()->set_auto_login_delay(delay
);
482 RefreshDevicePolicy();
484 // Wait for ExistingUserController to read the updated settings.
491 void ConfigureAutoLogin() {
492 existing_user_controller()->ConfigurePublicSessionAutoLogin();
495 void FireAutoLogin() {
496 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
499 const std::string public_session_user_id_
;
502 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest
);
505 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
506 ConfigureAutoLoginUsingPolicy
) {
507 existing_user_controller()->OnSigninScreenReady();
508 EXPECT_EQ("", auto_login_username());
509 EXPECT_EQ(0, auto_login_delay());
510 EXPECT_FALSE(auto_login_timer());
513 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
514 EXPECT_EQ(public_session_user_id_
, auto_login_username());
515 EXPECT_EQ(kAutoLoginLongDelay
, auto_login_delay());
516 ASSERT_TRUE(auto_login_timer());
517 EXPECT_TRUE(auto_login_timer()->IsRunning());
520 SetAutoLoginPolicy("", 0);
521 EXPECT_EQ("", auto_login_username());
522 EXPECT_EQ(0, auto_login_delay());
523 ASSERT_TRUE(auto_login_timer());
524 EXPECT_FALSE(auto_login_timer()->IsRunning());
527 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
529 // Set up mocks to check login success.
530 UserContext
user_context(public_session_user_id_
);
531 user_context
.SetUserIDHash(user_context
.GetUserID());
532 ExpectSuccessfulLogin(user_context
);
533 existing_user_controller()->OnSigninScreenReady();
535 // Start auto-login and wait for login tasks to complete.
536 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginNoDelay
);
537 content::RunAllPendingInMessageLoop();
540 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
541 AutoLoginShortDelay
) {
542 // Set up mocks to check login success.
543 UserContext
user_context(public_session_user_id_
);
544 user_context
.SetUserIDHash(user_context
.GetUserID());
545 ExpectSuccessfulLogin(user_context
);
546 existing_user_controller()->OnSigninScreenReady();
547 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginShortDelay
);
548 ASSERT_TRUE(auto_login_timer());
549 // Don't assert that timer is running: with the short delay sometimes
550 // the trigger happens before the assert. We've already tested that
551 // the timer starts when it should.
553 // Wait for the timer to fire.
554 base::RunLoop runner
;
555 base::OneShotTimer
<base::RunLoop
> timer
;
556 timer
.Start(FROM_HERE
,
557 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay
+ 1),
558 runner
.QuitClosure());
561 // Wait for login tasks to complete.
562 content::RunAllPendingInMessageLoop();
565 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
566 LoginStopsAutoLogin
) {
567 // Set up mocks to check login success.
568 UserContext
user_context(kUsername
);
569 user_context
.SetKey(Key(kPassword
));
570 user_context
.SetUserIDHash(user_context
.GetUserID());
571 ExpectSuccessfulLogin(user_context
);
573 existing_user_controller()->OnSigninScreenReady();
574 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
575 ASSERT_TRUE(auto_login_timer());
577 // Log in and check that it stopped the timer.
578 existing_user_controller()->Login(user_context
, SigninSpecifics());
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_F(ExistingUserControllerPublicSessionTest
,
592 GuestModeLoginStopsAutoLogin
) {
593 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
595 UserContext
user_context(kUsername
);
596 user_context
.SetKey(Key(kPassword
));
597 EXPECT_CALL(*mock_login_utils_
, CreateAuthenticator(_
))
599 .WillOnce(WithArg
<0>(CreateAuthenticator(user_context
)));
600 EXPECT_CALL(*mock_login_utils_
, CompleteOffTheRecordLogin(_
))
603 existing_user_controller()->OnSigninScreenReady();
604 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
605 ASSERT_TRUE(auto_login_timer());
607 // Login and check that it stopped the timer.
608 existing_user_controller()->LoginAsGuest();
609 EXPECT_TRUE(is_login_in_progress());
610 ASSERT_TRUE(auto_login_timer());
611 EXPECT_FALSE(auto_login_timer()->IsRunning());
613 // Wait for login tasks to complete.
614 content::RunAllPendingInMessageLoop();
616 // Timer should still be stopped after login completes.
617 ASSERT_TRUE(auto_login_timer());
618 EXPECT_FALSE(auto_login_timer()->IsRunning());
621 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
622 CompleteLoginStopsAutoLogin
) {
623 // Set up mocks to check login success.
624 UserContext
user_context(kUsername
);
625 user_context
.SetKey(Key(kPassword
));
626 user_context
.SetUserIDHash(user_context
.GetUserID());
627 ExpectSuccessfulLogin(user_context
);
628 EXPECT_CALL(*mock_login_display_host_
, OnCompleteLogin())
631 existing_user_controller()->OnSigninScreenReady();
632 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
633 ASSERT_TRUE(auto_login_timer());
635 // Check that login completes and stops the timer.
636 existing_user_controller()->CompleteLogin(user_context
);
637 ASSERT_TRUE(auto_login_timer());
638 EXPECT_FALSE(auto_login_timer()->IsRunning());
640 // Wait for login tasks to complete.
641 content::RunAllPendingInMessageLoop();
643 // Timer should still be stopped after login completes.
644 ASSERT_TRUE(auto_login_timer());
645 EXPECT_FALSE(auto_login_timer()->IsRunning());
648 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
649 PublicSessionLoginStopsAutoLogin
) {
650 // Set up mocks to check login success.
651 UserContext
user_context(public_session_user_id_
);
652 user_context
.SetUserIDHash(user_context
.GetUserID());
653 ExpectSuccessfulLogin(user_context
);
654 existing_user_controller()->OnSigninScreenReady();
655 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
656 ASSERT_TRUE(auto_login_timer());
658 // Login and check that it stopped the timer.
659 existing_user_controller()->LoginAsPublicAccount(public_session_user_id_
);
660 EXPECT_TRUE(is_login_in_progress());
661 ASSERT_TRUE(auto_login_timer());
662 EXPECT_FALSE(auto_login_timer()->IsRunning());
664 // Wait for login tasks to complete.
665 content::RunAllPendingInMessageLoop();
667 // Timer should still be stopped after login completes.
668 ASSERT_TRUE(auto_login_timer());
669 EXPECT_FALSE(auto_login_timer()->IsRunning());
672 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
673 PRE_TestLoadingPublicUsersFromLocalState
) {
674 // First run propagates public accounts and stores them in Local State.
677 // See http://crbug.com/393704; flaky.
678 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
679 DISABLED_TestLoadingPublicUsersFromLocalState
) {
680 // Second run loads list of public accounts from Local State.
683 } // namespace chromeos