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

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

Issue 58313002: Removed the PolicyDefinitionList. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@chrome-policy-schema-10-use-registry
Patch Set: Created 7 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) 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 "chrome/browser/policy/configuration_policy_provider_test.h" 5 #include "chrome/browser/policy/configuration_policy_provider_test.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/values.h" 10 #include "base/values.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 " }" 104 " }"
105 " }" 105 " }"
106 " }" 106 " }"
107 " }" 107 " }"
108 " }" 108 " }"
109 " }" 109 " }"
110 " }" 110 " }"
111 " }" 111 " }"
112 "}"; 112 "}";
113 113
114 namespace test_policy_definitions { 114 namespace test_keys {
115 115
116 const char kKeyString[] = "StringPolicy"; 116 const char kKeyString[] = "StringPolicy";
117 const char kKeyBoolean[] = "BooleanPolicy"; 117 const char kKeyBoolean[] = "BooleanPolicy";
118 const char kKeyInteger[] = "IntegerPolicy"; 118 const char kKeyInteger[] = "IntegerPolicy";
119 const char kKeyStringList[] = "StringListPolicy"; 119 const char kKeyStringList[] = "StringListPolicy";
120 const char kKeyDictionary[] = "DictionaryPolicy"; 120 const char kKeyDictionary[] = "DictionaryPolicy";
121 121
122 static const PolicyDefinitionList::Entry kEntries[] = { 122 } // namespace test_keys
123 { kKeyString, base::Value::TYPE_STRING },
124 { kKeyBoolean, base::Value::TYPE_BOOLEAN },
125 { kKeyInteger, base::Value::TYPE_INTEGER },
126 { kKeyStringList, base::Value::TYPE_LIST },
127 { kKeyDictionary, base::Value::TYPE_DICTIONARY },
128 };
129
130 const PolicyDefinitionList kList = {
131 kEntries, kEntries + arraysize(kEntries)
132 };
133
134 } // namespace test_policy_definitions
135 123
136 PolicyTestBase::PolicyTestBase() {} 124 PolicyTestBase::PolicyTestBase() {}
137 125
138 PolicyTestBase::~PolicyTestBase() {} 126 PolicyTestBase::~PolicyTestBase() {}
139 127
140 void PolicyTestBase::SetUp() { 128 void PolicyTestBase::SetUp() {
141 std::string error; 129 std::string error;
142 chrome_schema_ = Schema::Parse(kTestChromeSchema, &error); 130 chrome_schema_ = Schema::Parse(kTestChromeSchema, &error);
143 ASSERT_TRUE(chrome_schema_.valid()) << error; 131 ASSERT_TRUE(chrome_schema_.valid()) << error;
144 schema_registry_.RegisterComponent(PolicyNamespace(POLICY_DOMAIN_CHROME, ""), 132 schema_registry_.RegisterComponent(PolicyNamespace(POLICY_DOMAIN_CHROME, ""),
(...skipping 27 matching lines...) Expand all
172 160
173 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} 161 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {}
174 162
175 void ConfigurationPolicyProviderTest::SetUp() { 163 void ConfigurationPolicyProviderTest::SetUp() {
176 PolicyTestBase::SetUp(); 164 PolicyTestBase::SetUp();
177 165
178 test_harness_.reset((*GetParam())()); 166 test_harness_.reset((*GetParam())());
179 test_harness_->SetUp(); 167 test_harness_->SetUp();
180 168
181 Schema extension_schema = 169 Schema extension_schema =
182 chrome_schema_.GetKnownProperty(test_policy_definitions::kKeyDictionary); 170 chrome_schema_.GetKnownProperty(test_keys::kKeyDictionary);
183 ASSERT_TRUE(extension_schema.valid()); 171 ASSERT_TRUE(extension_schema.valid());
184 schema_registry_.RegisterComponent( 172 schema_registry_.RegisterComponent(
185 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 173 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
186 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"), 174 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"),
187 extension_schema); 175 extension_schema);
188 schema_registry_.RegisterComponent( 176 schema_registry_.RegisterComponent(
189 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 177 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
190 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"), 178 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"),
191 extension_schema); 179 extension_schema);
192 schema_registry_.RegisterComponent( 180 schema_registry_.RegisterComponent(
193 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 181 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
194 "cccccccccccccccccccccccccccccccc"), 182 "cccccccccccccccccccccccccccccccc"),
195 extension_schema); 183 extension_schema);
196 184
197 provider_.reset(test_harness_->CreateProvider( 185 provider_.reset(test_harness_->CreateProvider(&schema_registry_,
198 &schema_registry_, 186 loop_.message_loop_proxy()));
199 loop_.message_loop_proxy(),
200 &test_policy_definitions::kList));
201 provider_->Init(&schema_registry_); 187 provider_->Init(&schema_registry_);
202 // Some providers do a reload on init. Make sure any notifications generated 188 // Some providers do a reload on init. Make sure any notifications generated
203 // are fired now. 189 // are fired now.
204 loop_.RunUntilIdle(); 190 loop_.RunUntilIdle();
205 191
206 const PolicyBundle kEmptyBundle; 192 const PolicyBundle kEmptyBundle;
207 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 193 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
208 } 194 }
209 195
210 void ConfigurationPolicyProviderTest::TearDown() { 196 void ConfigurationPolicyProviderTest::TearDown() {
(...skipping 27 matching lines...) Expand all
238 TEST_P(ConfigurationPolicyProviderTest, Empty) { 224 TEST_P(ConfigurationPolicyProviderTest, Empty) {
239 provider_->RefreshPolicies(); 225 provider_->RefreshPolicies();
240 loop_.RunUntilIdle(); 226 loop_.RunUntilIdle();
241 const PolicyBundle kEmptyBundle; 227 const PolicyBundle kEmptyBundle;
242 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 228 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
243 } 229 }
244 230
245 TEST_P(ConfigurationPolicyProviderTest, StringValue) { 231 TEST_P(ConfigurationPolicyProviderTest, StringValue) {
246 const char kTestString[] = "string_value"; 232 const char kTestString[] = "string_value";
247 base::StringValue expected_value(kTestString); 233 base::StringValue expected_value(kTestString);
248 CheckValue(test_policy_definitions::kKeyString, 234 CheckValue(test_keys::kKeyString,
249 expected_value, 235 expected_value,
250 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, 236 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy,
251 base::Unretained(test_harness_.get()), 237 base::Unretained(test_harness_.get()),
252 test_policy_definitions::kKeyString, 238 test_keys::kKeyString,
253 kTestString)); 239 kTestString));
254 } 240 }
255 241
256 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) { 242 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) {
257 base::FundamentalValue expected_value(true); 243 base::FundamentalValue expected_value(true);
258 CheckValue(test_policy_definitions::kKeyBoolean, 244 CheckValue(test_keys::kKeyBoolean,
259 expected_value, 245 expected_value,
260 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy, 246 base::Bind(&PolicyProviderTestHarness::InstallBooleanPolicy,
261 base::Unretained(test_harness_.get()), 247 base::Unretained(test_harness_.get()),
262 test_policy_definitions::kKeyBoolean, 248 test_keys::kKeyBoolean,
263 true)); 249 true));
264 } 250 }
265 251
266 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) { 252 TEST_P(ConfigurationPolicyProviderTest, IntegerValue) {
267 base::FundamentalValue expected_value(42); 253 base::FundamentalValue expected_value(42);
268 CheckValue(test_policy_definitions::kKeyInteger, 254 CheckValue(test_keys::kKeyInteger,
269 expected_value, 255 expected_value,
270 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, 256 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy,
271 base::Unretained(test_harness_.get()), 257 base::Unretained(test_harness_.get()),
272 test_policy_definitions::kKeyInteger, 258 test_keys::kKeyInteger,
273 42)); 259 42));
274 } 260 }
275 261
276 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { 262 TEST_P(ConfigurationPolicyProviderTest, StringListValue) {
277 base::ListValue expected_value; 263 base::ListValue expected_value;
278 expected_value.Set(0U, base::Value::CreateStringValue("first")); 264 expected_value.Set(0U, base::Value::CreateStringValue("first"));
279 expected_value.Set(1U, base::Value::CreateStringValue("second")); 265 expected_value.Set(1U, base::Value::CreateStringValue("second"));
280 CheckValue(test_policy_definitions::kKeyStringList, 266 CheckValue(test_keys::kKeyStringList,
281 expected_value, 267 expected_value,
282 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, 268 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy,
283 base::Unretained(test_harness_.get()), 269 base::Unretained(test_harness_.get()),
284 test_policy_definitions::kKeyStringList, 270 test_keys::kKeyStringList,
285 &expected_value)); 271 &expected_value));
286 } 272 }
287 273
288 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { 274 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) {
289 base::DictionaryValue expected_value; 275 base::DictionaryValue expected_value;
290 expected_value.SetBoolean("bool", true); 276 expected_value.SetBoolean("bool", true);
291 expected_value.SetDouble("double", 123.456); 277 expected_value.SetDouble("double", 123.456);
292 expected_value.SetInteger("int", 123); 278 expected_value.SetInteger("int", 123);
293 expected_value.SetString("string", "omg"); 279 expected_value.SetString("string", "omg");
294 280
295 base::ListValue* list = new base::ListValue(); 281 base::ListValue* list = new base::ListValue();
296 list->Set(0U, base::Value::CreateStringValue("first")); 282 list->Set(0U, base::Value::CreateStringValue("first"));
297 list->Set(1U, base::Value::CreateStringValue("second")); 283 list->Set(1U, base::Value::CreateStringValue("second"));
298 expected_value.Set("array", list); 284 expected_value.Set("array", list);
299 285
300 base::DictionaryValue* dict = new base::DictionaryValue(); 286 base::DictionaryValue* dict = new base::DictionaryValue();
301 dict->SetString("sub", "value"); 287 dict->SetString("sub", "value");
302 list = new base::ListValue(); 288 list = new base::ListValue();
303 base::DictionaryValue* sub = new base::DictionaryValue(); 289 base::DictionaryValue* sub = new base::DictionaryValue();
304 sub->SetInteger("aaa", 111); 290 sub->SetInteger("aaa", 111);
305 sub->SetInteger("bbb", 222); 291 sub->SetInteger("bbb", 222);
306 list->Append(sub); 292 list->Append(sub);
307 sub = new base::DictionaryValue(); 293 sub = new base::DictionaryValue();
308 sub->SetString("ccc", "333"); 294 sub->SetString("ccc", "333");
309 sub->SetString("ddd", "444"); 295 sub->SetString("ddd", "444");
310 list->Append(sub); 296 list->Append(sub);
311 dict->Set("sublist", list); 297 dict->Set("sublist", list);
312 expected_value.Set("dictionary", dict); 298 expected_value.Set("dictionary", dict);
313 299
314 CheckValue(test_policy_definitions::kKeyDictionary, 300 CheckValue(test_keys::kKeyDictionary,
315 expected_value, 301 expected_value,
316 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy, 302 base::Bind(&PolicyProviderTestHarness::InstallDictionaryPolicy,
317 base::Unretained(test_harness_.get()), 303 base::Unretained(test_harness_.get()),
318 test_policy_definitions::kKeyDictionary, 304 test_keys::kKeyDictionary,
319 &expected_value)); 305 &expected_value));
320 } 306 }
321 307
322 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) { 308 TEST_P(ConfigurationPolicyProviderTest, RefreshPolicies) {
323 PolicyBundle bundle; 309 PolicyBundle bundle;
324 EXPECT_TRUE(provider_->policies().Equals(bundle)); 310 EXPECT_TRUE(provider_->policies().Equals(bundle));
325 311
326 // OnUpdatePolicy is called even when there are no changes. 312 // OnUpdatePolicy is called even when there are no changes.
327 MockConfigurationPolicyObserver observer; 313 MockConfigurationPolicyObserver observer;
328 provider_->AddObserver(&observer); 314 provider_->AddObserver(&observer);
329 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 315 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
330 provider_->RefreshPolicies(); 316 provider_->RefreshPolicies();
331 loop_.RunUntilIdle(); 317 loop_.RunUntilIdle();
332 Mock::VerifyAndClearExpectations(&observer); 318 Mock::VerifyAndClearExpectations(&observer);
333 319
334 EXPECT_TRUE(provider_->policies().Equals(bundle)); 320 EXPECT_TRUE(provider_->policies().Equals(bundle));
335 321
336 // OnUpdatePolicy is called when there are changes. 322 // OnUpdatePolicy is called when there are changes.
337 test_harness_->InstallStringPolicy(test_policy_definitions::kKeyString, 323 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value");
338 "value");
339 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 324 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
340 provider_->RefreshPolicies(); 325 provider_->RefreshPolicies();
341 loop_.RunUntilIdle(); 326 loop_.RunUntilIdle();
342 Mock::VerifyAndClearExpectations(&observer); 327 Mock::VerifyAndClearExpectations(&observer);
343 328
344 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 329 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
345 .Set(test_policy_definitions::kKeyString, 330 .Set(test_keys::kKeyString,
346 test_harness_->policy_level(), 331 test_harness_->policy_level(),
347 test_harness_->policy_scope(), 332 test_harness_->policy_scope(),
348 base::Value::CreateStringValue("value"), 333 base::Value::CreateStringValue("value"),
349 NULL); 334 NULL);
350 EXPECT_TRUE(provider_->policies().Equals(bundle)); 335 EXPECT_TRUE(provider_->policies().Equals(bundle));
351 provider_->RemoveObserver(&observer); 336 provider_->RemoveObserver(&observer);
352 } 337 }
353 338
354 TEST(ConfigurationPolicyProviderTest, FixDeprecatedPolicies) { 339 TEST(ConfigurationPolicyProviderTest, FixDeprecatedPolicies) {
355 PolicyMap policy_map; 340 PolicyMap policy_map;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 for (int i = 0; i < 2; ++i) { 391 for (int i = 0; i < 2; ++i) {
407 base::DictionaryValue* dict = new base::DictionaryValue(); 392 base::DictionaryValue* dict = new base::DictionaryValue();
408 dict->SetInteger("subdictindex", i); 393 dict->SetInteger("subdictindex", i);
409 dict->Set("subdict", policy_dict.DeepCopy()); 394 dict->Set("subdict", policy_dict.DeepCopy());
410 list->Append(dict); 395 list->Append(dict);
411 } 396 }
412 policy_dict.Set("list", list); 397 policy_dict.Set("list", list);
413 policy_dict.Set("dict", policy_dict.DeepCopy()); 398 policy_dict.Set("dict", policy_dict.DeepCopy());
414 399
415 // Install these policies as a Chrome policy. 400 // Install these policies as a Chrome policy.
416 test_harness_->InstallDictionaryPolicy( 401 test_harness_->InstallDictionaryPolicy(test_keys::kKeyDictionary,
417 test_policy_definitions::kKeyDictionary, &policy_dict); 402 &policy_dict);
418 // Install them as 3rd party policies too. 403 // Install them as 3rd party policies too.
419 base::DictionaryValue policy_3rdparty; 404 base::DictionaryValue policy_3rdparty;
420 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", 405 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
421 policy_dict.DeepCopy()); 406 policy_dict.DeepCopy());
422 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 407 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
423 policy_dict.DeepCopy()); 408 policy_dict.DeepCopy());
424 // Install invalid 3rd party policies that shouldn't be loaded. These also 409 // Install invalid 3rd party policies that shouldn't be loaded. These also
425 // help detecting memory leaks in the code paths that detect invalid input. 410 // help detecting memory leaks in the code paths that detect invalid input.
426 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); 411 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy());
427 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", 412 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc",
428 base::Value::CreateStringValue("invalid-value")); 413 base::Value::CreateStringValue("invalid-value"));
429 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); 414 test_harness_->Install3rdPartyPolicy(&policy_3rdparty);
430 415
431 provider_->RefreshPolicies(); 416 provider_->RefreshPolicies();
432 loop_.RunUntilIdle(); 417 loop_.RunUntilIdle();
433 418
434 PolicyMap expected_policy; 419 PolicyMap expected_policy;
435 expected_policy.Set(test_policy_definitions::kKeyDictionary, 420 expected_policy.Set(test_keys::kKeyDictionary,
436 test_harness_->policy_level(), 421 test_harness_->policy_level(),
437 test_harness_->policy_scope(), 422 test_harness_->policy_scope(),
438 policy_dict.DeepCopy(), 423 policy_dict.DeepCopy(),
439 NULL); 424 NULL);
440 PolicyBundle expected_bundle; 425 PolicyBundle expected_bundle;
441 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 426 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
442 .CopyFrom(expected_policy); 427 .CopyFrom(expected_policy);
443 expected_policy.Clear(); 428 expected_policy.Clear();
444 expected_policy.LoadFrom(&policy_dict, 429 expected_policy.LoadFrom(&policy_dict,
445 test_harness_->policy_level(), 430 test_harness_->policy_level(),
446 test_harness_->policy_scope()); 431 test_harness_->policy_scope());
447 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 432 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
448 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) 433 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
449 .CopyFrom(expected_policy); 434 .CopyFrom(expected_policy);
450 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 435 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
451 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 436 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
452 .CopyFrom(expected_policy); 437 .CopyFrom(expected_policy);
453 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 438 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
454 } 439 }
455 440
456 } // namespace policy 441 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698