| 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.h" | 7 #include "base/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/policy/proto/chrome_device_policy.pb.h" | 10 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" |
| 11 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 11 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 12 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" | 12 #include "chrome/browser/chromeos/settings/mock_owner_key_util.h" |
| 13 #include "content/public/browser/browser_thread.h" | 13 #include "content/public/browser/browser_thread.h" |
| 14 | 14 |
| 15 namespace chromeos { | 15 namespace chromeos { |
| 16 | 16 |
| 17 DeviceSettingsTestHelper::DeviceSettingsTestHelper() {} | 17 DeviceSettingsTestHelper::DeviceSettingsTestHelper() { |
| 18 // DeviceSettingsTestHelper is used both by browser tests (where CrosSettings |
| 19 // is already initialized) and unit tests, where it is not. |
| 20 if (!CrosSettings::IsInitialized()) |
| 21 test_cros_settings_.reset(new ScopedTestCrosSettings); |
| 22 } |
| 18 | 23 |
| 19 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {} | 24 DeviceSettingsTestHelper::~DeviceSettingsTestHelper() { |
| 25 } |
| 20 | 26 |
| 21 void DeviceSettingsTestHelper::FlushLoops() { | 27 void DeviceSettingsTestHelper::FlushLoops() { |
| 22 // DeviceSettingsService may trigger operations that hop back and forth | 28 // DeviceSettingsService may trigger operations that hop back and forth |
| 23 // between the message loop and the blocking pool. 2 iterations are currently | 29 // between the message loop and the blocking pool. 2 iterations are currently |
| 24 // sufficient (key loading, signing). | 30 // sufficient (key loading, signing). |
| 25 for (int i = 0; i < 2; ++i) { | 31 for (int i = 0; i < 2; ++i) { |
| 26 MessageLoop::current()->RunUntilIdle(); | 32 MessageLoop::current()->RunUntilIdle(); |
| 27 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 33 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 28 } | 34 } |
| 29 MessageLoop::current()->RunUntilIdle(); | 35 MessageLoop::current()->RunUntilIdle(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 device_local_account_policy_[account_id].policy_blob_ = policy_blob; | 166 device_local_account_policy_[account_id].policy_blob_ = policy_blob; |
| 161 device_local_account_policy_[account_id].store_callbacks_.push_back(callback); | 167 device_local_account_policy_[account_id].store_callbacks_.push_back(callback); |
| 162 } | 168 } |
| 163 | 169 |
| 164 DeviceSettingsTestHelper::PolicyState::PolicyState() | 170 DeviceSettingsTestHelper::PolicyState::PolicyState() |
| 165 : store_result_(true) {} | 171 : store_result_(true) {} |
| 166 | 172 |
| 167 DeviceSettingsTestHelper::PolicyState::~PolicyState() {} | 173 DeviceSettingsTestHelper::PolicyState::~PolicyState() {} |
| 168 | 174 |
| 169 ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() { | 175 ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() { |
| 170 DeviceSettingsService::Get()->Initialize(this, new MockOwnerKeyUtil()); | 176 DeviceSettingsService::Get()->InitializeSessionManager( |
| 177 this, new MockOwnerKeyUtil()); |
| 171 DeviceSettingsService::Get()->Load(); | 178 DeviceSettingsService::Get()->Load(); |
| 172 Flush(); | 179 Flush(); |
| 173 } | 180 } |
| 174 | 181 |
| 175 ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { | 182 ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { |
| 176 Flush(); | 183 Flush(); |
| 177 DeviceSettingsService::Get()->Shutdown(); | 184 DeviceSettingsService::Get()->ShutdownSessionManager(); |
| 178 } | 185 } |
| 179 | 186 |
| 180 DeviceSettingsTestBase::DeviceSettingsTestBase() | 187 DeviceSettingsTestBase::DeviceSettingsTestBase() |
| 181 : loop_(MessageLoop::TYPE_UI), | 188 : loop_(MessageLoop::TYPE_UI), |
| 182 ui_thread_(content::BrowserThread::UI, &loop_), | 189 ui_thread_(content::BrowserThread::UI, &loop_), |
| 183 file_thread_(content::BrowserThread::FILE, &loop_), | 190 file_thread_(content::BrowserThread::FILE, &loop_), |
| 184 owner_key_util_(new MockOwnerKeyUtil()) {} | 191 owner_key_util_(new MockOwnerKeyUtil()), |
| 192 device_settings_service_(DeviceSettingsService::Get()) { |
| 193 } |
| 185 | 194 |
| 186 DeviceSettingsTestBase::~DeviceSettingsTestBase() { | 195 DeviceSettingsTestBase::~DeviceSettingsTestBase() { |
| 187 base::RunLoop().RunUntilIdle(); | 196 base::RunLoop().RunUntilIdle(); |
| 188 } | 197 } |
| 189 | 198 |
| 190 void DeviceSettingsTestBase::SetUp() { | 199 void DeviceSettingsTestBase::SetUp() { |
| 191 device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled( | 200 device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled( |
| 192 false); | 201 false); |
| 193 owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key()); | 202 owner_key_util_->SetPublicKeyFromPrivateKey(device_policy_.signing_key()); |
| 194 device_policy_.Build(); | 203 device_policy_.Build(); |
| 195 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); | 204 device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob()); |
| 196 device_settings_service_.Initialize(&device_settings_test_helper_, | 205 device_settings_service_->InitializeSessionManager( |
| 197 owner_key_util_); | 206 &device_settings_test_helper_, |
| 207 owner_key_util_); |
| 198 } | 208 } |
| 199 | 209 |
| 200 void DeviceSettingsTestBase::TearDown() { | 210 void DeviceSettingsTestBase::TearDown() { |
| 201 FlushDeviceSettings(); | 211 FlushDeviceSettings(); |
| 202 device_settings_service_.Shutdown(); | 212 device_settings_service_->ShutdownSessionManager(); |
| 203 } | 213 } |
| 204 | 214 |
| 205 void DeviceSettingsTestBase::FlushDeviceSettings() { | 215 void DeviceSettingsTestBase::FlushDeviceSettings() { |
| 206 device_settings_test_helper_.Flush(); | 216 device_settings_test_helper_.Flush(); |
| 207 } | 217 } |
| 208 | 218 |
| 209 void DeviceSettingsTestBase::ReloadDeviceSettings() { | 219 void DeviceSettingsTestBase::ReloadDeviceSettings() { |
| 210 device_settings_service_.OwnerKeySet(true); | 220 device_settings_service_->OwnerKeySet(true); |
| 211 FlushDeviceSettings(); | 221 FlushDeviceSettings(); |
| 212 } | 222 } |
| 213 | 223 |
| 214 } // namespace chromeos | 224 } // namespace chromeos |
| OLD | NEW |