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

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

Issue 710073003: Store attachment crc in AttachmentStore (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 1 month 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 0b0bd5408ef353d4941b1e86a0a516a5f1dfc9f1..369d1ee326a9fee8223766b3b47a9cf05f095424 100644
--- a/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
+++ b/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
@@ -154,7 +154,7 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, CloseAndReopen) {
result = AttachmentStore::UNSPECIFIED_ERROR;
std::string some_data = "data";
Attachment attachment =
- Attachment::Create(base::RefCountedString::TakeString(&some_data));
+ Attachment::CreateNew(base::RefCountedString::TakeString(&some_data));
AttachmentList attachments;
attachments.push_back(attachment);
store_->Write(attachments,
@@ -266,6 +266,8 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, StoreMetadata) {
EXPECT_EQ(store_.get(), nullptr);
}
+// Ensure that attachment store correctly maintains metadata records for
+// attachments.
TEST_F(OnDiskAttachmentStoreSpecificTest, RecordMetadata) {
ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
base::FilePath db_path =
@@ -285,10 +287,10 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, RecordMetadata) {
AttachmentList attachments;
some_data = "data1";
attachments.push_back(
- Attachment::Create(base::RefCountedString::TakeString(&some_data)));
+ Attachment::CreateNew(base::RefCountedString::TakeString(&some_data)));
some_data = "data2";
attachments.push_back(
- Attachment::Create(base::RefCountedString::TakeString(&some_data)));
+ Attachment::CreateNew(base::RefCountedString::TakeString(&some_data)));
store_->Write(attachments,
base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
base::Unretained(this),
@@ -313,4 +315,42 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, RecordMetadata) {
VerifyAttachmentRecordsPresent(db_path, attachments[1].GetId(), true);
}
+// Ensure that attachment store fails to load attachment with mismatched crc.
+TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrc) {
+ ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
+ // base::FilePath db_path =
maniscalco 2014/11/11 00:44:54 Left over from a previous revision?
pavely 2014/11/11 22:27:15 Done.
+ // 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 attachment.
+ std::string some_data("data1");
+ Attachment attachment = Attachment::RestoreExisting(
+ AttachmentId::Create(), base::RefCountedString::TakeString(&some_data),
+ 0);
maniscalco 2014/11/11 00:44:54 Maybe put into a var named intentionally_wrong_crc
pavely 2014/11/11 22:27:15 Done.
+ AttachmentList attachments;
+ attachments.push_back(attachment);
+ store_->Write(attachments,
+ base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
+ base::Unretained(this), &result));
+ RunLoop();
+ EXPECT_EQ(result, AttachmentStore::SUCCESS);
+
+ // Read attachment.
+ AttachmentIdList attachment_ids;
+ attachment_ids.push_back(attachment.GetId());
+ store_->Read(
+ attachment_ids,
+ base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultAttachments,
+ base::Unretained(this), &result));
+ RunLoop();
+ EXPECT_EQ(result, AttachmentStore::UNSPECIFIED_ERROR);
+}
+
} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698