1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/json_schema/json_schema_validator_unittest_base.h"
11 #include "base/base_paths.h"
12 #include "base/file_util.h"
13 #include "base/json/json_file_value_serializer.h"
14 #include "base/logging.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h"
17 #include "base/strings/stringprintf.h"
18 #include "base/values.h"
19 #include "components/json_schema/json_schema_constants.h"
20 #include "components/json_schema/json_schema_validator.h"
22 namespace schema = json_schema_constants;
26 #define TEST_SOURCE base::StringPrintf("%s:%i", __FILE__, __LINE__)
28 base::Value* LoadValue(const std::string& filename) {
30 PathService::Get(base::DIR_SOURCE_ROOT, &path);
31 path = path.AppendASCII("components")
34 .AppendASCII("json_schema")
35 .AppendASCII(filename);
36 EXPECT_TRUE(base::PathExists(path));
38 std::string error_message;
39 JSONFileValueSerializer serializer(path);
40 base::Value* result = serializer.Deserialize(NULL, &error_message);
42 ADD_FAILURE() << "Could not parse JSON: " << error_message;
46 base::Value* LoadValue(const std::string& filename, base::Value::Type type) {
47 scoped_ptr<base::Value> result(LoadValue(filename));
50 if (!result->IsType(type)) {
51 ADD_FAILURE() << "Expected type " << type << ", got: " << result->GetType();
54 return result.release();
57 base::ListValue* LoadList(const std::string& filename) {
58 return static_cast<base::ListValue*>(
59 LoadValue(filename, base::Value::TYPE_LIST));
62 base::DictionaryValue* LoadDictionary(const std::string& filename) {
63 return static_cast<base::DictionaryValue*>(
64 LoadValue(filename, base::Value::TYPE_DICTIONARY));
70 JSONSchemaValidatorTestBase::JSONSchemaValidatorTestBase(
71 JSONSchemaValidatorTestBase::ValidatorType type)
75 void JSONSchemaValidatorTestBase::RunTests() {
91 void JSONSchemaValidatorTestBase::TestComplex() {
92 scoped_ptr<base::DictionaryValue> schema(
93 LoadDictionary("complex_schema.json"));
94 scoped_ptr<base::ListValue> instance(LoadList("complex_instance.json"));
96 ASSERT_TRUE(schema.get());
97 ASSERT_TRUE(instance.get());
99 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
100 instance->Remove(instance->GetSize() - 1, NULL);
101 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
102 instance->Append(new base::DictionaryValue());
103 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
104 JSONSchemaValidator::FormatErrorMessage(
105 JSONSchemaValidator::kInvalidType,
108 instance->Remove(instance->GetSize() - 1, NULL);
110 base::DictionaryValue* item = NULL;
111 ASSERT_TRUE(instance->GetDictionary(0, &item));
112 item->SetString("url", "xxxxxxxxxxx");
114 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
116 JSONSchemaValidator::FormatErrorMessage(
117 JSONSchemaValidator::kStringMaxLength, "10"));
120 void JSONSchemaValidatorTestBase::TestStringPattern() {
121 // Regex patterns not supported in CPP validator.
125 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
126 schema->SetString(schema::kType, schema::kString);
127 schema->SetString(schema::kPattern, "foo+");
129 ExpectValid(TEST_SOURCE,
130 scoped_ptr<base::Value>(new base::StringValue("foo")).get(),
132 ExpectValid(TEST_SOURCE,
133 scoped_ptr<base::Value>(new base::StringValue("foooooo")).get(),
135 ExpectNotValid(TEST_SOURCE,
136 scoped_ptr<base::Value>(new base::StringValue("bar")).get(),
140 JSONSchemaValidator::FormatErrorMessage(
141 JSONSchemaValidator::kStringPattern, "foo+"));
144 void JSONSchemaValidatorTestBase::TestEnum() {
145 scoped_ptr<base::DictionaryValue> schema(LoadDictionary("enum_schema.json"));
147 ExpectValid(TEST_SOURCE,
148 scoped_ptr<base::Value>(new base::StringValue("foo")).get(),
150 ExpectValid(TEST_SOURCE,
151 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
153 ExpectValid(TEST_SOURCE,
154 scoped_ptr<base::Value>(new base::FundamentalValue(false)).get(),
157 ExpectNotValid(TEST_SOURCE,
158 scoped_ptr<base::Value>(new base::StringValue("42")).get(),
162 JSONSchemaValidator::kInvalidEnum);
163 ExpectNotValid(TEST_SOURCE,
164 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
168 JSONSchemaValidator::kInvalidEnum);
171 void JSONSchemaValidatorTestBase::TestChoices() {
172 scoped_ptr<base::DictionaryValue> schema(
173 LoadDictionary("choices_schema.json"));
175 ExpectValid(TEST_SOURCE,
176 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
178 ExpectValid(TEST_SOURCE,
179 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
182 scoped_ptr<base::DictionaryValue> instance(new base::DictionaryValue());
183 instance->SetString("foo", "bar");
184 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
186 ExpectNotValid(TEST_SOURCE,
187 scoped_ptr<base::Value>(new base::StringValue("foo")).get(),
191 JSONSchemaValidator::kInvalidChoice);
192 ExpectNotValid(TEST_SOURCE,
193 scoped_ptr<base::Value>(new base::ListValue()).get(),
197 JSONSchemaValidator::kInvalidChoice);
199 instance->SetInteger("foo", 42);
200 ExpectNotValid(TEST_SOURCE,
205 JSONSchemaValidator::kInvalidChoice);
208 void JSONSchemaValidatorTestBase::TestExtends() {
212 void JSONSchemaValidatorTestBase::TestObject() {
213 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
214 schema->SetString(schema::kType, schema::kObject);
215 schema->SetString("properties.foo.type", schema::kString);
216 schema->SetString("properties.bar.type", schema::kInteger);
218 scoped_ptr<base::DictionaryValue> instance(new base::DictionaryValue());
219 instance->SetString("foo", "foo");
220 instance->SetInteger("bar", 42);
222 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
224 instance->SetBoolean("extra", true);
225 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
226 "extra", JSONSchemaValidator::kUnexpectedProperty);
228 instance->Remove("extra", NULL);
229 instance->Remove("bar", NULL);
230 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar",
231 JSONSchemaValidator::kObjectPropertyIsRequired);
233 instance->SetString("bar", "42");
234 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar",
235 JSONSchemaValidator::FormatErrorMessage(
236 JSONSchemaValidator::kInvalidType,
240 base::DictionaryValue* additional_properties = new base::DictionaryValue();
241 additional_properties->SetString(schema::kType, schema::kAny);
242 schema->Set(schema::kAdditionalProperties, additional_properties);
244 instance->SetInteger("bar", 42);
245 instance->SetBoolean("extra", true);
246 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
248 instance->SetString("extra", "foo");
249 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
251 additional_properties->SetString(schema::kType, schema::kBoolean);
252 instance->SetBoolean("extra", true);
253 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
255 instance->SetString("extra", "foo");
256 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
257 "extra", JSONSchemaValidator::FormatErrorMessage(
258 JSONSchemaValidator::kInvalidType,
262 base::DictionaryValue* properties = NULL;
263 base::DictionaryValue* bar_property = NULL;
264 ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties));
265 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property));
267 bar_property->SetBoolean(schema::kOptional, true);
268 instance->Remove("extra", NULL);
269 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
270 instance->Remove("bar", NULL);
271 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
272 instance->Set("bar", base::Value::CreateNullValue());
273 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
274 "bar", JSONSchemaValidator::FormatErrorMessage(
275 JSONSchemaValidator::kInvalidType,
278 instance->SetString("bar", "42");
279 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
280 "bar", JSONSchemaValidator::FormatErrorMessage(
281 JSONSchemaValidator::kInvalidType,
286 void JSONSchemaValidatorTestBase::TestTypeReference() {
287 scoped_ptr<base::ListValue> types(LoadList("reference_types.json"));
288 ASSERT_TRUE(types.get());
290 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
291 schema->SetString(schema::kType, schema::kObject);
292 schema->SetString("properties.foo.type", schema::kString);
293 schema->SetString("properties.bar.$ref", "Max10Int");
294 schema->SetString("properties.baz.$ref", "MinLengthString");
296 scoped_ptr<base::DictionaryValue> schema_inline(new base::DictionaryValue());
297 schema_inline->SetString(schema::kType, schema::kObject);
298 schema_inline->SetString("properties.foo.type", schema::kString);
299 schema_inline->SetString("properties.bar.id", "NegativeInt");
300 schema_inline->SetString("properties.bar.type", schema::kInteger);
301 schema_inline->SetInteger("properties.bar.maximum", 0);
302 schema_inline->SetString("properties.baz.$ref", "NegativeInt");
304 scoped_ptr<base::DictionaryValue> instance(new base::DictionaryValue());
305 instance->SetString("foo", "foo");
306 instance->SetInteger("bar", 4);
307 instance->SetString("baz", "ab");
309 scoped_ptr<base::DictionaryValue> instance_inline(
310 new base::DictionaryValue());
311 instance_inline->SetString("foo", "foo");
312 instance_inline->SetInteger("bar", -4);
313 instance_inline->SetInteger("baz", -2);
315 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), types.get());
316 ExpectValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL);
318 // Validation failure, but successful schema reference.
319 instance->SetString("baz", "a");
320 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), types.get(),
321 "baz", JSONSchemaValidator::FormatErrorMessage(
322 JSONSchemaValidator::kStringMinLength, "2"));
324 instance_inline->SetInteger("bar", 20);
325 ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL,
326 "bar", JSONSchemaValidator::FormatErrorMessage(
327 JSONSchemaValidator::kNumberMaximum, "0"));
329 // Remove MinLengthString type.
330 types->Remove(types->GetSize() - 1, NULL);
331 instance->SetString("baz", "ab");
332 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), types.get(),
333 "bar", JSONSchemaValidator::FormatErrorMessage(
334 JSONSchemaValidator::kUnknownTypeReference,
337 // Remove internal type "NegativeInt".
338 schema_inline->Remove("properties.bar", NULL);
339 instance_inline->Remove("bar", NULL);
340 ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL,
341 "baz", JSONSchemaValidator::FormatErrorMessage(
342 JSONSchemaValidator::kUnknownTypeReference,
346 void JSONSchemaValidatorTestBase::TestArrayTuple() {
347 scoped_ptr<base::DictionaryValue> schema(
348 LoadDictionary("array_tuple_schema.json"));
349 ASSERT_TRUE(schema.get());
351 scoped_ptr<base::ListValue> instance(new base::ListValue());
352 instance->Append(new base::StringValue("42"));
353 instance->Append(new base::FundamentalValue(42));
355 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
357 instance->Append(new base::StringValue("anything"));
358 ExpectNotValid(TEST_SOURCE,
363 JSONSchemaValidator::FormatErrorMessage(
364 JSONSchemaValidator::kArrayMaxItems, "2"));
366 instance->Remove(1, NULL);
367 instance->Remove(1, NULL);
368 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
369 JSONSchemaValidator::kArrayItemRequired);
371 instance->Set(0, new base::FundamentalValue(42));
372 instance->Append(new base::FundamentalValue(42));
373 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
374 JSONSchemaValidator::FormatErrorMessage(
375 JSONSchemaValidator::kInvalidType,
379 base::DictionaryValue* additional_properties = new base::DictionaryValue();
380 additional_properties->SetString(schema::kType, schema::kAny);
381 schema->Set(schema::kAdditionalProperties, additional_properties);
382 instance->Set(0, new base::StringValue("42"));
383 instance->Append(new base::StringValue("anything"));
384 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
385 instance->Set(2, new base::ListValue());
386 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
388 additional_properties->SetString(schema::kType, schema::kBoolean);
389 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2",
390 JSONSchemaValidator::FormatErrorMessage(
391 JSONSchemaValidator::kInvalidType,
394 instance->Set(2, new base::FundamentalValue(false));
395 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
397 base::ListValue* items_schema = NULL;
398 base::DictionaryValue* item0_schema = NULL;
399 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema));
400 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema));
401 item0_schema->SetBoolean(schema::kOptional, true);
402 instance->Remove(2, NULL);
403 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
404 // TODO(aa): I think this is inconsistent with the handling of NULL+optional
406 instance->Set(0, base::Value::CreateNullValue());
407 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
408 instance->Set(0, new base::FundamentalValue(42));
409 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
410 JSONSchemaValidator::FormatErrorMessage(
411 JSONSchemaValidator::kInvalidType,
416 void JSONSchemaValidatorTestBase::TestArrayNonTuple() {
417 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
418 schema->SetString(schema::kType, schema::kArray);
419 schema->SetString("items.type", schema::kString);
420 schema->SetInteger(schema::kMinItems, 2);
421 schema->SetInteger(schema::kMaxItems, 3);
423 scoped_ptr<base::ListValue> instance(new base::ListValue());
424 instance->Append(new base::StringValue("x"));
425 instance->Append(new base::StringValue("x"));
427 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
428 instance->Append(new base::StringValue("x"));
429 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
431 instance->Append(new base::StringValue("x"));
432 ExpectNotValid(TEST_SOURCE,
437 JSONSchemaValidator::FormatErrorMessage(
438 JSONSchemaValidator::kArrayMaxItems, "3"));
439 instance->Remove(1, NULL);
440 instance->Remove(1, NULL);
441 instance->Remove(1, NULL);
442 ExpectNotValid(TEST_SOURCE,
447 JSONSchemaValidator::FormatErrorMessage(
448 JSONSchemaValidator::kArrayMinItems, "2"));
450 instance->Remove(1, NULL);
451 instance->Append(new base::FundamentalValue(42));
452 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
453 JSONSchemaValidator::FormatErrorMessage(
454 JSONSchemaValidator::kInvalidType,
459 void JSONSchemaValidatorTestBase::TestString() {
460 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
461 schema->SetString(schema::kType, schema::kString);
462 schema->SetInteger(schema::kMinLength, 1);
463 schema->SetInteger(schema::kMaxLength, 10);
465 ExpectValid(TEST_SOURCE,
466 scoped_ptr<base::Value>(new base::StringValue("x")).get(),
468 ExpectValid(TEST_SOURCE,
469 scoped_ptr<base::Value>(
470 new base::StringValue("xxxxxxxxxx")).get(),
475 scoped_ptr<base::Value>(new base::StringValue(std::string())).get(),
479 JSONSchemaValidator::FormatErrorMessage(
480 JSONSchemaValidator::kStringMinLength, "1"));
483 scoped_ptr<base::Value>(new base::StringValue("xxxxxxxxxxx")).get(),
487 JSONSchemaValidator::FormatErrorMessage(
488 JSONSchemaValidator::kStringMaxLength, "10"));
491 void JSONSchemaValidatorTestBase::TestNumber() {
492 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
493 schema->SetString(schema::kType, schema::kNumber);
494 schema->SetInteger(schema::kMinimum, 1);
495 schema->SetInteger(schema::kMaximum, 100);
496 schema->SetInteger("maxDecimal", 2);
498 ExpectValid(TEST_SOURCE,
499 scoped_ptr<base::Value>(new base::FundamentalValue(1)).get(),
501 ExpectValid(TEST_SOURCE,
502 scoped_ptr<base::Value>(new base::FundamentalValue(50)).get(),
504 ExpectValid(TEST_SOURCE,
505 scoped_ptr<base::Value>(new base::FundamentalValue(100)).get(),
507 ExpectValid(TEST_SOURCE,
508 scoped_ptr<base::Value>(new base::FundamentalValue(88.88)).get(),
511 ExpectNotValid(TEST_SOURCE,
512 scoped_ptr<base::Value>(new base::FundamentalValue(0.5)).get(),
516 JSONSchemaValidator::FormatErrorMessage(
517 JSONSchemaValidator::kNumberMinimum, "1"));
520 scoped_ptr<base::Value>(new base::FundamentalValue(100.1)).get(),
524 JSONSchemaValidator::FormatErrorMessage(
525 JSONSchemaValidator::kNumberMaximum, "100"));
528 void JSONSchemaValidatorTestBase::TestTypeClassifier() {
529 EXPECT_EQ(std::string(schema::kBoolean),
530 JSONSchemaValidator::GetJSONSchemaType(
531 scoped_ptr<base::Value>(
532 new base::FundamentalValue(true)).get()));
533 EXPECT_EQ(std::string(schema::kBoolean),
534 JSONSchemaValidator::GetJSONSchemaType(
535 scoped_ptr<base::Value>(
536 new base::FundamentalValue(false)).get()));
538 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the
539 // number is integral and within the representable range of integers in
540 // double, it's classified as 'integer'.
541 EXPECT_EQ(std::string(schema::kInteger),
542 JSONSchemaValidator::GetJSONSchemaType(
543 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get()));
544 EXPECT_EQ(std::string(schema::kInteger),
545 JSONSchemaValidator::GetJSONSchemaType(
546 scoped_ptr<base::Value>(new base::FundamentalValue(0)).get()));
547 EXPECT_EQ(std::string(schema::kInteger),
548 JSONSchemaValidator::GetJSONSchemaType(
549 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get()));
550 EXPECT_EQ(std::string(schema::kInteger),
551 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
552 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG))).get()));
553 EXPECT_EQ(std::string(schema::kInteger),
554 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
555 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG))).get()));
557 // "number" is only used for non-integral numbers, or numbers beyond what
558 // double can accurately represent.
559 EXPECT_EQ(std::string(schema::kNumber),
560 JSONSchemaValidator::GetJSONSchemaType(
561 scoped_ptr<base::Value>(
562 new base::FundamentalValue(88.8)).get()));
563 EXPECT_EQ(std::string(schema::kNumber),
564 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
565 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG) * 2)).get()));
566 EXPECT_EQ(std::string(schema::kNumber),
567 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
568 new base::FundamentalValue(
569 pow(-2.0, DBL_MANT_DIG) * 2)).get()));
571 EXPECT_EQ(std::string(schema::kString),
572 JSONSchemaValidator::GetJSONSchemaType(
573 scoped_ptr<base::Value>(new base::StringValue("foo")).get()));
574 EXPECT_EQ(std::string(schema::kArray),
575 JSONSchemaValidator::GetJSONSchemaType(
576 scoped_ptr<base::Value>(new base::ListValue()).get()));
577 EXPECT_EQ(std::string(schema::kObject),
578 JSONSchemaValidator::GetJSONSchemaType(
579 scoped_ptr<base::Value>(new base::DictionaryValue()).get()));
580 EXPECT_EQ(std::string(schema::kNull),
581 JSONSchemaValidator::GetJSONSchemaType(
582 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get()));
585 void JSONSchemaValidatorTestBase::TestTypes() {
586 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
589 schema->SetString(schema::kType, schema::kObject);
590 ExpectValid(TEST_SOURCE,
591 scoped_ptr<base::Value>(new base::DictionaryValue()).get(),
594 schema->SetString(schema::kType, schema::kArray);
595 ExpectValid(TEST_SOURCE, scoped_ptr<base::Value>(new base::ListValue()).get(),
598 schema->SetString(schema::kType, schema::kString);
599 ExpectValid(TEST_SOURCE,
600 scoped_ptr<base::Value>(new base::StringValue("foobar")).get(),
603 schema->SetString(schema::kType, schema::kNumber);
604 ExpectValid(TEST_SOURCE,
605 scoped_ptr<base::Value>(new base::FundamentalValue(88.8)).get(),
607 ExpectValid(TEST_SOURCE,
608 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
610 ExpectValid(TEST_SOURCE,
611 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
613 ExpectValid(TEST_SOURCE,
614 scoped_ptr<base::Value>(new base::FundamentalValue(0)).get(),
617 schema->SetString(schema::kType, schema::kInteger);
618 ExpectValid(TEST_SOURCE,
619 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
621 ExpectValid(TEST_SOURCE,
622 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
624 ExpectValid(TEST_SOURCE,
625 scoped_ptr<base::Value>(new base::FundamentalValue(0)).get(),
627 ExpectValid(TEST_SOURCE,
628 scoped_ptr<base::Value>(
629 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG))).get(),
631 ExpectValid(TEST_SOURCE,
632 scoped_ptr<base::Value>(
633 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG))).get(),
636 schema->SetString(schema::kType, schema::kBoolean);
637 ExpectValid(TEST_SOURCE,
638 scoped_ptr<base::Value>(new base::FundamentalValue(false)).get(),
640 ExpectValid(TEST_SOURCE,
641 scoped_ptr<base::Value>(new base::FundamentalValue(true)).get(),
644 schema->SetString(schema::kType, schema::kNull);
645 ExpectValid(TEST_SOURCE,
646 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
650 schema->SetString(schema::kType, schema::kObject);
653 scoped_ptr<base::Value>(new base::ListValue()).get(),
657 JSONSchemaValidator::FormatErrorMessage(
658 JSONSchemaValidator::kInvalidType, schema::kObject, schema::kArray));
660 schema->SetString(schema::kType, schema::kObject);
663 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
667 JSONSchemaValidator::FormatErrorMessage(
668 JSONSchemaValidator::kInvalidType, schema::kObject, schema::kNull));
670 schema->SetString(schema::kType, schema::kArray);
673 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
677 JSONSchemaValidator::FormatErrorMessage(
678 JSONSchemaValidator::kInvalidType, schema::kArray, schema::kInteger));
680 schema->SetString(schema::kType, schema::kString);
683 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
687 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType,
691 schema->SetString(schema::kType, schema::kNumber);
694 scoped_ptr<base::Value>(new base::StringValue("42")).get(),
698 JSONSchemaValidator::FormatErrorMessage(
699 JSONSchemaValidator::kInvalidType, schema::kNumber, schema::kString));
701 schema->SetString(schema::kType, schema::kInteger);
704 scoped_ptr<base::Value>(new base::FundamentalValue(88.8)).get(),
708 JSONSchemaValidator::kInvalidTypeIntegerNumber);
710 schema->SetString(schema::kType, schema::kBoolean);
713 scoped_ptr<base::Value>(new base::FundamentalValue(1)).get(),
717 JSONSchemaValidator::FormatErrorMessage(JSONSchemaValidator::kInvalidType,
721 schema->SetString(schema::kType, schema::kNull);
724 scoped_ptr<base::Value>(new base::FundamentalValue(false)).get(),
728 JSONSchemaValidator::FormatErrorMessage(
729 JSONSchemaValidator::kInvalidType, schema::kNull, schema::kBoolean));