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

Unified Diff: content/browser/indexed_db/leveldb/leveldb_unittest.cc

Issue 2708223002: IndexedDB: Optimize range deletion operations (e.g. clearing a store) (Closed)
Patch Set: Created 3 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
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_transaction_unittest.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/indexed_db/leveldb/leveldb_unittest.cc
diff --git a/content/browser/indexed_db/leveldb/leveldb_unittest.cc b/content/browser/indexed_db/leveldb/leveldb_unittest.cc
index 1ce48cb457ce54b66604a9edc120cede12435845..379a6ba484b09f2123a3d6dd131b730df4dee93e 100644
--- a/content/browser/indexed_db/leveldb/leveldb_unittest.cc
+++ b/content/browser/indexed_db/leveldb/leveldb_unittest.cc
@@ -11,13 +11,10 @@
#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "content/browser/indexed_db/leveldb/leveldb_comparator.h"
#include "content/browser/indexed_db/leveldb/leveldb_database.h"
#include "content/browser/indexed_db/leveldb/leveldb_env.h"
-#include "content/browser/indexed_db/leveldb/leveldb_iterator.h"
-#include "content/browser/indexed_db/leveldb/leveldb_transaction.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/leveldatabase/env_chromium.h"
@@ -89,162 +86,6 @@ TEST(LevelDBDatabaseTest, CorruptionTest) {
EXPECT_FALSE(found);
}
-TEST(LevelDBDatabaseTest, Transaction) {
- base::ScopedTempDir temp_directory;
- ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
-
- const std::string key("key");
- std::string got_value;
- std::string put_value;
- SimpleComparator comparator;
-
- std::unique_ptr<LevelDBDatabase> leveldb;
- LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
- EXPECT_TRUE(leveldb);
-
- const std::string old_value("value");
- put_value = old_value;
- leveldb::Status status = leveldb->Put(key, &put_value);
- EXPECT_TRUE(status.ok());
-
- scoped_refptr<LevelDBTransaction> transaction =
- new LevelDBTransaction(leveldb.get());
-
- const std::string new_value("new value");
- put_value = new_value;
- status = leveldb->Put(key, &put_value);
- EXPECT_TRUE(status.ok());
-
- bool found = false;
- status = transaction->Get(key, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_TRUE(found);
- EXPECT_EQ(comparator.Compare(got_value, old_value), 0);
-
- found = false;
- status = leveldb->Get(key, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_TRUE(found);
- EXPECT_EQ(comparator.Compare(got_value, new_value), 0);
-
- const std::string added_key("added key");
- const std::string added_value("added value");
- put_value = added_value;
- status = leveldb->Put(added_key, &put_value);
- EXPECT_TRUE(status.ok());
-
- status = leveldb->Get(added_key, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_TRUE(found);
- EXPECT_EQ(comparator.Compare(got_value, added_value), 0);
-
- status = transaction->Get(added_key, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_FALSE(found);
-
- const std::string another_key("another key");
- const std::string another_value("another value");
- put_value = another_value;
- transaction->Put(another_key, &put_value);
-
- status = transaction->Get(another_key, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_TRUE(found);
- EXPECT_EQ(comparator.Compare(got_value, another_value), 0);
-}
-
-TEST(LevelDBDatabaseTest, TransactionIterator) {
- base::ScopedTempDir temp_directory;
- ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
-
- const std::string key1("key1");
- const std::string value1("value1");
- const std::string key2("key2");
- const std::string value2("value2");
- std::string put_value;
- SimpleComparator comparator;
-
- std::unique_ptr<LevelDBDatabase> leveldb;
- LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
- EXPECT_TRUE(leveldb);
-
- put_value = value1;
- leveldb::Status s = leveldb->Put(key1, &put_value);
- EXPECT_TRUE(s.ok());
- put_value = value2;
- s = leveldb->Put(key2, &put_value);
- EXPECT_TRUE(s.ok());
-
- scoped_refptr<LevelDBTransaction> transaction =
- new LevelDBTransaction(leveldb.get());
-
- s = leveldb->Remove(key2);
- EXPECT_TRUE(s.ok());
-
- std::unique_ptr<LevelDBIterator> it = transaction->CreateIterator();
-
- it->Seek(std::string());
-
- EXPECT_TRUE(it->IsValid());
- EXPECT_EQ(comparator.Compare(it->Key(), key1), 0);
- EXPECT_EQ(comparator.Compare(it->Value(), value1), 0);
-
- it->Next();
-
- EXPECT_TRUE(it->IsValid());
- EXPECT_EQ(comparator.Compare(it->Key(), key2), 0);
- EXPECT_EQ(comparator.Compare(it->Value(), value2), 0);
-
- it->Next();
-
- EXPECT_FALSE(it->IsValid());
-}
-
-TEST(LevelDBDatabaseTest, TransactionCommitTest) {
- base::ScopedTempDir temp_directory;
- ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
-
- const std::string key1("key1");
- const std::string key2("key2");
- const std::string value1("value1");
- const std::string value2("value2");
- const std::string value3("value3");
-
- std::string put_value;
- std::string got_value;
- SimpleComparator comparator;
- bool found;
-
- std::unique_ptr<LevelDBDatabase> leveldb;
- LevelDBDatabase::Open(temp_directory.GetPath(), &comparator, &leveldb);
- EXPECT_TRUE(leveldb);
-
- scoped_refptr<LevelDBTransaction> transaction =
- new LevelDBTransaction(leveldb.get());
-
- put_value = value1;
- transaction->Put(key1, &put_value);
-
- put_value = value2;
- transaction->Put(key2, &put_value);
-
- put_value = value3;
- transaction->Put(key2, &put_value);
-
- leveldb::Status status = transaction->Commit();
- EXPECT_TRUE(status.ok());
-
- status = leveldb->Get(key1, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_TRUE(found);
- EXPECT_EQ(value1, got_value);
-
- status = leveldb->Get(key2, &got_value, &found);
- EXPECT_TRUE(status.ok());
- EXPECT_TRUE(found);
- EXPECT_EQ(value3, got_value);
-}
-
TEST(LevelDB, Locking) {
base::ScopedTempDir temp_directory;
ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
« no previous file with comments | « content/browser/indexed_db/leveldb/leveldb_transaction_unittest.cc ('k') | content/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698