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.
5 #ifndef CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_
6 #define CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_
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"
23 class FakeOwnerSettingsService
;
24 class ScopedTestCrosSettings
;
25 class ScopedTestDeviceSettingsService
;
27 class ScopedCrosSettingsTestHelper
{
29 ScopedCrosSettingsTestHelper();
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
35 explicit ScopedCrosSettingsTestHelper(bool create_settings_service
);
36 ~ScopedCrosSettingsTestHelper();
38 // Methods to replace and restore CrosSettingsProvider for the specified
40 void ReplaceProvider(const std::string
& path
);
41 void RestoreProvider();
43 // Method to create an owner settings service that uses
44 // |stub_settings_provider_| as settings write path.
45 scoped_ptr
<FakeOwnerSettingsService
> CreateOwnerSettingsService(
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
);
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
);
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
);
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
);
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_
;
76 void Initialize(bool create_settings_service
);
78 DISALLOW_COPY_AND_ASSIGN(ScopedCrosSettingsTestHelper
);
81 } // namespace chromeos
83 #endif // CHROME_BROWSER_CHROMEOS_SETTINGS_SCOPED_CROS_SETTINGS_TEST_HELPER_H_