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

Unified Diff: sync/internal_api/attachments/attachment_downloader_impl_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/attachment_downloader_impl_unittest.cc
diff --git a/sync/internal_api/attachments/attachment_downloader_impl_unittest.cc b/sync/internal_api/attachments/attachment_downloader_impl_unittest.cc
index 1d026eb56a5f6de7e01c241b1e18dd332c30057a..0cae099337e11942ea598066ca02b2dd5676ceea 100644
--- a/sync/internal_api/attachments/attachment_downloader_impl_unittest.cc
+++ b/sync/internal_api/attachments/attachment_downloader_impl_unittest.cc
@@ -152,7 +152,12 @@ class AttachmentDownloaderImplTest : public testing::Test {
HASH_HEADER_INVALID
};
- AttachmentDownloaderImplTest() : num_completed_downloads_(0) {}
+ AttachmentDownloaderImplTest()
+ : num_completed_downloads_(0),
+ attachment_id_(
+ Attachment::Create(new base::RefCountedStaticMemory(
+ kAttachmentContent,
+ strlen(kAttachmentContent))).GetId()) {}
void SetUp() override;
void TearDown() override;
@@ -163,6 +168,8 @@ class AttachmentDownloaderImplTest : public testing::Test {
int num_completed_downloads() { return num_completed_downloads_; }
+ const AttachmentId attachment_id() const { return attachment_id_; }
+
AttachmentDownloader::DownloadCallback download_callback(
const AttachmentId& id) {
return base::Bind(&AttachmentDownloaderImplTest::DownloadDone,
@@ -193,6 +200,7 @@ class AttachmentDownloaderImplTest : public testing::Test {
scoped_ptr<AttachmentDownloader> attachment_downloader_;
ResultsMap download_results_;
int num_completed_downloads_;
+ const AttachmentId attachment_id_;
};
void AttachmentDownloaderImplTest::SetUp() {
@@ -294,7 +302,7 @@ void AttachmentDownloaderImplTest::AddHashHeader(
}
TEST_F(AttachmentDownloaderImplTest, HappyCase) {
- AttachmentId id1 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
// DownloadAttachment should trigger RequestAccessToken.
downloader()->DownloadAttachment(id1, download_callback(id1));
RunMessageLoop();
@@ -314,7 +322,7 @@ TEST_F(AttachmentDownloaderImplTest, HappyCase) {
}
TEST_F(AttachmentDownloaderImplTest, SameIdMultipleDownloads) {
- AttachmentId id1 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
base::HistogramTester histogram_tester;
// Call DownloadAttachment two times for the same id.
downloader()->DownloadAttachment(id1, download_callback(id1));
@@ -351,8 +359,8 @@ TEST_F(AttachmentDownloaderImplTest, SameIdMultipleDownloads) {
}
TEST_F(AttachmentDownloaderImplTest, RequestAccessTokenFails) {
- AttachmentId id1 = AttachmentId::Create();
- AttachmentId id2 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
+ AttachmentId id2 = AttachmentId::Create(id1.GetSize(), id1.GetCrc32c());
// Trigger first RequestAccessToken.
downloader()->DownloadAttachment(id1, download_callback(id1));
RunMessageLoop();
@@ -375,7 +383,7 @@ TEST_F(AttachmentDownloaderImplTest, RequestAccessTokenFails) {
}
TEST_F(AttachmentDownloaderImplTest, URLFetcher_BadToken) {
- AttachmentId id1 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
downloader()->DownloadAttachment(id1, download_callback(id1));
RunMessageLoop();
// Return valid access token.
@@ -393,7 +401,7 @@ TEST_F(AttachmentDownloaderImplTest, URLFetcher_BadToken) {
}
TEST_F(AttachmentDownloaderImplTest, URLFetcher_ServiceUnavailable) {
- AttachmentId id1 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
downloader()->DownloadAttachment(id1, download_callback(id1));
RunMessageLoop();
// Return valid access token.
@@ -413,7 +421,7 @@ TEST_F(AttachmentDownloaderImplTest, URLFetcher_ServiceUnavailable) {
// Verify that if no hash is present on the response the downloader accepts the
// received attachment.
TEST_F(AttachmentDownloaderImplTest, NoHash) {
- AttachmentId id1 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
downloader()->DownloadAttachment(id1, download_callback(id1));
RunMessageLoop();
token_service()->RespondToAccessTokenRequest(
@@ -426,7 +434,7 @@ TEST_F(AttachmentDownloaderImplTest, NoHash) {
// Verify that if an invalid hash is present on the response the downloader
// treats it as a transient error.
TEST_F(AttachmentDownloaderImplTest, InvalidHash) {
- AttachmentId id1 = AttachmentId::Create();
+ AttachmentId id1 = attachment_id();
downloader()->DownloadAttachment(id1, download_callback(id1));
RunMessageLoop();
token_service()->RespondToAccessTokenRequest(
@@ -436,6 +444,21 @@ TEST_F(AttachmentDownloaderImplTest, InvalidHash) {
VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_TRANSIENT_ERROR);
}
+// Verify that when the hash from the attachment id does not match the one on
+// the response the result is an unspecified error.
+TEST_F(AttachmentDownloaderImplTest, IdHashDoesNotMatch) {
+ // id1 has the wrong crc32c.
+ AttachmentId id1 = AttachmentId::Create(attachment_id().GetSize(), 12345);
+ downloader()->DownloadAttachment(id1, download_callback(id1));
+ RunMessageLoop();
+ token_service()->RespondToAccessTokenRequest(
+ GoogleServiceAuthError::AuthErrorNone());
+ RunMessageLoop();
+ CompleteDownload(net::HTTP_OK, HASH_HEADER_VALID);
+ VerifyDownloadResult(id1, AttachmentDownloader::DOWNLOAD_UNSPECIFIED_ERROR);
+}
+
+
// Verify that extract fails when there is no headers object.
TEST_F(AttachmentDownloaderImplTest, ExtractCrc32c_NoHeaders) {
uint32_t extracted;

Powered by Google App Engine
This is Rietveld 408576698