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

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

Issue 11853012: Improved test coverage of login_utils_browsertest.cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 fake_io_thread_("fake_io_thread"), 138 fake_io_thread_("fake_io_thread"),
139 loop_(MessageLoop::TYPE_IO), 139 loop_(MessageLoop::TYPE_IO),
140 browser_process_(TestingBrowserProcess::GetGlobal()), 140 browser_process_(TestingBrowserProcess::GetGlobal()),
141 local_state_(browser_process_), 141 local_state_(browser_process_),
142 ui_thread_(BrowserThread::UI, &loop_), 142 ui_thread_(BrowserThread::UI, &loop_),
143 db_thread_(BrowserThread::DB), 143 db_thread_(BrowserThread::DB),
144 file_thread_(BrowserThread::FILE, &loop_), 144 file_thread_(BrowserThread::FILE, &loop_),
145 mock_async_method_caller_(NULL), 145 mock_async_method_caller_(NULL),
146 connector_(NULL), 146 connector_(NULL),
147 cryptohome_(NULL), 147 cryptohome_(NULL),
148 prepared_profile_(NULL), 148 prepared_profile_(NULL) {}
149 created_profile_(NULL) {}
150 149
151 virtual void SetUp() OVERRIDE { 150 virtual void SetUp() OVERRIDE {
152 // 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
153 // 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
154 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that 153 // ProfileImpl post to IO (usually from ProfileIOData), and DCHECK that
155 // 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
156 // 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
157 // 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.
158 // 157 //
159 // 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 // If there was work then keep waiting for more work. 350 // If there was work then keep waiting for more work.
352 // If there was no work then quit the fake IO loop. 351 // If there was no work then quit the fake IO loop.
353 return has_work; 352 return has_work;
354 } 353 }
355 354
356 virtual void OnProfilePrepared(Profile* profile) OVERRIDE { 355 virtual void OnProfilePrepared(Profile* profile) OVERRIDE {
357 EXPECT_FALSE(prepared_profile_); 356 EXPECT_FALSE(prepared_profile_);
358 prepared_profile_ = profile; 357 prepared_profile_ = profile;
359 } 358 }
360 359
361 virtual void OnProfileCreated(Profile* profile) OVERRIDE {
362 created_profile_ = profile;
363 }
364
365 #if defined(ENABLE_RLZ) 360 #if defined(ENABLE_RLZ)
366 virtual void OnRlzInitialized(Profile* profile) OVERRIDE { 361 virtual void OnRlzInitialized(Profile* profile) OVERRIDE {
367 rlz_initialized_cb_.Run(); 362 rlz_initialized_cb_.Run();
368 } 363 }
369 #endif 364 #endif
370 365
371 virtual void OnLoginFailure(const LoginFailure& error) OVERRIDE { 366 virtual void OnLoginFailure(const LoginFailure& error) OVERRIDE {
372 FAIL() << "OnLoginFailure not expected"; 367 FAIL() << "OnLoginFailure not expected";
373 } 368 }
374 369
375 virtual void OnLoginSuccess(const std::string& username, 370 virtual void OnLoginSuccess(const std::string& username,
376 const std::string& password, 371 const std::string& password,
377 bool pending_requests, 372 bool pending_requests,
378 bool using_oauth) OVERRIDE { 373 bool using_oauth) OVERRIDE {
379 FAIL() << "OnLoginSuccess not expected"; 374 FAIL() << "OnLoginSuccess not expected";
380 } 375 }
381 376
382 void LockDevice(const std::string& username) { 377 void EnrollDevice(const std::string& username) {
383 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall()) 378 EXPECT_CALL(*cryptohome_, InstallAttributesIsFirstInstall())
384 .WillOnce(Return(true)) 379 .WillOnce(Return(true))
385 .WillRepeatedly(Return(false)); 380 .WillRepeatedly(Return(false));
386 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, 381 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS,
387 connector_->GetInstallAttributes()->LockDevice( 382 connector_->GetInstallAttributes()->LockDevice(
388 username, policy::DEVICE_MODE_ENTERPRISE, kDeviceId)); 383 username, policy::DEVICE_MODE_ENTERPRISE, kDeviceId));
389 RunUntilIdle(); 384 RunUntilIdle();
390 } 385 }
391 386
392 void PrepareProfile(const std::string& username) { 387 void PrepareProfile(const std::string& username) {
393 ScopedDeviceSettingsTestHelper device_settings_test_helper; 388 ScopedDeviceSettingsTestHelper device_settings_test_helper;
394 MockSessionManagerClient* session_manager_client = 389 MockSessionManagerClient* session_manager_client =
395 mock_dbus_thread_manager_.mock_session_manager_client(); 390 mock_dbus_thread_manager_.mock_session_manager_client();
396 EXPECT_CALL(*session_manager_client, StartSession(_)); 391 EXPECT_CALL(*session_manager_client, StartSession(_));
397 EXPECT_CALL(*cryptohome_, GetSystemSalt()) 392 EXPECT_CALL(*cryptohome_, GetSystemSalt())
398 .WillRepeatedly(Return(std::string("stub_system_salt"))); 393 .WillRepeatedly(Return(std::string("stub_system_salt")));
399 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _)) 394 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _))
400 .WillRepeatedly(Return()); 395 .WillRepeatedly(Return());
401 396
402 scoped_refptr<Authenticator> authenticator = 397 scoped_refptr<Authenticator> authenticator =
403 LoginUtils::Get()->CreateAuthenticator(this); 398 LoginUtils::Get()->CreateAuthenticator(this);
404 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(), 399 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(),
405 username, 400 username,
406 "password"); 401 "password");
407 402
408 const bool kPendingRequests = false; 403 const bool kPendingRequests = false;
409 const bool kUsingOAuth = true; 404 const bool kUsingOAuth = true;
410 const bool kHasCookies = true; 405 // Setting |kHasCookies| to false prevents ProfileAuthData::Transfer from
406 // waiting for an IO task before proceeding.
407 const bool kHasCookies = false;
Joao da Silva 2013/01/11 12:25:50 This prevents the UI->IO->UI jump at ProfileAuthDa
411 LoginUtils::Get()->PrepareProfile(username, std::string(), "password", 408 LoginUtils::Get()->PrepareProfile(username, std::string(), "password",
412 kPendingRequests, kUsingOAuth, 409 kPendingRequests, kUsingOAuth,
413 kHasCookies, this); 410 kHasCookies, this);
414 device_settings_test_helper.Flush(); 411 device_settings_test_helper.Flush();
415 RunUntilIdle(); 412 RunUntilIdle();
416 } 413 }
417 414
418 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) { 415 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) {
419 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); 416 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0);
420 EXPECT_TRUE(fetcher); 417 EXPECT_TRUE(fetcher);
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 MockDBusThreadManager mock_dbus_thread_manager_; 479 MockDBusThreadManager mock_dbus_thread_manager_;
483 input_method::MockInputMethodManager mock_input_method_manager_; 480 input_method::MockInputMethodManager mock_input_method_manager_;
484 disks::MockDiskMountManager mock_disk_mount_manager_; 481 disks::MockDiskMountManager mock_disk_mount_manager_;
485 net::TestURLFetcherFactory test_url_fetcher_factory_; 482 net::TestURLFetcherFactory test_url_fetcher_factory_;
486 483
487 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; 484 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_;
488 485
489 policy::BrowserPolicyConnector* connector_; 486 policy::BrowserPolicyConnector* connector_;
490 MockCryptohomeLibrary* cryptohome_; 487 MockCryptohomeLibrary* cryptohome_;
491 Profile* prepared_profile_; 488 Profile* prepared_profile_;
492 Profile* created_profile_;
493 489
494 base::Closure rlz_initialized_cb_; 490 base::Closure rlz_initialized_cb_;
495 491
496 private: 492 private:
497 base::ScopedTempDir scoped_temp_dir_; 493 base::ScopedTempDir scoped_temp_dir_;
498 494
499 std::string device_policy_; 495 std::string device_policy_;
500 std::string user_policy_; 496 std::string user_policy_;
501 497
502 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest); 498 DISALLOW_COPY_AND_ASSIGN(LoginUtilsTest);
503 }; 499 };
504 500
505 class LoginUtilsBlockingLoginTest 501 class LoginUtilsBlockingLoginTest
506 : public LoginUtilsTest, 502 : public LoginUtilsTest,
507 public testing::WithParamInterface<int> {}; 503 public testing::WithParamInterface<int> {};
508 504
509 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) { 505 TEST_F(LoginUtilsTest, NormalLoginDoesntBlock) {
510 UserManager* user_manager = UserManager::Get(); 506 UserManager* user_manager = UserManager::Get();
511 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); 507 EXPECT_FALSE(user_manager->IsUserLoggedIn());
512 EXPECT_FALSE(connector_->IsEnterpriseManaged()); 508 EXPECT_FALSE(connector_->IsEnterpriseManaged());
513 EXPECT_FALSE(prepared_profile_); 509 EXPECT_FALSE(prepared_profile_);
510 EXPECT_EQ(policy::USER_AFFILIATION_NONE,
511 connector_->GetUserAffiliation(kUsername));
514 512
515 // The profile will be created without waiting for a policy response. 513 // The profile will be created without waiting for a policy response.
516 PrepareProfile(kUsername); 514 PrepareProfile(kUsername);
517 515
518 // This should shortcut cookie transfer step that is missing due to
519 // IO thread being mocked.
520 EXPECT_TRUE(created_profile_);
521 LoginUtils::Get()->CompleteProfileCreate(created_profile_);
522
523 EXPECT_TRUE(prepared_profile_); 516 EXPECT_TRUE(prepared_profile_);
524 ASSERT_TRUE(user_manager->IsUserLoggedIn()); 517 ASSERT_TRUE(user_manager->IsUserLoggedIn());
525 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email()); 518 EXPECT_EQ(kUsername, user_manager->GetLoggedInUser()->email());
526 } 519 }
527 520
528 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) { 521 TEST_F(LoginUtilsTest, EnterpriseLoginDoesntBlockForNormalUser) {
529 UserManager* user_manager = UserManager::Get(); 522 UserManager* user_manager = UserManager::Get();
530 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); 523 EXPECT_FALSE(user_manager->IsUserLoggedIn());
531 EXPECT_FALSE(connector_->IsEnterpriseManaged()); 524 EXPECT_FALSE(connector_->IsEnterpriseManaged());
532 EXPECT_FALSE(prepared_profile_); 525 EXPECT_FALSE(prepared_profile_);
533 526
534 // Enroll the device. 527 // Enroll the device.
535 LockDevice(kUsername); 528 EnrollDevice(kUsername);
536 529
537 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); 530 EXPECT_FALSE(user_manager->IsUserLoggedIn());
538 EXPECT_TRUE(connector_->IsEnterpriseManaged()); 531 EXPECT_TRUE(connector_->IsEnterpriseManaged());
539 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); 532 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain());
540 EXPECT_FALSE(prepared_profile_); 533 EXPECT_FALSE(prepared_profile_);
534 EXPECT_EQ(policy::USER_AFFILIATION_NONE,
535 connector_->GetUserAffiliation(kUsernameOtherDomain));
541 536
542 // Login with a non-enterprise user shouldn't block. 537 // Login with a non-enterprise user shouldn't block.
543 PrepareProfile(kUsernameOtherDomain); 538 PrepareProfile(kUsernameOtherDomain);
544 539
545 // This should shortcut cookie transfer step that is missing due to
546 // IO thread being mocked.
547 EXPECT_TRUE(created_profile_);
548 LoginUtils::Get()->CompleteProfileCreate(created_profile_);
549
550 EXPECT_TRUE(prepared_profile_); 540 EXPECT_TRUE(prepared_profile_);
551 ASSERT_TRUE(user_manager->IsUserLoggedIn()); 541 ASSERT_TRUE(user_manager->IsUserLoggedIn());
552 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email()); 542 EXPECT_EQ(kUsernameOtherDomain, user_manager->GetLoggedInUser()->email());
553 } 543 }
554 544
555 #if defined(ENABLE_RLZ) 545 #if defined(ENABLE_RLZ)
556 TEST_F(LoginUtilsTest, RlzInitialized) { 546 TEST_F(LoginUtilsTest, RlzInitialized) {
557 // No RLZ brand code set initially. 547 // No RLZ brand code set initially.
558 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); 548 EXPECT_FALSE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand));
559 549
560 base::RunLoop wait_for_rlz_init; 550 base::RunLoop wait_for_rlz_init;
561 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure(); 551 rlz_initialized_cb_ = wait_for_rlz_init.QuitClosure();
562 552
563 PrepareProfile(kUsername); 553 PrepareProfile(kUsername);
564 554
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
570 wait_for_rlz_init.Run(); 555 wait_for_rlz_init.Run();
571 // Wait for blocking RLZ tasks to complete. 556 // Wait for blocking RLZ tasks to complete.
572 RunUntilIdle(); 557 RunUntilIdle();
573 558
574 // RLZ brand code has been set to empty string. 559 // RLZ brand code has been set to empty string.
575 EXPECT_TRUE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand)); 560 EXPECT_TRUE(local_state_.Get()->HasPrefPath(prefs::kRLZBrand));
576 EXPECT_EQ(std::string(), local_state_.Get()->GetString(prefs::kRLZBrand)); 561 EXPECT_EQ(std::string(), local_state_.Get()->GetString(prefs::kRLZBrand));
577 562
578 // RLZ value for homepage access point should have been initialized. 563 // RLZ value for homepage access point should have been initialized.
579 string16 rlz_string; 564 string16 rlz_string;
580 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( 565 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
581 RLZTracker::CHROME_HOME_PAGE, &rlz_string)); 566 RLZTracker::CHROME_HOME_PAGE, &rlz_string));
582 EXPECT_EQ(string16(), rlz_string); 567 EXPECT_EQ(string16(), rlz_string);
583 } 568 }
584 #endif 569 #endif
585 570
586 TEST_P(LoginUtilsBlockingLoginTest, EnterpriseLoginBlocksForEnterpriseUser) { 571 TEST_P(LoginUtilsBlockingLoginTest, EnterpriseLoginBlocksForEnterpriseUser) {
587 UserManager* user_manager = UserManager::Get(); 572 UserManager* user_manager = UserManager::Get();
588 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); 573 EXPECT_FALSE(user_manager->IsUserLoggedIn());
589 EXPECT_FALSE(connector_->IsEnterpriseManaged()); 574 EXPECT_FALSE(connector_->IsEnterpriseManaged());
590 EXPECT_FALSE(prepared_profile_); 575 EXPECT_FALSE(prepared_profile_);
591 576
592 // Enroll the device. 577 // Enroll the device.
593 LockDevice(kUsername); 578 EnrollDevice(kUsername);
594 579
595 ASSERT_TRUE(!user_manager->IsUserLoggedIn()); 580 EXPECT_FALSE(user_manager->IsUserLoggedIn());
596 EXPECT_TRUE(connector_->IsEnterpriseManaged()); 581 EXPECT_TRUE(connector_->IsEnterpriseManaged());
597 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain()); 582 EXPECT_EQ(kDomain, connector_->GetEnterpriseDomain());
598 EXPECT_FALSE(prepared_profile_); 583 EXPECT_FALSE(prepared_profile_);
584 EXPECT_EQ(policy::USER_AFFILIATION_MANAGED,
585 connector_->GetUserAffiliation(kUsername));
586 EXPECT_FALSE(user_manager->IsKnownUser(kUsername));
599 587
600 // Login with a user of the enterprise domain waits for policy. 588 // Login with a user of the enterprise domain waits for policy.
601 PrepareProfile(kUsername); 589 PrepareProfile(kUsername);
602 590
603 EXPECT_FALSE(prepared_profile_); 591 EXPECT_FALSE(prepared_profile_);
604 ASSERT_TRUE(user_manager->IsUserLoggedIn()); 592 ASSERT_TRUE(user_manager->IsUserLoggedIn());
593 EXPECT_TRUE(user_manager->IsCurrentUserNew());
605 594
606 GaiaUrls* gaia_urls = GaiaUrls::GetInstance(); 595 GaiaUrls* gaia_urls = GaiaUrls::GetInstance();
607 net::TestURLFetcher* fetcher; 596 net::TestURLFetcher* fetcher;
608 597
609 // |steps| is the test parameter, and is the number of successful fetches. 598 // |steps| is the test parameter, and is the number of successful fetches.
610 // The first incomplete fetch will fail. In any case, the profile creation 599 // The first incomplete fetch will fail. In any case, the profile creation
611 // should resume. 600 // should resume.
612 int steps = GetParam(); 601 int steps = GetParam();
613 602
614 do { 603 do {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 // Verify that the profile hasn't been created yet. 650 // Verify that the profile hasn't been created yet.
662 EXPECT_FALSE(prepared_profile_); 651 EXPECT_FALSE(prepared_profile_);
663 652
664 // Make the current fetcher fail. 653 // Make the current fetcher fail.
665 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); 654 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0);
666 ASSERT_TRUE(fetcher); 655 ASSERT_TRUE(fetcher);
667 EXPECT_TRUE(fetcher->delegate()); 656 EXPECT_TRUE(fetcher->delegate());
668 fetcher->set_url(fetcher->GetOriginalURL()); 657 fetcher->set_url(fetcher->GetOriginalURL());
669 fetcher->set_response_code(500); 658 fetcher->set_response_code(500);
670 fetcher->delegate()->OnURLFetchComplete(fetcher); 659 fetcher->delegate()->OnURLFetchComplete(fetcher);
660 RunUntilIdle();
671 } 661 }
672 662
673 // This should shortcut cookie transfer step that is missing due to
674 // IO thread being mocked.
675 EXPECT_TRUE(created_profile_);
676 LoginUtils::Get()->CompleteProfileCreate(created_profile_);
677
678 // The profile is finally ready: 663 // The profile is finally ready:
679 EXPECT_TRUE(prepared_profile_); 664 EXPECT_TRUE(prepared_profile_);
680 } 665 }
681 666
682 INSTANTIATE_TEST_CASE_P( 667 INSTANTIATE_TEST_CASE_P(
683 LoginUtilsBlockingLoginTestInstance, 668 LoginUtilsBlockingLoginTestInstance,
684 LoginUtilsBlockingLoginTest, 669 LoginUtilsBlockingLoginTest,
685 testing::Values(0, 1, 2, 3, 4, 5)); 670 testing::Values(0, 1, 2, 3, 4, 5));
686 671
687 } // namespace 672 } // namespace
688 673
689 } 674 }
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/login_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698