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

Side by Side Diff: base/prefs/json_pref_store_unittest.cc

Issue 144633002: Add a unit test for JsonPrefStore::Remove. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: update name and add comment Created 6 years, 10 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 | « no previous file | no next file » | 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) 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 ASSERT_FALSE(pref_store->ReadOnly()); 250 ASSERT_FALSE(pref_store->ReadOnly());
251 251
252 // Check values. 252 // Check values.
253 const Value* result = NULL; 253 const Value* result = NULL;
254 EXPECT_TRUE(pref_store->GetValue("list", &result)); 254 EXPECT_TRUE(pref_store->GetValue("list", &result));
255 EXPECT_TRUE(ListValue().Equals(result)); 255 EXPECT_TRUE(ListValue().Equals(result));
256 EXPECT_TRUE(pref_store->GetValue("dict", &result)); 256 EXPECT_TRUE(pref_store->GetValue("dict", &result));
257 EXPECT_TRUE(DictionaryValue().Equals(result)); 257 EXPECT_TRUE(DictionaryValue().Equals(result));
258 } 258 }
259 259
260 // This test is just documenting some potentially non-obvious behavior. It
261 // shouldn't be taken as normative.
262 TEST_F(JsonPrefStoreTest, RemoveClearsEmptyParent) {
263 FilePath pref_file = temp_dir_.path().AppendASCII("empty_values.json");
264
265 scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
266 pref_file,
267 message_loop_.message_loop_proxy(),
268 scoped_ptr<PrefFilter>());
269
270 base::DictionaryValue* dict = new base::DictionaryValue;
271 dict->SetString("key", "value");
272 pref_store->SetValue("dict", dict);
273
274 pref_store->RemoveValue("dict.key");
275
276 const base::Value* retrieved_dict = NULL;
277 bool has_dict = pref_store->GetValue("dict", &retrieved_dict);
278 EXPECT_FALSE(has_dict);
279 }
280
260 // Tests asynchronous reading of the file when there is no file. 281 // Tests asynchronous reading of the file when there is no file.
261 TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { 282 TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
262 base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); 283 base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
263 ASSERT_FALSE(PathExists(bogus_input_file)); 284 ASSERT_FALSE(PathExists(bogus_input_file));
264 scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore( 285 scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
265 bogus_input_file, 286 bogus_input_file,
266 message_loop_.message_loop_proxy().get(), 287 message_loop_.message_loop_proxy().get(),
267 scoped_ptr<PrefFilter>()); 288 scoped_ptr<PrefFilter>());
268 MockPrefStoreObserver mock_observer; 289 MockPrefStoreObserver mock_observer;
269 pref_store->AddObserver(&mock_observer); 290 pref_store->AddObserver(&mock_observer);
270 291
271 MockReadErrorDelegate *mock_error_delegate = new MockReadErrorDelegate; 292 MockReadErrorDelegate *mock_error_delegate = new MockReadErrorDelegate;
272 pref_store->ReadPrefsAsync(mock_error_delegate); 293 pref_store->ReadPrefsAsync(mock_error_delegate);
273 294
274 EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); 295 EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1);
275 EXPECT_CALL(*mock_error_delegate, 296 EXPECT_CALL(*mock_error_delegate,
276 OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1); 297 OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1);
277 RunLoop().RunUntilIdle(); 298 RunLoop().RunUntilIdle();
278 pref_store->RemoveObserver(&mock_observer); 299 pref_store->RemoveObserver(&mock_observer);
279 300
280 EXPECT_FALSE(pref_store->ReadOnly()); 301 EXPECT_FALSE(pref_store->ReadOnly());
281 } 302 }
282 303
283 } // namespace base 304 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698