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 kGaiaID
[] = "12345";
75 const char kUsername
[] = "test_user@gmail.com";
76 const char kSupervisedUserID
[] = "supervised_user@locally-managed.localhost";
77 const char kPassword
[] = "test_password";
79 const char kPublicSessionAccountId
[] = "public_session_user@localhost";
80 const int kAutoLoginNoDelay
= 0;
81 const int kAutoLoginShortDelay
= 1;
82 const int kAutoLoginLongDelay
= 10000;
84 // Wait for cros settings to become permanently untrusted and run |callback|.
85 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure
& callback
) {
87 const CrosSettingsProvider::TrustedStatus status
=
88 CrosSettings::Get()->PrepareTrustedValues(base::Bind(
89 &WaitForPermanentlyUntrustedStatusAndRun
,
92 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED
:
95 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED
:
97 case CrosSettingsProvider::TRUSTED
:
98 content::RunAllPendingInMessageLoop();
106 class ExistingUserControllerTest
: public policy::DevicePolicyCrosBrowserTest
{
108 ExistingUserControllerTest() : mock_login_display_(NULL
) {}
110 ExistingUserController
* existing_user_controller() {
111 return ExistingUserController::current_controller();
114 const ExistingUserController
* existing_user_controller() const {
115 return ExistingUserController::current_controller();
118 void SetUpInProcessBrowserTestFixture() override
{
119 SetUpSessionManager();
121 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture();
123 mock_login_display_host_
.reset(new MockLoginDisplayHost());
124 mock_login_display_
= new MockLoginDisplay();
128 virtual void SetUpSessionManager() {
131 virtual void SetUpLoginDisplay() {
132 EXPECT_CALL(*mock_login_display_host_
.get(), CreateLoginDisplay(_
))
134 .WillOnce(Return(mock_login_display_
));
135 EXPECT_CALL(*mock_login_display_host_
.get(), GetNativeWindow())
137 .WillOnce(ReturnNull());
138 EXPECT_CALL(*mock_login_display_host_
.get(), OnPreferencesChanged())
140 EXPECT_CALL(*mock_login_display_
, Init(_
, false, true, true))
144 void SetUpCommandLine(base::CommandLine
* command_line
) override
{
145 command_line
->AppendSwitch(switches::kLoginManager
);
146 command_line
->AppendSwitch(switches::kForceLoginManagerInTests
);
149 void SetUpOnMainThread() override
{
150 existing_user_controller_
.reset(
151 new ExistingUserController(mock_login_display_host_
.get()));
152 ASSERT_EQ(existing_user_controller(), existing_user_controller_
.get());
153 existing_user_controller_
->Init(user_manager::UserList());
155 chromeos::test::UserSessionManagerTestApi
session_manager_test_api(
156 chromeos::UserSessionManager::GetInstance());
157 session_manager_test_api
.SetShouldObtainTokenHandleInTests(false);
160 void TearDownOnMainThread() override
{
161 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread();
163 // |existing_user_controller_| has data members that are CrosSettings
164 // observers. They need to be destructed before CrosSettings.
165 existing_user_controller_
.reset();
167 // Test case may be configured with the real user manager but empty user
168 // list initially. So network OOBE screen is initialized.
169 // Need to reset it manually so that we don't end up with CrosSettings
170 // observer that wasn't removed.
171 WizardController
* controller
= WizardController::default_controller();
172 if (controller
&& controller
->current_screen())
173 controller
->current_screen()->Hide();
176 void ExpectLoginFailure() {
177 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
179 EXPECT_CALL(*mock_login_display_
,
180 ShowError(IDS_LOGIN_ERROR_OWNER_KEY_LOST
,
182 HelpAppLauncher::HELP_CANT_ACCESS_ACCOUNT
))
184 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
188 void RegisterUser(const std::string
& user_id
) {
189 ListPrefUpdate
users_pref(g_browser_process
->local_state(),
191 users_pref
->AppendIfNotPresent(new base::StringValue(user_id
));
194 // ExistingUserController private member accessors.
195 base::OneShotTimer
<ExistingUserController
>* auto_login_timer() {
196 return existing_user_controller()->auto_login_timer_
.get();
199 const std::string
& auto_login_username() const {
200 return existing_user_controller()->public_session_auto_login_username_
;
203 int auto_login_delay() const {
204 return existing_user_controller()->public_session_auto_login_delay_
;
207 bool is_login_in_progress() const {
208 return existing_user_controller()->is_login_in_progress_
;
211 scoped_ptr
<ExistingUserController
> existing_user_controller_
;
213 // |mock_login_display_| is owned by the ExistingUserController, which calls
214 // CreateLoginDisplay() on the |mock_login_display_host_| to get it.
215 MockLoginDisplay
* mock_login_display_
;
216 scoped_ptr
<MockLoginDisplayHost
> mock_login_display_host_
;
219 MockURLFetcherFactory
<SuccessFetcher
> factory_
;
222 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest
);
225 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
, PRE_ExistingUserLogin
) {
226 RegisterUser(kUsername
);
229 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest
, ExistingUserLogin
) {
230 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
232 UserContext
user_context(kUsername
);
233 user_context
.SetGaiaID(kGaiaID
);
234 user_context
.SetKey(Key(kPassword
));
235 user_context
.SetUserIDHash(kUsername
);
236 test::UserSessionManagerTestApi
session_manager_test_api(
237 UserSessionManager::GetInstance());
238 session_manager_test_api
.InjectStubUserContext(user_context
);
239 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true))
241 EXPECT_CALL(*mock_login_display_host_
,
242 StartWizard(WizardController::kTermsOfServiceScreenName
))
245 content::WindowedNotificationObserver
profile_prepared_observer(
246 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
247 content::NotificationService::AllSources());
248 existing_user_controller()->Login(user_context
, SigninSpecifics());
250 profile_prepared_observer
.Wait();
251 content::RunAllPendingInMessageLoop();
254 // Verifies that when the cros settings are untrusted, no new session can be
256 class ExistingUserControllerUntrustedTest
: public ExistingUserControllerTest
{
258 ExistingUserControllerUntrustedTest();
260 void SetUpInProcessBrowserTestFixture() override
;
262 void SetUpSessionManager() override
;
265 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerUntrustedTest
);
268 ExistingUserControllerUntrustedTest::ExistingUserControllerUntrustedTest() {
271 void ExistingUserControllerUntrustedTest::SetUpInProcessBrowserTestFixture() {
272 ExistingUserControllerTest::SetUpInProcessBrowserTestFixture();
274 ExpectLoginFailure();
277 void ExistingUserControllerUntrustedTest::SetUpSessionManager() {
281 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
282 ExistingUserLoginForbidden
) {
283 UserContext
user_context(kUsername
);
284 user_context
.SetGaiaID(kGaiaID
);
285 user_context
.SetKey(Key(kPassword
));
286 user_context
.SetUserIDHash(kUsername
);
287 existing_user_controller()->Login(user_context
, SigninSpecifics());
290 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
291 NewUserLoginForbidden
) {
292 UserContext
user_context(kUsername
);
293 user_context
.SetGaiaID(kGaiaID
);
294 user_context
.SetKey(Key(kPassword
));
295 user_context
.SetUserIDHash(kUsername
);
296 existing_user_controller()->CompleteLogin(user_context
);
299 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
300 CreateAccountForbidden
) {
301 existing_user_controller()->CreateAccount();
304 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
305 GuestLoginForbidden
) {
306 existing_user_controller()->Login(
307 UserContext(user_manager::USER_TYPE_GUEST
, std::string()),
311 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
312 SupervisedUserLoginForbidden
) {
313 UserContext
user_context(kSupervisedUserID
);
314 user_context
.SetKey(Key(kPassword
));
315 user_context
.SetUserIDHash(kUsername
);
316 existing_user_controller()->Login(user_context
, SigninSpecifics());
319 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest
,
320 SupervisedUserCreationForbidden
) {
321 MockBaseScreenDelegate mock_base_screen_delegate
;
322 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler
;
323 SupervisedUserCreationScreen
supervised_user_creation_screen(
324 &mock_base_screen_delegate
, &supervised_user_creation_screen_handler
);
326 supervised_user_creation_screen
.AuthenticateManager(kUsername
, kPassword
);
329 MATCHER_P(HasDetails
, expected
, "") {
330 return expected
== *content::Details
<const std::string
>(arg
).ptr();
333 class ExistingUserControllerPublicSessionTest
334 : public ExistingUserControllerTest
{
336 ExistingUserControllerPublicSessionTest()
337 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
338 kPublicSessionAccountId
,
339 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION
)) {
342 void SetUpOnMainThread() override
{
343 ExistingUserControllerTest::SetUpOnMainThread();
345 // Wait for the public session user to be created.
346 if (!user_manager::UserManager::Get()->IsKnownUser(
347 public_session_user_id_
)) {
348 content::WindowedNotificationObserver(
349 chrome::NOTIFICATION_USER_LIST_CHANGED
,
350 base::Bind(&user_manager::UserManager::IsKnownUser
,
351 base::Unretained(user_manager::UserManager::Get()),
352 public_session_user_id_
)).Wait();
355 // Wait for the device local account policy to be installed.
356 policy::CloudPolicyStore
* store
=
357 TestingBrowserProcess::GetGlobal()
359 ->browser_policy_connector_chromeos()
360 ->GetDeviceLocalAccountPolicyService()
361 ->GetBrokerForUser(public_session_user_id_
)
364 if (!store
->has_policy()) {
365 policy::MockCloudPolicyStoreObserver observer
;
368 store
->AddObserver(&observer
);
369 EXPECT_CALL(observer
, OnStoreLoaded(store
))
371 .WillOnce(InvokeWithoutArgs(&loop
, &base::RunLoop::Quit
));
373 store
->RemoveObserver(&observer
);
377 void SetUpSessionManager() override
{
380 // Setup the device policy.
381 em::ChromeDeviceSettingsProto
& proto(device_policy()->payload());
382 em::DeviceLocalAccountInfoProto
* account
=
383 proto
.mutable_device_local_accounts()->add_account();
384 account
->set_account_id(kPublicSessionAccountId
);
386 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION
);
387 RefreshDevicePolicy();
389 // Setup the device local account policy.
390 policy::UserPolicyBuilder device_local_account_policy
;
391 device_local_account_policy
.policy_data().set_username(
392 kPublicSessionAccountId
);
393 device_local_account_policy
.policy_data().set_policy_type(
394 policy::dm_protocol::kChromePublicAccountPolicyType
);
395 device_local_account_policy
.policy_data().set_settings_entity_id(
396 kPublicSessionAccountId
);
397 device_local_account_policy
.Build();
398 session_manager_client()->set_device_local_account_policy(
399 kPublicSessionAccountId
,
400 device_local_account_policy
.GetBlob());
403 void SetUpLoginDisplay() override
{
404 EXPECT_CALL(*mock_login_display_host_
.get(), CreateLoginDisplay(_
))
406 .WillOnce(Return(mock_login_display_
));
407 EXPECT_CALL(*mock_login_display_host_
.get(), GetNativeWindow())
409 .WillRepeatedly(ReturnNull());
410 EXPECT_CALL(*mock_login_display_host_
.get(), OnPreferencesChanged())
412 EXPECT_CALL(*mock_login_display_
, Init(_
, _
, _
, _
))
416 void TearDownOnMainThread() override
{
417 ExistingUserControllerTest::TearDownOnMainThread();
419 // Test case may be configured with the real user manager but empty user
420 // list initially. So network OOBE screen is initialized.
421 // Need to reset it manually so that we don't end up with CrosSettings
422 // observer that wasn't removed.
423 WizardController
* controller
= WizardController::default_controller();
424 if (controller
&& controller
->current_screen())
425 controller
->current_screen()->Hide();
428 void ExpectSuccessfulLogin(const UserContext
& user_context
) {
429 test::UserSessionManagerTestApi
session_manager_test_api(
430 UserSessionManager::GetInstance());
431 session_manager_test_api
.InjectStubUserContext(user_context
);
432 EXPECT_CALL(*mock_login_display_host_
,
433 StartWizard(WizardController::kTermsOfServiceScreenName
))
435 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false)).Times(AnyNumber());
436 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(true)).Times(AnyNumber());
439 void SetAutoLoginPolicy(const std::string
& username
, int delay
) {
440 // Wait until ExistingUserController has finished auto-login
441 // configuration by observing the same settings that trigger
442 // ConfigurePublicSessionAutoLogin.
444 em::ChromeDeviceSettingsProto
& proto(device_policy()->payload());
446 // If both settings have changed we need to wait for both to
447 // propagate, so check the new values against the old ones.
448 scoped_refptr
<content::MessageLoopRunner
> runner1
;
449 scoped_ptr
<CrosSettings::ObserverSubscription
> subscription1
;
450 if (!proto
.has_device_local_accounts() ||
451 !proto
.device_local_accounts().has_auto_login_id() ||
452 proto
.device_local_accounts().auto_login_id() != username
) {
453 runner1
= new content::MessageLoopRunner
;
454 subscription1
= chromeos::CrosSettings::Get()->AddSettingsObserver(
455 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId
,
456 runner1
->QuitClosure());
458 scoped_refptr
<content::MessageLoopRunner
> runner2
;
459 scoped_ptr
<CrosSettings::ObserverSubscription
> subscription2
;
460 if (!proto
.has_device_local_accounts() ||
461 !proto
.device_local_accounts().has_auto_login_delay() ||
462 proto
.device_local_accounts().auto_login_delay() != delay
) {
463 runner2
= new content::MessageLoopRunner
;
464 subscription2
= chromeos::CrosSettings::Get()->AddSettingsObserver(
465 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay
,
466 runner2
->QuitClosure());
469 // Update the policy.
470 proto
.mutable_device_local_accounts()->set_auto_login_id(username
);
471 proto
.mutable_device_local_accounts()->set_auto_login_delay(delay
);
472 RefreshDevicePolicy();
474 // Wait for ExistingUserController to read the updated settings.
481 void ConfigureAutoLogin() {
482 existing_user_controller()->ConfigurePublicSessionAutoLogin();
485 void FireAutoLogin() {
486 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
489 void MakeCrosSettingsPermanentlyUntrusted() {
490 device_policy()->policy().set_policy_data_signature("bad signature");
491 session_manager_client()->set_device_policy(device_policy()->GetBlob());
492 session_manager_client()->OnPropertyChangeComplete(true);
494 base::RunLoop run_loop
;
495 WaitForPermanentlyUntrustedStatusAndRun(run_loop
.QuitClosure());
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(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
531 public_session_user_id_
);
532 user_context
.SetUserIDHash(user_context
.GetUserID());
533 ExpectSuccessfulLogin(user_context
);
534 existing_user_controller()->OnSigninScreenReady();
536 // Start auto-login and wait for login tasks to complete.
537 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginNoDelay
);
538 content::RunAllPendingInMessageLoop();
541 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
542 AutoLoginShortDelay
) {
543 // Set up mocks to check login success.
544 UserContext
user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
545 public_session_user_id_
);
546 user_context
.SetUserIDHash(user_context
.GetUserID());
547 ExpectSuccessfulLogin(user_context
);
548 existing_user_controller()->OnSigninScreenReady();
550 content::WindowedNotificationObserver
profile_prepared_observer(
551 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
552 content::NotificationService::AllSources());
554 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginShortDelay
);
555 ASSERT_TRUE(auto_login_timer());
556 // Don't assert that timer is running: with the short delay sometimes
557 // the trigger happens before the assert. We've already tested that
558 // the timer starts when it should.
560 // Wait for the timer to fire.
561 base::RunLoop runner
;
562 base::OneShotTimer
<base::RunLoop
> timer
;
563 timer
.Start(FROM_HERE
,
564 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay
+ 1),
565 runner
.QuitClosure());
568 profile_prepared_observer
.Wait();
570 // Wait for login tasks to complete.
571 content::RunAllPendingInMessageLoop();
574 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
575 LoginStopsAutoLogin
) {
576 // Set up mocks to check login success.
577 UserContext
user_context(kUsername
);
578 user_context
.SetGaiaID(kGaiaID
);
579 user_context
.SetKey(Key(kPassword
));
580 user_context
.SetUserIDHash(user_context
.GetUserID());
581 ExpectSuccessfulLogin(user_context
);
583 existing_user_controller()->OnSigninScreenReady();
584 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
585 EXPECT_TRUE(auto_login_timer());
587 content::WindowedNotificationObserver
profile_prepared_observer(
588 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
589 content::NotificationService::AllSources());
591 // Log in and check that it stopped the timer.
592 existing_user_controller()->Login(user_context
, SigninSpecifics());
593 EXPECT_TRUE(is_login_in_progress());
594 ASSERT_TRUE(auto_login_timer());
595 EXPECT_FALSE(auto_login_timer()->IsRunning());
597 profile_prepared_observer
.Wait();
599 // Wait for login tasks to complete.
600 content::RunAllPendingInMessageLoop();
602 // Timer should still be stopped after login completes.
603 ASSERT_TRUE(auto_login_timer());
604 EXPECT_FALSE(auto_login_timer()->IsRunning());
607 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
608 GuestModeLoginStopsAutoLogin
) {
609 EXPECT_CALL(*mock_login_display_
, SetUIEnabled(false))
611 UserContext
user_context(kUsername
);
612 user_context
.SetGaiaID(kGaiaID
);
613 user_context
.SetKey(Key(kPassword
));
614 test::UserSessionManagerTestApi
session_manager_test_api(
615 UserSessionManager::GetInstance());
616 session_manager_test_api
.InjectStubUserContext(user_context
);
618 existing_user_controller()->OnSigninScreenReady();
619 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
620 EXPECT_TRUE(auto_login_timer());
622 // Login and check that it stopped the timer.
623 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST
,
626 EXPECT_TRUE(is_login_in_progress());
627 ASSERT_TRUE(auto_login_timer());
628 EXPECT_FALSE(auto_login_timer()->IsRunning());
630 // Wait for login tasks to complete.
631 content::RunAllPendingInMessageLoop();
633 // Timer should still be stopped after login completes.
634 ASSERT_TRUE(auto_login_timer());
635 EXPECT_FALSE(auto_login_timer()->IsRunning());
638 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
639 CompleteLoginStopsAutoLogin
) {
640 // Set up mocks to check login success.
641 UserContext
user_context(kUsername
);
642 user_context
.SetGaiaID(kGaiaID
);
643 user_context
.SetKey(Key(kPassword
));
644 user_context
.SetUserIDHash(user_context
.GetUserID());
645 ExpectSuccessfulLogin(user_context
);
646 EXPECT_CALL(*mock_login_display_host_
, OnCompleteLogin())
649 existing_user_controller()->OnSigninScreenReady();
650 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
651 EXPECT_TRUE(auto_login_timer());
653 content::WindowedNotificationObserver
profile_prepared_observer(
654 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
655 content::NotificationService::AllSources());
657 // Check that login completes and stops the timer.
658 existing_user_controller()->CompleteLogin(user_context
);
659 ASSERT_TRUE(auto_login_timer());
660 EXPECT_FALSE(auto_login_timer()->IsRunning());
662 profile_prepared_observer
.Wait();
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 PublicSessionLoginStopsAutoLogin
) {
674 // Set up mocks to check login success.
675 UserContext
user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
676 public_session_user_id_
);
677 user_context
.SetUserIDHash(user_context
.GetUserID());
678 ExpectSuccessfulLogin(user_context
);
679 existing_user_controller()->OnSigninScreenReady();
680 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
681 EXPECT_TRUE(auto_login_timer());
683 content::WindowedNotificationObserver
profile_prepared_observer(
684 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED
,
685 content::NotificationService::AllSources());
687 // Login and check that it stopped the timer.
688 existing_user_controller()->Login(
689 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT
,
690 public_session_user_id_
),
693 EXPECT_TRUE(is_login_in_progress());
694 ASSERT_TRUE(auto_login_timer());
695 EXPECT_FALSE(auto_login_timer()->IsRunning());
697 profile_prepared_observer
.Wait();
699 // Wait for login tasks to complete.
700 content::RunAllPendingInMessageLoop();
702 // Timer should still be stopped after login completes.
703 ASSERT_TRUE(auto_login_timer());
704 EXPECT_FALSE(auto_login_timer()->IsRunning());
707 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
708 LoginForbiddenWhenUntrusted
) {
709 // Make cros settings untrusted.
710 MakeCrosSettingsPermanentlyUntrusted();
712 // Check that the attempt to start a public session fails with an error.
713 ExpectLoginFailure();
714 UserContext
user_context(kUsername
);
715 user_context
.SetGaiaID(kGaiaID
);
716 user_context
.SetKey(Key(kPassword
));
717 user_context
.SetUserIDHash(user_context
.GetUserID());
718 existing_user_controller()->Login(user_context
, SigninSpecifics());
721 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
722 NoAutoLoginWhenUntrusted
) {
723 // Start the public session timer.
724 SetAutoLoginPolicy(kPublicSessionAccountId
, kAutoLoginLongDelay
);
725 existing_user_controller()->OnSigninScreenReady();
726 EXPECT_TRUE(auto_login_timer());
728 // Make cros settings untrusted.
729 MakeCrosSettingsPermanentlyUntrusted();
731 // Check that when the timer fires, auto-login fails with an error.
732 ExpectLoginFailure();
736 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
737 PRE_TestLoadingPublicUsersFromLocalState
) {
738 // First run propagates public accounts and stores them in Local State.
741 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest
,
742 TestLoadingPublicUsersFromLocalState
) {
743 // Second run loads list of public accounts from Local State.
746 } // namespace chromeos