| 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" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/prefs/pref_registry_simple.h" | 13 #include "base/prefs/pref_registry_simple.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
| 17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
| 18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
| 19 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" | 20 #include "chrome/browser/chromeos/cros/mock_cryptohome_library.h" |
| 21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" | 21 #include "chrome/browser/chromeos/input_method/input_method_configuration.h" |
| 22 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" | 22 #include "chrome/browser/chromeos/input_method/mock_input_method_manager.h" |
| 23 #include "chrome/browser/chromeos/login/authenticator.h" | 23 #include "chrome/browser/chromeos/login/authenticator.h" |
| 24 #include "chrome/browser/chromeos/login/login_status_consumer.h" | 24 #include "chrome/browser/chromeos/login/login_status_consumer.h" |
| 25 #include "chrome/browser/chromeos/login/user_manager.h" | 25 #include "chrome/browser/chromeos/login/user_manager.h" |
| 26 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" | 26 #include "chrome/browser/chromeos/net/connectivity_state_helper.h" |
| 27 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" | 27 #include "chrome/browser/chromeos/net/mock_connectivity_state_helper.h" |
| 28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 28 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 29 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 30 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 29 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 31 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 32 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" |
| 30 #include "chrome/browser/io_thread.h" | 33 #include "chrome/browser/io_thread.h" |
| 31 #include "chrome/browser/net/predictor.h" | 34 #include "chrome/browser/net/predictor.h" |
| 32 #include "chrome/browser/policy/browser_policy_connector.h" | 35 #include "chrome/browser/policy/browser_policy_connector.h" |
| 33 #include "chrome/browser/policy/cloud/device_management_service.h" | 36 #include "chrome/browser/policy/cloud/device_management_service.h" |
| 34 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" | 37 #include "chrome/browser/policy/cloud/proto/device_management_backend.pb.h" |
| 35 #include "chrome/browser/policy/policy_service.h" | 38 #include "chrome/browser/policy/policy_service.h" |
| 36 #include "chrome/browser/profiles/profile_manager.h" | 39 #include "chrome/browser/profiles/profile_manager.h" |
| 37 #include "chrome/browser/rlz/rlz.h" | 40 #include "chrome/browser/rlz/rlz.h" |
| 38 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 39 #include "chrome/common/chrome_paths.h" | 42 #include "chrome/common/chrome_paths.h" |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), | 286 .WillRepeatedly(DoAll(SetArgPointee<1>(kMode), |
| 284 Return(true))); | 287 Return(true))); |
| 285 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) | 288 EXPECT_CALL(*cryptohome_, InstallAttributesGet(kAttrEnterpriseDeviceId, _)) |
| 286 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), | 289 .WillRepeatedly(DoAll(SetArgPointee<1>(kDeviceId), |
| 287 Return(true))); | 290 Return(true))); |
| 288 test_api->SetCryptohomeLibrary(cryptohome_, true); | 291 test_api->SetCryptohomeLibrary(cryptohome_, true); |
| 289 | 292 |
| 290 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); | 293 cryptohome_client_ = mock_dbus_thread_manager_.mock_cryptohome_client(); |
| 291 EXPECT_CALL(*cryptohome_client_, IsMounted(_)); | 294 EXPECT_CALL(*cryptohome_client_, IsMounted(_)); |
| 292 | 295 |
| 296 test_cros_settings_.reset(new ScopedTestCrosSettings); |
| 297 |
| 293 browser_process_->SetProfileManager( | 298 browser_process_->SetProfileManager( |
| 294 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); | 299 new ProfileManagerWithoutInit(scoped_temp_dir_.path())); |
| 295 connector_ = browser_process_->browser_policy_connector(); | 300 connector_ = browser_process_->browser_policy_connector(); |
| 296 connector_->Init(local_state_.Get(), | 301 connector_->Init(local_state_.Get(), |
| 297 browser_process_->system_request_context()); | 302 browser_process_->system_request_context()); |
| 298 | 303 |
| 299 io_thread_state_.reset(new IOThread(local_state_.Get(), | 304 io_thread_state_.reset(new IOThread(local_state_.Get(), |
| 300 browser_process_->policy_service(), | 305 browser_process_->policy_service(), |
| 301 NULL, NULL)); | 306 NULL, NULL)); |
| 302 browser_process_->SetIOThread(io_thread_state_.get()); | 307 browser_process_->SetIOThread(io_thread_state_.get()); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 412 policy::EnterpriseInstallAttributes::LockResult result; | 417 policy::EnterpriseInstallAttributes::LockResult result; |
| 413 connector_->GetInstallAttributes()->LockDevice( | 418 connector_->GetInstallAttributes()->LockDevice( |
| 414 username, policy::DEVICE_MODE_ENTERPRISE, kDeviceId, | 419 username, policy::DEVICE_MODE_ENTERPRISE, kDeviceId, |
| 415 base::Bind(&CopyLockResult, &loop, &result)); | 420 base::Bind(&CopyLockResult, &loop, &result)); |
| 416 loop.Run(); | 421 loop.Run(); |
| 417 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, result); | 422 EXPECT_EQ(policy::EnterpriseInstallAttributes::LOCK_SUCCESS, result); |
| 418 RunUntilIdle(); | 423 RunUntilIdle(); |
| 419 } | 424 } |
| 420 | 425 |
| 421 void PrepareProfile(const std::string& username) { | 426 void PrepareProfile(const std::string& username) { |
| 422 ScopedDeviceSettingsTestHelper device_settings_test_helper; | 427 DeviceSettingsTestHelper device_settings_test_helper; |
| 428 DeviceSettingsService::Get()->SetSessionManager( |
| 429 &device_settings_test_helper, new MockOwnerKeyUtil()); |
| 430 |
| 423 MockSessionManagerClient* session_manager_client = | 431 MockSessionManagerClient* session_manager_client = |
| 424 mock_dbus_thread_manager_.mock_session_manager_client(); | 432 mock_dbus_thread_manager_.mock_session_manager_client(); |
| 425 EXPECT_CALL(*session_manager_client, StartSession(_)); | 433 EXPECT_CALL(*session_manager_client, StartSession(_)); |
| 426 EXPECT_CALL(*cryptohome_, GetSystemSalt()) | 434 EXPECT_CALL(*cryptohome_, GetSystemSalt()) |
| 427 .WillRepeatedly(Return(std::string("stub_system_salt"))); | 435 .WillRepeatedly(Return(std::string("stub_system_salt"))); |
| 428 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _)) | 436 EXPECT_CALL(*mock_async_method_caller_, AsyncMount(_, _, _, _)) |
| 429 .WillRepeatedly(Return()); | 437 .WillRepeatedly(Return()); |
| 430 EXPECT_CALL(*mock_async_method_caller_, AsyncGetSanitizedUsername(_, _)) | 438 EXPECT_CALL(*mock_async_method_caller_, AsyncGetSanitizedUsername(_, _)) |
| 431 .WillRepeatedly(Return()); | 439 .WillRepeatedly(Return()); |
| 432 | 440 |
| 433 scoped_refptr<Authenticator> authenticator = | 441 scoped_refptr<Authenticator> authenticator = |
| 434 LoginUtils::Get()->CreateAuthenticator(this); | 442 LoginUtils::Get()->CreateAuthenticator(this); |
| 435 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(), | 443 authenticator->CompleteLogin(ProfileManager::GetDefaultProfile(), |
| 436 UserContext(username, | 444 UserContext(username, |
| 437 "password", | 445 "password", |
| 438 std::string(), | 446 std::string(), |
| 439 username)); // username_hash | 447 username)); // username_hash |
| 440 | 448 |
| 441 const bool kUsingOAuth = true; | 449 const bool kUsingOAuth = true; |
| 442 // Setting |kHasCookies| to false prevents ProfileAuthData::Transfer from | 450 // Setting |kHasCookies| to false prevents ProfileAuthData::Transfer from |
| 443 // waiting for an IO task before proceeding. | 451 // waiting for an IO task before proceeding. |
| 444 const bool kHasCookies = false; | 452 const bool kHasCookies = false; |
| 445 LoginUtils::Get()->PrepareProfile( | 453 LoginUtils::Get()->PrepareProfile( |
| 446 UserContext(username, "password", std::string(), username), | 454 UserContext(username, "password", std::string(), username), |
| 447 std::string(), kUsingOAuth, kHasCookies, this); | 455 std::string(), kUsingOAuth, kHasCookies, this); |
| 448 device_settings_test_helper.Flush(); | 456 device_settings_test_helper.Flush(); |
| 449 RunUntilIdle(); | 457 RunUntilIdle(); |
| 458 |
| 459 DeviceSettingsService::Get()->UnsetSessionManager(); |
| 450 } | 460 } |
| 451 | 461 |
| 452 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) { | 462 net::TestURLFetcher* PrepareOAuthFetcher(const std::string& expected_url) { |
| 453 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); | 463 net::TestURLFetcher* fetcher = test_url_fetcher_factory_.GetFetcherByID(0); |
| 454 EXPECT_TRUE(fetcher); | 464 EXPECT_TRUE(fetcher); |
| 455 if (!fetcher) | 465 if (!fetcher) |
| 456 return NULL; | 466 return NULL; |
| 457 EXPECT_TRUE(fetcher->delegate()); | 467 EXPECT_TRUE(fetcher->delegate()); |
| 458 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(), | 468 EXPECT_TRUE(StartsWithASCII(fetcher->GetOriginalURL().spec(), |
| 459 expected_url, | 469 expected_url, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 input_method::MockInputMethodManager mock_input_method_manager_; | 532 input_method::MockInputMethodManager mock_input_method_manager_; |
| 523 disks::MockDiskMountManager mock_disk_mount_manager_; | 533 disks::MockDiskMountManager mock_disk_mount_manager_; |
| 524 net::TestURLFetcherFactory test_url_fetcher_factory_; | 534 net::TestURLFetcherFactory test_url_fetcher_factory_; |
| 525 MockConnectivityStateHelper mock_connectivity_state_helper_; | 535 MockConnectivityStateHelper mock_connectivity_state_helper_; |
| 526 | 536 |
| 527 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; | 537 cryptohome::MockAsyncMethodCaller* mock_async_method_caller_; |
| 528 | 538 |
| 529 policy::BrowserPolicyConnector* connector_; | 539 policy::BrowserPolicyConnector* connector_; |
| 530 MockCryptohomeLibrary* cryptohome_; | 540 MockCryptohomeLibrary* cryptohome_; |
| 531 MockCryptohomeClient* cryptohome_client_; | 541 MockCryptohomeClient* cryptohome_client_; |
| 542 |
| 543 // Initialized after |mock_dbus_thread_manager_| and |cryptohome_| are set up. |
| 544 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; |
| 545 |
| 532 Profile* prepared_profile_; | 546 Profile* prepared_profile_; |
| 533 | 547 |
| 534 base::Closure rlz_initialized_cb_; | 548 base::Closure rlz_initialized_cb_; |
| 535 | 549 |
| 536 private: | 550 private: |
| 537 base::ScopedTempDir scoped_temp_dir_; | 551 base::ScopedTempDir scoped_temp_dir_; |
| 538 | 552 |
| 539 std::string device_policy_; | 553 std::string device_policy_; |
| 540 std::string user_policy_; | 554 std::string user_policy_; |
| 541 | 555 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 735 } |
| 722 | 736 |
| 723 INSTANTIATE_TEST_CASE_P( | 737 INSTANTIATE_TEST_CASE_P( |
| 724 LoginUtilsBlockingLoginTestInstance, | 738 LoginUtilsBlockingLoginTestInstance, |
| 725 LoginUtilsBlockingLoginTest, | 739 LoginUtilsBlockingLoginTest, |
| 726 testing::Values(0, 1, 2, 3, 4, 5)); | 740 testing::Values(0, 1, 2, 3, 4, 5)); |
| 727 | 741 |
| 728 } // namespace | 742 } // namespace |
| 729 | 743 |
| 730 } | 744 } |
| OLD | NEW |