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

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

Issue 3774003: Cleanup and style guideline conformance for policy implementation (Closed) Base URL: git://codf21.jail/chromium.git
Patch Set: fix windows build and tests Created 10 years, 1 month 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/path_service.h" 8 #include "base/path_service.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"
(...skipping 14 matching lines...) Expand all
25 virtual void SetUp() { 25 virtual void SetUp() {
26 ASSERT_TRUE(test_dir_.CreateUniqueTempDir()); 26 ASSERT_TRUE(test_dir_.CreateUniqueTempDir());
27 } 27 }
28 28
29 // JSON-encode a dictionary and write it to a file. 29 // JSON-encode a dictionary and write it to a file.
30 void WriteConfigFile(const DictionaryValue& dict, 30 void WriteConfigFile(const DictionaryValue& dict,
31 const std::string& file_name) { 31 const std::string& file_name) {
32 std::string data; 32 std::string data;
33 JSONStringValueSerializer serializer(&data); 33 JSONStringValueSerializer serializer(&data);
34 serializer.Serialize(dict); 34 serializer.Serialize(dict);
35 FilePath file_path(test_dir().AppendASCII(file_name)); 35 const FilePath file_path(test_dir().AppendASCII(file_name));
36 ASSERT_TRUE(file_util::WriteFile(file_path, data.c_str(), data.size())); 36 ASSERT_TRUE(file_util::WriteFile(file_path, data.c_str(), data.size()));
37 } 37 }
38 38
39 const FilePath& test_dir() { return test_dir_.path(); } 39 const FilePath& test_dir() { return test_dir_.path(); }
40 40
41 private: 41 private:
42 ScopedTempDir test_dir_; 42 ScopedTempDir test_dir_;
43 }; 43 };
44 44
45 class ConfigDirPolicyLoaderTest 45 class ConfigDirPolicyLoaderTest
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 scoped_ptr<DictionaryValue> policy(loader.Load()); 97 scoped_ptr<DictionaryValue> policy(loader.Load());
98 EXPECT_TRUE(policy.get()); 98 EXPECT_TRUE(policy.get());
99 EXPECT_TRUE(policy->Equals(&test_dict_foo)); 99 EXPECT_TRUE(policy->Equals(&test_dict_foo));
100 } 100 }
101 101
102 // Holds policy type, corresponding policy key string and a valid value for use 102 // Holds policy type, corresponding policy key string and a valid value for use
103 // in parametrized value tests. 103 // in parametrized value tests.
104 class ValueTestParams { 104 class ValueTestParams {
105 public: 105 public:
106 // Assumes ownership of |test_value|. 106 // Assumes ownership of |test_value|.
107 ValueTestParams(ConfigurationPolicyStore::PolicyType type, 107 ValueTestParams(ConfigurationPolicyType type,
108 const char* policy_key, 108 const char* policy_key,
109 Value* test_value) 109 Value* test_value)
110 : type_(type), 110 : type_(type),
111 policy_key_(policy_key), 111 policy_key_(policy_key),
112 test_value_(test_value) {} 112 test_value_(test_value) {}
113 113
114 // testing::TestWithParam does copying, so provide copy constructor and 114 // testing::TestWithParam does copying, so provide copy constructor and
115 // assignment operator. 115 // assignment operator.
116 ValueTestParams(const ValueTestParams& other) 116 ValueTestParams(const ValueTestParams& other)
117 : type_(other.type_), 117 : type_(other.type_),
118 policy_key_(other.policy_key_), 118 policy_key_(other.policy_key_),
119 test_value_(other.test_value_->DeepCopy()) {} 119 test_value_(other.test_value_->DeepCopy()) {}
120 120
121 const ValueTestParams& operator=(ValueTestParams other) { 121 const ValueTestParams& operator=(ValueTestParams other) {
122 swap(other); 122 swap(other);
123 return *this; 123 return *this;
124 } 124 }
125 125
126 void swap(ValueTestParams& other) { 126 void swap(ValueTestParams& other) {
127 std::swap(type_, other.type_); 127 std::swap(type_, other.type_);
128 std::swap(policy_key_, other.policy_key_); 128 std::swap(policy_key_, other.policy_key_);
129 test_value_.swap(other.test_value_); 129 test_value_.swap(other.test_value_);
130 } 130 }
131 131
132 ConfigurationPolicyStore::PolicyType type() const { return type_; } 132 ConfigurationPolicyType type() const { return type_; }
133 const char* policy_key() const { return policy_key_; } 133 const char* policy_key() const { return policy_key_; }
134 const Value* test_value() const { return test_value_.get(); } 134 const Value* test_value() const { return test_value_.get(); }
135 135
136 // Factory methods that create parameter objects for different value types. 136 // Factory methods that create parameter objects for different value types.
137 static ValueTestParams ForStringPolicy( 137 static ValueTestParams ForStringPolicy(
138 ConfigurationPolicyStore::PolicyType type, 138 ConfigurationPolicyType type,
139 const char* policy_key) { 139 const char* policy_key) {
140 return ValueTestParams(type, policy_key, Value::CreateStringValue("test")); 140 return ValueTestParams(type, policy_key, Value::CreateStringValue("test"));
141 } 141 }
142 static ValueTestParams ForBooleanPolicy( 142 static ValueTestParams ForBooleanPolicy(
143 ConfigurationPolicyStore::PolicyType type, 143 ConfigurationPolicyType type,
144 const char* policy_key) { 144 const char* policy_key) {
145 return ValueTestParams(type, policy_key, Value::CreateBooleanValue(true)); 145 return ValueTestParams(type, policy_key, Value::CreateBooleanValue(true));
146 } 146 }
147 static ValueTestParams ForIntegerPolicy( 147 static ValueTestParams ForIntegerPolicy(
148 ConfigurationPolicyStore::PolicyType type, 148 ConfigurationPolicyType type,
149 const char* policy_key) { 149 const char* policy_key) {
150 return ValueTestParams(type, policy_key, Value::CreateIntegerValue(42)); 150 return ValueTestParams(type, policy_key, Value::CreateIntegerValue(42));
151 } 151 }
152 static ValueTestParams ForListPolicy( 152 static ValueTestParams ForListPolicy(
153 ConfigurationPolicyStore::PolicyType type, 153 ConfigurationPolicyType type,
154 const char* policy_key) { 154 const char* policy_key) {
155 ListValue* value = new ListValue(); 155 ListValue* value = new ListValue();
156 value->Set(0U, Value::CreateStringValue("first")); 156 value->Set(0U, Value::CreateStringValue("first"));
157 value->Set(1U, Value::CreateStringValue("second")); 157 value->Set(1U, Value::CreateStringValue("second"));
158 return ValueTestParams(type, policy_key, value); 158 return ValueTestParams(type, policy_key, value);
159 } 159 }
160 160
161 private: 161 private:
162 ConfigurationPolicyStore::PolicyType type_; 162 ConfigurationPolicyType type_;
163 const char* policy_key_; 163 const char* policy_key_;
164 scoped_ptr<Value> test_value_; 164 scoped_ptr<Value> test_value_;
165 }; 165 };
166 166
167 // Tests whether the provider correctly reads a value from the file and forwards 167 // Tests whether the provider correctly reads a value from the file and forwards
168 // it to the store. 168 // it to the store.
169 class ConfigDirPolicyProviderValueTest 169 class ConfigDirPolicyProviderValueTest
170 : public ConfigDirPolicyProviderTestBase< 170 : public ConfigDirPolicyProviderTestBase<
171 testing::TestWithParam<ValueTestParams> > { 171 testing::TestWithParam<ValueTestParams> > {
172 protected: 172 protected:
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 ASSERT_TRUE(value); 218 ASSERT_TRUE(value);
219 EXPECT_TRUE(GetParam().test_value()->Equals(value)); 219 EXPECT_TRUE(GetParam().test_value()->Equals(value));
220 } 220 }
221 221
222 // Test parameters for all supported policies. 222 // Test parameters for all supported policies.
223 INSTANTIATE_TEST_CASE_P( 223 INSTANTIATE_TEST_CASE_P(
224 ConfigDirPolicyProviderValueTestInstance, 224 ConfigDirPolicyProviderValueTestInstance,
225 ConfigDirPolicyProviderValueTest, 225 ConfigDirPolicyProviderValueTest,
226 testing::Values( 226 testing::Values(
227 ValueTestParams::ForStringPolicy( 227 ValueTestParams::ForStringPolicy(
228 ConfigurationPolicyStore::kPolicyHomePage, 228 kPolicyHomePage,
229 key::kHomepageLocation), 229 key::kHomepageLocation),
230 ValueTestParams::ForBooleanPolicy( 230 ValueTestParams::ForBooleanPolicy(
231 ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, 231 kPolicyHomepageIsNewTabPage,
232 key::kHomepageIsNewTabPage), 232 key::kHomepageIsNewTabPage),
233 ValueTestParams::ForIntegerPolicy( 233 ValueTestParams::ForIntegerPolicy(
234 ConfigurationPolicyStore::kPolicyRestoreOnStartup, 234 kPolicyRestoreOnStartup,
235 key::kRestoreOnStartup), 235 key::kRestoreOnStartup),
236 ValueTestParams::ForListPolicy( 236 ValueTestParams::ForListPolicy(
237 ConfigurationPolicyStore::kPolicyURLsToRestoreOnStartup, 237 kPolicyURLsToRestoreOnStartup,
238 key::kURLsToRestoreOnStartup), 238 key::kURLsToRestoreOnStartup),
239 ValueTestParams::ForBooleanPolicy( 239 ValueTestParams::ForBooleanPolicy(
240 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEnabled, 240 kPolicyDefaultSearchProviderEnabled,
241 key::kDefaultSearchProviderEnabled), 241 key::kDefaultSearchProviderEnabled),
242 ValueTestParams::ForStringPolicy( 242 ValueTestParams::ForStringPolicy(
243 ConfigurationPolicyStore::kPolicyDefaultSearchProviderName, 243 kPolicyDefaultSearchProviderName,
244 key::kDefaultSearchProviderName), 244 key::kDefaultSearchProviderName),
245 ValueTestParams::ForStringPolicy( 245 ValueTestParams::ForStringPolicy(
246 ConfigurationPolicyStore::kPolicyDefaultSearchProviderKeyword, 246 kPolicyDefaultSearchProviderKeyword,
247 key::kDefaultSearchProviderKeyword), 247 key::kDefaultSearchProviderKeyword),
248 ValueTestParams::ForStringPolicy( 248 ValueTestParams::ForStringPolicy(
249 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSearchURL, 249 kPolicyDefaultSearchProviderSearchURL,
250 key::kDefaultSearchProviderSearchURL), 250 key::kDefaultSearchProviderSearchURL),
251 ValueTestParams::ForStringPolicy( 251 ValueTestParams::ForStringPolicy(
252 ConfigurationPolicyStore::kPolicyDefaultSearchProviderSuggestURL, 252 kPolicyDefaultSearchProviderSuggestURL,
253 key::kDefaultSearchProviderSuggestURL), 253 key::kDefaultSearchProviderSuggestURL),
254 ValueTestParams::ForStringPolicy( 254 ValueTestParams::ForStringPolicy(
255 ConfigurationPolicyStore::kPolicyDefaultSearchProviderIconURL, 255 kPolicyDefaultSearchProviderIconURL,
256 key::kDefaultSearchProviderIconURL), 256 key::kDefaultSearchProviderIconURL),
257 ValueTestParams::ForStringPolicy( 257 ValueTestParams::ForStringPolicy(
258 ConfigurationPolicyStore::kPolicyDefaultSearchProviderEncodings, 258 kPolicyDefaultSearchProviderEncodings,
259 key::kDefaultSearchProviderEncodings), 259 key::kDefaultSearchProviderEncodings),
260 ValueTestParams::ForIntegerPolicy( 260 ValueTestParams::ForIntegerPolicy(
261 ConfigurationPolicyStore::kPolicyProxyServerMode, 261 kPolicyProxyServerMode,
262 key::kProxyServerMode), 262 key::kProxyServerMode),
263 ValueTestParams::ForStringPolicy( 263 ValueTestParams::ForStringPolicy(
264 ConfigurationPolicyStore::kPolicyProxyServer, 264 kPolicyProxyServer,
265 key::kProxyServer), 265 key::kProxyServer),
266 ValueTestParams::ForStringPolicy( 266 ValueTestParams::ForStringPolicy(
267 ConfigurationPolicyStore::kPolicyProxyPacUrl, 267 kPolicyProxyPacUrl,
268 key::kProxyPacUrl), 268 key::kProxyPacUrl),
269 ValueTestParams::ForStringPolicy( 269 ValueTestParams::ForStringPolicy(
270 ConfigurationPolicyStore::kPolicyProxyBypassList, 270 kPolicyProxyBypassList,
271 key::kProxyBypassList), 271 key::kProxyBypassList),
272 ValueTestParams::ForBooleanPolicy( 272 ValueTestParams::ForBooleanPolicy(
273 ConfigurationPolicyStore::kPolicyAlternateErrorPagesEnabled, 273 kPolicyAlternateErrorPagesEnabled,
274 key::kAlternateErrorPagesEnabled), 274 key::kAlternateErrorPagesEnabled),
275 ValueTestParams::ForBooleanPolicy( 275 ValueTestParams::ForBooleanPolicy(
276 ConfigurationPolicyStore::kPolicySearchSuggestEnabled, 276 kPolicySearchSuggestEnabled,
277 key::kSearchSuggestEnabled), 277 key::kSearchSuggestEnabled),
278 ValueTestParams::ForBooleanPolicy( 278 ValueTestParams::ForBooleanPolicy(
279 ConfigurationPolicyStore::kPolicyDnsPrefetchingEnabled, 279 kPolicyDnsPrefetchingEnabled,
280 key::kDnsPrefetchingEnabled), 280 key::kDnsPrefetchingEnabled),
281 ValueTestParams::ForBooleanPolicy( 281 ValueTestParams::ForBooleanPolicy(
282 ConfigurationPolicyStore::kPolicySafeBrowsingEnabled, 282 kPolicySafeBrowsingEnabled,
283 key::kSafeBrowsingEnabled), 283 key::kSafeBrowsingEnabled),
284 ValueTestParams::ForBooleanPolicy( 284 ValueTestParams::ForBooleanPolicy(
285 ConfigurationPolicyStore::kPolicyMetricsReportingEnabled, 285 kPolicyMetricsReportingEnabled,
286 key::kMetricsReportingEnabled), 286 key::kMetricsReportingEnabled),
287 ValueTestParams::ForBooleanPolicy( 287 ValueTestParams::ForBooleanPolicy(
288 ConfigurationPolicyStore::kPolicyPasswordManagerEnabled, 288 kPolicyPasswordManagerEnabled,
289 key::kPasswordManagerEnabled), 289 key::kPasswordManagerEnabled),
290 ValueTestParams::ForBooleanPolicy( 290 ValueTestParams::ForBooleanPolicy(
291 ConfigurationPolicyStore::kPolicyPasswordManagerAllowShowPasswords, 291 kPolicyPasswordManagerAllowShowPasswords,
292 key::kPasswordManagerAllowShowPasswords), 292 key::kPasswordManagerAllowShowPasswords),
293 ValueTestParams::ForListPolicy( 293 ValueTestParams::ForListPolicy(
294 ConfigurationPolicyStore::kPolicyDisabledPlugins, 294 kPolicyDisabledPlugins,
295 key::kDisabledPlugins), 295 key::kDisabledPlugins),
296 ValueTestParams::ForBooleanPolicy( 296 ValueTestParams::ForBooleanPolicy(
297 ConfigurationPolicyStore::kPolicyAutoFillEnabled, 297 kPolicyAutoFillEnabled,
298 key::kAutoFillEnabled), 298 key::kAutoFillEnabled),
299 ValueTestParams::ForStringPolicy( 299 ValueTestParams::ForStringPolicy(
300 ConfigurationPolicyStore::kPolicyApplicationLocale, 300 kPolicyApplicationLocale,
301 key::kApplicationLocaleValue), 301 key::kApplicationLocaleValue),
302 ValueTestParams::ForBooleanPolicy( 302 ValueTestParams::ForBooleanPolicy(
303 ConfigurationPolicyStore::kPolicySyncDisabled, 303 kPolicySyncDisabled,
304 key::kSyncDisabled), 304 key::kSyncDisabled),
305 ValueTestParams::ForListPolicy( 305 ValueTestParams::ForListPolicy(
306 ConfigurationPolicyStore::kPolicyExtensionInstallAllowList, 306 kPolicyExtensionInstallAllowList,
307 key::kExtensionInstallAllowList), 307 key::kExtensionInstallAllowList),
308 ValueTestParams::ForListPolicy( 308 ValueTestParams::ForListPolicy(
309 ConfigurationPolicyStore::kPolicyExtensionInstallDenyList, 309 kPolicyExtensionInstallDenyList,
310 key::kExtensionInstallDenyList), 310 key::kExtensionInstallDenyList),
311 ValueTestParams::ForBooleanPolicy( 311 ValueTestParams::ForBooleanPolicy(
312 ConfigurationPolicyStore::kPolicyShowHomeButton, 312 kPolicyShowHomeButton,
313 key::kShowHomeButton), 313 key::kShowHomeButton),
314 ValueTestParams::ForBooleanPolicy( 314 ValueTestParams::ForBooleanPolicy(
315 ConfigurationPolicyStore::kPolicyPrintingEnabled, 315 kPolicyPrintingEnabled,
316 key::kPrintingEnabled))); 316 key::kPrintingEnabled)));
317 317
318 } // namespace policy 318 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/policy/config_dir_policy_provider.cc ('k') | chrome/browser/policy/configuration_policy_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698