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/schema.h" | 5 #include "components/policy/core/common/schema.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> |
10 | 11 |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
13 #include "components/policy/core/common/schema_internal.h" | 14 #include "components/policy/core/common/schema_internal.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace policy { | 17 namespace policy { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
763 root.Remove("Object.one", NULL); | 764 root.Remove("Object.one", NULL); |
764 } | 765 } |
765 | 766 |
766 // Tests on ArrayOfObjects. | 767 // Tests on ArrayOfObjects. |
767 { | 768 { |
768 Schema subschema = schema.GetProperty("ArrayOfObjects"); | 769 Schema subschema = schema.GetProperty("ArrayOfObjects"); |
769 ASSERT_TRUE(subschema.valid()); | 770 ASSERT_TRUE(subschema.valid()); |
770 base::ListValue root; | 771 base::ListValue root; |
771 | 772 |
772 // Unknown property. | 773 // Unknown property. |
773 base::DictionaryValue* dict_value = new base::DictionaryValue(); | 774 std::unique_ptr<base::DictionaryValue> dict_value( |
| 775 new base::DictionaryValue()); |
774 dict_value->SetBoolean("three", true); | 776 dict_value->SetBoolean("three", true); |
775 root.Append(dict_value); // Pass ownership to root. | 777 root.Append(std::move(dict_value)); |
776 TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); | 778 TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); |
777 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, false); | 779 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, false); |
778 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, true); | 780 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, true); |
779 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); | 781 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); |
780 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); | 782 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); |
781 TestSchemaValidationWithPath(subschema, root, "items[0]"); | 783 TestSchemaValidationWithPath(subschema, root, "items[0]"); |
782 root.Remove(root.GetSize() - 1, NULL); | 784 root.Remove(root.GetSize() - 1, NULL); |
783 | 785 |
784 // Invalid property. | 786 // Invalid property. |
785 dict_value = new base::DictionaryValue(); | 787 dict_value.reset(new base::DictionaryValue()); |
786 dict_value->SetBoolean("two", true); | 788 dict_value->SetBoolean("two", true); |
787 root.Append(dict_value); // Pass ownership to root. | 789 root.Append(std::move(dict_value)); |
788 TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); | 790 TestSchemaValidation(subschema, root, SCHEMA_STRICT, false); |
789 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, false); | 791 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, false); |
790 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, false); | 792 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, false); |
791 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); | 793 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); |
792 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); | 794 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); |
793 TestSchemaValidationWithPath(subschema, root, "items[0].two"); | 795 TestSchemaValidationWithPath(subschema, root, "items[0].two"); |
794 root.Remove(root.GetSize() - 1, NULL); | 796 root.Remove(root.GetSize() - 1, NULL); |
795 } | 797 } |
796 | 798 |
797 // Tests on ObjectOfArray. | 799 // Tests on ObjectOfArray. |
(...skipping 23 matching lines...) Expand all Loading... |
821 TestSchemaValidationWithPath(subschema, root, "List.items[1]"); | 823 TestSchemaValidationWithPath(subschema, root, "List.items[1]"); |
822 } | 824 } |
823 | 825 |
824 // Tests on ArrayOfObjectOfArray. | 826 // Tests on ArrayOfObjectOfArray. |
825 { | 827 { |
826 Schema subschema = schema.GetProperty("ArrayOfObjectOfArray"); | 828 Schema subschema = schema.GetProperty("ArrayOfObjectOfArray"); |
827 ASSERT_TRUE(subschema.valid()); | 829 ASSERT_TRUE(subschema.valid()); |
828 base::ListValue root; | 830 base::ListValue root; |
829 | 831 |
830 base::ListValue* list_value = new base::ListValue(); | 832 base::ListValue* list_value = new base::ListValue(); |
831 base::DictionaryValue* dict_value = new base::DictionaryValue(); | 833 std::unique_ptr<base::DictionaryValue> dict_value( |
| 834 new base::DictionaryValue()); |
832 dict_value->Set("List", list_value); // Pass ownership to dict_value. | 835 dict_value->Set("List", list_value); // Pass ownership to dict_value. |
833 root.Append(dict_value); // Pass ownership to root. | 836 root.Append(std::move(dict_value)); |
834 | 837 |
835 // Test that there are not errors here. | 838 // Test that there are not errors here. |
836 list_value->AppendString("blabla"); | 839 list_value->AppendString("blabla"); |
837 TestSchemaValidation(subschema, root, SCHEMA_STRICT, true); | 840 TestSchemaValidation(subschema, root, SCHEMA_STRICT, true); |
838 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, true); | 841 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN_TOPLEVEL, true); |
839 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, true); | 842 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_UNKNOWN, true); |
840 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); | 843 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID_TOPLEVEL, true); |
841 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); | 844 TestSchemaValidation(subschema, root, SCHEMA_ALLOW_INVALID, true); |
842 | 845 |
843 // Invalid list item. | 846 // Invalid list item. |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 | 1177 |
1175 EXPECT_FALSE(ParseFails(SchemaObjectWrapper( | 1178 EXPECT_FALSE(ParseFails(SchemaObjectWrapper( |
1176 "{" | 1179 "{" |
1177 " \"type\": \"integer\"," | 1180 " \"type\": \"integer\"," |
1178 " \"minimum\": 10," | 1181 " \"minimum\": 10," |
1179 " \"maximum\": 20" | 1182 " \"maximum\": 20" |
1180 "}"))); | 1183 "}"))); |
1181 } | 1184 } |
1182 | 1185 |
1183 } // namespace policy | 1186 } // namespace policy |
OLD | NEW |