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

Unified Diff: sync/internal_api/attachments/on_disk_attachment_store_unittest.cc

Issue 690723004: Add per attachment metadata records. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Typo Created 6 years, 2 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
Index: sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
diff --git a/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc b/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
index ded5f0a2ef2a3b029c62e778d570e192f86fb8eb..0b0bd5408ef353d4941b1e86a0a516a5f1dfc9f1 100644
--- a/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
+++ b/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "sync/api/attachments/attachment_store.h"
+#include "sync/internal_api/public/attachments/on_disk_attachment_store.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
@@ -109,6 +109,28 @@ class OnDiskAttachmentStoreSpecificTest : public testing::Test {
return content;
}
+ void VerifyAttachmentRecordsPresent(const base::FilePath& path,
+ const AttachmentId& attachment_id,
+ bool expect_records_present) {
+ scoped_ptr<leveldb::DB> db = OpenLevelDB(path);
+
+ std::string metadata_key =
+ OnDiskAttachmentStore::MakeMetadataKeyFromAttachmentId(attachment_id);
+ std::string data_key =
+ OnDiskAttachmentStore::MakeDataKeyFromAttachmentId(attachment_id);
+ std::string data;
+ leveldb::Status s = db->Get(leveldb::ReadOptions(), data_key, &data);
+ if (expect_records_present)
+ EXPECT_TRUE(s.ok());
+ else
+ EXPECT_TRUE(s.IsNotFound());
+ s = db->Get(leveldb::ReadOptions(), metadata_key, &data);
+ if (expect_records_present)
+ EXPECT_TRUE(s.ok());
+ else
+ EXPECT_TRUE(s.IsNotFound());
+ }
+
void RunLoop() {
base::RunLoop run_loop;
run_loop.RunUntilIdle();
@@ -211,7 +233,7 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, StoreMetadata) {
// AttachmentStore should create metadata record.
std::string data = ReadStoreMetadataRecord(db_path);
- attachment_store_pb::AttachmentStoreMetadata metadata;
+ attachment_store_pb::StoreMetadata metadata;
EXPECT_TRUE(metadata.ParseFromString(data));
EXPECT_EQ(metadata.schema_version(), 1);
@@ -244,4 +266,51 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, StoreMetadata) {
EXPECT_EQ(store_.get(), nullptr);
}
+TEST_F(OnDiskAttachmentStoreSpecificTest, RecordMetadata) {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ base::FilePath db_path =
+ temp_dir_.path().Append(FILE_PATH_LITERAL("leveldb"));
+
+ // Create attachment store.
+ AttachmentStore::Result result = AttachmentStore::UNSPECIFIED_ERROR;
+ AttachmentStore::CreateOnDiskStore(
+ temp_dir_.path(),
+ base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&AttachmentStoreCreated, &store_, &result));
+ RunLoop();
+ EXPECT_EQ(result, AttachmentStore::SUCCESS);
+
+ // Write two attachments.
+ std::string some_data;
+ AttachmentList attachments;
+ some_data = "data1";
+ attachments.push_back(
+ Attachment::Create(base::RefCountedString::TakeString(&some_data)));
+ some_data = "data2";
+ attachments.push_back(
+ Attachment::Create(base::RefCountedString::TakeString(&some_data)));
+ store_->Write(attachments,
+ base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
+ base::Unretained(this),
+ &result));
+ RunLoop();
+ EXPECT_EQ(result, AttachmentStore::SUCCESS);
+
+ // Delete one of written attachments.
+ AttachmentIdList attachment_ids;
+ attachment_ids.push_back(attachments[0].GetId());
+ store_->Drop(attachment_ids,
+ base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
+ base::Unretained(this),
+ &result));
+ RunLoop();
+ EXPECT_EQ(result, AttachmentStore::SUCCESS);
+ store_ = nullptr;
+ RunLoop();
+
+ // Verify that attachment store contains only records for second attachment.
+ VerifyAttachmentRecordsPresent(db_path, attachments[0].GetId(), false);
+ VerifyAttachmentRecordsPresent(db_path, attachments[1].GetId(), true);
+}
+
} // namespace syncer
« no previous file with comments | « sync/internal_api/attachments/on_disk_attachment_store.cc ('k') | sync/internal_api/attachments/proto/attachment_store.proto » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698