Chromium Code Reviews| Index: chrome/browser/chromeos/login/device_settings_test_helper.cc |
| diff --git a/chrome/browser/chromeos/login/device_settings_test_helper.cc b/chrome/browser/chromeos/login/device_settings_test_helper.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..63b035f2d80d73c97f12eb2a9a0729f66d423b2f |
| --- /dev/null |
| +++ b/chrome/browser/chromeos/login/device_settings_test_helper.cc |
| @@ -0,0 +1,124 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/chromeos/login/device_settings_test_helper.h" |
| + |
| +#include "base/message_loop.h" |
| +#include "base/threading/sequenced_worker_pool.h" |
| +#include "chrome/browser/chromeos/login/device_settings_service.h" |
| +#include "chrome/browser/chromeos/login/mock_owner_key_util.h" |
| +#include "content/public/browser/browser_thread.h" |
| + |
| +namespace chromeos { |
| + |
| +DeviceSettingsTestHelper::DeviceSettingsTestHelper() |
| + : store_result_(true) {} |
| + |
| +DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {} |
| + |
| +void DeviceSettingsTestHelper::FlushStore() { |
| + do { |
| + FlushLoops(); |
| + std::vector<StorePolicyCallback> callbacks; |
| + callbacks.swap(store_callbacks_); |
| + for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin()); |
| + cb != callbacks.end(); ++cb) { |
| + cb->Run(store_result_); |
| + FlushLoops(); |
| + } |
| + } while (!store_callbacks_.empty()); |
| +} |
| + |
| +void DeviceSettingsTestHelper::FlushRetrieve() { |
| + do { |
| + FlushLoops(); |
| + std::vector<RetrievePolicyCallback> callbacks; |
| + callbacks.swap(retrieve_callbacks_); |
| + for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin()); |
| + cb != callbacks.end(); ++cb) { |
| + cb->Run(policy_blob_); |
| + FlushLoops(); |
| + } |
| + } while (!retrieve_callbacks_.empty()); |
| +} |
| + |
| +void DeviceSettingsTestHelper::Flush() { |
| + do { |
| + FlushStore(); |
| + FlushRetrieve(); |
| + } while (!store_callbacks_.empty()); |
| +} |
| + |
| +void DeviceSettingsTestHelper::FlushLoops() { |
| + // DeviceSettingsService may trigger operations that hop back and forth |
| + // between the message loop and the blocking pool. 2 iterations are currently |
| + // sufficient (key loading, signing). |
| + for (int i = 0; i < 2; ++i) { |
|
pastarmovj
2012/07/30 12:19:19
Any chance this can be replaced with a while(has_p
Mattias Nissler (ping if slow)
2012/07/31 13:02:15
No, there's no good way to find out for the blocki
|
| + MessageLoop::current()->RunAllPending(); |
| + content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| + } |
| + MessageLoop::current()->RunAllPending(); |
| +} |
| + |
| +void DeviceSettingsTestHelper::AddObserver(Observer* observer) {} |
| + |
| +void DeviceSettingsTestHelper::RemoveObserver(Observer* observer) {} |
| + |
| +bool DeviceSettingsTestHelper::HasObserver(Observer* observer) { |
| + return false; |
| +} |
| + |
| +void DeviceSettingsTestHelper::EmitLoginPromptReady() {} |
| + |
| +void DeviceSettingsTestHelper::EmitLoginPromptVisible() {} |
| + |
| +void DeviceSettingsTestHelper::RestartJob(int pid, |
| + const std::string& command_line) {} |
| + |
| +void DeviceSettingsTestHelper::RestartEntd() {} |
| + |
| +void DeviceSettingsTestHelper::StartSession(const std::string& user_email) {} |
| + |
| +void DeviceSettingsTestHelper::StopSession() {} |
| + |
| +void DeviceSettingsTestHelper::RequestLockScreen() {} |
| + |
| +void DeviceSettingsTestHelper::RequestUnlockScreen() {} |
| + |
| +bool DeviceSettingsTestHelper::GetIsScreenLocked() { |
| + return false; |
| +} |
| + |
| +void DeviceSettingsTestHelper::RetrieveDevicePolicy( |
| + const RetrievePolicyCallback& callback) { |
| + retrieve_callbacks_.push_back(callback); |
| +} |
| + |
| +void DeviceSettingsTestHelper::RetrieveUserPolicy( |
| + const RetrievePolicyCallback& callback) { |
| +} |
| + |
| +void DeviceSettingsTestHelper::StoreDevicePolicy( |
| + const std::string& policy_blob, |
| + const StorePolicyCallback& callback) { |
| + policy_blob_ = policy_blob; |
| + store_callbacks_.push_back(callback); |
| +} |
| + |
| +void DeviceSettingsTestHelper::StoreUserPolicy( |
| + const std::string& policy_blob, |
| + const StorePolicyCallback& callback) {} |
| + |
| +ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() { |
| + DeviceSettingsService::Get()->Initialize(this, new MockOwnerKeyUtil()); |
| + DeviceSettingsService::Get()->Load(); |
| + Flush(); |
| +} |
| + |
| +ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() { |
| + Flush(); |
| + DeviceSettingsService::Get()->Shutdown(); |
| +} |
| + |
| +} // namespace chromeos |