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

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: Created 6 years, 11 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 | base/test/data/prefs/remove.golden.json » ('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) 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 TEST_F(JsonPrefStoreTest, Remove) {
261 ASSERT_TRUE(base::CopyFile(data_dir_.AppendASCII("remove.original.json"),
262 temp_dir_.path().AppendASCII("remove.json")));
263 base::FilePath input_output_file =
264 temp_dir_.path().AppendASCII("remove.json");
265 ASSERT_TRUE(PathExists(input_output_file));
266 scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
267 input_output_file,
268 message_loop_.message_loop_proxy().get(),
269 scoped_ptr<PrefFilter>());
270 ASSERT_EQ(PersistentPrefStore::PREF_READ_ERROR_NONE, pref_store->ReadPrefs());
271 ASSERT_FALSE(pref_store->ReadOnly());
Mattias Nissler (ping if slow) 2014/01/23 09:07:54 Reading this code, I have no idea what the test is
272
273 pref_store->RemoveValue("long_int.pref");
274
275 pref_store->CommitPendingWrite();
276 RunLoop().RunUntilIdle();
277
278 base::FilePath golden_output_file =
279 data_dir_.AppendASCII("remove.golden.json");
280 EXPECT_TRUE(TextContentsEqual(golden_output_file, input_output_file));
281 }
282
260 // Tests asynchronous reading of the file when there is no file. 283 // Tests asynchronous reading of the file when there is no file.
261 TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) { 284 TEST_F(JsonPrefStoreTest, AsyncNonExistingFile) {
262 base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt"); 285 base::FilePath bogus_input_file = data_dir_.AppendASCII("read.txt");
263 ASSERT_FALSE(PathExists(bogus_input_file)); 286 ASSERT_FALSE(PathExists(bogus_input_file));
264 scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore( 287 scoped_refptr<JsonPrefStore> pref_store = new JsonPrefStore(
265 bogus_input_file, 288 bogus_input_file,
266 message_loop_.message_loop_proxy().get(), 289 message_loop_.message_loop_proxy().get(),
267 scoped_ptr<PrefFilter>()); 290 scoped_ptr<PrefFilter>());
268 MockPrefStoreObserver mock_observer; 291 MockPrefStoreObserver mock_observer;
269 pref_store->AddObserver(&mock_observer); 292 pref_store->AddObserver(&mock_observer);
270 293
271 MockReadErrorDelegate *mock_error_delegate = new MockReadErrorDelegate; 294 MockReadErrorDelegate *mock_error_delegate = new MockReadErrorDelegate;
272 pref_store->ReadPrefsAsync(mock_error_delegate); 295 pref_store->ReadPrefsAsync(mock_error_delegate);
273 296
274 EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1); 297 EXPECT_CALL(mock_observer, OnInitializationCompleted(true)).Times(1);
275 EXPECT_CALL(*mock_error_delegate, 298 EXPECT_CALL(*mock_error_delegate,
276 OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1); 299 OnError(PersistentPrefStore::PREF_READ_ERROR_NO_FILE)).Times(1);
277 RunLoop().RunUntilIdle(); 300 RunLoop().RunUntilIdle();
278 pref_store->RemoveObserver(&mock_observer); 301 pref_store->RemoveObserver(&mock_observer);
279 302
280 EXPECT_FALSE(pref_store->ReadOnly()); 303 EXPECT_FALSE(pref_store->ReadOnly());
281 } 304 }
282 305
283 } // namespace base 306 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/test/data/prefs/remove.golden.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698