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 "base/values.h" | 5 #include "base/values.h" |
6 #include "components/json_schema/json_schema_validator.h" | 6 #include "components/json_schema/json_schema_validator.h" |
7 #include "components/json_schema/json_schema_validator_unittest_base.h" | 7 #include "components/json_schema/json_schema_validator_unittest_base.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase { | 10 class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 "}", &error)); | 76 "}", &error)); |
77 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( | 77 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
78 "{" | 78 "{" |
79 " \"type\": \"string\"," | 79 " \"type\": \"string\"," |
80 " \"enum\": [ {} ]" // "enum" dict values must contain "name". | 80 " \"enum\": [ {} ]" // "enum" dict values must contain "name". |
81 "}", &error)); | 81 "}", &error)); |
82 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( | 82 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
83 "{" | 83 "{" |
84 " \"type\": \"string\"," | 84 " \"type\": \"string\"," |
85 " \"enum\": [ { \"name\": {} } ]" // "enum" name must be a simple value. | 85 " \"enum\": [ { \"name\": {} } ]" // "enum" name must be a simple value. |
86 "}", | 86 "}", &error)); |
87 &error)); | |
88 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( | 87 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
89 "{" | 88 "{" |
90 " \"type\": \"array\"," | 89 " \"type\": \"array\"," |
91 " \"items\": [ 123 ]," // "items" must contain a schema or schemas. | 90 " \"items\": [ 123 ]," // "items" must contain a schema or schemas. |
92 "}", &error)); | 91 "}", &error)); |
93 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( | 92 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
94 "{ \"type\": \"object\" }", &error)) << error; | 93 "{ \"type\": \"object\" }", &error)) << error; |
95 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( | 94 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
96 "{ \"type\": [\"object\", \"array\"] }", &error)) << error; | 95 "{ \"type\": [\"object\", \"array\"] }", &error)) << error; |
97 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( | 96 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
(...skipping 27 matching lines...) Expand all Loading... |
125 " \"items\": [" | 124 " \"items\": [" |
126 " { \"type\": \"string\" }," | 125 " { \"type\": \"string\" }," |
127 " { \"type\": \"integer\" }" | 126 " { \"type\": \"integer\" }" |
128 " ]" | 127 " ]" |
129 " }" | 128 " }" |
130 " }," | 129 " }," |
131 " \"additionalProperties\": {" | 130 " \"additionalProperties\": {" |
132 " \"type\": \"any\"" | 131 " \"type\": \"any\"" |
133 " }" | 132 " }" |
134 "}", &error)) << error; | 133 "}", &error)) << error; |
| 134 EXPECT_TRUE(JSONSchemaValidator::IsValidSchema( |
| 135 "{" |
| 136 " \"type\": \"object\"," |
| 137 " \"unknown attribute\": \"that should just be ignored\"" |
| 138 "}", |
| 139 JSONSchemaValidator::OPTIONS_IGNORE_UNKNOWN_ATTRIBUTES, |
| 140 &error)) << error; |
| 141 EXPECT_FALSE(JSONSchemaValidator::IsValidSchema( |
| 142 "{" |
| 143 " \"type\": \"object\"," |
| 144 " \"unknown attribute\": \"that will cause a failure\"" |
| 145 "}", 0, &error)) << error; |
135 } | 146 } |
OLD | NEW |