| Index: chrome/common/json_schema_validator_unittest_base.cc
|
| diff --git a/chrome/common/json_schema_validator_unittest_base.cc b/chrome/common/json_schema_validator_unittest_base.cc
|
| index 3e1ee7391fd24a2eebe7170e2c3a5da46506e8cb..a81082c4de80c9991a0133be03c32398f46365bb 100644
|
| --- a/chrome/common/json_schema_validator_unittest_base.cc
|
| +++ b/chrome/common/json_schema_validator_unittest_base.cc
|
| @@ -16,8 +16,11 @@
|
| #include "base/stringprintf.h"
|
| #include "base/values.h"
|
| #include "chrome/common/chrome_paths.h"
|
| +#include "chrome/common/json_schema_constants.h"
|
| #include "chrome/common/json_schema_validator.h"
|
|
|
| +using namespace json_schema_constants;
|
| +
|
| namespace {
|
|
|
| #define TEST_SOURCE base::StringPrintf("%s:%i", __FILE__, __LINE__)
|
| @@ -94,7 +97,7 @@ void JSONSchemaValidatorTestBase::TestComplex() {
|
| instance->Append(new DictionaryValue());
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "number", "object"));
|
| + JSONSchemaValidator::kInvalidType, kNumber, kObject));
|
| instance->Remove(instance->GetSize() - 1, NULL);
|
|
|
| DictionaryValue* item = NULL;
|
| @@ -113,8 +116,8 @@ void JSONSchemaValidatorTestBase::TestStringPattern() {
|
| return;
|
|
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
| - schema->SetString("type", "string");
|
| - schema->SetString("pattern", "foo+");
|
| + schema->SetString(kType, kString);
|
| + schema->SetString(kPattern, "foo+");
|
|
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateStringValue("foo")).get(),
|
| @@ -182,9 +185,9 @@ void JSONSchemaValidatorTestBase::TestExtends() {
|
|
|
| void JSONSchemaValidatorTestBase::TestObject() {
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
| - schema->SetString("type", "object");
|
| - schema->SetString("properties.foo.type", "string");
|
| - schema->SetString("properties.bar.type", "integer");
|
| + schema->SetString(kType, kObject);
|
| + schema->SetString("properties.foo.type", kString);
|
| + schema->SetString("properties.bar.type", kInteger);
|
|
|
| scoped_ptr<DictionaryValue> instance(new DictionaryValue());
|
| instance->SetString("foo", "foo");
|
| @@ -204,11 +207,11 @@ void JSONSchemaValidatorTestBase::TestObject() {
|
| instance->SetString("bar", "42");
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "integer", "string"));
|
| + JSONSchemaValidator::kInvalidType, kInteger, kString));
|
|
|
| DictionaryValue* additional_properties = new DictionaryValue();
|
| - additional_properties->SetString("type", "any");
|
| - schema->Set("additionalProperties", additional_properties);
|
| + additional_properties->SetString(kType, kAny);
|
| + schema->Set(kAdditionalProperties, additional_properties);
|
|
|
| instance->SetInteger("bar", 42);
|
| instance->SetBoolean("extra", true);
|
| @@ -217,21 +220,21 @@ void JSONSchemaValidatorTestBase::TestObject() {
|
| instance->SetString("extra", "foo");
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
|
|
| - additional_properties->SetString("type", "boolean");
|
| + additional_properties->SetString(kType, kBoolean);
|
| instance->SetBoolean("extra", true);
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
|
|
| instance->SetString("extra", "foo");
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
|
| "extra", JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "boolean", "string"));
|
| + JSONSchemaValidator::kInvalidType, kBoolean, kString));
|
|
|
| DictionaryValue* properties = NULL;
|
| DictionaryValue* bar_property = NULL;
|
| - ASSERT_TRUE(schema->GetDictionary("properties", &properties));
|
| + ASSERT_TRUE(schema->GetDictionary(kProperties, &properties));
|
| ASSERT_TRUE(properties->GetDictionary("bar", &bar_property));
|
|
|
| - bar_property->SetBoolean("optional", true);
|
| + bar_property->SetBoolean(kOptional, true);
|
| instance->Remove("extra", NULL);
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
| instance->Remove("bar", NULL);
|
| @@ -239,11 +242,11 @@ void JSONSchemaValidatorTestBase::TestObject() {
|
| instance->Set("bar", Value::CreateNullValue());
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
|
| "bar", JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "integer", "null"));
|
| + JSONSchemaValidator::kInvalidType, kInteger, kNull));
|
| instance->SetString("bar", "42");
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
|
| "bar", JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "integer", "string"));
|
| + JSONSchemaValidator::kInvalidType, kInteger, kString));
|
| }
|
|
|
| void JSONSchemaValidatorTestBase::TestTypeReference() {
|
| @@ -251,16 +254,16 @@ void JSONSchemaValidatorTestBase::TestTypeReference() {
|
| ASSERT_TRUE(types.get());
|
|
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
| - schema->SetString("type", "object");
|
| - schema->SetString("properties.foo.type", "string");
|
| + schema->SetString(kType, kObject);
|
| + schema->SetString("properties.foo.type", kString);
|
| schema->SetString("properties.bar.$ref", "Max10Int");
|
| schema->SetString("properties.baz.$ref", "MinLengthString");
|
|
|
| scoped_ptr<DictionaryValue> schema_inline(new DictionaryValue());
|
| - schema_inline->SetString("type", "object");
|
| - schema_inline->SetString("properties.foo.type", "string");
|
| + schema_inline->SetString(kType, kObject);
|
| + schema_inline->SetString("properties.foo.type", kString);
|
| schema_inline->SetString("properties.bar.id", "NegativeInt");
|
| - schema_inline->SetString("properties.bar.type", "integer");
|
| + schema_inline->SetString("properties.bar.type", kInteger);
|
| schema_inline->SetInteger("properties.bar.maximum", 0);
|
| schema_inline->SetString("properties.baz.$ref", "NegativeInt");
|
|
|
| @@ -329,29 +332,29 @@ void JSONSchemaValidatorTestBase::TestArrayTuple() {
|
| instance->Append(Value::CreateIntegerValue(42));
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "string", "integer"));
|
| + JSONSchemaValidator::kInvalidType, kString, kInteger));
|
|
|
| DictionaryValue* additional_properties = new DictionaryValue();
|
| - additional_properties->SetString("type", "any");
|
| - schema->Set("additionalProperties", additional_properties);
|
| + additional_properties->SetString(kType, kAny);
|
| + schema->Set(kAdditionalProperties, additional_properties);
|
| instance->Set(0, Value::CreateStringValue("42"));
|
| instance->Append(Value::CreateStringValue("anything"));
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
| instance->Set(2, new ListValue());
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
|
|
| - additional_properties->SetString("type", "boolean");
|
| + additional_properties->SetString(kType, kBoolean);
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "boolean", "array"));
|
| + JSONSchemaValidator::kInvalidType, kBoolean, kArray));
|
| instance->Set(2, Value::CreateBooleanValue(false));
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
|
|
| ListValue* items_schema = NULL;
|
| DictionaryValue* item0_schema = NULL;
|
| - ASSERT_TRUE(schema->GetList("items", &items_schema));
|
| + ASSERT_TRUE(schema->GetList(kItems, &items_schema));
|
| ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema));
|
| - item0_schema->SetBoolean("optional", true);
|
| + item0_schema->SetBoolean(kOptional, true);
|
| instance->Remove(2, NULL);
|
| ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
|
| // TODO(aa): I think this is inconsistent with the handling of NULL+optional
|
| @@ -361,15 +364,15 @@ void JSONSchemaValidatorTestBase::TestArrayTuple() {
|
| instance->Set(0, Value::CreateIntegerValue(42));
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "string", "integer"));
|
| + JSONSchemaValidator::kInvalidType, kString, kInteger));
|
| }
|
|
|
| void JSONSchemaValidatorTestBase::TestArrayNonTuple() {
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
| - schema->SetString("type", "array");
|
| - schema->SetString("items.type", "string");
|
| - schema->SetInteger("minItems", 2);
|
| - schema->SetInteger("maxItems", 3);
|
| + schema->SetString(kType, kArray);
|
| + schema->SetString("items.type", kString);
|
| + schema->SetInteger(kMinItems, 2);
|
| + schema->SetInteger(kMaxItems, 3);
|
|
|
| scoped_ptr<ListValue> instance(new ListValue());
|
| instance->Append(Value::CreateStringValue("x"));
|
| @@ -394,14 +397,14 @@ void JSONSchemaValidatorTestBase::TestArrayNonTuple() {
|
| instance->Append(Value::CreateIntegerValue(42));
|
| ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "string", "integer"));
|
| + JSONSchemaValidator::kInvalidType, kString, kInteger));
|
| }
|
|
|
| void JSONSchemaValidatorTestBase::TestString() {
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
| - schema->SetString("type", "string");
|
| - schema->SetInteger("minLength", 1);
|
| - schema->SetInteger("maxLength", 10);
|
| + schema->SetString(kType, kString);
|
| + schema->SetInteger(kMinLength, 1);
|
| + schema->SetInteger(kMaxLength, 10);
|
|
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateStringValue("x")).get(),
|
| @@ -426,9 +429,9 @@ void JSONSchemaValidatorTestBase::TestString() {
|
|
|
| void JSONSchemaValidatorTestBase::TestNumber() {
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
| - schema->SetString("type", "number");
|
| - schema->SetInteger("minimum", 1);
|
| - schema->SetInteger("maximum", 100);
|
| + schema->SetString(kType, kNumber);
|
| + schema->SetInteger(kMinimum, 1);
|
| + schema->SetInteger(kMaximum, 100);
|
| schema->SetInteger("maxDecimal", 2);
|
|
|
| ExpectValid(TEST_SOURCE,
|
| @@ -505,20 +508,20 @@ void JSONSchemaValidatorTestBase::TestTypes() {
|
| scoped_ptr<DictionaryValue> schema(new DictionaryValue());
|
|
|
| // valid
|
| - schema->SetString("type", "object");
|
| + schema->SetString(kType, kObject);
|
| ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new DictionaryValue()).get(),
|
| schema.get(), NULL);
|
|
|
| - schema->SetString("type", "array");
|
| + schema->SetString(kType, kArray);
|
| ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(),
|
| schema.get(), NULL);
|
|
|
| - schema->SetString("type", "string");
|
| + schema->SetString(kType, kString);
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateStringValue("foobar")).get(),
|
| schema.get(), NULL);
|
|
|
| - schema->SetString("type", "number");
|
| + schema->SetString(kType, kNumber);
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(),
|
| schema.get(), NULL);
|
| @@ -532,7 +535,7 @@ void JSONSchemaValidatorTestBase::TestTypes() {
|
| scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(),
|
| schema.get(), NULL);
|
|
|
| - schema->SetString("type", "integer");
|
| + schema->SetString(kType, kInteger);
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(),
|
| schema.get(), NULL);
|
| @@ -551,7 +554,7 @@ void JSONSchemaValidatorTestBase::TestTypes() {
|
| Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get(),
|
| schema.get(), NULL);
|
|
|
| - schema->SetString("type", "boolean");
|
| + schema->SetString(kType, kBoolean);
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(),
|
| schema.get(), NULL);
|
| @@ -559,70 +562,70 @@ void JSONSchemaValidatorTestBase::TestTypes() {
|
| scoped_ptr<Value>(Value::CreateBooleanValue(true)).get(),
|
| schema.get(), NULL);
|
|
|
| - schema->SetString("type", "null");
|
| + schema->SetString(kType, kNull);
|
| ExpectValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateNullValue()).get(),
|
| schema.get(), NULL);
|
|
|
| // not valid
|
| - schema->SetString("type", "object");
|
| + schema->SetString(kType, kObject);
|
| ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "object", "array"));
|
| + JSONSchemaValidator::kInvalidType, kObject, kArray));
|
|
|
| - schema->SetString("type", "object");
|
| + schema->SetString(kType, kObject);
|
| ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(Value::CreateNullValue()).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "object", "null"));
|
| + JSONSchemaValidator::kInvalidType, kObject, kNull));
|
|
|
| - schema->SetString("type", "array");
|
| + schema->SetString(kType, kArray);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "array", "integer"));
|
| + JSONSchemaValidator::kInvalidType, kArray, kInteger));
|
|
|
| - schema->SetString("type", "string");
|
| + schema->SetString(kType, kString);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "string", "integer"));
|
| + JSONSchemaValidator::kInvalidType, kString, kInteger));
|
|
|
| - schema->SetString("type", "number");
|
| + schema->SetString(kType, kNumber);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateStringValue("42")).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "number", "string"));
|
| + JSONSchemaValidator::kInvalidType, kNumber, kString));
|
|
|
| - schema->SetString("type", "integer");
|
| + schema->SetString(kType, kInteger);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "integer", "number"));
|
| + JSONSchemaValidator::kInvalidType, kInteger, kNumber));
|
|
|
| - schema->SetString("type", "integer");
|
| + schema->SetString(kType, kInteger);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "integer", "number"));
|
| + JSONSchemaValidator::kInvalidType, kInteger, kNumber));
|
|
|
| - schema->SetString("type", "boolean");
|
| + schema->SetString(kType, kBoolean);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "boolean", "integer"));
|
| + JSONSchemaValidator::kInvalidType, kBoolean, kInteger));
|
|
|
| - schema->SetString("type", "null");
|
| + schema->SetString(kType, kNull);
|
| ExpectNotValid(TEST_SOURCE,
|
| scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(),
|
| schema.get(), NULL, "",
|
| JSONSchemaValidator::FormatErrorMessage(
|
| - JSONSchemaValidator::kInvalidType, "null", "boolean"));
|
| + JSONSchemaValidator::kInvalidType, kNull, kBoolean));
|
| }
|
|
|