Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(734)

Side by Side Diff: components/policy/core/common/configuration_policy_provider_test.h

Issue 99333002: Revert of Move ConfigurationPolicyProvider, etc. to components/policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_
7
8 #include <string>
9
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/message_loop/message_loop.h"
15 #include "components/policy/core/common/policy_types.h"
16 #include "components/policy/core/common/schema.h"
17 #include "components/policy/core/common/schema_registry.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 namespace base {
21 class DictionaryValue;
22 class ListValue;
23 class SequencedTaskRunner;
24 class Value;
25 }
26
27 namespace policy {
28
29 class ConfigurationPolicyProvider;
30
31 namespace test_keys {
32
33 extern const char kKeyString[];
34 extern const char kKeyBoolean[];
35 extern const char kKeyInteger[];
36 extern const char kKeyStringList[];
37 extern const char kKeyDictionary[];
38
39 } // namespace test_keys
40
41 class PolicyTestBase : public testing::Test {
42 public:
43 PolicyTestBase();
44 virtual ~PolicyTestBase();
45
46 // testing::Test:
47 virtual void SetUp() OVERRIDE;
48 virtual void TearDown() OVERRIDE;
49
50 protected:
51 Schema chrome_schema_;
52 SchemaRegistry schema_registry_;
53
54 // Create an actual IO loop (needed by FilePathWatcher).
55 base::MessageLoopForIO loop_;
56
57 private:
58 DISALLOW_COPY_AND_ASSIGN(PolicyTestBase);
59 };
60
61 // 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 // ConfigurationPolicyProviderTest below.
64 class PolicyProviderTestHarness {
65 public:
66 // |level| and |scope| are the level and scope of the policies returned by
67 // the providers from CreateProvider().
68 PolicyProviderTestHarness(PolicyLevel level, PolicyScope scope);
69 virtual ~PolicyProviderTestHarness();
70
71 // Actions to run at gtest SetUp() time.
72 virtual void SetUp() = 0;
73
74 // Create a new policy provider.
75 virtual ConfigurationPolicyProvider* CreateProvider(
76 SchemaRegistry* registry,
77 scoped_refptr<base::SequencedTaskRunner> task_runner) = 0;
78
79 // Returns the policy level and scope set by the policy provider.
80 PolicyLevel policy_level() const;
81 PolicyScope policy_scope() const;
82
83 // Helpers to configure the environment the policy provider reads from.
84 virtual void InstallEmptyPolicy() = 0;
85 virtual void InstallStringPolicy(const std::string& policy_name,
86 const std::string& policy_value) = 0;
87 virtual void InstallIntegerPolicy(const std::string& policy_name,
88 int policy_value) = 0;
89 virtual void InstallBooleanPolicy(const std::string& policy_name,
90 bool policy_value) = 0;
91 virtual void InstallStringListPolicy(const std::string& policy_name,
92 const base::ListValue* policy_value) = 0;
93 virtual void InstallDictionaryPolicy(
94 const std::string& policy_name,
95 const base::DictionaryValue* policy_value) = 0;
96
97 // Not every provider supports installing 3rd party policy. Those who do
98 // should override this method; the default just makes the test fail.
99 virtual void Install3rdPartyPolicy(const base::DictionaryValue* policies);
100
101 private:
102 PolicyLevel level_;
103 PolicyScope scope_;
104
105 DISALLOW_COPY_AND_ASSIGN(PolicyProviderTestHarness);
106 };
107
108 // A factory method for creating a test harness.
109 typedef PolicyProviderTestHarness* (*CreatePolicyProviderTestHarness)();
110
111 // Abstract policy provider test. This is meant to be instantiated for each
112 // policy provider implementation, passing in a suitable harness factory
113 // function as the test parameter.
114 class ConfigurationPolicyProviderTest
115 : public PolicyTestBase,
116 public testing::WithParamInterface<CreatePolicyProviderTestHarness> {
117 protected:
118 ConfigurationPolicyProviderTest();
119 virtual ~ConfigurationPolicyProviderTest();
120
121 virtual void SetUp() OVERRIDE;
122 virtual void TearDown() OVERRIDE;
123
124 // Installs a valid policy and checks whether the provider returns the
125 // |expected_value|.
126 void CheckValue(const char* policy_name,
127 const base::Value& expected_value,
128 base::Closure install_value);
129
130 scoped_ptr<PolicyProviderTestHarness> test_harness_;
131 scoped_ptr<ConfigurationPolicyProvider> provider_;
132
133 private:
134 DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyProviderTest);
135 };
136
137 // An extension of ConfigurationPolicyProviderTest that also tests loading of
138 // 3rd party policy. Policy provider implementations that support loading of
139 // 3rd party policy should also instantiate these tests.
140 class Configuration3rdPartyPolicyProviderTest
141 : public ConfigurationPolicyProviderTest {
142 protected:
143 Configuration3rdPartyPolicyProviderTest();
144 virtual ~Configuration3rdPartyPolicyProviderTest();
145
146 private:
147 DISALLOW_COPY_AND_ASSIGN(Configuration3rdPartyPolicyProviderTest);
148 };
149
150 } // namespace policy
151
152 #endif // COMPONENTS_POLICY_CORE_COMMON_CONFIGURATION_POLICY_PROVIDER_TEST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698