OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 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 "base/values.h" | |
13 #include "chrome/browser/chromeos/settings/stub_cros_settings_provider.h" | |
14 | |
15 class KeyedService; | |
Mattias Nissler (ping if slow)
2015/04/08 11:38:17
not needed?
| |
16 class Profile; | |
17 | |
18 namespace content { | |
19 class BrowserContext; | |
20 } | |
21 | |
22 namespace chromeos { | |
23 | |
24 class CrosSettingsProvider; | |
25 class FakeOwnerSettingsService; | |
26 class ScopedTestCrosSettings; | |
27 class ScopedTestDeviceSettingsService; | |
28 | |
29 class ScopedCrosSettingsTestHelper { | |
30 public: | |
31 ScopedCrosSettingsTestHelper(); | |
32 | |
33 // In some cases it is required to pass |create_settings_service| as false: | |
34 // if the test already has a device settings service and/or CrosSettings set | |
35 // up by another bundle, creating another one causes crash. | |
36 explicit ScopedCrosSettingsTestHelper(bool create_settings_service); | |
37 virtual ~ScopedCrosSettingsTestHelper(); | |
38 | |
39 // Methods to replace and restore CrosSettingsProvider for the specified | |
40 // |path|. | |
41 void ReplaceProvider(const std::string& path); | |
42 void RestoreProvider(); | |
43 | |
44 // Method to create an owner settings service that uses | |
45 // |stub_settings_provider_| as settings write path. | |
46 FakeOwnerSettingsService* CreateOwnerSettingsService(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 |