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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/compiler_specific.h" | 15 #include "base/compiler_specific.h" |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 20 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" | 21 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
22 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" | 22 #include "chrome/browser/chromeos/policy/device_cloud_policy_initializer.h" |
23 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" | 23 #include "chrome/browser/chromeos/policy/device_cloud_policy_store_chromeos.h" |
24 #include "chrome/browser/chromeos/policy/enrollment_config.h" | 24 #include "chrome/browser/chromeos/policy/enrollment_config.h" |
25 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" | 25 #include "chrome/browser/chromeos/policy/enrollment_status_chromeos.h" |
26 #include "chrome/browser/chromeos/policy/enterprise_install_attributes.h" | |
27 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 26 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
28 #include "chrome/browser/chromeos/settings/cros_settings.h" | 27 #include "chrome/browser/chromeos/settings/cros_settings.h" |
29 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" | 28 #include "chrome/browser/chromeos/settings/device_oauth2_token_service.h" |
30 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" | 29 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
31 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 30 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
32 #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/install_attributes.h" |
33 #include "chrome/browser/prefs/browser_prefs.h" | 33 #include "chrome/browser/prefs/browser_prefs.h" |
34 #include "chrome/test/base/testing_browser_process.h" | 34 #include "chrome/test/base/testing_browser_process.h" |
35 #include "chrome/test/base/testing_profile.h" | 35 #include "chrome/test/base/testing_profile.h" |
36 #include "chromeos/attestation/mock_attestation_flow.h" | 36 #include "chromeos/attestation/mock_attestation_flow.h" |
37 #include "chromeos/cryptohome/async_method_caller.h" | 37 #include "chromeos/cryptohome/async_method_caller.h" |
38 #include "chromeos/cryptohome/system_salt_getter.h" | 38 #include "chromeos/cryptohome/system_salt_getter.h" |
39 #include "chromeos/dbus/dbus_client_implementation_type.h" | 39 #include "chromeos/dbus/dbus_client_implementation_type.h" |
40 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
41 #include "chromeos/dbus/fake_cryptohome_client.h" | 41 #include "chromeos/dbus/fake_cryptohome_client.h" |
42 #include "chromeos/dbus/fake_session_manager_client.h" | 42 #include "chromeos/dbus/fake_session_manager_client.h" |
(...skipping 28 matching lines...) Expand all Loading... |
71 using testing::StrictMock; | 71 using testing::StrictMock; |
72 using testing::WithArgs; | 72 using testing::WithArgs; |
73 using testing::_; | 73 using testing::_; |
74 | 74 |
75 namespace em = enterprise_management; | 75 namespace em = enterprise_management; |
76 | 76 |
77 namespace policy { | 77 namespace policy { |
78 namespace { | 78 namespace { |
79 | 79 |
80 void CopyLockResult(base::RunLoop* loop, | 80 void CopyLockResult(base::RunLoop* loop, |
81 EnterpriseInstallAttributes::LockResult* out, | 81 chromeos::InstallAttributes::LockResult* out, |
82 EnterpriseInstallAttributes::LockResult result) { | 82 chromeos::InstallAttributes::LockResult result) { |
83 *out = result; | 83 *out = result; |
84 loop->Quit(); | 84 loop->Quit(); |
85 } | 85 } |
86 | 86 |
87 void CertCallbackSuccess( | 87 void CertCallbackSuccess( |
88 const chromeos::attestation::AttestationFlow::CertificateCallback& | 88 const chromeos::attestation::AttestationFlow::CertificateCallback& |
89 callback) { | 89 callback) { |
90 base::ThreadTaskRunnerHandle::Get()->PostTask( | 90 base::ThreadTaskRunnerHandle::Get()->PostTask( |
91 FROM_HERE, base::Bind(callback, true, "fake_cert")); | 91 FROM_HERE, base::Bind(callback, true, "fake_cert")); |
92 } | 92 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 virtual bool ShouldRegisterWithCert() const { return false; } | 128 virtual bool ShouldRegisterWithCert() const { return false; } |
129 | 129 |
130 void SetUp() override { | 130 void SetUp() override { |
131 DeviceSettingsTestBase::SetUp(); | 131 DeviceSettingsTestBase::SetUp(); |
132 dbus_setter_->SetCryptohomeClient( | 132 dbus_setter_->SetCryptohomeClient( |
133 std::unique_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); | 133 std::unique_ptr<chromeos::CryptohomeClient>(fake_cryptohome_client_)); |
134 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); | 134 chromeos::DBusThreadManager::Get()->GetCryptohomeClient(); |
135 cryptohome::AsyncMethodCaller::Initialize(); | 135 cryptohome::AsyncMethodCaller::Initialize(); |
136 | 136 |
137 install_attributes_.reset( | 137 install_attributes_.reset( |
138 new EnterpriseInstallAttributes(fake_cryptohome_client_)); | 138 new chromeos::InstallAttributes(fake_cryptohome_client_)); |
139 store_ = new DeviceCloudPolicyStoreChromeOS( | 139 store_ = new DeviceCloudPolicyStoreChromeOS( |
140 &device_settings_service_, install_attributes_.get(), | 140 &device_settings_service_, install_attributes_.get(), |
141 base::ThreadTaskRunnerHandle::Get()); | 141 base::ThreadTaskRunnerHandle::Get()); |
142 manager_.reset(new TestingDeviceCloudPolicyManagerChromeOS( | 142 manager_.reset(new TestingDeviceCloudPolicyManagerChromeOS( |
143 base::WrapUnique(store_), base::ThreadTaskRunnerHandle::Get(), | 143 base::WrapUnique(store_), base::ThreadTaskRunnerHandle::Get(), |
144 &state_keys_broker_)); | 144 &state_keys_broker_)); |
145 | 145 |
146 chrome::RegisterLocalState(local_state_.registry()); | 146 chrome::RegisterLocalState(local_state_.registry()); |
147 manager_->Init(&schema_registry_); | 147 manager_->Init(&schema_registry_); |
148 | 148 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 initializer_->Shutdown(); | 185 initializer_->Shutdown(); |
186 DeviceSettingsTestBase::TearDown(); | 186 DeviceSettingsTestBase::TearDown(); |
187 | 187 |
188 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); | 188 chromeos::DeviceOAuth2TokenServiceFactory::Shutdown(); |
189 chromeos::SystemSaltGetter::Shutdown(); | 189 chromeos::SystemSaltGetter::Shutdown(); |
190 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); | 190 TestingBrowserProcess::GetGlobal()->SetLocalState(NULL); |
191 } | 191 } |
192 | 192 |
193 void LockDevice() { | 193 void LockDevice() { |
194 base::RunLoop loop; | 194 base::RunLoop loop; |
195 EnterpriseInstallAttributes::LockResult result; | 195 chromeos::InstallAttributes::LockResult result; |
196 install_attributes_->LockDevice( | 196 install_attributes_->LockDevice( |
197 PolicyBuilder::kFakeUsername, | 197 PolicyBuilder::kFakeUsername, |
198 DEVICE_MODE_ENTERPRISE, | 198 DEVICE_MODE_ENTERPRISE, |
199 PolicyBuilder::kFakeDeviceId, | 199 PolicyBuilder::kFakeDeviceId, |
200 base::Bind(&CopyLockResult, &loop, &result)); | 200 base::Bind(&CopyLockResult, &loop, &result)); |
201 loop.Run(); | 201 loop.Run(); |
202 ASSERT_EQ(EnterpriseInstallAttributes::LOCK_SUCCESS, result); | 202 ASSERT_EQ(chromeos::InstallAttributes::LOCK_SUCCESS, result); |
203 } | 203 } |
204 | 204 |
205 void ConnectManager() { | 205 void ConnectManager() { |
206 std::unique_ptr<chromeos::attestation::AttestationFlow> unique_flow( | 206 std::unique_ptr<chromeos::attestation::AttestationFlow> unique_flow( |
207 CreateAttestationFlow()); | 207 CreateAttestationFlow()); |
208 manager_->Initialize(&local_state_); | 208 manager_->Initialize(&local_state_); |
209 manager_->AddDeviceCloudPolicyManagerObserver(this); | 209 manager_->AddDeviceCloudPolicyManagerObserver(this); |
210 initializer_.reset(new DeviceCloudPolicyInitializer( | 210 initializer_.reset(new DeviceCloudPolicyInitializer( |
211 &local_state_, &device_management_service_, | 211 &local_state_, &device_management_service_, |
212 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(), | 212 base::ThreadTaskRunnerHandle::Get(), install_attributes_.get(), |
(...skipping 23 matching lines...) Expand all Loading... |
236 DM_STATUS_TEMPORARY_UNAVAILABLE)); | 236 DM_STATUS_TEMPORARY_UNAVAILABLE)); |
237 EXPECT_CALL( | 237 EXPECT_CALL( |
238 device_management_service_, | 238 device_management_service_, |
239 StartJob(dm_protocol::kValueRequestRemoteCommands, _, _, _, _, _)) | 239 StartJob(dm_protocol::kValueRequestRemoteCommands, _, _, _, _, _)) |
240 .Times(AnyNumber()); | 240 .Times(AnyNumber()); |
241 } | 241 } |
242 | 242 |
243 MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void()); | 243 MOCK_METHOD0(OnDeviceCloudPolicyManagerConnected, void()); |
244 MOCK_METHOD0(OnDeviceCloudPolicyManagerDisconnected, void()); | 244 MOCK_METHOD0(OnDeviceCloudPolicyManagerDisconnected, void()); |
245 | 245 |
246 std::unique_ptr<EnterpriseInstallAttributes> install_attributes_; | 246 std::unique_ptr<chromeos::InstallAttributes> install_attributes_; |
247 | 247 |
248 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 248 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
249 net::TestURLFetcherFactory url_fetcher_factory_; | 249 net::TestURLFetcherFactory url_fetcher_factory_; |
250 int url_fetcher_response_code_; | 250 int url_fetcher_response_code_; |
251 std::string url_fetcher_response_string_; | 251 std::string url_fetcher_response_string_; |
252 TestingPrefServiceSimple local_state_; | 252 TestingPrefServiceSimple local_state_; |
253 MockDeviceManagementService device_management_service_; | 253 MockDeviceManagementService device_management_service_; |
254 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 254 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
255 chromeos::ScopedTestCrosSettings test_cros_settings_; | 255 chromeos::ScopedTestCrosSettings test_cros_settings_; |
256 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; | 256 chromeos::system::ScopedFakeStatisticsProvider fake_statistics_provider_; |
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 DeviceCloudPolicyManagerChromeOSEnrollmentTest, | 793 DeviceCloudPolicyManagerChromeOSEnrollmentTest, |
794 ::testing::Values(false, true)); | 794 ::testing::Values(false, true)); |
795 | 795 |
796 INSTANTIATE_TEST_CASE_P( | 796 INSTANTIATE_TEST_CASE_P( |
797 Cert, | 797 Cert, |
798 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, | 798 DeviceCloudPolicyManagerChromeOSEnrollmentBlankSystemSaltTest, |
799 ::testing::Values(false, true)); | 799 ::testing::Values(false, true)); |
800 | 800 |
801 } // namespace | 801 } // namespace |
802 } // namespace policy | 802 } // namespace policy |
OLD | NEW |