This source file includes following definitions.
- FlushLoops
- FlushStore
- FlushRetrieve
- Flush
- HasPendingOperations
- Init
- SetStubDelegate
- AddObserver
- RemoveObserver
- HasObserver
- EmitLoginPromptVisible
- RestartJob
- StartSession
- StopSession
- StartDeviceWipe
- RequestLockScreen
- NotifyLockScreenShown
- NotifyLockScreenDismissed
- RetrieveActiveSessions
- RetrieveDevicePolicy
- RetrievePolicyForUser
- BlockingRetrievePolicyForUser
- RetrieveDeviceLocalAccountPolicy
- StoreDevicePolicy
- StorePolicyForUser
- StoreDeviceLocalAccountPolicy
- SetFlagsForUser
- fake_dbus_thread_manager_
- SetUp
- TearDown
- FlushDeviceSettings
- ReloadDeviceSettings
#include "chrome/browser/chromeos/settings/device_settings_test_helper.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "base/threading/sequenced_worker_pool.h"
#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/chromeos/settings/device_settings_service.h"
#include "chrome/browser/chromeos/settings/mock_owner_key_util.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/fake_dbus_thread_manager.h"
#include "chromeos/network/network_handler.h"
#include "content/public/browser/browser_thread.h"
namespace chromeos {
DeviceSettingsTestHelper::DeviceSettingsTestHelper() {}
DeviceSettingsTestHelper::~DeviceSettingsTestHelper() {}
void DeviceSettingsTestHelper::FlushLoops() {
for (int i = 0; i < 2; ++i) {
base::MessageLoop::current()->RunUntilIdle();
content::BrowserThread::GetBlockingPool()->FlushForTesting();
}
base::MessageLoop::current()->RunUntilIdle();
}
void DeviceSettingsTestHelper::FlushStore() {
std::vector<StorePolicyCallback> callbacks;
callbacks.swap(device_policy_.store_callbacks_);
for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin());
cb != callbacks.end(); ++cb) {
cb->Run(device_policy_.store_result_);
}
std::map<std::string, PolicyState>::iterator device_local_account_state;
for (device_local_account_state = device_local_account_policy_.begin();
device_local_account_state != device_local_account_policy_.end();
++device_local_account_state) {
callbacks.swap(device_local_account_state->second.store_callbacks_);
for (std::vector<StorePolicyCallback>::iterator cb(callbacks.begin());
cb != callbacks.end(); ++cb) {
cb->Run(device_local_account_state->second.store_result_);
}
}
}
void DeviceSettingsTestHelper::FlushRetrieve() {
std::vector<RetrievePolicyCallback> callbacks;
callbacks.swap(device_policy_.retrieve_callbacks_);
for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
cb != callbacks.end(); ++cb) {
cb->Run(device_policy_.policy_blob_);
}
std::map<std::string, PolicyState>::iterator device_local_account_state;
for (device_local_account_state = device_local_account_policy_.begin();
device_local_account_state != device_local_account_policy_.end();
++device_local_account_state) {
std::vector<RetrievePolicyCallback> callbacks;
callbacks.swap(device_local_account_state->second.retrieve_callbacks_);
for (std::vector<RetrievePolicyCallback>::iterator cb(callbacks.begin());
cb != callbacks.end(); ++cb) {
cb->Run(device_local_account_state->second.policy_blob_);
}
}
}
void DeviceSettingsTestHelper::Flush() {
do {
FlushLoops();
FlushStore();
FlushLoops();
FlushRetrieve();
FlushLoops();
} while (HasPendingOperations());
}
bool DeviceSettingsTestHelper::HasPendingOperations() const {
if (device_policy_.HasPendingOperations())
return true;
std::map<std::string, PolicyState>::const_iterator device_local_account_state;
for (device_local_account_state = device_local_account_policy_.begin();
device_local_account_state != device_local_account_policy_.end();
++device_local_account_state) {
if (device_local_account_state->second.HasPendingOperations())
return true;
}
return false;
}
void DeviceSettingsTestHelper::Init(dbus::Bus* bus) {}
void DeviceSettingsTestHelper::SetStubDelegate(
SessionManagerClient::StubDelegate* delegate) {}
void DeviceSettingsTestHelper::AddObserver(Observer* observer) {}
void DeviceSettingsTestHelper::RemoveObserver(Observer* observer) {}
bool DeviceSettingsTestHelper::HasObserver(Observer* observer) {
return false;
}
void DeviceSettingsTestHelper::EmitLoginPromptVisible() {}
void DeviceSettingsTestHelper::RestartJob(int pid,
const std::string& command_line) {}
void DeviceSettingsTestHelper::StartSession(const std::string& user_email) {}
void DeviceSettingsTestHelper::StopSession() {}
void DeviceSettingsTestHelper::StartDeviceWipe() {}
void DeviceSettingsTestHelper::RequestLockScreen() {}
void DeviceSettingsTestHelper::NotifyLockScreenShown() {}
void DeviceSettingsTestHelper::NotifyLockScreenDismissed() {}
void DeviceSettingsTestHelper::RetrieveActiveSessions(
const ActiveSessionsCallback& callback) {}
void DeviceSettingsTestHelper::RetrieveDevicePolicy(
const RetrievePolicyCallback& callback) {
device_policy_.retrieve_callbacks_.push_back(callback);
}
void DeviceSettingsTestHelper::RetrievePolicyForUser(
const std::string& username,
const RetrievePolicyCallback& callback) {
}
std::string DeviceSettingsTestHelper::BlockingRetrievePolicyForUser(
const std::string& username) {
return "";
}
void DeviceSettingsTestHelper::RetrieveDeviceLocalAccountPolicy(
const std::string& account_id,
const RetrievePolicyCallback& callback) {
device_local_account_policy_[account_id].retrieve_callbacks_.push_back(
callback);
}
void DeviceSettingsTestHelper::StoreDevicePolicy(
const std::string& policy_blob,
const StorePolicyCallback& callback) {
device_policy_.policy_blob_ = policy_blob;
device_policy_.store_callbacks_.push_back(callback);
}
void DeviceSettingsTestHelper::StorePolicyForUser(
const std::string& username,
const std::string& policy_blob,
const std::string& policy_key,
const StorePolicyCallback& callback) {
}
void DeviceSettingsTestHelper::StoreDeviceLocalAccountPolicy(
const std::string& account_id,
const std::string& policy_blob,
const StorePolicyCallback& callback) {
device_local_account_policy_[account_id].policy_blob_ = policy_blob;
device_local_account_policy_[account_id].store_callbacks_.push_back(callback);
}
void DeviceSettingsTestHelper::SetFlagsForUser(
const std::string& account_id,
const std::vector<std::string>& flags) {}
DeviceSettingsTestHelper::PolicyState::PolicyState()
: store_result_(true) {}
DeviceSettingsTestHelper::PolicyState::~PolicyState() {}
ScopedDeviceSettingsTestHelper::ScopedDeviceSettingsTestHelper() {
DeviceSettingsService::Initialize();
DeviceSettingsService::Get()->SetSessionManager(this, new MockOwnerKeyUtil());
DeviceSettingsService::Get()->Load();
Flush();
}
ScopedDeviceSettingsTestHelper::~ScopedDeviceSettingsTestHelper() {
Flush();
DeviceSettingsService::Get()->UnsetSessionManager();
DeviceSettingsService::Shutdown();
}
DeviceSettingsTestBase::DeviceSettingsTestBase()
: ui_thread_(content::BrowserThread::UI, &loop_),
file_thread_(content::BrowserThread::FILE, &loop_),
owner_key_util_(new MockOwnerKeyUtil()),
fake_dbus_thread_manager_(new FakeDBusThreadManager()) {
fake_dbus_thread_manager_->SetFakeClients();
}
DeviceSettingsTestBase::~DeviceSettingsTestBase() {
base::RunLoop().RunUntilIdle();
}
void DeviceSettingsTestBase::SetUp() {
chromeos::DBusThreadManager::InitializeForTesting(fake_dbus_thread_manager_);
NetworkHandler::Initialize();
loop_.RunUntilIdle();
device_policy_.payload().mutable_metrics_enabled()->set_metrics_enabled(
false);
owner_key_util_->SetPublicKeyFromPrivateKey(*device_policy_.GetSigningKey());
device_policy_.Build();
device_settings_test_helper_.set_policy_blob(device_policy_.GetBlob());
device_settings_service_.SetSessionManager(&device_settings_test_helper_,
owner_key_util_);
}
void DeviceSettingsTestBase::TearDown() {
FlushDeviceSettings();
device_settings_service_.UnsetSessionManager();
NetworkHandler::Shutdown();
DBusThreadManager::Shutdown();
}
void DeviceSettingsTestBase::FlushDeviceSettings() {
device_settings_test_helper_.Flush();
}
void DeviceSettingsTestBase::ReloadDeviceSettings() {
device_settings_service_.OwnerKeySet(true);
FlushDeviceSettings();
}
}