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/settings/device_settings_test_helper.h" | 5 #include "chrome/browser/chromeos/settings/device_settings_test_helper.h" |
6 | 6 |
7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
10 #include "chrome/browser/chromeos/ownership/owner_settings_service.h" | 10 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
11 #include "chrome/browser/chromeos/ownership/owner_settings_service_factory.h" | 11 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact
ory.h" |
12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | 12 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
13 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 13 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
14 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 14 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
16 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
17 #include "chromeos/dbus/dbus_thread_manager.h" | 17 #include "chromeos/dbus/dbus_thread_manager.h" |
18 #include "components/ownership/mock_owner_key_util.h" | 18 #include "components/ownership/mock_owner_key_util.h" |
19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/browser/browser_thread.h" |
20 | 20 |
21 namespace chromeos { | 21 namespace chromeos { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { | 200 ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { |
201 Flush(); | 201 Flush(); |
202 DeviceSettingsService::Get()->UnsetSessionManager(); | 202 DeviceSettingsService::Get()->UnsetSessionManager(); |
203 DeviceSettingsService::Shutdown(); | 203 DeviceSettingsService::Shutdown(); |
204 } | 204 } |
205 | 205 |
206 DeviceSettingsTestBase::DeviceSettingsTestBase() | 206 DeviceSettingsTestBase::DeviceSettingsTestBase() |
207 : user_manager_(new FakeUserManager()), | 207 : user_manager_(new FakeUserManager()), |
208 user_manager_enabler_(user_manager_), | 208 user_manager_enabler_(user_manager_), |
209 owner_key_util_(new ownership::MockOwnerKeyUtil()) { | 209 owner_key_util_(new ownership::MockOwnerKeyUtil()) { |
210 OwnerSettingsServiceFactory::GetInstance()->SetOwnerKeyUtilForTesting( | 210 OwnerSettingsServiceChromeOSFactory::GetInstance()->SetOwnerKeyUtilForTesting( |
211 owner_key_util_); | 211 owner_key_util_); |
212 } | 212 } |
213 | 213 |
214 DeviceSettingsTestBase::~DeviceSettingsTestBase() { | 214 DeviceSettingsTestBase::~DeviceSettingsTestBase() { |
215 base::RunLoop().RunUntilIdle(); | 215 base::RunLoop().RunUntilIdle(); |
216 } | 216 } |
217 | 217 |
218 void DeviceSettingsTestBase::SetUp() { | 218 void DeviceSettingsTestBase::SetUp() { |
219 // Initialize DBusThreadManager with a stub implementation. | 219 // Initialize DBusThreadManager with a stub implementation. |
220 dbus_setter_ = chromeos::DBusThreadManager::GetSetterForTesting(); | 220 dbus_setter_ = chromeos::DBusThreadManager::GetSetterForTesting(); |
221 | 221 |
222 base::RunLoop().RunUntilIdle(); | 222 base::RunLoop().RunUntilIdle(); |
223 | 223 |
224 device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled( | 224 device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled( |
225 false); | 225 false); |
226 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); | 226 owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey()); |
227 device_policy_.Build(); | 227 device_policy_.Build(); |
228 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 228 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
229 device_settings_service_.SetSessionManager(&device_settings_test_helper_, | 229 device_settings_service_.SetSessionManager(&device_settings_test_helper_, |
230 owner_key_util_); | 230 owner_key_util_); |
231 OwnerSettingsService::SetDeviceSettingsServiceForTesting( | 231 OwnerSettingsServiceChromeOS::SetDeviceSettingsServiceForTesting( |
232 &device_settings_service_); | 232 &device_settings_service_); |
233 profile_.reset(new TestingProfile()); | 233 profile_.reset(new TestingProfile()); |
234 } | 234 } |
235 | 235 |
236 void DeviceSettingsTestBase::TearDown() { | 236 void DeviceSettingsTestBase::TearDown() { |
237 OwnerSettingsService::SetDeviceSettingsServiceForTesting(NULL); | 237 OwnerSettingsServiceChromeOS::SetDeviceSettingsServiceForTesting(NULL); |
238 FlushDeviceSettings(); | 238 FlushDeviceSettings(); |
239 device_settings_service_.UnsetSessionManager(); | 239 device_settings_service_.UnsetSessionManager(); |
240 DBusThreadManager::Shutdown(); | 240 DBusThreadManager::Shutdown(); |
241 } | 241 } |
242 | 242 |
243 void DeviceSettingsTestBase::FlushDeviceSettings() { | 243 void DeviceSettingsTestBase::FlushDeviceSettings() { |
244 device_settings_test_helper_.Flush(); | 244 device_settings_test_helper_.Flush(); |
245 } | 245 } |
246 | 246 |
247 void DeviceSettingsTestBase::ReloadDeviceSettings() { | 247 void DeviceSettingsTestBase::ReloadDeviceSettings() { |
248 device_settings_service_.OwnerKeySet(true); | 248 device_settings_service_.OwnerKeySet(true); |
249 FlushDeviceSettings(); | 249 FlushDeviceSettings(); |
250 } | 250 } |
251 | 251 |
252 void DeviceSettingsTestBase::InitOwner(const std::string& user_id, | 252 void DeviceSettingsTestBase::InitOwner(const std::string& user_id, |
253 bool tpm_is_ready) { | 253 bool tpm_is_ready) { |
254 const user_manager::User* user = user_manager_->FindUser(user_id); | 254 const user_manager::User* user = user_manager_->FindUser(user_id); |
255 if (!user) { | 255 if (!user) { |
256 user = user_manager_->AddUser(user_id); | 256 user = user_manager_->AddUser(user_id); |
257 profile_->set_profile_name(user_id); | 257 profile_->set_profile_name(user_id); |
258 | 258 |
259 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, | 259 ProfileHelper::Get()->SetUserToProfileMappingForTesting(user, |
260 profile_.get()); | 260 profile_.get()); |
261 } | 261 } |
262 OwnerSettingsService* service = | 262 OwnerSettingsServiceChromeOS* service = |
263 OwnerSettingsServiceFactory::GetForProfile(profile_.get()); | 263 OwnerSettingsServiceChromeOSFactory::GetForProfile(profile_.get()); |
264 CHECK(service); | 264 CHECK(service); |
265 if (tpm_is_ready) | 265 if (tpm_is_ready) |
266 service->OnTPMTokenReady(true /* token is enabled */); | 266 service->OnTPMTokenReady(true /* token is enabled */); |
267 } | 267 } |
268 | 268 |
269 } // namespace chromeos | 269 } // namespace chromeos |
OLD | NEW |