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

Unified Diff: base/prefs/leveldb_pref_store_unittest.cc

Issue 169323003: Implementation of leveldb-backed PrefStore (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« base/prefs/leveldb_pref_store.cc ('K') | « base/prefs/leveldb_pref_store.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/prefs/leveldb_pref_store_unittest.cc
diff --git a/base/prefs/leveldb_pref_store_unittest.cc b/base/prefs/leveldb_pref_store_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..db8ae8985b2e21200711ad758969239e0373bd9e
--- /dev/null
+++ b/base/prefs/leveldb_pref_store_unittest.cc
@@ -0,0 +1,78 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/prefs/leveldb_pref_store.h"
+
+#include "base/file_util.h"
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 unused?
dgrogan 2014/02/25 03:32:08 Needed for PathExists.
+#include "base/files/scoped_temp_dir.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/path_service.h"
+#include "base/run_loop.h"
+#include "base/strings/string_number_conversions.h"
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 unused?
dgrogan 2014/02/25 03:32:08 Done.
+#include "base/strings/string_util.h"
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 unused?
dgrogan 2014/02/25 03:32:08 Done.
+#include "base/threading/sequenced_worker_pool.h"
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 unused?
dgrogan 2014/02/25 03:32:08 Done.
+#include "base/threading/thread.h"
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 unused?
dgrogan 2014/02/25 03:32:08 Done.
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace base {
+
+class LevelDBPrefStoreTest : public testing::Test {
+ protected:
+ virtual void SetUp() OVERRIDE {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+
+ ASSERT_TRUE(PathService::Get(base::DIR_TEST_DATA, &data_dir_));
+ data_dir_ = data_dir_.AppendASCII("prefs");
+ ASSERT_TRUE(PathExists(data_dir_));
+ }
+
+ void Open() {
+ pref_store_ = new LevelDBPrefStore(
+ temp_dir_.path(), message_loop_.message_loop_proxy().get());
+ DCHECK_EQ(LevelDBPrefStore::PREF_READ_ERROR_NONE, pref_store_->ReadPrefs());
+ }
+
+ void CloseAndReopen() {
+ pref_store_ = NULL;
+ Open();
+ }
+
+ // The path to temporary directory used to contain the test operations.
+ base::ScopedTempDir temp_dir_;
+ // The path to the directory where the test data is stored in the source tree.
+ base::FilePath data_dir_;
+ // A message loop that we can use as the file thread message loop.
+ MessageLoop message_loop_;
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 #include "base/message_loop/message_loop.h"
dgrogan 2014/02/25 03:32:08 Done.
+
+ scoped_refptr<LevelDBPrefStore> pref_store_;
+};
+
+TEST_F(LevelDBPrefStoreTest, PutAndGet) {
+ Open();
+ const std::string key = "some.key";
+ base::Value* value = new FundamentalValue(5);
+ pref_store_->SetValue(key, value);
+ RunLoop().RunUntilIdle();
+ const base::Value* actual_value;
+ EXPECT_TRUE(pref_store_->GetValue(key, &actual_value));
+ EXPECT_TRUE(value->Equals(actual_value));
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 This is dangerous, value is now owned by pref_stor
dgrogan 2014/02/25 03:32:08 Fixed.
+}
+
+TEST_F(LevelDBPrefStoreTest, PutAndGetPersistent) {
+ Open();
+ const std::string key = "some.key";
+ base::Value* value = new FundamentalValue(5);
+ pref_store_->SetValue(key, value);
+ RunLoop().RunUntilIdle();
+
+ CloseAndReopen();
+ const base::Value* actual_value = NULL;
+ value = new FundamentalValue(5);
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 |value| leaks.
dgrogan 2014/02/25 03:32:08 Done.
+ EXPECT_TRUE(pref_store_->GetValue(key, &actual_value));
+ EXPECT_TRUE(base::Value::Equals(value, actual_value));
+}
Mattias Nissler (ping if slow) 2014/02/24 09:00:40 I'd like to see more tests, in particular covering
dgrogan 2014/02/25 03:32:08 Included today is everything except various types
+
+} // namespace base
« base/prefs/leveldb_pref_store.cc ('K') | « base/prefs/leveldb_pref_store.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698