diff options
author | ginkage <ginkage@chromium.org> | 2015-04-22 10:54:18 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-04-22 17:55:14 +0000 |
commit | 3a599661a49fa5ebfe63cb4016bb8efcd2d02712 (patch) | |
tree | e3189872e381c763f90909c4a18c4bc18cebad90 /chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h | |
parent | f72001505b06d68f7716b474e35865f33fffd4fe (diff) | |
download | chromium_src-3a599661a49fa5ebfe63cb4016bb8efcd2d02712.zip chromium_src-3a599661a49fa5ebfe63cb4016bb8efcd2d02712.tar.gz chromium_src-3a599661a49fa5ebfe63cb4016bb8efcd2d02712.tar.bz2 |
Get rid of excessive CrosSettings::Get()->Set*() usage, mostly in tests.
The following tests were affected:
unit_tests:
AttestationPolicyObserverTest.*
CryptohomeAuthenticatorTest.*
ExtensionCacheTest.*
EPKPChallengeMachineKeyTest.DevicePolicyDisabled
EPKPChallengeUserKeyTest.DevicePolicyDisabled
HeartbeatSchedulerTest.*
NetworkConfigurationUpdaterTest.*
PlatformVerificationFlowTest.*
StatusUploaderTest.*
ShutdownPolicyHandlerTest.*
UserManagerTest.*
browser_tests:
DeviceStatusCollectorTest.*
KioskAppManagerTest.*
KioskEnterpriseTest.*
KioskTest.*
KioskUpdateTest.*
BUG=433840
Review URL: https://codereview.chromium.org/1019283004
Cr-Commit-Position: refs/heads/master@{#326338}
Diffstat (limited to 'chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h')
-rw-r--r-- | chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h new file mode 100644 index 0000000..86a07bd --- /dev/null +++ b/chrome/browser/chromeos/settings/scoped_cros_settings_test_helper.h @@ -0,0 +1,83 @@ +// Copyright 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. + +#ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ +#define CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ + +#include <string> + +#include "base/macros.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" +#include "chromeos/settings/cros_settings_provider.h" + +class Profile; + +namespace base { +class Value; +} + +namespace chromeos { + +class FakeOwnerSettingsService; +class ScopedTestCrosSettings; +class ScopedTestDeviceSettingsService; + +class ScopedCrosSettingsTestHelper { + public: + ScopedCrosSettingsTestHelper(); + + // In some cases it is required to pass |create_settings_service| as false: + // If the test already has a device settings service and/or CrosSettings set + // up by another (instantiated or base) class, creating another one causes + // crash. + explicit ScopedCrosSettingsTestHelper(bool create_settings_service); + ~ScopedCrosSettingsTestHelper(); + + // Methods to replace and restore CrosSettingsProvider for the specified + // |path|. + void ReplaceProvider(const std::string& path); + void RestoreProvider(); + + // Method to create an owner settings service that uses + // |stub_settings_provider_| as settings write path. + scoped_ptr<FakeOwnerSettingsService> CreateOwnerSettingsService( + Profile* profile); + + // These methods simply call the according |stub_settings_provider_| method. + void SetTrustedStatus(CrosSettingsProvider::TrustedStatus status); + void SetCurrentUserIsOwner(bool owner); + void Set(const std::string& path, const base::Value& in_value); + + // Convenience forms of Set() from CrosSettingsProvider. These methods will + // replace any existing value at that |path|, even if it has a different type. + void SetBoolean(const std::string& path, bool in_value); + void SetInteger(const std::string& path, int in_value); + void SetDouble(const std::string& path, double in_value); + void SetString(const std::string& path, const std::string& in_value); + + // This may be called before |ReplaceProvider| to copy values currently stored + // in the old provider. If the method is called after |ReplaceProvider|, then + // the value is retreived from |real_settings_provider_| for any |path|. + void CopyStoredValue(const std::string& path); + + // Write the setting from |path| to local state so that it can be retreived + // later on browser test startup by the device settings service. + void StoreCachedDeviceSetting(const std::string& path); + + private: + // Helpers used to mock out cros settings. + scoped_ptr<ScopedTestDeviceSettingsService> test_device_settings_service_; + scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; + CrosSettingsProvider* real_settings_provider_ = nullptr; + StubCrosSettingsProvider stub_settings_provider_; + + void Initialize(bool create_settings_service); + + DISALLOW_COPY_AND_ASSIGN(ScopedCrosSettingsTestHelper); +}; + +} // namespace chromeos + +#endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ |