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

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

Issue 143413002: Add additional restriction to policy schema internal (part2) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@expand-policy-schema
Patch Set: fix comments 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
« no previous file with comments | « components/policy/core/common/schema.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 3e0fd261f758c1e47334a7a82ae757505ba69799..8a3ba90b1bd09876b9f0f98900fb11a9ddd50b6c 100644
--- a/components/policy/core/common/schema_unittest.cc
+++ b/components/policy/core/common/schema_unittest.cc
@@ -48,6 +48,23 @@ const char kTestSchema[] =
" \"two\": { \"type\": \"integer\" }"
" },"
" \"additionalProperties\": { \"type\": \"string\" }"
+ " },"
+ " \"IntegerWithEnums\": {"
+ " \"type\": \"integer\","
+ " \"enum\": [1, 2, 3]"
+ " },"
+ " \"IntegerWithEnumsGaps\": {"
+ " \"type\": \"integer\","
+ " \"enum\": [10, 20, 30]"
+ " },"
+ " \"StringWithEnums\": {"
+ " \"type\": \"string\","
+ " \"enum\": [\"one\", \"two\", \"three\"]"
+ " },"
+ " \"IntegerWithRange\": {"
+ " \"type\": \"integer\","
+ " \"minimum\": 1,"
+ " \"maximum\": 3"
" }"
" }"
"}";
@@ -238,19 +255,39 @@ TEST(SchemaTest, ValidSchema) {
ASSERT_TRUE(subsub.valid());
EXPECT_EQ(base::Value::TYPE_STRING, subsub.type());
+ sub = schema.GetProperty("IntegerWithEnums");
+ ASSERT_TRUE(sub.valid());
+ ASSERT_EQ(base::Value::TYPE_INTEGER, sub.type());
+
+ sub = schema.GetProperty("IntegerWithEnumsGaps");
+ ASSERT_TRUE(sub.valid());
+ ASSERT_EQ(base::Value::TYPE_INTEGER, sub.type());
+
+ sub = schema.GetProperty("StringWithEnums");
+ ASSERT_TRUE(sub.valid());
+ ASSERT_EQ(base::Value::TYPE_STRING, sub.type());
+
+ sub = schema.GetProperty("IntegerWithRange");
+ ASSERT_TRUE(sub.valid());
+ ASSERT_EQ(base::Value::TYPE_INTEGER, sub.type());
+
struct {
const char* expected_key;
base::Value::Type expected_type;
} kExpectedProperties[] = {
- { "Array", base::Value::TYPE_LIST },
- { "ArrayOfArray", base::Value::TYPE_LIST },
- { "ArrayOfObjects", base::Value::TYPE_LIST },
- { "Boolean", base::Value::TYPE_BOOLEAN },
- { "Integer", base::Value::TYPE_INTEGER },
- { "Null", base::Value::TYPE_NULL },
- { "Number", base::Value::TYPE_DOUBLE },
- { "Object", base::Value::TYPE_DICTIONARY },
- { "String", base::Value::TYPE_STRING },
+ { "Array", base::Value::TYPE_LIST },
+ { "ArrayOfArray", base::Value::TYPE_LIST },
+ { "ArrayOfObjects", base::Value::TYPE_LIST },
+ { "Boolean", base::Value::TYPE_BOOLEAN },
+ { "Integer", base::Value::TYPE_INTEGER },
+ { "IntegerWithEnums", base::Value::TYPE_INTEGER },
+ { "IntegerWithEnumsGaps", base::Value::TYPE_INTEGER },
+ { "IntegerWithRange", base::Value::TYPE_INTEGER },
+ { "Null", base::Value::TYPE_NULL },
+ { "Number", base::Value::TYPE_DOUBLE },
+ { "Object", base::Value::TYPE_DICTIONARY },
+ { "String", base::Value::TYPE_STRING },
+ { "StringWithEnums", base::Value::TYPE_STRING },
};
Schema::Iterator it = schema.GetPropertiesIterator();
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kExpectedProperties); ++i) {
@@ -503,10 +540,50 @@ TEST(SchemaTest, Validate) {
bundle.Set("Object", dict.DeepCopy());
}
+ bundle.SetInteger("IntegerWithEnums", 1);
+ bundle.SetInteger("IntegerWithEnumsGaps", 20);
+ bundle.SetString("StringWithEnums", "two");
+ bundle.SetInteger("IntegerWithRange", 3);
+
EXPECT_TRUE(schema.Validate(bundle));
bundle.SetString("boom", "bang");
EXPECT_FALSE(schema.Validate(bundle));
+ bundle.Remove("boom", NULL);
+
+ bundle.SetInteger("IntegerWithEnums", 0);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnums", 1);
+
+ bundle.SetInteger("IntegerWithEnumsGaps", 0);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 9);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 10);
+ EXPECT_TRUE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 11);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 19);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 21);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 29);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 30);
+ EXPECT_TRUE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 31);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 100);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithEnumsGaps", 20);
+
+ bundle.SetString("StringWithEnums", "FOUR");
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetString("StringWithEnums", "two");
+
+ bundle.SetInteger("IntegerWithRange", 4);
+ EXPECT_FALSE(schema.Validate(bundle));
+ bundle.SetInteger("IntegerWithRange", 3);
}
TEST(SchemaTest, InvalidReferences) {
« no previous file with comments | « components/policy/core/common/schema.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698