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