| 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" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 : mock_login_display_(NULL), mock_user_manager_(NULL) {} | 87 : mock_login_display_(NULL), mock_user_manager_(NULL) {} |
| 88 | 88 |
| 89 ExistingUserController* existing_user_controller() { | 89 ExistingUserController* existing_user_controller() { |
| 90 return ExistingUserController::current_controller(); | 90 return ExistingUserController::current_controller(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 const ExistingUserController* existing_user_controller() const { | 93 const ExistingUserController* existing_user_controller() const { |
| 94 return ExistingUserController::current_controller(); | 94 return ExistingUserController::current_controller(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE { | 97 virtual void SetUpInProcessBrowserTestFixture() override { |
| 98 SetUpSessionManager(); | 98 SetUpSessionManager(); |
| 99 | 99 |
| 100 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); | 100 DevicePolicyCrosBrowserTest::SetUpInProcessBrowserTestFixture(); |
| 101 | 101 |
| 102 mock_login_utils_ = new MockLoginUtils(); | 102 mock_login_utils_ = new MockLoginUtils(); |
| 103 LoginUtils::Set(mock_login_utils_); | 103 LoginUtils::Set(mock_login_utils_); |
| 104 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) | 104 EXPECT_CALL(*mock_login_utils_, DelegateDeleted(_)) |
| 105 .Times(1); | 105 .Times(1); |
| 106 | 106 |
| 107 mock_login_display_host_.reset(new MockLoginDisplayHost()); | 107 mock_login_display_host_.reset(new MockLoginDisplayHost()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 118 .WillOnce(Return(mock_login_display_)); | 118 .WillOnce(Return(mock_login_display_)); |
| 119 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 119 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 120 .Times(1) | 120 .Times(1) |
| 121 .WillOnce(ReturnNull()); | 121 .WillOnce(ReturnNull()); |
| 122 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 122 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
| 123 .Times(1); | 123 .Times(1); |
| 124 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) | 124 EXPECT_CALL(*mock_login_display_, Init(_, false, true, true)) |
| 125 .Times(1); | 125 .Times(1); |
| 126 } | 126 } |
| 127 | 127 |
| 128 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 128 virtual void SetUpCommandLine(CommandLine* command_line) override { |
| 129 command_line->AppendSwitch(switches::kLoginManager); | 129 command_line->AppendSwitch(switches::kLoginManager); |
| 130 } | 130 } |
| 131 | 131 |
| 132 virtual void SetUpUserManager() { | 132 virtual void SetUpUserManager() { |
| 133 // Replace the UserManager singleton with a mock. | 133 // Replace the UserManager singleton with a mock. |
| 134 mock_user_manager_ = new MockUserManager; | 134 mock_user_manager_ = new MockUserManager; |
| 135 user_manager_enabler_.reset( | 135 user_manager_enabler_.reset( |
| 136 new ScopedUserManagerEnabler(mock_user_manager_)); | 136 new ScopedUserManagerEnabler(mock_user_manager_)); |
| 137 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kUsername)) | 137 EXPECT_CALL(*mock_user_manager_, IsKnownUser(kUsername)) |
| 138 .Times(AnyNumber()) | 138 .Times(AnyNumber()) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 155 EXPECT_CALL(*mock_user_manager_, IsSessionStarted()) | 155 EXPECT_CALL(*mock_user_manager_, IsSessionStarted()) |
| 156 .Times(AnyNumber()) | 156 .Times(AnyNumber()) |
| 157 .WillRepeatedly(Return(false)); | 157 .WillRepeatedly(Return(false)); |
| 158 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) | 158 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) |
| 159 .Times(AnyNumber()) | 159 .Times(AnyNumber()) |
| 160 .WillRepeatedly(Return(false)); | 160 .WillRepeatedly(Return(false)); |
| 161 EXPECT_CALL(*mock_user_manager_, Shutdown()) | 161 EXPECT_CALL(*mock_user_manager_, Shutdown()) |
| 162 .Times(1); | 162 .Times(1); |
| 163 } | 163 } |
| 164 | 164 |
| 165 virtual void SetUpOnMainThread() OVERRIDE { | 165 virtual void SetUpOnMainThread() override { |
| 166 testing_profile_.reset(new TestingProfile()); | 166 testing_profile_.reset(new TestingProfile()); |
| 167 SetUpUserManager(); | 167 SetUpUserManager(); |
| 168 existing_user_controller_.reset( | 168 existing_user_controller_.reset( |
| 169 new ExistingUserController(mock_login_display_host_.get())); | 169 new ExistingUserController(mock_login_display_host_.get())); |
| 170 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); | 170 ASSERT_EQ(existing_user_controller(), existing_user_controller_.get()); |
| 171 existing_user_controller_->Init(user_manager::UserList()); | 171 existing_user_controller_->Init(user_manager::UserList()); |
| 172 profile_prepared_cb_ = | 172 profile_prepared_cb_ = |
| 173 base::Bind(&ExistingUserController::OnProfilePrepared, | 173 base::Bind(&ExistingUserController::OnProfilePrepared, |
| 174 base::Unretained(existing_user_controller()), | 174 base::Unretained(existing_user_controller()), |
| 175 testing_profile_.get()); | 175 testing_profile_.get()); |
| 176 } | 176 } |
| 177 | 177 |
| 178 virtual void TearDownOnMainThread() OVERRIDE { | 178 virtual void TearDownOnMainThread() override { |
| 179 // ExistingUserController must be deleted before the thread is cleaned up: | 179 // ExistingUserController must be deleted before the thread is cleaned up: |
| 180 // If there is an outstanding login attempt when ExistingUserController is | 180 // If there is an outstanding login attempt when ExistingUserController is |
| 181 // deleted, its LoginPerformer instance will be deleted, which in turn | 181 // deleted, its LoginPerformer instance will be deleted, which in turn |
| 182 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must | 182 // deletes its OnlineAttemptHost instance. However, OnlineAttemptHost must |
| 183 // be deleted on the UI thread. | 183 // be deleted on the UI thread. |
| 184 existing_user_controller_.reset(); | 184 existing_user_controller_.reset(); |
| 185 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread(); | 185 DevicePolicyCrosBrowserTest::InProcessBrowserTest::TearDownOnMainThread(); |
| 186 testing_profile_.reset(NULL); | 186 testing_profile_.reset(NULL); |
| 187 user_manager_enabler_.reset(); | 187 user_manager_enabler_.reset(); |
| 188 } | 188 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 | 340 |
| 341 class ExistingUserControllerPublicSessionTest | 341 class ExistingUserControllerPublicSessionTest |
| 342 : public ExistingUserControllerTest { | 342 : public ExistingUserControllerTest { |
| 343 protected: | 343 protected: |
| 344 ExistingUserControllerPublicSessionTest() | 344 ExistingUserControllerPublicSessionTest() |
| 345 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId( | 345 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId( |
| 346 kPublicSessionAccountId, | 346 kPublicSessionAccountId, |
| 347 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) { | 347 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) { |
| 348 } | 348 } |
| 349 | 349 |
| 350 virtual void SetUpOnMainThread() OVERRIDE { | 350 virtual void SetUpOnMainThread() override { |
| 351 ExistingUserControllerTest::SetUpOnMainThread(); | 351 ExistingUserControllerTest::SetUpOnMainThread(); |
| 352 | 352 |
| 353 // Wait for the public session user to be created. | 353 // Wait for the public session user to be created. |
| 354 if (!user_manager::UserManager::Get()->IsKnownUser( | 354 if (!user_manager::UserManager::Get()->IsKnownUser( |
| 355 public_session_user_id_)) { | 355 public_session_user_id_)) { |
| 356 content::WindowedNotificationObserver( | 356 content::WindowedNotificationObserver( |
| 357 chrome::NOTIFICATION_USER_LIST_CHANGED, | 357 chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 358 base::Bind(&user_manager::UserManager::IsKnownUser, | 358 base::Bind(&user_manager::UserManager::IsKnownUser, |
| 359 base::Unretained(user_manager::UserManager::Get()), | 359 base::Unretained(user_manager::UserManager::Get()), |
| 360 public_session_user_id_)).Wait(); | 360 public_session_user_id_)).Wait(); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 375 base::RunLoop loop; | 375 base::RunLoop loop; |
| 376 store->AddObserver(&observer); | 376 store->AddObserver(&observer); |
| 377 EXPECT_CALL(observer, OnStoreLoaded(store)) | 377 EXPECT_CALL(observer, OnStoreLoaded(store)) |
| 378 .Times(1) | 378 .Times(1) |
| 379 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); | 379 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); |
| 380 loop.Run(); | 380 loop.Run(); |
| 381 store->RemoveObserver(&observer); | 381 store->RemoveObserver(&observer); |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 virtual void SetUpSessionManager() OVERRIDE { | 385 virtual void SetUpSessionManager() override { |
| 386 InstallOwnerKey(); | 386 InstallOwnerKey(); |
| 387 | 387 |
| 388 // Setup the device policy. | 388 // Setup the device policy. |
| 389 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 389 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 390 em::DeviceLocalAccountInfoProto* account = | 390 em::DeviceLocalAccountInfoProto* account = |
| 391 proto.mutable_device_local_accounts()->add_account(); | 391 proto.mutable_device_local_accounts()->add_account(); |
| 392 account->set_account_id(kPublicSessionAccountId); | 392 account->set_account_id(kPublicSessionAccountId); |
| 393 account->set_type( | 393 account->set_type( |
| 394 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); | 394 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); |
| 395 RefreshDevicePolicy(); | 395 RefreshDevicePolicy(); |
| 396 | 396 |
| 397 // Setup the device local account policy. | 397 // Setup the device local account policy. |
| 398 policy::UserPolicyBuilder device_local_account_policy; | 398 policy::UserPolicyBuilder device_local_account_policy; |
| 399 device_local_account_policy.policy_data().set_username( | 399 device_local_account_policy.policy_data().set_username( |
| 400 kPublicSessionAccountId); | 400 kPublicSessionAccountId); |
| 401 device_local_account_policy.policy_data().set_policy_type( | 401 device_local_account_policy.policy_data().set_policy_type( |
| 402 policy::dm_protocol::kChromePublicAccountPolicyType); | 402 policy::dm_protocol::kChromePublicAccountPolicyType); |
| 403 device_local_account_policy.policy_data().set_settings_entity_id( | 403 device_local_account_policy.policy_data().set_settings_entity_id( |
| 404 kPublicSessionAccountId); | 404 kPublicSessionAccountId); |
| 405 device_local_account_policy.Build(); | 405 device_local_account_policy.Build(); |
| 406 session_manager_client()->set_device_local_account_policy( | 406 session_manager_client()->set_device_local_account_policy( |
| 407 kPublicSessionAccountId, | 407 kPublicSessionAccountId, |
| 408 device_local_account_policy.GetBlob()); | 408 device_local_account_policy.GetBlob()); |
| 409 } | 409 } |
| 410 | 410 |
| 411 virtual void SetUpLoginDisplay() OVERRIDE { | 411 virtual void SetUpLoginDisplay() override { |
| 412 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 412 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 413 .Times(1) | 413 .Times(1) |
| 414 .WillOnce(Return(mock_login_display_)); | 414 .WillOnce(Return(mock_login_display_)); |
| 415 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 415 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 416 .Times(AnyNumber()) | 416 .Times(AnyNumber()) |
| 417 .WillRepeatedly(ReturnNull()); | 417 .WillRepeatedly(ReturnNull()); |
| 418 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) | 418 EXPECT_CALL(*mock_login_display_host_.get(), OnPreferencesChanged()) |
| 419 .Times(AnyNumber()); | 419 .Times(AnyNumber()); |
| 420 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) | 420 EXPECT_CALL(*mock_login_display_, Init(_, _, _, _)) |
| 421 .Times(AnyNumber()); | 421 .Times(AnyNumber()); |
| 422 } | 422 } |
| 423 | 423 |
| 424 virtual void SetUpUserManager() OVERRIDE { | 424 virtual void SetUpUserManager() override { |
| 425 } | 425 } |
| 426 | 426 |
| 427 void ExpectSuccessfulLogin(const UserContext& user_context) { | 427 void ExpectSuccessfulLogin(const UserContext& user_context) { |
| 428 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 428 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 429 .Times(AnyNumber()); | 429 .Times(AnyNumber()); |
| 430 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 430 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
| 431 .Times(1) | 431 .Times(1) |
| 432 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); | 432 .WillOnce(WithArg<0>(CreateAuthenticator(user_context))); |
| 433 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) | 433 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _)) |
| 434 .Times(1) | 434 .Times(1) |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 680 // First run propagates public accounts and stores them in Local State. | 680 // First run propagates public accounts and stores them in Local State. |
| 681 } | 681 } |
| 682 | 682 |
| 683 // See http://crbug.com/393704; flaky. | 683 // See http://crbug.com/393704; flaky. |
| 684 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 684 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 685 DISABLED_TestLoadingPublicUsersFromLocalState) { | 685 DISABLED_TestLoadingPublicUsersFromLocalState) { |
| 686 // Second run loads list of public accounts from Local State. | 686 // Second run loads list of public accounts from Local State. |
| 687 } | 687 } |
| 688 | 688 |
| 689 } // namespace chromeos | 689 } // namespace chromeos |
| OLD | NEW |