| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 69 |
| 70 namespace chromeos { | 70 namespace chromeos { |
| 71 | 71 |
| 72 namespace { | 72 namespace { |
| 73 | 73 |
| 74 const char kGaiaID[] = "12345"; | 74 const char kGaiaID[] = "12345"; |
| 75 const char kUsername[] = "test_user@gmail.com"; | 75 const char kUsername[] = "test_user@gmail.com"; |
| 76 const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost"; | 76 const char kSupervisedUserID[] = "supervised_user@locally-managed.localhost"; |
| 77 const char kPassword[] = "test_password"; | 77 const char kPassword[] = "test_password"; |
| 78 | 78 |
| 79 const char kPublicSessionAccountId[] = "public_session_user@localhost"; | 79 const char kPublicSessionUserEmail[] = "public_session_user@localhost"; |
| 80 const int kAutoLoginNoDelay = 0; | 80 const int kAutoLoginNoDelay = 0; |
| 81 const int kAutoLoginShortDelay = 1; | 81 const int kAutoLoginShortDelay = 1; |
| 82 const int kAutoLoginLongDelay = 10000; | 82 const int kAutoLoginLongDelay = 10000; |
| 83 | 83 |
| 84 // Wait for cros settings to become permanently untrusted and run |callback|. | 84 // Wait for cros settings to become permanently untrusted and run |callback|. |
| 85 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) { | 85 void WaitForPermanentlyUntrustedStatusAndRun(const base::Closure& callback) { |
| 86 while (true) { | 86 while (true) { |
| 87 const CrosSettingsProvider::TrustedStatus status = | 87 const CrosSettingsProvider::TrustedStatus status = |
| 88 CrosSettings::Get()->PrepareTrustedValues(base::Bind( | 88 CrosSettings::Get()->PrepareTrustedValues(base::Bind( |
| 89 &WaitForPermanentlyUntrustedStatusAndRun, | 89 &WaitForPermanentlyUntrustedStatusAndRun, |
| 90 callback)); | 90 callback)); |
| 91 switch (status) { | 91 switch (status) { |
| 92 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED: | 92 case CrosSettingsProvider::PERMANENTLY_UNTRUSTED: |
| 93 callback.Run(); | 93 callback.Run(); |
| 94 return; | 94 return; |
| 95 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED: | 95 case CrosSettingsProvider::TEMPORARILY_UNTRUSTED: |
| 96 return; | 96 return; |
| 97 case CrosSettingsProvider::TRUSTED: | 97 case CrosSettingsProvider::TRUSTED: |
| 98 content::RunAllPendingInMessageLoop(); | 98 content::RunAllPendingInMessageLoop(); |
| 99 break; | 99 break; |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace | 104 } // namespace |
| 105 | 105 |
| 106 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { | 106 class ExistingUserControllerTest : public policy::DevicePolicyCrosBrowserTest { |
| 107 protected: | 107 protected: |
| 108 ExistingUserControllerTest() : mock_login_display_(NULL) {} | 108 ExistingUserControllerTest() {} |
| 109 | 109 |
| 110 ExistingUserController* existing_user_controller() { | 110 ExistingUserController* existing_user_controller() { |
| 111 return ExistingUserController::current_controller(); | 111 return ExistingUserController::current_controller(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 const ExistingUserController* existing_user_controller() const { | 114 const ExistingUserController* existing_user_controller() const { |
| 115 return ExistingUserController::current_controller(); | 115 return ExistingUserController::current_controller(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void SetUpInProcessBrowserTestFixture() override { | 118 void SetUpInProcessBrowserTestFixture() override { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 ListPrefUpdate users_pref(g_browser_process->local_state(), | 189 ListPrefUpdate users_pref(g_browser_process->local_state(), |
| 190 "LoggedInUsers"); | 190 "LoggedInUsers"); |
| 191 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); | 191 users_pref->AppendIfNotPresent(new base::StringValue(user_id)); |
| 192 } | 192 } |
| 193 | 193 |
| 194 // ExistingUserController private member accessors. | 194 // ExistingUserController private member accessors. |
| 195 base::OneShotTimer* auto_login_timer() { | 195 base::OneShotTimer* auto_login_timer() { |
| 196 return existing_user_controller()->auto_login_timer_.get(); | 196 return existing_user_controller()->auto_login_timer_.get(); |
| 197 } | 197 } |
| 198 | 198 |
| 199 const std::string& auto_login_username() const { | 199 AccountId auto_login_account_id() const { |
| 200 return existing_user_controller()->public_session_auto_login_username_; | 200 return AccountId::FromUserEmail( |
| 201 existing_user_controller()->public_session_auto_login_username_); |
| 201 } | 202 } |
| 202 | 203 |
| 203 int auto_login_delay() const { | 204 int auto_login_delay() const { |
| 204 return existing_user_controller()->public_session_auto_login_delay_; | 205 return existing_user_controller()->public_session_auto_login_delay_; |
| 205 } | 206 } |
| 206 | 207 |
| 207 bool is_login_in_progress() const { | 208 bool is_login_in_progress() const { |
| 208 return existing_user_controller()->is_login_in_progress_; | 209 return existing_user_controller()->is_login_in_progress_; |
| 209 } | 210 } |
| 210 | 211 |
| 211 scoped_ptr<ExistingUserController> existing_user_controller_; | 212 scoped_ptr<ExistingUserController> existing_user_controller_; |
| 212 | 213 |
| 213 // |mock_login_display_| is owned by the ExistingUserController, which calls | 214 // |mock_login_display_| is owned by the ExistingUserController, which calls |
| 214 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. | 215 // CreateLoginDisplay() on the |mock_login_display_host_| to get it. |
| 215 MockLoginDisplay* mock_login_display_; | 216 MockLoginDisplay* mock_login_display_ = nullptr; |
| 216 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; | 217 scoped_ptr<MockLoginDisplayHost> mock_login_display_host_; |
| 217 | 218 |
| 218 // Mock URLFetcher. | 219 // Mock URLFetcher. |
| 219 MockURLFetcherFactory<SuccessFetcher> factory_; | 220 MockURLFetcherFactory<SuccessFetcher> factory_; |
| 220 | 221 |
| 222 const AccountId account_id_ = AccountId::FromUserEmail(kUsername); |
| 223 |
| 221 private: | 224 private: |
| 222 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); | 225 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerTest); |
| 223 }; | 226 }; |
| 224 | 227 |
| 225 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, PRE_ExistingUserLogin) { | 228 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, PRE_ExistingUserLogin) { |
| 226 RegisterUser(kUsername); | 229 RegisterUser(account_id_.GetUserEmail()); |
| 227 } | 230 } |
| 228 | 231 |
| 229 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { | 232 IN_PROC_BROWSER_TEST_F(ExistingUserControllerTest, ExistingUserLogin) { |
| 230 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 233 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 231 .Times(2); | 234 .Times(2); |
| 232 UserContext user_context(kUsername); | 235 UserContext user_context(account_id_); |
| 233 user_context.SetGaiaID(kGaiaID); | 236 user_context.SetGaiaID(kGaiaID); |
| 234 user_context.SetKey(Key(kPassword)); | 237 user_context.SetKey(Key(kPassword)); |
| 235 user_context.SetUserIDHash(kUsername); | 238 user_context.SetUserIDHash(account_id_.GetUserEmail()); |
| 236 test::UserSessionManagerTestApi session_manager_test_api( | 239 test::UserSessionManagerTestApi session_manager_test_api( |
| 237 UserSessionManager::GetInstance()); | 240 UserSessionManager::GetInstance()); |
| 238 session_manager_test_api.InjectStubUserContext(user_context); | 241 session_manager_test_api.InjectStubUserContext(user_context); |
| 239 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 242 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
| 240 .Times(1); | 243 .Times(1); |
| 241 EXPECT_CALL(*mock_login_display_host_, | 244 EXPECT_CALL(*mock_login_display_host_, |
| 242 StartWizard(WizardController::kTermsOfServiceScreenName)) | 245 StartWizard(WizardController::kTermsOfServiceScreenName)) |
| 243 .Times(0); | 246 .Times(0); |
| 244 | 247 |
| 245 content::WindowedNotificationObserver profile_prepared_observer( | 248 content::WindowedNotificationObserver profile_prepared_observer( |
| (...skipping 27 matching lines...) Expand all Loading... |
| 273 | 276 |
| 274 ExpectLoginFailure(); | 277 ExpectLoginFailure(); |
| 275 } | 278 } |
| 276 | 279 |
| 277 void ExistingUserControllerUntrustedTest::SetUpSessionManager() { | 280 void ExistingUserControllerUntrustedTest::SetUpSessionManager() { |
| 278 InstallOwnerKey(); | 281 InstallOwnerKey(); |
| 279 } | 282 } |
| 280 | 283 |
| 281 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, | 284 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, |
| 282 ExistingUserLoginForbidden) { | 285 ExistingUserLoginForbidden) { |
| 283 UserContext user_context(kUsername); | 286 UserContext user_context(account_id_); |
| 284 user_context.SetGaiaID(kGaiaID); | 287 user_context.SetGaiaID(kGaiaID); |
| 285 user_context.SetKey(Key(kPassword)); | 288 user_context.SetKey(Key(kPassword)); |
| 286 user_context.SetUserIDHash(kUsername); | 289 user_context.SetUserIDHash(account_id_.GetUserEmail()); |
| 287 existing_user_controller()->Login(user_context, SigninSpecifics()); | 290 existing_user_controller()->Login(user_context, SigninSpecifics()); |
| 288 } | 291 } |
| 289 | 292 |
| 290 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, | 293 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, |
| 291 NewUserLoginForbidden) { | 294 NewUserLoginForbidden) { |
| 292 UserContext user_context(kUsername); | 295 UserContext user_context(account_id_); |
| 293 user_context.SetGaiaID(kGaiaID); | 296 user_context.SetGaiaID(kGaiaID); |
| 294 user_context.SetKey(Key(kPassword)); | 297 user_context.SetKey(Key(kPassword)); |
| 295 user_context.SetUserIDHash(kUsername); | 298 user_context.SetUserIDHash(account_id_.GetUserEmail()); |
| 296 existing_user_controller()->CompleteLogin(user_context); | 299 existing_user_controller()->CompleteLogin(user_context); |
| 297 } | 300 } |
| 298 | 301 |
| 299 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, | 302 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, |
| 300 GuestLoginForbidden) { | 303 GuestLoginForbidden) { |
| 301 existing_user_controller()->Login( | 304 existing_user_controller()->Login( |
| 302 UserContext(user_manager::USER_TYPE_GUEST, std::string()), | 305 UserContext(user_manager::USER_TYPE_GUEST, std::string()), |
| 303 SigninSpecifics()); | 306 SigninSpecifics()); |
| 304 } | 307 } |
| 305 | 308 |
| 306 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, | 309 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, |
| 307 SupervisedUserLoginForbidden) { | 310 SupervisedUserLoginForbidden) { |
| 308 UserContext user_context(kSupervisedUserID); | 311 UserContext user_context(AccountId::FromUserEmail(kSupervisedUserID)); |
| 309 user_context.SetKey(Key(kPassword)); | 312 user_context.SetKey(Key(kPassword)); |
| 310 user_context.SetUserIDHash(kUsername); | 313 user_context.SetUserIDHash(account_id_.GetUserEmail()); |
| 311 existing_user_controller()->Login(user_context, SigninSpecifics()); | 314 existing_user_controller()->Login(user_context, SigninSpecifics()); |
| 312 } | 315 } |
| 313 | 316 |
| 314 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, | 317 IN_PROC_BROWSER_TEST_F(ExistingUserControllerUntrustedTest, |
| 315 SupervisedUserCreationForbidden) { | 318 SupervisedUserCreationForbidden) { |
| 316 MockBaseScreenDelegate mock_base_screen_delegate; | 319 MockBaseScreenDelegate mock_base_screen_delegate; |
| 317 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler; | 320 SupervisedUserCreationScreenHandler supervised_user_creation_screen_handler; |
| 318 SupervisedUserCreationScreen supervised_user_creation_screen( | 321 SupervisedUserCreationScreen supervised_user_creation_screen( |
| 319 &mock_base_screen_delegate, &supervised_user_creation_screen_handler); | 322 &mock_base_screen_delegate, &supervised_user_creation_screen_handler); |
| 320 | 323 |
| 321 supervised_user_creation_screen.AuthenticateManager(kUsername, kPassword); | 324 supervised_user_creation_screen.AuthenticateManager( |
| 325 account_id_.GetUserEmail(), kPassword); |
| 322 } | 326 } |
| 323 | 327 |
| 324 MATCHER_P(HasDetails, expected, "") { | 328 MATCHER_P(HasDetails, expected, "") { |
| 325 return expected == *content::Details<const std::string>(arg).ptr(); | 329 return expected == *content::Details<const std::string>(arg).ptr(); |
| 326 } | 330 } |
| 327 | 331 |
| 328 class ExistingUserControllerPublicSessionTest | 332 class ExistingUserControllerPublicSessionTest |
| 329 : public ExistingUserControllerTest { | 333 : public ExistingUserControllerTest { |
| 330 protected: | 334 protected: |
| 331 ExistingUserControllerPublicSessionTest() | 335 ExistingUserControllerPublicSessionTest() {} |
| 332 : public_session_user_id_(policy::GenerateDeviceLocalAccountUserId( | |
| 333 kPublicSessionAccountId, | |
| 334 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)) { | |
| 335 } | |
| 336 | 336 |
| 337 void SetUpOnMainThread() override { | 337 void SetUpOnMainThread() override { |
| 338 ExistingUserControllerTest::SetUpOnMainThread(); | 338 ExistingUserControllerTest::SetUpOnMainThread(); |
| 339 | 339 |
| 340 // Wait for the public session user to be created. | 340 // Wait for the public session user to be created. |
| 341 if (!user_manager::UserManager::Get()->IsKnownUser( | 341 if (!user_manager::UserManager::Get()->IsKnownUser( |
| 342 public_session_user_id_)) { | 342 public_session_account_id_)) { |
| 343 content::WindowedNotificationObserver( | 343 content::WindowedNotificationObserver( |
| 344 chrome::NOTIFICATION_USER_LIST_CHANGED, | 344 chrome::NOTIFICATION_USER_LIST_CHANGED, |
| 345 base::Bind(&user_manager::UserManager::IsKnownUser, | 345 base::Bind(&user_manager::UserManager::IsKnownUser, |
| 346 base::Unretained(user_manager::UserManager::Get()), | 346 base::Unretained(user_manager::UserManager::Get()), |
| 347 public_session_user_id_)).Wait(); | 347 public_session_account_id_)) |
| 348 .Wait(); |
| 348 } | 349 } |
| 349 | 350 |
| 350 // Wait for the device local account policy to be installed. | 351 // Wait for the device local account policy to be installed. |
| 351 policy::CloudPolicyStore* store = | 352 policy::CloudPolicyStore* store = |
| 352 TestingBrowserProcess::GetGlobal() | 353 TestingBrowserProcess::GetGlobal() |
| 353 ->platform_part() | 354 ->platform_part() |
| 354 ->browser_policy_connector_chromeos() | 355 ->browser_policy_connector_chromeos() |
| 355 ->GetDeviceLocalAccountPolicyService() | 356 ->GetDeviceLocalAccountPolicyService() |
| 356 ->GetBrokerForUser(public_session_user_id_) | 357 ->GetBrokerForUser(public_session_account_id_.GetUserEmail()) |
| 357 ->core() | 358 ->core() |
| 358 ->store(); | 359 ->store(); |
| 359 if (!store->has_policy()) { | 360 if (!store->has_policy()) { |
| 360 policy::MockCloudPolicyStoreObserver observer; | 361 policy::MockCloudPolicyStoreObserver observer; |
| 361 | 362 |
| 362 base::RunLoop loop; | 363 base::RunLoop loop; |
| 363 store->AddObserver(&observer); | 364 store->AddObserver(&observer); |
| 364 EXPECT_CALL(observer, OnStoreLoaded(store)) | 365 EXPECT_CALL(observer, OnStoreLoaded(store)) |
| 365 .Times(1) | 366 .Times(1) |
| 366 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); | 367 .WillOnce(InvokeWithoutArgs(&loop, &base::RunLoop::Quit)); |
| 367 loop.Run(); | 368 loop.Run(); |
| 368 store->RemoveObserver(&observer); | 369 store->RemoveObserver(&observer); |
| 369 } | 370 } |
| 370 } | 371 } |
| 371 | 372 |
| 372 void SetUpSessionManager() override { | 373 void SetUpSessionManager() override { |
| 373 InstallOwnerKey(); | 374 InstallOwnerKey(); |
| 374 | 375 |
| 375 // Setup the device policy. | 376 // Setup the device policy. |
| 376 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 377 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 377 em::DeviceLocalAccountInfoProto* account = | 378 em::DeviceLocalAccountInfoProto* account = |
| 378 proto.mutable_device_local_accounts()->add_account(); | 379 proto.mutable_device_local_accounts()->add_account(); |
| 379 account->set_account_id(kPublicSessionAccountId); | 380 account->set_account_id(public_session_account_id_.GetUserEmail()); |
| 380 account->set_type( | 381 account->set_type( |
| 381 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); | 382 em::DeviceLocalAccountInfoProto::ACCOUNT_TYPE_PUBLIC_SESSION); |
| 382 RefreshDevicePolicy(); | 383 RefreshDevicePolicy(); |
| 383 | 384 |
| 384 // Setup the device local account policy. | 385 // Setup the device local account policy. |
| 385 policy::UserPolicyBuilder device_local_account_policy; | 386 policy::UserPolicyBuilder device_local_account_policy; |
| 386 device_local_account_policy.policy_data().set_username( | 387 device_local_account_policy.policy_data().set_username( |
| 387 kPublicSessionAccountId); | 388 public_session_account_id_.GetUserEmail()); |
| 388 device_local_account_policy.policy_data().set_policy_type( | 389 device_local_account_policy.policy_data().set_policy_type( |
| 389 policy::dm_protocol::kChromePublicAccountPolicyType); | 390 policy::dm_protocol::kChromePublicAccountPolicyType); |
| 390 device_local_account_policy.policy_data().set_settings_entity_id( | 391 device_local_account_policy.policy_data().set_settings_entity_id( |
| 391 kPublicSessionAccountId); | 392 public_session_account_id_.GetUserEmail()); |
| 392 device_local_account_policy.Build(); | 393 device_local_account_policy.Build(); |
| 393 session_manager_client()->set_device_local_account_policy( | 394 session_manager_client()->set_device_local_account_policy( |
| 394 kPublicSessionAccountId, | 395 public_session_account_id_.GetUserEmail(), |
| 395 device_local_account_policy.GetBlob()); | 396 device_local_account_policy.GetBlob()); |
| 396 } | 397 } |
| 397 | 398 |
| 398 void SetUpLoginDisplay() override { | 399 void SetUpLoginDisplay() override { |
| 399 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) | 400 EXPECT_CALL(*mock_login_display_host_.get(), CreateLoginDisplay(_)) |
| 400 .Times(1) | 401 .Times(1) |
| 401 .WillOnce(Return(mock_login_display_)); | 402 .WillOnce(Return(mock_login_display_)); |
| 402 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) | 403 EXPECT_CALL(*mock_login_display_host_.get(), GetNativeWindow()) |
| 403 .Times(AnyNumber()) | 404 .Times(AnyNumber()) |
| 404 .WillRepeatedly(ReturnNull()); | 405 .WillRepeatedly(ReturnNull()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 424 test::UserSessionManagerTestApi session_manager_test_api( | 425 test::UserSessionManagerTestApi session_manager_test_api( |
| 425 UserSessionManager::GetInstance()); | 426 UserSessionManager::GetInstance()); |
| 426 session_manager_test_api.InjectStubUserContext(user_context); | 427 session_manager_test_api.InjectStubUserContext(user_context); |
| 427 EXPECT_CALL(*mock_login_display_host_, | 428 EXPECT_CALL(*mock_login_display_host_, |
| 428 StartWizard(WizardController::kTermsOfServiceScreenName)) | 429 StartWizard(WizardController::kTermsOfServiceScreenName)) |
| 429 .Times(0); | 430 .Times(0); |
| 430 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)).Times(AnyNumber()); | 431 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)).Times(AnyNumber()); |
| 431 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)).Times(AnyNumber()); | 432 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)).Times(AnyNumber()); |
| 432 } | 433 } |
| 433 | 434 |
| 434 void SetAutoLoginPolicy(const std::string& username, int delay) { | 435 void SetAutoLoginPolicy(const AccountId& account_id, int delay) { |
| 435 // Wait until ExistingUserController has finished auto-login | 436 // Wait until ExistingUserController has finished auto-login |
| 436 // configuration by observing the same settings that trigger | 437 // configuration by observing the same settings that trigger |
| 437 // ConfigurePublicSessionAutoLogin. | 438 // ConfigurePublicSessionAutoLogin. |
| 438 | 439 |
| 439 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); | 440 em::ChromeDeviceSettingsProto& proto(device_policy()->payload()); |
| 440 | 441 |
| 441 // If both settings have changed we need to wait for both to | 442 // If both settings have changed we need to wait for both to |
| 442 // propagate, so check the new values against the old ones. | 443 // propagate, so check the new values against the old ones. |
| 443 scoped_refptr<content::MessageLoopRunner> runner1; | 444 scoped_refptr<content::MessageLoopRunner> runner1; |
| 444 scoped_ptr<CrosSettings::ObserverSubscription> subscription1; | 445 scoped_ptr<CrosSettings::ObserverSubscription> subscription1; |
| 445 if (!proto.has_device_local_accounts() || | 446 if (!proto.has_device_local_accounts() || |
| 446 !proto.device_local_accounts().has_auto_login_id() || | 447 !proto.device_local_accounts().has_auto_login_id() || |
| 447 proto.device_local_accounts().auto_login_id() != username) { | 448 proto.device_local_accounts().auto_login_id() != |
| 449 account_id.GetUserEmail()) { |
| 448 runner1 = new content::MessageLoopRunner; | 450 runner1 = new content::MessageLoopRunner; |
| 449 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver( | 451 subscription1 = chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 450 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId, | 452 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginId, |
| 451 runner1->QuitClosure()); | 453 runner1->QuitClosure()); |
| 452 } | 454 } |
| 453 scoped_refptr<content::MessageLoopRunner> runner2; | 455 scoped_refptr<content::MessageLoopRunner> runner2; |
| 454 scoped_ptr<CrosSettings::ObserverSubscription> subscription2; | 456 scoped_ptr<CrosSettings::ObserverSubscription> subscription2; |
| 455 if (!proto.has_device_local_accounts() || | 457 if (!proto.has_device_local_accounts() || |
| 456 !proto.device_local_accounts().has_auto_login_delay() || | 458 !proto.device_local_accounts().has_auto_login_delay() || |
| 457 proto.device_local_accounts().auto_login_delay() != delay) { | 459 proto.device_local_accounts().auto_login_delay() != delay) { |
| 458 runner2 = new content::MessageLoopRunner; | 460 runner2 = new content::MessageLoopRunner; |
| 459 subscription2 = chromeos::CrosSettings::Get()->AddSettingsObserver( | 461 subscription2 = chromeos::CrosSettings::Get()->AddSettingsObserver( |
| 460 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay, | 462 chromeos::kAccountsPrefDeviceLocalAccountAutoLoginDelay, |
| 461 runner2->QuitClosure()); | 463 runner2->QuitClosure()); |
| 462 } | 464 } |
| 463 | 465 |
| 464 // Update the policy. | 466 // Update the policy. |
| 465 proto.mutable_device_local_accounts()->set_auto_login_id(username); | 467 proto.mutable_device_local_accounts()->set_auto_login_id( |
| 468 account_id.GetUserEmail()); |
| 466 proto.mutable_device_local_accounts()->set_auto_login_delay(delay); | 469 proto.mutable_device_local_accounts()->set_auto_login_delay(delay); |
| 467 RefreshDevicePolicy(); | 470 RefreshDevicePolicy(); |
| 468 | 471 |
| 469 // Wait for ExistingUserController to read the updated settings. | 472 // Wait for ExistingUserController to read the updated settings. |
| 470 if (runner1.get()) | 473 if (runner1.get()) |
| 471 runner1->Run(); | 474 runner1->Run(); |
| 472 if (runner2.get()) | 475 if (runner2.get()) |
| 473 runner2->Run(); | 476 runner2->Run(); |
| 474 } | 477 } |
| 475 | 478 |
| 476 void ConfigureAutoLogin() { | 479 void ConfigureAutoLogin() { |
| 477 existing_user_controller()->ConfigurePublicSessionAutoLogin(); | 480 existing_user_controller()->ConfigurePublicSessionAutoLogin(); |
| 478 } | 481 } |
| 479 | 482 |
| 480 void FireAutoLogin() { | 483 void FireAutoLogin() { |
| 481 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); | 484 existing_user_controller()->OnPublicSessionAutoLoginTimerFire(); |
| 482 } | 485 } |
| 483 | 486 |
| 484 void MakeCrosSettingsPermanentlyUntrusted() { | 487 void MakeCrosSettingsPermanentlyUntrusted() { |
| 485 device_policy()->policy().set_policy_data_signature("bad signature"); | 488 device_policy()->policy().set_policy_data_signature("bad signature"); |
| 486 session_manager_client()->set_device_policy(device_policy()->GetBlob()); | 489 session_manager_client()->set_device_policy(device_policy()->GetBlob()); |
| 487 session_manager_client()->OnPropertyChangeComplete(true); | 490 session_manager_client()->OnPropertyChangeComplete(true); |
| 488 | 491 |
| 489 base::RunLoop run_loop; | 492 base::RunLoop run_loop; |
| 490 WaitForPermanentlyUntrustedStatusAndRun(run_loop.QuitClosure()); | 493 WaitForPermanentlyUntrustedStatusAndRun(run_loop.QuitClosure()); |
| 491 run_loop.Run(); | 494 run_loop.Run(); |
| 492 } | 495 } |
| 493 | 496 |
| 494 const std::string public_session_user_id_; | 497 const AccountId public_session_account_id_ = |
| 498 AccountId::FromUserEmail(policy::GenerateDeviceLocalAccountUserId( |
| 499 kPublicSessionUserEmail, |
| 500 policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION)); |
| 495 | 501 |
| 496 private: | 502 private: |
| 497 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); | 503 DISALLOW_COPY_AND_ASSIGN(ExistingUserControllerPublicSessionTest); |
| 498 }; | 504 }; |
| 499 | 505 |
| 500 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 506 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 501 ConfigureAutoLoginUsingPolicy) { | 507 ConfigureAutoLoginUsingPolicy) { |
| 502 existing_user_controller()->OnSigninScreenReady(); | 508 existing_user_controller()->OnSigninScreenReady(); |
| 503 EXPECT_EQ("", auto_login_username()); | 509 EXPECT_TRUE(!auto_login_account_id().is_valid()); |
| 504 EXPECT_EQ(0, auto_login_delay()); | 510 EXPECT_EQ(0, auto_login_delay()); |
| 505 EXPECT_FALSE(auto_login_timer()); | 511 EXPECT_FALSE(auto_login_timer()); |
| 506 | 512 |
| 507 // Set the policy. | 513 // Set the policy. |
| 508 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 514 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginLongDelay); |
| 509 EXPECT_EQ(public_session_user_id_, auto_login_username()); | 515 EXPECT_EQ(public_session_account_id_, auto_login_account_id()); |
| 510 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); | 516 EXPECT_EQ(kAutoLoginLongDelay, auto_login_delay()); |
| 511 ASSERT_TRUE(auto_login_timer()); | 517 ASSERT_TRUE(auto_login_timer()); |
| 512 EXPECT_TRUE(auto_login_timer()->IsRunning()); | 518 EXPECT_TRUE(auto_login_timer()->IsRunning()); |
| 513 | 519 |
| 514 // Unset the policy. | 520 // Unset the policy. |
| 515 SetAutoLoginPolicy("", 0); | 521 SetAutoLoginPolicy(EmptyAccountId(), 0); |
| 516 EXPECT_EQ("", auto_login_username()); | 522 EXPECT_TRUE(!auto_login_account_id().is_valid()); |
| 517 EXPECT_EQ(0, auto_login_delay()); | 523 EXPECT_EQ(0, auto_login_delay()); |
| 518 ASSERT_TRUE(auto_login_timer()); | 524 ASSERT_TRUE(auto_login_timer()); |
| 519 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 525 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 520 } | 526 } |
| 521 | 527 |
| 522 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 528 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 523 AutoLoginNoDelay) { | 529 AutoLoginNoDelay) { |
| 524 // Set up mocks to check login success. | 530 // Set up mocks to check login success. |
| 525 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 531 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
| 526 public_session_user_id_); | 532 public_session_account_id_.GetUserEmail()); |
| 527 user_context.SetUserIDHash(user_context.GetUserID()); | 533 user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail()); |
| 528 ExpectSuccessfulLogin(user_context); | 534 ExpectSuccessfulLogin(user_context); |
| 529 existing_user_controller()->OnSigninScreenReady(); | 535 existing_user_controller()->OnSigninScreenReady(); |
| 530 | 536 |
| 531 // Start auto-login and wait for login tasks to complete. | 537 // Start auto-login and wait for login tasks to complete. |
| 532 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginNoDelay); | 538 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginNoDelay); |
| 533 content::RunAllPendingInMessageLoop(); | 539 content::RunAllPendingInMessageLoop(); |
| 534 } | 540 } |
| 535 | 541 |
| 536 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 542 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 537 AutoLoginShortDelay) { | 543 AutoLoginShortDelay) { |
| 538 // Set up mocks to check login success. | 544 // Set up mocks to check login success. |
| 539 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 545 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
| 540 public_session_user_id_); | 546 public_session_account_id_.GetUserEmail()); |
| 541 user_context.SetUserIDHash(user_context.GetUserID()); | 547 user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail()); |
| 542 ExpectSuccessfulLogin(user_context); | 548 ExpectSuccessfulLogin(user_context); |
| 543 existing_user_controller()->OnSigninScreenReady(); | 549 existing_user_controller()->OnSigninScreenReady(); |
| 544 | 550 |
| 545 content::WindowedNotificationObserver profile_prepared_observer( | 551 content::WindowedNotificationObserver profile_prepared_observer( |
| 546 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 552 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 547 content::NotificationService::AllSources()); | 553 content::NotificationService::AllSources()); |
| 548 | 554 |
| 549 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginShortDelay); | 555 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginShortDelay); |
| 550 ASSERT_TRUE(auto_login_timer()); | 556 ASSERT_TRUE(auto_login_timer()); |
| 551 // Don't assert that timer is running: with the short delay sometimes | 557 // Don't assert that timer is running: with the short delay sometimes |
| 552 // the trigger happens before the assert. We've already tested that | 558 // the trigger happens before the assert. We've already tested that |
| 553 // the timer starts when it should. | 559 // the timer starts when it should. |
| 554 | 560 |
| 555 // Wait for the timer to fire. | 561 // Wait for the timer to fire. |
| 556 base::RunLoop runner; | 562 base::RunLoop runner; |
| 557 base::OneShotTimer timer; | 563 base::OneShotTimer timer; |
| 558 timer.Start(FROM_HERE, | 564 timer.Start(FROM_HERE, |
| 559 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), | 565 base::TimeDelta::FromMilliseconds(kAutoLoginShortDelay + 1), |
| 560 runner.QuitClosure()); | 566 runner.QuitClosure()); |
| 561 runner.Run(); | 567 runner.Run(); |
| 562 | 568 |
| 563 profile_prepared_observer.Wait(); | 569 profile_prepared_observer.Wait(); |
| 564 | 570 |
| 565 // Wait for login tasks to complete. | 571 // Wait for login tasks to complete. |
| 566 content::RunAllPendingInMessageLoop(); | 572 content::RunAllPendingInMessageLoop(); |
| 567 } | 573 } |
| 568 | 574 |
| 569 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 575 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 570 LoginStopsAutoLogin) { | 576 LoginStopsAutoLogin) { |
| 571 // Set up mocks to check login success. | 577 // Set up mocks to check login success. |
| 572 UserContext user_context(kUsername); | 578 UserContext user_context(account_id_); |
| 573 user_context.SetGaiaID(kGaiaID); | 579 user_context.SetGaiaID(kGaiaID); |
| 574 user_context.SetKey(Key(kPassword)); | 580 user_context.SetKey(Key(kPassword)); |
| 575 user_context.SetUserIDHash(user_context.GetUserID()); | 581 user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail()); |
| 576 ExpectSuccessfulLogin(user_context); | 582 ExpectSuccessfulLogin(user_context); |
| 577 | 583 |
| 578 existing_user_controller()->OnSigninScreenReady(); | 584 existing_user_controller()->OnSigninScreenReady(); |
| 579 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 585 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginLongDelay); |
| 580 EXPECT_TRUE(auto_login_timer()); | 586 EXPECT_TRUE(auto_login_timer()); |
| 581 | 587 |
| 582 content::WindowedNotificationObserver profile_prepared_observer( | 588 content::WindowedNotificationObserver profile_prepared_observer( |
| 583 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 589 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 584 content::NotificationService::AllSources()); | 590 content::NotificationService::AllSources()); |
| 585 | 591 |
| 586 // Log in and check that it stopped the timer. | 592 // Log in and check that it stopped the timer. |
| 587 existing_user_controller()->Login(user_context, SigninSpecifics()); | 593 existing_user_controller()->Login(user_context, SigninSpecifics()); |
| 588 EXPECT_TRUE(is_login_in_progress()); | 594 EXPECT_TRUE(is_login_in_progress()); |
| 589 ASSERT_TRUE(auto_login_timer()); | 595 ASSERT_TRUE(auto_login_timer()); |
| 590 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 596 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 591 | 597 |
| 592 profile_prepared_observer.Wait(); | 598 profile_prepared_observer.Wait(); |
| 593 | 599 |
| 594 // Wait for login tasks to complete. | 600 // Wait for login tasks to complete. |
| 595 content::RunAllPendingInMessageLoop(); | 601 content::RunAllPendingInMessageLoop(); |
| 596 | 602 |
| 597 // Timer should still be stopped after login completes. | 603 // Timer should still be stopped after login completes. |
| 598 ASSERT_TRUE(auto_login_timer()); | 604 ASSERT_TRUE(auto_login_timer()); |
| 599 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 605 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 600 } | 606 } |
| 601 | 607 |
| 602 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 608 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 603 GuestModeLoginStopsAutoLogin) { | 609 GuestModeLoginStopsAutoLogin) { |
| 604 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 610 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
| 605 .Times(2); | 611 .Times(2); |
| 606 UserContext user_context(kUsername); | 612 UserContext user_context(account_id_); |
| 607 user_context.SetGaiaID(kGaiaID); | 613 user_context.SetGaiaID(kGaiaID); |
| 608 user_context.SetKey(Key(kPassword)); | 614 user_context.SetKey(Key(kPassword)); |
| 609 test::UserSessionManagerTestApi session_manager_test_api( | 615 test::UserSessionManagerTestApi session_manager_test_api( |
| 610 UserSessionManager::GetInstance()); | 616 UserSessionManager::GetInstance()); |
| 611 session_manager_test_api.InjectStubUserContext(user_context); | 617 session_manager_test_api.InjectStubUserContext(user_context); |
| 612 | 618 |
| 613 existing_user_controller()->OnSigninScreenReady(); | 619 existing_user_controller()->OnSigninScreenReady(); |
| 614 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 620 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginLongDelay); |
| 615 EXPECT_TRUE(auto_login_timer()); | 621 EXPECT_TRUE(auto_login_timer()); |
| 616 | 622 |
| 617 // Login and check that it stopped the timer. | 623 // Login and check that it stopped the timer. |
| 618 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST, | 624 existing_user_controller()->Login(UserContext(user_manager::USER_TYPE_GUEST, |
| 619 std::string()), | 625 std::string()), |
| 620 SigninSpecifics()); | 626 SigninSpecifics()); |
| 621 EXPECT_TRUE(is_login_in_progress()); | 627 EXPECT_TRUE(is_login_in_progress()); |
| 622 ASSERT_TRUE(auto_login_timer()); | 628 ASSERT_TRUE(auto_login_timer()); |
| 623 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 629 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 624 | 630 |
| 625 // Wait for login tasks to complete. | 631 // Wait for login tasks to complete. |
| 626 content::RunAllPendingInMessageLoop(); | 632 content::RunAllPendingInMessageLoop(); |
| 627 | 633 |
| 628 // Timer should still be stopped after login completes. | 634 // Timer should still be stopped after login completes. |
| 629 ASSERT_TRUE(auto_login_timer()); | 635 ASSERT_TRUE(auto_login_timer()); |
| 630 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 636 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 631 } | 637 } |
| 632 | 638 |
| 633 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 639 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 634 CompleteLoginStopsAutoLogin) { | 640 CompleteLoginStopsAutoLogin) { |
| 635 // Set up mocks to check login success. | 641 // Set up mocks to check login success. |
| 636 UserContext user_context(kUsername); | 642 UserContext user_context(account_id_); |
| 637 user_context.SetGaiaID(kGaiaID); | 643 user_context.SetGaiaID(kGaiaID); |
| 638 user_context.SetKey(Key(kPassword)); | 644 user_context.SetKey(Key(kPassword)); |
| 639 user_context.SetUserIDHash(user_context.GetUserID()); | 645 user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail()); |
| 640 ExpectSuccessfulLogin(user_context); | 646 ExpectSuccessfulLogin(user_context); |
| 641 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) | 647 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) |
| 642 .Times(1); | 648 .Times(1); |
| 643 | 649 |
| 644 existing_user_controller()->OnSigninScreenReady(); | 650 existing_user_controller()->OnSigninScreenReady(); |
| 645 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 651 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginLongDelay); |
| 646 EXPECT_TRUE(auto_login_timer()); | 652 EXPECT_TRUE(auto_login_timer()); |
| 647 | 653 |
| 648 content::WindowedNotificationObserver profile_prepared_observer( | 654 content::WindowedNotificationObserver profile_prepared_observer( |
| 649 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 655 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 650 content::NotificationService::AllSources()); | 656 content::NotificationService::AllSources()); |
| 651 | 657 |
| 652 // Check that login completes and stops the timer. | 658 // Check that login completes and stops the timer. |
| 653 existing_user_controller()->CompleteLogin(user_context); | 659 existing_user_controller()->CompleteLogin(user_context); |
| 654 ASSERT_TRUE(auto_login_timer()); | 660 ASSERT_TRUE(auto_login_timer()); |
| 655 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 661 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 656 | 662 |
| 657 profile_prepared_observer.Wait(); | 663 profile_prepared_observer.Wait(); |
| 658 | 664 |
| 659 // Wait for login tasks to complete. | 665 // Wait for login tasks to complete. |
| 660 content::RunAllPendingInMessageLoop(); | 666 content::RunAllPendingInMessageLoop(); |
| 661 | 667 |
| 662 // Timer should still be stopped after login completes. | 668 // Timer should still be stopped after login completes. |
| 663 ASSERT_TRUE(auto_login_timer()); | 669 ASSERT_TRUE(auto_login_timer()); |
| 664 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 670 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 665 } | 671 } |
| 666 | 672 |
| 667 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 673 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 668 PublicSessionLoginStopsAutoLogin) { | 674 PublicSessionLoginStopsAutoLogin) { |
| 669 // Set up mocks to check login success. | 675 // Set up mocks to check login success. |
| 670 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 676 UserContext user_context(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
| 671 public_session_user_id_); | 677 public_session_account_id_.GetUserEmail()); |
| 672 user_context.SetUserIDHash(user_context.GetUserID()); | 678 user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail()); |
| 673 ExpectSuccessfulLogin(user_context); | 679 ExpectSuccessfulLogin(user_context); |
| 674 existing_user_controller()->OnSigninScreenReady(); | 680 existing_user_controller()->OnSigninScreenReady(); |
| 675 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 681 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginLongDelay); |
| 676 EXPECT_TRUE(auto_login_timer()); | 682 EXPECT_TRUE(auto_login_timer()); |
| 677 | 683 |
| 678 content::WindowedNotificationObserver profile_prepared_observer( | 684 content::WindowedNotificationObserver profile_prepared_observer( |
| 679 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, | 685 chrome::NOTIFICATION_LOGIN_USER_PROFILE_PREPARED, |
| 680 content::NotificationService::AllSources()); | 686 content::NotificationService::AllSources()); |
| 681 | 687 |
| 682 // Login and check that it stopped the timer. | 688 // Login and check that it stopped the timer. |
| 683 existing_user_controller()->Login( | 689 existing_user_controller()->Login( |
| 684 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT, | 690 UserContext(user_manager::USER_TYPE_PUBLIC_ACCOUNT, |
| 685 public_session_user_id_), | 691 public_session_account_id_.GetUserEmail()), |
| 686 SigninSpecifics()); | 692 SigninSpecifics()); |
| 687 | 693 |
| 688 EXPECT_TRUE(is_login_in_progress()); | 694 EXPECT_TRUE(is_login_in_progress()); |
| 689 ASSERT_TRUE(auto_login_timer()); | 695 ASSERT_TRUE(auto_login_timer()); |
| 690 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 696 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 691 | 697 |
| 692 profile_prepared_observer.Wait(); | 698 profile_prepared_observer.Wait(); |
| 693 | 699 |
| 694 // Wait for login tasks to complete. | 700 // Wait for login tasks to complete. |
| 695 content::RunAllPendingInMessageLoop(); | 701 content::RunAllPendingInMessageLoop(); |
| 696 | 702 |
| 697 // Timer should still be stopped after login completes. | 703 // Timer should still be stopped after login completes. |
| 698 ASSERT_TRUE(auto_login_timer()); | 704 ASSERT_TRUE(auto_login_timer()); |
| 699 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 705 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
| 700 } | 706 } |
| 701 | 707 |
| 702 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 708 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 703 LoginForbiddenWhenUntrusted) { | 709 LoginForbiddenWhenUntrusted) { |
| 704 // Make cros settings untrusted. | 710 // Make cros settings untrusted. |
| 705 MakeCrosSettingsPermanentlyUntrusted(); | 711 MakeCrosSettingsPermanentlyUntrusted(); |
| 706 | 712 |
| 707 // Check that the attempt to start a public session fails with an error. | 713 // Check that the attempt to start a public session fails with an error. |
| 708 ExpectLoginFailure(); | 714 ExpectLoginFailure(); |
| 709 UserContext user_context(kUsername); | 715 UserContext user_context(account_id_); |
| 710 user_context.SetGaiaID(kGaiaID); | 716 user_context.SetGaiaID(kGaiaID); |
| 711 user_context.SetKey(Key(kPassword)); | 717 user_context.SetKey(Key(kPassword)); |
| 712 user_context.SetUserIDHash(user_context.GetUserID()); | 718 user_context.SetUserIDHash(user_context.GetAccountId().GetUserEmail()); |
| 713 existing_user_controller()->Login(user_context, SigninSpecifics()); | 719 existing_user_controller()->Login(user_context, SigninSpecifics()); |
| 714 } | 720 } |
| 715 | 721 |
| 716 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 722 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 717 NoAutoLoginWhenUntrusted) { | 723 NoAutoLoginWhenUntrusted) { |
| 718 // Start the public session timer. | 724 // Start the public session timer. |
| 719 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 725 SetAutoLoginPolicy(public_session_account_id_, kAutoLoginLongDelay); |
| 720 existing_user_controller()->OnSigninScreenReady(); | 726 existing_user_controller()->OnSigninScreenReady(); |
| 721 EXPECT_TRUE(auto_login_timer()); | 727 EXPECT_TRUE(auto_login_timer()); |
| 722 | 728 |
| 723 // Make cros settings untrusted. | 729 // Make cros settings untrusted. |
| 724 MakeCrosSettingsPermanentlyUntrusted(); | 730 MakeCrosSettingsPermanentlyUntrusted(); |
| 725 | 731 |
| 726 // Check that when the timer fires, auto-login fails with an error. | 732 // Check that when the timer fires, auto-login fails with an error. |
| 727 ExpectLoginFailure(); | 733 ExpectLoginFailure(); |
| 728 FireAutoLogin(); | 734 FireAutoLogin(); |
| 729 } | 735 } |
| 730 | 736 |
| 731 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 737 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 732 PRE_TestLoadingPublicUsersFromLocalState) { | 738 PRE_TestLoadingPublicUsersFromLocalState) { |
| 733 // First run propagates public accounts and stores them in Local State. | 739 // First run propagates public accounts and stores them in Local State. |
| 734 } | 740 } |
| 735 | 741 |
| 736 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, | 742 IN_PROC_BROWSER_TEST_F(ExistingUserControllerPublicSessionTest, |
| 737 TestLoadingPublicUsersFromLocalState) { | 743 TestLoadingPublicUsersFromLocalState) { |
| 738 // Second run loads list of public accounts from Local State. | 744 // Second run loads list of public accounts from Local State. |
| 739 } | 745 } |
| 740 | 746 |
| 741 } // namespace chromeos | 747 } // namespace chromeos |
| OLD | NEW |