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