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

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

Issue 982883002: [Sync] Add size and crc32c to AttachmentId. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with master. Created 5 years, 9 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 4dcc8f86c6ba02b0fba55dd340a6c09963fefe78..2f45b20860bcab8e865342e08ac53b6f3e1cecfc 100644
--- a/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
+++ b/sync/internal_api/attachments/on_disk_attachment_store_unittest.cc
@@ -311,8 +311,9 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, RecordMetadata) {
VerifyAttachmentRecordsPresent(attachments[1].GetId(), true);
}
-// Ensure that attachment store fails to load attachment with mismatched crc.
-TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrc) {
+// Ensure that attachment store fails to load attachment if the crc in the store
+// does not match the data.
+TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrcInStore) {
// Create attachment store.
AttachmentStore::Result create_result = AttachmentStore::UNSPECIFIED_ERROR;
store_ = AttachmentStore::CreateOnDiskStore(
@@ -322,10 +323,12 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrc) {
// Write attachment with incorrect crc32c.
AttachmentStore::Result write_result = AttachmentStore::UNSPECIFIED_ERROR;
const uint32_t intentionally_wrong_crc32c = 0;
- std::string some_data("data1");
+
+ scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString());
+ some_data->data() = "data1";
Attachment attachment = Attachment::CreateFromParts(
- AttachmentId::Create(), base::RefCountedString::TakeString(&some_data),
- intentionally_wrong_crc32c);
+ AttachmentId::Create(some_data->size(), intentionally_wrong_crc32c),
+ some_data);
AttachmentList attachments;
attachments.push_back(attachment);
store_->Write(attachments,
@@ -348,6 +351,44 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrc) {
EXPECT_THAT(failed_attachment_ids, testing::ElementsAre(attachment.GetId()));
}
+// Ensure that attachment store fails to load attachment if the crc in the id
+// does not match the data.
+TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrcInId) {
+ // Create attachment store.
+ AttachmentStore::Result create_result = AttachmentStore::UNSPECIFIED_ERROR;
+ store_ = AttachmentStore::CreateOnDiskStore(
+ temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(),
+ base::Bind(&AttachmentStoreCreated, &create_result));
+
+ AttachmentStore::Result write_result = AttachmentStore::UNSPECIFIED_ERROR;
+ scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString());
+ some_data->data() = "data1";
+ Attachment attachment = Attachment::Create(some_data);
+ AttachmentList attachments;
+ attachments.push_back(attachment);
+ store_->Write(attachments,
+ base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
+ base::Unretained(this), &write_result));
+
+ // Read, but with the wrong crc32c in the id.
+ AttachmentStore::Result read_result = AttachmentStore::SUCCESS;
+
+ AttachmentId id_with_bad_crc32c =
+ AttachmentId::Create(attachment.GetId().GetSize(), 12345);
+ AttachmentIdList attachment_ids;
+ attachment_ids.push_back(id_with_bad_crc32c);
+ AttachmentIdList failed_attachment_ids;
+ store_->Read(
+ attachment_ids,
+ base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultAttachments,
+ base::Unretained(this), &read_result, &failed_attachment_ids));
+ RunLoop();
+ EXPECT_EQ(AttachmentStore::SUCCESS, create_result);
+ EXPECT_EQ(AttachmentStore::SUCCESS, write_result);
+ EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, read_result);
+ EXPECT_THAT(failed_attachment_ids, testing::ElementsAre(id_with_bad_crc32c));
+}
+
// Ensure that after store initialization failure ReadWrite/Drop operations fail
// with correct error.
TEST_F(OnDiskAttachmentStoreSpecificTest, OpsAfterInitializationFailed) {
@@ -365,7 +406,10 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, OpsAfterInitializationFailed) {
// STORE_INITIALIZATION_FAILED.
AttachmentStore::Result read_result = AttachmentStore::SUCCESS;
AttachmentIdList attachment_ids;
- attachment_ids.push_back(AttachmentId::Create());
+ std::string some_data("data1");
+ Attachment attachment =
+ Attachment::Create(base::RefCountedString::TakeString(&some_data));
+ attachment_ids.push_back(attachment.GetId());
AttachmentIdList failed_attachment_ids;
store_->Read(
attachment_ids,
@@ -382,11 +426,8 @@ TEST_F(OnDiskAttachmentStoreSpecificTest, OpsAfterInitializationFailed) {
// Writing to uninitialized store should result in
// STORE_INITIALIZATION_FAILED.
AttachmentStore::Result write_result = AttachmentStore::SUCCESS;
- std::string some_data;
AttachmentList attachments;
- some_data = "data1";
- attachments.push_back(
- Attachment::Create(base::RefCountedString::TakeString(&some_data)));
+ attachments.push_back(attachment);
store_->Write(attachments,
base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
base::Unretained(this), &write_result));

Powered by Google App Engine
This is Rietveld 408576698