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

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 2832223004: interrupt and resume download with CONTENT_LENGTH_MISMATCH errors (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/browser/download/download_item_impl.h" 5 #include "content/browser/download/download_item_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <deque> 9 #include <deque>
10 #include <iterator> 10 #include <iterator>
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 std::unique_ptr<crypto::SecureHash>()); 712 std::unique_ptr<crypto::SecureHash>());
713 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); 713 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
714 // Should not try to auto-resume. 714 // Should not try to auto-resume.
715 ASSERT_EQ(1, observer.interrupt_count()); 715 ASSERT_EQ(1, observer.interrupt_count());
716 ASSERT_EQ(0, observer.resume_count()); 716 ASSERT_EQ(0, observer.resume_count());
717 RunAllPendingInMessageLoops(); 717 RunAllPendingInMessageLoops();
718 718
719 CleanupItem(item, nullptr, DownloadItem::INTERRUPTED); 719 CleanupItem(item, nullptr, DownloadItem::INTERRUPTED);
720 } 720 }
721 721
722 // Test that a download is resumed automatcially after a content length mismatch
David Trainor- moved to gerrit 2017/04/25 03:50:41 automatically
qinmin 2017/04/25 19:27:47 Done.
723 // error.
724 TEST_F(DownloadItemTest, AutomaticResumption_ContentLengthMismatch) {
725 DownloadItemImpl* item = CreateDownloadItem();
726 TestDownloadItemObserver observer(item);
727 MockDownloadFile* download_file =
728 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
729
730 // Interrupt the download with content length mismatch error. The intermediate
731 // file with data shouldn't be discarded.
732
733 // The DownloadFile should be detached without discarding.
734 EXPECT_CALL(*download_file, FullPath())
735 .WillOnce(ReturnRefOfCopy(base::FilePath()));
736 EXPECT_CALL(*download_file, Detach());
737
738 // Resumption attempt should pass the intermediate file along.
739 EXPECT_CALL(*mock_delegate(),
740 MockResumeInterruptedDownload(
741 AllOf(Property(&DownloadUrlParameters::file_path,
742 Property(&base::FilePath::value,
743 kDummyIntermediatePath)),
744 Property(&DownloadUrlParameters::offset, 1)),
745 _));
746
747 item->DestinationObserverAsWeakPtr()->DestinationError(
748 DOWNLOAD_INTERRUPT_REASON_SERVER_CONTENT_LENGTH_MISMATCH, 1,
749 std::unique_ptr<crypto::SecureHash>());
750 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated());
751 // Since the download is resumed automatically, the observer shouldn't notice
752 // the interruption.
753 ASSERT_EQ(0, observer.interrupt_count());
754 ASSERT_EQ(0, observer.resume_count());
755
756 RunAllPendingInMessageLoops();
757 CleanupItem(item, nullptr, DownloadItem::IN_PROGRESS);
758 }
759
722 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts. 760 // Check we do correct cleanup for RESUME_MODE_INVALID interrupts.
723 TEST_F(DownloadItemTest, UnresumableInterrupt) { 761 TEST_F(DownloadItemTest, UnresumableInterrupt) {
724 DownloadItemImpl* item = CreateDownloadItem(); 762 DownloadItemImpl* item = CreateDownloadItem();
725 TestDownloadItemObserver observer(item); 763 TestDownloadItemObserver observer(item);
726 MockDownloadFile* download_file = 764 MockDownloadFile* download_file =
727 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); 765 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS);
728 766
729 // Fail final rename with unresumable reason. 767 // Fail final rename with unresumable reason.
730 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) 768 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _))
731 .WillOnce(Return(true)); 769 .WillOnce(Return(true));
(...skipping 1577 matching lines...) Expand 10 before | Expand all | Expand 10 after
2309 2347
2310 item_->Cancel(true); 2348 item_->Cancel(true);
2311 RunAllPendingInMessageLoops(); 2349 RunAllPendingInMessageLoops();
2312 } 2350 }
2313 2351
2314 TEST(MockDownloadItem, Compiles) { 2352 TEST(MockDownloadItem, Compiles) {
2315 MockDownloadItem mock_item; 2353 MockDownloadItem mock_item;
2316 } 2354 }
2317 2355
2318 } // namespace content 2356 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698