| Index: components/policy/core/common/schema_unittest.cc
|
| diff --git a/components/policy/core/common/schema_unittest.cc b/components/policy/core/common/schema_unittest.cc
|
| index 8fe58cf29bfbf889f7b77ac72f3cfc9eec9af249..6872cc847432d6c02a91f8431eade254a57dd5e2 100644
|
| --- a/components/policy/core/common/schema_unittest.cc
|
| +++ b/components/policy/core/common/schema_unittest.cc
|
| @@ -61,6 +61,15 @@ bool ParseFails(const std::string& content) {
|
| return true;
|
| }
|
|
|
| +std::string schemaObjectWrapper(const std::string &subschema) {
|
| + return "{"
|
| + " \"type\": \"object\","
|
| + " \"properties\": {"
|
| + " \"SomePropertyName\":" + subschema +
|
| + " }"
|
| + "}";
|
| +}
|
| +
|
| } // namespace
|
|
|
| TEST(SchemaTest, MinimalSchema) {
|
| @@ -682,5 +691,55 @@ TEST(SchemaTest, ItemsReference) {
|
| ASSERT_EQ(base::Value::TYPE_BOOLEAN, items.type());
|
| }
|
|
|
| +TEST(SchemaTest, EnumerationRestriction) {
|
| + // Enum attribute is a list.
|
| + EXPECT_TRUE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"string\","
|
| + " \"enum\": 12"
|
| + "}")));
|
| +
|
| + // Empty enum attributes is not allowed.
|
| + EXPECT_TRUE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"integer\","
|
| + " \"enum\": []"
|
| + "}")));
|
| +
|
| + // Enum elements type should be same as stated.
|
| + EXPECT_TRUE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"string\","
|
| + " \"enum\": [1, 2, 3]"
|
| + "}")));
|
| +
|
| + EXPECT_FALSE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"integer\","
|
| + " \"enum\": [1, 2, 3]"
|
| + "}")));
|
| +
|
| + EXPECT_FALSE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"string\","
|
| + " \"enum\": [\"1\", \"2\", \"3\"]"
|
| + "}")));
|
| +}
|
| +
|
| +TEST(SchemaTest, RangedRestriction) {
|
| + EXPECT_TRUE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"integer\","
|
| + " \"minimum\": 10,"
|
| + " \"maximum\": 5"
|
| + "}")));
|
| +
|
| + EXPECT_FALSE(ParseFails(schemaObjectWrapper(
|
| + "{"
|
| + " \"type\": \"integer\","
|
| + " \"minimum\": 10,"
|
| + " \"maximum\": 20"
|
| + "}")));
|
| +}
|
|
|
| } // namespace policy
|
|
|