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

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

Issue 10055003: Keep emtpy List/Dictionary pref value with non-empty default. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: for comments in #1 Created 8 years, 8 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 | « chrome/common/json_pref_store.cc ('k') | chrome/common/persistent_pref_store.h » ('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) 2011 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/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_temp_dir.h" 11 #include "base/scoped_temp_dir.h"
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 pref_store->ReadPrefsAsync(mock_error_delegate); 237 pref_store->ReadPrefsAsync(mock_error_delegate);
238 238
239 EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); 239 EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1);
240 EXPECT_CALL(*mock_error_delegate, 240 EXPECT_CALL(*mock_error_delegate,
241 OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1); 241 OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1);
242 message_loop_.RunAllPending(); 242 message_loop_.RunAllPending();
243 pref_store->RemoveObserver(&mock_observer); 243 pref_store->RemoveObserver(&mock_observer);
244 244
245 EXPECT_FALSE(pref_store->ReadOnly()); 245 EXPECT_FALSE(pref_store->ReadOnly());
246 } 246 }
247
248 TEST_F(JsonPrefStoreTest, NeedsEmptyValue) {
249 FilePath pref_file = temp_dir_.path().AppendASCII("write.json");
250
251 ASSERT_TRUE(file_util::CopyFile(
252 data_dir_.AppendASCII("read.need_empty_value.json"),
253 pref_file));
254
255 // Test that the persistent value can be loaded.
256 ASSERT_TRUE(file_util::PathExists(pref_file));
257 scoped_refptr<JsonPrefStore> pref_store =
258 new JsonPrefStore(pref_file, message_loop_proxy_.get());
259 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
260 ASSERT_FALSE(pref_store->ReadOnly());
261
262 // The JSON file looks like this:
263 // {
264 // "list": [ 1 ],
265 // "list_needs_empty_value": [ 2 ],
266 // "dict": {
267 // "dummy": true,
268 // },
269 // "dict_needs_empty_value": {
270 // "dummy": true,
271 // },
272 // }
273
274 // Set flag to preserve empty values for the following keys.
275 pref_store->MarkNeedsEmptyValue("list_needs_empty_value");
276 pref_store->MarkNeedsEmptyValue("dict_needs_empty_value");
277
278 // Set all keys to empty values.
279 pref_store->SetValue("list", new base::ListValue);
280 pref_store->SetValue("list_needs_empty_value", new base::ListValue);
281 pref_store->SetValue("dict", new base::DictionaryValue);
282 pref_store->SetValue("dict_needs_empty_value", new base::DictionaryValue);
283
284 // Write to file.
285 pref_store->CommitPendingWrite();
286 MessageLoop::current()->RunAllPending();
287
288 // Compare to expected output.
289 FilePath golden_output_file =
290 data_dir_.AppendASCII("write.golden.need_empty_value.json");
291 ASSERT_TRUE(file_util::PathExists(golden_output_file));
292 EXPECT_TRUE(file_util::TextContentsEqual(golden_output_file, pref_file));
293 }
OLDNEW
« no previous file with comments | « chrome/common/json_pref_store.cc ('k') | chrome/common/persistent_pref_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698