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

Side by Side Diff: chrome/common/json_schema_validator_unittest_base.cc

Issue 7649006: more changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another typo Created 9 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/common/json_schema_validator_unittest_base.h" 5 #include "chrome/common/json_schema_validator_unittest_base.h"
6 6
7 #include <cfloat> 7 #include <cfloat>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 void JSONSchemaValidatorTestBase::TestStringPattern() { 110 void JSONSchemaValidatorTestBase::TestStringPattern() {
111 // Regex patterns not supported in CPP validator. 111 // Regex patterns not supported in CPP validator.
112 if (type_ == CPP) 112 if (type_ == CPP)
113 return; 113 return;
114 114
115 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 115 scoped_ptr<DictionaryValue> schema(new DictionaryValue());
116 schema->SetString("type", "string"); 116 schema->SetString("type", "string");
117 schema->SetString("pattern", "foo+"); 117 schema->SetString("pattern", "foo+");
118 118
119 ExpectValid(TEST_SOURCE, 119 ExpectValid(TEST_SOURCE,
120 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), 120 scoped_ptr<Value>(base::StringValue::New("foo")).get(),
121 schema.get(), NULL); 121 schema.get(), NULL);
122 ExpectValid(TEST_SOURCE, 122 ExpectValid(TEST_SOURCE,
123 scoped_ptr<Value>(Value::CreateStringValue("foooooo")).get(), 123 scoped_ptr<Value>(base::StringValue::New("foooooo")).get(),
124 schema.get(), NULL); 124 schema.get(), NULL);
125 ExpectNotValid(TEST_SOURCE, 125 ExpectNotValid(TEST_SOURCE,
126 scoped_ptr<Value>(Value::CreateStringValue("bar")).get(), 126 scoped_ptr<Value>(base::StringValue::New("bar")).get(),
127 schema.get(), NULL, "", 127 schema.get(), NULL, "",
128 JSONSchemaValidator::FormatErrorMessage( 128 JSONSchemaValidator::FormatErrorMessage(
129 JSONSchemaValidator::kStringPattern, "foo+")); 129 JSONSchemaValidator::kStringPattern, "foo+"));
130 } 130 }
131 131
132 void JSONSchemaValidatorTestBase::TestEnum() { 132 void JSONSchemaValidatorTestBase::TestEnum() {
133 scoped_ptr<DictionaryValue> schema(LoadDictionary("enum_schema.json")); 133 scoped_ptr<DictionaryValue> schema(LoadDictionary("enum_schema.json"));
134 134
135 ExpectValid(TEST_SOURCE, 135 ExpectValid(TEST_SOURCE,
136 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), 136 scoped_ptr<Value>(base::StringValue::New("foo")).get(),
137 schema.get(), NULL); 137 schema.get(), NULL);
138 ExpectValid(TEST_SOURCE, 138 ExpectValid(TEST_SOURCE,
139 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 139 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
140 schema.get(), NULL); 140 schema.get(), NULL);
141 ExpectValid(TEST_SOURCE, 141 ExpectValid(TEST_SOURCE,
142 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), 142 scoped_ptr<Value>(base::FalseValue()).get(),
143 schema.get(), NULL); 143 schema.get(), NULL);
144 144
145 ExpectNotValid(TEST_SOURCE, 145 ExpectNotValid(TEST_SOURCE,
146 scoped_ptr<Value>(Value::CreateStringValue("42")).get(), 146 scoped_ptr<Value>(base::StringValue::New("42")).get(),
147 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum); 147 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum);
148 ExpectNotValid(TEST_SOURCE, 148 ExpectNotValid(TEST_SOURCE,
149 scoped_ptr<Value>(Value::CreateNullValue()).get(), 149 scoped_ptr<Value>(base::NullValue()).get(),
150 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum); 150 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum);
151 } 151 }
152 152
153 void JSONSchemaValidatorTestBase::TestChoices() { 153 void JSONSchemaValidatorTestBase::TestChoices() {
154 scoped_ptr<DictionaryValue> schema(LoadDictionary("choices_schema.json")); 154 scoped_ptr<DictionaryValue> schema(LoadDictionary("choices_schema.json"));
155 155
156 ExpectValid(TEST_SOURCE, 156 ExpectValid(TEST_SOURCE,
157 scoped_ptr<Value>(Value::CreateNullValue()).get(), 157 scoped_ptr<Value>(base::NullValue()).get(),
158 schema.get(), NULL); 158 schema.get(), NULL);
159 ExpectValid(TEST_SOURCE, 159 ExpectValid(TEST_SOURCE,
160 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 160 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
161 schema.get(), NULL); 161 schema.get(), NULL);
162 162
163 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); 163 scoped_ptr<DictionaryValue> instance(new DictionaryValue());
164 instance->SetString("foo", "bar"); 164 instance->SetString("foo", "bar");
165 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 165 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
166 166
167 ExpectNotValid(TEST_SOURCE, 167 ExpectNotValid(TEST_SOURCE,
168 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), 168 scoped_ptr<Value>(base::StringValue::New("foo")).get(),
169 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); 169 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice);
170 ExpectNotValid(TEST_SOURCE, 170 ExpectNotValid(TEST_SOURCE,
171 scoped_ptr<Value>(new ListValue()).get(), 171 scoped_ptr<Value>(new ListValue()).get(),
172 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); 172 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice);
173 173
174 instance->SetInteger("foo", 42); 174 instance->SetInteger("foo", 42);
175 ExpectNotValid(TEST_SOURCE, instance.get(), 175 ExpectNotValid(TEST_SOURCE, instance.get(),
176 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); 176 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice);
177 } 177 }
178 178
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 DictionaryValue* properties = NULL; 229 DictionaryValue* properties = NULL;
230 DictionaryValue* bar_property = NULL; 230 DictionaryValue* bar_property = NULL;
231 ASSERT_TRUE(schema->GetDictionary("properties", &properties)); 231 ASSERT_TRUE(schema->GetDictionary("properties", &properties));
232 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); 232 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property));
233 233
234 bar_property->SetBoolean("optional", true); 234 bar_property->SetBoolean("optional", true);
235 instance->Remove("extra", NULL); 235 instance->Remove("extra", NULL);
236 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 236 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
237 instance->Remove("bar", NULL); 237 instance->Remove("bar", NULL);
238 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 238 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
239 instance->Set("bar", Value::CreateNullValue()); 239 instance->Set("bar", base::NullValue());
240 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 240 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
241 "bar", JSONSchemaValidator::FormatErrorMessage( 241 "bar", JSONSchemaValidator::FormatErrorMessage(
242 JSONSchemaValidator::kInvalidType, "integer", "null")); 242 JSONSchemaValidator::kInvalidType, "integer", "null"));
243 instance->SetString("bar", "42"); 243 instance->SetString("bar", "42");
244 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 244 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
245 "bar", JSONSchemaValidator::FormatErrorMessage( 245 "bar", JSONSchemaValidator::FormatErrorMessage(
246 JSONSchemaValidator::kInvalidType, "integer", "string")); 246 JSONSchemaValidator::kInvalidType, "integer", "string"));
247 } 247 }
248 248
249 void JSONSchemaValidatorTestBase::TestTypeReference() { 249 void JSONSchemaValidatorTestBase::TestTypeReference() {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 "baz", JSONSchemaValidator::FormatErrorMessage( 303 "baz", JSONSchemaValidator::FormatErrorMessage(
304 JSONSchemaValidator::kUnknownTypeReference, 304 JSONSchemaValidator::kUnknownTypeReference,
305 "NegativeInt")); 305 "NegativeInt"));
306 } 306 }
307 307
308 void JSONSchemaValidatorTestBase::TestArrayTuple() { 308 void JSONSchemaValidatorTestBase::TestArrayTuple() {
309 scoped_ptr<DictionaryValue> schema(LoadDictionary("array_tuple_schema.json")); 309 scoped_ptr<DictionaryValue> schema(LoadDictionary("array_tuple_schema.json"));
310 ASSERT_TRUE(schema.get()); 310 ASSERT_TRUE(schema.get());
311 311
312 scoped_ptr<ListValue> instance(new ListValue()); 312 scoped_ptr<ListValue> instance(new ListValue());
313 instance->Append(Value::CreateStringValue("42")); 313 instance->Append(base::StringValue::New("42"));
314 instance->Append(Value::CreateIntegerValue(42)); 314 instance->Append(base::NumberValue::New(42));
315 315
316 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 316 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
317 317
318 instance->Append(Value::CreateStringValue("anything")); 318 instance->Append(base::StringValue::New("anything"));
319 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", 319 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "",
320 JSONSchemaValidator::FormatErrorMessage( 320 JSONSchemaValidator::FormatErrorMessage(
321 JSONSchemaValidator::kArrayMaxItems, "2")); 321 JSONSchemaValidator::kArrayMaxItems, "2"));
322 322
323 instance->Remove(1, NULL); 323 instance->Remove(1, NULL);
324 instance->Remove(1, NULL); 324 instance->Remove(1, NULL);
325 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", 325 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
326 JSONSchemaValidator::kArrayItemRequired); 326 JSONSchemaValidator::kArrayItemRequired);
327 327
328 instance->Set(0, Value::CreateIntegerValue(42)); 328 instance->Set(0, base::NumberValue::New(42));
329 instance->Append(Value::CreateIntegerValue(42)); 329 instance->Append(base::NumberValue::New(42));
330 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", 330 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
331 JSONSchemaValidator::FormatErrorMessage( 331 JSONSchemaValidator::FormatErrorMessage(
332 JSONSchemaValidator::kInvalidType, "string", "integer")); 332 JSONSchemaValidator::kInvalidType, "string", "integer"));
333 333
334 DictionaryValue* additional_properties = new DictionaryValue(); 334 DictionaryValue* additional_properties = new DictionaryValue();
335 additional_properties->SetString("type", "any"); 335 additional_properties->SetString("type", "any");
336 schema->Set("additionalProperties", additional_properties); 336 schema->Set("additionalProperties", additional_properties);
337 instance->Set(0, Value::CreateStringValue("42")); 337 instance->Set(0, base::StringValue::New("42"));
338 instance->Append(Value::CreateStringValue("anything")); 338 instance->Append(base::StringValue::New("anything"));
339 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 339 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
340 instance->Set(2, new ListValue()); 340 instance->Set(2, new ListValue());
341 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 341 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
342 342
343 additional_properties->SetString("type", "boolean"); 343 additional_properties->SetString("type", "boolean");
344 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", 344 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2",
345 JSONSchemaValidator::FormatErrorMessage( 345 JSONSchemaValidator::FormatErrorMessage(
346 JSONSchemaValidator::kInvalidType, "boolean", "array")); 346 JSONSchemaValidator::kInvalidType, "boolean", "array"));
347 instance->Set(2, Value::CreateBooleanValue(false)); 347 instance->Set(2, base::FalseValue());
348 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 348 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
349 349
350 ListValue* items_schema = NULL; 350 ListValue* items_schema = NULL;
351 DictionaryValue* item0_schema = NULL; 351 DictionaryValue* item0_schema = NULL;
352 ASSERT_TRUE(schema->GetList("items", &items_schema)); 352 ASSERT_TRUE(schema->GetList("items", &items_schema));
353 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); 353 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema));
354 item0_schema->SetBoolean("optional", true); 354 item0_schema->SetBoolean("optional", true);
355 instance->Remove(2, NULL); 355 instance->Remove(2, NULL);
356 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 356 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
357 // TODO(aa): I think this is inconsistent with the handling of NULL+optional 357 // TODO(aa): I think this is inconsistent with the handling of NULL+optional
358 // for objects. 358 // for objects.
359 instance->Set(0, Value::CreateNullValue()); 359 instance->Set(0, base::NullValue());
360 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 360 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
361 instance->Set(0, Value::CreateIntegerValue(42)); 361 instance->Set(0, base::NumberValue::New(42));
362 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", 362 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
363 JSONSchemaValidator::FormatErrorMessage( 363 JSONSchemaValidator::FormatErrorMessage(
364 JSONSchemaValidator::kInvalidType, "string", "integer")); 364 JSONSchemaValidator::kInvalidType, "string", "integer"));
365 } 365 }
366 366
367 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { 367 void JSONSchemaValidatorTestBase::TestArrayNonTuple() {
368 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 368 scoped_ptr<DictionaryValue> schema(new DictionaryValue());
369 schema->SetString("type", "array"); 369 schema->SetString("type", "array");
370 schema->SetString("items.type", "string"); 370 schema->SetString("items.type", "string");
371 schema->SetInteger("minItems", 2); 371 schema->SetInteger("minItems", 2);
372 schema->SetInteger("maxItems", 3); 372 schema->SetInteger("maxItems", 3);
373 373
374 scoped_ptr<ListValue> instance(new ListValue()); 374 scoped_ptr<ListValue> instance(new ListValue());
375 instance->Append(Value::CreateStringValue("x")); 375 instance->Append(base::StringValue::New("x"));
376 instance->Append(Value::CreateStringValue("x")); 376 instance->Append(base::StringValue::New("x"));
377 377
378 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 378 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
379 instance->Append(Value::CreateStringValue("x")); 379 instance->Append(base::StringValue::New("x"));
380 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 380 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
381 381
382 instance->Append(Value::CreateStringValue("x")); 382 instance->Append(base::StringValue::New("x"));
383 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", 383 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "",
384 JSONSchemaValidator::FormatErrorMessage( 384 JSONSchemaValidator::FormatErrorMessage(
385 JSONSchemaValidator::kArrayMaxItems, "3")); 385 JSONSchemaValidator::kArrayMaxItems, "3"));
386 instance->Remove(1, NULL); 386 instance->Remove(1, NULL);
387 instance->Remove(1, NULL); 387 instance->Remove(1, NULL);
388 instance->Remove(1, NULL); 388 instance->Remove(1, NULL);
389 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", 389 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "",
390 JSONSchemaValidator::FormatErrorMessage( 390 JSONSchemaValidator::FormatErrorMessage(
391 JSONSchemaValidator::kArrayMinItems, "2")); 391 JSONSchemaValidator::kArrayMinItems, "2"));
392 392
393 instance->Remove(1, NULL); 393 instance->Remove(1, NULL);
394 instance->Append(Value::CreateIntegerValue(42)); 394 instance->Append(base::NumberValue::New(42));
395 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", 395 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
396 JSONSchemaValidator::FormatErrorMessage( 396 JSONSchemaValidator::FormatErrorMessage(
397 JSONSchemaValidator::kInvalidType, "string", "integer")); 397 JSONSchemaValidator::kInvalidType, "string", "integer"));
398 } 398 }
399 399
400 void JSONSchemaValidatorTestBase::TestString() { 400 void JSONSchemaValidatorTestBase::TestString() {
401 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 401 scoped_ptr<DictionaryValue> schema(new DictionaryValue());
402 schema->SetString("type", "string"); 402 schema->SetString("type", "string");
403 schema->SetInteger("minLength", 1); 403 schema->SetInteger("minLength", 1);
404 schema->SetInteger("maxLength", 10); 404 schema->SetInteger("maxLength", 10);
405 405
406 ExpectValid(TEST_SOURCE, 406 ExpectValid(TEST_SOURCE,
407 scoped_ptr<Value>(Value::CreateStringValue("x")).get(), 407 scoped_ptr<Value>(base::StringValue::New("x")).get(),
408 schema.get(), NULL); 408 schema.get(), NULL);
409 ExpectValid(TEST_SOURCE, 409 ExpectValid(TEST_SOURCE,
410 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxx")).get(), 410 scoped_ptr<Value>(base::StringValue::New("xxxxxxxxxx")).get(),
411 schema.get(), NULL); 411 schema.get(), NULL);
412 412
413 ExpectNotValid(TEST_SOURCE, 413 ExpectNotValid(TEST_SOURCE,
414 scoped_ptr<Value>(Value::CreateStringValue("")).get(), 414 scoped_ptr<Value>(base::StringValue::New("")).get(),
415 schema.get(), NULL, "", 415 schema.get(), NULL, "",
416 JSONSchemaValidator::FormatErrorMessage( 416 JSONSchemaValidator::FormatErrorMessage(
417 JSONSchemaValidator::kStringMinLength, "1")); 417 JSONSchemaValidator::kStringMinLength, "1"));
418 ExpectNotValid( 418 ExpectNotValid(
419 TEST_SOURCE, 419 TEST_SOURCE,
420 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxxx")).get(), 420 scoped_ptr<Value>(base::StringValue::New("xxxxxxxxxxx")).get(),
421 schema.get(), NULL, "", 421 schema.get(), NULL, "",
422 JSONSchemaValidator::FormatErrorMessage( 422 JSONSchemaValidator::FormatErrorMessage(
423 JSONSchemaValidator::kStringMaxLength, "10")); 423 JSONSchemaValidator::kStringMaxLength, "10"));
424 424
425 } 425 }
426 426
427 void JSONSchemaValidatorTestBase::TestNumber() { 427 void JSONSchemaValidatorTestBase::TestNumber() {
428 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 428 scoped_ptr<DictionaryValue> schema(new DictionaryValue());
429 schema->SetString("type", "number"); 429 schema->SetString("type", "number");
430 schema->SetInteger("minimum", 1); 430 schema->SetInteger("minimum", 1);
431 schema->SetInteger("maximum", 100); 431 schema->SetInteger("maximum", 100);
432 schema->SetInteger("maxDecimal", 2); 432 schema->SetInteger("maxDecimal", 2);
433 433
434 ExpectValid(TEST_SOURCE, 434 ExpectValid(TEST_SOURCE,
435 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), 435 scoped_ptr<Value>(base::NumberValue::New(1)).get(),
436 schema.get(), NULL); 436 schema.get(), NULL);
437 ExpectValid(TEST_SOURCE, 437 ExpectValid(TEST_SOURCE,
438 scoped_ptr<Value>(Value::CreateIntegerValue(50)).get(), 438 scoped_ptr<Value>(base::NumberValue::New(50)).get(),
439 schema.get(), NULL); 439 schema.get(), NULL);
440 ExpectValid(TEST_SOURCE, 440 ExpectValid(TEST_SOURCE,
441 scoped_ptr<Value>(Value::CreateIntegerValue(100)).get(), 441 scoped_ptr<Value>(base::NumberValue::New(100)).get(),
442 schema.get(), NULL); 442 schema.get(), NULL);
443 ExpectValid(TEST_SOURCE, 443 ExpectValid(TEST_SOURCE,
444 scoped_ptr<Value>(Value::CreateDoubleValue(88.88)).get(), 444 scoped_ptr<Value>(base::NumberValue::New(88.88)).get(),
445 schema.get(), NULL); 445 schema.get(), NULL);
446 446
447 ExpectNotValid( 447 ExpectNotValid(
448 TEST_SOURCE, 448 TEST_SOURCE,
449 scoped_ptr<Value>(Value::CreateDoubleValue(0.5)).get(), 449 scoped_ptr<Value>(base::NumberValue::New(0.5)).get(),
450 schema.get(), NULL, "", 450 schema.get(), NULL, "",
451 JSONSchemaValidator::FormatErrorMessage( 451 JSONSchemaValidator::FormatErrorMessage(
452 JSONSchemaValidator::kNumberMinimum, "1")); 452 JSONSchemaValidator::kNumberMinimum, "1"));
453 ExpectNotValid( 453 ExpectNotValid(
454 TEST_SOURCE, 454 TEST_SOURCE,
455 scoped_ptr<Value>(Value::CreateDoubleValue(100.1)).get(), 455 scoped_ptr<Value>(base::NumberValue::New(100.1)).get(),
456 schema.get(), NULL, "", 456 schema.get(), NULL, "",
457 JSONSchemaValidator::FormatErrorMessage( 457 JSONSchemaValidator::FormatErrorMessage(
458 JSONSchemaValidator::kNumberMaximum, "100")); 458 JSONSchemaValidator::kNumberMaximum, "100"));
459 } 459 }
460 460
461 void JSONSchemaValidatorTestBase::TestTypeClassifier() { 461 void JSONSchemaValidatorTestBase::TestTypeClassifier() {
462 EXPECT_EQ("boolean", JSONSchemaValidator::GetJSONSchemaType( 462 EXPECT_EQ("boolean", JSONSchemaValidator::GetJSONSchemaType(
463 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get())); 463 scoped_ptr<Value>(base::TrueValue()).get()));
464 EXPECT_EQ("boolean", JSONSchemaValidator::GetJSONSchemaType( 464 EXPECT_EQ("boolean", JSONSchemaValidator::GetJSONSchemaType(
465 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get())); 465 scoped_ptr<Value>(base::FalseValue()).get()));
466 466
467 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the 467 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the
468 // number is integral and within the representable range of integers in 468 // number is integral and within the representable range of integers in
469 // double, it's classified as 'integer'. 469 // double, it's classified as 'integer'.
470 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( 470 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType(
471 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get())); 471 scoped_ptr<Value>(base::NumberValue::New(42)).get()));
472 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( 472 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType(
473 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get())); 473 scoped_ptr<Value>(base::NumberValue::New(0)).get()));
474 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( 474 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType(
475 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get())); 475 scoped_ptr<Value>(base::NumberValue::New(42)).get()));
476 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( 476 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType(
477 scoped_ptr<Value>( 477 scoped_ptr<Value>(
478 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get())); 478 base::NumberValue::New(pow(2.0, DBL_MANT_DIG))).get()));
479 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType( 479 EXPECT_EQ("integer", JSONSchemaValidator::GetJSONSchemaType(
480 scoped_ptr<Value>( 480 scoped_ptr<Value>(
481 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get())); 481 base::NumberValue::New(pow(-2.0, DBL_MANT_DIG))).get()));
482 482
483 // "number" is only used for non-integral numbers, or numbers beyond what 483 // "number" is only used for non-integral numbers, or numbers beyond what
484 // double can accurately represent. 484 // double can accurately represent.
485 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType( 485 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType(
486 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get())); 486 scoped_ptr<Value>(base::NumberValue::New(88.8)).get()));
487 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType( 487 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType(
488 scoped_ptr<Value>(Value::CreateDoubleValue( 488 scoped_ptr<Value>(base::NumberValue::New(
489 pow(2.0, DBL_MANT_DIG) * 2)).get())); 489 pow(2.0, DBL_MANT_DIG) * 2)).get()));
490 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType( 490 EXPECT_EQ("number", JSONSchemaValidator::GetJSONSchemaType(
491 scoped_ptr<Value>(Value::CreateDoubleValue( 491 scoped_ptr<Value>(base::NumberValue::New(
492 pow(-2.0, DBL_MANT_DIG) * 2)).get())); 492 pow(-2.0, DBL_MANT_DIG) * 2)).get()));
493 493
494 EXPECT_EQ("string", JSONSchemaValidator::GetJSONSchemaType( 494 EXPECT_EQ("string", JSONSchemaValidator::GetJSONSchemaType(
495 scoped_ptr<Value>(Value::CreateStringValue("foo")).get())); 495 scoped_ptr<Value>(base::StringValue::New("foo")).get()));
496 EXPECT_EQ("array", JSONSchemaValidator::GetJSONSchemaType( 496 EXPECT_EQ("array", JSONSchemaValidator::GetJSONSchemaType(
497 scoped_ptr<Value>(new ListValue()).get())); 497 scoped_ptr<Value>(new ListValue()).get()));
498 EXPECT_EQ("object", JSONSchemaValidator::GetJSONSchemaType( 498 EXPECT_EQ("object", JSONSchemaValidator::GetJSONSchemaType(
499 scoped_ptr<Value>(new DictionaryValue()).get())); 499 scoped_ptr<Value>(new DictionaryValue()).get()));
500 EXPECT_EQ("null", JSONSchemaValidator::GetJSONSchemaType( 500 EXPECT_EQ("null", JSONSchemaValidator::GetJSONSchemaType(
501 scoped_ptr<Value>(Value::CreateNullValue()).get())); 501 scoped_ptr<Value>(base::NullValue()).get()));
502 } 502 }
503 503
504 void JSONSchemaValidatorTestBase::TestTypes() { 504 void JSONSchemaValidatorTestBase::TestTypes() {
505 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 505 scoped_ptr<DictionaryValue> schema(new DictionaryValue());
506 506
507 // valid 507 // valid
508 schema->SetString("type", "object"); 508 schema->SetString("type", "object");
509 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new DictionaryValue()).get(), 509 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new DictionaryValue()).get(),
510 schema.get(), NULL); 510 schema.get(), NULL);
511 511
512 schema->SetString("type", "array"); 512 schema->SetString("type", "array");
513 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), 513 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(),
514 schema.get(), NULL); 514 schema.get(), NULL);
515 515
516 schema->SetString("type", "string"); 516 schema->SetString("type", "string");
517 ExpectValid(TEST_SOURCE, 517 ExpectValid(TEST_SOURCE,
518 scoped_ptr<Value>(Value::CreateStringValue("foobar")).get(), 518 scoped_ptr<Value>(base::StringValue::New("foobar")).get(),
519 schema.get(), NULL); 519 schema.get(), NULL);
520 520
521 schema->SetString("type", "number"); 521 schema->SetString("type", "number");
522 ExpectValid(TEST_SOURCE, 522 ExpectValid(TEST_SOURCE,
523 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), 523 scoped_ptr<Value>(base::NumberValue::New(88.8)).get(),
524 schema.get(), NULL); 524 schema.get(), NULL);
525 ExpectValid(TEST_SOURCE, 525 ExpectValid(TEST_SOURCE,
526 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), 526 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
527 schema.get(), NULL); 527 schema.get(), NULL);
528 ExpectValid(TEST_SOURCE, 528 ExpectValid(TEST_SOURCE,
529 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 529 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
530 schema.get(), NULL); 530 schema.get(), NULL);
531 ExpectValid(TEST_SOURCE, 531 ExpectValid(TEST_SOURCE,
532 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), 532 scoped_ptr<Value>(base::NumberValue::New(0)).get(),
533 schema.get(), NULL); 533 schema.get(), NULL);
534 534
535 schema->SetString("type", "integer"); 535 schema->SetString("type", "integer");
536 ExpectValid(TEST_SOURCE, 536 ExpectValid(TEST_SOURCE,
537 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 537 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
538 schema.get(), NULL); 538 schema.get(), NULL);
539 ExpectValid(TEST_SOURCE, 539 ExpectValid(TEST_SOURCE,
540 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), 540 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
541 schema.get(), NULL); 541 schema.get(), NULL);
542 ExpectValid(TEST_SOURCE, 542 ExpectValid(TEST_SOURCE,
543 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), 543 scoped_ptr<Value>(base::NumberValue::New(0)).get(),
544 schema.get(), NULL); 544 schema.get(), NULL);
545 ExpectValid(TEST_SOURCE, 545 ExpectValid(TEST_SOURCE,
546 scoped_ptr<Value>( 546 scoped_ptr<Value>(
547 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get(), 547 base::NumberValue::New(pow(2.0, DBL_MANT_DIG))).get(),
548 schema.get(), NULL); 548 schema.get(), NULL);
549 ExpectValid(TEST_SOURCE, 549 ExpectValid(TEST_SOURCE,
550 scoped_ptr<Value>( 550 scoped_ptr<Value>(
551 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get(), 551 base::NumberValue::New(pow(-2.0, DBL_MANT_DIG))).get(),
552 schema.get(), NULL); 552 schema.get(), NULL);
553 553
554 schema->SetString("type", "boolean"); 554 schema->SetString("type", "boolean");
555 ExpectValid(TEST_SOURCE, 555 ExpectValid(TEST_SOURCE,
556 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), 556 scoped_ptr<Value>(base::FalseValue()).get(),
557 schema.get(), NULL); 557 schema.get(), NULL);
558 ExpectValid(TEST_SOURCE, 558 ExpectValid(TEST_SOURCE,
559 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get(), 559 scoped_ptr<Value>(base::TrueValue()).get(),
560 schema.get(), NULL); 560 schema.get(), NULL);
561 561
562 schema->SetString("type", "null"); 562 schema->SetString("type", "null");
563 ExpectValid(TEST_SOURCE, 563 ExpectValid(TEST_SOURCE,
564 scoped_ptr<Value>(Value::CreateNullValue()).get(), 564 scoped_ptr<Value>(base::NullValue()).get(),
565 schema.get(), NULL); 565 schema.get(), NULL);
566 566
567 // not valid 567 // not valid
568 schema->SetString("type", "object"); 568 schema->SetString("type", "object");
569 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), 569 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(),
570 schema.get(), NULL, "", 570 schema.get(), NULL, "",
571 JSONSchemaValidator::FormatErrorMessage( 571 JSONSchemaValidator::FormatErrorMessage(
572 JSONSchemaValidator::kInvalidType, "object", "array")); 572 JSONSchemaValidator::kInvalidType, "object", "array"));
573 573
574 schema->SetString("type", "object"); 574 schema->SetString("type", "object");
575 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(Value::CreateNullValue()).get(), 575 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(base::NullValue()).get(),
576 schema.get(), NULL, "", 576 schema.get(), NULL, "",
577 JSONSchemaValidator::FormatErrorMessage( 577 JSONSchemaValidator::FormatErrorMessage(
578 JSONSchemaValidator::kInvalidType, "object", "null")); 578 JSONSchemaValidator::kInvalidType, "object", "null"));
579 579
580 schema->SetString("type", "array"); 580 schema->SetString("type", "array");
581 ExpectNotValid(TEST_SOURCE, 581 ExpectNotValid(TEST_SOURCE,
582 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 582 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
583 schema.get(), NULL, "", 583 schema.get(), NULL, "",
584 JSONSchemaValidator::FormatErrorMessage( 584 JSONSchemaValidator::FormatErrorMessage(
585 JSONSchemaValidator::kInvalidType, "array", "integer")); 585 JSONSchemaValidator::kInvalidType, "array", "integer"));
586 586
587 schema->SetString("type", "string"); 587 schema->SetString("type", "string");
588 ExpectNotValid(TEST_SOURCE, 588 ExpectNotValid(TEST_SOURCE,
589 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 589 scoped_ptr<Value>(base::NumberValue::New(42)).get(),
590 schema.get(), NULL, "", 590 schema.get(), NULL, "",
591 JSONSchemaValidator::FormatErrorMessage( 591 JSONSchemaValidator::FormatErrorMessage(
592 JSONSchemaValidator::kInvalidType, "string", "integer")); 592 JSONSchemaValidator::kInvalidType, "string", "integer"));
593 593
594 schema->SetString("type", "number"); 594 schema->SetString("type", "number");
595 ExpectNotValid(TEST_SOURCE, 595 ExpectNotValid(TEST_SOURCE,
596 scoped_ptr<Value>(Value::CreateStringValue("42")).get(), 596 scoped_ptr<Value>(base::StringValue::New("42")).get(),
597 schema.get(), NULL, "", 597 schema.get(), NULL, "",
598 JSONSchemaValidator::FormatErrorMessage( 598 JSONSchemaValidator::FormatErrorMessage(
599 JSONSchemaValidator::kInvalidType, "number", "string")); 599 JSONSchemaValidator::kInvalidType, "number", "string"));
600 600
601 schema->SetString("type", "integer"); 601 schema->SetString("type", "integer");
602 ExpectNotValid(TEST_SOURCE, 602 ExpectNotValid(TEST_SOURCE,
603 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), 603 scoped_ptr<Value>(base::NumberValue::New(88.8)).get(),
604 schema.get(), NULL, "", 604 schema.get(), NULL, "",
605 JSONSchemaValidator::FormatErrorMessage( 605 JSONSchemaValidator::FormatErrorMessage(
606 JSONSchemaValidator::kInvalidType, "integer", "number")); 606 JSONSchemaValidator::kInvalidType, "integer", "number"));
607 607
608 schema->SetString("type", "integer"); 608 schema->SetString("type", "integer");
609 ExpectNotValid(TEST_SOURCE, 609 ExpectNotValid(TEST_SOURCE,
610 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), 610 scoped_ptr<Value>(base::NumberValue::New(88.8)).get(),
611 schema.get(), NULL, "", 611 schema.get(), NULL, "",
612 JSONSchemaValidator::FormatErrorMessage( 612 JSONSchemaValidator::FormatErrorMessage(
613 JSONSchemaValidator::kInvalidType, "integer", "number")); 613 JSONSchemaValidator::kInvalidType, "integer", "number"));
614 614
615 schema->SetString("type", "boolean"); 615 schema->SetString("type", "boolean");
616 ExpectNotValid(TEST_SOURCE, 616 ExpectNotValid(TEST_SOURCE,
617 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), 617 scoped_ptr<Value>(base::NumberValue::New(1)).get(),
618 schema.get(), NULL, "", 618 schema.get(), NULL, "",
619 JSONSchemaValidator::FormatErrorMessage( 619 JSONSchemaValidator::FormatErrorMessage(
620 JSONSchemaValidator::kInvalidType, "boolean", "integer")); 620 JSONSchemaValidator::kInvalidType, "boolean", "integer"));
621 621
622 schema->SetString("type", "null"); 622 schema->SetString("type", "null");
623 ExpectNotValid(TEST_SOURCE, 623 ExpectNotValid(TEST_SOURCE,
624 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), 624 scoped_ptr<Value>(base::FalseValue()).get(),
625 schema.get(), NULL, "", 625 schema.get(), NULL, "",
626 JSONSchemaValidator::FormatErrorMessage( 626 JSONSchemaValidator::FormatErrorMessage(
627 JSONSchemaValidator::kInvalidType, "null", "boolean")); 627 JSONSchemaValidator::kInvalidType, "null", "boolean"));
628 } 628 }
OLDNEW
« no previous file with comments | « chrome/common/json_schema_validator.h ('k') | chrome/renderer/automation/dom_automation_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698