+// Upload three attachments. For one of them, server responds with error.
+TEST_F(AttachmentServiceImplTest, UploadAttachments_OneUploadFails) {
+ AttachmentIdSet attachment_ids;
+ const unsigned num_attachments = 3;
+ for (unsigned i = 0; i < num_attachments; ++i) {
+ attachment_ids.insert(AttachmentId::Create());
+ }
+ attachment_service()->UploadAttachments(attachment_ids);
+
+ for (unsigned i = 0; i < 3; ++i) {
+ RunLoopAndFireTimer();
+ ASSERT_GE(store()->read_ids.size(), 1U);
+ store()->RespondToRead(attachment_ids);
+ RunLoop();
+ ASSERT_EQ(1U, uploader()->upload_requests.size());
+ AttachmentUploader::UploadResult result =
+ AttachmentUploader::UPLOAD_SUCCESS;
+ // Fail the 2nd one.
+ if (i == 2U) {
+ result = AttachmentUploader::UPLOAD_UNSPECIFIED_ERROR;
+ } else {
+ result = AttachmentUploader::UPLOAD_SUCCESS;
+ }
+ uploader()->RespondToUpload(uploader()->upload_requests.begin()->first,
+ result);
+ RunLoop();
+ }
+ ASSERT_EQ(2U, on_attachment_uploaded_list().size());
+}
+
+// Attempt an upload, respond with transient error to trigger backoff, issue
+// network disconnect/connect events and see that backoff is cleared.
+TEST_F(AttachmentServiceImplTest,
+ UploadAttachments_ResetBackoffAfterNetworkChange) {
+ AttachmentIdSet attachment_ids;
+ attachment_ids.insert(AttachmentId::Create());
+ attachment_service()->UploadAttachments(attachment_ids);
+
+ RunLoopAndFireTimer();
+ ASSERT_EQ(1U, store()->read_ids.size());
+ store()->RespondToRead(attachment_ids);
+ RunLoop();
+ ASSERT_EQ(1U, uploader()->upload_requests.size());
+
+ uploader()->RespondToUpload(uploader()->upload_requests.begin()->first,
+ AttachmentUploader::UPLOAD_TRANSIENT_ERROR);