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

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

Issue 147220: Use platform-appropriate newlines in JSON output (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 | « base/json_writer_unittest.cc ('k') | chrome/common/pref_service_unittest.cc » ('j') | 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/json_reader.h" 7 #include "base/json_reader.h"
8 #include "base/json_writer.h" 8 #include "base/json_writer.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 // Now try writing. 286 // Now try writing.
287 const FilePath written_file_path = 287 const FilePath written_file_path =
288 test_dir_.Append(FILE_PATH_LITERAL("test_output.js")); 288 test_dir_.Append(FILE_PATH_LITERAL("test_output.js"));
289 289
290 ASSERT_FALSE(file_util::PathExists(written_file_path)); 290 ASSERT_FALSE(file_util::PathExists(written_file_path));
291 JSONFileValueSerializer serializer(written_file_path); 291 JSONFileValueSerializer serializer(written_file_path);
292 ASSERT_TRUE(serializer.Serialize(*root)); 292 ASSERT_TRUE(serializer.Serialize(*root));
293 ASSERT_TRUE(file_util::PathExists(written_file_path)); 293 ASSERT_TRUE(file_util::PathExists(written_file_path));
294 294
295 // Now compare file contents. 295 // Now compare file contents.
296 EXPECT_TRUE(file_util::ContentsEqual(original_file_path, written_file_path)); 296 EXPECT_TRUE(file_util::TextContentsEqual(original_file_path,
297 written_file_path));
297 EXPECT_TRUE(file_util::Delete(written_file_path, false)); 298 EXPECT_TRUE(file_util::Delete(written_file_path, false));
298 } 299 }
299 300
300 TEST_F(JSONFileValueSerializerTest, RoundtripNested) { 301 TEST_F(JSONFileValueSerializerTest, RoundtripNested) {
301 FilePath original_file_path; 302 FilePath original_file_path;
302 ASSERT_TRUE( 303 ASSERT_TRUE(
303 PathService::Get(chrome::DIR_TEST_DATA, &original_file_path)); 304 PathService::Get(chrome::DIR_TEST_DATA, &original_file_path));
304 original_file_path = 305 original_file_path =
305 original_file_path.Append(FILE_PATH_LITERAL("serializer_nested_test.js")); 306 original_file_path.Append(FILE_PATH_LITERAL("serializer_nested_test.js"));
306 307
307 ASSERT_TRUE(file_util::PathExists(original_file_path)); 308 ASSERT_TRUE(file_util::PathExists(original_file_path));
308 309
309 JSONFileValueSerializer deserializer(original_file_path); 310 JSONFileValueSerializer deserializer(original_file_path);
310 scoped_ptr<Value> root; 311 scoped_ptr<Value> root;
311 root.reset(deserializer.Deserialize(NULL)); 312 root.reset(deserializer.Deserialize(NULL));
312 ASSERT_TRUE(root.get()); 313 ASSERT_TRUE(root.get());
313 314
314 // Now try writing. 315 // Now try writing.
315 FilePath written_file_path = 316 FilePath written_file_path =
316 test_dir_.Append(FILE_PATH_LITERAL("test_output.js")); 317 test_dir_.Append(FILE_PATH_LITERAL("test_output.js"));
317 318
318 ASSERT_FALSE(file_util::PathExists(written_file_path)); 319 ASSERT_FALSE(file_util::PathExists(written_file_path));
319 JSONFileValueSerializer serializer(written_file_path); 320 JSONFileValueSerializer serializer(written_file_path);
320 ASSERT_TRUE(serializer.Serialize(*root)); 321 ASSERT_TRUE(serializer.Serialize(*root));
321 ASSERT_TRUE(file_util::PathExists(written_file_path)); 322 ASSERT_TRUE(file_util::PathExists(written_file_path));
322 323
323 // Now compare file contents. 324 // Now compare file contents.
324 EXPECT_TRUE(file_util::ContentsEqual(original_file_path, written_file_path)); 325 EXPECT_TRUE(file_util::TextContentsEqual(original_file_path,
326 written_file_path));
325 EXPECT_TRUE(file_util::Delete(written_file_path, false)); 327 EXPECT_TRUE(file_util::Delete(written_file_path, false));
326 } 328 }
327 329
328 TEST_F(JSONFileValueSerializerTest, NoWhitespace) { 330 TEST_F(JSONFileValueSerializerTest, NoWhitespace) {
329 FilePath source_file_path; 331 FilePath source_file_path;
330 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_file_path)); 332 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_file_path));
331 source_file_path = source_file_path.Append( 333 source_file_path = source_file_path.Append(
332 FILE_PATH_LITERAL("serializer_test_nowhitespace.js")); 334 FILE_PATH_LITERAL("serializer_test_nowhitespace.js"));
333 ASSERT_TRUE(file_util::PathExists(source_file_path)); 335 ASSERT_TRUE(file_util::PathExists(source_file_path));
334 JSONFileValueSerializer serializer(source_file_path); 336 JSONFileValueSerializer serializer(source_file_path);
335 scoped_ptr<Value> root; 337 scoped_ptr<Value> root;
336 root.reset(serializer.Deserialize(NULL)); 338 root.reset(serializer.Deserialize(NULL));
337 ASSERT_TRUE(root.get()); 339 ASSERT_TRUE(root.get());
338 } 340 }
OLDNEW
« no previous file with comments | « base/json_writer_unittest.cc ('k') | chrome/common/pref_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698