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 "chrome/browser/chromeos/login/login_utils.h" | 5 #include "chrome/browser/chromeos/login/login_utils.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 loop_(MessageLoop::TYPE_IO), | 137 loop_(MessageLoop::TYPE_IO), |
138 browser_process_( | 138 browser_process_( |
139 static_cast<TestingBrowserProcess*>(g_browser_process)), | 139 static_cast<TestingBrowserProcess*>(g_browser_process)), |
140 local_state_(browser_process_), | 140 local_state_(browser_process_), |
141 ui_thread_(BrowserThread::UI, &loop_), | 141 ui_thread_(BrowserThread::UI, &loop_), |
142 db_thread_(BrowserThread::DB), | 142 db_thread_(BrowserThread::DB), |
143 file_thread_(BrowserThread::FILE, &loop_), | 143 file_thread_(BrowserThread::FILE, &loop_), |
144 mock_async_method_caller_(NULL), | 144 mock_async_method_caller_(NULL), |
145 connector_(NULL), | 145 connector_(NULL), |
146 cryptohome_(NULL), | 146 cryptohome_(NULL), |
147 prepared_profile_(NULL) {} | 147 prepared_profile_(NULL), |
| 148 created_profile_(NULL) {} |
148 | 149 |
149 virtual void SetUp() OVERRIDE { | 150 virtual void SetUp() OVERRIDE { |
150 // This test is not a full blown InProcessBrowserTest, and doesn't have | 151 // This test is not a full blown InProcessBrowserTest, and doesn't have |
151 // all the usual threads running. However a lot of subsystems pulled from | 152 // all the usual threads running. However a lot of subsystems pulled from |
152 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that | 153 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that |
153 // those tasks were posted. Those tasks in turn depend on a lot of other | 154 // those tasks were posted. Those tasks in turn depend on a lot of other |
154 // components that aren't there during this test, so this kludge is used to | 155 // components that aren't there during this test, so this kludge is used to |
155 // have a running IO loop that doesn't really execute any tasks. | 156 // have a running IO loop that doesn't really execute any tasks. |
156 // | 157 // |
157 // See InvokeOnIO() below for a way to perform specific tasks on IO, when | 158 // See InvokeOnIO() below for a way to perform specific tasks on IO, when |
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 // If there was work then keep waiting for more work. | 348 // If there was work then keep waiting for more work. |
348 // If there was no work then quit the fake IO loop. | 349 // If there was no work then quit the fake IO loop. |
349 return has_work; | 350 return has_work; |
350 } | 351 } |
351 | 352 |
352 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { | 353 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { |
353 EXPECT_FALSE(prepared_profile_); | 354 EXPECT_FALSE(prepared_profile_); |
354 prepared_profile_ = profile; | 355 prepared_profile_ = profile; |
355 } | 356 } |
356 | 357 |
| 358 virtual void OnProfileCreated(Profile* profile) OVERRIDE { |
| 359 created_profile_ = profile; |
| 360 } |
| 361 |
357 #if defined(ENABLE_RLZ) | 362 #if defined(ENABLE_RLZ) |
358 virtual void OnRlzInitialized(Profile* profile) OVERRIDE { | 363 virtual void OnRlzInitialized(Profile* profile) OVERRIDE { |
359 rlz_initialized_cb_.Run(); | 364 rlz_initialized_cb_.Run(); |
360 } | 365 } |
361 #endif | 366 #endif |
362 | 367 |
363 virtual void OnLoginFailure(const LoginFailure& error) OVERRIDE { | 368 virtual void OnLoginFailure(const LoginFailure& error) OVERRIDE { |
364 FAIL() << "OnLoginFailure not expected"; | 369 FAIL() << "OnLoginFailure not expected"; |
365 } | 370 } |
366 | 371 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
473 | 478 |
474 MockDBusThreadManager mock_dbus_thread_manager_; | 479 MockDBusThreadManager mock_dbus_thread_manager_; |
475 input_method::MockInputMethodManager mock_input_method_manager_; | 480 input_method::MockInputMethodManager mock_input_method_manager_; |
476 net::TestURLFetcherFactory test_url_fetcher_factory_; | 481 net::TestURLFetcherFactory test_url_fetcher_factory_; |
477 | 482 |
478 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; | 483 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; |
479 | 484 |
480 policy::BrowserPolicyConnector* connector_; | 485 policy::BrowserPolicyConnector* connector_; |
481 MockCryptohomeLibrary* cryptohome_; | 486 MockCryptohomeLibrary* cryptohome_; |
482 Profile* prepared_profile_; | 487 Profile* prepared_profile_; |
| 488 Profile* created_profile_; |
483 | 489 |
484 base::Closure rlz_initialized_cb_; | 490 base::Closure rlz_initialized_cb_; |
485 | 491 |
486 private: | 492 private: |
487 base::ScopedTempDir scoped_temp_dir_; | 493 base::ScopedTempDir scoped_temp_dir_; |
488 | 494 |
489 std::string device_policy_; | 495 std::string device_policy_; |
490 std::string user_policy_; | 496 std::string user_policy_; |
491 | 497 |
492 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); | 498 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); |
493 }; | 499 }; |
494 | 500 |
495 class LoginUtilsBlockingLoginTest | 501 class LoginUtilsBlockingLoginTest |
496 : public LoginUtilsTest, | 502 : public LoginUtilsTest, |
497 public testing::WithParamInterface<int> {}; | 503 public testing::WithParamInterface<int> {}; |
498 | 504 |
499 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { | 505 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { |
500 UserManager* user_manager = UserManager::Get(); | 506 UserManager* user_manager = UserManager::Get(); |
501 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); | 507 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
502 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 508 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
503 EXPECT_FALSE(prepared_profile_); | 509 EXPECT_FALSE(prepared_profile_); |
504 | 510 |
505 // The profile will be created without waiting for a policy response. | 511 // The profile will be created without waiting for a policy response. |
506 PrepareProfile(kUsername); | 512 PrepareProfile(kUsername); |
507 | 513 |
| 514 // This should shortcut cookie transfer step that is missing due to |
| 515 // IO thread being mocked. |
| 516 EXPECT_TRUE(created_profile_); |
| 517 LoginUtils::Get()->CompleteProfileCreate(created_profile_); |
| 518 |
508 EXPECT_TRUE(prepared_profile_); | 519 EXPECT_TRUE(prepared_profile_); |
509 ASSERT_TRUE(user_manager->IsUserLoggedIn()); | 520 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
510 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email()); | 521 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email()); |
511 } | 522 } |
512 | 523 |
513 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { | 524 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { |
514 UserManager* user_manager = UserManager::Get(); | 525 UserManager* user_manager = UserManager::Get(); |
515 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); | 526 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
516 EXPECT_FALSE(connector_->IsEnterpriseManaged()); | 527 EXPECT_FALSE(connector_->IsEnterpriseManaged()); |
517 EXPECT_FALSE(prepared_profile_); | 528 EXPECT_FALSE(prepared_profile_); |
518 | 529 |
519 // Enroll the device. | 530 // Enroll the device. |
520 LockDevice(kUsername); | 531 LockDevice(kUsername); |
521 | 532 |
522 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); | 533 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); |
523 EXPECT_TRUE(connector_->IsEnterpriseManaged()); | 534 EXPECT_TRUE(connector_->IsEnterpriseManaged()); |
524 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); | 535 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); |
525 EXPECT_FALSE(prepared_profile_); | 536 EXPECT_FALSE(prepared_profile_); |
526 | 537 |
527 // Login with a non-enterprise user shouldn't block. | 538 // Login with a non-enterprise user shouldn't block. |
528 PrepareProfile(kUsernameOtherDomain); | 539 PrepareProfile(kUsernameOtherDomain); |
529 | 540 |
| 541 // This should shortcut cookie transfer step that is missing due to |
| 542 // IO thread being mocked. |
| 543 EXPECT_TRUE(created_profile_); |
| 544 LoginUtils::Get()->CompleteProfileCreate(created_profile_); |
| 545 |
530 EXPECT_TRUE(prepared_profile_); | 546 EXPECT_TRUE(prepared_profile_); |
531 ASSERT_TRUE(user_manager->IsUserLoggedIn()); | 547 ASSERT_TRUE(user_manager->IsUserLoggedIn()); |
532 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email()); | 548 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email()); |
533 } | 549 } |
534 | 550 |
535 #if defined(ENABLE_RLZ) | 551 #if defined(ENABLE_RLZ) |
536 TEST_F(LoginUtilsTest, RlzInitialized) { | 552 TEST_F(LoginUtilsTest, RlzInitialized) { |
537 // No RLZ brand code set initially. | 553 // No RLZ brand code set initially. |
538 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); | 554 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); |
539 | 555 |
540 base::RunLoop wait_for_rlz_init; | 556 base::RunLoop wait_for_rlz_init; |
541 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); | 557 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); |
542 | 558 |
543 PrepareProfile(kUsername); | 559 PrepareProfile(kUsername); |
544 | 560 |
545 wait_for_rlz_init.Run(); | 561 wait_for_rlz_init.Run(); |
546 // Wait for blocking RLZ tasks to complete. | 562 // Wait for blocking RLZ tasks to complete. |
547 RunUntilIdle(); | 563 RunUntilIdle(); |
548 | 564 |
| 565 // This should shortcut cookie transfer step that is missing due to |
| 566 // IO thread being mocked. |
| 567 EXPECT_TRUE(created_profile_); |
| 568 LoginUtils::Get()->CompleteProfileCreate(created_profile_); |
| 569 |
549 // RLZ brand code has been set to empty string. | 570 // RLZ brand code has been set to empty string. |
550 EXPECT_TRUE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); | 571 EXPECT_TRUE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); |
551 EXPECT_EQ(std::string(), local_state_.Get()->GetString(prefs::kRLZBrand)); | 572 EXPECT_EQ(std::string(), local_state_.Get()->GetString(prefs::kRLZBrand)); |
552 | 573 |
553 // RLZ value for homepage access point should have been initialized. | 574 // RLZ value for homepage access point should have been initialized. |
554 string16 rlz_string; | 575 string16 rlz_string; |
555 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( | 576 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( |
556 RLZTracker::CHROME_HOME_PAGE, &rlz_string)); | 577 RLZTracker::CHROME_HOME_PAGE, &rlz_string)); |
557 EXPECT_EQ(string16(), rlz_string); | 578 EXPECT_EQ(string16(), rlz_string); |
558 } | 579 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 659 |
639 // Make the current fetcher fail. | 660 // Make the current fetcher fail. |
640 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); | 661 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); |
641 ASSERT_TRUE(fetcher); | 662 ASSERT_TRUE(fetcher); |
642 EXPECT_TRUE(fetcher->delegate()); | 663 EXPECT_TRUE(fetcher->delegate()); |
643 fetcher->set_url(fetcher->GetOriginalURL()); | 664 fetcher->set_url(fetcher->GetOriginalURL()); |
644 fetcher->set_response_code(500); | 665 fetcher->set_response_code(500); |
645 fetcher->delegate()->OnURLFetchComplete(fetcher); | 666 fetcher->delegate()->OnURLFetchComplete(fetcher); |
646 } | 667 } |
647 | 668 |
| 669 // This should shortcut cookie transfer step that is missing due to |
| 670 // IO thread being mocked. |
| 671 EXPECT_TRUE(created_profile_); |
| 672 LoginUtils::Get()->CompleteProfileCreate(created_profile_); |
| 673 |
648 // The profile is finally ready: | 674 // The profile is finally ready: |
649 EXPECT_TRUE(prepared_profile_); | 675 EXPECT_TRUE(prepared_profile_); |
650 } | 676 } |
651 | 677 |
652 INSTANTIATE_TEST_CASE_P( | 678 INSTANTIATE_TEST_CASE_P( |
653 LoginUtilsBlockingLoginTestInstance, | 679 LoginUtilsBlockingLoginTestInstance, |
654 LoginUtilsBlockingLoginTest, | 680 LoginUtilsBlockingLoginTest, |
655 testing::Values(0, 1, 2, 3, 4, 5)); | 681 testing::Values(0, 1, 2, 3, 4, 5)); |
656 | 682 |
657 } // namespace | 683 } // namespace |
658 | 684 |
659 } | 685 } |
OLD | NEW |