| Index: chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc
|
| diff --git a/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..4b080761cde5a3897b5869de3ed24468bd40aa92
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.cc
|
| @@ -0,0 +1,86 @@
|
| +// Copyright (c) 2015 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/settings/scoped_cros_settings_test_helper.h"
|
| +
|
| +#include "chrome/browser/chromeos/ownership/fake_owner_settings_service.h"
|
| +#include "chrome/browser/chromeos/settings/cros_settings.h"
|
| +#include "chrome/browser/profiles/profile.h"
|
| +#include "components/ownership/mock_owner_key_util.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper() {
|
| + Initialize(true);
|
| +}
|
| +
|
| +ScopedCrosSettingsTestHelper::ScopedCrosSettingsTestHelper(
|
| + bool create_settings_service) {
|
| + Initialize(create_settings_service);
|
| +}
|
| +
|
| +ScopedCrosSettingsTestHelper::~ScopedCrosSettingsTestHelper() {
|
| + RestoreProvider();
|
| +}
|
| +
|
| +FakeOwnerSettingsService*
|
| +ScopedCrosSettingsTestHelper::CreateOwnerSettingsService(Profile* profile) {
|
| + return new FakeOwnerSettingsService(
|
| + profile, new ownership::MockOwnerKeyUtil(), &stub_settings_provider_);
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::ReplaceProvider(const std::string& path) {
|
| + // Swap out the DeviceSettingsProvider with our settings provider so we can
|
| + // set values for the specified path.
|
| + CrosSettings* const cros_settings = CrosSettings::Get();
|
| + device_settings_provider_ = cros_settings->GetProvider(path);
|
| + EXPECT_TRUE(device_settings_provider_);
|
| + EXPECT_TRUE(cros_settings->RemoveSettingsProvider(device_settings_provider_));
|
| + cros_settings->AddSettingsProvider(&stub_settings_provider_);
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::RestoreProvider() {
|
| + if (device_settings_provider_) {
|
| + // Restore the real DeviceSettingsProvider.
|
| + CrosSettings* const cros_settings = CrosSettings::Get();
|
| + EXPECT_TRUE(
|
| + cros_settings->RemoveSettingsProvider(&stub_settings_provider_));
|
| + cros_settings->AddSettingsProvider(device_settings_provider_);
|
| + device_settings_provider_ = nullptr;
|
| + }
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::SetBoolean(const std::string& path,
|
| + bool in_value) {
|
| + base::FundamentalValue value(in_value);
|
| + stub_settings_provider_.Set(path, value);
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::SetInteger(const std::string& path,
|
| + int in_value) {
|
| + base::FundamentalValue value(in_value);
|
| + stub_settings_provider_.Set(path, value);
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::SetDouble(const std::string& path,
|
| + double in_value) {
|
| + base::FundamentalValue value(in_value);
|
| + stub_settings_provider_.Set(path, value);
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::SetString(const std::string& path,
|
| + const std::string& in_value) {
|
| + base::StringValue value(in_value);
|
| + stub_settings_provider_.Set(path, value);
|
| +}
|
| +
|
| +void ScopedCrosSettingsTestHelper::Initialize(bool create_settings_service) {
|
| + if (create_settings_service && !DeviceSettingsService::IsInitialized()) {
|
| + test_device_settings_service_.reset(new ScopedTestDeviceSettingsService());
|
| + test_cros_settings_.reset(new ScopedTestCrosSettings());
|
| + }
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|