OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/prefs/pref_value_map.h" | 9 #include "base/prefs/pref_value_map.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 Schema schema = Schema::Parse(kSchemaJson, &error); | 645 Schema schema = Schema::Parse(kSchemaJson, &error); |
646 ASSERT_TRUE(schema.valid()) << error; | 646 ASSERT_TRUE(schema.valid()) << error; |
647 | 647 |
648 static const char kPolicyMapJson[] = | 648 static const char kPolicyMapJson[] = |
649 "{" | 649 "{" |
650 " \"PolicyForTesting\": {" | 650 " \"PolicyForTesting\": {" |
651 " \"OneToThree\": 2," | 651 " \"OneToThree\": 2," |
652 " \"Colors\": \"White\"" | 652 " \"Colors\": \"White\"" |
653 " }" | 653 " }" |
654 "}"; | 654 "}"; |
655 scoped_ptr<base::Value> policy_map_value( | 655 scoped_ptr<base::Value> policy_map_value = |
656 base::JSONReader::DeprecatedReadAndReturnError( | 656 base::JSONReader::ReadAndReturnError(kPolicyMapJson, base::JSON_PARSE_RFC, |
657 kPolicyMapJson, base::JSON_PARSE_RFC, NULL, &error)); | 657 NULL, &error); |
658 ASSERT_TRUE(policy_map_value) << error; | 658 ASSERT_TRUE(policy_map_value) << error; |
659 | 659 |
660 const base::DictionaryValue* policy_map_dict = NULL; | 660 const base::DictionaryValue* policy_map_dict = NULL; |
661 ASSERT_TRUE(policy_map_value->GetAsDictionary(&policy_map_dict)); | 661 ASSERT_TRUE(policy_map_value->GetAsDictionary(&policy_map_dict)); |
662 | 662 |
663 PolicyMap policy_map; | 663 PolicyMap policy_map; |
664 policy_map.LoadFrom( | 664 policy_map.LoadFrom( |
665 policy_map_dict, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); | 665 policy_map_dict, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); |
666 | 666 |
667 TestSchemaValidatingPolicyHandler handler(schema, SCHEMA_ALLOW_INVALID); | 667 TestSchemaValidatingPolicyHandler handler(schema, SCHEMA_ALLOW_INVALID); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 Schema schema = Schema::Parse(kSchemaJson, &error); | 705 Schema schema = Schema::Parse(kSchemaJson, &error); |
706 ASSERT_TRUE(schema.valid()) << error; | 706 ASSERT_TRUE(schema.valid()) << error; |
707 | 707 |
708 static const char kPolicyMapJson[] = | 708 static const char kPolicyMapJson[] = |
709 "{" | 709 "{" |
710 " \"PolicyForTesting\": {" | 710 " \"PolicyForTesting\": {" |
711 " \"OneToThree\": 2," | 711 " \"OneToThree\": 2," |
712 " \"Colors\": \"Green\"" | 712 " \"Colors\": \"Green\"" |
713 " }" | 713 " }" |
714 "}"; | 714 "}"; |
715 scoped_ptr<base::Value> policy_map_value( | 715 scoped_ptr<base::Value> policy_map_value = |
716 base::JSONReader::DeprecatedReadAndReturnError( | 716 base::JSONReader::ReadAndReturnError(kPolicyMapJson, base::JSON_PARSE_RFC, |
717 kPolicyMapJson, base::JSON_PARSE_RFC, NULL, &error)); | 717 NULL, &error); |
718 ASSERT_TRUE(policy_map_value) << error; | 718 ASSERT_TRUE(policy_map_value) << error; |
719 | 719 |
720 const base::DictionaryValue* policy_map_dict = NULL; | 720 const base::DictionaryValue* policy_map_dict = NULL; |
721 ASSERT_TRUE(policy_map_value->GetAsDictionary(&policy_map_dict)); | 721 ASSERT_TRUE(policy_map_value->GetAsDictionary(&policy_map_dict)); |
722 | 722 |
723 PolicyMap policy_map_recommended; | 723 PolicyMap policy_map_recommended; |
724 policy_map_recommended.LoadFrom( | 724 policy_map_recommended.LoadFrom( |
725 policy_map_dict, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); | 725 policy_map_dict, POLICY_LEVEL_RECOMMENDED, POLICY_SCOPE_USER); |
726 | 726 |
727 PolicyMap policy_map_mandatory; | 727 PolicyMap policy_map_mandatory; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); | 810 handler_recommended.ApplyPolicySettings(policy_map_mandatory, &prefs); |
811 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); | 811 EXPECT_TRUE(prefs.GetValue(kTestPref, &value_set_in_pref)); |
812 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); | 812 EXPECT_TRUE(value_expected_in_pref->Equals(value_set_in_pref)); |
813 | 813 |
814 EXPECT_FALSE( | 814 EXPECT_FALSE( |
815 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); | 815 handler_none.CheckPolicySettings(policy_map_recommended, &errors)); |
816 EXPECT_FALSE(errors.empty()); | 816 EXPECT_FALSE(errors.empty()); |
817 } | 817 } |
818 | 818 |
819 } // namespace policy | 819 } // namespace policy |
OLD | NEW |