| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" |
| 7 #include "base/json/json_file_value_serializer.h" | 8 #include "base/json/json_file_value_serializer.h" |
| 8 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 9 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 10 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 11 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 12 #include "base/scoped_temp_dir.h" | |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 TEST(JSONValueSerializerTest, Roundtrip) { | 20 TEST(JSONValueSerializerTest, Roundtrip) { |
| 21 const std::string original_serialization = | 21 const std::string original_serialization = |
| 22 "{\"bool\":true,\"double\":3.14,\"int\":42,\"list\":[1,2],\"null\":null}"; | 22 "{\"bool\":true,\"double\":3.14,\"int\":42,\"list\":[1,2],\"null\":null}"; |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 237 root.reset(base::JSONReader::Read("/ * * / [1]")); | 237 root.reset(base::JSONReader::Read("/ * * / [1]")); |
| 238 ASSERT_FALSE(root.get()); | 238 ASSERT_FALSE(root.get()); |
| 239 } | 239 } |
| 240 | 240 |
| 241 class JSONFileValueSerializerTest : public testing::Test { | 241 class JSONFileValueSerializerTest : public testing::Test { |
| 242 protected: | 242 protected: |
| 243 virtual void SetUp() { | 243 virtual void SetUp() { |
| 244 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 244 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| 245 } | 245 } |
| 246 | 246 |
| 247 ScopedTempDir temp_dir_; | 247 base::ScopedTempDir temp_dir_; |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 TEST_F(JSONFileValueSerializerTest, Roundtrip) { | 250 TEST_F(JSONFileValueSerializerTest, Roundtrip) { |
| 251 FilePath original_file_path; | 251 FilePath original_file_path; |
| 252 ASSERT_TRUE( | 252 ASSERT_TRUE( |
| 253 PathService::Get(chrome::DIR_TEST_DATA, &original_file_path)); | 253 PathService::Get(chrome::DIR_TEST_DATA, &original_file_path)); |
| 254 original_file_path = | 254 original_file_path = |
| 255 original_file_path.Append(FILE_PATH_LITERAL("serializer_test.js")); | 255 original_file_path.Append(FILE_PATH_LITERAL("serializer_test.js")); |
| 256 | 256 |
| 257 ASSERT_TRUE(file_util::PathExists(original_file_path)); | 257 ASSERT_TRUE(file_util::PathExists(original_file_path)); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 FilePath source_file_path; | 330 FilePath source_file_path; |
| 331 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_file_path)); | 331 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &source_file_path)); |
| 332 source_file_path = source_file_path.Append( | 332 source_file_path = source_file_path.Append( |
| 333 FILE_PATH_LITERAL("serializer_test_nowhitespace.js")); | 333 FILE_PATH_LITERAL("serializer_test_nowhitespace.js")); |
| 334 ASSERT_TRUE(file_util::PathExists(source_file_path)); | 334 ASSERT_TRUE(file_util::PathExists(source_file_path)); |
| 335 JSONFileValueSerializer serializer(source_file_path); | 335 JSONFileValueSerializer serializer(source_file_path); |
| 336 scoped_ptr<Value> root; | 336 scoped_ptr<Value> root; |
| 337 root.reset(serializer.Deserialize(NULL, NULL)); | 337 root.reset(serializer.Deserialize(NULL, NULL)); |
| 338 ASSERT_TRUE(root.get()); | 338 ASSERT_TRUE(root.get()); |
| 339 } | 339 } |
| OLD | NEW |