Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1037)

Side by Side Diff: chrome/browser/chromeos/login/existing_user_controller_browsertest.cc

Issue 14927015: Translate device-local account IDs to user IDs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix forward declaration. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); 288 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest);
300 }; 289 };
301 290
302 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) { 291 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) {
303 // This is disabled twice: once right after signin but before checking for 292 // This is disabled twice: once right after signin but before checking for
304 // auto-enrollment, and again after doing an ownership status check. 293 // auto-enrollment, and again after doing an ownership status check.
305 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 294 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
306 .Times(2); 295 .Times(2);
307 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) 296 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
308 .Times(1) 297 .Times(1)
309 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator))); 298 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
310 EXPECT_CALL(*mock_login_utils_, 299 EXPECT_CALL(*mock_login_utils_,
311 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername), 300 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername),
312 _, _, _, _)) 301 _, _, _, _))
313 .Times(1) 302 .Times(1)
314 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 303 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
315 &base::Callback<void(void)>::Run)); 304 &base::Callback<void(void)>::Run));
316 EXPECT_CALL(*mock_login_utils_, 305 EXPECT_CALL(*mock_login_utils_,
317 DoBrowserLaunch(testing_profile_.get(), 306 DoBrowserLaunch(testing_profile_.get(),
318 mock_login_display_host_.get())) 307 mock_login_display_host_.get()))
319 .Times(1); 308 .Times(1);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 EXPECT_CALL(*mock_login_display_host_, 354 EXPECT_CALL(*mock_login_display_host_,
366 StartWizardPtr(WizardController::kEnrollmentScreenName, 355 StartWizardPtr(WizardController::kEnrollmentScreenName,
367 _)) 356 _))
368 .Times(0); 357 .Times(0);
369 EXPECT_CALL(*mock_login_display_host_, 358 EXPECT_CALL(*mock_login_display_host_,
370 StartWizardPtr(WizardController::kTermsOfServiceScreenName, 359 StartWizardPtr(WizardController::kTermsOfServiceScreenName,
371 NULL)) 360 NULL))
372 .Times(1); 361 .Times(1);
373 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) 362 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
374 .Times(1) 363 .Times(1)
375 .WillOnce(WithArg<0>(Invoke(CreateAuthenticatorNewUser))); 364 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword)));
376 EXPECT_CALL(*mock_login_utils_, 365 EXPECT_CALL(*mock_login_utils_,
377 PrepareProfile(UserContext(kNewUsername, 366 PrepareProfile(UserContext(kNewUsername,
378 kPassword, 367 kPassword,
379 std::string(), 368 std::string(),
380 kNewUsername), 369 kNewUsername),
381 _, _, _, _)) 370 _, _, _, _))
382 .Times(1) 371 .Times(1)
383 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 372 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
384 &base::Callback<void(void)>::Run)); 373 &base::Callback<void(void)>::Run));
385 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) 374 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername))
(...skipping 23 matching lines...) Expand all
409 content::RunAllPendingInMessageLoop(); 398 content::RunAllPendingInMessageLoop();
410 } 399 }
411 400
412 MATCHER_P(HasDetails, expected, "") { 401 MATCHER_P(HasDetails, expected, "") {
413 return expected == *content::Details<const std::string>(arg).ptr(); 402 return expected == *content::Details<const std::string>(arg).ptr();
414 } 403 }
415 404
416 class ExistingUserControllerPublicSessionTest 405 class ExistingUserControllerPublicSessionTest
417 : public ExistingUserControllerTest { 406 : public ExistingUserControllerTest {
418 protected: 407 protected:
419 ExistingUserControllerPublicSessionTest() { 408 ExistingUserControllerPublicSessionTest()
409 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId(
410 kPublicSessionAccountId,
411 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) {
420 } 412 }
421 413
422 virtual void SetUpOnMainThread() OVERRIDE { 414 virtual void SetUpOnMainThread() OVERRIDE {
423 ExistingUserControllerTest::SetUpOnMainThread(); 415 ExistingUserControllerTest::SetUpOnMainThread();
424 416
425 // Wait for the public session user to be created. 417 // Wait for the public session user to be created.
426 if (!chromeos::UserManager::Get()->IsKnownUser(kAutoLoginUsername)) { 418 if (!chromeos::UserManager::Get()->IsKnownUser(public_session_user_id_)) {
427 NotificationWatcher( 419 NotificationWatcher(
428 chrome::NOTIFICATION_USER_LIST_CHANGED, 420 chrome::NOTIFICATION_USER_LIST_CHANGED,
429 base::Bind(&chromeos::UserManager::IsKnownUser, 421 base::Bind(&chromeos::UserManager::IsKnownUser,
430 base::Unretained(chromeos::UserManager::Get()), 422 base::Unretained(chromeos::UserManager::Get()),
431 kAutoLoginUsername)).Run(); 423 public_session_user_id_)).Run();
432 } 424 }
433 425
434 // Wait for the device local account policy to be installed. 426 // Wait for the device local account policy to be installed.
435 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()-> 427 policy::CloudPolicyStore* store = TestingBrowserProcess::GetGlobal()->
436 browser_policy_connector()->GetDeviceLocalAccountPolicyService()-> 428 browser_policy_connector()->GetDeviceLocalAccountPolicyService()->
437 GetBrokerForAccount(kAutoLoginUsername)->core()->store(); 429 GetBrokerForUser(public_session_user_id_)->core()->store();
438 if (!store->has_policy()) { 430 if (!store->has_policy()) {
439 policy::MockCloudPolicyStoreObserver observer; 431 policy::MockCloudPolicyStoreObserver observer;
440 432
441 base::RunLoop loop; 433 base::RunLoop loop;
442 store->AddObserver(&observer); 434 store->AddObserver(&observer);
443 EXPECT_CALL(observer, OnStoreLoaded(store)) 435 EXPECT_CALL(observer, OnStoreLoaded(store))
444 .Times(1) 436 .Times(1)
445 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); 437 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit));
446 loop.Run(); 438 loop.Run();
447 store->RemoveObserver(&observer); 439 store->RemoveObserver(&observer);
448 } 440 }
449 } 441 }
450 442
451 virtual void SetUpSessionManager() OVERRIDE { 443 virtual void SetUpSessionManager() OVERRIDE {
452 InstallOwnerKey(); 444 InstallOwnerKey();
453 445
454 // Setup the device policy. 446 // Setup the device policy.
455 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); 447 em::ChromeDeviceSettingsProto& proto(device_policy()->payload());
456 em::DeviceLocalAccountInfoProto* account = 448 em::DeviceLocalAccountInfoProto* account =
457 proto.mutable_device_local_accounts()->add_account(); 449 proto.mutable_device_local_accounts()->add_account();
458 account->set_account_id(kAutoLoginUsername); 450 account->set_account_id(kPublicSessionAccountId);
459 account->set_type( 451 account->set_type(
460 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); 452 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION);
461 RefreshDevicePolicy(); 453 RefreshDevicePolicy();
462 454
463 // Setup the device local account policy. 455 // Setup the device local account policy.
464 policy::UserPolicyBuilder device_local_account_policy; 456 policy::UserPolicyBuilder device_local_account_policy;
465 device_local_account_policy.policy_data().set_username(kAutoLoginUsername); 457 device_local_account_policy.policy_data().set_username(
458 kPublicSessionAccountId);
466 device_local_account_policy.policy_data().set_policy_type( 459 device_local_account_policy.policy_data().set_policy_type(
467 policy::dm_protocol::kChromePublicAccountPolicyType); 460 policy::dm_protocol::kChromePublicAccountPolicyType);
468 device_local_account_policy.policy_data().set_settings_entity_id( 461 device_local_account_policy.policy_data().set_settings_entity_id(
469 kAutoLoginUsername); 462 kPublicSessionAccountId);
470 device_local_account_policy.Build(); 463 device_local_account_policy.Build();
471 session_manager_client()->set_device_local_account_policy( 464 session_manager_client()->set_device_local_account_policy(
472 kAutoLoginUsername, 465 kPublicSessionAccountId,
473 device_local_account_policy.GetBlob()); 466 device_local_account_policy.GetBlob());
474 } 467 }
475 468
476 virtual void SetUpLoginDisplay() OVERRIDE { 469 virtual void SetUpLoginDisplay() OVERRIDE {
477 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) 470 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_))
478 .Times(1) 471 .Times(1)
479 .WillOnce(Return(mock_login_display_)); 472 .WillOnce(Return(mock_login_display_));
480 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) 473 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow())
481 .Times(AnyNumber()) 474 .Times(AnyNumber())
482 .WillRepeatedly(ReturnNull()); 475 .WillRepeatedly(ReturnNull());
483 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) 476 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged())
484 .Times(AnyNumber()); 477 .Times(AnyNumber());
485 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) 478 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _))
486 .Times(AnyNumber()); 479 .Times(AnyNumber());
487 } 480 }
488 481
489 virtual void SetUpUserManager() OVERRIDE { 482 virtual void SetUpUserManager() OVERRIDE {
490 } 483 }
491 484
492 void ExpectSuccessfulLogin(const std::string& username, 485 void ExpectSuccessfulLogin(const std::string& username,
493 const std::string& password, 486 const std::string& password) {
494 scoped_refptr<Authenticator> create_authenticator(
495 LoginStatusConsumer* consumer)) {
496 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 487 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
497 .Times(AnyNumber()); 488 .Times(AnyNumber());
498 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) 489 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
499 .Times(1) 490 .Times(1)
500 .WillOnce(WithArg<0>(Invoke(create_authenticator))); 491 .WillOnce(WithArg<0>(CreateAuthenticator(username, password)));
501 EXPECT_CALL(*mock_login_utils_, 492 EXPECT_CALL(*mock_login_utils_,
502 PrepareProfile(UserContext(username, password, "", username), 493 PrepareProfile(UserContext(username, password, "", username),
503 _, _, _, _)) 494 _, _, _, _))
504 .Times(1) 495 .Times(1)
505 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, 496 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_,
506 &base::Callback<void(void)>::Run)); 497 &base::Callback<void(void)>::Run));
507 EXPECT_CALL(*mock_login_utils_, 498 EXPECT_CALL(*mock_login_utils_,
508 DoBrowserLaunch(testing_profile_.get(), 499 DoBrowserLaunch(testing_profile_.get(),
509 mock_login_display_host_.get())) 500 mock_login_display_host_.get()))
510 .Times(1); 501 .Times(1);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 } 568 }
578 569
579 void ConfigureAutoLogin() { 570 void ConfigureAutoLogin() {
580 existing_user_controller()->ConfigurePublicSessionAutoLogin(); 571 existing_user_controller()->ConfigurePublicSessionAutoLogin();
581 } 572 }
582 573
583 void FireAutoLogin() { 574 void FireAutoLogin() {
584 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); 575 existing_user_controller()->OnPublicSessionAutoLoginTimerFire();
585 } 576 }
586 577
578 const std::string public_session_user_id_;
579
587 private: 580 private:
588 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); 581 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest);
589 }; 582 };
590 583
591 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 584 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
592 ConfigureAutoLoginUsingPolicy) { 585 ConfigureAutoLoginUsingPolicy) {
593 existing_user_controller()->OnSigninScreenReady(); 586 existing_user_controller()->OnSigninScreenReady();
594 EXPECT_EQ("", auto_login_username()); 587 EXPECT_EQ("", auto_login_username());
595 EXPECT_EQ(0, auto_login_delay()); 588 EXPECT_EQ(0, auto_login_delay());
596 EXPECT_FALSE(auto_login_timer()); 589 EXPECT_FALSE(auto_login_timer());
597 590
598 // Set the policy. 591 // Set the policy.
599 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); 592 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
600 EXPECT_EQ(kAutoLoginUsername, auto_login_username()); 593 EXPECT_EQ(public_session_user_id_, auto_login_username());
601 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); 594 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay());
602 ASSERT_TRUE(auto_login_timer()); 595 ASSERT_TRUE(auto_login_timer());
603 EXPECT_TRUE(auto_login_timer()->IsRunning()); 596 EXPECT_TRUE(auto_login_timer()->IsRunning());
604 597
605 // Unset the policy. 598 // Unset the policy.
606 SetAutoLoginPolicy("", 0); 599 SetAutoLoginPolicy("", 0);
607 EXPECT_EQ("", auto_login_username()); 600 EXPECT_EQ("", auto_login_username());
608 EXPECT_EQ(0, auto_login_delay()); 601 EXPECT_EQ(0, auto_login_delay());
609 ASSERT_TRUE(auto_login_timer()); 602 ASSERT_TRUE(auto_login_timer());
610 EXPECT_FALSE(auto_login_timer()->IsRunning()); 603 EXPECT_FALSE(auto_login_timer()->IsRunning());
611 } 604 }
612 605
613 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 606 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
614 AutoLoginNoDelay) { 607 AutoLoginNoDelay) {
615 // Set up mocks to check login success. 608 // Set up mocks to check login success.
616 ExpectSuccessfulLogin(kAutoLoginUsername, "", 609 ExpectSuccessfulLogin(public_session_user_id_, "");
617 CreateAuthenticatorForPublicSession);
618 existing_user_controller()->OnSigninScreenReady(); 610 existing_user_controller()->OnSigninScreenReady();
619 611
620 // Start auto-login and wait for login tasks to complete. 612 // Start auto-login and wait for login tasks to complete.
621 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginNoDelay); 613 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginNoDelay);
622 content::RunAllPendingInMessageLoop(); 614 content::RunAllPendingInMessageLoop();
623 } 615 }
624 616
625 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 617 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
626 AutoLoginShortDelay) { 618 AutoLoginShortDelay) {
627 // Set up mocks to check login success. 619 // Set up mocks to check login success.
628 ExpectSuccessfulLogin(kAutoLoginUsername, "", 620 ExpectSuccessfulLogin(public_session_user_id_, "");
629 CreateAuthenticatorForPublicSession);
630 existing_user_controller()->OnSigninScreenReady(); 621 existing_user_controller()->OnSigninScreenReady();
631 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginShortDelay); 622 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay);
632 ASSERT_TRUE(auto_login_timer()); 623 ASSERT_TRUE(auto_login_timer());
633 // Don't assert that timer is running: with the short delay sometimes 624 // Don't assert that timer is running: with the short delay sometimes
634 // the trigger happens before the assert. We've already tested that 625 // the trigger happens before the assert. We've already tested that
635 // the timer starts when it should. 626 // the timer starts when it should.
636 627
637 // Wait for the timer to fire. 628 // Wait for the timer to fire.
638 base::RunLoop runner; 629 base::RunLoop runner;
639 base::OneShotTimer<base::RunLoop> timer; 630 base::OneShotTimer<base::RunLoop> timer;
640 timer.Start(FROM_HERE, 631 timer.Start(FROM_HERE,
641 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), 632 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1),
642 runner.QuitClosure()); 633 runner.QuitClosure());
643 runner.Run(); 634 runner.Run();
644 635
645 // Wait for login tasks to complete. 636 // Wait for login tasks to complete.
646 content::RunAllPendingInMessageLoop(); 637 content::RunAllPendingInMessageLoop();
647 } 638 }
648 639
649 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 640 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
650 LoginStopsAutoLogin) { 641 LoginStopsAutoLogin) {
651 // Set up mocks to check login success. 642 // Set up mocks to check login success.
652 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); 643 ExpectSuccessfulLogin(kUsername, kPassword);
653 644
654 existing_user_controller()->OnSigninScreenReady(); 645 existing_user_controller()->OnSigninScreenReady();
655 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); 646 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
656 ASSERT_TRUE(auto_login_timer()); 647 ASSERT_TRUE(auto_login_timer());
657 648
658 // Login and check that it stopped the timer. 649 // Login and check that it stopped the timer.
659 existing_user_controller()->Login(UserContext(kUsername, kPassword, "")); 650 existing_user_controller()->Login(UserContext(kUsername, kPassword, ""));
660 EXPECT_TRUE(is_login_in_progress()); 651 EXPECT_TRUE(is_login_in_progress());
661 ASSERT_TRUE(auto_login_timer()); 652 ASSERT_TRUE(auto_login_timer());
662 EXPECT_FALSE(auto_login_timer()->IsRunning()); 653 EXPECT_FALSE(auto_login_timer()->IsRunning());
663 654
664 // Wait for login tasks to complete. 655 // Wait for login tasks to complete.
665 content::RunAllPendingInMessageLoop(); 656 content::RunAllPendingInMessageLoop();
666 657
667 // Timer should still be stopped after login completes. 658 // Timer should still be stopped after login completes.
668 ASSERT_TRUE(auto_login_timer()); 659 ASSERT_TRUE(auto_login_timer());
669 EXPECT_FALSE(auto_login_timer()->IsRunning()); 660 EXPECT_FALSE(auto_login_timer()->IsRunning());
670 } 661 }
671 662
672 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 663 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
673 GuestModeLoginStopsAutoLogin) { 664 GuestModeLoginStopsAutoLogin) {
674 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) 665 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false))
675 .Times(1); 666 .Times(1);
676 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) 667 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_))
677 .Times(1) 668 .Times(1)
678 .WillOnce(WithArg<0>(Invoke(CreateAuthenticator))); 669 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword)));
679 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_)) 670 EXPECT_CALL(*mock_login_utils_, CompleteOffTheRecordLogin(_))
680 .Times(1); 671 .Times(1);
681 672
682 existing_user_controller()->OnSigninScreenReady(); 673 existing_user_controller()->OnSigninScreenReady();
683 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); 674 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
684 ASSERT_TRUE(auto_login_timer()); 675 ASSERT_TRUE(auto_login_timer());
685 676
686 // Login and check that it stopped the timer. 677 // Login and check that it stopped the timer.
687 existing_user_controller()->LoginAsGuest(); 678 existing_user_controller()->LoginAsGuest();
688 EXPECT_TRUE(is_login_in_progress()); 679 EXPECT_TRUE(is_login_in_progress());
689 ASSERT_TRUE(auto_login_timer()); 680 ASSERT_TRUE(auto_login_timer());
690 EXPECT_FALSE(auto_login_timer()->IsRunning()); 681 EXPECT_FALSE(auto_login_timer()->IsRunning());
691 682
692 // Wait for login tasks to complete. 683 // Wait for login tasks to complete.
693 content::RunAllPendingInMessageLoop(); 684 content::RunAllPendingInMessageLoop();
694 685
695 // Timer should still be stopped after login completes. 686 // Timer should still be stopped after login completes.
696 ASSERT_TRUE(auto_login_timer()); 687 ASSERT_TRUE(auto_login_timer());
697 EXPECT_FALSE(auto_login_timer()->IsRunning()); 688 EXPECT_FALSE(auto_login_timer()->IsRunning());
698 } 689 }
699 690
700 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 691 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
701 CompleteLoginStopsAutoLogin) { 692 CompleteLoginStopsAutoLogin) {
702 // Set up mocks to check login success. 693 // Set up mocks to check login success.
703 ExpectSuccessfulLogin(kUsername, kPassword, CreateAuthenticator); 694 ExpectSuccessfulLogin(kUsername, kPassword);
704 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) 695 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin())
705 .Times(1); 696 .Times(1);
706 697
707 existing_user_controller()->OnSigninScreenReady(); 698 existing_user_controller()->OnSigninScreenReady();
708 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); 699 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
709 ASSERT_TRUE(auto_login_timer()); 700 ASSERT_TRUE(auto_login_timer());
710 701
711 // Check that login completes and stops the timer. 702 // Check that login completes and stops the timer.
712 existing_user_controller()->CompleteLogin( 703 existing_user_controller()->CompleteLogin(
713 UserContext(kUsername, kPassword, "")); 704 UserContext(kUsername, kPassword, ""));
714 ASSERT_TRUE(auto_login_timer()); 705 ASSERT_TRUE(auto_login_timer());
715 EXPECT_FALSE(auto_login_timer()->IsRunning()); 706 EXPECT_FALSE(auto_login_timer()->IsRunning());
716 707
717 // Wait for login tasks to complete. 708 // Wait for login tasks to complete.
718 content::RunAllPendingInMessageLoop(); 709 content::RunAllPendingInMessageLoop();
719 710
720 // Timer should still be stopped after login completes. 711 // Timer should still be stopped after login completes.
721 ASSERT_TRUE(auto_login_timer()); 712 ASSERT_TRUE(auto_login_timer());
722 EXPECT_FALSE(auto_login_timer()->IsRunning()); 713 EXPECT_FALSE(auto_login_timer()->IsRunning());
723 } 714 }
724 715
725 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, 716 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest,
726 PublicSessionLoginStopsAutoLogin) { 717 PublicSessionLoginStopsAutoLogin) {
727 // Set up mocks to check login success. 718 // Set up mocks to check login success.
728 ExpectSuccessfulLogin(kAutoLoginUsername, "", 719 ExpectSuccessfulLogin(public_session_user_id_, "");
729 CreateAuthenticatorForPublicSession);
730 existing_user_controller()->OnSigninScreenReady(); 720 existing_user_controller()->OnSigninScreenReady();
731 SetAutoLoginPolicy(kAutoLoginUsername, kAutoLoginLongDelay); 721 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay);
732 ASSERT_TRUE(auto_login_timer()); 722 ASSERT_TRUE(auto_login_timer());
733 723
734 // Login and check that it stopped the timer. 724 // Login and check that it stopped the timer.
735 existing_user_controller()->LoginAsPublicAccount(kAutoLoginUsername); 725 existing_user_controller()->LoginAsPublicAccount(public_session_user_id_);
736 EXPECT_TRUE(is_login_in_progress()); 726 EXPECT_TRUE(is_login_in_progress());
737 ASSERT_TRUE(auto_login_timer()); 727 ASSERT_TRUE(auto_login_timer());
738 EXPECT_FALSE(auto_login_timer()->IsRunning()); 728 EXPECT_FALSE(auto_login_timer()->IsRunning());
739 729
740 // Wait for login tasks to complete. 730 // Wait for login tasks to complete.
741 content::RunAllPendingInMessageLoop(); 731 content::RunAllPendingInMessageLoop();
742 732
743 // Timer should still be stopped after login completes. 733 // Timer should still be stopped after login completes.
744 ASSERT_TRUE(auto_login_timer()); 734 ASSERT_TRUE(auto_login_timer());
745 EXPECT_FALSE(auto_login_timer()->IsRunning()); 735 EXPECT_FALSE(auto_login_timer()->IsRunning());
746 } 736 }
747 737
748 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation, 738 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation,
749 ExistingUserControllerTest, 739 ExistingUserControllerTest,
750 testing::Bool()); 740 testing::Bool());
751 741
752 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation, 742 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation,
753 ExistingUserControllerPublicSessionTest, 743 ExistingUserControllerPublicSessionTest,
754 testing::Bool()); 744 testing::Bool());
755 745
756 } // namespace chromeos 746 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698