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/memory/ptr_util.h" |
9 #include "base/values.h" | 10 #include "base/values.h" |
10 #include "components/policy/core/common/configuration_policy_provider.h" | 11 #include "components/policy/core/common/configuration_policy_provider.h" |
11 #include "components/policy/core/common/external_data_fetcher.h" | 12 #include "components/policy/core/common/external_data_fetcher.h" |
12 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 13 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
13 #include "components/policy/core/common/policy_bundle.h" | 14 #include "components/policy/core/common/policy_bundle.h" |
14 #include "components/policy/core/common/policy_map.h" | 15 #include "components/policy/core/common/policy_map.h" |
15 #include "components/policy/core/common/policy_namespace.h" | 16 #include "components/policy/core/common/policy_namespace.h" |
16 #include "components/policy/core/common/policy_types.h" | 17 #include "components/policy/core/common/policy_types.h" |
17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
18 | 19 |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 void ConfigurationPolicyProviderTest::CheckValue( | 221 void ConfigurationPolicyProviderTest::CheckValue( |
221 const char* policy_name, | 222 const char* policy_name, |
222 const base::Value& expected_value, | 223 const base::Value& expected_value, |
223 base::Closure install_value) { | 224 base::Closure install_value) { |
224 // Install the value, reload policy and check the provider for the value. | 225 // Install the value, reload policy and check the provider for the value. |
225 install_value.Run(); | 226 install_value.Run(); |
226 provider_->RefreshPolicies(); | 227 provider_->RefreshPolicies(); |
227 loop_.RunUntilIdle(); | 228 loop_.RunUntilIdle(); |
228 PolicyBundle expected_bundle; | 229 PolicyBundle expected_bundle; |
229 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 230 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
230 .Set(policy_name, | 231 .Set(policy_name, test_harness_->policy_level(), |
231 test_harness_->policy_level(), | 232 test_harness_->policy_scope(), test_harness_->policy_source(), |
232 test_harness_->policy_scope(), | 233 expected_value.CreateDeepCopy(), nullptr); |
233 test_harness_->policy_source(), | |
234 expected_value.DeepCopy(), | |
235 NULL); | |
236 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 234 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
237 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, | 235 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, |
238 // and extend the |expected_bundle|, once all providers are ready. | 236 // and extend the |expected_bundle|, once all providers are ready. |
239 } | 237 } |
240 | 238 |
241 TEST_P(ConfigurationPolicyProviderTest, Empty) { | 239 TEST_P(ConfigurationPolicyProviderTest, Empty) { |
242 provider_->RefreshPolicies(); | 240 provider_->RefreshPolicies(); |
243 loop_.RunUntilIdle(); | 241 loop_.RunUntilIdle(); |
244 const PolicyBundle kEmptyBundle; | 242 const PolicyBundle kEmptyBundle; |
245 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 243 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 335 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
338 | 336 |
339 // OnUpdatePolicy is called when there are changes. | 337 // OnUpdatePolicy is called when there are changes. |
340 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); | 338 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); |
341 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 339 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
342 provider_->RefreshPolicies(); | 340 provider_->RefreshPolicies(); |
343 loop_.RunUntilIdle(); | 341 loop_.RunUntilIdle(); |
344 Mock::VerifyAndClearExpectations(&observer); | 342 Mock::VerifyAndClearExpectations(&observer); |
345 | 343 |
346 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 344 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
347 .Set(test_keys::kKeyString, | 345 .Set(test_keys::kKeyString, test_harness_->policy_level(), |
348 test_harness_->policy_level(), | 346 test_harness_->policy_scope(), test_harness_->policy_source(), |
349 test_harness_->policy_scope(), | 347 base::WrapUnique(new base::StringValue("value")), nullptr); |
350 test_harness_->policy_source(), | |
351 new base::StringValue("value"), | |
352 NULL); | |
353 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 348 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
354 provider_->RemoveObserver(&observer); | 349 provider_->RemoveObserver(&observer); |
355 } | 350 } |
356 | 351 |
357 Configuration3rdPartyPolicyProviderTest:: | 352 Configuration3rdPartyPolicyProviderTest:: |
358 Configuration3rdPartyPolicyProviderTest() {} | 353 Configuration3rdPartyPolicyProviderTest() {} |
359 | 354 |
360 Configuration3rdPartyPolicyProviderTest:: | 355 Configuration3rdPartyPolicyProviderTest:: |
361 ~Configuration3rdPartyPolicyProviderTest() {} | 356 ~Configuration3rdPartyPolicyProviderTest() {} |
362 | 357 |
(...skipping 27 matching lines...) Expand all Loading... |
390 // help detecting memory leaks in the code paths that detect invalid input. | 385 // help detecting memory leaks in the code paths that detect invalid input. |
391 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); | 386 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); |
392 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", | 387 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", |
393 new base::StringValue("invalid-value")); | 388 new base::StringValue("invalid-value")); |
394 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); | 389 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); |
395 | 390 |
396 provider_->RefreshPolicies(); | 391 provider_->RefreshPolicies(); |
397 loop_.RunUntilIdle(); | 392 loop_.RunUntilIdle(); |
398 | 393 |
399 PolicyMap expected_policy; | 394 PolicyMap expected_policy; |
400 expected_policy.Set(test_keys::kKeyDictionary, | 395 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(), |
401 test_harness_->policy_level(), | |
402 test_harness_->policy_scope(), | 396 test_harness_->policy_scope(), |
403 test_harness_->policy_source(), | 397 test_harness_->policy_source(), |
404 policy_dict.DeepCopy(), | 398 policy_dict.CreateDeepCopy(), nullptr); |
405 NULL); | |
406 PolicyBundle expected_bundle; | 399 PolicyBundle expected_bundle; |
407 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 400 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
408 .CopyFrom(expected_policy); | 401 .CopyFrom(expected_policy); |
409 expected_policy.Clear(); | 402 expected_policy.Clear(); |
410 expected_policy.LoadFrom(&policy_dict, | 403 expected_policy.LoadFrom(&policy_dict, |
411 test_harness_->policy_level(), | 404 test_harness_->policy_level(), |
412 test_harness_->policy_scope(), | 405 test_harness_->policy_scope(), |
413 test_harness_->policy_source()); | 406 test_harness_->policy_source()); |
414 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 407 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
415 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 408 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
416 .CopyFrom(expected_policy); | 409 .CopyFrom(expected_policy); |
417 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 410 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
418 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 411 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
419 .CopyFrom(expected_policy); | 412 .CopyFrom(expected_policy); |
420 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 413 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
421 } | 414 } |
422 | 415 |
423 } // namespace policy | 416 } // namespace policy |
OLD | NEW |