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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // The JSON file looks like this: | 169 // The JSON file looks like this: |
170 // { | 170 // { |
171 // "homepage": "http://www.cnn.com", | 171 // "homepage": "http://www.cnn.com", |
172 // "some_directory": "/usr/local/", | 172 // "some_directory": "/usr/local/", |
173 // "tabs": { | 173 // "tabs": { |
174 // "new_windows_in_tabs": true, | 174 // "new_windows_in_tabs": true, |
175 // "max_tabs": 20 | 175 // "max_tabs": 20 |
176 // } | 176 // } |
177 // } | 177 // } |
178 | 178 |
179 RunBasicJsonPrefStoreTest(pref_store, | 179 RunBasicJsonPrefStoreTest( |
180 input_file, | 180 pref_store.get(), input_file, data_dir_.AppendASCII("write.golden.json")); |
181 data_dir_.AppendASCII("write.golden.json")); | |
182 } | 181 } |
183 | 182 |
184 TEST_F(JsonPrefStoreTest, BasicAsync) { | 183 TEST_F(JsonPrefStoreTest, BasicAsync) { |
185 ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"), | 184 ASSERT_TRUE(file_util::CopyFile(data_dir_.AppendASCII("read.json"), |
186 temp_dir_.path().AppendASCII("write.json"))); | 185 temp_dir_.path().AppendASCII("write.json"))); |
187 | 186 |
188 // Test that the persistent value can be loaded. | 187 // Test that the persistent value can be loaded. |
189 base::FilePath input_file = temp_dir_.path().AppendASCII("write.json"); | 188 base::FilePath input_file = temp_dir_.path().AppendASCII("write.json"); |
190 ASSERT_TRUE(file_util::PathExists(input_file)); | 189 ASSERT_TRUE(file_util::PathExists(input_file)); |
191 scoped_refptr<JsonPrefStore> pref_store = | 190 scoped_refptr<JsonPrefStore> pref_store = |
(...skipping 19 matching lines...) Expand all Loading... |
211 // The JSON file looks like this: | 210 // The JSON file looks like this: |
212 // { | 211 // { |
213 // "homepage": "http://www.cnn.com", | 212 // "homepage": "http://www.cnn.com", |
214 // "some_directory": "/usr/local/", | 213 // "some_directory": "/usr/local/", |
215 // "tabs": { | 214 // "tabs": { |
216 // "new_windows_in_tabs": true, | 215 // "new_windows_in_tabs": true, |
217 // "max_tabs": 20 | 216 // "max_tabs": 20 |
218 // } | 217 // } |
219 // } | 218 // } |
220 | 219 |
221 RunBasicJsonPrefStoreTest(pref_store, | 220 RunBasicJsonPrefStoreTest( |
222 input_file, | 221 pref_store.get(), input_file, data_dir_.AppendASCII("write.golden.json")); |
223 data_dir_.AppendASCII("write.golden.json")); | |
224 } | 222 } |
225 | 223 |
226 // Tests asynchronous reading of the file when there is no file. | 224 // Tests asynchronous reading of the file when there is no file. |
227 TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { | 225 TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { |
228 base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); | 226 base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); |
229 ASSERT_FALSE(file_util::PathExists(bogus_input_file)); | 227 ASSERT_FALSE(file_util::PathExists(bogus_input_file)); |
230 scoped_refptr<JsonPrefStore> pref_store = | 228 scoped_refptr<JsonPrefStore> pref_store = |
231 new JsonPrefStore( | 229 new JsonPrefStore( |
232 bogus_input_file, message_loop_.message_loop_proxy()); | 230 bogus_input_file, message_loop_.message_loop_proxy()); |
233 MockPrefStoreObserver mock_observer; | 231 MockPrefStoreObserver mock_observer; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 RunLoop().RunUntilIdle(); | 285 RunLoop().RunUntilIdle(); |
288 | 286 |
289 // Compare to expected output. | 287 // Compare to expected output. |
290 base::FilePath golden_output_file = | 288 base::FilePath golden_output_file = |
291 data_dir_.AppendASCII("write.golden.need_empty_value.json"); | 289 data_dir_.AppendASCII("write.golden.need_empty_value.json"); |
292 ASSERT_TRUE(file_util::PathExists(golden_output_file)); | 290 ASSERT_TRUE(file_util::PathExists(golden_output_file)); |
293 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); | 291 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file)); |
294 } | 292 } |
295 | 293 |
296 } // namespace base | 294 } // namespace base |
OLD | NEW |