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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "components/policy/core/common/schema_internal.h" | 8 #include "components/policy/core/common/schema_internal.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 // Test that Schema::Validate() works as expected. | 122 // Test that Schema::Validate() works as expected. |
123 error = kNoErrorReturned; | 123 error = kNoErrorReturned; |
124 bool returned = schema.Validate(value, strategy, NULL, &error); | 124 bool returned = schema.Validate(value, strategy, NULL, &error); |
125 EXPECT_EQ(returned, expected_return_value) << error; | 125 EXPECT_EQ(returned, expected_return_value) << error; |
126 | 126 |
127 // Test that Schema::Normalize() will return the same value as | 127 // Test that Schema::Normalize() will return the same value as |
128 // Schema::Validate(). | 128 // Schema::Validate(). |
129 error = kNoErrorReturned; | 129 error = kNoErrorReturned; |
130 scoped_ptr<base::Value> cloned_value(value.DeepCopy()); | 130 scoped_ptr<base::Value> cloned_value(value.DeepCopy()); |
131 returned = schema.Normalize(cloned_value.get(), strategy, NULL, &error); | 131 bool touched = false; |
| 132 returned = |
| 133 schema.Normalize(cloned_value.get(), strategy, NULL, &error, &touched); |
132 EXPECT_EQ(returned, expected_return_value) << error; | 134 EXPECT_EQ(returned, expected_return_value) << error; |
133 | 135 |
| 136 bool strictly_valid = schema.Validate(value, SCHEMA_STRICT, NULL, &error); |
| 137 EXPECT_EQ(!strictly_valid && returned, touched); |
| 138 |
134 // Test that Schema::Normalize() have actually dropped invalid and unknown | 139 // Test that Schema::Normalize() have actually dropped invalid and unknown |
135 // properties. | 140 // properties. |
136 if (expected_return_value) { | 141 if (expected_return_value) { |
137 EXPECT_TRUE( | 142 EXPECT_TRUE( |
138 schema.Validate(*cloned_value.get(), SCHEMA_STRICT, NULL, &error)); | 143 schema.Validate(*cloned_value.get(), SCHEMA_STRICT, NULL, &error)); |
139 EXPECT_TRUE( | 144 EXPECT_TRUE(schema.Normalize( |
140 schema.Normalize(cloned_value.get(), SCHEMA_STRICT, NULL, &error)); | 145 cloned_value.get(), SCHEMA_STRICT, NULL, &error, NULL)); |
141 } | 146 } |
142 } | 147 } |
143 | 148 |
144 void TestSchemaValidationWithPath(Schema schema, | 149 void TestSchemaValidationWithPath(Schema schema, |
145 const base::Value& value, | 150 const base::Value& value, |
146 const std::string& expected_failure_path) { | 151 const std::string& expected_failure_path) { |
147 std::string error_path = "NOT_SET"; | 152 std::string error_path = "NOT_SET"; |
148 std::string error; | 153 std::string error; |
149 | 154 |
150 bool returned = schema.Validate(value, SCHEMA_STRICT, &error_path, &error); | 155 bool returned = schema.Validate(value, SCHEMA_STRICT, &error_path, &error); |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 | 1050 |
1046 EXPECT_FALSE(ParseFails(SchemaObjectWrapper( | 1051 EXPECT_FALSE(ParseFails(SchemaObjectWrapper( |
1047 "{" | 1052 "{" |
1048 " \"type\": \"integer\"," | 1053 " \"type\": \"integer\"," |
1049 " \"minimum\": 10," | 1054 " \"minimum\": 10," |
1050 " \"maximum\": 20" | 1055 " \"maximum\": 20" |
1051 "}"))); | 1056 "}"))); |
1052 } | 1057 } |
1053 | 1058 |
1054 } // namespace policy | 1059 } // namespace policy |
OLD | NEW |