| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/policy/core/common/configuration_policy_provider_test.h" | 5 #include "components/policy/core/common/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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 CheckValue(test_keys::kKeyInteger, | 265 CheckValue(test_keys::kKeyInteger, |
| 266 expected_value, | 266 expected_value, |
| 267 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, | 267 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, |
| 268 base::Unretained(test_harness_.get()), | 268 base::Unretained(test_harness_.get()), |
| 269 test_keys::kKeyInteger, | 269 test_keys::kKeyInteger, |
| 270 42)); | 270 42)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { | 273 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { |
| 274 base::ListValue expected_value; | 274 base::ListValue expected_value; |
| 275 expected_value.Set(0U, base::Value::CreateStringValue("first")); | 275 expected_value.Set(0U, new base::StringValue("first")); |
| 276 expected_value.Set(1U, base::Value::CreateStringValue("second")); | 276 expected_value.Set(1U, new base::StringValue("second")); |
| 277 CheckValue(test_keys::kKeyStringList, | 277 CheckValue(test_keys::kKeyStringList, |
| 278 expected_value, | 278 expected_value, |
| 279 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, | 279 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, |
| 280 base::Unretained(test_harness_.get()), | 280 base::Unretained(test_harness_.get()), |
| 281 test_keys::kKeyStringList, | 281 test_keys::kKeyStringList, |
| 282 &expected_value)); | 282 &expected_value)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { | 285 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { |
| 286 base::DictionaryValue expected_value; | 286 base::DictionaryValue expected_value; |
| 287 expected_value.SetBoolean("bool", true); | 287 expected_value.SetBoolean("bool", true); |
| 288 expected_value.SetDouble("double", 123.456); | 288 expected_value.SetDouble("double", 123.456); |
| 289 expected_value.SetInteger("int", 123); | 289 expected_value.SetInteger("int", 123); |
| 290 expected_value.SetString("string", "omg"); | 290 expected_value.SetString("string", "omg"); |
| 291 | 291 |
| 292 base::ListValue* list = new base::ListValue(); | 292 base::ListValue* list = new base::ListValue(); |
| 293 list->Set(0U, base::Value::CreateStringValue("first")); | 293 list->Set(0U, new base::StringValue("first")); |
| 294 list->Set(1U, base::Value::CreateStringValue("second")); | 294 list->Set(1U, new base::StringValue("second")); |
| 295 expected_value.Set("array", list); | 295 expected_value.Set("array", list); |
| 296 | 296 |
| 297 base::DictionaryValue* dict = new base::DictionaryValue(); | 297 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 298 dict->SetString("sub", "value"); | 298 dict->SetString("sub", "value"); |
| 299 list = new base::ListValue(); | 299 list = new base::ListValue(); |
| 300 base::DictionaryValue* sub = new base::DictionaryValue(); | 300 base::DictionaryValue* sub = new base::DictionaryValue(); |
| 301 sub->SetInteger("aaa", 111); | 301 sub->SetInteger("aaa", 111); |
| 302 sub->SetInteger("bbb", 222); | 302 sub->SetInteger("bbb", 222); |
| 303 list->Append(sub); | 303 list->Append(sub); |
| 304 sub = new base::DictionaryValue(); | 304 sub = new base::DictionaryValue(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 334 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); | 334 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); |
| 335 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 335 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
| 336 provider_->RefreshPolicies(); | 336 provider_->RefreshPolicies(); |
| 337 loop_.RunUntilIdle(); | 337 loop_.RunUntilIdle(); |
| 338 Mock::VerifyAndClearExpectations(&observer); | 338 Mock::VerifyAndClearExpectations(&observer); |
| 339 | 339 |
| 340 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 340 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 341 .Set(test_keys::kKeyString, | 341 .Set(test_keys::kKeyString, |
| 342 test_harness_->policy_level(), | 342 test_harness_->policy_level(), |
| 343 test_harness_->policy_scope(), | 343 test_harness_->policy_scope(), |
| 344 base::Value::CreateStringValue("value"), | 344 new base::StringValue("value"), |
| 345 NULL); | 345 NULL); |
| 346 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 346 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 347 provider_->RemoveObserver(&observer); | 347 provider_->RemoveObserver(&observer); |
| 348 } | 348 } |
| 349 | 349 |
| 350 Configuration3rdPartyPolicyProviderTest:: | 350 Configuration3rdPartyPolicyProviderTest:: |
| 351 Configuration3rdPartyPolicyProviderTest() {} | 351 Configuration3rdPartyPolicyProviderTest() {} |
| 352 | 352 |
| 353 Configuration3rdPartyPolicyProviderTest:: | 353 Configuration3rdPartyPolicyProviderTest:: |
| 354 ~Configuration3rdPartyPolicyProviderTest() {} | 354 ~Configuration3rdPartyPolicyProviderTest() {} |
| (...skipping 21 matching lines...) Expand all Loading... |
| 376 // Install them as 3rd party policies too. | 376 // Install them as 3rd party policies too. |
| 377 base::DictionaryValue policy_3rdparty; | 377 base::DictionaryValue policy_3rdparty; |
| 378 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | 378 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 379 policy_dict.DeepCopy()); | 379 policy_dict.DeepCopy()); |
| 380 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", | 380 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", |
| 381 policy_dict.DeepCopy()); | 381 policy_dict.DeepCopy()); |
| 382 // Install invalid 3rd party policies that shouldn't be loaded. These also | 382 // Install invalid 3rd party policies that shouldn't be loaded. These also |
| 383 // help detecting memory leaks in the code paths that detect invalid input. | 383 // help detecting memory leaks in the code paths that detect invalid input. |
| 384 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); | 384 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); |
| 385 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", | 385 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", |
| 386 base::Value::CreateStringValue("invalid-value")); | 386 new base::StringValue("invalid-value")); |
| 387 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); | 387 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); |
| 388 | 388 |
| 389 provider_->RefreshPolicies(); | 389 provider_->RefreshPolicies(); |
| 390 loop_.RunUntilIdle(); | 390 loop_.RunUntilIdle(); |
| 391 | 391 |
| 392 PolicyMap expected_policy; | 392 PolicyMap expected_policy; |
| 393 expected_policy.Set(test_keys::kKeyDictionary, | 393 expected_policy.Set(test_keys::kKeyDictionary, |
| 394 test_harness_->policy_level(), | 394 test_harness_->policy_level(), |
| 395 test_harness_->policy_scope(), | 395 test_harness_->policy_scope(), |
| 396 policy_dict.DeepCopy(), | 396 policy_dict.DeepCopy(), |
| 397 NULL); | 397 NULL); |
| 398 PolicyBundle expected_bundle; | 398 PolicyBundle expected_bundle; |
| 399 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 399 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 400 .CopyFrom(expected_policy); | 400 .CopyFrom(expected_policy); |
| 401 expected_policy.Clear(); | 401 expected_policy.Clear(); |
| 402 expected_policy.LoadFrom(&policy_dict, | 402 expected_policy.LoadFrom(&policy_dict, |
| 403 test_harness_->policy_level(), | 403 test_harness_->policy_level(), |
| 404 test_harness_->policy_scope()); | 404 test_harness_->policy_scope()); |
| 405 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 405 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 406 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 406 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 407 .CopyFrom(expected_policy); | 407 .CopyFrom(expected_policy); |
| 408 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 408 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 409 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 409 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 410 .CopyFrom(expected_policy); | 410 .CopyFrom(expected_policy); |
| 411 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 411 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 412 } | 412 } |
| 413 | 413 |
| 414 } // namespace policy | 414 } // namespace policy |
| OLD | NEW |