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

Side by Side 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: Fix argument evaluation order bug. 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h" 5 #include "sync/internal_api/public/attachments/on_disk_attachment_store.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrc) { 315 TEST_F(OnDiskAttachmentStoreSpecificTest, MismatchedCrc) {
316 // Create attachment store. 316 // Create attachment store.
317 AttachmentStore::Result create_result = AttachmentStore::UNSPECIFIED_ERROR; 317 AttachmentStore::Result create_result = AttachmentStore::UNSPECIFIED_ERROR;
318 store_ = AttachmentStore::CreateOnDiskStore( 318 store_ = AttachmentStore::CreateOnDiskStore(
319 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), 319 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(),
320 base::Bind(&AttachmentStoreCreated, &create_result)); 320 base::Bind(&AttachmentStoreCreated, &create_result));
321 321
322 // Write attachment with incorrect crc32c. 322 // Write attachment with incorrect crc32c.
323 AttachmentStore::Result write_result = AttachmentStore::UNSPECIFIED_ERROR; 323 AttachmentStore::Result write_result = AttachmentStore::UNSPECIFIED_ERROR;
324 const uint32_t intentionally_wrong_crc32c = 0; 324 const uint32_t intentionally_wrong_crc32c = 0;
325 std::string some_data("data1"); 325
326 scoped_refptr<base::RefCountedString> some_data(new base::RefCountedString());
327 some_data->data() = "data1";
326 Attachment attachment = Attachment::CreateFromParts( 328 Attachment attachment = Attachment::CreateFromParts(
327 AttachmentId::Create(), base::RefCountedString::TakeString(&some_data), 329 AttachmentId::Create(some_data->size(), intentionally_wrong_crc32c),
328 intentionally_wrong_crc32c); 330 some_data);
329 AttachmentList attachments; 331 AttachmentList attachments;
330 attachments.push_back(attachment); 332 attachments.push_back(attachment);
331 store_->Write(attachments, 333 store_->Write(attachments,
332 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult, 334 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
333 base::Unretained(this), &write_result)); 335 base::Unretained(this), &write_result));
334 336
335 // Read attachment. 337 // Read attachment.
336 AttachmentStore::Result read_result = AttachmentStore::UNSPECIFIED_ERROR; 338 AttachmentStore::Result read_result = AttachmentStore::UNSPECIFIED_ERROR;
337 AttachmentIdList attachment_ids; 339 AttachmentIdList attachment_ids;
338 attachment_ids.push_back(attachment.GetId()); 340 attachment_ids.push_back(attachment.GetId());
(...skipping 19 matching lines...) Expand all
358 360
359 AttachmentStore::Result create_result = AttachmentStore::SUCCESS; 361 AttachmentStore::Result create_result = AttachmentStore::SUCCESS;
360 store_ = AttachmentStore::CreateOnDiskStore( 362 store_ = AttachmentStore::CreateOnDiskStore(
361 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(), 363 temp_dir_.path(), base::ThreadTaskRunnerHandle::Get(),
362 base::Bind(&AttachmentStoreCreated, &create_result)); 364 base::Bind(&AttachmentStoreCreated, &create_result));
363 365
364 // Reading from uninitialized store should result in 366 // Reading from uninitialized store should result in
365 // STORE_INITIALIZATION_FAILED. 367 // STORE_INITIALIZATION_FAILED.
366 AttachmentStore::Result read_result = AttachmentStore::SUCCESS; 368 AttachmentStore::Result read_result = AttachmentStore::SUCCESS;
367 AttachmentIdList attachment_ids; 369 AttachmentIdList attachment_ids;
368 attachment_ids.push_back(AttachmentId::Create()); 370 std::string some_data("data1");
371 Attachment attachment =
372 Attachment::Create(base::RefCountedString::TakeString(&some_data));
373 attachment_ids.push_back(attachment.GetId());
369 AttachmentIdList failed_attachment_ids; 374 AttachmentIdList failed_attachment_ids;
370 store_->Read( 375 store_->Read(
371 attachment_ids, 376 attachment_ids,
372 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultAttachments, 377 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultAttachments,
373 base::Unretained(this), &read_result, &failed_attachment_ids)); 378 base::Unretained(this), &read_result, &failed_attachment_ids));
374 379
375 // Dropping from uninitialized store should result in 380 // Dropping from uninitialized store should result in
376 // STORE_INITIALIZATION_FAILED. 381 // STORE_INITIALIZATION_FAILED.
377 AttachmentStore::Result drop_result = AttachmentStore::SUCCESS; 382 AttachmentStore::Result drop_result = AttachmentStore::SUCCESS;
378 store_->Drop(attachment_ids, 383 store_->Drop(attachment_ids,
379 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult, 384 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
380 base::Unretained(this), &drop_result)); 385 base::Unretained(this), &drop_result));
381 386
382 // Writing to uninitialized store should result in 387 // Writing to uninitialized store should result in
383 // STORE_INITIALIZATION_FAILED. 388 // STORE_INITIALIZATION_FAILED.
384 AttachmentStore::Result write_result = AttachmentStore::SUCCESS; 389 AttachmentStore::Result write_result = AttachmentStore::SUCCESS;
385 std::string some_data;
386 AttachmentList attachments; 390 AttachmentList attachments;
387 some_data = "data1"; 391 attachments.push_back(attachment);
388 attachments.push_back(
389 Attachment::Create(base::RefCountedString::TakeString(&some_data)));
390 store_->Write(attachments, 392 store_->Write(attachments,
391 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult, 393 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResult,
392 base::Unretained(this), &write_result)); 394 base::Unretained(this), &write_result));
393 395
394 RunLoop(); 396 RunLoop();
395 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, create_result); 397 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, create_result);
396 EXPECT_EQ(AttachmentStore::STORE_INITIALIZATION_FAILED, read_result); 398 EXPECT_EQ(AttachmentStore::STORE_INITIALIZATION_FAILED, read_result);
397 EXPECT_THAT(failed_attachment_ids, testing::ElementsAre(attachment_ids[0])); 399 EXPECT_THAT(failed_attachment_ids, testing::ElementsAre(attachment_ids[0]));
398 EXPECT_EQ(AttachmentStore::STORE_INITIALIZATION_FAILED, drop_result); 400 EXPECT_EQ(AttachmentStore::STORE_INITIALIZATION_FAILED, drop_result);
399 EXPECT_EQ(AttachmentStore::STORE_INITIALIZATION_FAILED, write_result); 401 EXPECT_EQ(AttachmentStore::STORE_INITIALIZATION_FAILED, write_result);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 store_->ReadAllMetadata( 470 store_->ReadAllMetadata(
469 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultMetadata, 471 base::Bind(&OnDiskAttachmentStoreSpecificTest::CopyResultMetadata,
470 base::Unretained(this), &metadata_result, &metadata_list)); 472 base::Unretained(this), &metadata_result, &metadata_list));
471 RunLoop(); 473 RunLoop();
472 EXPECT_EQ(AttachmentStore::SUCCESS, create_result); 474 EXPECT_EQ(AttachmentStore::SUCCESS, create_result);
473 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, metadata_result); 475 EXPECT_EQ(AttachmentStore::UNSPECIFIED_ERROR, metadata_result);
474 EXPECT_EQ(2U, metadata_list->size()); 476 EXPECT_EQ(2U, metadata_list->size());
475 } 477 }
476 478
477 } // namespace syncer 479 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698