| 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/values.h" | 9 #include "base/values.h" |
| 10 #include "components/policy/core/common/configuration_policy_provider.h" | 10 #include "components/policy/core/common/configuration_policy_provider.h" |
| 11 #include "components/policy/core/common/external_data_fetcher.h" | 11 #include "components/policy/core/common/external_data_fetcher.h" |
| 12 #include "components/policy/core/common/mock_configuration_policy_provider.h" | 12 #include "components/policy/core/common/mock_configuration_policy_provider.h" |
| 13 #include "components/policy/core/common/policy_bundle.h" | 13 #include "components/policy/core/common/policy_bundle.h" |
| 14 #include "components/policy/core/common/policy_map.h" | 14 #include "components/policy/core/common/policy_map.h" |
| 15 #include "components/policy/core/common/policy_namespace.h" | 15 #include "components/policy/core/common/policy_namespace.h" |
| 16 #include "components/policy/core/common/policy_types.h" | |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
| 18 | 17 |
| 19 using ::testing::Mock; | 18 using ::testing::Mock; |
| 20 using ::testing::_; | 19 using ::testing::_; |
| 21 | 20 |
| 22 namespace policy { | 21 namespace policy { |
| 23 | 22 |
| 24 const char kTestChromeSchema[] = | 23 const char kTestChromeSchema[] = |
| 25 "{" | 24 "{" |
| 26 " \"type\": \"object\"," | 25 " \"type\": \"object\"," |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 Schema schema = Schema::Parse(schema_string, &error); | 139 Schema schema = Schema::Parse(schema_string, &error); |
| 141 if (schema.valid()) { | 140 if (schema.valid()) { |
| 142 schema_registry_.RegisterComponent(ns, schema); | 141 schema_registry_.RegisterComponent(ns, schema); |
| 143 return true; | 142 return true; |
| 144 } | 143 } |
| 145 ADD_FAILURE() << error; | 144 ADD_FAILURE() << error; |
| 146 return false; | 145 return false; |
| 147 } | 146 } |
| 148 | 147 |
| 149 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, | 148 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, |
| 150 PolicyScope scope, | 149 PolicyScope scope) |
| 151 PolicySource source) | 150 : level_(level), scope_(scope) {} |
| 152 : level_(level), scope_(scope), source_(source) {} | |
| 153 | 151 |
| 154 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} | 152 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} |
| 155 | 153 |
| 156 PolicyLevel PolicyProviderTestHarness::policy_level() const { | 154 PolicyLevel PolicyProviderTestHarness::policy_level() const { |
| 157 return level_; | 155 return level_; |
| 158 } | 156 } |
| 159 | 157 |
| 160 PolicyScope PolicyProviderTestHarness::policy_scope() const { | 158 PolicyScope PolicyProviderTestHarness::policy_scope() const { |
| 161 return scope_; | 159 return scope_; |
| 162 } | 160 } |
| 163 | 161 |
| 164 PolicySource PolicyProviderTestHarness::policy_source() const { | |
| 165 return source_; | |
| 166 } | |
| 167 | |
| 168 void PolicyProviderTestHarness::Install3rdPartyPolicy( | 162 void PolicyProviderTestHarness::Install3rdPartyPolicy( |
| 169 const base::DictionaryValue* policies) { | 163 const base::DictionaryValue* policies) { |
| 170 FAIL(); | 164 FAIL(); |
| 171 } | 165 } |
| 172 | 166 |
| 173 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} | 167 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} |
| 174 | 168 |
| 175 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} | 169 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} |
| 176 | 170 |
| 177 void ConfigurationPolicyProviderTest::SetUp() { | 171 void ConfigurationPolicyProviderTest::SetUp() { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 base::Closure install_value) { | 217 base::Closure install_value) { |
| 224 // Install the value, reload policy and check the provider for the value. | 218 // Install the value, reload policy and check the provider for the value. |
| 225 install_value.Run(); | 219 install_value.Run(); |
| 226 provider_->RefreshPolicies(); | 220 provider_->RefreshPolicies(); |
| 227 loop_.RunUntilIdle(); | 221 loop_.RunUntilIdle(); |
| 228 PolicyBundle expected_bundle; | 222 PolicyBundle expected_bundle; |
| 229 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 223 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 230 .Set(policy_name, | 224 .Set(policy_name, |
| 231 test_harness_->policy_level(), | 225 test_harness_->policy_level(), |
| 232 test_harness_->policy_scope(), | 226 test_harness_->policy_scope(), |
| 233 test_harness_->policy_source(), | |
| 234 expected_value.DeepCopy(), | 227 expected_value.DeepCopy(), |
| 235 NULL); | 228 NULL); |
| 236 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 229 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 237 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, | 230 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, |
| 238 // and extend the |expected_bundle|, once all providers are ready. | 231 // and extend the |expected_bundle|, once all providers are ready. |
| 239 } | 232 } |
| 240 | 233 |
| 241 TEST_P(ConfigurationPolicyProviderTest, Empty) { | 234 TEST_P(ConfigurationPolicyProviderTest, Empty) { |
| 242 provider_->RefreshPolicies(); | 235 provider_->RefreshPolicies(); |
| 243 loop_.RunUntilIdle(); | 236 loop_.RunUntilIdle(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); | 333 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); |
| 341 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 334 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
| 342 provider_->RefreshPolicies(); | 335 provider_->RefreshPolicies(); |
| 343 loop_.RunUntilIdle(); | 336 loop_.RunUntilIdle(); |
| 344 Mock::VerifyAndClearExpectations(&observer); | 337 Mock::VerifyAndClearExpectations(&observer); |
| 345 | 338 |
| 346 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 339 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 347 .Set(test_keys::kKeyString, | 340 .Set(test_keys::kKeyString, |
| 348 test_harness_->policy_level(), | 341 test_harness_->policy_level(), |
| 349 test_harness_->policy_scope(), | 342 test_harness_->policy_scope(), |
| 350 test_harness_->policy_source(), | |
| 351 new base::StringValue("value"), | 343 new base::StringValue("value"), |
| 352 NULL); | 344 NULL); |
| 353 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 345 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 354 provider_->RemoveObserver(&observer); | 346 provider_->RemoveObserver(&observer); |
| 355 } | 347 } |
| 356 | 348 |
| 357 Configuration3rdPartyPolicyProviderTest:: | 349 Configuration3rdPartyPolicyProviderTest:: |
| 358 Configuration3rdPartyPolicyProviderTest() {} | 350 Configuration3rdPartyPolicyProviderTest() {} |
| 359 | 351 |
| 360 Configuration3rdPartyPolicyProviderTest:: | 352 Configuration3rdPartyPolicyProviderTest:: |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 new base::StringValue("invalid-value")); | 385 new base::StringValue("invalid-value")); |
| 394 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); | 386 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); |
| 395 | 387 |
| 396 provider_->RefreshPolicies(); | 388 provider_->RefreshPolicies(); |
| 397 loop_.RunUntilIdle(); | 389 loop_.RunUntilIdle(); |
| 398 | 390 |
| 399 PolicyMap expected_policy; | 391 PolicyMap expected_policy; |
| 400 expected_policy.Set(test_keys::kKeyDictionary, | 392 expected_policy.Set(test_keys::kKeyDictionary, |
| 401 test_harness_->policy_level(), | 393 test_harness_->policy_level(), |
| 402 test_harness_->policy_scope(), | 394 test_harness_->policy_scope(), |
| 403 test_harness_->policy_source(), | |
| 404 policy_dict.DeepCopy(), | 395 policy_dict.DeepCopy(), |
| 405 NULL); | 396 NULL); |
| 406 PolicyBundle expected_bundle; | 397 PolicyBundle expected_bundle; |
| 407 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 398 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 408 .CopyFrom(expected_policy); | 399 .CopyFrom(expected_policy); |
| 409 expected_policy.Clear(); | 400 expected_policy.Clear(); |
| 410 expected_policy.LoadFrom(&policy_dict, | 401 expected_policy.LoadFrom(&policy_dict, |
| 411 test_harness_->policy_level(), | 402 test_harness_->policy_level(), |
| 412 test_harness_->policy_scope(), | 403 test_harness_->policy_scope()); |
| 413 test_harness_->policy_source()); | |
| 414 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 404 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 415 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 405 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 416 .CopyFrom(expected_policy); | 406 .CopyFrom(expected_policy); |
| 417 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 407 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 418 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 408 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 419 .CopyFrom(expected_policy); | 409 .CopyFrom(expected_policy); |
| 420 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 410 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 421 } | 411 } |
| 422 | 412 |
| 423 } // namespace policy | 413 } // namespace policy |
| OLD | NEW |