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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 }; | 234 }; |
235 | 235 |
236 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) { | 236 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, ExistingUserLogin) { |
237 // This is disabled twice: once right after signin but before checking for | 237 // This is disabled twice: once right after signin but before checking for |
238 // auto-enrollment, and again after doing an ownership status check. | 238 // auto-enrollment, and again after doing an ownership status check. |
239 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 239 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
240 .Times(2); | 240 .Times(2); |
241 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 241 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
242 .Times(1) | 242 .Times(1) |
243 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword))); | 243 .WillOnce(WithArg<0>(CreateAuthenticator(kUsername, kPassword))); |
244 EXPECT_CALL(*mock_login_utils_, | 244 UserContext user_context(kUsername); |
245 PrepareProfile(UserContext(kUsername, kPassword, "", kUsername), | 245 user_context.SetPassword(kPassword); |
246 _, _, _, _)) | 246 user_context.SetUserIDHash(kUsername); |
| 247 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _, _)) |
247 .Times(1) | 248 .Times(1) |
248 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 249 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
249 &base::Callback<void(void)>::Run)); | 250 &base::Callback<void(void)>::Run)); |
250 EXPECT_CALL(*mock_login_utils_, | 251 EXPECT_CALL(*mock_login_utils_, |
251 DoBrowserLaunch(testing_profile_.get(), | 252 DoBrowserLaunch(testing_profile_.get(), |
252 mock_login_display_host_.get())) | 253 mock_login_display_host_.get())) |
253 .Times(1); | 254 .Times(1); |
254 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) | 255 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kUsername)) |
255 .Times(1); | 256 .Times(1); |
256 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 257 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
257 .Times(1); | 258 .Times(1); |
258 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 259 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
259 .Times(1); | 260 .Times(1); |
260 EXPECT_CALL(*mock_login_display_host_, | 261 EXPECT_CALL(*mock_login_display_host_, |
261 StartWizardPtr(WizardController::kTermsOfServiceScreenName, NULL)) | 262 StartWizardPtr(WizardController::kTermsOfServiceScreenName, NULL)) |
262 .Times(0); | 263 .Times(0); |
263 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) | 264 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) |
264 .Times(AnyNumber()) | 265 .Times(AnyNumber()) |
265 .WillRepeatedly(Return(false)); | 266 .WillRepeatedly(Return(false)); |
266 existing_user_controller()->Login(UserContext(kUsername, kPassword, "")); | 267 existing_user_controller()->Login(user_context); |
267 content::RunAllPendingInMessageLoop(); | 268 content::RunAllPendingInMessageLoop(); |
268 } | 269 } |
269 | 270 |
270 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, AutoEnrollAfterSignIn) { | 271 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, AutoEnrollAfterSignIn) { |
271 EXPECT_CALL(*mock_login_display_host_, | 272 EXPECT_CALL(*mock_login_display_host_, |
272 StartWizardPtr(WizardController::kEnrollmentScreenName, | 273 StartWizardPtr(WizardController::kEnrollmentScreenName, |
273 _)) | 274 _)) |
274 .Times(1); | 275 .Times(1); |
275 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 276 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
276 .Times(1); | 277 .Times(1); |
277 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) | 278 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) |
278 .Times(1); | 279 .Times(1); |
279 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) | 280 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) |
280 .Times(AnyNumber()) | 281 .Times(AnyNumber()) |
281 .WillRepeatedly(Return(false)); | 282 .WillRepeatedly(Return(false)); |
282 // The order of these expected calls matters: the UI if first disabled | 283 // The order of these expected calls matters: the UI if first disabled |
283 // during the login sequence, and is enabled again for the enrollment screen. | 284 // during the login sequence, and is enabled again for the enrollment screen. |
284 Sequence uiEnabledSequence; | 285 Sequence uiEnabledSequence; |
285 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 286 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
286 .Times(1) | 287 .Times(1) |
287 .InSequence(uiEnabledSequence); | 288 .InSequence(uiEnabledSequence); |
288 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 289 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
289 .Times(1) | 290 .Times(1) |
290 .InSequence(uiEnabledSequence); | 291 .InSequence(uiEnabledSequence); |
291 existing_user_controller()->DoAutoEnrollment(); | 292 existing_user_controller()->DoAutoEnrollment(); |
292 existing_user_controller()->CompleteLogin( | 293 UserContext user_context(kUsername); |
293 UserContext(kUsername, kPassword, "")); | 294 user_context.SetPassword(kPassword); |
| 295 existing_user_controller()->CompleteLogin(user_context); |
294 content::RunAllPendingInMessageLoop(); | 296 content::RunAllPendingInMessageLoop(); |
295 } | 297 } |
296 | 298 |
297 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, | 299 IN_PROC_BROWSER_TEST_P(ExistingUserControllerTest, |
298 NewUserDontAutoEnrollAfterSignIn) { | 300 NewUserDontAutoEnrollAfterSignIn) { |
299 EXPECT_CALL(*mock_login_display_host_, | 301 EXPECT_CALL(*mock_login_display_host_, |
300 StartWizardPtr(WizardController::kEnrollmentScreenName, | 302 StartWizardPtr(WizardController::kEnrollmentScreenName, |
301 _)) | 303 _)) |
302 .Times(0); | 304 .Times(0); |
303 EXPECT_CALL(*mock_login_display_host_, | 305 EXPECT_CALL(*mock_login_display_host_, |
304 StartWizardPtr(WizardController::kTermsOfServiceScreenName, | 306 StartWizardPtr(WizardController::kTermsOfServiceScreenName, |
305 NULL)) | 307 NULL)) |
306 .Times(1); | 308 .Times(1); |
307 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 309 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
308 .Times(1) | 310 .Times(1) |
309 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword))); | 311 .WillOnce(WithArg<0>(CreateAuthenticator(kNewUsername, kPassword))); |
310 base::Callback<void(void)> add_user_cb = | 312 base::Callback<void(void)> add_user_cb = |
311 base::Bind(&MockUserManager::AddUser, | 313 base::Bind(&MockUserManager::AddUser, |
312 base::Unretained(mock_user_manager_), | 314 base::Unretained(mock_user_manager_), |
313 kNewUsername); | 315 kNewUsername); |
314 EXPECT_CALL(*mock_login_utils_, | 316 UserContext user_context(kNewUsername); |
315 PrepareProfile(UserContext(kNewUsername, | 317 user_context.SetPassword(kPassword); |
316 kPassword, | 318 user_context.SetUserIDHash(kNewUsername); |
317 std::string(), | 319 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _, _)) |
318 kNewUsername), | |
319 _, _, _, _)) | |
320 .Times(1) | 320 .Times(1) |
321 .WillOnce(DoAll( | 321 .WillOnce(DoAll( |
322 InvokeWithoutArgs(&add_user_cb, | 322 InvokeWithoutArgs(&add_user_cb, |
323 &base::Callback<void(void)>::Run), | 323 &base::Callback<void(void)>::Run), |
324 InvokeWithoutArgs(&profile_prepared_cb_, | 324 InvokeWithoutArgs(&profile_prepared_cb_, |
325 &base::Callback<void(void)>::Run))); | 325 &base::Callback<void(void)>::Run))); |
326 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) | 326 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(kNewUsername)) |
327 .Times(1); | 327 .Times(1); |
328 EXPECT_CALL(*mock_login_display_, OnFadeOut()) | 328 EXPECT_CALL(*mock_login_display_, OnFadeOut()) |
329 .Times(1); | 329 .Times(1); |
330 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) | 330 EXPECT_CALL(*mock_login_display_host_.get(), OnCompleteLogin()) |
331 .Times(1); | 331 .Times(1); |
332 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) | 332 EXPECT_CALL(*mock_user_manager_, IsCurrentUserNew()) |
333 .Times(AnyNumber()) | 333 .Times(AnyNumber()) |
334 .WillRepeatedly(Return(true)); | 334 .WillRepeatedly(Return(true)); |
335 | 335 |
336 // The order of these expected calls matters: the UI if first disabled | 336 // The order of these expected calls matters: the UI if first disabled |
337 // during the login sequence, and is enabled again after login completion. | 337 // during the login sequence, and is enabled again after login completion. |
338 Sequence uiEnabledSequence; | 338 Sequence uiEnabledSequence; |
339 // This is disabled twice: once right after signin but before checking for | 339 // This is disabled twice: once right after signin but before checking for |
340 // auto-enrollment, and again after doing an ownership status check. | 340 // auto-enrollment, and again after doing an ownership status check. |
341 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 341 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
342 .Times(2) | 342 .Times(2) |
343 .InSequence(uiEnabledSequence); | 343 .InSequence(uiEnabledSequence); |
344 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 344 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
345 .Times(1) | 345 .Times(1) |
346 .InSequence(uiEnabledSequence); | 346 .InSequence(uiEnabledSequence); |
347 | 347 |
348 existing_user_controller()->CompleteLogin( | 348 existing_user_controller()->CompleteLogin(user_context); |
349 UserContext(kNewUsername, kPassword, "")); | |
350 content::RunAllPendingInMessageLoop(); | 349 content::RunAllPendingInMessageLoop(); |
351 } | 350 } |
352 | 351 |
353 MATCHER_P(HasDetails, expected, "") { | 352 MATCHER_P(HasDetails, expected, "") { |
354 return expected == *content::Details<const std::string>(arg).ptr(); | 353 return expected == *content::Details<const std::string>(arg).ptr(); |
355 } | 354 } |
356 | 355 |
357 class ExistingUserControllerPublicSessionTest | 356 class ExistingUserControllerPublicSessionTest |
358 : public ExistingUserControllerTest { | 357 : public ExistingUserControllerTest { |
359 protected: | 358 protected: |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
439 virtual void SetUpUserManager() OVERRIDE { | 438 virtual void SetUpUserManager() OVERRIDE { |
440 } | 439 } |
441 | 440 |
442 void ExpectSuccessfulLogin(const std::string& username, | 441 void ExpectSuccessfulLogin(const std::string& username, |
443 const std::string& password) { | 442 const std::string& password) { |
444 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) | 443 EXPECT_CALL(*mock_login_display_, SetUIEnabled(false)) |
445 .Times(AnyNumber()); | 444 .Times(AnyNumber()); |
446 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) | 445 EXPECT_CALL(*mock_login_utils_, CreateAuthenticator(_)) |
447 .Times(1) | 446 .Times(1) |
448 .WillOnce(WithArg<0>(CreateAuthenticator(username, password))); | 447 .WillOnce(WithArg<0>(CreateAuthenticator(username, password))); |
449 EXPECT_CALL(*mock_login_utils_, | 448 UserContext user_context(username); |
450 PrepareProfile(UserContext(username, password, "", username), | 449 user_context.SetPassword(password); |
451 _, _, _, _)) | 450 user_context.SetUserIDHash(username); |
| 451 EXPECT_CALL(*mock_login_utils_, PrepareProfile(user_context, _, _, _, _)) |
452 .Times(1) | 452 .Times(1) |
453 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, | 453 .WillOnce(InvokeWithoutArgs(&profile_prepared_cb_, |
454 &base::Callback<void(void)>::Run)); | 454 &base::Callback<void(void)>::Run)); |
455 EXPECT_CALL(*mock_login_utils_, | 455 EXPECT_CALL(*mock_login_utils_, |
456 DoBrowserLaunch(testing_profile_.get(), | 456 DoBrowserLaunch(testing_profile_.get(), |
457 mock_login_display_host_.get())) | 457 mock_login_display_host_.get())) |
458 .Times(1); | 458 .Times(1); |
459 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username)) | 459 EXPECT_CALL(*mock_login_display_, OnLoginSuccess(username)) |
460 .Times(1); | 460 .Times(1); |
461 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) | 461 EXPECT_CALL(*mock_login_display_, SetUIEnabled(true)) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
583 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, | 583 IN_PROC_BROWSER_TEST_P(ExistingUserControllerPublicSessionTest, |
584 LoginStopsAutoLogin) { | 584 LoginStopsAutoLogin) { |
585 // Set up mocks to check login success. | 585 // Set up mocks to check login success. |
586 ExpectSuccessfulLogin(kUsername, kPassword); | 586 ExpectSuccessfulLogin(kUsername, kPassword); |
587 | 587 |
588 existing_user_controller()->OnSigninScreenReady(); | 588 existing_user_controller()->OnSigninScreenReady(); |
589 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 589 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
590 ASSERT_TRUE(auto_login_timer()); | 590 ASSERT_TRUE(auto_login_timer()); |
591 | 591 |
592 // Login and check that it stopped the timer. | 592 // Login and check that it stopped the timer. |
593 existing_user_controller()->Login(UserContext(kUsername, kPassword, "")); | 593 UserContext user_context(kUsername); |
| 594 user_context.SetPassword(kPassword); |
| 595 existing_user_controller()->Login(user_context); |
594 EXPECT_TRUE(is_login_in_progress()); | 596 EXPECT_TRUE(is_login_in_progress()); |
595 ASSERT_TRUE(auto_login_timer()); | 597 ASSERT_TRUE(auto_login_timer()); |
596 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 598 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
597 | 599 |
598 // Wait for login tasks to complete. | 600 // Wait for login tasks to complete. |
599 content::RunAllPendingInMessageLoop(); | 601 content::RunAllPendingInMessageLoop(); |
600 | 602 |
601 // Timer should still be stopped after login completes. | 603 // Timer should still be stopped after login completes. |
602 ASSERT_TRUE(auto_login_timer()); | 604 ASSERT_TRUE(auto_login_timer()); |
603 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 605 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 // Set up mocks to check login success. | 638 // Set up mocks to check login success. |
637 ExpectSuccessfulLogin(kUsername, kPassword); | 639 ExpectSuccessfulLogin(kUsername, kPassword); |
638 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) | 640 EXPECT_CALL(*mock_login_display_host_, OnCompleteLogin()) |
639 .Times(1); | 641 .Times(1); |
640 | 642 |
641 existing_user_controller()->OnSigninScreenReady(); | 643 existing_user_controller()->OnSigninScreenReady(); |
642 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); | 644 SetAutoLoginPolicy(kPublicSessionAccountId, kAutoLoginLongDelay); |
643 ASSERT_TRUE(auto_login_timer()); | 645 ASSERT_TRUE(auto_login_timer()); |
644 | 646 |
645 // Check that login completes and stops the timer. | 647 // Check that login completes and stops the timer. |
646 existing_user_controller()->CompleteLogin( | 648 UserContext user_context(kUsername); |
647 UserContext(kUsername, kPassword, "")); | 649 user_context.SetPassword(kPassword); |
| 650 existing_user_controller()->CompleteLogin(user_context); |
648 ASSERT_TRUE(auto_login_timer()); | 651 ASSERT_TRUE(auto_login_timer()); |
649 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 652 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
650 | 653 |
651 // Wait for login tasks to complete. | 654 // Wait for login tasks to complete. |
652 content::RunAllPendingInMessageLoop(); | 655 content::RunAllPendingInMessageLoop(); |
653 | 656 |
654 // Timer should still be stopped after login completes. | 657 // Timer should still be stopped after login completes. |
655 ASSERT_TRUE(auto_login_timer()); | 658 ASSERT_TRUE(auto_login_timer()); |
656 EXPECT_FALSE(auto_login_timer()->IsRunning()); | 659 EXPECT_FALSE(auto_login_timer()->IsRunning()); |
657 } | 660 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 | 693 |
691 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation, | 694 INSTANTIATE_TEST_CASE_P(ExistingUserControllerTestInstantiation, |
692 ExistingUserControllerTest, | 695 ExistingUserControllerTest, |
693 testing::Bool()); | 696 testing::Bool()); |
694 | 697 |
695 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation, | 698 INSTANTIATE_TEST_CASE_P(ExistingUserControllerPublicSessionTestInstantiation, |
696 ExistingUserControllerPublicSessionTest, | 699 ExistingUserControllerPublicSessionTest, |
697 testing::Bool()); | 700 testing::Bool()); |
698 | 701 |
699 } // namespace chromeos | 702 } // namespace chromeos |
OLD | NEW |