| 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/policy/device_cloud_policy_manager_chromeos.h" | 5 #include "chrome/browser/chromeos/policy/device_cloud_policy_manager_chromeos.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| 11 #include "base/prefs/pref_registry_simple.h" | 11 #include "base/prefs/pref_registry_simple.h" |
| 12 #include "base/prefs/testing_pref_service.h" | 12 #include "base/prefs/testing_pref_service.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 14 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
| 15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | 15 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" |
| 16 #include "chrome/browser/chromeos/settings/cros_settings.h" | 16 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 17 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
| 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 18 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
| 19 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 19 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 20 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" | 20 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
| 21 #include "chrome/browser/policy/cloud/cloud_policy_client.h" | 21 #include "chrome/browser/policy/cloud/cloud_policy_client.h" |
| 22 #include "chrome/browser/policy/cloud/mock_device_management_service.h" | 22 #include "chrome/browser/policy/cloud/mock_device_management_service.h" |
| 23 #include "chrome/browser/policy/external_data_fetcher.h" | 23 #include "chrome/browser/policy/external_data_fetcher.h" |
| 24 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" | 24 #include "chrome/browser/policy/proto/chromeos/chrome_device_policy.pb.h" |
| 25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" | 25 #include "chrome/browser/policy/proto/cloud/device_management_backend.pb.h" |
| 26 #include "chrome/browser/prefs/browser_prefs.h" | 26 #include "chrome/browser/prefs/browser_prefs.h" |
| 27 #include "chrome/test/base/testing_browser_process.h" | 27 #include "chrome/test/base/testing_browser_process.h" |
| 28 #include "chromeos/cryptohome/cryptohome_library.h" | 28 #include "chromeos/cryptohome/cryptohome_library.h" |
| 29 #include "chromeos/dbus/cryptohome_client_stub.h" | |
| 30 #include "chromeos/dbus/dbus_client_implementation_type.h" | 29 #include "chromeos/dbus/dbus_client_implementation_type.h" |
| 30 #include "chromeos/dbus/fake_cryptohome_client.h" |
| 31 #include "google_apis/gaia/gaia_oauth_client.h" | 31 #include "google_apis/gaia/gaia_oauth_client.h" |
| 32 #include "net/url_request/test_url_fetcher_factory.h" | 32 #include "net/url_request/test_url_fetcher_factory.h" |
| 33 #include "net/url_request/url_request_test_util.h" | 33 #include "net/url_request/url_request_test_util.h" |
| 34 #include "policy/policy_constants.h" | 34 #include "policy/policy_constants.h" |
| 35 #include "testing/gmock/include/gmock/gmock.h" | 35 #include "testing/gmock/include/gmock/gmock.h" |
| 36 #include "testing/gtest/include/gtest/gtest.h" | 36 #include "testing/gtest/include/gtest/gtest.h" |
| 37 | 37 |
| 38 using testing::AnyNumber; | 38 using testing::AnyNumber; |
| 39 using testing::AtMost; | 39 using testing::AtMost; |
| 40 using testing::DoAll; | 40 using testing::DoAll; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 52 EnterpriseInstallAttributes::LockResult result) { | 52 EnterpriseInstallAttributes::LockResult result) { |
| 53 *out = result; | 53 *out = result; |
| 54 loop->Quit(); | 54 loop->Quit(); |
| 55 } | 55 } |
| 56 | 56 |
| 57 class DeviceCloudPolicyManagerChromeOSTest | 57 class DeviceCloudPolicyManagerChromeOSTest |
| 58 : public chromeos::DeviceSettingsTestBase { | 58 : public chromeos::DeviceSettingsTestBase { |
| 59 protected: | 59 protected: |
| 60 DeviceCloudPolicyManagerChromeOSTest() | 60 DeviceCloudPolicyManagerChromeOSTest() |
| 61 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), | 61 : cryptohome_library_(chromeos::CryptohomeLibrary::GetTestImpl()), |
| 62 stub_cryptohome_client_(new chromeos::CryptohomeClientStubImpl()), | 62 fake_cryptohome_client_(new chromeos::FakeCryptohomeClient()), |
| 63 install_attributes_(cryptohome_library_.get(), | 63 install_attributes_(cryptohome_library_.get(), |
| 64 stub_cryptohome_client_.get()), | 64 fake_cryptohome_client_.get()), |
| 65 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, | 65 store_(new DeviceCloudPolicyStoreChromeOS(&device_settings_service_, |
| 66 &install_attributes_)), | 66 &install_attributes_)), |
| 67 manager_(make_scoped_ptr(store_), | 67 manager_(make_scoped_ptr(store_), |
| 68 loop_.message_loop_proxy(), | 68 loop_.message_loop_proxy(), |
| 69 &install_attributes_) { | 69 &install_attributes_) { |
| 70 stub_cryptohome_client_->Init(NULL /* no dbus::Bus */); | 70 fake_cryptohome_client_->Init(NULL /* no dbus::Bus */); |
| 71 } | 71 } |
| 72 | 72 |
| 73 virtual void SetUp() OVERRIDE { | 73 virtual void SetUp() OVERRIDE { |
| 74 DeviceSettingsTestBase::SetUp(); | 74 DeviceSettingsTestBase::SetUp(); |
| 75 chrome::RegisterLocalState(local_state_.registry()); | 75 chrome::RegisterLocalState(local_state_.registry()); |
| 76 manager_.Init(); | 76 manager_.Init(); |
| 77 | 77 |
| 78 // DeviceOAuth2TokenService uses the system request context to fetch | 78 // DeviceOAuth2TokenService uses the system request context to fetch |
| 79 // OAuth tokens, then writes the token to local state, encrypting it | 79 // OAuth tokens, then writes the token to local state, encrypting it |
| 80 // first with methods in CryptohomeLibrary. | 80 // first with methods in CryptohomeLibrary. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 94 virtual void TearDown() OVERRIDE { | 94 virtual void TearDown() OVERRIDE { |
| 95 manager_.Shutdown(); | 95 manager_.Shutdown(); |
| 96 DeviceSettingsTestBase::TearDown(); | 96 DeviceSettingsTestBase::TearDown(); |
| 97 | 97 |
| 98 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 98 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
| 99 chromeos::CryptohomeLibrary::SetForTest(NULL); | 99 chromeos::CryptohomeLibrary::SetForTest(NULL); |
| 100 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 100 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
| 101 } | 101 } |
| 102 | 102 |
| 103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_library_; | 103 scoped_ptr<chromeos::CryptohomeLibrary> cryptohome_library_; |
| 104 scoped_ptr<chromeos::CryptohomeClientStubImpl> stub_cryptohome_client_; | 104 scoped_ptr<chromeos::FakeCryptohomeClient> fake_cryptohome_client_; |
| 105 EnterpriseInstallAttributes install_attributes_; | 105 EnterpriseInstallAttributes install_attributes_; |
| 106 | 106 |
| 107 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 107 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
| 108 net::TestURLFetcherFactory url_fetcher_factory_; | 108 net::TestURLFetcherFactory url_fetcher_factory_; |
| 109 int url_fetcher_response_code_; | 109 int url_fetcher_response_code_; |
| 110 string url_fetcher_response_string_; | 110 string url_fetcher_response_string_; |
| 111 TestingPrefServiceSimple local_state_; | 111 TestingPrefServiceSimple local_state_; |
| 112 MockDeviceManagementService device_management_service_; | 112 MockDeviceManagementService device_management_service_; |
| 113 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 113 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 114 chromeos::ScopedTestCrosSettings test_cros_settings_; | 114 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { | 490 TEST_F(DeviceCloudPolicyManagerChromeOSEnrollmentTest, LoadError) { |
| 491 loaded_blob_.clear(); | 491 loaded_blob_.clear(); |
| 492 RunTest(); | 492 RunTest(); |
| 493 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); | 493 ExpectFailedEnrollment(EnrollmentStatus::STATUS_STORE_ERROR); |
| 494 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, | 494 EXPECT_EQ(CloudPolicyStore::STATUS_LOAD_ERROR, |
| 495 status_.store_status()); | 495 status_.store_status()); |
| 496 } | 496 } |
| 497 | 497 |
| 498 } // namespace | 498 } // namespace |
| 499 } // namespace policy | 499 } // namespace policy |
| OLD | NEW |