| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| 6 #define CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 6 #define COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback_forward.h" | 11 #include "base/callback_forward.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "components/policy/core/common/policy_types.h" | 15 #include "components/policy/core/common/policy_types.h" |
| 16 #include "components/policy/core/common/schema.h" | 16 #include "components/policy/core/common/schema.h" |
| 17 #include "components/policy/core/common/schema_registry.h" | 17 #include "components/policy/core/common/schema_registry.h" |
| 18 #include "components/policy/policy_export.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace base { | 21 namespace base { |
| 21 class DictionaryValue; | 22 class DictionaryValue; |
| 22 class ListValue; | 23 class ListValue; |
| 23 class SequencedTaskRunner; | 24 class SequencedTaskRunner; |
| 24 class Value; | 25 class Value; |
| 25 } | 26 } |
| 26 | 27 |
| 27 namespace policy { | 28 namespace policy { |
| 28 | 29 |
| 29 class ConfigurationPolicyProvider; | 30 class ConfigurationPolicyProvider; |
| 30 | 31 |
| 31 namespace test_keys { | 32 namespace test_keys { |
| 32 | 33 |
| 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 POLICY_EXPORT PolicyTestBase : public testing::Test { |
| 42 public: | 43 public: |
| 43 PolicyTestBase(); | 44 PolicyTestBase(); |
| 44 virtual ~PolicyTestBase(); | 45 virtual ~PolicyTestBase(); |
| 45 | 46 |
| 46 // testing::Test: | 47 // testing::Test: |
| 47 virtual void SetUp() OVERRIDE; | 48 virtual void SetUp() OVERRIDE; |
| 48 virtual void TearDown() OVERRIDE; | 49 virtual void TearDown() OVERRIDE; |
| 49 | 50 |
| 50 protected: | 51 protected: |
| 51 Schema chrome_schema_; | 52 Schema chrome_schema_; |
| 52 SchemaRegistry schema_registry_; | 53 SchemaRegistry schema_registry_; |
| 53 | 54 |
| 54 // Create an actual IO loop (needed by FilePathWatcher). | 55 // Create an actual IO loop (needed by FilePathWatcher). |
| 55 base::MessageLoopForIO loop_; | 56 base::MessageLoopForIO loop_; |
| 56 | 57 |
| 57 private: | 58 private: |
| 58 DISALLOW_COPY_AND_ASSIGN(PolicyTestBase); | 59 DISALLOW_COPY_AND_ASSIGN(PolicyTestBase); |
| 59 }; | 60 }; |
| 60 | 61 |
| 61 // An interface for creating a test policy provider and creating a policy | 62 // An interface for creating a test policy provider and creating a policy |
| 62 // provider instance for testing. Used as the parameter to the abstract | 63 // provider instance for testing. Used as the parameter to the abstract |
| 63 // ConfigurationPolicyProviderTest below. | 64 // ConfigurationPolicyProviderTest below. |
| 64 class PolicyProviderTestHarness { | 65 class POLICY_EXPORT PolicyProviderTestHarness { |
| 65 public: | 66 public: |
| 66 // |level| and |scope| are the level and scope of the policies returned by | 67 // |level| and |scope| are the level and scope of the policies returned by |
| 67 // the providers from CreateProvider(). | 68 // the providers from CreateProvider(). |
| 68 PolicyProviderTestHarness(PolicyLevel level, PolicyScope scope); | 69 PolicyProviderTestHarness(PolicyLevel level, PolicyScope scope); |
| 69 virtual ~PolicyProviderTestHarness(); | 70 virtual ~PolicyProviderTestHarness(); |
| 70 | 71 |
| 71 // Actions to run at gtest SetUp() time. | 72 // Actions to run at gtest SetUp() time. |
| 72 virtual void SetUp() = 0; | 73 virtual void SetUp() = 0; |
| 73 | 74 |
| 74 // Create a new policy provider. | 75 // Create a new policy provider. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); | 106 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 // A factory method for creating a test harness. | 109 // A factory method for creating a test harness. |
| 109 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); | 110 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)(); |
| 110 | 111 |
| 111 // Abstract policy provider test. This is meant to be instantiated for each | 112 // Abstract policy provider test. This is meant to be instantiated for each |
| 112 // policy provider implementation, passing in a suitable harness factory | 113 // policy provider implementation, passing in a suitable harness factory |
| 113 // function as the test parameter. | 114 // function as the test parameter. |
| 114 class ConfigurationPolicyProviderTest | 115 class POLICY_EXPORT ConfigurationPolicyProviderTest |
| 115 : public PolicyTestBase, | 116 : public PolicyTestBase, |
| 116 public testing::WithParamInterface<CreatePolicyProviderTestHarness> { | 117 public testing::WithParamInterface<CreatePolicyProviderTestHarness> { |
| 117 protected: | 118 protected: |
| 118 ConfigurationPolicyProviderTest(); | 119 ConfigurationPolicyProviderTest(); |
| 119 virtual ~ConfigurationPolicyProviderTest(); | 120 virtual ~ConfigurationPolicyProviderTest(); |
| 120 | 121 |
| 121 virtual void SetUp() OVERRIDE; | 122 virtual void SetUp() OVERRIDE; |
| 122 virtual void TearDown() OVERRIDE; | 123 virtual void TearDown() OVERRIDE; |
| 123 | 124 |
| 124 // Installs a valid policy and checks whether the provider returns the | 125 // Installs a valid policy and checks whether the provider returns the |
| 125 // |expected_value|. | 126 // |expected_value|. |
| 126 void CheckValue(const char* policy_name, | 127 void CheckValue(const char* policy_name, |
| 127 const base::Value& expected_value, | 128 const base::Value& expected_value, |
| 128 base::Closure install_value); | 129 base::Closure install_value); |
| 129 | 130 |
| 130 scoped_ptr<PolicyProviderTestHarness> test_harness_; | 131 scoped_ptr<PolicyProviderTestHarness> test_harness_; |
| 131 scoped_ptr<ConfigurationPolicyProvider> provider_; | 132 scoped_ptr<ConfigurationPolicyProvider> provider_; |
| 132 | 133 |
| 133 private: | 134 private: |
| 134 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); | 135 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest); |
| 135 }; | 136 }; |
| 136 | 137 |
| 137 // An extension of ConfigurationPolicyProviderTest that also tests loading of | 138 // An extension of ConfigurationPolicyProviderTest that also tests loading of |
| 138 // 3rd party policy. Policy provider implementations that support loading of | 139 // 3rd party policy. Policy provider implementations that support loading of |
| 139 // 3rd party policy should also instantiate these tests. | 140 // 3rd party policy should also instantiate these tests. |
| 140 class Configuration3rdPartyPolicyProviderTest | 141 class POLICY_EXPORT Configuration3rdPartyPolicyProviderTest |
| 141 : public ConfigurationPolicyProviderTest { | 142 : public ConfigurationPolicyProviderTest { |
| 142 protected: | 143 protected: |
| 143 Configuration3rdPartyPolicyProviderTest(); | 144 Configuration3rdPartyPolicyProviderTest(); |
| 144 virtual ~Configuration3rdPartyPolicyProviderTest(); | 145 virtual ~Configuration3rdPartyPolicyProviderTest(); |
| 145 | 146 |
| 146 private: | 147 private: |
| 147 DISALLOW_COPY_AND_ASSIGN(Configuration3rdPartyPolicyProviderTest); | 148 DISALLOW_COPY_AND_ASSIGN(Configuration3rdPartyPolicyProviderTest); |
| 148 }; | 149 }; |
| 149 | 150 |
| 150 } // namespace policy | 151 } // namespace policy |
| 151 | 152 |
| 152 #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_PROVIDER_TEST_H_ | 153 #endif // COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_ |
| OLD | NEW |