OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/memory/ref_counted.h" | |
13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
14 #include "chrome/browser/chromeos/cros/cros_mock.h" | 13 #include "chrome/browser/chromeos/cros/cros_mock.h" |
15 #include "chrome/browser/chromeos/cros/mock_network_library.h" | 14 #include "chrome/browser/chromeos/cros/mock_network_library.h" |
16 #include "chrome/browser/chromeos/login/authenticator.h" | 15 #include "chrome/browser/chromeos/login/authenticator.h" |
17 #include "chrome/browser/chromeos/login/existing_user_controller.h" | 16 #include "chrome/browser/chromeos/login/existing_user_controller.h" |
18 #include "chrome/browser/chromeos/login/helper.h" | 17 #include "chrome/browser/chromeos/login/helper.h" |
19 #include "chrome/browser/chromeos/login/login_status_consumer.h" | |
20 #include "chrome/browser/chromeos/login/mock_authenticator.h" | 18 #include "chrome/browser/chromeos/login/mock_authenticator.h" |
21 #include "chrome/browser/chromeos/login/mock_login_display.h" | 19 #include "chrome/browser/chromeos/login/mock_login_display.h" |
22 #include "chrome/browser/chromeos/login/mock_login_display_host.h" | 20 #include "chrome/browser/chromeos/login/mock_login_display_host.h" |
23 #include "chrome/browser/chromeos/login/mock_login_utils.h" | 21 #include "chrome/browser/chromeos/login/mock_login_utils.h" |
24 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" | 22 #include "chrome/browser/chromeos/login/mock_url_fetchers.h" |
25 #include "chrome/browser/chromeos/login/mock_user_manager.h" | 23 #include "chrome/browser/chromeos/login/mock_user_manager.h" |
26 #include "chrome/browser/chromeos/login/user_manager.h" | 24 #include "chrome/browser/chromeos/login/user_manager.h" |
27 #include "chrome/browser/chromeos/login/wizard_controller.h" | 25 #include "chrome/browser/chromeos/login/wizard_controller.h" |
| 26 #include "chrome/browser/chromeos/policy/device_local_account.h" |
28 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" | 27 #include "chrome/browser/chromeos/policy/device_local_account_policy_service.h" |
29 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" | 28 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
30 #include "chrome/browser/chromeos/settings/cros_settings.h" | 29 #include "chrome/browser/chromeos/settings/cros_settings.h" |
31 #include "chrome/browser/chromeos/settings/cros_settings_names.h" | 30 #include "chrome/browser/chromeos/settings/cros_settings_names.h" |
32 #include "chrome/browser/policy/browser_policy_connector.h" | 31 #include "chrome/browser/policy/browser_policy_connector.h" |
33 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" | 32 #include "chrome/browser/policy/cloud/cloud_policy_constants.h" |
34 #include "chrome/browser/policy/cloud/cloud_policy_core.h" | 33 #include "chrome/browser/policy/cloud/cloud_policy_core.h" |
35 #include "chrome/browser/policy/cloud/cloud_policy_store.h" | 34 #include "chrome/browser/policy/cloud/cloud_policy_store.h" |
36 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" | 35 #include "chrome/browser/policy/cloud/mock_cloud_policy_store.h" |
37 #include "chrome/browser/policy/cloud/policy_builder.h" | 36 #include "chrome/browser/policy/cloud/policy_builder.h" |
(...skipping 25 matching lines...) Expand all Loading... |
63 namespace em = enterprise_management; | 62 namespace em = enterprise_management; |
64 | 63 |
65 namespace chromeos { | 64 namespace chromeos { |
66 | 65 |
67 namespace { | 66 namespace { |
68 | 67 |
69 const char kUsername[] = "test_user@gmail.com"; | 68 const char kUsername[] = "test_user@gmail.com"; |
70 const char kNewUsername[] = "test_new_user@gmail.com"; | 69 const char kNewUsername[] = "test_new_user@gmail.com"; |
71 const char kPassword[] = "test_password"; | 70 const char kPassword[] = "test_password"; |
72 | 71 |
73 const char kAutoLoginUsername[] = "public_session_user@localhost"; | 72 const char kPublicSessionAccountId[] = "public_session_user@localhost"; |
74 const int kAutoLoginNoDelay = 0; | 73 const int kAutoLoginNoDelay = 0; |
75 const int kAutoLoginShortDelay = 1; | 74 const int kAutoLoginShortDelay = 1; |
76 const int kAutoLoginLongDelay = 10000; | 75 const int kAutoLoginLongDelay = 10000; |
77 | 76 |
78 scoped_refptr<Authenticator> CreateAuthenticator( | |
79 LoginStatusConsumer* consumer) { | |
80 return new MockAuthenticator(consumer, kUsername, kPassword); | |
81 } | |
82 | 77 |
83 scoped_refptr<Authenticator> CreateAuthenticatorNewUser( | 78 ACTION_P2(CreateAuthenticator, username, password) { |
84 LoginStatusConsumer* consumer) { | 79 return new MockAuthenticator(arg0, username, password); |
85 return new MockAuthenticator(consumer, kNewUsername, kPassword); | |
86 } | |
87 | |
88 scoped_refptr<Authenticator> CreateAuthenticatorForPublicSession( | |
89 LoginStatusConsumer* consumer) { | |
90 return new MockAuthenticator(consumer, kAutoLoginUsername, ""); | |
91 } | 80 } |
92 | 81 |
93 // Observes a specific notification type and quits the message loop once a | 82 // Observes a specific notification type and quits the message loop once a |
94 // condition holds. | 83 // condition holds. |
95 class NotificationWatcher : public content::NotificationObserver { | 84 class NotificationWatcher : public content::NotificationObserver { |
96 public: | 85 public: |
97 // Callback invoked on notifications. Should return true when the condition | 86 // Callback invoked on notifications. Should return true when the condition |
98 // that the caller is waiting for is satisfied. | 87 // that the caller is waiting for is satisfied. |
99 typedef base::Callback<bool(void)> ConditionTestCallback; | 88 typedef base::Callback<bool(void)> ConditionTestCallback; |
100 | 89 |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); | 285 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); |
297 }; | 286 }; |
298 | 287 |
299 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { | 288 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { |
300 // This is disabled twice: once right after signin but before checking for | 289 // This is disabled twice: once right after signin but before checking for |
301 // auto-enrollment, and again after doing an ownership status check. | 290 // auto-enrollment, and again after doing an ownership status check. |
302 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 291 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
303 .Times(2); | 292 .Times(2); |
304 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 293 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
305 .Times(1) | 294 .Times(1) |
306 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator))); | 295 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword))); |
307 EXPECT_CALL(*mock_login_utils_, | 296 EXPECT_CALL(*mock_login_utils_, |
308 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername), | 297 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername), |
309 _, _, _, _)) | 298 _, _, _, _)) |
310 .Times(1) | 299 .Times(1) |
311 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 300 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
312 &base::Callback<void(void)>::Run)); | 301 &base::Callback<void(void)>::Run)); |
313 EXPECT_CALL(*mock_login_utils_, | 302 EXPECT_CALL(*mock_login_utils_, |
314 DoBrowserLaunch(testing_profile_.get(), | 303 DoBrowserLaunch(testing_profile_.get(), |
315 mock_login_display_host_.get())) | 304 mock_login_display_host_.get())) |
316 .Times(1); | 305 .Times(1); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 EXPECT_CALL(*mock_login_display_host_, | 351 EXPECT_CALL(*mock_login_display_host_, |
363 StartWizardPtr(WizardController::kEnrollmentScreenName, | 352 StartWizardPtr(WizardController::kEnrollmentScreenName, |
364 _)) | 353 _)) |
365 .Times(0); | 354 .Times(0); |
366 EXPECT_CALL(*mock_login_display_host_, | 355 EXPECT_CALL(*mock_login_display_host_, |
367 StartWizardPtr(WizardController::kTermsOfServiceScreenName, | 356 StartWizardPtr(WizardController::kTermsOfServiceScreenName, |
368 NULL)) | 357 NULL)) |
369 .Times(1); | 358 .Times(1); |
370 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 359 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
371 .Times(1) | 360 .Times(1) |
372 .WillOnce(WithArg<0>(Invoke(CreateAuthenticatorNewUser))); | 361 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword))); |
373 EXPECT_CALL(*mock_login_utils_, | 362 EXPECT_CALL(*mock_login_utils_, |
374 PrepareProfile(UserContext(kNewUsername, | 363 PrepareProfile(UserContext(kNewUsername, |
375 kPassword, | 364 kPassword, |
376 std::string(), | 365 std::string(), |
377 kNewUsername), | 366 kNewUsername), |
378 _, _, _, _)) | 367 _, _, _, _)) |
379 .Times(1) | 368 .Times(1) |
380 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 369 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
381 &base::Callback<void(void)>::Run)); | 370 &base::Callback<void(void)>::Run)); |
382 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) | 371 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) |
(...skipping 23 matching lines...) Expand all Loading... |
406 content::RunAllPendingInMessageLoop(); | 395 content::RunAllPendingInMessageLoop(); |
407 } | 396 } |
408 | 397 |
409 MATCHER_P(HasDetails, expected, "") { | 398 MATCHER_P(HasDetails, expected, "") { |
410 return expected == *content::Details<const std::string>(arg).ptr(); | 399 return expected == *content::Details<const std::string>(arg).ptr(); |
411 } | 400 } |
412 | 401 |
413 class ExistingUserControllerPublicSessionTest | 402 class ExistingUserControllerPublicSessionTest |
414 : public ExistingUserControllerTest { | 403 : public ExistingUserControllerTest { |
415 protected: | 404 protected: |
416 ExistingUserControllerPublicSessionTest() { | 405 ExistingUserControllerPublicSessionTest() |
| 406 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId( |
| 407 kPublicSessionAccountId, |
| 408 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) { |
417 } | 409 } |
418 | 410 |
419 virtual void SetUpOnMainThread() OVERRIDE { | 411 virtual void SetUpOnMainThread() OVERRIDE { |
420 ExistingUserControllerTest::SetUpOnMainThread(); | 412 ExistingUserControllerTest::SetUpOnMainThread(); |
421 | 413 |
422 // Wait for the public session user to be created. | 414 // Wait for the public session user to be created. |
423 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { | 415 if (!chromeos::UserManager::Get()->IsKnownUser(public_session_user_id_)) { |
424 NotificationWatcher( | 416 NotificationWatcher( |
425 chrome::NOTIFICATION_USER_LIST_CHANGED, | 417 chrome::NOTIFICATION_USER_LIST_CHANGED, |
426 base::Bind(&chromeos::UserManager::IsKnownUser, | 418 base::Bind(&chromeos::UserManager::IsKnownUser, |
427 base::Unretained(chromeos::UserManager::Get()), | 419 base::Unretained(chromeos::UserManager::Get()), |
428 kAutoLoginUsername)).Run(); | 420 public_session_user_id_)).Run(); |
429 } | 421 } |
430 | 422 |
431 // Wait for the device local account policy to be installed. | 423 // Wait for the device local account policy to be installed. |
432 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> | 424 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> |
433 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> | 425 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> |
434 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); | 426 GetBrokerForUser(public_session_user_id_)->core()->store(); |
435 if (!store->has_policy()) { | 427 if (!store->has_policy()) { |
436 policy::MockCloudPolicyStoreObserver observer; | 428 policy::MockCloudPolicyStoreObserver observer; |
437 | 429 |
438 base::RunLoop loop; | 430 base::RunLoop loop; |
439 store->AddObserver(&observer); | 431 store->AddObserver(&observer); |
440 EXPECT_CALL(observer, OnStoreLoaded(store)) | 432 EXPECT_CALL(observer, OnStoreLoaded(store)) |
441 .Times(1) | 433 .Times(1) |
442 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); | 434 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); |
443 loop.Run(); | 435 loop.Run(); |
444 store->RemoveObserver(&observer); | 436 store->RemoveObserver(&observer); |
445 } | 437 } |
446 } | 438 } |
447 | 439 |
448 virtual void SetUpSessionManager() OVERRIDE { | 440 virtual void SetUpSessionManager() OVERRIDE { |
449 InstallOwnerKey(); | 441 InstallOwnerKey(); |
450 | 442 |
451 // Setup the device policy. | 443 // Setup the device policy. |
452 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 444 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
453 em::DeviceLocalAccountInfoProto* account = | 445 em::DeviceLocalAccountInfoProto* account = |
454 proto.mutable_device_local_accounts()->add_account(); | 446 proto.mutable_device_local_accounts()->add_account(); |
455 account->set_account_id(kAutoLoginUsername); | 447 account->set_account_id(kPublicSessionAccountId); |
456 account->set_type( | 448 account->set_type( |
457 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); | 449 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); |
458 RefreshDevicePolicy(); | 450 RefreshDevicePolicy(); |
459 | 451 |
460 // Setup the device local account policy. | 452 // Setup the device local account policy. |
461 policy::UserPolicyBuilder device_local_account_policy; | 453 policy::UserPolicyBuilder device_local_account_policy; |
462 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); | 454 device_local_account_policy.policy_data().set_username( |
| 455 kPublicSessionAccountId); |
463 device_local_account_policy.policy_data().set_policy_type( | 456 device_local_account_policy.policy_data().set_policy_type( |
464 policy::dm_protocol::kChromePublicAccountPolicyType); | 457 policy::dm_protocol::kChromePublicAccountPolicyType); |
465 device_local_account_policy.policy_data().set_settings_entity_id( | 458 device_local_account_policy.policy_data().set_settings_entity_id( |
466 kAutoLoginUsername); | 459 kPublicSessionAccountId); |
467 device_local_account_policy.Build(); | 460 device_local_account_policy.Build(); |
468 session_manager_client()->set_device_local_account_policy( | 461 session_manager_client()->set_device_local_account_policy( |
469 kAutoLoginUsername, | 462 kPublicSessionAccountId, |
470 device_local_account_policy.GetBlob()); | 463 device_local_account_policy.GetBlob()); |
471 } | 464 } |
472 | 465 |
473 virtual void SetUpLoginDisplay() OVERRIDE { | 466 virtual void SetUpLoginDisplay() OVERRIDE { |
474 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 467 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
475 .Times(1) | 468 .Times(1) |
476 .WillOnce(Return(mock_login_display_)); | 469 .WillOnce(Return(mock_login_display_)); |
477 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 470 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
478 .Times(AnyNumber()) | 471 .Times(AnyNumber()) |
479 .WillRepeatedly(ReturnNull()); | 472 .WillRepeatedly(ReturnNull()); |
480 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 473 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
481 .Times(AnyNumber()); | 474 .Times(AnyNumber()); |
482 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) | 475 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) |
483 .Times(AnyNumber()); | 476 .Times(AnyNumber()); |
484 } | 477 } |
485 | 478 |
486 virtual void SetUpUserManager() OVERRIDE { | 479 virtual void SetUpUserManager() OVERRIDE { |
487 } | 480 } |
488 | 481 |
489 void ExpectSuccessfulLogin(const std::string& username, | 482 void ExpectSuccessfulLogin(const std::string& username, |
490 const std::string& password, | 483 const std::string& password) { |
491 scoped_refptr<Authenticator> create_authenticator( | |
492 LoginStatusConsumer* consumer)) { | |
493 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 484 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
494 .Times(AnyNumber()); | 485 .Times(AnyNumber()); |
495 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 486 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
496 .Times(1) | 487 .Times(1) |
497 .WillOnce(WithArg<0>(Invoke(create_authenticator))); | 488 .WillOnce(WithArg<0>(CreateAuthenticator(username, password))); |
498 EXPECT_CALL(*mock_login_utils_, | 489 EXPECT_CALL(*mock_login_utils_, |
499 PrepareProfile(UserContext(username, password, "", username), | 490 PrepareProfile(UserContext(username, password, "", username), |
500 _, _, _, _)) | 491 _, _, _, _)) |
501 .Times(1) | 492 .Times(1) |
502 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 493 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
503 &base::Callback<void(void)>::Run)); | 494 &base::Callback<void(void)>::Run)); |
504 EXPECT_CALL(*mock_login_utils_, | 495 EXPECT_CALL(*mock_login_utils_, |
505 DoBrowserLaunch(testing_profile_.get(), | 496 DoBrowserLaunch(testing_profile_.get(), |
506 mock_login_display_host_.get())) | 497 mock_login_display_host_.get())) |
507 .Times(1); | 498 .Times(1); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 565 } |
575 | 566 |
576 void ConfigureAutoLogin() { | 567 void ConfigureAutoLogin() { |
577 existing_user_controller()->ConfigurePublicSessionAutoLogin(); | 568 existing_user_controller()->ConfigurePublicSessionAutoLogin(); |
578 } | 569 } |
579 | 570 |
580 void FireAutoLogin() { | 571 void FireAutoLogin() { |
581 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); | 572 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); |
582 } | 573 } |
583 | 574 |
| 575 const std::string public_session_user_id_; |
| 576 |
584 private: | 577 private: |
585 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); | 578 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); |
586 }; | 579 }; |
587 | 580 |
588 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 581 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
589 ConfigureAutoLoginUsingPolicy) { | 582 ConfigureAutoLoginUsingPolicy) { |
590 existing_user_controller()->OnSigninScreenReady(); | 583 existing_user_controller()->OnSigninScreenReady(); |
591 EXPECT_EQ("", auto_login_username()); | 584 EXPECT_EQ("", auto_login_username()); |
592 EXPECT_EQ(0, auto_login_delay()); | 585 EXPECT_EQ(0, auto_login_delay()); |
593 EXPECT_FALSE(auto_login_timer()); | 586 EXPECT_FALSE(auto_login_timer()); |
594 | 587 |
595 // Set the policy. | 588 // Set the policy. |
596 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); | 589 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
597 EXPECT_EQ(kAutoLoginUsername, auto_login_username()); | 590 EXPECT_EQ(public_session_user_id_, auto_login_username()); |
598 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); | 591 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); |
599 ASSERT_TRUE(auto_login_timer()); | 592 ASSERT_TRUE(auto_login_timer()); |
600 EXPECT_TRUE(auto_login_timer()->IsRunning()); | 593 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
601 | 594 |
602 // Unset the policy. | 595 // Unset the policy. |
603 SetAutoLoginPolicy("", 0); | 596 SetAutoLoginPolicy("", 0); |
604 EXPECT_EQ("", auto_login_username()); | 597 EXPECT_EQ("", auto_login_username()); |
605 EXPECT_EQ(0, auto_login_delay()); | 598 EXPECT_EQ(0, auto_login_delay()); |
606 ASSERT_TRUE(auto_login_timer()); | 599 ASSERT_TRUE(auto_login_timer()); |
607 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 600 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
608 } | 601 } |
609 | 602 |
610 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 603 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
611 AutoLoginNoDelay) { | 604 AutoLoginNoDelay) { |
612 // Set up mocks to check login success. | 605 // Set up mocks to check login success. |
613 ExpectSuccessfulLogin(kAutoLoginUsername, "", | 606 ExpectSuccessfulLogin(public_session_user_id_, ""); |
614 CreateAuthenticatorForPublicSession); | |
615 existing_user_controller()->OnSigninScreenReady(); | 607 existing_user_controller()->OnSigninScreenReady(); |
616 | 608 |
617 // Start auto-login and wait for login tasks to complete. | 609 // Start auto-login and wait for login tasks to complete. |
618 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay); | 610 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginNoDelay); |
619 content::RunAllPendingInMessageLoop(); | 611 content::RunAllPendingInMessageLoop(); |
620 } | 612 } |
621 | 613 |
622 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 614 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
623 AutoLoginShortDelay) { | 615 AutoLoginShortDelay) { |
624 // Set up mocks to check login success. | 616 // Set up mocks to check login success. |
625 ExpectSuccessfulLogin(kAutoLoginUsername, "", | 617 ExpectSuccessfulLogin(public_session_user_id_, ""); |
626 CreateAuthenticatorForPublicSession); | |
627 existing_user_controller()->OnSigninScreenReady(); | 618 existing_user_controller()->OnSigninScreenReady(); |
628 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay); | 619 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay); |
629 ASSERT_TRUE(auto_login_timer()); | 620 ASSERT_TRUE(auto_login_timer()); |
630 // Don't assert that timer is running: with the short delay sometimes | 621 // Don't assert that timer is running: with the short delay sometimes |
631 // the trigger happens before the assert. We've already tested that | 622 // the trigger happens before the assert. We've already tested that |
632 // the timer starts when it should. | 623 // the timer starts when it should. |
633 | 624 |
634 // Wait for the timer to fire. | 625 // Wait for the timer to fire. |
635 base::RunLoop runner; | 626 base::RunLoop runner; |
636 base::OneShotTimer<base::RunLoop> timer; | 627 base::OneShotTimer<base::RunLoop> timer; |
637 timer.Start(FROM_HERE, | 628 timer.Start(FROM_HERE, |
638 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), | 629 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), |
639 runner.QuitClosure()); | 630 runner.QuitClosure()); |
640 runner.Run(); | 631 runner.Run(); |
641 | 632 |
642 // Wait for login tasks to complete. | 633 // Wait for login tasks to complete. |
643 content::RunAllPendingInMessageLoop(); | 634 content::RunAllPendingInMessageLoop(); |
644 } | 635 } |
645 | 636 |
646 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 637 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
647 LoginStopsAutoLogin) { | 638 LoginStopsAutoLogin) { |
648 // Set up mocks to check login success. | 639 // Set up mocks to check login success. |
649 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); | 640 ExpectSuccessfulLogin(kUsername, kPassword); |
650 | 641 |
651 existing_user_controller()->OnSigninScreenReady(); | 642 existing_user_controller()->OnSigninScreenReady(); |
652 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); | 643 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
653 ASSERT_TRUE(auto_login_timer()); | 644 ASSERT_TRUE(auto_login_timer()); |
654 | 645 |
655 // Login and check that it stopped the timer. | 646 // Login and check that it stopped the timer. |
656 existing_user_controller()->Login(UserContext(kUsername, kPassword, "")); | 647 existing_user_controller()->Login(UserContext(kUsername, kPassword, "")); |
657 EXPECT_TRUE(is_login_in_progress()); | 648 EXPECT_TRUE(is_login_in_progress()); |
658 ASSERT_TRUE(auto_login_timer()); | 649 ASSERT_TRUE(auto_login_timer()); |
659 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 650 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
660 | 651 |
661 // Wait for login tasks to complete. | 652 // Wait for login tasks to complete. |
662 content::RunAllPendingInMessageLoop(); | 653 content::RunAllPendingInMessageLoop(); |
663 | 654 |
664 // Timer should still be stopped after login completes. | 655 // Timer should still be stopped after login completes. |
665 ASSERT_TRUE(auto_login_timer()); | 656 ASSERT_TRUE(auto_login_timer()); |
666 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 657 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
667 } | 658 } |
668 | 659 |
669 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 660 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
670 GuestModeLoginStopsAutoLogin) { | 661 GuestModeLoginStopsAutoLogin) { |
671 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 662 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
672 .Times(1); | 663 .Times(1); |
673 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 664 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
674 .Times(1) | 665 .Times(1) |
675 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator))); | 666 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword))); |
676 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_)) | 667 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_)) |
677 .Times(1); | 668 .Times(1); |
678 | 669 |
679 existing_user_controller()->OnSigninScreenReady(); | 670 existing_user_controller()->OnSigninScreenReady(); |
680 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); | 671 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
681 ASSERT_TRUE(auto_login_timer()); | 672 ASSERT_TRUE(auto_login_timer()); |
682 | 673 |
683 // Login and check that it stopped the timer. | 674 // Login and check that it stopped the timer. |
684 existing_user_controller()->LoginAsGuest(); | 675 existing_user_controller()->LoginAsGuest(); |
685 EXPECT_TRUE(is_login_in_progress()); | 676 EXPECT_TRUE(is_login_in_progress()); |
686 ASSERT_TRUE(auto_login_timer()); | 677 ASSERT_TRUE(auto_login_timer()); |
687 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 678 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
688 | 679 |
689 // Wait for login tasks to complete. | 680 // Wait for login tasks to complete. |
690 content::RunAllPendingInMessageLoop(); | 681 content::RunAllPendingInMessageLoop(); |
691 | 682 |
692 // Timer should still be stopped after login completes. | 683 // Timer should still be stopped after login completes. |
693 ASSERT_TRUE(auto_login_timer()); | 684 ASSERT_TRUE(auto_login_timer()); |
694 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 685 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
695 } | 686 } |
696 | 687 |
697 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 688 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
698 CompleteLoginStopsAutoLogin) { | 689 CompleteLoginStopsAutoLogin) { |
699 // Set up mocks to check login success. | 690 // Set up mocks to check login success. |
700 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); | 691 ExpectSuccessfulLogin(kUsername, kPassword); |
701 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) | 692 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) |
702 .Times(1); | 693 .Times(1); |
703 | 694 |
704 existing_user_controller()->OnSigninScreenReady(); | 695 existing_user_controller()->OnSigninScreenReady(); |
705 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); | 696 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
706 ASSERT_TRUE(auto_login_timer()); | 697 ASSERT_TRUE(auto_login_timer()); |
707 | 698 |
708 // Check that login completes and stops the timer. | 699 // Check that login completes and stops the timer. |
709 existing_user_controller()->CompleteLogin( | 700 existing_user_controller()->CompleteLogin( |
710 UserContext(kUsername, kPassword, "")); | 701 UserContext(kUsername, kPassword, "")); |
711 ASSERT_TRUE(auto_login_timer()); | 702 ASSERT_TRUE(auto_login_timer()); |
712 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 703 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
713 | 704 |
714 // Wait for login tasks to complete. | 705 // Wait for login tasks to complete. |
715 content::RunAllPendingInMessageLoop(); | 706 content::RunAllPendingInMessageLoop(); |
716 | 707 |
717 // Timer should still be stopped after login completes. | 708 // Timer should still be stopped after login completes. |
718 ASSERT_TRUE(auto_login_timer()); | 709 ASSERT_TRUE(auto_login_timer()); |
719 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 710 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
720 } | 711 } |
721 | 712 |
722 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 713 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
723 PublicSessionLoginStopsAutoLogin) { | 714 PublicSessionLoginStopsAutoLogin) { |
724 // Set up mocks to check login success. | 715 // Set up mocks to check login success. |
725 ExpectSuccessfulLogin(kAutoLoginUsername, "", | 716 ExpectSuccessfulLogin(public_session_user_id_, ""); |
726 CreateAuthenticatorForPublicSession); | |
727 existing_user_controller()->OnSigninScreenReady(); | 717 existing_user_controller()->OnSigninScreenReady(); |
728 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); | 718 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
729 ASSERT_TRUE(auto_login_timer()); | 719 ASSERT_TRUE(auto_login_timer()); |
730 | 720 |
731 // Login and check that it stopped the timer. | 721 // Login and check that it stopped the timer. |
732 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername); | 722 existing_user_controller()->LoginAsPublicAccount(public_session_user_id_); |
733 EXPECT_TRUE(is_login_in_progress()); | 723 EXPECT_TRUE(is_login_in_progress()); |
734 ASSERT_TRUE(auto_login_timer()); | 724 ASSERT_TRUE(auto_login_timer()); |
735 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 725 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
736 | 726 |
737 // Wait for login tasks to complete. | 727 // Wait for login tasks to complete. |
738 content::RunAllPendingInMessageLoop(); | 728 content::RunAllPendingInMessageLoop(); |
739 | 729 |
740 // Timer should still be stopped after login completes. | 730 // Timer should still be stopped after login completes. |
741 ASSERT_TRUE(auto_login_timer()); | 731 ASSERT_TRUE(auto_login_timer()); |
742 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 732 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
743 } | 733 } |
744 | 734 |
745 } // namespace chromeos | 735 } // namespace chromeos |
OLD | NEW |