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

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

Issue 12207167: Cleanup: Remove deprecated base::Value methods from chrome/common. Use base::Value too. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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
« no previous file with comments | « chrome/common/extensions/value_builder.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/json/json_file_value_serializer.h" 12 #include "base/json/json_file_value_serializer.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
17 #include "base/values.h" 17 #include "base/values.h"
18 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "chrome/common/json_schema_constants.h" 19 #include "chrome/common/json_schema_constants.h"
20 #include "chrome/common/json_schema_validator.h" 20 #include "chrome/common/json_schema_validator.h"
21 21
22 namespace schema = json_schema_constants; 22 namespace schema = json_schema_constants;
23 23
24 namespace { 24 namespace {
25 25
26 #define TEST_SOURCE base::StringPrintf("%s:%i", __FILE__, __LINE__) 26 #define TEST_SOURCE base::StringPrintf("%s:%i", __FILE__, __LINE__)
27 27
28 Value* LoadValue(const std::string& filename) { 28 base::Value* LoadValue(const std::string& filename) {
29 base::FilePath path; 29 base::FilePath path;
30 PathService::Get(chrome::DIR_TEST_DATA, &path); 30 PathService::Get(chrome::DIR_TEST_DATA, &path);
31 path = path.AppendASCII("json_schema_validator").AppendASCII(filename); 31 path = path.AppendASCII("json_schema_validator").AppendASCII(filename);
32 EXPECT_TRUE(file_util::PathExists(path)); 32 EXPECT_TRUE(file_util::PathExists(path));
33 33
34 std::string error_message; 34 std::string error_message;
35 JSONFileValueSerializer serializer(path); 35 JSONFileValueSerializer serializer(path);
36 Value* result = serializer.Deserialize(NULL, &error_message); 36 base::Value* result = serializer.Deserialize(NULL, &error_message);
37 if (!result) 37 if (!result)
38 ADD_FAILURE() << "Could not parse JSON: " << error_message; 38 ADD_FAILURE() << "Could not parse JSON: " << error_message;
39 return result; 39 return result;
40 } 40 }
41 41
42 Value* LoadValue(const std::string& filename, base::Value::Type type) { 42 base::Value* LoadValue(const std::string& filename, base::Value::Type type) {
43 scoped_ptr<Value> result(LoadValue(filename)); 43 scoped_ptr<base::Value> result(LoadValue(filename));
44 if (!result.get()) 44 if (!result.get())
45 return NULL; 45 return NULL;
46 if (!result->IsType(type)) { 46 if (!result->IsType(type)) {
47 ADD_FAILURE() << "Expected type " << type << ", got: " << result->GetType(); 47 ADD_FAILURE() << "Expected type " << type << ", got: " << result->GetType();
48 return NULL; 48 return NULL;
49 } 49 }
50 return result.release(); 50 return result.release();
51 } 51 }
52 52
53 ListValue* LoadList(const std::string& filename) { 53 base::ListValue* LoadList(const std::string& filename) {
54 return static_cast<ListValue*>( 54 return static_cast<base::ListValue*>(
55 LoadValue(filename, Value::TYPE_LIST)); 55 LoadValue(filename, base::Value::TYPE_LIST));
56 } 56 }
57 57
58 DictionaryValue* LoadDictionary(const std::string& filename) { 58 base::DictionaryValue* LoadDictionary(const std::string& filename) {
59 return static_cast<DictionaryValue*>( 59 return static_cast<base::DictionaryValue*>(
60 LoadValue(filename, Value::TYPE_DICTIONARY)); 60 LoadValue(filename, base::Value::TYPE_DICTIONARY));
61 } 61 }
62 62
63 } // namespace 63 } // namespace
64 64
65 65
66 JSONSchemaValidatorTestBase::JSONSchemaValidatorTestBase( 66 JSONSchemaValidatorTestBase::JSONSchemaValidatorTestBase(
67 JSONSchemaValidatorTestBase::ValidatorType type) 67 JSONSchemaValidatorTestBase::ValidatorType type)
68 : type_(type) { 68 : type_(type) {
69 } 69 }
70 70
71 void JSONSchemaValidatorTestBase::RunTests() { 71 void JSONSchemaValidatorTestBase::RunTests() {
72 TestComplex(); 72 TestComplex();
73 TestStringPattern(); 73 TestStringPattern();
74 TestEnum(); 74 TestEnum();
75 TestChoices(); 75 TestChoices();
76 TestExtends(); 76 TestExtends();
77 TestObject(); 77 TestObject();
78 TestTypeReference(); 78 TestTypeReference();
79 TestArrayTuple(); 79 TestArrayTuple();
80 TestArrayNonTuple(); 80 TestArrayNonTuple();
81 TestString(); 81 TestString();
82 TestNumber(); 82 TestNumber();
83 TestTypeClassifier(); 83 TestTypeClassifier();
84 TestTypes(); 84 TestTypes();
85 } 85 }
86 86
87 void JSONSchemaValidatorTestBase::TestComplex() { 87 void JSONSchemaValidatorTestBase::TestComplex() {
88 scoped_ptr<DictionaryValue> schema(LoadDictionary("complex_schema.json")); 88 scoped_ptr<base::DictionaryValue> schema(
89 scoped_ptr<ListValue> instance(LoadList("complex_instance.json")); 89 LoadDictionary("complex_schema.json"));
90 scoped_ptr<base::ListValue> instance(LoadList("complex_instance.json"));
90 91
91 ASSERT_TRUE(schema.get()); 92 ASSERT_TRUE(schema.get());
92 ASSERT_TRUE(instance.get()); 93 ASSERT_TRUE(instance.get());
93 94
94 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 95 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
95 instance->Remove(instance->GetSize() - 1, NULL); 96 instance->Remove(instance->GetSize() - 1, NULL);
96 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 97 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
97 instance->Append(new DictionaryValue()); 98 instance->Append(new base::DictionaryValue());
98 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", 99 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
99 JSONSchemaValidator::FormatErrorMessage( 100 JSONSchemaValidator::FormatErrorMessage(
100 JSONSchemaValidator::kInvalidType, 101 JSONSchemaValidator::kInvalidType,
101 schema::kNumber, 102 schema::kNumber,
102 schema::kObject)); 103 schema::kObject));
103 instance->Remove(instance->GetSize() - 1, NULL); 104 instance->Remove(instance->GetSize() - 1, NULL);
104 105
105 DictionaryValue* item = NULL; 106 base::DictionaryValue* item = NULL;
106 ASSERT_TRUE(instance->GetDictionary(0, &item)); 107 ASSERT_TRUE(instance->GetDictionary(0, &item));
107 item->SetString("url", "xxxxxxxxxxx"); 108 item->SetString("url", "xxxxxxxxxxx");
108 109
109 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 110 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
110 "0.url", 111 "0.url",
111 JSONSchemaValidator::FormatErrorMessage( 112 JSONSchemaValidator::FormatErrorMessage(
112 JSONSchemaValidator::kStringMaxLength, "10")); 113 JSONSchemaValidator::kStringMaxLength, "10"));
113 } 114 }
114 115
115 void JSONSchemaValidatorTestBase::TestStringPattern() { 116 void JSONSchemaValidatorTestBase::TestStringPattern() {
116 // Regex patterns not supported in CPP validator. 117 // Regex patterns not supported in CPP validator.
117 if (type_ == CPP) 118 if (type_ == CPP)
118 return; 119 return;
119 120
120 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 121 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
121 schema->SetString(schema::kType, schema::kString); 122 schema->SetString(schema::kType, schema::kString);
122 schema->SetString(schema::kPattern, "foo+"); 123 schema->SetString(schema::kPattern, "foo+");
123 124
124 ExpectValid(TEST_SOURCE, 125 ExpectValid(TEST_SOURCE,
125 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), 126 scoped_ptr<base::Value>(new base::StringValue("foo")).get(),
126 schema.get(), NULL); 127 schema.get(), NULL);
127 ExpectValid(TEST_SOURCE, 128 ExpectValid(TEST_SOURCE,
128 scoped_ptr<Value>(Value::CreateStringValue("foooooo")).get(), 129 scoped_ptr<base::Value>(new base::StringValue("foooooo")).get(),
129 schema.get(), NULL); 130 schema.get(), NULL);
130 ExpectNotValid(TEST_SOURCE, 131 ExpectNotValid(TEST_SOURCE,
131 scoped_ptr<Value>(Value::CreateStringValue("bar")).get(), 132 scoped_ptr<base::Value>(new base::StringValue("bar")).get(),
132 schema.get(), NULL, "", 133 schema.get(), NULL, "",
133 JSONSchemaValidator::FormatErrorMessage( 134 JSONSchemaValidator::FormatErrorMessage(
134 JSONSchemaValidator::kStringPattern, "foo+")); 135 JSONSchemaValidator::kStringPattern, "foo+"));
135 } 136 }
136 137
137 void JSONSchemaValidatorTestBase::TestEnum() { 138 void JSONSchemaValidatorTestBase::TestEnum() {
138 scoped_ptr<DictionaryValue> schema(LoadDictionary("enum_schema.json")); 139 scoped_ptr<base::DictionaryValue> schema(LoadDictionary("enum_schema.json"));
139 140
140 ExpectValid(TEST_SOURCE, 141 ExpectValid(TEST_SOURCE,
141 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), 142 scoped_ptr<base::Value>(new base::StringValue("foo")).get(),
142 schema.get(), NULL); 143 schema.get(), NULL);
143 ExpectValid(TEST_SOURCE, 144 ExpectValid(TEST_SOURCE,
144 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 145 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
145 schema.get(), NULL); 146 schema.get(), NULL);
146 ExpectValid(TEST_SOURCE, 147 ExpectValid(TEST_SOURCE,
147 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), 148 scoped_ptr<base::Value>(new base::FundamentalValue(false)).get(),
148 schema.get(), NULL); 149 schema.get(), NULL);
149 150
150 ExpectNotValid(TEST_SOURCE, 151 ExpectNotValid(TEST_SOURCE,
151 scoped_ptr<Value>(Value::CreateStringValue("42")).get(), 152 scoped_ptr<base::Value>(new base::StringValue("42")).get(),
152 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum); 153 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum);
153 ExpectNotValid(TEST_SOURCE, 154 ExpectNotValid(TEST_SOURCE,
154 scoped_ptr<Value>(Value::CreateNullValue()).get(), 155 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
155 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum); 156 schema.get(), NULL, "", JSONSchemaValidator::kInvalidEnum);
156 } 157 }
157 158
158 void JSONSchemaValidatorTestBase::TestChoices() { 159 void JSONSchemaValidatorTestBase::TestChoices() {
159 scoped_ptr<DictionaryValue> schema(LoadDictionary("choices_schema.json")); 160 scoped_ptr<base::DictionaryValue> schema(
161 LoadDictionary("choices_schema.json"));
160 162
161 ExpectValid(TEST_SOURCE, 163 ExpectValid(TEST_SOURCE,
162 scoped_ptr<Value>(Value::CreateNullValue()).get(), 164 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
163 schema.get(), NULL); 165 schema.get(), NULL);
164 ExpectValid(TEST_SOURCE, 166 ExpectValid(TEST_SOURCE,
165 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 167 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
166 schema.get(), NULL); 168 schema.get(), NULL);
167 169
168 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); 170 scoped_ptr<base::DictionaryValue> instance(new base::DictionaryValue());
169 instance->SetString("foo", "bar"); 171 instance->SetString("foo", "bar");
170 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 172 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
171 173
172 ExpectNotValid(TEST_SOURCE, 174 ExpectNotValid(TEST_SOURCE,
173 scoped_ptr<Value>(Value::CreateStringValue("foo")).get(), 175 scoped_ptr<base::Value>(new base::StringValue("foo")).get(),
174 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); 176 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice);
175 ExpectNotValid(TEST_SOURCE, 177 ExpectNotValid(TEST_SOURCE,
176 scoped_ptr<Value>(new ListValue()).get(), 178 scoped_ptr<base::Value>(new base::ListValue()).get(),
177 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); 179 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice);
178 180
179 instance->SetInteger("foo", 42); 181 instance->SetInteger("foo", 42);
180 ExpectNotValid(TEST_SOURCE, instance.get(), 182 ExpectNotValid(TEST_SOURCE, instance.get(),
181 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice); 183 schema.get(), NULL, "", JSONSchemaValidator::kInvalidChoice);
182 } 184 }
183 185
184 void JSONSchemaValidatorTestBase::TestExtends() { 186 void JSONSchemaValidatorTestBase::TestExtends() {
185 // TODO(aa): JS only 187 // TODO(aa): JS only
186 } 188 }
187 189
188 void JSONSchemaValidatorTestBase::TestObject() { 190 void JSONSchemaValidatorTestBase::TestObject() {
189 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 191 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
190 schema->SetString(schema::kType, schema::kObject); 192 schema->SetString(schema::kType, schema::kObject);
191 schema->SetString("properties.foo.type", schema::kString); 193 schema->SetString("properties.foo.type", schema::kString);
192 schema->SetString("properties.bar.type", schema::kInteger); 194 schema->SetString("properties.bar.type", schema::kInteger);
193 195
194 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); 196 scoped_ptr<base::DictionaryValue> instance(new base::DictionaryValue());
195 instance->SetString("foo", "foo"); 197 instance->SetString("foo", "foo");
196 instance->SetInteger("bar", 42); 198 instance->SetInteger("bar", 42);
197 199
198 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 200 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
199 201
200 instance->SetBoolean("extra", true); 202 instance->SetBoolean("extra", true);
201 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 203 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
202 "extra", JSONSchemaValidator::kUnexpectedProperty); 204 "extra", JSONSchemaValidator::kUnexpectedProperty);
203 205
204 instance->Remove("extra", NULL); 206 instance->Remove("extra", NULL);
205 instance->Remove("bar", NULL); 207 instance->Remove("bar", NULL);
206 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", 208 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar",
207 JSONSchemaValidator::kObjectPropertyIsRequired); 209 JSONSchemaValidator::kObjectPropertyIsRequired);
208 210
209 instance->SetString("bar", "42"); 211 instance->SetString("bar", "42");
210 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar", 212 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "bar",
211 JSONSchemaValidator::FormatErrorMessage( 213 JSONSchemaValidator::FormatErrorMessage(
212 JSONSchemaValidator::kInvalidType, 214 JSONSchemaValidator::kInvalidType,
213 schema::kInteger, 215 schema::kInteger,
214 schema::kString)); 216 schema::kString));
215 217
216 DictionaryValue* additional_properties = new DictionaryValue(); 218 base::DictionaryValue* additional_properties = new base::DictionaryValue();
217 additional_properties->SetString(schema::kType, schema::kAny); 219 additional_properties->SetString(schema::kType, schema::kAny);
218 schema->Set(schema::kAdditionalProperties, additional_properties); 220 schema->Set(schema::kAdditionalProperties, additional_properties);
219 221
220 instance->SetInteger("bar", 42); 222 instance->SetInteger("bar", 42);
221 instance->SetBoolean("extra", true); 223 instance->SetBoolean("extra", true);
222 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 224 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
223 225
224 instance->SetString("extra", "foo"); 226 instance->SetString("extra", "foo");
225 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 227 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
226 228
227 additional_properties->SetString(schema::kType, schema::kBoolean); 229 additional_properties->SetString(schema::kType, schema::kBoolean);
228 instance->SetBoolean("extra", true); 230 instance->SetBoolean("extra", true);
229 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 231 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
230 232
231 instance->SetString("extra", "foo"); 233 instance->SetString("extra", "foo");
232 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 234 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
233 "extra", JSONSchemaValidator::FormatErrorMessage( 235 "extra", JSONSchemaValidator::FormatErrorMessage(
234 JSONSchemaValidator::kInvalidType, 236 JSONSchemaValidator::kInvalidType,
235 schema::kBoolean, 237 schema::kBoolean,
236 schema::kString)); 238 schema::kString));
237 239
238 DictionaryValue* properties = NULL; 240 base::DictionaryValue* properties = NULL;
239 DictionaryValue* bar_property = NULL; 241 base::DictionaryValue* bar_property = NULL;
240 ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties)); 242 ASSERT_TRUE(schema->GetDictionary(schema::kProperties, &properties));
241 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property)); 243 ASSERT_TRUE(properties->GetDictionary("bar", &bar_property));
242 244
243 bar_property->SetBoolean(schema::kOptional, true); 245 bar_property->SetBoolean(schema::kOptional, true);
244 instance->Remove("extra", NULL); 246 instance->Remove("extra", NULL);
245 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 247 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
246 instance->Remove("bar", NULL); 248 instance->Remove("bar", NULL);
247 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 249 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
248 instance->Set("bar", Value::CreateNullValue()); 250 instance->Set("bar", base::Value::CreateNullValue());
249 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 251 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
250 "bar", JSONSchemaValidator::FormatErrorMessage( 252 "bar", JSONSchemaValidator::FormatErrorMessage(
251 JSONSchemaValidator::kInvalidType, 253 JSONSchemaValidator::kInvalidType,
252 schema::kInteger, 254 schema::kInteger,
253 schema::kNull)); 255 schema::kNull));
254 instance->SetString("bar", "42"); 256 instance->SetString("bar", "42");
255 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, 257 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL,
256 "bar", JSONSchemaValidator::FormatErrorMessage( 258 "bar", JSONSchemaValidator::FormatErrorMessage(
257 JSONSchemaValidator::kInvalidType, 259 JSONSchemaValidator::kInvalidType,
258 schema::kInteger, 260 schema::kInteger,
259 schema::kString)); 261 schema::kString));
260 } 262 }
261 263
262 void JSONSchemaValidatorTestBase::TestTypeReference() { 264 void JSONSchemaValidatorTestBase::TestTypeReference() {
263 scoped_ptr<ListValue> types(LoadList("reference_types.json")); 265 scoped_ptr<base::ListValue> types(LoadList("reference_types.json"));
264 ASSERT_TRUE(types.get()); 266 ASSERT_TRUE(types.get());
265 267
266 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 268 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
267 schema->SetString(schema::kType, schema::kObject); 269 schema->SetString(schema::kType, schema::kObject);
268 schema->SetString("properties.foo.type", schema::kString); 270 schema->SetString("properties.foo.type", schema::kString);
269 schema->SetString("properties.bar.$ref", "Max10Int"); 271 schema->SetString("properties.bar.$ref", "Max10Int");
270 schema->SetString("properties.baz.$ref", "MinLengthString"); 272 schema->SetString("properties.baz.$ref", "MinLengthString");
271 273
272 scoped_ptr<DictionaryValue> schema_inline(new DictionaryValue()); 274 scoped_ptr<base::DictionaryValue> schema_inline(new base::DictionaryValue());
273 schema_inline->SetString(schema::kType, schema::kObject); 275 schema_inline->SetString(schema::kType, schema::kObject);
274 schema_inline->SetString("properties.foo.type", schema::kString); 276 schema_inline->SetString("properties.foo.type", schema::kString);
275 schema_inline->SetString("properties.bar.id", "NegativeInt"); 277 schema_inline->SetString("properties.bar.id", "NegativeInt");
276 schema_inline->SetString("properties.bar.type", schema::kInteger); 278 schema_inline->SetString("properties.bar.type", schema::kInteger);
277 schema_inline->SetInteger("properties.bar.maximum", 0); 279 schema_inline->SetInteger("properties.bar.maximum", 0);
278 schema_inline->SetString("properties.baz.$ref", "NegativeInt"); 280 schema_inline->SetString("properties.baz.$ref", "NegativeInt");
279 281
280 scoped_ptr<DictionaryValue> instance(new DictionaryValue()); 282 scoped_ptr<base::DictionaryValue> instance(new base::DictionaryValue());
281 instance->SetString("foo", "foo"); 283 instance->SetString("foo", "foo");
282 instance->SetInteger("bar", 4); 284 instance->SetInteger("bar", 4);
283 instance->SetString("baz", "ab"); 285 instance->SetString("baz", "ab");
284 286
285 scoped_ptr<DictionaryValue> instance_inline(new DictionaryValue()); 287 scoped_ptr<base::DictionaryValue> instance_inline(
288 new base::DictionaryValue());
286 instance_inline->SetString("foo", "foo"); 289 instance_inline->SetString("foo", "foo");
287 instance_inline->SetInteger("bar", -4); 290 instance_inline->SetInteger("bar", -4);
288 instance_inline->SetInteger("baz", -2); 291 instance_inline->SetInteger("baz", -2);
289 292
290 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), types.get()); 293 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), types.get());
291 ExpectValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL); 294 ExpectValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL);
292 295
293 // Validation failure, but successful schema reference. 296 // Validation failure, but successful schema reference.
294 instance->SetString("baz", "a"); 297 instance->SetString("baz", "a");
295 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), types.get(), 298 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), types.get(),
(...skipping 16 matching lines...) Expand all
312 // Remove internal type "NegativeInt". 315 // Remove internal type "NegativeInt".
313 schema_inline->Remove("properties.bar", NULL); 316 schema_inline->Remove("properties.bar", NULL);
314 instance_inline->Remove("bar", NULL); 317 instance_inline->Remove("bar", NULL);
315 ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL, 318 ExpectNotValid(TEST_SOURCE, instance_inline.get(), schema_inline.get(), NULL,
316 "baz", JSONSchemaValidator::FormatErrorMessage( 319 "baz", JSONSchemaValidator::FormatErrorMessage(
317 JSONSchemaValidator::kUnknownTypeReference, 320 JSONSchemaValidator::kUnknownTypeReference,
318 "NegativeInt")); 321 "NegativeInt"));
319 } 322 }
320 323
321 void JSONSchemaValidatorTestBase::TestArrayTuple() { 324 void JSONSchemaValidatorTestBase::TestArrayTuple() {
322 scoped_ptr<DictionaryValue> schema(LoadDictionary("array_tuple_schema.json")); 325 scoped_ptr<base::DictionaryValue> schema(
326 LoadDictionary("array_tuple_schema.json"));
323 ASSERT_TRUE(schema.get()); 327 ASSERT_TRUE(schema.get());
324 328
325 scoped_ptr<ListValue> instance(new ListValue()); 329 scoped_ptr<base::ListValue> instance(new base::ListValue());
326 instance->Append(Value::CreateStringValue("42")); 330 instance->Append(new base::StringValue("42"));
327 instance->Append(Value::CreateIntegerValue(42)); 331 instance->Append(new base::FundamentalValue(42));
328 332
329 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 333 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
330 334
331 instance->Append(Value::CreateStringValue("anything")); 335 instance->Append(new base::StringValue("anything"));
332 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", 336 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "",
333 JSONSchemaValidator::FormatErrorMessage( 337 JSONSchemaValidator::FormatErrorMessage(
334 JSONSchemaValidator::kArrayMaxItems, "2")); 338 JSONSchemaValidator::kArrayMaxItems, "2"));
335 339
336 instance->Remove(1, NULL); 340 instance->Remove(1, NULL);
337 instance->Remove(1, NULL); 341 instance->Remove(1, NULL);
338 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", 342 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
339 JSONSchemaValidator::kArrayItemRequired); 343 JSONSchemaValidator::kArrayItemRequired);
340 344
341 instance->Set(0, Value::CreateIntegerValue(42)); 345 instance->Set(0, new base::FundamentalValue(42));
342 instance->Append(Value::CreateIntegerValue(42)); 346 instance->Append(new base::FundamentalValue(42));
343 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", 347 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
344 JSONSchemaValidator::FormatErrorMessage( 348 JSONSchemaValidator::FormatErrorMessage(
345 JSONSchemaValidator::kInvalidType, 349 JSONSchemaValidator::kInvalidType,
346 schema::kString, 350 schema::kString,
347 schema::kInteger)); 351 schema::kInteger));
348 352
349 DictionaryValue* additional_properties = new DictionaryValue(); 353 base::DictionaryValue* additional_properties = new base::DictionaryValue();
350 additional_properties->SetString(schema::kType, schema::kAny); 354 additional_properties->SetString(schema::kType, schema::kAny);
351 schema->Set(schema::kAdditionalProperties, additional_properties); 355 schema->Set(schema::kAdditionalProperties, additional_properties);
352 instance->Set(0, Value::CreateStringValue("42")); 356 instance->Set(0, new base::StringValue("42"));
353 instance->Append(Value::CreateStringValue("anything")); 357 instance->Append(new base::StringValue("anything"));
354 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 358 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
355 instance->Set(2, new ListValue()); 359 instance->Set(2, new base::ListValue());
356 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 360 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
357 361
358 additional_properties->SetString(schema::kType, schema::kBoolean); 362 additional_properties->SetString(schema::kType, schema::kBoolean);
359 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2", 363 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "2",
360 JSONSchemaValidator::FormatErrorMessage( 364 JSONSchemaValidator::FormatErrorMessage(
361 JSONSchemaValidator::kInvalidType, 365 JSONSchemaValidator::kInvalidType,
362 schema::kBoolean, 366 schema::kBoolean,
363 schema::kArray)); 367 schema::kArray));
364 instance->Set(2, Value::CreateBooleanValue(false)); 368 instance->Set(2, new base::FundamentalValue(false));
365 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 369 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
366 370
367 ListValue* items_schema = NULL; 371 base::ListValue* items_schema = NULL;
368 DictionaryValue* item0_schema = NULL; 372 base::DictionaryValue* item0_schema = NULL;
369 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema)); 373 ASSERT_TRUE(schema->GetList(schema::kItems, &items_schema));
370 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema)); 374 ASSERT_TRUE(items_schema->GetDictionary(0, &item0_schema));
371 item0_schema->SetBoolean(schema::kOptional, true); 375 item0_schema->SetBoolean(schema::kOptional, true);
372 instance->Remove(2, NULL); 376 instance->Remove(2, NULL);
373 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 377 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
374 // TODO(aa): I think this is inconsistent with the handling of NULL+optional 378 // TODO(aa): I think this is inconsistent with the handling of NULL+optional
375 // for objects. 379 // for objects.
376 instance->Set(0, Value::CreateNullValue()); 380 instance->Set(0, base::Value::CreateNullValue());
377 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 381 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
378 instance->Set(0, Value::CreateIntegerValue(42)); 382 instance->Set(0, new base::FundamentalValue(42));
379 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0", 383 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "0",
380 JSONSchemaValidator::FormatErrorMessage( 384 JSONSchemaValidator::FormatErrorMessage(
381 JSONSchemaValidator::kInvalidType, 385 JSONSchemaValidator::kInvalidType,
382 schema::kString, 386 schema::kString,
383 schema::kInteger)); 387 schema::kInteger));
384 } 388 }
385 389
386 void JSONSchemaValidatorTestBase::TestArrayNonTuple() { 390 void JSONSchemaValidatorTestBase::TestArrayNonTuple() {
387 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 391 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
388 schema->SetString(schema::kType, schema::kArray); 392 schema->SetString(schema::kType, schema::kArray);
389 schema->SetString("items.type", schema::kString); 393 schema->SetString("items.type", schema::kString);
390 schema->SetInteger(schema::kMinItems, 2); 394 schema->SetInteger(schema::kMinItems, 2);
391 schema->SetInteger(schema::kMaxItems, 3); 395 schema->SetInteger(schema::kMaxItems, 3);
392 396
393 scoped_ptr<ListValue> instance(new ListValue()); 397 scoped_ptr<base::ListValue> instance(new base::ListValue());
394 instance->Append(Value::CreateStringValue("x")); 398 instance->Append(new base::StringValue("x"));
395 instance->Append(Value::CreateStringValue("x")); 399 instance->Append(new base::StringValue("x"));
396 400
397 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 401 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
398 instance->Append(Value::CreateStringValue("x")); 402 instance->Append(new base::StringValue("x"));
399 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL); 403 ExpectValid(TEST_SOURCE, instance.get(), schema.get(), NULL);
400 404
401 instance->Append(Value::CreateStringValue("x")); 405 instance->Append(new base::StringValue("x"));
402 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", 406 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "",
403 JSONSchemaValidator::FormatErrorMessage( 407 JSONSchemaValidator::FormatErrorMessage(
404 JSONSchemaValidator::kArrayMaxItems, "3")); 408 JSONSchemaValidator::kArrayMaxItems, "3"));
405 instance->Remove(1, NULL); 409 instance->Remove(1, NULL);
406 instance->Remove(1, NULL); 410 instance->Remove(1, NULL);
407 instance->Remove(1, NULL); 411 instance->Remove(1, NULL);
408 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "", 412 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "",
409 JSONSchemaValidator::FormatErrorMessage( 413 JSONSchemaValidator::FormatErrorMessage(
410 JSONSchemaValidator::kArrayMinItems, "2")); 414 JSONSchemaValidator::kArrayMinItems, "2"));
411 415
412 instance->Remove(1, NULL); 416 instance->Remove(1, NULL);
413 instance->Append(Value::CreateIntegerValue(42)); 417 instance->Append(new base::FundamentalValue(42));
414 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1", 418 ExpectNotValid(TEST_SOURCE, instance.get(), schema.get(), NULL, "1",
415 JSONSchemaValidator::FormatErrorMessage( 419 JSONSchemaValidator::FormatErrorMessage(
416 JSONSchemaValidator::kInvalidType, 420 JSONSchemaValidator::kInvalidType,
417 schema::kString, 421 schema::kString,
418 schema::kInteger)); 422 schema::kInteger));
419 } 423 }
420 424
421 void JSONSchemaValidatorTestBase::TestString() { 425 void JSONSchemaValidatorTestBase::TestString() {
422 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 426 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
423 schema->SetString(schema::kType, schema::kString); 427 schema->SetString(schema::kType, schema::kString);
424 schema->SetInteger(schema::kMinLength, 1); 428 schema->SetInteger(schema::kMinLength, 1);
425 schema->SetInteger(schema::kMaxLength, 10); 429 schema->SetInteger(schema::kMaxLength, 10);
426 430
427 ExpectValid(TEST_SOURCE, 431 ExpectValid(TEST_SOURCE,
428 scoped_ptr<Value>(Value::CreateStringValue("x")).get(), 432 scoped_ptr<base::Value>(new base::StringValue("x")).get(),
429 schema.get(), NULL); 433 schema.get(), NULL);
430 ExpectValid(TEST_SOURCE, 434 ExpectValid(TEST_SOURCE,
431 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxx")).get(), 435 scoped_ptr<base::Value>(
436 new base::StringValue("xxxxxxxxxx")).get(),
432 schema.get(), NULL); 437 schema.get(), NULL);
433 438
434 ExpectNotValid(TEST_SOURCE, 439 ExpectNotValid(TEST_SOURCE,
435 scoped_ptr<Value>(Value::CreateStringValue("")).get(), 440 scoped_ptr<base::Value>(new base::StringValue("")).get(),
436 schema.get(), NULL, "", 441 schema.get(), NULL, "",
437 JSONSchemaValidator::FormatErrorMessage( 442 JSONSchemaValidator::FormatErrorMessage(
438 JSONSchemaValidator::kStringMinLength, "1")); 443 JSONSchemaValidator::kStringMinLength, "1"));
439 ExpectNotValid( 444 ExpectNotValid(
440 TEST_SOURCE, 445 TEST_SOURCE,
441 scoped_ptr<Value>(Value::CreateStringValue("xxxxxxxxxxx")).get(), 446 scoped_ptr<base::Value>(new base::StringValue("xxxxxxxxxxx")).get(),
442 schema.get(), NULL, "", 447 schema.get(), NULL, "",
443 JSONSchemaValidator::FormatErrorMessage( 448 JSONSchemaValidator::FormatErrorMessage(
444 JSONSchemaValidator::kStringMaxLength, "10")); 449 JSONSchemaValidator::kStringMaxLength, "10"));
445
446 } 450 }
447 451
448 void JSONSchemaValidatorTestBase::TestNumber() { 452 void JSONSchemaValidatorTestBase::TestNumber() {
449 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 453 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
450 schema->SetString(schema::kType, schema::kNumber); 454 schema->SetString(schema::kType, schema::kNumber);
451 schema->SetInteger(schema::kMinimum, 1); 455 schema->SetInteger(schema::kMinimum, 1);
452 schema->SetInteger(schema::kMaximum, 100); 456 schema->SetInteger(schema::kMaximum, 100);
453 schema->SetInteger("maxDecimal", 2); 457 schema->SetInteger("maxDecimal", 2);
454 458
455 ExpectValid(TEST_SOURCE, 459 ExpectValid(TEST_SOURCE,
456 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), 460 scoped_ptr<base::Value>(new base::FundamentalValue(1)).get(),
457 schema.get(), NULL); 461 schema.get(), NULL);
458 ExpectValid(TEST_SOURCE, 462 ExpectValid(TEST_SOURCE,
459 scoped_ptr<Value>(Value::CreateIntegerValue(50)).get(), 463 scoped_ptr<base::Value>(new base::FundamentalValue(50)).get(),
460 schema.get(), NULL); 464 schema.get(), NULL);
461 ExpectValid(TEST_SOURCE, 465 ExpectValid(TEST_SOURCE,
462 scoped_ptr<Value>(Value::CreateIntegerValue(100)).get(), 466 scoped_ptr<base::Value>(new base::FundamentalValue(100)).get(),
463 schema.get(), NULL); 467 schema.get(), NULL);
464 ExpectValid(TEST_SOURCE, 468 ExpectValid(TEST_SOURCE,
465 scoped_ptr<Value>(Value::CreateDoubleValue(88.88)).get(), 469 scoped_ptr<base::Value>(new base::FundamentalValue(88.88)).get(),
466 schema.get(), NULL); 470 schema.get(), NULL);
467 471
468 ExpectNotValid( 472 ExpectNotValid(
469 TEST_SOURCE, 473 TEST_SOURCE,
470 scoped_ptr<Value>(Value::CreateDoubleValue(0.5)).get(), 474 scoped_ptr<base::Value>(new base::FundamentalValue(0.5)).get(),
471 schema.get(), NULL, "", 475 schema.get(), NULL, "",
472 JSONSchemaValidator::FormatErrorMessage( 476 JSONSchemaValidator::FormatErrorMessage(
473 JSONSchemaValidator::kNumberMinimum, "1")); 477 JSONSchemaValidator::kNumberMinimum, "1"));
474 ExpectNotValid( 478 ExpectNotValid(
475 TEST_SOURCE, 479 TEST_SOURCE,
476 scoped_ptr<Value>(Value::CreateDoubleValue(100.1)).get(), 480 scoped_ptr<base::Value>(new base::FundamentalValue(100.1)).get(),
477 schema.get(), NULL, "", 481 schema.get(), NULL, "",
478 JSONSchemaValidator::FormatErrorMessage( 482 JSONSchemaValidator::FormatErrorMessage(
479 JSONSchemaValidator::kNumberMaximum, "100")); 483 JSONSchemaValidator::kNumberMaximum, "100"));
480 } 484 }
481 485
482 void JSONSchemaValidatorTestBase::TestTypeClassifier() { 486 void JSONSchemaValidatorTestBase::TestTypeClassifier() {
483 EXPECT_EQ(std::string(schema::kBoolean), 487 EXPECT_EQ(std::string(schema::kBoolean),
484 JSONSchemaValidator::GetJSONSchemaType( 488 JSONSchemaValidator::GetJSONSchemaType(
485 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get())); 489 scoped_ptr<base::Value>(
490 new base::FundamentalValue(true)).get()));
486 EXPECT_EQ(std::string(schema::kBoolean), 491 EXPECT_EQ(std::string(schema::kBoolean),
487 JSONSchemaValidator::GetJSONSchemaType( 492 JSONSchemaValidator::GetJSONSchemaType(
488 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get())); 493 scoped_ptr<base::Value>(
494 new base::FundamentalValue(false)).get()));
489 495
490 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the 496 // It doesn't matter whether the C++ type is 'integer' or 'real'. If the
491 // number is integral and within the representable range of integers in 497 // number is integral and within the representable range of integers in
492 // double, it's classified as 'integer'. 498 // double, it's classified as 'integer'.
493 EXPECT_EQ(std::string(schema::kInteger), 499 EXPECT_EQ(std::string(schema::kInteger),
494 JSONSchemaValidator::GetJSONSchemaType( 500 JSONSchemaValidator::GetJSONSchemaType(
495 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get())); 501 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get()));
496 EXPECT_EQ(std::string(schema::kInteger), 502 EXPECT_EQ(std::string(schema::kInteger),
497 JSONSchemaValidator::GetJSONSchemaType( 503 JSONSchemaValidator::GetJSONSchemaType(
498 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get())); 504 scoped_ptr<base::Value>(new base::FundamentalValue(0)).get()));
499 EXPECT_EQ(std::string(schema::kInteger), 505 EXPECT_EQ(std::string(schema::kInteger),
500 JSONSchemaValidator::GetJSONSchemaType( 506 JSONSchemaValidator::GetJSONSchemaType(
501 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get())); 507 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get()));
502 EXPECT_EQ(std::string(schema::kInteger), 508 EXPECT_EQ(std::string(schema::kInteger),
503 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( 509 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
504 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get())); 510 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG))).get()));
505 EXPECT_EQ(std::string(schema::kInteger), 511 EXPECT_EQ(std::string(schema::kInteger),
506 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( 512 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
507 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get())); 513 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG))).get()));
508 514
509 // "number" is only used for non-integral numbers, or numbers beyond what 515 // "number" is only used for non-integral numbers, or numbers beyond what
510 // double can accurately represent. 516 // double can accurately represent.
511 EXPECT_EQ(std::string(schema::kNumber), 517 EXPECT_EQ(std::string(schema::kNumber),
512 JSONSchemaValidator::GetJSONSchemaType( 518 JSONSchemaValidator::GetJSONSchemaType(
513 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get())); 519 scoped_ptr<base::Value>(
520 new base::FundamentalValue(88.8)).get()));
514 EXPECT_EQ(std::string(schema::kNumber), 521 EXPECT_EQ(std::string(schema::kNumber),
515 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( 522 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
516 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG) * 2)).get())); 523 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG) * 2)).get()));
517 EXPECT_EQ(std::string(schema::kNumber), 524 EXPECT_EQ(std::string(schema::kNumber),
518 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<Value>( 525 JSONSchemaValidator::GetJSONSchemaType(scoped_ptr<base::Value>(
519 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG) * 2)).get())); 526 new base::FundamentalValue(
527 pow(-2.0, DBL_MANT_DIG) * 2)).get()));
520 528
521 EXPECT_EQ(std::string(schema::kString), 529 EXPECT_EQ(std::string(schema::kString),
522 JSONSchemaValidator::GetJSONSchemaType( 530 JSONSchemaValidator::GetJSONSchemaType(
523 scoped_ptr<Value>(Value::CreateStringValue("foo")).get())); 531 scoped_ptr<base::Value>(new base::StringValue("foo")).get()));
524 EXPECT_EQ(std::string(schema::kArray), 532 EXPECT_EQ(std::string(schema::kArray),
525 JSONSchemaValidator::GetJSONSchemaType( 533 JSONSchemaValidator::GetJSONSchemaType(
526 scoped_ptr<Value>(new ListValue()).get())); 534 scoped_ptr<base::Value>(new base::ListValue()).get()));
527 EXPECT_EQ(std::string(schema::kObject), 535 EXPECT_EQ(std::string(schema::kObject),
528 JSONSchemaValidator::GetJSONSchemaType( 536 JSONSchemaValidator::GetJSONSchemaType(
529 scoped_ptr<Value>(new DictionaryValue()).get())); 537 scoped_ptr<base::Value>(new base::DictionaryValue()).get()));
530 EXPECT_EQ(std::string(schema::kNull), 538 EXPECT_EQ(std::string(schema::kNull),
531 JSONSchemaValidator::GetJSONSchemaType( 539 JSONSchemaValidator::GetJSONSchemaType(
532 scoped_ptr<Value>(Value::CreateNullValue()).get())); 540 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get()));
533 } 541 }
534 542
535 void JSONSchemaValidatorTestBase::TestTypes() { 543 void JSONSchemaValidatorTestBase::TestTypes() {
536 scoped_ptr<DictionaryValue> schema(new DictionaryValue()); 544 scoped_ptr<base::DictionaryValue> schema(new base::DictionaryValue());
537 545
538 // valid 546 // valid
539 schema->SetString(schema::kType, schema::kObject); 547 schema->SetString(schema::kType, schema::kObject);
540 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new DictionaryValue()).get(), 548 ExpectValid(TEST_SOURCE,
549 scoped_ptr<base::Value>(new base::DictionaryValue()).get(),
541 schema.get(), NULL); 550 schema.get(), NULL);
542 551
543 schema->SetString(schema::kType, schema::kArray); 552 schema->SetString(schema::kType, schema::kArray);
544 ExpectValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), 553 ExpectValid(TEST_SOURCE, scoped_ptr<base::Value>(new base::ListValue()).get(),
545 schema.get(), NULL); 554 schema.get(), NULL);
546 555
547 schema->SetString(schema::kType, schema::kString); 556 schema->SetString(schema::kType, schema::kString);
548 ExpectValid(TEST_SOURCE, 557 ExpectValid(TEST_SOURCE,
549 scoped_ptr<Value>(Value::CreateStringValue("foobar")).get(), 558 scoped_ptr<base::Value>(new base::StringValue("foobar")).get(),
550 schema.get(), NULL); 559 schema.get(), NULL);
551 560
552 schema->SetString(schema::kType, schema::kNumber); 561 schema->SetString(schema::kType, schema::kNumber);
553 ExpectValid(TEST_SOURCE, 562 ExpectValid(TEST_SOURCE,
554 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), 563 scoped_ptr<base::Value>(new base::FundamentalValue(88.8)).get(),
555 schema.get(), NULL); 564 schema.get(), NULL);
556 ExpectValid(TEST_SOURCE, 565 ExpectValid(TEST_SOURCE,
557 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), 566 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
558 schema.get(), NULL); 567 schema.get(), NULL);
559 ExpectValid(TEST_SOURCE, 568 ExpectValid(TEST_SOURCE,
560 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 569 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
561 schema.get(), NULL); 570 schema.get(), NULL);
562 ExpectValid(TEST_SOURCE, 571 ExpectValid(TEST_SOURCE,
563 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), 572 scoped_ptr<base::Value>(new base::FundamentalValue(0)).get(),
564 schema.get(), NULL); 573 schema.get(), NULL);
565 574
566 schema->SetString(schema::kType, schema::kInteger); 575 schema->SetString(schema::kType, schema::kInteger);
567 ExpectValid(TEST_SOURCE, 576 ExpectValid(TEST_SOURCE,
568 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 577 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
569 schema.get(), NULL); 578 schema.get(), NULL);
570 ExpectValid(TEST_SOURCE, 579 ExpectValid(TEST_SOURCE,
571 scoped_ptr<Value>(Value::CreateDoubleValue(42)).get(), 580 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
572 schema.get(), NULL); 581 schema.get(), NULL);
573 ExpectValid(TEST_SOURCE, 582 ExpectValid(TEST_SOURCE,
574 scoped_ptr<Value>(Value::CreateIntegerValue(0)).get(), 583 scoped_ptr<base::Value>(new base::FundamentalValue(0)).get(),
575 schema.get(), NULL); 584 schema.get(), NULL);
576 ExpectValid(TEST_SOURCE, 585 ExpectValid(TEST_SOURCE,
577 scoped_ptr<Value>( 586 scoped_ptr<base::Value>(
578 Value::CreateDoubleValue(pow(2.0, DBL_MANT_DIG))).get(), 587 new base::FundamentalValue(pow(2.0, DBL_MANT_DIG))).get(),
579 schema.get(), NULL); 588 schema.get(), NULL);
580 ExpectValid(TEST_SOURCE, 589 ExpectValid(TEST_SOURCE,
581 scoped_ptr<Value>( 590 scoped_ptr<base::Value>(
582 Value::CreateDoubleValue(pow(-2.0, DBL_MANT_DIG))).get(), 591 new base::FundamentalValue(pow(-2.0, DBL_MANT_DIG))).get(),
583 schema.get(), NULL); 592 schema.get(), NULL);
584 593
585 schema->SetString(schema::kType, schema::kBoolean); 594 schema->SetString(schema::kType, schema::kBoolean);
586 ExpectValid(TEST_SOURCE, 595 ExpectValid(TEST_SOURCE,
587 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), 596 scoped_ptr<base::Value>(new base::FundamentalValue(false)).get(),
588 schema.get(), NULL); 597 schema.get(), NULL);
589 ExpectValid(TEST_SOURCE, 598 ExpectValid(TEST_SOURCE,
590 scoped_ptr<Value>(Value::CreateBooleanValue(true)).get(), 599 scoped_ptr<base::Value>(new base::FundamentalValue(true)).get(),
591 schema.get(), NULL); 600 schema.get(), NULL);
592 601
593 schema->SetString(schema::kType, schema::kNull); 602 schema->SetString(schema::kType, schema::kNull);
594 ExpectValid(TEST_SOURCE, 603 ExpectValid(TEST_SOURCE,
595 scoped_ptr<Value>(Value::CreateNullValue()).get(), 604 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
596 schema.get(), NULL); 605 schema.get(), NULL);
597 606
598 // not valid 607 // not valid
599 schema->SetString(schema::kType, schema::kObject); 608 schema->SetString(schema::kType, schema::kObject);
600 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(new ListValue()).get(), 609 ExpectNotValid(TEST_SOURCE,
610 scoped_ptr<base::Value>(new base::ListValue()).get(),
601 schema.get(), NULL, "", 611 schema.get(), NULL, "",
602 JSONSchemaValidator::FormatErrorMessage( 612 JSONSchemaValidator::FormatErrorMessage(
603 JSONSchemaValidator::kInvalidType, 613 JSONSchemaValidator::kInvalidType,
604 schema::kObject, 614 schema::kObject,
605 schema::kArray)); 615 schema::kArray));
606 616
607 schema->SetString(schema::kType, schema::kObject); 617 schema->SetString(schema::kType, schema::kObject);
608 ExpectNotValid(TEST_SOURCE, scoped_ptr<Value>(Value::CreateNullValue()).get(), 618 ExpectNotValid(TEST_SOURCE,
619 scoped_ptr<base::Value>(base::Value::CreateNullValue()).get(),
609 schema.get(), NULL, "", 620 schema.get(), NULL, "",
610 JSONSchemaValidator::FormatErrorMessage( 621 JSONSchemaValidator::FormatErrorMessage(
611 JSONSchemaValidator::kInvalidType, 622 JSONSchemaValidator::kInvalidType,
612 schema::kObject, 623 schema::kObject,
613 schema::kNull)); 624 schema::kNull));
614 625
615 schema->SetString(schema::kType, schema::kArray); 626 schema->SetString(schema::kType, schema::kArray);
616 ExpectNotValid(TEST_SOURCE, 627 ExpectNotValid(TEST_SOURCE,
617 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 628 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
618 schema.get(), NULL, "", 629 schema.get(), NULL, "",
619 JSONSchemaValidator::FormatErrorMessage( 630 JSONSchemaValidator::FormatErrorMessage(
620 JSONSchemaValidator::kInvalidType, 631 JSONSchemaValidator::kInvalidType,
621 schema::kArray, 632 schema::kArray,
622 schema::kInteger)); 633 schema::kInteger));
623 634
624 schema->SetString(schema::kType, schema::kString); 635 schema->SetString(schema::kType, schema::kString);
625 ExpectNotValid(TEST_SOURCE, 636 ExpectNotValid(TEST_SOURCE,
626 scoped_ptr<Value>(Value::CreateIntegerValue(42)).get(), 637 scoped_ptr<base::Value>(new base::FundamentalValue(42)).get(),
627 schema.get(), NULL, "", 638 schema.get(), NULL, "",
628 JSONSchemaValidator::FormatErrorMessage( 639 JSONSchemaValidator::FormatErrorMessage(
629 JSONSchemaValidator::kInvalidType, 640 JSONSchemaValidator::kInvalidType,
630 schema::kString, 641 schema::kString,
631 schema::kInteger)); 642 schema::kInteger));
632 643
633 schema->SetString(schema::kType, schema::kNumber); 644 schema->SetString(schema::kType, schema::kNumber);
634 ExpectNotValid(TEST_SOURCE, 645 ExpectNotValid(TEST_SOURCE,
635 scoped_ptr<Value>(Value::CreateStringValue("42")).get(), 646 scoped_ptr<base::Value>(new base::StringValue("42")).get(),
636 schema.get(), NULL, "", 647 schema.get(), NULL, "",
637 JSONSchemaValidator::FormatErrorMessage( 648 JSONSchemaValidator::FormatErrorMessage(
638 JSONSchemaValidator::kInvalidType, 649 JSONSchemaValidator::kInvalidType,
639 schema::kNumber, 650 schema::kNumber,
640 schema::kString)); 651 schema::kString));
641 652
642 schema->SetString(schema::kType, schema::kInteger); 653 schema->SetString(schema::kType, schema::kInteger);
643 ExpectNotValid(TEST_SOURCE, 654 ExpectNotValid(TEST_SOURCE,
644 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), 655 scoped_ptr<base::Value>(
656 new base::FundamentalValue(88.8)).get(),
645 schema.get(), NULL, "", 657 schema.get(), NULL, "",
646 JSONSchemaValidator::FormatErrorMessage( 658 JSONSchemaValidator::FormatErrorMessage(
647 JSONSchemaValidator::kInvalidType, 659 JSONSchemaValidator::kInvalidType,
648 schema::kInteger, 660 schema::kInteger,
649 schema::kNumber)); 661 schema::kNumber));
650 662
651 schema->SetString(schema::kType, schema::kInteger); 663 schema->SetString(schema::kType, schema::kInteger);
652 ExpectNotValid(TEST_SOURCE, 664 ExpectNotValid(TEST_SOURCE,
653 scoped_ptr<Value>(Value::CreateDoubleValue(88.8)).get(), 665 scoped_ptr<base::Value>(
666 new base::FundamentalValue(88.8)).get(),
654 schema.get(), NULL, "", 667 schema.get(), NULL, "",
655 JSONSchemaValidator::FormatErrorMessage( 668 JSONSchemaValidator::FormatErrorMessage(
656 JSONSchemaValidator::kInvalidType, 669 JSONSchemaValidator::kInvalidType,
657 schema::kInteger, 670 schema::kInteger,
658 schema::kNumber)); 671 schema::kNumber));
659 672
660 schema->SetString(schema::kType, schema::kBoolean); 673 schema->SetString(schema::kType, schema::kBoolean);
661 ExpectNotValid(TEST_SOURCE, 674 ExpectNotValid(TEST_SOURCE,
662 scoped_ptr<Value>(Value::CreateIntegerValue(1)).get(), 675 scoped_ptr<base::Value>(new base::FundamentalValue(1)).get(),
663 schema.get(), NULL, "", 676 schema.get(), NULL, "",
664 JSONSchemaValidator::FormatErrorMessage( 677 JSONSchemaValidator::FormatErrorMessage(
665 JSONSchemaValidator::kInvalidType, 678 JSONSchemaValidator::kInvalidType,
666 schema::kBoolean, 679 schema::kBoolean,
667 schema::kInteger)); 680 schema::kInteger));
668 681
669 schema->SetString(schema::kType, schema::kNull); 682 schema->SetString(schema::kType, schema::kNull);
670 ExpectNotValid(TEST_SOURCE, 683 ExpectNotValid(TEST_SOURCE,
671 scoped_ptr<Value>(Value::CreateBooleanValue(false)).get(), 684 scoped_ptr<base::Value>(
685 new base::FundamentalValue(false)).get(),
672 schema.get(), NULL, "", 686 schema.get(), NULL, "",
673 JSONSchemaValidator::FormatErrorMessage( 687 JSONSchemaValidator::FormatErrorMessage(
674 JSONSchemaValidator::kInvalidType, 688 JSONSchemaValidator::kInvalidType,
675 schema::kNull, 689 schema::kNull,
676 schema::kBoolean)); 690 schema::kBoolean));
677 } 691 }
OLDNEW
« no previous file with comments | « chrome/common/extensions/value_builder.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698