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

Unified Diff: components/json_schema/json_schema_validator_unittest.cc

Issue 94043003: Ignore unknown attributes when parsing JSON schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: added flag Created 7 years 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 side-by-side diff with in-line comments
Download patch
Index: components/json_schema/json_schema_validator_unittest.cc
diff --git a/components/json_schema/json_schema_validator_unittest.cc b/components/json_schema/json_schema_validator_unittest.cc
index 6372032c13576b29f56a860d255c19c18c057edd..8a5d113abc90ea97b5debd29f63a794479f39ac0 100644
--- a/components/json_schema/json_schema_validator_unittest.cc
+++ b/components/json_schema/json_schema_validator_unittest.cc
@@ -54,46 +54,45 @@ TEST_F(JSONSchemaValidatorCPPTest, Test) {
TEST(JSONSchemaValidator, IsValidSchema) {
std::string error;
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("", &error));
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\0", &error));
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("string", &error));
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\"string\"", &error));
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("[]", &error));
- EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("{}", &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("", false, &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\0", false, &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("string", false, &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("\"string\"", false, &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("[]", false, &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema("{}", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
- "{ \"type\": 123 }", &error));
+ "{ \"type\": 123 }", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
- "{ \"type\": \"invalid\" }", &error));
+ "{ \"type\": \"invalid\" }", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": \"object\","
" \"properties\": []" // Invalid properties type.
- "}", &error));
+ "}", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": \"string\","
" \"maxLength\": -1" // Must be >= 0.
- "}", &error));
+ "}", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": \"string\","
" \"enum\": [ {} ]" // "enum" dict values must contain "name".
- "}", &error));
+ "}", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": \"string\","
" \"enum\": [ { \"name\": {} } ]" // "enum" name must be a simple value.
- "}",
- &error));
+ "}", false, &error));
EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": \"array\","
" \"items\": [ 123 ]," // "items" must contain a schema or schemas.
- "}", &error));
+ "}", false, &error));
EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
- "{ \"type\": \"object\" }", &error)) << error;
+ "{ \"type\": \"object\" }", false, &error)) << error;
EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
- "{ \"type\": [\"object\", \"array\"] }", &error)) << error;
+ "{ \"type\": [\"object\", \"array\"] }", false, &error)) << error;
EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
"{"
" \"type\": [\"object\", \"array\"],"
@@ -131,5 +130,15 @@ TEST(JSONSchemaValidator, IsValidSchema) {
" \"additionalProperties\": {"
" \"type\": \"any\""
" }"
- "}", &error)) << error;
+ "}", false, &error)) << error;
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": \"object\","
+ " \"unknown attribute\": \"that should just be ignored\""
+ "}", true, &error)) << error;
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": \"object\","
+ " \"unknown attribute\": \"that will cause a failure\""
+ "}", false, &error)) << error;
}

Powered by Google App Engine
This is Rietveld 408576698