Chromium Code Reviews| Index: components/json_schema/json_schema_validator_unittest_base.cc |
| diff --git a/components/json_schema/json_schema_validator_unittest_base.cc b/components/json_schema/json_schema_validator_unittest_base.cc |
| index 2e936a2eb9a2a0ac923b0607df66ab0e41979524..f0746ed101dbdb927e1508d3ec5b72fe9fd26ebe 100644 |
| --- a/components/json_schema/json_schema_validator_unittest_base.cc |
| +++ b/components/json_schema/json_schema_validator_unittest_base.cc |
| @@ -118,10 +118,6 @@ void JSONSchemaValidatorTestBase::TestComplex() { |
| } |
| void JSONSchemaValidatorTestBase::TestStringPattern() { |
| - // Regex patterns not supported in CPP validator. |
| - if (type_ == CPP) |
| - return; |
| - |
| scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue()); |
| schema->SetString(schema::kType, schema::kString); |
| schema->SetString(schema::kPattern, "foo+"); |
| @@ -224,8 +220,8 @@ void JSONSchemaValidatorTestBase::TestObject() { |
| instance->SetBoolean("extra", true); |
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| "extra", JSONSchemaValidator::kUnexpectedProperty); |
| - |
| instance->Remove("extra", NULL); |
| + |
| instance->Remove("bar", NULL); |
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", |
| JSONSchemaValidator::kObjectPropertyIsRequired); |
| @@ -236,12 +232,49 @@ void JSONSchemaValidatorTestBase::TestObject() { |
| JSONSchemaValidator::kInvalidType, |
| schema::kInteger, |
| schema::kString)); |
| + instance->SetInteger("bar", 42); |
| + // Test "patternProperties". |
| + instance->SetInteger("extra", 42); |
| + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| + "extra", JSONSchemaValidator::kUnexpectedProperty); |
| + schema->SetString("patternProperties.extra+.type", |
| + schema::kInteger); |
| + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| + instance->SetInteger("extra", 42); |
|
Joao da Silva
2014/03/13 15:10:52
Isn't this already done in line 238 and tested in
binjin
2014/03/20 15:14:30
Done.
|
| + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| + instance->Remove("extra", NULL); |
| + instance->SetInteger("extraaa", 42); |
| + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| + instance->Remove("extraaa", NULL); |
| + instance->SetInteger("extr", 42); |
| + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| + "extr", JSONSchemaValidator::kUnexpectedProperty); |
| + instance->Remove("extr", NULL); |
| + schema->Remove(schema::kPatternProperties, NULL); |
| + |
| + // Test "patternProperties" and "properties" schemas are both checked if |
| + // applicable. |
| + schema->SetString("patternProperties.fo+.type", schema::kInteger); |
| + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "foo", |
| + JSONSchemaValidator::FormatErrorMessage( |
| + JSONSchemaValidator::kInvalidType, |
| + schema::kInteger, |
| + schema::kString)); |
| + instance->SetInteger("foo", 123); |
| + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "foo", |
| + JSONSchemaValidator::FormatErrorMessage( |
| + JSONSchemaValidator::kInvalidType, |
| + schema::kString, |
| + schema::kInteger)); |
| + instance->SetString("foo", "foo"); |
| + schema->Remove(schema::kPatternProperties, NULL); |
| + |
| + // Test additional properties. |
| base::DictionaryValue* additional_properties = new base::DictionaryValue(); |
| additional_properties->SetString(schema::kType, schema::kAny); |
| schema->Set(schema::kAdditionalProperties, additional_properties); |
| - instance->SetInteger("bar", 42); |
| instance->SetBoolean("extra", true); |
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| @@ -258,6 +291,7 @@ void JSONSchemaValidatorTestBase::TestObject() { |
| JSONSchemaValidator::kInvalidType, |
| schema::kBoolean, |
| schema::kString)); |
| + instance->Remove("extra", NULL); |
| base::DictionaryValue* properties = NULL; |
| base::DictionaryValue* bar_property = NULL; |
| @@ -265,7 +299,6 @@ void JSONSchemaValidatorTestBase::TestObject() { |
| ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); |
| bar_property->SetBoolean(schema::kOptional, true); |
| - instance->Remove("extra", NULL); |
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| instance->Remove("bar", NULL); |
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| @@ -281,6 +314,18 @@ void JSONSchemaValidatorTestBase::TestObject() { |
| JSONSchemaValidator::kInvalidType, |
| schema::kInteger, |
| schema::kString)); |
| + |
| + // Verify that JSON parser handles dot in "patternProperties" well. |
| + schema.reset(LoadDictionary("pattern_properties_dot.json")); |
| + ASSERT_TRUE(schema->GetDictionary(schema::kPatternProperties, &properties)); |
| + ASSERT_TRUE(properties->HasKey("^.$")); |
| + |
| + instance.reset(new base::DictionaryValue()); |
| + instance->SetString("a", "whatever"); |
| + ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); |
| + instance->SetString("foo", "bar"); |
| + ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, |
| + "foo", JSONSchemaValidator::kUnexpectedProperty); |
| } |
| void JSONSchemaValidatorTestBase::TestTypeReference() { |