| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 TEST_P(ConfigurationPolicyProviderTest, Empty) { | 247 TEST_P(ConfigurationPolicyProviderTest, Empty) { |
| 248 provider_->RefreshPolicies(); | 248 provider_->RefreshPolicies(); |
| 249 base::RunLoop().RunUntilIdle(); | 249 base::RunLoop().RunUntilIdle(); |
| 250 const PolicyBundle kEmptyBundle; | 250 const PolicyBundle kEmptyBundle; |
| 251 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 251 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 TEST_P(ConfigurationPolicyProviderTest, StringValue) { | 254 TEST_P(ConfigurationPolicyProviderTest, StringValue) { |
| 255 const char kTestString[] = "string_value"; | 255 const char kTestString[] = "string_value"; |
| 256 base::StringValue expected_value(kTestString); | 256 base::Value expected_value(kTestString); |
| 257 CheckValue(test_keys::kKeyString, | 257 CheckValue(test_keys::kKeyString, |
| 258 expected_value, | 258 expected_value, |
| 259 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, | 259 base::Bind(&PolicyProviderTestHarness::InstallStringPolicy, |
| 260 base::Unretained(test_harness_.get()), | 260 base::Unretained(test_harness_.get()), |
| 261 test_keys::kKeyString, | 261 test_keys::kKeyString, |
| 262 kTestString)); | 262 kTestString)); |
| 263 } | 263 } |
| 264 | 264 |
| 265 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) { | 265 TEST_P(ConfigurationPolicyProviderTest, BooleanValue) { |
| 266 base::Value expected_value(true); | 266 base::Value expected_value(true); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 277 CheckValue(test_keys::kKeyInteger, | 277 CheckValue(test_keys::kKeyInteger, |
| 278 expected_value, | 278 expected_value, |
| 279 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, | 279 base::Bind(&PolicyProviderTestHarness::InstallIntegerPolicy, |
| 280 base::Unretained(test_harness_.get()), | 280 base::Unretained(test_harness_.get()), |
| 281 test_keys::kKeyInteger, | 281 test_keys::kKeyInteger, |
| 282 42)); | 282 42)); |
| 283 } | 283 } |
| 284 | 284 |
| 285 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { | 285 TEST_P(ConfigurationPolicyProviderTest, StringListValue) { |
| 286 base::ListValue expected_value; | 286 base::ListValue expected_value; |
| 287 expected_value.Set(0U, new base::StringValue("first")); | 287 expected_value.Set(0U, new base::Value("first")); |
| 288 expected_value.Set(1U, new base::StringValue("second")); | 288 expected_value.Set(1U, new base::Value("second")); |
| 289 CheckValue(test_keys::kKeyStringList, | 289 CheckValue(test_keys::kKeyStringList, |
| 290 expected_value, | 290 expected_value, |
| 291 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, | 291 base::Bind(&PolicyProviderTestHarness::InstallStringListPolicy, |
| 292 base::Unretained(test_harness_.get()), | 292 base::Unretained(test_harness_.get()), |
| 293 test_keys::kKeyStringList, | 293 test_keys::kKeyStringList, |
| 294 &expected_value)); | 294 &expected_value)); |
| 295 } | 295 } |
| 296 | 296 |
| 297 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { | 297 TEST_P(ConfigurationPolicyProviderTest, DictionaryValue) { |
| 298 base::DictionaryValue expected_value; | 298 base::DictionaryValue expected_value; |
| 299 expected_value.SetBoolean("bool", true); | 299 expected_value.SetBoolean("bool", true); |
| 300 expected_value.SetDouble("double", 123.456); | 300 expected_value.SetDouble("double", 123.456); |
| 301 expected_value.SetInteger("int", 123); | 301 expected_value.SetInteger("int", 123); |
| 302 expected_value.SetString("string", "omg"); | 302 expected_value.SetString("string", "omg"); |
| 303 | 303 |
| 304 base::ListValue* list = new base::ListValue(); | 304 base::ListValue* list = new base::ListValue(); |
| 305 list->Set(0U, new base::StringValue("first")); | 305 list->Set(0U, new base::Value("first")); |
| 306 list->Set(1U, new base::StringValue("second")); | 306 list->Set(1U, new base::Value("second")); |
| 307 expected_value.Set("array", list); | 307 expected_value.Set("array", list); |
| 308 | 308 |
| 309 base::DictionaryValue* dict = new base::DictionaryValue(); | 309 base::DictionaryValue* dict = new base::DictionaryValue(); |
| 310 dict->SetString("sub", "value"); | 310 dict->SetString("sub", "value"); |
| 311 list = new base::ListValue(); | 311 list = new base::ListValue(); |
| 312 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue()); | 312 std::unique_ptr<base::DictionaryValue> sub(new base::DictionaryValue()); |
| 313 sub->SetInteger("aaa", 111); | 313 sub->SetInteger("aaa", 111); |
| 314 sub->SetInteger("bbb", 222); | 314 sub->SetInteger("bbb", 222); |
| 315 list->Append(std::move(sub)); | 315 list->Append(std::move(sub)); |
| 316 sub.reset(new base::DictionaryValue()); | 316 sub.reset(new base::DictionaryValue()); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 345 // OnUpdatePolicy is called when there are changes. | 345 // OnUpdatePolicy is called when there are changes. |
| 346 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); | 346 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); |
| 347 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 347 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
| 348 provider_->RefreshPolicies(); | 348 provider_->RefreshPolicies(); |
| 349 base::RunLoop().RunUntilIdle(); | 349 base::RunLoop().RunUntilIdle(); |
| 350 Mock::VerifyAndClearExpectations(&observer); | 350 Mock::VerifyAndClearExpectations(&observer); |
| 351 | 351 |
| 352 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 352 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 353 .Set(test_keys::kKeyString, test_harness_->policy_level(), | 353 .Set(test_keys::kKeyString, test_harness_->policy_level(), |
| 354 test_harness_->policy_scope(), test_harness_->policy_source(), | 354 test_harness_->policy_scope(), test_harness_->policy_source(), |
| 355 base::MakeUnique<base::StringValue>("value"), nullptr); | 355 base::MakeUnique<base::Value>("value"), nullptr); |
| 356 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 356 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 357 provider_->RemoveObserver(&observer); | 357 provider_->RemoveObserver(&observer); |
| 358 } | 358 } |
| 359 | 359 |
| 360 Configuration3rdPartyPolicyProviderTest:: | 360 Configuration3rdPartyPolicyProviderTest:: |
| 361 Configuration3rdPartyPolicyProviderTest() {} | 361 Configuration3rdPartyPolicyProviderTest() {} |
| 362 | 362 |
| 363 Configuration3rdPartyPolicyProviderTest:: | 363 Configuration3rdPartyPolicyProviderTest:: |
| 364 ~Configuration3rdPartyPolicyProviderTest() {} | 364 ~Configuration3rdPartyPolicyProviderTest() {} |
| 365 | 365 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 386 // Install them as 3rd party policies too. | 386 // Install them as 3rd party policies too. |
| 387 base::DictionaryValue policy_3rdparty; | 387 base::DictionaryValue policy_3rdparty; |
| 388 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", | 388 policy_3rdparty.Set("extensions.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", |
| 389 policy_dict.DeepCopy()); | 389 policy_dict.DeepCopy()); |
| 390 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", | 390 policy_3rdparty.Set("extensions.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", |
| 391 policy_dict.DeepCopy()); | 391 policy_dict.DeepCopy()); |
| 392 // Install invalid 3rd party policies that shouldn't be loaded. These also | 392 // Install invalid 3rd party policies that shouldn't be loaded. These also |
| 393 // help detecting memory leaks in the code paths that detect invalid input. | 393 // help detecting memory leaks in the code paths that detect invalid input. |
| 394 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); | 394 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); |
| 395 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", | 395 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", |
| 396 new base::StringValue("invalid-value")); | 396 new base::Value("invalid-value")); |
| 397 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); | 397 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); |
| 398 | 398 |
| 399 provider_->RefreshPolicies(); | 399 provider_->RefreshPolicies(); |
| 400 base::RunLoop().RunUntilIdle(); | 400 base::RunLoop().RunUntilIdle(); |
| 401 | 401 |
| 402 PolicyMap expected_policy; | 402 PolicyMap expected_policy; |
| 403 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(), | 403 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(), |
| 404 test_harness_->policy_scope(), | 404 test_harness_->policy_scope(), |
| 405 test_harness_->policy_source(), | 405 test_harness_->policy_source(), |
| 406 policy_dict.CreateDeepCopy(), nullptr); | 406 policy_dict.CreateDeepCopy(), nullptr); |
| 407 PolicyBundle expected_bundle; | 407 PolicyBundle expected_bundle; |
| 408 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 408 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 409 .CopyFrom(expected_policy); | 409 .CopyFrom(expected_policy); |
| 410 expected_policy.Clear(); | 410 expected_policy.Clear(); |
| 411 expected_policy.LoadFrom(&policy_dict, | 411 expected_policy.LoadFrom(&policy_dict, |
| 412 test_harness_->policy_level(), | 412 test_harness_->policy_level(), |
| 413 test_harness_->policy_scope(), | 413 test_harness_->policy_scope(), |
| 414 test_harness_->policy_source()); | 414 test_harness_->policy_source()); |
| 415 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 415 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 416 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 416 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 417 .CopyFrom(expected_policy); | 417 .CopyFrom(expected_policy); |
| 418 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 418 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 419 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 419 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 420 .CopyFrom(expected_policy); | 420 .CopyFrom(expected_policy); |
| 421 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 421 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 422 } | 422 } |
| 423 | 423 |
| 424 } // namespace policy | 424 } // namespace policy |
| OLD | NEW |