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) { |