OLD | NEW |
---|---|
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 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 ASSERT_TRUE(item->IsPaused()); | 613 ASSERT_TRUE(item->IsPaused()); |
614 | 614 |
615 item->Resume(); | 615 item->Resume(); |
616 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); | 616 ASSERT_TRUE(observer.CheckAndResetDownloadUpdated()); |
617 | 617 |
618 RunAllPendingInMessageLoops(); | 618 RunAllPendingInMessageLoops(); |
619 | 619 |
620 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); | 620 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); |
621 } | 621 } |
622 | 622 |
623 // Test that a download is resumed automatcially after a continuable interrupt. | 623 // Test that a download is resumed automatically after a continuable interrupt. |
624 TEST_F(DownloadItemTest, AutomaticResumption_Continue) { | 624 TEST_F(DownloadItemTest, AutomaticResumption_Continue) { |
625 DownloadItemImpl* item = CreateDownloadItem(); | 625 DownloadItemImpl* item = CreateDownloadItem(); |
626 TestDownloadItemObserver observer(item); | 626 TestDownloadItemObserver observer(item); |
627 MockDownloadFile* download_file = | 627 MockDownloadFile* download_file = |
628 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 628 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
629 | 629 |
630 // Interrupt the download using a continuable interrupt after writing a single | 630 // Interrupt the download using a continuable interrupt after writing a single |
631 // byte. An intermediate file with data shouldn't be discarding after a | 631 // byte. An intermediate file with data shouldn't be discarding after a |
632 // continuable interrupt. | 632 // continuable interrupt. |
633 | 633 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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/26 16:09:01
Fixed the other one. This one is still automatcia
qinmin
2017/04/27 18:20:54
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 Loading... | |
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 |
OLD | NEW |