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

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 SchemaTest.ValidSchema 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 3e0fd261f758c1e47334a7a82ae757505ba69799..b0eb6e308c264c2316f6bcc7e1a80d08bfccabc7 100644
--- a/components/policy/core/common/schema_unittest.cc
+++ b/components/policy/core/common/schema_unittest.cc
@@ -48,6 +48,19 @@ const char kTestSchema[] =
" \"two\": { \"type\": \"integer\" }"
" },"
" \"additionalProperties\": { \"type\": \"string\" }"
+ " },"
+ " \"IntegerWithEnums\": {"
+ " \"type\": \"integer\","
+ " \"enum\": [1, 2, 3]"
Joao da Silva 2014/01/20 20:22:18 This enumeration will get converted into a range (
binjin 2014/01/21 16:12:07 Done.
+ " },"
+ " \"StringWithEnums\": {"
+ " \"type\": \"string\","
+ " \"enum\": [\"one\", \"two\", \"three\"]"
+ " },"
+ " \"IntegerWithRange\": {"
+ " \"type\": \"integer\","
+ " \"minimum\": 1,"
+ " \"maximum\": 3"
" }"
" }"
"}";
@@ -238,6 +251,18 @@ 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("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;
@@ -247,10 +272,13 @@ TEST(SchemaTest, ValidSchema) {
{ "ArrayOfObjects", base::Value::TYPE_LIST },
{ "Boolean", base::Value::TYPE_BOOLEAN },
{ "Integer", base::Value::TYPE_INTEGER },
+ { "IntegerWithEnums", 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 +531,27 @@ TEST(SchemaTest, Validate) {
bundle.Set("Object", dict.DeepCopy());
}
+ bundle.SetInteger("IntegerWithEnums", 1);
+ 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.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);
Joao da Silva 2014/01/20 20:22:18 After adding the integer enum with gaps, test valu
binjin 2014/01/21 16:12:07 Done.
}
TEST(SchemaTest, InvalidReferences) {
« components/policy/core/common/schema.cc ('K') | « components/policy/core/common/schema.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698