Chromium Code Reviews| 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" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 Schema schema = Schema::Parse(schema_string, &error); | 139 Schema schema = Schema::Parse(schema_string, &error); |
| 140 if (schema.valid()) { | 140 if (schema.valid()) { |
| 141 schema_registry_.RegisterComponent(ns, schema); | 141 schema_registry_.RegisterComponent(ns, schema); |
| 142 return true; | 142 return true; |
| 143 } | 143 } |
| 144 ADD_FAILURE() << error; | 144 ADD_FAILURE() << error; |
| 145 return false; | 145 return false; |
| 146 } | 146 } |
| 147 | 147 |
| 148 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, | 148 PolicyProviderTestHarness::PolicyProviderTestHarness(PolicyLevel level, |
| 149 PolicyScope scope) | 149 PolicyScope scope, |
| 150 : level_(level), scope_(scope) {} | 150 PolicySource source) |
| 151 : level_(level), scope_(scope), source_(source) {} | |
| 151 | 152 |
| 152 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} | 153 PolicyProviderTestHarness::~PolicyProviderTestHarness() {} |
| 153 | 154 |
| 154 PolicyLevel PolicyProviderTestHarness::policy_level() const { | 155 PolicyLevel PolicyProviderTestHarness::policy_level() const { |
| 155 return level_; | 156 return level_; |
| 156 } | 157 } |
| 157 | 158 |
| 158 PolicyScope PolicyProviderTestHarness::policy_scope() const { | 159 PolicyScope PolicyProviderTestHarness::policy_scope() const { |
| 159 return scope_; | 160 return scope_; |
| 160 } | 161 } |
| 161 | 162 |
| 163 PolicySource PolicyProviderTestHarness::policy_source() const { | |
| 164 return source_; | |
| 165 } | |
| 166 | |
| 162 void PolicyProviderTestHarness::Install3rdPartyPolicy( | 167 void PolicyProviderTestHarness::Install3rdPartyPolicy( |
| 163 const base::DictionaryValue* policies) { | 168 const base::DictionaryValue* policies) { |
| 164 FAIL(); | 169 FAIL(); |
| 165 } | 170 } |
| 166 | 171 |
| 167 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} | 172 ConfigurationPolicyProviderTest::ConfigurationPolicyProviderTest() {} |
| 168 | 173 |
| 169 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} | 174 ConfigurationPolicyProviderTest::~ConfigurationPolicyProviderTest() {} |
| 170 | 175 |
| 171 void ConfigurationPolicyProviderTest::SetUp() { | 176 void ConfigurationPolicyProviderTest::SetUp() { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 void ConfigurationPolicyProviderTest::CheckValue( | 219 void ConfigurationPolicyProviderTest::CheckValue( |
| 215 const char* policy_name, | 220 const char* policy_name, |
| 216 const base::Value& expected_value, | 221 const base::Value& expected_value, |
| 217 base::Closure install_value) { | 222 base::Closure install_value) { |
| 218 // Install the value, reload policy and check the provider for the value. | 223 // Install the value, reload policy and check the provider for the value. |
| 219 install_value.Run(); | 224 install_value.Run(); |
| 220 provider_->RefreshPolicies(); | 225 provider_->RefreshPolicies(); |
| 221 loop_.RunUntilIdle(); | 226 loop_.RunUntilIdle(); |
| 222 PolicyBundle expected_bundle; | 227 PolicyBundle expected_bundle; |
| 223 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 228 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 224 .Set(policy_name, | 229 .Set(policy_name, test_harness_->policy_level(), |
| 225 test_harness_->policy_level(), | 230 test_harness_->policy_scope(), expected_value.DeepCopy(), NULL, |
| 226 test_harness_->policy_scope(), | 231 test_harness_->policy_source()); |
| 227 expected_value.DeepCopy(), | |
| 228 NULL); | |
| 229 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 232 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 230 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, | 233 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, |
| 231 // and extend the |expected_bundle|, once all providers are ready. | 234 // and extend the |expected_bundle|, once all providers are ready. |
| 232 } | 235 } |
| 233 | 236 |
| 234 TEST_P(ConfigurationPolicyProviderTest, Empty) { | 237 TEST_P(ConfigurationPolicyProviderTest, Empty) { |
| 235 provider_->RefreshPolicies(); | 238 provider_->RefreshPolicies(); |
| 236 loop_.RunUntilIdle(); | 239 loop_.RunUntilIdle(); |
| 237 const PolicyBundle kEmptyBundle; | 240 const PolicyBundle kEmptyBundle; |
| 238 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); | 241 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 333 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 331 | 334 |
| 332 // OnUpdatePolicy is called when there are changes. | 335 // OnUpdatePolicy is called when there are changes. |
| 333 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); | 336 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); |
| 334 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); | 337 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); |
| 335 provider_->RefreshPolicies(); | 338 provider_->RefreshPolicies(); |
| 336 loop_.RunUntilIdle(); | 339 loop_.RunUntilIdle(); |
| 337 Mock::VerifyAndClearExpectations(&observer); | 340 Mock::VerifyAndClearExpectations(&observer); |
| 338 | 341 |
| 339 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 342 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 340 .Set(test_keys::kKeyString, | 343 .Set(test_keys::kKeyString, test_harness_->policy_level(), |
|
Thiemo Nagel
2015/09/01 17:40:37
Don't reformat...
fhorschig
2015/09/04 06:53:54
Done.
| |
| 341 test_harness_->policy_level(), | 344 test_harness_->policy_scope(), new base::StringValue("value"), NULL, |
| 342 test_harness_->policy_scope(), | 345 test_harness_->policy_source()); |
| 343 new base::StringValue("value"), | |
| 344 NULL); | |
| 345 EXPECT_TRUE(provider_->policies().Equals(bundle)); | 346 EXPECT_TRUE(provider_->policies().Equals(bundle)); |
| 346 provider_->RemoveObserver(&observer); | 347 provider_->RemoveObserver(&observer); |
| 347 } | 348 } |
| 348 | 349 |
| 349 Configuration3rdPartyPolicyProviderTest:: | 350 Configuration3rdPartyPolicyProviderTest:: |
| 350 Configuration3rdPartyPolicyProviderTest() {} | 351 Configuration3rdPartyPolicyProviderTest() {} |
| 351 | 352 |
| 352 Configuration3rdPartyPolicyProviderTest:: | 353 Configuration3rdPartyPolicyProviderTest:: |
| 353 ~Configuration3rdPartyPolicyProviderTest() {} | 354 ~Configuration3rdPartyPolicyProviderTest() {} |
| 354 | 355 |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 382 // 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. |
| 383 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); | 384 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); |
| 384 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", | 385 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", |
| 385 new base::StringValue("invalid-value")); | 386 new base::StringValue("invalid-value")); |
| 386 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); | 387 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); |
| 387 | 388 |
| 388 provider_->RefreshPolicies(); | 389 provider_->RefreshPolicies(); |
| 389 loop_.RunUntilIdle(); | 390 loop_.RunUntilIdle(); |
| 390 | 391 |
| 391 PolicyMap expected_policy; | 392 PolicyMap expected_policy; |
| 392 expected_policy.Set(test_keys::kKeyDictionary, | 393 expected_policy.Set(test_keys::kKeyDictionary, test_harness_->policy_level(), |
| 393 test_harness_->policy_level(), | 394 test_harness_->policy_scope(), policy_dict.DeepCopy(), |
| 394 test_harness_->policy_scope(), | 395 NULL, test_harness_->policy_source()); |
| 395 policy_dict.DeepCopy(), | |
| 396 NULL); | |
| 397 PolicyBundle expected_bundle; | 396 PolicyBundle expected_bundle; |
| 398 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) | 397 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) |
| 399 .CopyFrom(expected_policy); | 398 .CopyFrom(expected_policy); |
| 400 expected_policy.Clear(); | 399 expected_policy.Clear(); |
| 401 expected_policy.LoadFrom(&policy_dict, | 400 expected_policy.LoadFrom(&policy_dict, test_harness_->policy_level(), |
| 402 test_harness_->policy_level(), | 401 test_harness_->policy_scope(), |
| 403 test_harness_->policy_scope()); | 402 test_harness_->policy_source()); |
| 404 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 403 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 405 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) | 404 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) |
| 406 .CopyFrom(expected_policy); | 405 .CopyFrom(expected_policy); |
| 407 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, | 406 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, |
| 408 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) | 407 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) |
| 409 .CopyFrom(expected_policy); | 408 .CopyFrom(expected_policy); |
| 410 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); | 409 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); |
| 411 } | 410 } |
| 412 | 411 |
| 413 } // namespace policy | 412 } // namespace policy |
| OLD | NEW |