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

Side by Side Diff: chrome/browser/policy/config_dir_policy_provider_unittest.cc

Issue 10384145: Removed ConfigurationPolicyProvider::Provide(). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebased Created 8 years, 7 months 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
OLDNEW
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 #include "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/json/json_string_value_serializer.h" 7 #include "base/json/json_string_value_serializer.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/scoped_temp_dir.h" 9 #include "base/scoped_temp_dir.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/values.h" 11 #include "base/values.h"
12 #include "chrome/browser/policy/config_dir_policy_provider.h" 12 #include "chrome/browser/policy/config_dir_policy_provider.h"
13 #include "chrome/browser/policy/configuration_policy_provider_test.h" 13 #include "chrome/browser/policy/configuration_policy_provider_test.h"
14 #include "chrome/browser/policy/policy_bundle.h"
15 #include "chrome/browser/policy/policy_map.h"
14 16
15 namespace policy { 17 namespace policy {
16 18
17 namespace { 19 namespace {
18 20
19 class TestHarness : public PolicyProviderTestHarness { 21 class TestHarness : public PolicyProviderTestHarness {
20 public: 22 public:
21 TestHarness(); 23 TestHarness();
22 virtual ~TestHarness(); 24 virtual ~TestHarness();
23 25
24 virtual void SetUp() OVERRIDE; 26 virtual void SetUp() OVERRIDE;
25 27
26 virtual AsynchronousPolicyProvider* CreateProvider( 28 virtual AsynchronousPolicyProvider* CreateProvider(
27 const PolicyDefinitionList* policy_definition_list) OVERRIDE; 29 const PolicyDefinitionList* policy_definition_list) OVERRIDE;
28 30
31 virtual PolicyLevel GetPolicyLevel() const OVERRIDE;
32 virtual PolicyScope GetPolicyScope() const OVERRIDE;
33
29 virtual void InstallEmptyPolicy() OVERRIDE; 34 virtual void InstallEmptyPolicy() OVERRIDE;
30 virtual void InstallStringPolicy(const std::string& policy_name, 35 virtual void InstallStringPolicy(const std::string& policy_name,
31 const std::string& policy_value) OVERRIDE; 36 const std::string& policy_value) OVERRIDE;
32 virtual void InstallIntegerPolicy(const std::string& policy_name, 37 virtual void InstallIntegerPolicy(const std::string& policy_name,
33 int policy_value) OVERRIDE; 38 int policy_value) OVERRIDE;
34 virtual void InstallBooleanPolicy(const std::string& policy_name, 39 virtual void InstallBooleanPolicy(const std::string& policy_name,
35 bool policy_value) OVERRIDE; 40 bool policy_value) OVERRIDE;
36 virtual void InstallStringListPolicy( 41 virtual void InstallStringListPolicy(
37 const std::string& policy_name, 42 const std::string& policy_name,
38 const base::ListValue* policy_value) OVERRIDE; 43 const base::ListValue* policy_value) OVERRIDE;
(...skipping 24 matching lines...) Expand all
63 } 68 }
64 69
65 AsynchronousPolicyProvider* TestHarness::CreateProvider( 70 AsynchronousPolicyProvider* TestHarness::CreateProvider(
66 const PolicyDefinitionList* policy_definition_list) { 71 const PolicyDefinitionList* policy_definition_list) {
67 return new ConfigDirPolicyProvider(policy_definition_list, 72 return new ConfigDirPolicyProvider(policy_definition_list,
68 POLICY_LEVEL_MANDATORY, 73 POLICY_LEVEL_MANDATORY,
69 POLICY_SCOPE_MACHINE, 74 POLICY_SCOPE_MACHINE,
70 test_dir()); 75 test_dir());
71 } 76 }
72 77
78 PolicyLevel TestHarness::GetPolicyLevel() const {
79 return POLICY_LEVEL_MANDATORY;
80 }
81
82 PolicyScope TestHarness::GetPolicyScope() const {
83 return POLICY_SCOPE_MACHINE;
84 }
85
73 void TestHarness::InstallEmptyPolicy() { 86 void TestHarness::InstallEmptyPolicy() {
74 base::DictionaryValue dict; 87 base::DictionaryValue dict;
75 WriteConfigFile(dict, "policy"); 88 WriteConfigFile(dict, "policy");
76 } 89 }
77 90
78 void TestHarness::InstallStringPolicy(const std::string& policy_name, 91 void TestHarness::InstallStringPolicy(const std::string& policy_name,
79 const std::string& policy_value) { 92 const std::string& policy_value) {
80 base::DictionaryValue dict; 93 base::DictionaryValue dict;
81 dict.SetString(policy_name, policy_value); 94 dict.SetString(policy_name, policy_value);
82 WriteConfigFile(dict, "policy"); 95 WriteConfigFile(dict, "policy");
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 155
143 TestHarness harness_; 156 TestHarness harness_;
144 }; 157 };
145 158
146 // The preferences dictionary is expected to be empty when there are no files to 159 // The preferences dictionary is expected to be empty when there are no files to
147 // load. 160 // load.
148 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) { 161 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) {
149 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(), 162 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
150 POLICY_LEVEL_MANDATORY, 163 POLICY_LEVEL_MANDATORY,
151 POLICY_SCOPE_MACHINE); 164 POLICY_SCOPE_MACHINE);
152 scoped_ptr<PolicyMap> policy(loader.Load()); 165 scoped_ptr<PolicyBundle> bundle(loader.Load());
153 EXPECT_TRUE(policy.get()); 166 ASSERT_TRUE(bundle.get());
154 EXPECT_TRUE(policy->empty()); 167 const PolicyBundle kEmptyBundle;
168 EXPECT_TRUE(bundle->Equals(kEmptyBundle));
155 } 169 }
156 170
157 // Reading from a non-existent directory should result in an empty preferences 171 // Reading from a non-existent directory should result in an empty preferences
158 // dictionary. 172 // dictionary.
159 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) { 173 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) {
160 FilePath non_existent_dir( 174 FilePath non_existent_dir(
161 harness_.test_dir().Append(FILE_PATH_LITERAL("not_there"))); 175 harness_.test_dir().Append(FILE_PATH_LITERAL("not_there")));
162 ConfigDirPolicyProviderDelegate loader(non_existent_dir, 176 ConfigDirPolicyProviderDelegate loader(non_existent_dir,
163 POLICY_LEVEL_MANDATORY, 177 POLICY_LEVEL_MANDATORY,
164 POLICY_SCOPE_MACHINE); 178 POLICY_SCOPE_MACHINE);
165 scoped_ptr<PolicyMap> policy(loader.Load()); 179 scoped_ptr<PolicyBundle> bundle(loader.Load());
166 EXPECT_TRUE(policy.get()); 180 ASSERT_TRUE(bundle.get());
167 EXPECT_TRUE(policy->empty()); 181 const PolicyBundle kEmptyBundle;
182 EXPECT_TRUE(bundle->Equals(kEmptyBundle));
168 } 183 }
169 184
170 // Test merging values from different files. 185 // Test merging values from different files.
171 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { 186 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
172 // Write a bunch of data files in order to increase the chance to detect the 187 // Write a bunch of data files in order to increase the chance to detect the
173 // provider not respecting lexicographic ordering when reading them. Since the 188 // provider not respecting lexicographic ordering when reading them. Since the
174 // filesystem may return files in arbitrary order, there is no way to be sure, 189 // filesystem may return files in arbitrary order, there is no way to be sure,
175 // but this is better than nothing. 190 // but this is better than nothing.
176 base::DictionaryValue test_dict_bar; 191 base::DictionaryValue test_dict_bar;
177 test_dict_bar.SetString("HomepageLocation", "http://bar.com"); 192 test_dict_bar.SetString("HomepageLocation", "http://bar.com");
178 for (unsigned int i = 1; i <= 4; ++i) 193 for (unsigned int i = 1; i <= 4; ++i)
179 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i)); 194 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
180 base::DictionaryValue test_dict_foo; 195 base::DictionaryValue test_dict_foo;
181 test_dict_foo.SetString("HomepageLocation", "http://foo.com"); 196 test_dict_foo.SetString("HomepageLocation", "http://foo.com");
182 harness_.WriteConfigFile(test_dict_foo, "9"); 197 harness_.WriteConfigFile(test_dict_foo, "9");
183 for (unsigned int i = 5; i <= 8; ++i) 198 for (unsigned int i = 5; i <= 8; ++i)
184 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i)); 199 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
185 200
186 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(), 201 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
187 POLICY_LEVEL_MANDATORY, 202 POLICY_LEVEL_MANDATORY,
188 POLICY_SCOPE_USER); 203 POLICY_SCOPE_USER);
189 scoped_ptr<PolicyMap> policy(loader.Load()); 204 scoped_ptr<PolicyBundle> bundle(loader.Load());
190 EXPECT_TRUE(policy.get()); 205 ASSERT_TRUE(bundle.get());
191 PolicyMap expected; 206 PolicyBundle expected_bundle;
192 expected.LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); 207 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
193 EXPECT_TRUE(policy->Equals(expected)); 208 .LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
209 EXPECT_TRUE(bundle->Equals(expected_bundle));
194 } 210 }
195 211
196 } // namespace policy 212 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698