Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: components/policy/core/common/configuration_policy_provider_test.cc

Issue 1304843004: Add source column to chrome://policy showing the origins of policies. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 .SetWithSource(policy_name,
225 test_harness_->policy_level(), 230 test_harness_->policy_level(),
226 test_harness_->policy_scope(), 231 test_harness_->policy_scope(),
227 expected_value.DeepCopy(), 232 expected_value.DeepCopy(),
228 NULL); 233 NULL,
bartfab (slow) 2015/09/14 14:42:27 Nit: s/NULL/nullptr/
fhorschig 2015/09/16 13:52:05 Done.
234 test_harness_->policy_source());
229 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 235 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
230 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too, 236 // TODO(joaodasilva): set the policy in the POLICY_DOMAIN_EXTENSIONS too,
231 // and extend the |expected_bundle|, once all providers are ready. 237 // and extend the |expected_bundle|, once all providers are ready.
232 } 238 }
233 239
234 TEST_P(ConfigurationPolicyProviderTest, Empty) { 240 TEST_P(ConfigurationPolicyProviderTest, Empty) {
235 provider_->RefreshPolicies(); 241 provider_->RefreshPolicies();
236 loop_.RunUntilIdle(); 242 loop_.RunUntilIdle();
237 const PolicyBundle kEmptyBundle; 243 const PolicyBundle kEmptyBundle;
238 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle)); 244 EXPECT_TRUE(provider_->policies().Equals(kEmptyBundle));
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 EXPECT_TRUE(provider_->policies().Equals(bundle)); 336 EXPECT_TRUE(provider_->policies().Equals(bundle));
331 337
332 // OnUpdatePolicy is called when there are changes. 338 // OnUpdatePolicy is called when there are changes.
333 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value"); 339 test_harness_->InstallStringPolicy(test_keys::kKeyString, "value");
334 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1); 340 EXPECT_CALL(observer, OnUpdatePolicy(provider_.get())).Times(1);
335 provider_->RefreshPolicies(); 341 provider_->RefreshPolicies();
336 loop_.RunUntilIdle(); 342 loop_.RunUntilIdle();
337 Mock::VerifyAndClearExpectations(&observer); 343 Mock::VerifyAndClearExpectations(&observer);
338 344
339 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 345 bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
340 .Set(test_keys::kKeyString, 346 .SetWithSource(test_keys::kKeyString,
341 test_harness_->policy_level(), 347 test_harness_->policy_level(),
342 test_harness_->policy_scope(), 348 test_harness_->policy_scope(),
343 new base::StringValue("value"), 349 new base::StringValue("value"),
344 NULL); 350 NULL,
bartfab (slow) 2015/09/14 14:42:27 Nit: s/NULL/nullptr/
fhorschig 2015/09/16 13:52:05 Done.
351 test_harness_->policy_source());
345 EXPECT_TRUE(provider_->policies().Equals(bundle)); 352 EXPECT_TRUE(provider_->policies().Equals(bundle));
346 provider_->RemoveObserver(&observer); 353 provider_->RemoveObserver(&observer);
347 } 354 }
348 355
349 Configuration3rdPartyPolicyProviderTest:: 356 Configuration3rdPartyPolicyProviderTest::
350 Configuration3rdPartyPolicyProviderTest() {} 357 Configuration3rdPartyPolicyProviderTest() {}
351 358
352 Configuration3rdPartyPolicyProviderTest:: 359 Configuration3rdPartyPolicyProviderTest::
353 ~Configuration3rdPartyPolicyProviderTest() {} 360 ~Configuration3rdPartyPolicyProviderTest() {}
354 361
(...skipping 27 matching lines...) Expand all
382 // help detecting memory leaks in the code paths that detect invalid input. 389 // help detecting memory leaks in the code paths that detect invalid input.
383 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy()); 390 policy_3rdparty.Set("invalid-domain.component", policy_dict.DeepCopy());
384 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc", 391 policy_3rdparty.Set("extensions.cccccccccccccccccccccccccccccccc",
385 new base::StringValue("invalid-value")); 392 new base::StringValue("invalid-value"));
386 test_harness_->Install3rdPartyPolicy(&policy_3rdparty); 393 test_harness_->Install3rdPartyPolicy(&policy_3rdparty);
387 394
388 provider_->RefreshPolicies(); 395 provider_->RefreshPolicies();
389 loop_.RunUntilIdle(); 396 loop_.RunUntilIdle();
390 397
391 PolicyMap expected_policy; 398 PolicyMap expected_policy;
392 expected_policy.Set(test_keys::kKeyDictionary, 399 expected_policy.SetWithSource(test_keys::kKeyDictionary,
393 test_harness_->policy_level(), 400 test_harness_->policy_level(),
394 test_harness_->policy_scope(), 401 test_harness_->policy_scope(),
395 policy_dict.DeepCopy(), 402 policy_dict.DeepCopy(),
396 NULL); 403 NULL,
bartfab (slow) 2015/09/14 14:42:27 Nit: s/NULL/nullptr/
fhorschig 2015/09/16 13:52:05 Done.
404 test_harness_->policy_source());
397 PolicyBundle expected_bundle; 405 PolicyBundle expected_bundle;
398 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 406 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
399 .CopyFrom(expected_policy); 407 .CopyFrom(expected_policy);
400 expected_policy.Clear(); 408 expected_policy.Clear();
401 expected_policy.LoadFrom(&policy_dict, 409 expected_policy.LoadFrom(&policy_dict,
402 test_harness_->policy_level(), 410 test_harness_->policy_level(),
403 test_harness_->policy_scope()); 411 test_harness_->policy_scope());
412 expected_policy.ApplySourceToEntries(test_harness_->policy_source());
bartfab (slow) 2015/09/14 14:42:27 If LoadFrom() is able to set the level and scope,
fhorschig 2015/09/16 13:52:05 Done.
404 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 413 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
405 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) 414 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
406 .CopyFrom(expected_policy); 415 .CopyFrom(expected_policy);
407 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, 416 expected_bundle.Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS,
408 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")) 417 "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"))
409 .CopyFrom(expected_policy); 418 .CopyFrom(expected_policy);
410 EXPECT_TRUE(provider_->policies().Equals(expected_bundle)); 419 EXPECT_TRUE(provider_->policies().Equals(expected_bundle));
411 } 420 }
412 421
413 } // namespace policy 422 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698