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

Unified Diff: content/browser/download/download_item_impl_unittest.cc

Issue 2832223004: interrupt and resume download with CONTENT_LENGTH_MISMATCH errors (Closed)
Patch Set: fix tests Created 3 years, 8 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
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_request_core.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_item_impl_unittest.cc
diff --git a/content/browser/download/download_item_impl_unittest.cc b/content/browser/download/download_item_impl_unittest.cc
index 3dce43e94f6cc961613675783a4627f712c51323..3303320887dadc9fc990eb6aa46700036d4bf860 100644
--- a/content/browser/download/download_item_impl_unittest.cc
+++ b/content/browser/download/download_item_impl_unittest.cc
@@ -620,7 +620,7 @@ TEST_F(DownloadItemTest, NotificationAfterTogglePause) {
CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
}
-// Test that a download is resumed automatcially after a continuable interrupt.
+// Test that a download is resumed automatically after a continuable interrupt.
TEST_F(DownloadItemTest, AutomaticResumption_Continue) {
DownloadItemImpl* item = CreateDownloadItem();
TestDownloadItemObserver observer(item);
@@ -719,6 +719,44 @@ TEST_F(DownloadItemTest, AutomaticResumption_NeedsUserAction) {
CleanupItem(item, nullptr, DownloadItem::INTERRUPTED);
}
+// Test that a download is resumed automatically after a content length mismatch
+// error.
+TEST_F(DownloadItemTest, AutomaticResumption_ContentLengthMismatch) {
+ DownloadItemImpl* item = CreateDownloadItem();
+ TestDownloadItemObserver observer(item);
+ MockDownloadFile* download_file =
+ DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
+
+ // Interrupt the download with content length mismatch error. The intermediate
+ // file with data shouldn't be discarded.
+
+ // The DownloadFile should be detached without discarding.
+ EXPECT_CALL(*download_file, FullPath())
+ .WillOnce(ReturnRefOfCopy(base::FilePath()));
+ EXPECT_CALL(*download_file, Detach());
+
+ // Resumption attempt should pass the intermediate file along.
+ EXPECT_CALL(*mock_delegate(),
+ MockResumeInterruptedDownload(
+ AllOf(Property(&DownloadUrlParameters::file_path,
+ Property(&base::FilePath::value,
+ kDummyIntermediatePath)),
+ Property(&DownloadUrlParameters::offset, 1)),
+ _));
+
+ item->DestinationObserverAsWeakPtr()->DestinationError(
+ DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH, 1,
+ std::unique_ptr<crypto::SecureHash>());
+ ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
+ // Since the download is resumed automatically, the observer shouldn't notice
+ // the interruption.
+ ASSERT_EQ(0, observer.interrupt_count());
+ ASSERT_EQ(0, observer.resume_count());
+
+ RunAllPendingInMessageLoops();
+ CleanupItem(item, nullptr, DownloadItem::IN_PROGRESS);
+}
+
// Check we do correct cleanup for RESUME_MODE_INVALID interrupts.
TEST_F(DownloadItemTest, UnresumableInterrupt) {
DownloadItemImpl* item = CreateDownloadItem();
« no previous file with comments | « content/browser/download/download_item_impl.cc ('k') | content/browser/download/download_request_core.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698