OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" |
| 13 #include "chromeos/settings/cros_settings_provider.h" |
| 14 |
| 15 class Profile; |
| 16 |
| 17 namespace base { |
| 18 class Value; |
| 19 } |
| 20 |
| 21 namespace chromeos { |
| 22 |
| 23 class FakeOwnerSettingsService; |
| 24 class ScopedTestCrosSettings; |
| 25 class ScopedTestDeviceSettingsService; |
| 26 |
| 27 class ScopedCrosSettingsTestHelper { |
| 28 public: |
| 29 ScopedCrosSettingsTestHelper(); |
| 30 |
| 31 // In some cases it is required to pass |create_settings_service| as false: |
| 32 // If the test already has a device settings service and/or CrosSettings set |
| 33 // up by another (instantiated or base) class, creating another one causes |
| 34 // crash. |
| 35 explicit ScopedCrosSettingsTestHelper(bool create_settings_service); |
| 36 ~ScopedCrosSettingsTestHelper(); |
| 37 |
| 38 // Methods to replace and restore CrosSettingsProvider for the specified |
| 39 // |path|. |
| 40 void ReplaceProvider(const std::string& path); |
| 41 void RestoreProvider(); |
| 42 |
| 43 // Method to create an owner settings service that uses |
| 44 // |stub_settings_provider_| as settings write path. |
| 45 scoped_ptr<FakeOwnerSettingsService> CreateOwnerSettingsService( |
| 46 Profile* profile); |
| 47 |
| 48 // These methods simply call the according |stub_settings_provider_| method. |
| 49 void SetTrustedStatus(CrosSettingsProvider::TrustedStatus status); |
| 50 void SetCurrentUserIsOwner(bool owner); |
| 51 void Set(const std::string& path, const base::Value& in_value); |
| 52 |
| 53 // Convenience forms of Set() from CrosSettingsProvider. These methods will |
| 54 // replace any existing value at that |path|, even if it has a different type. |
| 55 void SetBoolean(const std::string& path, bool in_value); |
| 56 void SetInteger(const std::string& path, int in_value); |
| 57 void SetDouble(const std::string& path, double in_value); |
| 58 void SetString(const std::string& path, const std::string& in_value); |
| 59 |
| 60 // This may be called before |ReplaceProvider| to copy values currently stored |
| 61 // in the old provider. If the method is called after |ReplaceProvider|, then |
| 62 // the value is retreived from |real_settings_provider_| for any |path|. |
| 63 void CopyStoredValue(const std::string& path); |
| 64 |
| 65 // Write the setting from |path| to local state so that it can be retreived |
| 66 // later on browser test startup by the device settings service. |
| 67 void StoreCachedDeviceSetting(const std::string& path); |
| 68 |
| 69 private: |
| 70 // Helpers used to mock out cros settings. |
| 71 scoped_ptr<ScopedTestDeviceSettingsService> test_device_settings_service_; |
| 72 scoped_ptr<ScopedTestCrosSettings> test_cros_settings_; |
| 73 CrosSettingsProvider* real_settings_provider_ = nullptr; |
| 74 StubCrosSettingsProvider stub_settings_provider_; |
| 75 |
| 76 void Initialize(bool create_settings_service); |
| 77 |
| 78 DISALLOW_COPY_AND_ASSIGN(ScopedCrosSettingsTestHelper); |
| 79 }; |
| 80 |
| 81 } // namespace chromeos |
| 82 |
| 83 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_ |
OLD | NEW |