OLD | NEW |
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 <string> | 5 #include <string> |
6 | 6 |
7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/json/json_file_value_serializer.h" | 9 #include "base/json/json_file_value_serializer.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ASSERT_EQ(1, value); | 86 ASSERT_EQ(1, value); |
87 } | 87 } |
88 | 88 |
89 // Test proper JSON deserialization from string is working. | 89 // Test proper JSON deserialization from string is working. |
90 TEST(JSONValueDeserializerTest, ReadProperJSONFromString) { | 90 TEST(JSONValueDeserializerTest, ReadProperJSONFromString) { |
91 // Try to deserialize it through the serializer. | 91 // Try to deserialize it through the serializer. |
92 JSONStringValueDeserializer str_deserializer(kProperJSON); | 92 JSONStringValueDeserializer str_deserializer(kProperJSON); |
93 | 93 |
94 int error_code = 0; | 94 int error_code = 0; |
95 std::string error_message; | 95 std::string error_message; |
96 scoped_ptr<Value> value( | 96 scoped_ptr<Value> value = |
97 str_deserializer.Deserialize(&error_code, &error_message)); | 97 str_deserializer.Deserialize(&error_code, &error_message); |
98 ASSERT_TRUE(value.get()); | 98 ASSERT_TRUE(value.get()); |
99 ASSERT_EQ(0, error_code); | 99 ASSERT_EQ(0, error_code); |
100 ASSERT_TRUE(error_message.empty()); | 100 ASSERT_TRUE(error_message.empty()); |
101 // Verify if the same JSON is still there. | 101 // Verify if the same JSON is still there. |
102 CheckJSONIsStillTheSame(*value); | 102 CheckJSONIsStillTheSame(*value); |
103 } | 103 } |
104 | 104 |
105 // Test proper JSON deserialization from a StringPiece substring. | 105 // Test proper JSON deserialization from a StringPiece substring. |
106 TEST(JSONValueDeserializerTest, ReadProperJSONFromStringPiece) { | 106 TEST(JSONValueDeserializerTest, ReadProperJSONFromStringPiece) { |
107 // Create a StringPiece for the substring of kProperJSONPadded that matches | 107 // Create a StringPiece for the substring of kProperJSONPadded that matches |
108 // kProperJSON. | 108 // kProperJSON. |
109 base::StringPiece proper_json(kProperJSONPadded); | 109 base::StringPiece proper_json(kProperJSONPadded); |
110 proper_json = proper_json.substr(5, proper_json.length() - 10); | 110 proper_json = proper_json.substr(5, proper_json.length() - 10); |
111 JSONStringValueDeserializer str_deserializer(proper_json); | 111 JSONStringValueDeserializer str_deserializer(proper_json); |
112 | 112 |
113 int error_code = 0; | 113 int error_code = 0; |
114 std::string error_message; | 114 std::string error_message; |
115 scoped_ptr<Value> value( | 115 scoped_ptr<Value> value = |
116 str_deserializer.Deserialize(&error_code, &error_message)); | 116 str_deserializer.Deserialize(&error_code, &error_message); |
117 ASSERT_TRUE(value.get()); | 117 ASSERT_TRUE(value.get()); |
118 ASSERT_EQ(0, error_code); | 118 ASSERT_EQ(0, error_code); |
119 ASSERT_TRUE(error_message.empty()); | 119 ASSERT_TRUE(error_message.empty()); |
120 // Verify if the same JSON is still there. | 120 // Verify if the same JSON is still there. |
121 CheckJSONIsStillTheSame(*value); | 121 CheckJSONIsStillTheSame(*value); |
122 } | 122 } |
123 | 123 |
124 // Test that trialing commas are only properly deserialized from string when | 124 // Test that trialing commas are only properly deserialized from string when |
125 // the proper flag for that is set. | 125 // the proper flag for that is set. |
126 TEST(JSONValueDeserializerTest, ReadJSONWithTrailingCommasFromString) { | 126 TEST(JSONValueDeserializerTest, ReadJSONWithTrailingCommasFromString) { |
127 // Try to deserialize it through the serializer. | 127 // Try to deserialize it through the serializer. |
128 JSONStringValueDeserializer str_deserializer(kProperJSONWithCommas); | 128 JSONStringValueDeserializer str_deserializer(kProperJSONWithCommas); |
129 | 129 |
130 int error_code = 0; | 130 int error_code = 0; |
131 std::string error_message; | 131 std::string error_message; |
132 scoped_ptr<Value> value( | 132 scoped_ptr<Value> value = |
133 str_deserializer.Deserialize(&error_code, &error_message)); | 133 str_deserializer.Deserialize(&error_code, &error_message); |
134 ASSERT_FALSE(value.get()); | 134 ASSERT_FALSE(value.get()); |
135 ASSERT_NE(0, error_code); | 135 ASSERT_NE(0, error_code); |
136 ASSERT_FALSE(error_message.empty()); | 136 ASSERT_FALSE(error_message.empty()); |
137 // Now the flag is set and it must pass. | 137 // Now the flag is set and it must pass. |
138 str_deserializer.set_allow_trailing_comma(true); | 138 str_deserializer.set_allow_trailing_comma(true); |
139 value.reset(str_deserializer.Deserialize(&error_code, &error_message)); | 139 value = str_deserializer.Deserialize(&error_code, &error_message); |
140 ASSERT_TRUE(value.get()); | 140 ASSERT_TRUE(value.get()); |
141 ASSERT_EQ(JSONReader::JSON_TRAILING_COMMA, error_code); | 141 ASSERT_EQ(JSONReader::JSON_TRAILING_COMMA, error_code); |
142 // Verify if the same JSON is still there. | 142 // Verify if the same JSON is still there. |
143 CheckJSONIsStillTheSame(*value); | 143 CheckJSONIsStillTheSame(*value); |
144 } | 144 } |
145 | 145 |
146 // Test proper JSON deserialization from file is working. | 146 // Test proper JSON deserialization from file is working. |
147 TEST(JSONValueDeserializerTest, ReadProperJSONFromFile) { | 147 TEST(JSONValueDeserializerTest, ReadProperJSONFromFile) { |
148 ScopedTempDir tempdir; | 148 ScopedTempDir tempdir; |
149 ASSERT_TRUE(tempdir.CreateUniqueTempDir()); | 149 ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
150 // Write it down in the file. | 150 // Write it down in the file. |
151 FilePath temp_file(tempdir.path().AppendASCII("test.json")); | 151 FilePath temp_file(tempdir.path().AppendASCII("test.json")); |
152 ASSERT_EQ(static_cast<int>(strlen(kProperJSON)), | 152 ASSERT_EQ(static_cast<int>(strlen(kProperJSON)), |
153 WriteFile(temp_file, kProperJSON, strlen(kProperJSON))); | 153 WriteFile(temp_file, kProperJSON, strlen(kProperJSON))); |
154 | 154 |
155 // Try to deserialize it through the serializer. | 155 // Try to deserialize it through the serializer. |
156 JSONFileValueDeserializer file_deserializer(temp_file); | 156 JSONFileValueDeserializer file_deserializer(temp_file); |
157 | 157 |
158 int error_code = 0; | 158 int error_code = 0; |
159 std::string error_message; | 159 std::string error_message; |
160 scoped_ptr<Value> value( | 160 scoped_ptr<Value> value = |
161 file_deserializer.Deserialize(&error_code, &error_message)); | 161 file_deserializer.Deserialize(&error_code, &error_message); |
162 ASSERT_TRUE(value.get()); | 162 ASSERT_TRUE(value.get()); |
163 ASSERT_EQ(0, error_code); | 163 ASSERT_EQ(0, error_code); |
164 ASSERT_TRUE(error_message.empty()); | 164 ASSERT_TRUE(error_message.empty()); |
165 // Verify if the same JSON is still there. | 165 // Verify if the same JSON is still there. |
166 CheckJSONIsStillTheSame(*value); | 166 CheckJSONIsStillTheSame(*value); |
167 } | 167 } |
168 | 168 |
169 // Test that trialing commas are only properly deserialized from file when | 169 // Test that trialing commas are only properly deserialized from file when |
170 // the proper flag for that is set. | 170 // the proper flag for that is set. |
171 TEST(JSONValueDeserializerTest, ReadJSONWithCommasFromFile) { | 171 TEST(JSONValueDeserializerTest, ReadJSONWithCommasFromFile) { |
172 ScopedTempDir tempdir; | 172 ScopedTempDir tempdir; |
173 ASSERT_TRUE(tempdir.CreateUniqueTempDir()); | 173 ASSERT_TRUE(tempdir.CreateUniqueTempDir()); |
174 // Write it down in the file. | 174 // Write it down in the file. |
175 FilePath temp_file(tempdir.path().AppendASCII("test.json")); | 175 FilePath temp_file(tempdir.path().AppendASCII("test.json")); |
176 ASSERT_EQ(static_cast<int>(strlen(kProperJSONWithCommas)), | 176 ASSERT_EQ(static_cast<int>(strlen(kProperJSONWithCommas)), |
177 WriteFile(temp_file, kProperJSONWithCommas, | 177 WriteFile(temp_file, kProperJSONWithCommas, |
178 strlen(kProperJSONWithCommas))); | 178 strlen(kProperJSONWithCommas))); |
179 | 179 |
180 // Try to deserialize it through the serializer. | 180 // Try to deserialize it through the serializer. |
181 JSONFileValueDeserializer file_deserializer(temp_file); | 181 JSONFileValueDeserializer file_deserializer(temp_file); |
182 // This must fail without the proper flag. | 182 // This must fail without the proper flag. |
183 int error_code = 0; | 183 int error_code = 0; |
184 std::string error_message; | 184 std::string error_message; |
185 scoped_ptr<Value> value( | 185 scoped_ptr<Value> value = |
186 file_deserializer.Deserialize(&error_code, &error_message)); | 186 file_deserializer.Deserialize(&error_code, &error_message); |
187 ASSERT_FALSE(value.get()); | 187 ASSERT_FALSE(value.get()); |
188 ASSERT_NE(0, error_code); | 188 ASSERT_NE(0, error_code); |
189 ASSERT_FALSE(error_message.empty()); | 189 ASSERT_FALSE(error_message.empty()); |
190 // Now the flag is set and it must pass. | 190 // Now the flag is set and it must pass. |
191 file_deserializer.set_allow_trailing_comma(true); | 191 file_deserializer.set_allow_trailing_comma(true); |
192 value.reset(file_deserializer.Deserialize(&error_code, &error_message)); | 192 value = file_deserializer.Deserialize(&error_code, &error_message); |
193 ASSERT_TRUE(value.get()); | 193 ASSERT_TRUE(value.get()); |
194 ASSERT_EQ(JSONReader::JSON_TRAILING_COMMA, error_code); | 194 ASSERT_EQ(JSONReader::JSON_TRAILING_COMMA, error_code); |
195 // Verify if the same JSON is still there. | 195 // Verify if the same JSON is still there. |
196 CheckJSONIsStillTheSame(*value); | 196 CheckJSONIsStillTheSame(*value); |
197 } | 197 } |
198 | 198 |
199 TEST(JSONValueDeserializerTest, AllowTrailingComma) { | 199 TEST(JSONValueDeserializerTest, AllowTrailingComma) { |
200 scoped_ptr<Value> root; | 200 scoped_ptr<Value> root; |
201 scoped_ptr<Value> root_expected; | 201 scoped_ptr<Value> root_expected; |
202 static const char kTestWithCommas[] = "{\"key\": [true,],}"; | 202 static const char kTestWithCommas[] = "{\"key\": [true,],}"; |
203 static const char kTestNoCommas[] = "{\"key\": [true]}"; | 203 static const char kTestNoCommas[] = "{\"key\": [true]}"; |
204 | 204 |
205 JSONStringValueDeserializer deserializer(kTestWithCommas); | 205 JSONStringValueDeserializer deserializer(kTestWithCommas); |
206 deserializer.set_allow_trailing_comma(true); | 206 deserializer.set_allow_trailing_comma(true); |
207 JSONStringValueDeserializer deserializer_expected(kTestNoCommas); | 207 JSONStringValueDeserializer deserializer_expected(kTestNoCommas); |
208 root.reset(deserializer.Deserialize(NULL, NULL)); | 208 root = deserializer.Deserialize(NULL, NULL); |
209 ASSERT_TRUE(root.get()); | 209 ASSERT_TRUE(root.get()); |
210 root_expected.reset(deserializer_expected.Deserialize(NULL, NULL)); | 210 root_expected = deserializer_expected.Deserialize(NULL, NULL); |
211 ASSERT_TRUE(root_expected.get()); | 211 ASSERT_TRUE(root_expected.get()); |
212 ASSERT_TRUE(root->Equals(root_expected.get())); | 212 ASSERT_TRUE(root->Equals(root_expected.get())); |
213 } | 213 } |
214 | 214 |
215 TEST(JSONValueSerializerTest, Roundtrip) { | 215 TEST(JSONValueSerializerTest, Roundtrip) { |
216 static const char kOriginalSerialization[] = | 216 static const char kOriginalSerialization[] = |
217 "{\"bool\":true,\"double\":3.14,\"int\":42,\"list\":[1,2],\"null\":null}"; | 217 "{\"bool\":true,\"double\":3.14,\"int\":42,\"list\":[1,2],\"null\":null}"; |
218 JSONStringValueDeserializer deserializer(kOriginalSerialization); | 218 JSONStringValueDeserializer deserializer(kOriginalSerialization); |
219 scoped_ptr<Value> root(deserializer.Deserialize(NULL, NULL)); | 219 scoped_ptr<Value> root = deserializer.Deserialize(NULL, NULL); |
220 ASSERT_TRUE(root.get()); | 220 ASSERT_TRUE(root.get()); |
221 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); | 221 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
222 | 222 |
223 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); | 223 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); |
224 | 224 |
225 Value* null_value = NULL; | 225 Value* null_value = NULL; |
226 ASSERT_TRUE(root_dict->Get("null", &null_value)); | 226 ASSERT_TRUE(root_dict->Get("null", &null_value)); |
227 ASSERT_TRUE(null_value); | 227 ASSERT_TRUE(null_value); |
228 ASSERT_TRUE(null_value->IsType(Value::TYPE_NULL)); | 228 ASSERT_TRUE(null_value->IsType(Value::TYPE_NULL)); |
229 | 229 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 | 319 |
320 static const char kExpected[] = "{\"web\":\"\xE7\xBD\x91\xE9\xA1\xB5\"}"; | 320 static const char kExpected[] = "{\"web\":\"\xE7\xBD\x91\xE9\xA1\xB5\"}"; |
321 | 321 |
322 std::string actual; | 322 std::string actual; |
323 JSONStringValueSerializer serializer(&actual); | 323 JSONStringValueSerializer serializer(&actual); |
324 ASSERT_TRUE(serializer.Serialize(root)); | 324 ASSERT_TRUE(serializer.Serialize(root)); |
325 ASSERT_EQ(kExpected, actual); | 325 ASSERT_EQ(kExpected, actual); |
326 | 326 |
327 // escaped ascii text -> json | 327 // escaped ascii text -> json |
328 JSONStringValueDeserializer deserializer(kExpected); | 328 JSONStringValueDeserializer deserializer(kExpected); |
329 scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL, NULL)); | 329 scoped_ptr<Value> deserial_root = deserializer.Deserialize(NULL, NULL); |
330 ASSERT_TRUE(deserial_root.get()); | 330 ASSERT_TRUE(deserial_root.get()); |
331 DictionaryValue* dict_root = | 331 DictionaryValue* dict_root = |
332 static_cast<DictionaryValue*>(deserial_root.get()); | 332 static_cast<DictionaryValue*>(deserial_root.get()); |
333 string16 web_value; | 333 string16 web_value; |
334 ASSERT_TRUE(dict_root->GetString("web", &web_value)); | 334 ASSERT_TRUE(dict_root->GetString("web", &web_value)); |
335 ASSERT_EQ(test, web_value); | 335 ASSERT_EQ(test, web_value); |
336 } | 336 } |
337 | 337 |
338 TEST(JSONValueSerializerTest, HexStrings) { | 338 TEST(JSONValueSerializerTest, HexStrings) { |
339 // hex string json -> escaped ascii text | 339 // hex string json -> escaped ascii text |
340 DictionaryValue root; | 340 DictionaryValue root; |
341 string16 test(WideToUTF16(L"\x01\x02")); | 341 string16 test(WideToUTF16(L"\x01\x02")); |
342 root.SetString("test", test); | 342 root.SetString("test", test); |
343 | 343 |
344 static const char kExpected[] = "{\"test\":\"\\u0001\\u0002\"}"; | 344 static const char kExpected[] = "{\"test\":\"\\u0001\\u0002\"}"; |
345 | 345 |
346 std::string actual; | 346 std::string actual; |
347 JSONStringValueSerializer serializer(&actual); | 347 JSONStringValueSerializer serializer(&actual); |
348 ASSERT_TRUE(serializer.Serialize(root)); | 348 ASSERT_TRUE(serializer.Serialize(root)); |
349 ASSERT_EQ(kExpected, actual); | 349 ASSERT_EQ(kExpected, actual); |
350 | 350 |
351 // escaped ascii text -> json | 351 // escaped ascii text -> json |
352 JSONStringValueDeserializer deserializer(kExpected); | 352 JSONStringValueDeserializer deserializer(kExpected); |
353 scoped_ptr<Value> deserial_root(deserializer.Deserialize(NULL, NULL)); | 353 scoped_ptr<Value> deserial_root = deserializer.Deserialize(NULL, NULL); |
354 ASSERT_TRUE(deserial_root.get()); | 354 ASSERT_TRUE(deserial_root.get()); |
355 DictionaryValue* dict_root = | 355 DictionaryValue* dict_root = |
356 static_cast<DictionaryValue*>(deserial_root.get()); | 356 static_cast<DictionaryValue*>(deserial_root.get()); |
357 string16 test_value; | 357 string16 test_value; |
358 ASSERT_TRUE(dict_root->GetString("test", &test_value)); | 358 ASSERT_TRUE(dict_root->GetString("test", &test_value)); |
359 ASSERT_EQ(test, test_value); | 359 ASSERT_EQ(test, test_value); |
360 | 360 |
361 // Test converting escaped regular chars | 361 // Test converting escaped regular chars |
362 static const char kEscapedChars[] = "{\"test\":\"\\u0067\\u006f\"}"; | 362 static const char kEscapedChars[] = "{\"test\":\"\\u0067\\u006f\"}"; |
363 JSONStringValueDeserializer deserializer2(kEscapedChars); | 363 JSONStringValueDeserializer deserializer2(kEscapedChars); |
364 deserial_root.reset(deserializer2.Deserialize(NULL, NULL)); | 364 deserial_root = deserializer2.Deserialize(NULL, NULL); |
365 ASSERT_TRUE(deserial_root.get()); | 365 ASSERT_TRUE(deserial_root.get()); |
366 dict_root = static_cast<DictionaryValue*>(deserial_root.get()); | 366 dict_root = static_cast<DictionaryValue*>(deserial_root.get()); |
367 ASSERT_TRUE(dict_root->GetString("test", &test_value)); | 367 ASSERT_TRUE(dict_root->GetString("test", &test_value)); |
368 ASSERT_EQ(ASCIIToUTF16("go"), test_value); | 368 ASSERT_EQ(ASCIIToUTF16("go"), test_value); |
369 } | 369 } |
370 | 370 |
371 TEST(JSONValueSerializerTest, JSONReaderComments) { | 371 TEST(JSONValueSerializerTest, JSONReaderComments) { |
372 ValidateJsonList("[ // 2, 3, ignore me ] \n1 ]"); | 372 ValidateJsonList("[ // 2, 3, ignore me ] \n1 ]"); |
373 ValidateJsonList("[ /* 2, \n3, ignore me ]*/ \n1 ]"); | 373 ValidateJsonList("[ /* 2, \n3, ignore me ]*/ \n1 ]"); |
374 ValidateJsonList("//header\n[ // 2, \n// 3, \n1 ]// footer"); | 374 ValidateJsonList("//header\n[ // 2, \n// 3, \n1 ]// footer"); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 TEST_F(JSONFileValueSerializerTest, Roundtrip) { | 406 TEST_F(JSONFileValueSerializerTest, Roundtrip) { |
407 base::FilePath original_file_path; | 407 base::FilePath original_file_path; |
408 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_file_path)); | 408 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_file_path)); |
409 original_file_path = | 409 original_file_path = |
410 original_file_path.Append(FILE_PATH_LITERAL("serializer_test.json")); | 410 original_file_path.Append(FILE_PATH_LITERAL("serializer_test.json")); |
411 | 411 |
412 ASSERT_TRUE(PathExists(original_file_path)); | 412 ASSERT_TRUE(PathExists(original_file_path)); |
413 | 413 |
414 JSONFileValueDeserializer deserializer(original_file_path); | 414 JSONFileValueDeserializer deserializer(original_file_path); |
415 scoped_ptr<Value> root; | 415 scoped_ptr<Value> root; |
416 root.reset(deserializer.Deserialize(NULL, NULL)); | 416 root = deserializer.Deserialize(NULL, NULL); |
417 | 417 |
418 ASSERT_TRUE(root.get()); | 418 ASSERT_TRUE(root.get()); |
419 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); | 419 ASSERT_TRUE(root->IsType(Value::TYPE_DICTIONARY)); |
420 | 420 |
421 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); | 421 DictionaryValue* root_dict = static_cast<DictionaryValue*>(root.get()); |
422 | 422 |
423 Value* null_value = NULL; | 423 Value* null_value = NULL; |
424 ASSERT_TRUE(root_dict->Get("null", &null_value)); | 424 ASSERT_TRUE(root_dict->Get("null", &null_value)); |
425 ASSERT_TRUE(null_value); | 425 ASSERT_TRUE(null_value); |
426 ASSERT_TRUE(null_value->IsType(Value::TYPE_NULL)); | 426 ASSERT_TRUE(null_value->IsType(Value::TYPE_NULL)); |
(...skipping 27 matching lines...) Expand all Loading... |
454 TEST_F(JSONFileValueSerializerTest, RoundtripNested) { | 454 TEST_F(JSONFileValueSerializerTest, RoundtripNested) { |
455 base::FilePath original_file_path; | 455 base::FilePath original_file_path; |
456 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_file_path)); | 456 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &original_file_path)); |
457 original_file_path = original_file_path.Append( | 457 original_file_path = original_file_path.Append( |
458 FILE_PATH_LITERAL("serializer_nested_test.json")); | 458 FILE_PATH_LITERAL("serializer_nested_test.json")); |
459 | 459 |
460 ASSERT_TRUE(PathExists(original_file_path)); | 460 ASSERT_TRUE(PathExists(original_file_path)); |
461 | 461 |
462 JSONFileValueDeserializer deserializer(original_file_path); | 462 JSONFileValueDeserializer deserializer(original_file_path); |
463 scoped_ptr<Value> root; | 463 scoped_ptr<Value> root; |
464 root.reset(deserializer.Deserialize(NULL, NULL)); | 464 root = deserializer.Deserialize(NULL, NULL); |
465 ASSERT_TRUE(root.get()); | 465 ASSERT_TRUE(root.get()); |
466 | 466 |
467 // Now try writing. | 467 // Now try writing. |
468 base::FilePath written_file_path = temp_dir_.path().Append( | 468 base::FilePath written_file_path = temp_dir_.path().Append( |
469 FILE_PATH_LITERAL("test_output.json")); | 469 FILE_PATH_LITERAL("test_output.json")); |
470 | 470 |
471 ASSERT_FALSE(PathExists(written_file_path)); | 471 ASSERT_FALSE(PathExists(written_file_path)); |
472 JSONFileValueSerializer serializer(written_file_path); | 472 JSONFileValueSerializer serializer(written_file_path); |
473 ASSERT_TRUE(serializer.Serialize(*root)); | 473 ASSERT_TRUE(serializer.Serialize(*root)); |
474 ASSERT_TRUE(PathExists(written_file_path)); | 474 ASSERT_TRUE(PathExists(written_file_path)); |
475 | 475 |
476 // Now compare file contents. | 476 // Now compare file contents. |
477 EXPECT_TRUE(TextContentsEqual(original_file_path, written_file_path)); | 477 EXPECT_TRUE(TextContentsEqual(original_file_path, written_file_path)); |
478 EXPECT_TRUE(base::DeleteFile(written_file_path, false)); | 478 EXPECT_TRUE(base::DeleteFile(written_file_path, false)); |
479 } | 479 } |
480 | 480 |
481 TEST_F(JSONFileValueSerializerTest, NoWhitespace) { | 481 TEST_F(JSONFileValueSerializerTest, NoWhitespace) { |
482 base::FilePath source_file_path; | 482 base::FilePath source_file_path; |
483 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &source_file_path)); | 483 ASSERT_TRUE(PathService::Get(DIR_TEST_DATA, &source_file_path)); |
484 source_file_path = source_file_path.Append( | 484 source_file_path = source_file_path.Append( |
485 FILE_PATH_LITERAL("serializer_test_nowhitespace.json")); | 485 FILE_PATH_LITERAL("serializer_test_nowhitespace.json")); |
486 ASSERT_TRUE(PathExists(source_file_path)); | 486 ASSERT_TRUE(PathExists(source_file_path)); |
487 JSONFileValueDeserializer deserializer(source_file_path); | 487 JSONFileValueDeserializer deserializer(source_file_path); |
488 scoped_ptr<Value> root; | 488 scoped_ptr<Value> root; |
489 root.reset(deserializer.Deserialize(NULL, NULL)); | 489 root = deserializer.Deserialize(NULL, NULL); |
490 ASSERT_TRUE(root.get()); | 490 ASSERT_TRUE(root.get()); |
491 } | 491 } |
492 | 492 |
493 } // namespace | 493 } // namespace |
494 | 494 |
495 } // namespace base | 495 } // namespace base |
OLD | NEW |