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

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
(...skipping 23 matching lines...) Expand all
47 const std::string& file_name); 49 const std::string& file_name);
48 50
49 static PolicyProviderTestHarness* Create(); 51 static PolicyProviderTestHarness* Create();
50 52
51 private: 53 private:
52 ScopedTempDir test_dir_; 54 ScopedTempDir test_dir_;
53 55
54 DISALLOW_COPY_AND_ASSIGN(TestHarness); 56 DISALLOW_COPY_AND_ASSIGN(TestHarness);
55 }; 57 };
56 58
57 TestHarness::TestHarness() {} 59 TestHarness::TestHarness()
60 : PolicyProviderTestHarness(POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE) {}
58 61
59 TestHarness::~TestHarness() {} 62 TestHarness::~TestHarness() {}
60 63
61 void TestHarness::SetUp() { 64 void TestHarness::SetUp() {
62 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); 65 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
63 } 66 }
64 67
65 AsynchronousPolicyProvider* TestHarness::CreateProvider( 68 AsynchronousPolicyProvider* TestHarness::CreateProvider(
66 const PolicyDefinitionList* policy_definition_list) { 69 const PolicyDefinitionList* policy_definition_list) {
67 return new ConfigDirPolicyProvider(policy_definition_list, 70 return new ConfigDirPolicyProvider(policy_definition_list,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 145
143 TestHarness harness_; 146 TestHarness harness_;
144 }; 147 };
145 148
146 // The preferences dictionary is expected to be empty when there are no files to 149 // The preferences dictionary is expected to be empty when there are no files to
147 // load. 150 // load.
148 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) { 151 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsEmpty) {
149 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(), 152 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
150 POLICY_LEVEL_MANDATORY, 153 POLICY_LEVEL_MANDATORY,
151 POLICY_SCOPE_MACHINE); 154 POLICY_SCOPE_MACHINE);
152 scoped_ptr<PolicyMap> policy(loader.Load()); 155 scoped_ptr<PolicyBundle> bundle(loader.Load());
153 EXPECT_TRUE(policy.get()); 156 ASSERT_TRUE(bundle.get());
154 EXPECT_TRUE(policy->empty()); 157 const PolicyBundle kEmptyBundle;
158 EXPECT_TRUE(bundle->Equals(kEmptyBundle));
155 } 159 }
156 160
157 // Reading from a non-existent directory should result in an empty preferences 161 // Reading from a non-existent directory should result in an empty preferences
158 // dictionary. 162 // dictionary.
159 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) { 163 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsNonExistentDirectory) {
160 FilePath non_existent_dir( 164 FilePath non_existent_dir(
161 harness_.test_dir().Append(FILE_PATH_LITERAL("not_there"))); 165 harness_.test_dir().Append(FILE_PATH_LITERAL("not_there")));
162 ConfigDirPolicyProviderDelegate loader(non_existent_dir, 166 ConfigDirPolicyProviderDelegate loader(non_existent_dir,
163 POLICY_LEVEL_MANDATORY, 167 POLICY_LEVEL_MANDATORY,
164 POLICY_SCOPE_MACHINE); 168 POLICY_SCOPE_MACHINE);
165 scoped_ptr<PolicyMap> policy(loader.Load()); 169 scoped_ptr<PolicyBundle> bundle(loader.Load());
166 EXPECT_TRUE(policy.get()); 170 ASSERT_TRUE(bundle.get());
167 EXPECT_TRUE(policy->empty()); 171 const PolicyBundle kEmptyBundle;
172 EXPECT_TRUE(bundle->Equals(kEmptyBundle));
168 } 173 }
169 174
170 // Test merging values from different files. 175 // Test merging values from different files.
171 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) { 176 TEST_F(ConfigDirPolicyLoaderTest, ReadPrefsMergePrefs) {
172 // Write a bunch of data files in order to increase the chance to detect the 177 // 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 178 // 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, 179 // filesystem may return files in arbitrary order, there is no way to be sure,
175 // but this is better than nothing. 180 // but this is better than nothing.
176 base::DictionaryValue test_dict_bar; 181 base::DictionaryValue test_dict_bar;
177 test_dict_bar.SetString("HomepageLocation", "http://bar.com"); 182 test_dict_bar.SetString("HomepageLocation", "http://bar.com");
178 for (unsigned int i = 1; i <= 4; ++i) 183 for (unsigned int i = 1; i <= 4; ++i)
179 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i)); 184 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
180 base::DictionaryValue test_dict_foo; 185 base::DictionaryValue test_dict_foo;
181 test_dict_foo.SetString("HomepageLocation", "http://foo.com"); 186 test_dict_foo.SetString("HomepageLocation", "http://foo.com");
182 harness_.WriteConfigFile(test_dict_foo, "9"); 187 harness_.WriteConfigFile(test_dict_foo, "9");
183 for (unsigned int i = 5; i <= 8; ++i) 188 for (unsigned int i = 5; i <= 8; ++i)
184 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i)); 189 harness_.WriteConfigFile(test_dict_bar, base::IntToString(i));
185 190
186 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(), 191 ConfigDirPolicyProviderDelegate loader(harness_.test_dir(),
187 POLICY_LEVEL_MANDATORY, 192 POLICY_LEVEL_MANDATORY,
188 POLICY_SCOPE_USER); 193 POLICY_SCOPE_USER);
189 scoped_ptr<PolicyMap> policy(loader.Load()); 194 scoped_ptr<PolicyBundle> bundle(loader.Load());
190 EXPECT_TRUE(policy.get()); 195 ASSERT_TRUE(bundle.get());
191 PolicyMap expected; 196 PolicyBundle expected_bundle;
192 expected.LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER); 197 expected_bundle.Get(POLICY_DOMAIN_CHROME, "")
193 EXPECT_TRUE(policy->Equals(expected)); 198 .LoadFrom(&test_dict_foo, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER);
199 EXPECT_TRUE(bundle->Equals(expected_bundle));
194 } 200 }
195 201
196 } // namespace policy 202 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/config_dir_policy_provider.cc ('k') | chrome/browser/policy/configuration_policy_provider.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698