| 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/prefs/json_pref_store.h" | 5 #include "base/prefs/json_pref_store.h" |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 EXPECT_TRUE(actual->GetAsString(&string_value)); | 141 EXPECT_TRUE(actual->GetAsString(&string_value)); |
| 142 int64 value; | 142 int64 value; |
| 143 base::StringToInt64(string_value, &value); | 143 base::StringToInt64(string_value, &value); |
| 144 EXPECT_EQ(214748364842LL, value); | 144 EXPECT_EQ(214748364842LL, value); |
| 145 | 145 |
| 146 // Serialize and compare to expected output. | 146 // Serialize and compare to expected output. |
| 147 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 147 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
| 148 pref_store->CommitPendingWrite(); | 148 pref_store->CommitPendingWrite(); |
| 149 RunLoop().RunUntilIdle(); | 149 RunLoop().RunUntilIdle(); |
| 150 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); | 150 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, output_file)); |
| 151 ASSERT_TRUE(file_util::Delete(output_file, false)); | 151 ASSERT_TRUE(base::Delete(output_file, false)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 TEST_F(JsonPrefStoreTest, Basic) { | 154 TEST_F(JsonPrefStoreTest, Basic) { |
| 155 ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"), | 155 ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"), |
| 156 temp_dir_.path().AppendASCII("write.json"))); | 156 temp_dir_.path().AppendASCII("write.json"))); |
| 157 | 157 |
| 158 // Test that the persistent value can be loaded. | 158 // Test that the persistent value can be loaded. |
| 159 base::FilePath input_file = temp_dir_.path().AppendASCII("write.json"); | 159 base::FilePath input_file = temp_dir_.path().AppendASCII("write.json"); |
| 160 ASSERT_TRUE(file_util::PathExists(input_file)); | 160 ASSERT_TRUE(file_util::PathExists(input_file)); |
| 161 scoped_refptr<JsonPrefStore> pref_store = | 161 scoped_refptr<JsonPrefStore> pref_store = |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 RunLoop().RunUntilIdle(); | 279 RunLoop().RunUntilIdle(); |
| 280 | 280 |
| 281 // Compare to expected output. | 281 // Compare to expected output. |
| 282 base::FilePath golden_output_file = | 282 base::FilePath golden_output_file = |
| 283 data_dir_.AppendASCII("write.golden.need_empty_value.json"); | 283 data_dir_.AppendASCII("write.golden.need_empty_value.json"); |
| 284 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 284 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
| 285 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); | 285 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); |
| 286 } | 286 } |
| 287 | 287 |
| 288 } // namespace base | 288 } // namespace base |
| OLD | NEW |