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

Unified Diff: components/policy/core/common/schema_unittest.cc

Issue 138003003: Add additional restriction to policy schema internal (part1) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix python generator and C++ parser Created 6 years, 11 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: 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

Powered by Google App Engine
This is Rietveld 408576698