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.
9 #include "base/bind_helpers.h"
10 #include "base/callback.h"
11 #include "base/command_line.h"
12 #include "base/location.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/prefs/pref_service.h"
15 #include "base/prefs/scoped_user_pref_update.h"
16 #include "base/run_loop.h"
17 #include "chrome/browser/chrome_notification_types.h"
18 #include "chrome/browser/chromeos/login/existing_user_controller.h"
19 #include "chrome/browser/chromeos/login/help_app_launcher.h"
20 #include "chrome/browser/chromeos/login/helper.h"
21 #include "chrome/browser/chromeos/login/screens/mock_base_screen_delegate.h"
22 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
23 #include "chrome/browser/chromeos/login/session/user_session_manager_test_api.h"
24 #include "chrome/browser/chromeos/login/supervised/supervised_user_creation_screen.h"
25 #include "chrome/browser/chromeos/login/ui/mock_login_display.h"
26 #include "chrome/browser/chromeos/login/ui/mock_login_display_host.h"
27 #include "chrome/browser/chromeos/login/wizard_controller.h"
28 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
29 #include "chrome/browser/chromeos/policy/device_local_account.h"
30 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h"
31 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
32 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
33 #include "chrome/browser/chromeos/settings/cros_settings.h"
34 #include "chrome/browser/ui/webui/chromeos/login/supervised_user_creation_screen_handler.h"
35 #include "chrome/grit/generated_resources.h"
36 #include "chrome/test/base/testing_browser_process.h"
37 #include "chromeos/chromeos_switches.h"
38 #include "chromeos/dbus/fake_session_manager_client.h"
39 #include "chromeos/login/auth/key.h"
40 #include "chromeos/login/auth/mock_url_fetchers.h"
41 #include "chromeos/login/auth/user_context.h"
42 #include "chromeos/login/user_names.h"
43 #include "chromeos/settings/cros_settings_names.h"
44 #include "chromeos/settings/cros_settings_provider.h"
45 #include "components/policy/core/common/cloud/cloud_policy_constants.h"
46 #include "components/policy/core/common/cloud/cloud_policy_core.h"
47 #include "components/policy/core/common/cloud/cloud_policy_store.h"
48 #include "components/policy/core/common/cloud/mock_cloud_policy_store.h"
49 #include "components/policy/core/common/cloud/policy_builder.h"
50 #include "components/user_manager/user.h"
51 #include "components/user_manager/user_manager.h"
52 #include "components/user_manager/user_type.h"
53 #include "content/public/test/mock_notification_observer.h"
54 #include "content/public/test/test_utils.h"
55 #include "google_apis/gaia/mock_url_fetcher_factory.h"
56 #include "policy/proto/device_management_backend.pb.h"
57 #include "testing/gmock/include/gmock/gmock.h"
58 #include "testing/gtest/include/gtest/gtest.h"
60 using ::testing::AnyNumber
;
61 using ::testing::Invoke
;
62 using ::testing::InvokeWithoutArgs
;
63 using ::testing::Return
;
64 using ::testing::ReturnNull
;
65 using ::testing::WithArg
;
68 namespace em
= enterprise_management
;
74 const char kUsername
[] = "test_user@gmail.com";
75 const char kSupervisedUserID
[] = "supervised_user@locally-managed.localhost";
76 const char kPassword
[] = "test_password";
78 const char kPublicSessionAccountId
[] = "public_session_user@localhost";
79 const int kAutoLoginNoDelay
= 0;
80 const int kAutoLoginShortDelay
= 1;
81 const int kAutoLoginLongDelay
= 10000;
83 // Wait for cros settings to become permanently untrusted and run |callback|.
84 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure
& callback
) {
86 const CrosSettingsProvider::TrustedStatus status
=
87 CrosSettings::Get()->PrepareTrustedValues(base::Bind(
88 &WaitForPermanentlyUntrustedStatusAndRun
,
91 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED
:
94 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED
:
96 case CrosSettingsProvider::TRUSTED
:
97 content::RunAllPendingInMessageLoop();
105 class ExistingUserControllerTest
: public policy::DevicePolicyCrosBrowserTest
{
107 ExistingUserControllerTest() : mock_login_display_(NULL
) {}
109 ExistingUserController
* existing_user_controller() {
110 return ExistingUserController::current_controller();
113 const ExistingUserController
* existing_user_controller() const {
114 return ExistingUserController::current_controller();
117 void SetUpInProcessBrowserTestFixture() override
{
118 SetUpSessionManager();
120 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
122 mock_login_display_host_
.reset(new MockLoginDisplayHost());
123 mock_login_display_
= new MockLoginDisplay();
127 virtual void SetUpSessionManager() {
130 virtual void SetUpLoginDisplay() {
131 EXPECT_CALL(*mock_login_display_host_
.get(), CreateLoginDisplay(_
))
133 .WillOnce(Return(mock_login_display_
));
134 EXPECT_CALL(*mock_login_display_host_
.get(), GetNativeWindow())
136 .WillOnce(ReturnNull());
137 EXPECT_CALL(*mock_login_display_host_
.get(), OnPreferencesChanged())
139 EXPECT_CALL(*mock_login_display_
, Init(_
, false, true, true))
143 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
144 command_line
->AppendSwitch(switches::kLoginManager
);
145 command_line
->AppendSwitch(switches::kForceLoginManagerInTests
);
148 void SetUpOnMainThread() override
{
149 existing_user_controller_
.reset(
150 new ExistingUserController(mock_login_display_host_
.get()));
151 ASSERT_EQ(existing_user_controller(), existing_user_controller_
.get());
152 existing_user_controller_
->Init(user_manager::UserList());
155 void TearDownOnMainThread() override
{
156 // ExistingUserController must be deleted before the thread is cleaned up:
157 // If there is an outstanding login attempt when ExistingUserController is
158 // deleted, its LoginPerformer instance will be deleted, which in turn
159 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must
160 // be deleted on the UI thread.
161 existing_user_controller_
.reset();
162 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread();
164 // Test case may be configured with the real user manager but empty user
165 // list initially. So network OOBE screen is initialized.
166 // Need to reset it manually so that we don't end up with CrosSettings
167 // observer that wasn't removed.
168 WizardController
* controller
= WizardController::default_controller();
169 if (controller
&& controller
->current_screen())
170 controller
->current_screen()->Hide();
173 void ExpectLoginFailure() {
174 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
176 EXPECT_CALL(*mock_login_display_
,
177 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST
,
179 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT
))
181 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
185 void RegisterUser(const std::string
& user_id
) {
186 ListPrefUpdate
users_pref(g_browser_process
->local_state(),
188 users_pref
->AppendIfNotPresent(new base::StringValue(user_id
));
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_
;
216 MockURLFetcherFactory
<SuccessFetcher
> factory_
;
219 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest
);
222 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
, PRE_ExistingUserLogin
) {
223 RegisterUser(kUsername
);
226 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
, ExistingUserLogin
) {
227 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
229 UserContext
user_context(kUsername
);
230 user_context
.SetKey(Key(kPassword
));
231 user_context
.SetUserIDHash(kUsername
);
232 test::UserSessionManagerTestApi
session_manager_test_api(
233 UserSessionManager::GetInstance());
234 session_manager_test_api
.InjectStubUserContext(user_context
);
235 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
237 EXPECT_CALL(*mock_login_display_host_
,
238 StartWizard(WizardController::kTermsOfServiceScreenName
))
241 content::WindowedNotificationObserver
profile_prepared_observer(
242 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
243 content::NotificationService::AllSources());
244 existing_user_controller()->Login(user_context
, SigninSpecifics());
246 profile_prepared_observer
.Wait();
247 content::RunAllPendingInMessageLoop();
250 // Verifies that when the cros settings are untrusted, no new session can be
252 class ExistingUserControllerUntrustedTest
: public ExistingUserControllerTest
{
254 ExistingUserControllerUntrustedTest();
256 void SetUpInProcessBrowserTestFixture() override
;
258 void SetUpSessionManager() override
;
261 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerUntrustedTest
);
264 ExistingUserControllerUntrustedTest::ExistingUserControllerUntrustedTest() {
267 void ExistingUserControllerUntrustedTest::SetUpInProcessBrowserTestFixture() {
268 ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
270 ExpectLoginFailure();
273 void ExistingUserControllerUntrustedTest::SetUpSessionManager() {
277 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
278 ExistingUserLoginForbidden
) {
279 UserContext
user_context(kUsername
);
280 user_context
.SetKey(Key(kPassword
));
281 user_context
.SetUserIDHash(kUsername
);
282 existing_user_controller()->Login(user_context
, SigninSpecifics());
285 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
286 NewUserLoginForbidden
) {
287 UserContext
user_context(kUsername
);
288 user_context
.SetKey(Key(kPassword
));
289 user_context
.SetUserIDHash(kUsername
);
290 existing_user_controller()->CompleteLogin(user_context
);
293 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
294 CreateAccountForbidden
) {
295 existing_user_controller()->CreateAccount();
298 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
299 GuestLoginForbidden
) {
300 existing_user_controller()->Login(
301 UserContext(user_manager::USER_TYPE_GUEST
, std::string()),
305 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
306 SupervisedUserLoginForbidden
) {
307 UserContext
user_context(kSupervisedUserID
);
308 user_context
.SetKey(Key(kPassword
));
309 user_context
.SetUserIDHash(kUsername
);
310 existing_user_controller()->Login(user_context
, SigninSpecifics());
313 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
314 SupervisedUserCreationForbidden
) {
315 MockBaseScreenDelegate mock_base_screen_delegate
;
316 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler
;
317 SupervisedUserCreationScreen
supervised_user_creation_screen(
318 &mock_base_screen_delegate
, &supervised_user_creation_screen_handler
);
320 supervised_user_creation_screen
.AuthenticateManager(kUsername
, kPassword
);
323 MATCHER_P(HasDetails
, expected
, "") {
324 return expected
== *content::Details
<const std::string
>(arg
).ptr();
327 class ExistingUserControllerPublicSessionTest
328 : public ExistingUserControllerTest
{
330 ExistingUserControllerPublicSessionTest()
331 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
332 kPublicSessionAccountId
,
333 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION
)) {
336 void SetUpOnMainThread() override
{
337 ExistingUserControllerTest::SetUpOnMainThread();
339 // Wait for the public session user to be created.
340 if (!user_manager::UserManager::Get()->IsKnownUser(
341 public_session_user_id_
)) {
342 content::WindowedNotificationObserver(
343 chrome::NOTIFICATION_USER_LIST_CHANGED
,
344 base::Bind(&user_manager::UserManager::IsKnownUser
,
345 base::Unretained(user_manager::UserManager::Get()),
346 public_session_user_id_
)).Wait();
349 // Wait for the device local account policy to be installed.
350 policy::CloudPolicyStore
* store
=
351 TestingBrowserProcess::GetGlobal()
353 ->browser_policy_connector_chromeos()
354 ->GetDeviceLocalAccountPolicyService()
355 ->GetBrokerForUser(public_session_user_id_
)
358 if (!store
->has_policy()) {
359 policy::MockCloudPolicyStoreObserver observer
;
362 store
->AddObserver(&observer
);
363 EXPECT_CALL(observer
, OnStoreLoaded(store
))
365 .WillOnce(InvokeWithoutArgs(&loop
, &base::RunLoop::Quit
));
367 store
->RemoveObserver(&observer
);
371 void SetUpSessionManager() override
{
374 // Setup the device policy.
375 em::ChromeDeviceSettingsProto
& proto(device_policy()->payload());
376 em::DeviceLocalAccountInfoProto
* account
=
377 proto
.mutable_device_local_accounts()->add_account();
378 account
->set_account_id(kPublicSessionAccountId
);
380 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION
);
381 RefreshDevicePolicy();
383 // Setup the device local account policy.
384 policy::UserPolicyBuilder device_local_account_policy
;
385 device_local_account_policy
.policy_data().set_username(
386 kPublicSessionAccountId
);
387 device_local_account_policy
.policy_data().set_policy_type(
388 policy::dm_protocol::kChromePublicAccountPolicyType
);
389 device_local_account_policy
.policy_data().set_settings_entity_id(
390 kPublicSessionAccountId
);
391 device_local_account_policy
.Build();
392 session_manager_client()->set_device_local_account_policy(
393 kPublicSessionAccountId
,
394 device_local_account_policy
.GetBlob());
397 void SetUpLoginDisplay() override
{
398 EXPECT_CALL(*mock_login_display_host_
.get(), CreateLoginDisplay(_
))
400 .WillOnce(Return(mock_login_display_
));
401 EXPECT_CALL(*mock_login_display_host_
.get(), GetNativeWindow())
403 .WillRepeatedly(ReturnNull());
404 EXPECT_CALL(*mock_login_display_host_
.get(), OnPreferencesChanged())
406 EXPECT_CALL(*mock_login_display_
, Init(_
, _
, _
, _
))
410 void TearDownOnMainThread() override
{
411 ExistingUserControllerTest::TearDownOnMainThread();
413 // Test case may be configured with the real user manager but empty user
414 // list initially. So network OOBE screen is initialized.
415 // Need to reset it manually so that we don't end up with CrosSettings
416 // observer that wasn't removed.
417 WizardController
* controller
= WizardController::default_controller();
418 if (controller
&& controller
->current_screen())
419 controller
->current_screen()->Hide();
422 void ExpectSuccessfulLogin(const UserContext
& user_context
) {
423 test::UserSessionManagerTestApi
session_manager_test_api(
424 UserSessionManager::GetInstance());
425 session_manager_test_api
.InjectStubUserContext(user_context
);
426 EXPECT_CALL(*mock_login_display_host_
,
427 StartWizard(WizardController::kTermsOfServiceScreenName
))
429 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false)).Times(AnyNumber());
430 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true)).Times(AnyNumber());
433 void SetAutoLoginPolicy(const std::string
& username
, int delay
) {
434 // Wait until ExistingUserController has finished auto-login
435 // configuration by observing the same settings that trigger
436 // ConfigurePublicSessionAutoLogin.
438 em::ChromeDeviceSettingsProto
& proto(device_policy()->payload());
440 // If both settings have changed we need to wait for both to
441 // propagate, so check the new values against the old ones.
442 scoped_refptr
<content::MessageLoopRunner
> runner1
;
443 scoped_ptr
<CrosSettings::ObserverSubscription
> subscription1
;
444 if (!proto
.has_device_local_accounts() ||
445 !proto
.device_local_accounts().has_auto_login_id() ||
446 proto
.device_local_accounts().auto_login_id() != username
) {
447 runner1
= new content::MessageLoopRunner
;
448 subscription1
= chromeos::CrosSettings::Get()->AddSettingsObserver(
449 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId
,
450 runner1
->QuitClosure());
452 scoped_refptr
<content::MessageLoopRunner
> runner2
;
453 scoped_ptr
<CrosSettings::ObserverSubscription
> subscription2
;
454 if (!proto
.has_device_local_accounts() ||
455 !proto
.device_local_accounts().has_auto_login_delay() ||
456 proto
.device_local_accounts().auto_login_delay() != delay
) {
457 runner1
= new content::MessageLoopRunner
;
458 subscription1
= chromeos::CrosSettings::Get()->AddSettingsObserver(
459 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay
,
460 runner1
->QuitClosure());
463 // Update the policy.
464 proto
.mutable_device_local_accounts()->set_auto_login_id(username
);
465 proto
.mutable_device_local_accounts()->set_auto_login_delay(delay
);
466 RefreshDevicePolicy();
468 // Wait for ExistingUserController to read the updated settings.
475 void ConfigureAutoLogin() {
476 existing_user_controller()->ConfigurePublicSessionAutoLogin();
479 void FireAutoLogin() {
480 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
483 void MakeCrosSettingsPermanentlyUntrusted() {
484 device_policy()->policy().set_policy_data_signature("bad signature");
485 session_manager_client()->set_device_policy(device_policy()->GetBlob());
486 session_manager_client()->OnPropertyChangeComplete(true);
488 base::RunLoop run_loop
;
489 WaitForPermanentlyUntrustedStatusAndRun(run_loop
.QuitClosure());
493 const std::string public_session_user_id_
;
496 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest
);
499 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
500 ConfigureAutoLoginUsingPolicy
) {
501 existing_user_controller()->OnSigninScreenReady();
502 EXPECT_EQ("", auto_login_username());
503 EXPECT_EQ(0, auto_login_delay());
504 EXPECT_FALSE(auto_login_timer());
507 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
508 EXPECT_EQ(public_session_user_id_
, auto_login_username());
509 EXPECT_EQ(kAutoLoginLongDelay
, auto_login_delay());
510 ASSERT_TRUE(auto_login_timer());
511 EXPECT_TRUE(auto_login_timer()->IsRunning());
514 SetAutoLoginPolicy("", 0);
515 EXPECT_EQ("", auto_login_username());
516 EXPECT_EQ(0, auto_login_delay());
517 ASSERT_TRUE(auto_login_timer());
518 EXPECT_FALSE(auto_login_timer()->IsRunning());
521 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
523 // Set up mocks to check login success.
524 UserContext
user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
525 public_session_user_id_
);
526 user_context
.SetUserIDHash(user_context
.GetUserID());
527 ExpectSuccessfulLogin(user_context
);
528 existing_user_controller()->OnSigninScreenReady();
530 // Start auto-login and wait for login tasks to complete.
531 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginNoDelay
);
532 content::RunAllPendingInMessageLoop();
535 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
536 AutoLoginShortDelay
) {
537 // Set up mocks to check login success.
538 UserContext
user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
539 public_session_user_id_
);
540 user_context
.SetUserIDHash(user_context
.GetUserID());
541 ExpectSuccessfulLogin(user_context
);
542 existing_user_controller()->OnSigninScreenReady();
544 content::WindowedNotificationObserver
profile_prepared_observer(
545 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
546 content::NotificationService::AllSources());
548 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginShortDelay
);
549 ASSERT_TRUE(auto_login_timer());
550 // Don't assert that timer is running: with the short delay sometimes
551 // the trigger happens before the assert. We've already tested that
552 // the timer starts when it should.
554 // Wait for the timer to fire.
555 base::RunLoop runner
;
556 base::OneShotTimer
<base::RunLoop
> timer
;
557 timer
.Start(FROM_HERE
,
558 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay
+ 1),
559 runner
.QuitClosure());
562 profile_prepared_observer
.Wait();
564 // Wait for login tasks to complete.
565 content::RunAllPendingInMessageLoop();
568 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
569 LoginStopsAutoLogin
) {
570 // Set up mocks to check login success.
571 UserContext
user_context(kUsername
);
572 user_context
.SetKey(Key(kPassword
));
573 user_context
.SetUserIDHash(user_context
.GetUserID());
574 ExpectSuccessfulLogin(user_context
);
576 existing_user_controller()->OnSigninScreenReady();
577 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
578 EXPECT_TRUE(auto_login_timer());
580 content::WindowedNotificationObserver
profile_prepared_observer(
581 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
582 content::NotificationService::AllSources());
584 // Log in and check that it stopped the timer.
585 existing_user_controller()->Login(user_context
, SigninSpecifics());
586 EXPECT_TRUE(is_login_in_progress());
587 ASSERT_TRUE(auto_login_timer());
588 EXPECT_FALSE(auto_login_timer()->IsRunning());
590 profile_prepared_observer
.Wait();
592 // Wait for login tasks to complete.
593 content::RunAllPendingInMessageLoop();
595 // Timer should still be stopped after login completes.
596 ASSERT_TRUE(auto_login_timer());
597 EXPECT_FALSE(auto_login_timer()->IsRunning());
600 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
601 GuestModeLoginStopsAutoLogin
) {
602 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
604 UserContext
user_context(kUsername
);
605 user_context
.SetKey(Key(kPassword
));
606 test::UserSessionManagerTestApi
session_manager_test_api(
607 UserSessionManager::GetInstance());
608 session_manager_test_api
.InjectStubUserContext(user_context
);
610 existing_user_controller()->OnSigninScreenReady();
611 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
612 EXPECT_TRUE(auto_login_timer());
614 // Login and check that it stopped the timer.
615 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST
,
618 EXPECT_TRUE(is_login_in_progress());
619 ASSERT_TRUE(auto_login_timer());
620 EXPECT_FALSE(auto_login_timer()->IsRunning());
622 // Wait for login tasks to complete.
623 content::RunAllPendingInMessageLoop();
625 // Timer should still be stopped after login completes.
626 ASSERT_TRUE(auto_login_timer());
627 EXPECT_FALSE(auto_login_timer()->IsRunning());
630 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
631 CompleteLoginStopsAutoLogin
) {
632 // Set up mocks to check login success.
633 UserContext
user_context(kUsername
);
634 user_context
.SetKey(Key(kPassword
));
635 user_context
.SetUserIDHash(user_context
.GetUserID());
636 ExpectSuccessfulLogin(user_context
);
637 EXPECT_CALL(*mock_login_display_host_
, OnCompleteLogin())
640 existing_user_controller()->OnSigninScreenReady();
641 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
642 EXPECT_TRUE(auto_login_timer());
644 content::WindowedNotificationObserver
profile_prepared_observer(
645 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
646 content::NotificationService::AllSources());
648 // Check that login completes and stops the timer.
649 existing_user_controller()->CompleteLogin(user_context
);
650 ASSERT_TRUE(auto_login_timer());
651 EXPECT_FALSE(auto_login_timer()->IsRunning());
653 profile_prepared_observer
.Wait();
655 // Wait for login tasks to complete.
656 content::RunAllPendingInMessageLoop();
658 // Timer should still be stopped after login completes.
659 ASSERT_TRUE(auto_login_timer());
660 EXPECT_FALSE(auto_login_timer()->IsRunning());
663 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
664 PublicSessionLoginStopsAutoLogin
) {
665 // Set up mocks to check login success.
666 UserContext
user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
667 public_session_user_id_
);
668 user_context
.SetUserIDHash(user_context
.GetUserID());
669 ExpectSuccessfulLogin(user_context
);
670 existing_user_controller()->OnSigninScreenReady();
671 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
672 EXPECT_TRUE(auto_login_timer());
674 content::WindowedNotificationObserver
profile_prepared_observer(
675 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
676 content::NotificationService::AllSources());
678 // Login and check that it stopped the timer.
679 existing_user_controller()->Login(
680 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
681 public_session_user_id_
),
684 EXPECT_TRUE(is_login_in_progress());
685 ASSERT_TRUE(auto_login_timer());
686 EXPECT_FALSE(auto_login_timer()->IsRunning());
688 profile_prepared_observer
.Wait();
690 // Wait for login tasks to complete.
691 content::RunAllPendingInMessageLoop();
693 // Timer should still be stopped after login completes.
694 ASSERT_TRUE(auto_login_timer());
695 EXPECT_FALSE(auto_login_timer()->IsRunning());
698 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
699 LoginForbiddenWhenUntrusted
) {
700 // Make cros settings untrusted.
701 MakeCrosSettingsPermanentlyUntrusted();
703 // Check that the attempt to start a public session fails with an error.
704 ExpectLoginFailure();
705 UserContext
user_context(kUsername
);
706 user_context
.SetKey(Key(kPassword
));
707 user_context
.SetUserIDHash(user_context
.GetUserID());
708 existing_user_controller()->Login(user_context
, SigninSpecifics());
711 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
712 NoAutoLoginWhenUntrusted
) {
713 // Start the public session timer.
714 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
715 existing_user_controller()->OnSigninScreenReady();
716 EXPECT_TRUE(auto_login_timer());
718 // Make cros settings untrusted.
719 MakeCrosSettingsPermanentlyUntrusted();
721 // Check that when the timer fires, auto-login fails with an error.
722 ExpectLoginFailure();
726 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
727 PRE_TestLoadingPublicUsersFromLocalState
) {
728 // First run propagates public accounts and stores them in Local State.
731 // See http://crbug.com/393704; flaky.
732 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
733 DISABLED_TestLoadingPublicUsersFromLocalState
) {
734 // Second run loads list of public accounts from Local State.
737 } // namespace chromeos