| 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 "base/callback.h" | 5 #include "base/callback.h" |
| 6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
| 7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "content/browser/byte_stream.h" | 10 #include "content/browser/byte_stream.h" |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 757 | 757 |
| 758 // Destination errors that occur before the intermediate rename shouldn't cause | 758 // Destination errors that occur before the intermediate rename shouldn't cause |
| 759 // the download to be marked as interrupted until after the intermediate rename. | 759 // the download to be marked as interrupted until after the intermediate rename. |
| 760 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Restart) { | 760 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Restart) { |
| 761 DownloadItemImpl* item = CreateDownloadItem(); | 761 DownloadItemImpl* item = CreateDownloadItem(); |
| 762 DownloadItemImplDelegate::DownloadTargetCallback callback; | 762 DownloadItemImplDelegate::DownloadTargetCallback callback; |
| 763 MockDownloadFile* download_file = | 763 MockDownloadFile* download_file = |
| 764 AddDownloadFileToDownloadItem(item, &callback); | 764 AddDownloadFileToDownloadItem(item, &callback); |
| 765 item->DestinationObserverAsWeakPtr()->DestinationError( | 765 item->DestinationObserverAsWeakPtr()->DestinationError( |
| 766 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 766 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
| 767 ASSERT_TRUE(item->IsInProgress()); | 767 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 768 | 768 |
| 769 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); | 769 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); |
| 770 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 770 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 771 base::FilePath new_intermediate_path( | 771 base::FilePath new_intermediate_path( |
| 772 final_path.InsertBeforeExtensionASCII("y")); | 772 final_path.InsertBeforeExtensionASCII("y")); |
| 773 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 773 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 774 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 774 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 775 new_intermediate_path)); | 775 new_intermediate_path)); |
| 776 EXPECT_CALL(*download_file, Cancel()) | 776 EXPECT_CALL(*download_file, Cancel()) |
| 777 .Times(1); | 777 .Times(1); |
| 778 | 778 |
| 779 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 779 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 780 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 780 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); |
| 781 RunAllPendingInMessageLoops(); | 781 RunAllPendingInMessageLoops(); |
| 782 // All the callbacks should have happened by now. | 782 // All the callbacks should have happened by now. |
| 783 ::testing::Mock::VerifyAndClearExpectations(download_file); | 783 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 784 mock_delegate()->VerifyAndClearExpectations(); | 784 mock_delegate()->VerifyAndClearExpectations(); |
| 785 EXPECT_TRUE(item->IsInterrupted()); | 785 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 786 EXPECT_TRUE(item->GetFullPath().empty()); | 786 EXPECT_TRUE(item->GetFullPath().empty()); |
| 787 EXPECT_EQ(final_path, item->GetTargetFilePath()); | 787 EXPECT_EQ(final_path, item->GetTargetFilePath()); |
| 788 } | 788 } |
| 789 | 789 |
| 790 // As above. But if the download can be resumed by continuing, then the | 790 // As above. But if the download can be resumed by continuing, then the |
| 791 // intermediate path should be retained when the download is interrupted after | 791 // intermediate path should be retained when the download is interrupted after |
| 792 // the intermediate rename succeeds. | 792 // the intermediate rename succeeds. |
| 793 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Continue) { | 793 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Continue) { |
| 794 CommandLine::ForCurrentProcess()->AppendSwitch( | 794 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 795 switches::kEnableDownloadResumption); | 795 switches::kEnableDownloadResumption); |
| 796 DownloadItemImpl* item = CreateDownloadItem(); | 796 DownloadItemImpl* item = CreateDownloadItem(); |
| 797 DownloadItemImplDelegate::DownloadTargetCallback callback; | 797 DownloadItemImplDelegate::DownloadTargetCallback callback; |
| 798 MockDownloadFile* download_file = | 798 MockDownloadFile* download_file = |
| 799 AddDownloadFileToDownloadItem(item, &callback); | 799 AddDownloadFileToDownloadItem(item, &callback); |
| 800 item->DestinationObserverAsWeakPtr()->DestinationError( | 800 item->DestinationObserverAsWeakPtr()->DestinationError( |
| 801 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); | 801 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); |
| 802 ASSERT_TRUE(item->IsInProgress()); | 802 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 803 | 803 |
| 804 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); | 804 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); |
| 805 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 805 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 806 base::FilePath new_intermediate_path( | 806 base::FilePath new_intermediate_path( |
| 807 final_path.InsertBeforeExtensionASCII("y")); | 807 final_path.InsertBeforeExtensionASCII("y")); |
| 808 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 808 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 809 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 809 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 810 new_intermediate_path)); | 810 new_intermediate_path)); |
| 811 EXPECT_CALL(*download_file, FullPath()) | 811 EXPECT_CALL(*download_file, FullPath()) |
| 812 .WillOnce(Return(base::FilePath(new_intermediate_path))); | 812 .WillOnce(Return(base::FilePath(new_intermediate_path))); |
| 813 EXPECT_CALL(*download_file, Detach()); | 813 EXPECT_CALL(*download_file, Detach()); |
| 814 | 814 |
| 815 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 815 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 816 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 816 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); |
| 817 RunAllPendingInMessageLoops(); | 817 RunAllPendingInMessageLoops(); |
| 818 // All the callbacks should have happened by now. | 818 // All the callbacks should have happened by now. |
| 819 ::testing::Mock::VerifyAndClearExpectations(download_file); | 819 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 820 mock_delegate()->VerifyAndClearExpectations(); | 820 mock_delegate()->VerifyAndClearExpectations(); |
| 821 EXPECT_TRUE(item->IsInterrupted()); | 821 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 822 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); | 822 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); |
| 823 EXPECT_EQ(final_path, item->GetTargetFilePath()); | 823 EXPECT_EQ(final_path, item->GetTargetFilePath()); |
| 824 } | 824 } |
| 825 | 825 |
| 826 // As above. If the intermediate rename fails, then the interrupt reason should | 826 // As above. If the intermediate rename fails, then the interrupt reason should |
| 827 // be set to the destination error and the intermediate path should be empty. | 827 // be set to the destination error and the intermediate path should be empty. |
| 828 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Failed) { | 828 TEST_F(DownloadItemTest, InterruptedBeforeIntermediateRename_Failed) { |
| 829 CommandLine::ForCurrentProcess()->AppendSwitch( | 829 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 830 switches::kEnableDownloadResumption); | 830 switches::kEnableDownloadResumption); |
| 831 DownloadItemImpl* item = CreateDownloadItem(); | 831 DownloadItemImpl* item = CreateDownloadItem(); |
| 832 DownloadItemImplDelegate::DownloadTargetCallback callback; | 832 DownloadItemImplDelegate::DownloadTargetCallback callback; |
| 833 MockDownloadFile* download_file = | 833 MockDownloadFile* download_file = |
| 834 AddDownloadFileToDownloadItem(item, &callback); | 834 AddDownloadFileToDownloadItem(item, &callback); |
| 835 item->DestinationObserverAsWeakPtr()->DestinationError( | 835 item->DestinationObserverAsWeakPtr()->DestinationError( |
| 836 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); | 836 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED); |
| 837 ASSERT_TRUE(item->IsInProgress()); | 837 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 838 | 838 |
| 839 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); | 839 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar")); |
| 840 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 840 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 841 base::FilePath new_intermediate_path( | 841 base::FilePath new_intermediate_path( |
| 842 final_path.InsertBeforeExtensionASCII("y")); | 842 final_path.InsertBeforeExtensionASCII("y")); |
| 843 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 843 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 844 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | 844 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 845 new_intermediate_path)); | 845 new_intermediate_path)); |
| 846 EXPECT_CALL(*download_file, Cancel()) | 846 EXPECT_CALL(*download_file, Cancel()) |
| 847 .Times(1); | 847 .Times(1); |
| 848 | 848 |
| 849 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 849 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 850 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 850 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); |
| 851 RunAllPendingInMessageLoops(); | 851 RunAllPendingInMessageLoops(); |
| 852 // All the callbacks should have happened by now. | 852 // All the callbacks should have happened by now. |
| 853 ::testing::Mock::VerifyAndClearExpectations(download_file); | 853 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 854 mock_delegate()->VerifyAndClearExpectations(); | 854 mock_delegate()->VerifyAndClearExpectations(); |
| 855 EXPECT_TRUE(item->IsInterrupted()); | 855 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 856 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, item->GetLastReason()); | 856 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, item->GetLastReason()); |
| 857 EXPECT_TRUE(item->GetFullPath().empty()); | 857 EXPECT_TRUE(item->GetFullPath().empty()); |
| 858 EXPECT_EQ(final_path, item->GetTargetFilePath()); | 858 EXPECT_EQ(final_path, item->GetTargetFilePath()); |
| 859 } | 859 } |
| 860 | 860 |
| 861 TEST_F(DownloadItemTest, Canceled) { | 861 TEST_F(DownloadItemTest, Canceled) { |
| 862 DownloadItemImpl* item = CreateDownloadItem(); | 862 DownloadItemImpl* item = CreateDownloadItem(); |
| 863 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL); | 863 MockDownloadFile* download_file = AddDownloadFileToDownloadItem(item, NULL); |
| 864 | 864 |
| 865 // Confirm cancel sets state properly. | 865 // Confirm cancel sets state properly. |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 EXPECT_EQ("", item->GetHashState()); | 955 EXPECT_EQ("", item->GetHashState()); |
| 956 EXPECT_TRUE(item->AllDataSaved()); | 956 EXPECT_TRUE(item->AllDataSaved()); |
| 957 } | 957 } |
| 958 | 958 |
| 959 TEST_F(DownloadItemTest, EnabledActionsForNormalDownload) { | 959 TEST_F(DownloadItemTest, EnabledActionsForNormalDownload) { |
| 960 DownloadItemImpl* item = CreateDownloadItem(); | 960 DownloadItemImpl* item = CreateDownloadItem(); |
| 961 MockDownloadFile* download_file = | 961 MockDownloadFile* download_file = |
| 962 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 962 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 963 | 963 |
| 964 // InProgress | 964 // InProgress |
| 965 ASSERT_TRUE(item->IsInProgress()); | 965 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 966 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 966 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
| 967 EXPECT_TRUE(item->CanShowInFolder()); | 967 EXPECT_TRUE(item->CanShowInFolder()); |
| 968 EXPECT_TRUE(item->CanOpenDownload()); | 968 EXPECT_TRUE(item->CanOpenDownload()); |
| 969 | 969 |
| 970 // Complete | 970 // Complete |
| 971 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) | 971 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
| 972 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 972 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 973 base::FilePath(kDummyPath))); | 973 base::FilePath(kDummyPath))); |
| 974 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 974 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
| 975 .WillOnce(Return(true)); | 975 .WillOnce(Return(true)); |
| 976 EXPECT_CALL(*download_file, FullPath()) | 976 EXPECT_CALL(*download_file, FullPath()) |
| 977 .WillOnce(Return(base::FilePath())); | 977 .WillOnce(Return(base::FilePath())); |
| 978 EXPECT_CALL(*download_file, Detach()); | 978 EXPECT_CALL(*download_file, Detach()); |
| 979 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 979 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
| 980 RunAllPendingInMessageLoops(); | 980 RunAllPendingInMessageLoops(); |
| 981 | 981 |
| 982 ASSERT_TRUE(item->IsComplete()); | 982 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); |
| 983 EXPECT_TRUE(item->CanShowInFolder()); | 983 EXPECT_TRUE(item->CanShowInFolder()); |
| 984 EXPECT_TRUE(item->CanOpenDownload()); | 984 EXPECT_TRUE(item->CanOpenDownload()); |
| 985 } | 985 } |
| 986 | 986 |
| 987 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { | 987 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { |
| 988 DownloadItemImpl* item = CreateDownloadItem(); | 988 DownloadItemImpl* item = CreateDownloadItem(); |
| 989 MockDownloadFile* download_file = | 989 MockDownloadFile* download_file = |
| 990 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 990 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 991 item->SetIsTemporary(true); | 991 item->SetIsTemporary(true); |
| 992 | 992 |
| 993 // InProgress Temporary | 993 // InProgress Temporary |
| 994 ASSERT_TRUE(item->IsInProgress()); | 994 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 995 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 995 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
| 996 ASSERT_TRUE(item->IsTemporary()); | 996 ASSERT_TRUE(item->IsTemporary()); |
| 997 EXPECT_FALSE(item->CanShowInFolder()); | 997 EXPECT_FALSE(item->CanShowInFolder()); |
| 998 EXPECT_FALSE(item->CanOpenDownload()); | 998 EXPECT_FALSE(item->CanOpenDownload()); |
| 999 | 999 |
| 1000 // Complete Temporary | 1000 // Complete Temporary |
| 1001 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 1001 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
| 1002 .WillOnce(Return(true)); | 1002 .WillOnce(Return(true)); |
| 1003 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) | 1003 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
| 1004 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1004 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
| 1005 base::FilePath(kDummyPath))); | 1005 base::FilePath(kDummyPath))); |
| 1006 EXPECT_CALL(*download_file, FullPath()) | 1006 EXPECT_CALL(*download_file, FullPath()) |
| 1007 .WillOnce(Return(base::FilePath())); | 1007 .WillOnce(Return(base::FilePath())); |
| 1008 EXPECT_CALL(*download_file, Detach()); | 1008 EXPECT_CALL(*download_file, Detach()); |
| 1009 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 1009 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
| 1010 RunAllPendingInMessageLoops(); | 1010 RunAllPendingInMessageLoops(); |
| 1011 | 1011 |
| 1012 ASSERT_TRUE(item->IsComplete()); | 1012 ASSERT_EQ(DownloadItem::COMPLETE, item->GetState()); |
| 1013 EXPECT_FALSE(item->CanShowInFolder()); | 1013 EXPECT_FALSE(item->CanShowInFolder()); |
| 1014 EXPECT_FALSE(item->CanOpenDownload()); | 1014 EXPECT_FALSE(item->CanOpenDownload()); |
| 1015 } | 1015 } |
| 1016 | 1016 |
| 1017 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { | 1017 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { |
| 1018 DownloadItemImpl* item = CreateDownloadItem(); | 1018 DownloadItemImpl* item = CreateDownloadItem(); |
| 1019 MockDownloadFile* download_file = | 1019 MockDownloadFile* download_file = |
| 1020 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 1020 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 1021 | 1021 |
| 1022 EXPECT_CALL(*download_file, Cancel()); | 1022 EXPECT_CALL(*download_file, Cancel()); |
| 1023 item->DestinationObserverAsWeakPtr()->DestinationError( | 1023 item->DestinationObserverAsWeakPtr()->DestinationError( |
| 1024 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); | 1024 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED); |
| 1025 RunAllPendingInMessageLoops(); | 1025 RunAllPendingInMessageLoops(); |
| 1026 | 1026 |
| 1027 ASSERT_TRUE(item->IsInterrupted()); | 1027 ASSERT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 1028 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 1028 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
| 1029 EXPECT_FALSE(item->CanShowInFolder()); | 1029 EXPECT_FALSE(item->CanShowInFolder()); |
| 1030 EXPECT_FALSE(item->CanOpenDownload()); | 1030 EXPECT_FALSE(item->CanOpenDownload()); |
| 1031 } | 1031 } |
| 1032 | 1032 |
| 1033 TEST_F(DownloadItemTest, EnabledActionsForCancelledDownload) { | 1033 TEST_F(DownloadItemTest, EnabledActionsForCancelledDownload) { |
| 1034 DownloadItemImpl* item = CreateDownloadItem(); | 1034 DownloadItemImpl* item = CreateDownloadItem(); |
| 1035 MockDownloadFile* download_file = | 1035 MockDownloadFile* download_file = |
| 1036 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 1036 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| 1037 | 1037 |
| 1038 EXPECT_CALL(*download_file, Cancel()); | 1038 EXPECT_CALL(*download_file, Cancel()); |
| 1039 item->Cancel(true); | 1039 item->Cancel(true); |
| 1040 RunAllPendingInMessageLoops(); | 1040 RunAllPendingInMessageLoops(); |
| 1041 | 1041 |
| 1042 ASSERT_TRUE(item->IsCancelled()); | 1042 ASSERT_EQ(DownloadItem::CANCELLED, item->GetState()); |
| 1043 EXPECT_FALSE(item->CanShowInFolder()); | 1043 EXPECT_FALSE(item->CanShowInFolder()); |
| 1044 EXPECT_FALSE(item->CanOpenDownload()); | 1044 EXPECT_FALSE(item->CanOpenDownload()); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 // Test various aspects of the delegate completion blocker. | 1047 // Test various aspects of the delegate completion blocker. |
| 1048 | 1048 |
| 1049 // Just allowing completion. | 1049 // Just allowing completion. |
| 1050 TEST_F(DownloadItemTest, CompleteDelegate_ReturnTrue) { | 1050 TEST_F(DownloadItemTest, CompleteDelegate_ReturnTrue) { |
| 1051 // Test to confirm that if we have a callback that returns true, | 1051 // Test to confirm that if we have a callback that returns true, |
| 1052 // we complete immediately. | 1052 // we complete immediately. |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 base::Unretained(&returned_path))); | 1271 base::Unretained(&returned_path))); |
| 1272 RunAllPendingInMessageLoops(); | 1272 RunAllPendingInMessageLoops(); |
| 1273 EXPECT_TRUE(returned_path.empty()); | 1273 EXPECT_TRUE(returned_path.empty()); |
| 1274 } | 1274 } |
| 1275 | 1275 |
| 1276 TEST(MockDownloadItem, Compiles) { | 1276 TEST(MockDownloadItem, Compiles) { |
| 1277 MockDownloadItem mock_item; | 1277 MockDownloadItem mock_item; |
| 1278 } | 1278 } |
| 1279 | 1279 |
| 1280 } // namespace content | 1280 } // namespace content |
| OLD | NEW |