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

Unified Diff: chrome/common/json_schema/json_schema_validator_unittest.cc

Issue 14830007: Added a validator for JSON v3 schemas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased, addressed comments Created 7 years, 7 months 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: chrome/common/json_schema/json_schema_validator_unittest.cc
diff --git a/chrome/common/json_schema/json_schema_validator_unittest.cc b/chrome/common/json_schema/json_schema_validator_unittest.cc
index b2fdc542957a262dc5e150857510d4216334dfbd..bf43bc66fa8c2336792cf66da0930df161cd296a 100644
--- a/chrome/common/json_schema/json_schema_validator_unittest.cc
+++ b/chrome/common/json_schema/json_schema_validator_unittest.cc
@@ -50,3 +50,79 @@ class JSONSchemaValidatorCPPTest : public JSONSchemaValidatorTestBase {
TEST_F(JSONSchemaValidatorCPPTest, Test) {
RunTests();
}
+
+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(
+ "{ \"type\": 123 }", &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
+ "{ \"type\": \"invalid\" }", &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": \"object\","
+ " \"properties\": []" // Invalid properties type.
+ "}", &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": \"string\","
+ " \"maxLength\": -1" // Must be >= 0.
+ "}", &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": \"string\","
+ " \"enum\": [ {} ]," // "enum" must contain simple values.
+ "}", &error));
+ EXPECT_FALSE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": \"array\","
+ " \"items\": [ 123 ]," // "items" must contain a schema or schemas.
+ "}", &error));
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
+ "{ \"type\": \"object\" }", &error)) << error;
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
+ "{ \"type\": [\"object\", \"array\"] }", &error)) << error;
+ EXPECT_TRUE(JSONSchemaValidator::IsValidSchema(
+ "{"
+ " \"type\": [\"object\", \"array\"],"
+ " \"properties\": {"
+ " \"string-property\": {"
+ " \"type\": \"string\","
+ " \"minLength\": 1,"
+ " \"maxLength\": 100,"
+ " \"title\": \"The String Policy\","
+ " \"description\": \"This policy controls the String widget.\""
+ " },"
+ " \"integer-property\": {"
+ " \"type\": \"number\","
+ " \"minimum\": 1000.0,"
+ " \"maximum\": 9999.0"
+ " },"
+ " \"enum-property\": {"
+ " \"type\": \"integer\","
+ " \"enum\": [0, 1, 10, 100]"
+ " },"
+ " \"items-property\": {"
+ " \"type\": \"array\","
+ " \"items\": {"
+ " \"type\": \"string\""
+ " }"
+ " },"
+ " \"items-list-property\": {"
+ " \"type\": \"array\","
+ " \"items\": ["
+ " { \"type\": \"string\" },"
+ " { \"type\": \"integer\" }"
+ " ]"
+ " }"
+ " },"
+ " \"additionalProperties\": {"
+ " \"type\": \"any\""
+ " }"
+ "}", &error)) << error;
+}

Powered by Google App Engine
This is Rietveld 408576698