OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
6 #define COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 class SequencedTaskRunner; | 28 class SequencedTaskRunner; |
29 class Value; | 29 class Value; |
30 } | 30 } |
31 | 31 |
32 namespace policy { | 32 namespace policy { |
33 | 33 |
34 class ConfigurationPolicyProvider; | 34 class ConfigurationPolicyProvider; |
35 | 35 |
36 namespace test_keys { | 36 namespace test_keys { |
37 | 37 |
38 // Key constants for general use. | |
39 extern const char kKeyString[]; | 38 extern const char kKeyString[]; |
40 extern const char kKeyBoolean[]; | 39 extern const char kKeyBoolean[]; |
41 extern const char kKeyInteger[]; | 40 extern const char kKeyInteger[]; |
42 extern const char kKeyStringList[]; | 41 extern const char kKeyStringList[]; |
43 extern const char kKeyDictionary[]; | 42 extern const char kKeyDictionary[]; |
44 | 43 |
45 } // namespace test_keys | 44 } // namespace test_keys |
46 | 45 |
47 class PolicyTestBase : public testing::Test { | 46 class PolicyTestBase : public testing::Test { |
48 public: | 47 public: |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 83 |
85 // Actions to run at gtest SetUp() time. | 84 // Actions to run at gtest SetUp() time. |
86 virtual void SetUp() = 0; | 85 virtual void SetUp() = 0; |
87 | 86 |
88 // Create a new policy provider. | 87 // Create a new policy provider. |
89 virtual ConfigurationPolicyProvider* CreateProvider( | 88 virtual ConfigurationPolicyProvider* CreateProvider( |
90 SchemaRegistry* registry, | 89 SchemaRegistry* registry, |
91 scoped_refptr<base::SequencedTaskRunner> task_runner) = 0; | 90 scoped_refptr<base::SequencedTaskRunner> task_runner) = 0; |
92 | 91 |
93 // Returns the policy level, scope and source set by the policy provider. | 92 // Returns the policy level, scope and source set by the policy provider. |
94 PolicyLevel policy_level() const { return level_; } | 93 PolicyLevel policy_level() const; |
95 PolicyScope policy_scope() const { return scope_; } | 94 PolicyScope policy_scope() const; |
96 PolicySource policy_source() const { return source_; } | 95 PolicySource policy_source() const; |
97 | |
98 // Returns policy keys and matching schema. | |
99 const char* key_string() const { return key_string_; } | |
100 const char* key_boolean() const { return key_boolean_; } | |
101 const char* key_integer() const { return key_integer_; } | |
102 const char* key_stringlist() const { return key_stringlist_; } | |
103 const char* key_dictionary() const { return key_dictionary_; } | |
104 const char* test_schema() const { return test_schema_; } | |
105 | 96 |
106 // Helpers to configure the environment the policy provider reads from. | 97 // Helpers to configure the environment the policy provider reads from. |
107 virtual void InstallEmptyPolicy() = 0; | 98 virtual void InstallEmptyPolicy() = 0; |
108 virtual void InstallStringPolicy(const std::string& policy_name, | 99 virtual void InstallStringPolicy(const std::string& policy_name, |
109 const std::string& policy_value) = 0; | 100 const std::string& policy_value) = 0; |
110 virtual void InstallIntegerPolicy(const std::string& policy_name, | 101 virtual void InstallIntegerPolicy(const std::string& policy_name, |
111 int policy_value) = 0; | 102 int policy_value) = 0; |
112 virtual void InstallBooleanPolicy(const std::string& policy_name, | 103 virtual void InstallBooleanPolicy(const std::string& policy_name, |
113 bool policy_value) = 0; | 104 bool policy_value) = 0; |
114 virtual void InstallStringListPolicy(const std::string& policy_name, | 105 virtual void InstallStringListPolicy(const std::string& policy_name, |
115 const base::ListValue* policy_value) = 0; | 106 const base::ListValue* policy_value) = 0; |
116 virtual void InstallDictionaryPolicy( | 107 virtual void InstallDictionaryPolicy( |
117 const std::string& policy_name, | 108 const std::string& policy_name, |
118 const base::DictionaryValue* policy_value) = 0; | 109 const base::DictionaryValue* policy_value) = 0; |
119 | 110 |
120 // Not every provider supports installing 3rd party policy. Those who do | 111 // Not every provider supports installing 3rd party policy. Those who do |
121 // should override this method; the default just makes the test fail. | 112 // should override this method; the default just makes the test fail. |
122 virtual void Install3rdPartyPolicy(const base::DictionaryValue* policies); | 113 virtual void Install3rdPartyPolicy(const base::DictionaryValue* policies); |
123 | 114 |
124 protected: | |
125 const char* key_string_; | |
126 const char* key_boolean_; | |
127 const char* key_integer_; | |
128 const char* key_stringlist_; | |
129 const char* key_dictionary_; | |
130 const char* test_schema_; | |
131 | |
132 private: | 115 private: |
133 PolicyLevel level_; | 116 PolicyLevel level_; |
134 PolicyScope scope_; | 117 PolicyScope scope_; |
135 PolicySource source_; | 118 PolicySource source_; |
136 | 119 |
137 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); | 120 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); |
138 }; | 121 }; |
139 | 122 |
140 // A factory method for creating a test harness. | 123 // A factory method for creating a test harness. |
141 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); | 124 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); |
(...skipping 10 matching lines...) Expand all Loading... |
152 | 135 |
153 void SetUp() override; | 136 void SetUp() override; |
154 void TearDown() override; | 137 void TearDown() override; |
155 | 138 |
156 // Installs a valid policy and checks whether the provider returns the | 139 // Installs a valid policy and checks whether the provider returns the |
157 // |expected_value|. | 140 // |expected_value|. |
158 void CheckValue(const char* policy_name, | 141 void CheckValue(const char* policy_name, |
159 const base::Value& expected_value, | 142 const base::Value& expected_value, |
160 base::Closure install_value); | 143 base::Closure install_value); |
161 | 144 |
162 std::unique_ptr<PolicyProviderTestHarness> harness_; | 145 std::unique_ptr<PolicyProviderTestHarness> test_harness_; |
163 std::unique_ptr<ConfigurationPolicyProvider> provider_; | 146 std::unique_ptr<ConfigurationPolicyProvider> provider_; |
164 | 147 |
165 private: | 148 private: |
166 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); | 149 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); |
167 }; | 150 }; |
168 | 151 |
169 // An extension of ConfigurationPolicyProviderTest that also tests loading of | 152 // An extension of ConfigurationPolicyProviderTest that also tests loading of |
170 // 3rd party policy. Policy provider implementations that support loading of | 153 // 3rd party policy. Policy provider implementations that support loading of |
171 // 3rd party policy should also instantiate these tests. | 154 // 3rd party policy should also instantiate these tests. |
172 class Configuration3rdPartyPolicyProviderTest | 155 class Configuration3rdPartyPolicyProviderTest |
173 : public ConfigurationPolicyProviderTest { | 156 : public ConfigurationPolicyProviderTest { |
174 protected: | 157 protected: |
175 Configuration3rdPartyPolicyProviderTest(); | 158 Configuration3rdPartyPolicyProviderTest(); |
176 virtual ~Configuration3rdPartyPolicyProviderTest(); | 159 virtual ~Configuration3rdPartyPolicyProviderTest(); |
177 | 160 |
178 private: | 161 private: |
179 DISALLOW_COPY_AND_ASSIGN(Configuration3rdPartyPolicyProviderTest); | 162 DISALLOW_COPY_AND_ASSIGN(Configuration3rdPartyPolicyProviderTest); |
180 }; | 163 }; |
181 | 164 |
182 } // namespace policy | 165 } // namespace policy |
183 | 166 |
184 #endif // COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 167 #endif // COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
OLD | NEW |