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

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

Issue 388963002: Get rid of the rest of CreateStringValue (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix bad rebase Created 6 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/policy_service_impl.h" 5 #include "components/policy/core/common/policy_service_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 return base::Value::Equals(arg, expected); 42 return base::Value::Equals(arg, expected);
43 } 43 }
44 44
45 // Helper that fills |bundle| with test policies. 45 // Helper that fills |bundle| with test policies.
46 void AddTestPolicies(PolicyBundle* bundle, 46 void AddTestPolicies(PolicyBundle* bundle,
47 const char* value, 47 const char* value,
48 PolicyLevel level, 48 PolicyLevel level,
49 PolicyScope scope) { 49 PolicyScope scope) {
50 PolicyMap* policy_map = 50 PolicyMap* policy_map =
51 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())); 51 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()));
52 policy_map->Set(kSameLevelPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 52 policy_map->Set(kSameLevelPolicy,
53 base::Value::CreateStringValue(value), NULL); 53 POLICY_LEVEL_MANDATORY,
54 policy_map->Set(kDiffLevelPolicy, level, scope, 54 POLICY_SCOPE_USER,
55 base::Value::CreateStringValue(value), NULL); 55 new base::StringValue(value),
56 NULL);
57 policy_map->Set(
58 kDiffLevelPolicy, level, scope, new base::StringValue(value), NULL);
56 policy_map = 59 policy_map =
57 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)); 60 &bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension));
58 policy_map->Set(kSameLevelPolicy, POLICY_LEVEL_MANDATORY, 61 policy_map->Set(kSameLevelPolicy,
59 POLICY_SCOPE_USER, base::Value::CreateStringValue(value), 62 POLICY_LEVEL_MANDATORY,
63 POLICY_SCOPE_USER,
64 new base::StringValue(value),
60 NULL); 65 NULL);
61 policy_map->Set(kDiffLevelPolicy, level, scope, 66 policy_map->Set(
62 base::Value::CreateStringValue(value), NULL); 67 kDiffLevelPolicy, level, scope, new base::StringValue(value), NULL);
63 } 68 }
64 69
65 // Observer class that changes the policy in the passed provider when the 70 // Observer class that changes the policy in the passed provider when the
66 // callback is invoked. 71 // callback is invoked.
67 class ChangePolicyObserver : public PolicyService::Observer { 72 class ChangePolicyObserver : public PolicyService::Observer {
68 public: 73 public:
69 explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider) 74 explicit ChangePolicyObserver(MockConfigurationPolicyProvider* provider)
70 : provider_(provider), 75 : provider_(provider),
71 observer_invoked_(false) {} 76 observer_invoked_(false) {}
72 77
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 policy_service_->AddObserver(POLICY_DOMAIN_EXTENSIONS, &extension_observer); 280 policy_service_->AddObserver(POLICY_DOMAIN_EXTENSIONS, &extension_observer);
276 281
277 PolicyMap previous_policy_map; 282 PolicyMap previous_policy_map;
278 previous_policy_map.Set("pre", 283 previous_policy_map.Set("pre",
279 POLICY_LEVEL_MANDATORY, 284 POLICY_LEVEL_MANDATORY,
280 POLICY_SCOPE_USER, 285 POLICY_SCOPE_USER,
281 new base::FundamentalValue(13), 286 new base::FundamentalValue(13),
282 NULL); 287 NULL);
283 PolicyMap policy_map; 288 PolicyMap policy_map;
284 policy_map.CopyFrom(previous_policy_map); 289 policy_map.CopyFrom(previous_policy_map);
285 policy_map.Set("policy", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 290 policy_map.Set("policy",
286 base::Value::CreateStringValue("value"), NULL); 291 POLICY_LEVEL_MANDATORY,
292 POLICY_SCOPE_USER,
293 new base::StringValue("value"),
294 NULL);
287 295
288 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); 296 scoped_ptr<PolicyBundle> bundle(new PolicyBundle());
289 // The initial setup includes a policy for chrome that is now changing. 297 // The initial setup includes a policy for chrome that is now changing.
290 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 298 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
291 .CopyFrom(policy_map); 299 .CopyFrom(policy_map);
292 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0)) 300 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0))
293 .CopyFrom(policy_map); 301 .CopyFrom(policy_map);
294 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) 302 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1))
295 .CopyFrom(policy_map); 303 .CopyFrom(policy_map);
296 304
(...skipping 17 matching lines...) Expand all
314 RunUntilIdle(); 322 RunUntilIdle();
315 Mock::VerifyAndClearExpectations(&chrome_observer); 323 Mock::VerifyAndClearExpectations(&chrome_observer);
316 Mock::VerifyAndClearExpectations(&extension_observer); 324 Mock::VerifyAndClearExpectations(&extension_observer);
317 325
318 // Chrome policy stays the same, kExtension0 is gone, kExtension1 changes, 326 // Chrome policy stays the same, kExtension0 is gone, kExtension1 changes,
319 // and kExtension2 is new. 327 // and kExtension2 is new.
320 previous_policy_map.CopyFrom(policy_map); 328 previous_policy_map.CopyFrom(policy_map);
321 bundle.reset(new PolicyBundle()); 329 bundle.reset(new PolicyBundle());
322 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())) 330 bundle->Get(PolicyNamespace(POLICY_DOMAIN_CHROME, std::string()))
323 .CopyFrom(policy_map); 331 .CopyFrom(policy_map);
324 policy_map.Set("policy", POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 332 policy_map.Set("policy",
325 base::Value::CreateStringValue("another value"), NULL); 333 POLICY_LEVEL_MANDATORY,
334 POLICY_SCOPE_USER,
335 new base::StringValue("another value"),
336 NULL);
326 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1)) 337 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension1))
327 .CopyFrom(policy_map); 338 .CopyFrom(policy_map);
328 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension2)) 339 bundle->Get(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension2))
329 .CopyFrom(policy_map); 340 .CopyFrom(policy_map);
330 341
331 EXPECT_CALL(chrome_observer, OnPolicyUpdated(_, _, _)).Times(0); 342 EXPECT_CALL(chrome_observer, OnPolicyUpdated(_, _, _)).Times(0);
332 EXPECT_CALL( 343 EXPECT_CALL(
333 extension_observer, 344 extension_observer,
334 OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0), 345 OnPolicyUpdated(PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension0),
335 PolicyEquals(&previous_policy_map), 346 PolicyEquals(&previous_policy_map),
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE); 578 POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE);
568 579
569 provider0_.UpdatePolicy(bundle0.Pass()); 580 provider0_.UpdatePolicy(bundle0.Pass());
570 provider1_.UpdatePolicy(bundle1.Pass()); 581 provider1_.UpdatePolicy(bundle1.Pass());
571 provider2_.UpdatePolicy(bundle2.Pass()); 582 provider2_.UpdatePolicy(bundle2.Pass());
572 RunUntilIdle(); 583 RunUntilIdle();
573 584
574 PolicyMap expected; 585 PolicyMap expected;
575 // For policies of the same level and scope, the first provider takes 586 // For policies of the same level and scope, the first provider takes
576 // precedence, on every namespace. 587 // precedence, on every namespace.
577 expected.Set(kSameLevelPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_USER, 588 expected.Set(kSameLevelPolicy,
578 base::Value::CreateStringValue("bundle0"), NULL); 589 POLICY_LEVEL_MANDATORY,
590 POLICY_SCOPE_USER,
591 new base::StringValue("bundle0"),
592 NULL);
579 // For policies with different levels and scopes, the highest priority 593 // For policies with different levels and scopes, the highest priority
580 // level/scope combination takes precedence, on every namespace. 594 // level/scope combination takes precedence, on every namespace.
581 expected.Set(kDiffLevelPolicy, POLICY_LEVEL_MANDATORY, POLICY_SCOPE_MACHINE, 595 expected.Set(kDiffLevelPolicy,
582 base::Value::CreateStringValue("bundle2"), NULL); 596 POLICY_LEVEL_MANDATORY,
597 POLICY_SCOPE_MACHINE,
598 new base::StringValue("bundle2"),
599 NULL);
583 EXPECT_TRUE(policy_service_->GetPolicies( 600 EXPECT_TRUE(policy_service_->GetPolicies(
584 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())).Equals(expected)); 601 PolicyNamespace(POLICY_DOMAIN_CHROME, std::string())).Equals(expected));
585 EXPECT_TRUE(policy_service_->GetPolicies( 602 EXPECT_TRUE(policy_service_->GetPolicies(
586 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)).Equals(expected)); 603 PolicyNamespace(POLICY_DOMAIN_EXTENSIONS, kExtension)).Equals(expected));
587 } 604 }
588 605
589 TEST_F(PolicyServiceTest, IsInitializationComplete) { 606 TEST_F(PolicyServiceTest, IsInitializationComplete) {
590 // |provider0| has all domains initialized. 607 // |provider0| has all domains initialized.
591 Mock::VerifyAndClearExpectations(&provider1_); 608 Mock::VerifyAndClearExpectations(&provider1_);
592 Mock::VerifyAndClearExpectations(&provider2_); 609 Mock::VerifyAndClearExpectations(&provider2_);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 // Individual proxy policy values in the Chrome namespace should be collected 692 // Individual proxy policy values in the Chrome namespace should be collected
676 // into a dictionary. 693 // into a dictionary.
677 policy_map.Set(key::kProxyServerMode, 694 policy_map.Set(key::kProxyServerMode,
678 POLICY_LEVEL_MANDATORY, 695 POLICY_LEVEL_MANDATORY,
679 POLICY_SCOPE_USER, 696 POLICY_SCOPE_USER,
680 new base::FundamentalValue(3), 697 new base::FundamentalValue(3),
681 NULL); 698 NULL);
682 699
683 // Both these policies should be ignored, since there's a higher priority 700 // Both these policies should be ignored, since there's a higher priority
684 // policy available. 701 // policy available.
685 policy_map.Set(key::kProxyMode, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 702 policy_map.Set(key::kProxyMode,
686 base::Value::CreateStringValue("pac_script"), NULL); 703 POLICY_LEVEL_RECOMMENDED,
687 policy_map.Set(key::kProxyPacUrl, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER, 704 POLICY_SCOPE_USER,
688 base::Value::CreateStringValue("http://example.com/wpad.dat"), 705 new base::StringValue("pac_script"),
706 NULL);
707 policy_map.Set(key::kProxyPacUrl,
708 POLICY_LEVEL_RECOMMENDED,
709 POLICY_SCOPE_USER,
710 new base::StringValue("http://example.com/wpad.dat"),
689 NULL); 711 NULL);
690 712
691 // Add a value to a non-Chrome namespace. 713 // Add a value to a non-Chrome namespace.
692 policy_bundle->Get(extension_namespace).Set(key::kProxyServerMode, 714 policy_bundle->Get(extension_namespace).Set(key::kProxyServerMode,
693 POLICY_LEVEL_MANDATORY, 715 POLICY_LEVEL_MANDATORY,
694 POLICY_SCOPE_USER, 716 POLICY_SCOPE_USER,
695 new base::FundamentalValue(3), 717 new base::FundamentalValue(3),
696 NULL); 718 NULL);
697 719
698 // The resulting Chrome namespace map should have the collected policy. 720 // The resulting Chrome namespace map should have the collected policy.
(...skipping 12 matching lines...) Expand all
711 NULL); 733 NULL);
712 734
713 provider0_.UpdatePolicy(policy_bundle.Pass()); 735 provider0_.UpdatePolicy(policy_bundle.Pass());
714 RunUntilIdle(); 736 RunUntilIdle();
715 737
716 EXPECT_TRUE(VerifyPolicies(chrome_namespace, expected_chrome)); 738 EXPECT_TRUE(VerifyPolicies(chrome_namespace, expected_chrome));
717 EXPECT_TRUE(VerifyPolicies(extension_namespace, expected_extension)); 739 EXPECT_TRUE(VerifyPolicies(extension_namespace, expected_extension));
718 } 740 }
719 741
720 } // namespace policy 742 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/policy_provider_android_unittest.cc ('k') | components/policy/core/common/preg_parser_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698