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..b33a9831914c9802a3476cca49ca65d34f8d5757 100644 |
--- a/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc |
+++ b/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc |
@@ -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 = |
@@ -313,4 +315,41 @@ 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()); |
+ |
+ // 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 with incorrect crc32c. |
+ const uint32_t intentionally_wrong_crc32c = 0; |
+ std::string some_data("data1"); |
+ Attachment attachment = Attachment::CreateFromParts( |
+ AttachmentId::Create(), base::RefCountedString::TakeString(&some_data), |
+ intentionally_wrong_crc32c); |
+ 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 |