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/file_util.h" | 5 #include "base/file_util.h" |
| 6 #include "base/files/scoped_temp_dir.h" |
6 #include "base/memory/ref_counted.h" | 7 #include "base/memory/ref_counted.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
8 #include "base/path_service.h" | 9 #include "base/path_service.h" |
9 #include "base/prefs/json_pref_store.h" | 10 #include "base/prefs/json_pref_store.h" |
10 #include "base/scoped_temp_dir.h" | |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.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 "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 17 matching lines...) Expand all Loading... |
38 protected: | 38 protected: |
39 virtual void SetUp() OVERRIDE { | 39 virtual void SetUp() OVERRIDE { |
40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 40 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
41 | 41 |
42 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); | 42 ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &data_dir_)); |
43 data_dir_ = data_dir_.AppendASCII("pref_service"); | 43 data_dir_ = data_dir_.AppendASCII("pref_service"); |
44 ASSERT_TRUE(file_util::PathExists(data_dir_)); | 44 ASSERT_TRUE(file_util::PathExists(data_dir_)); |
45 } | 45 } |
46 | 46 |
47 // The path to temporary directory used to contain the test operations. | 47 // The path to temporary directory used to contain the test operations. |
48 ScopedTempDir temp_dir_; | 48 base::ScopedTempDir temp_dir_; |
49 // The path to the directory where the test data is stored. | 49 // The path to the directory where the test data is stored. |
50 FilePath data_dir_; | 50 FilePath data_dir_; |
51 // A message loop that we can use as the file thread message loop. | 51 // A message loop that we can use as the file thread message loop. |
52 MessageLoop message_loop_; | 52 MessageLoop message_loop_; |
53 }; | 53 }; |
54 | 54 |
55 // Test fallback behavior for a nonexistent file. | 55 // Test fallback behavior for a nonexistent file. |
56 TEST_F(JsonPrefStoreTest, NonExistentFile) { | 56 TEST_F(JsonPrefStoreTest, NonExistentFile) { |
57 FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); | 57 FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); |
58 ASSERT_FALSE(file_util::PathExists(bogus_input_file)); | 58 ASSERT_FALSE(file_util::PathExists(bogus_input_file)); |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 // Write to file. | 285 // Write to file. |
286 pref_store->CommitPendingWrite(); | 286 pref_store->CommitPendingWrite(); |
287 MessageLoop::current()->RunUntilIdle(); | 287 MessageLoop::current()->RunUntilIdle(); |
288 | 288 |
289 // Compare to expected output. | 289 // Compare to expected output. |
290 FilePath golden_output_file = | 290 FilePath golden_output_file = |
291 data_dir_.AppendASCII("write.golden.need_empty_value.json"); | 291 data_dir_.AppendASCII("write.golden.need_empty_value.json"); |
292 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 292 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
293 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); | 293 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); |
294 } | 294 } |
OLD | NEW |