Chromium Code Reviews| 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 <iterator> | 9 #include <iterator> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 330 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 331 EXPECT_TRUE(item->GetTargetFilePath().empty()); | 331 EXPECT_TRUE(item->GetTargetFilePath().empty()); |
| 332 DownloadItemImplDelegate::DownloadTargetCallback callback; | 332 DownloadItemImplDelegate::DownloadTargetCallback callback; |
| 333 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); | 333 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); |
| 334 base::FilePath target_path(kDummyTargetPath); | 334 base::FilePath target_path(kDummyTargetPath); |
| 335 base::FilePath intermediate_path(kDummyIntermediatePath); | 335 base::FilePath intermediate_path(kDummyIntermediatePath); |
| 336 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 336 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 337 .WillOnce(ScheduleRenameAndUniquifyCallback( | 337 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 338 DOWNLOAD_INTERRUPT_REASON_NONE, intermediate_path)); | 338 DOWNLOAD_INTERRUPT_REASON_NONE, intermediate_path)); |
| 339 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 339 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 340 danger_type, intermediate_path); | 340 danger_type, intermediate_path, |
| 341 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 341 RunAllPendingInMessageLoops(); | 342 RunAllPendingInMessageLoops(); |
| 342 return download_file; | 343 return download_file; |
| 343 } | 344 } |
| 344 | 345 |
| 345 void DoDestinationComplete(DownloadItemImpl* item, | 346 void DoDestinationComplete(DownloadItemImpl* item, |
| 346 MockDownloadFile* download_file) { | 347 MockDownloadFile* download_file) { |
| 347 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) | 348 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
| 348 .WillOnce(Return(true)); | 349 .WillOnce(Return(true)); |
| 349 base::FilePath final_path(kDummyTargetPath); | 350 base::FilePath final_path(kDummyTargetPath); |
| 350 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)) | 351 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _, _, _, _)) |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 | 608 |
| 608 base::FilePath target_path(kDummyTargetPath); | 609 base::FilePath target_path(kDummyTargetPath); |
| 609 base::FilePath intermediate_path(kDummyIntermediatePath); | 610 base::FilePath intermediate_path(kDummyIntermediatePath); |
| 610 if (i == 0) { | 611 if (i == 0) { |
| 611 // RenameAndUniquify is only called the first time. In all the subsequent | 612 // RenameAndUniquify is only called the first time. In all the subsequent |
| 612 // iterations, the intermediate file already has the correct name, hence | 613 // iterations, the intermediate file already has the correct name, hence |
| 613 // no rename is necessary. | 614 // no rename is necessary. |
| 614 EXPECT_CALL(*mock_download_file, RenameAndUniquify(intermediate_path, _)) | 615 EXPECT_CALL(*mock_download_file, RenameAndUniquify(intermediate_path, _)) |
| 615 .WillOnce(ScheduleRenameAndUniquifyCallback( | 616 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 616 DOWNLOAD_INTERRUPT_REASON_NONE, intermediate_path)); | 617 DOWNLOAD_INTERRUPT_REASON_NONE, intermediate_path)); |
| 618 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
|
svaldez
2016/10/28 17:29:36
With this I think you should be changing the for s
asanka
2016/11/07 19:50:15
It needed more massaging. PTAL? :-)
| |
| 619 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, | |
| 620 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 621 RunAllPendingInMessageLoops(); | |
| 617 } | 622 } |
| 618 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 623 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 619 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 624 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 625 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 620 RunAllPendingInMessageLoops(); | 626 RunAllPendingInMessageLoops(); |
| 621 | 627 |
| 622 // Use a continuable interrupt. | 628 // Use a continuable interrupt. |
| 623 item->DestinationObserverAsWeakPtr()->DestinationError( | 629 item->DestinationObserverAsWeakPtr()->DestinationError( |
| 624 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, 0, | 630 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR, 0, |
| 625 std::unique_ptr<crypto::SecureHash>()); | 631 std::unique_ptr<crypto::SecureHash>()); |
| 626 | 632 |
| 627 RunAllPendingInMessageLoops(); | 633 RunAllPendingInMessageLoops(); |
| 628 ::testing::Mock::VerifyAndClearExpectations(mock_download_file); | 634 ::testing::Mock::VerifyAndClearExpectations(mock_download_file); |
| 629 } | 635 } |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 807 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); | 813 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); |
| 808 base::FilePath new_intermediate_path( | 814 base::FilePath new_intermediate_path( |
| 809 target_path.InsertBeforeExtensionASCII("y")); | 815 target_path.InsertBeforeExtensionASCII("y")); |
| 810 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 816 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 811 .WillOnce(ScheduleRenameAndUniquifyCallback( | 817 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 812 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); | 818 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); |
| 813 | 819 |
| 814 // Currently, a notification would be generated if the danger type is anything | 820 // Currently, a notification would be generated if the danger type is anything |
| 815 // other than NOT_DANGEROUS. | 821 // other than NOT_DANGEROUS. |
| 816 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 822 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 817 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 823 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 824 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 818 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); | 825 EXPECT_FALSE(observer.CheckAndResetDownloadUpdated()); |
| 819 RunAllPendingInMessageLoops(); | 826 RunAllPendingInMessageLoops(); |
| 820 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); | 827 EXPECT_TRUE(observer.CheckAndResetDownloadUpdated()); |
| 821 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); | 828 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); |
| 822 | 829 |
| 823 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); | 830 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); |
| 824 } | 831 } |
| 825 | 832 |
| 826 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { | 833 TEST_F(DownloadItemTest, NotificationAfterTogglePause) { |
| 827 DownloadItemImpl* item = CreateDownloadItem(); | 834 DownloadItemImpl* item = CreateDownloadItem(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 855 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); | 862 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); |
| 856 base::FilePath target_path( | 863 base::FilePath target_path( |
| 857 base::FilePath(kDummyTargetPath).AppendASCII("foo.bar")); | 864 base::FilePath(kDummyTargetPath).AppendASCII("foo.bar")); |
| 858 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); | 865 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); |
| 859 EXPECT_EQ(FILE_PATH_LITERAL(""), | 866 EXPECT_EQ(FILE_PATH_LITERAL(""), |
| 860 item->GetFileNameToReportUser().value()); | 867 item->GetFileNameToReportUser().value()); |
| 861 EXPECT_CALL(*download_file, RenameAndUniquify(_, _)) | 868 EXPECT_CALL(*download_file, RenameAndUniquify(_, _)) |
| 862 .WillOnce(ScheduleRenameAndUniquifyCallback( | 869 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 863 DOWNLOAD_INTERRUPT_REASON_NONE, intermediate_path)); | 870 DOWNLOAD_INTERRUPT_REASON_NONE, intermediate_path)); |
| 864 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 871 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 865 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 872 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 873 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 866 RunAllPendingInMessageLoops(); | 874 RunAllPendingInMessageLoops(); |
| 867 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), | 875 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), |
| 868 item->GetFileNameToReportUser().value()); | 876 item->GetFileNameToReportUser().value()); |
| 869 item->SetDisplayName(base::FilePath(FILE_PATH_LITERAL("new.name"))); | 877 item->SetDisplayName(base::FilePath(FILE_PATH_LITERAL("new.name"))); |
| 870 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), | 878 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), |
| 871 item->GetFileNameToReportUser().value()); | 879 item->GetFileNameToReportUser().value()); |
| 872 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); | 880 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); |
| 873 } | 881 } |
| 874 | 882 |
| 875 // Test to make sure that Start method calls DF initialize properly. | 883 // Test to make sure that Start method calls DF initialize properly. |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 905 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) | 913 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) |
| 906 .WillOnce(DoAll(SaveArg<1>(&download_target_callback), | 914 .WillOnce(DoAll(SaveArg<1>(&download_target_callback), |
| 907 ScheduleClosure(start_download_loop.QuitClosure()))); | 915 ScheduleClosure(start_download_loop.QuitClosure()))); |
| 908 | 916 |
| 909 item->Start(std::move(file), std::move(request_handle), *create_info()); | 917 item->Start(std::move(file), std::move(request_handle), *create_info()); |
| 910 start_download_loop.Run(); | 918 start_download_loop.Run(); |
| 911 | 919 |
| 912 download_target_callback.Run(base::FilePath(kDummyTargetPath), | 920 download_target_callback.Run(base::FilePath(kDummyTargetPath), |
| 913 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 921 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 914 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 922 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 915 base::FilePath(kDummyIntermediatePath)); | 923 base::FilePath(kDummyIntermediatePath), |
| 924 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 916 RunAllPendingInMessageLoops(); | 925 RunAllPendingInMessageLoops(); |
| 917 | 926 |
| 918 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); | 927 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 919 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, | 928 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_ACCESS_DENIED, |
| 920 item->GetLastReason()); | 929 item->GetLastReason()); |
| 921 } | 930 } |
| 922 | 931 |
| 923 // Handling of downloads initiated via a failed request. In this case, Start() | 932 // Handling of downloads initiated via a failed request. In this case, Start() |
| 924 // will get called with a DownloadCreateInfo with a non-zero interrupt_reason. | 933 // will get called with a DownloadCreateInfo with a non-zero interrupt_reason. |
| 925 TEST_F(DownloadItemTest, StartFailedDownload) { | 934 TEST_F(DownloadItemTest, StartFailedDownload) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 938 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 947 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 939 RunAllPendingInMessageLoops(); | 948 RunAllPendingInMessageLoops(); |
| 940 | 949 |
| 941 // The DownloadItemImpl should attempt to determine a target path even if the | 950 // The DownloadItemImpl should attempt to determine a target path even if the |
| 942 // download was interrupted. | 951 // download was interrupted. |
| 943 ASSERT_FALSE(download_target_callback.is_null()); | 952 ASSERT_FALSE(download_target_callback.is_null()); |
| 944 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 953 ASSERT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
| 945 base::FilePath target_path(FILE_PATH_LITERAL("foo")); | 954 base::FilePath target_path(FILE_PATH_LITERAL("foo")); |
| 946 download_target_callback.Run(target_path, | 955 download_target_callback.Run(target_path, |
| 947 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 956 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 948 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, target_path); | 957 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, target_path, |
| 958 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 949 RunAllPendingInMessageLoops(); | 959 RunAllPendingInMessageLoops(); |
| 950 | 960 |
| 951 EXPECT_EQ(target_path, item->GetTargetFilePath()); | 961 EXPECT_EQ(target_path, item->GetTargetFilePath()); |
| 952 CleanupItem(item, NULL, DownloadItem::INTERRUPTED); | 962 CleanupItem(item, NULL, DownloadItem::INTERRUPTED); |
| 953 } | 963 } |
| 954 | 964 |
| 955 // Test that the delegate is invoked after the download file is renamed. | 965 // Test that the delegate is invoked after the download file is renamed. |
| 956 TEST_F(DownloadItemTest, CallbackAfterRename) { | 966 TEST_F(DownloadItemTest, CallbackAfterRename) { |
| 957 DownloadItemImpl* item = CreateDownloadItem(); | 967 DownloadItemImpl* item = CreateDownloadItem(); |
| 958 DownloadItemImplDelegate::DownloadTargetCallback callback; | 968 DownloadItemImplDelegate::DownloadTargetCallback callback; |
| 959 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); | 969 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); |
| 960 base::FilePath final_path( | 970 base::FilePath final_path( |
| 961 base::FilePath(kDummyTargetPath).AppendASCII("foo.bar")); | 971 base::FilePath(kDummyTargetPath).AppendASCII("foo.bar")); |
| 962 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 972 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 963 base::FilePath new_intermediate_path( | 973 base::FilePath new_intermediate_path( |
| 964 final_path.InsertBeforeExtensionASCII("y")); | 974 final_path.InsertBeforeExtensionASCII("y")); |
| 965 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 975 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 966 .WillOnce(ScheduleRenameAndUniquifyCallback( | 976 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 967 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); | 977 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); |
| 968 | 978 |
| 969 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 979 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 970 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 980 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 981 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 971 RunAllPendingInMessageLoops(); | 982 RunAllPendingInMessageLoops(); |
| 972 // All the callbacks should have happened by now. | 983 // All the callbacks should have happened by now. |
| 973 ::testing::Mock::VerifyAndClearExpectations(download_file); | 984 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 974 mock_delegate()->VerifyAndClearExpectations(); | 985 mock_delegate()->VerifyAndClearExpectations(); |
| 975 | 986 |
| 976 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 987 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
| 977 .WillOnce(Return(true)); | 988 .WillOnce(Return(true)); |
| 978 EXPECT_CALL(*download_file, RenameAndAnnotate(final_path, _, _, _, _)) | 989 EXPECT_CALL(*download_file, RenameAndAnnotate(final_path, _, _, _, _)) |
| 979 .WillOnce(ScheduleRenameAndAnnotateCallback( | 990 .WillOnce(ScheduleRenameAndAnnotateCallback( |
| 980 DOWNLOAD_INTERRUPT_REASON_NONE, final_path)); | 991 DOWNLOAD_INTERRUPT_REASON_NONE, final_path)); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 999 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 1010 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 1000 base::FilePath new_intermediate_path( | 1011 base::FilePath new_intermediate_path( |
| 1001 final_path.InsertBeforeExtensionASCII("y")); | 1012 final_path.InsertBeforeExtensionASCII("y")); |
| 1002 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 1013 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 1003 .WillOnce(ScheduleRenameAndUniquifyCallback( | 1014 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 1004 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, new_intermediate_path)); | 1015 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, new_intermediate_path)); |
| 1005 EXPECT_CALL(*download_file, Cancel()) | 1016 EXPECT_CALL(*download_file, Cancel()) |
| 1006 .Times(1); | 1017 .Times(1); |
| 1007 | 1018 |
| 1008 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1019 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1009 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 1020 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 1021 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1010 RunAllPendingInMessageLoops(); | 1022 RunAllPendingInMessageLoops(); |
| 1011 // All the callbacks should have happened by now. | 1023 // All the callbacks should have happened by now. |
| 1012 ::testing::Mock::VerifyAndClearExpectations(download_file); | 1024 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 1013 mock_delegate()->VerifyAndClearExpectations(); | 1025 mock_delegate()->VerifyAndClearExpectations(); |
| 1014 } | 1026 } |
| 1015 | 1027 |
| 1016 TEST_F(DownloadItemTest, Interrupted) { | 1028 TEST_F(DownloadItemTest, Interrupted) { |
| 1017 DownloadItemImpl* item = CreateDownloadItem(); | 1029 DownloadItemImpl* item = CreateDownloadItem(); |
| 1018 MockDownloadFile* download_file = | 1030 MockDownloadFile* download_file = |
| 1019 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); | 1031 DoIntermediateRename(item, DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1051 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 1063 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 1052 base::FilePath new_intermediate_path( | 1064 base::FilePath new_intermediate_path( |
| 1053 final_path.InsertBeforeExtensionASCII("y")); | 1065 final_path.InsertBeforeExtensionASCII("y")); |
| 1054 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 1066 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 1055 .WillOnce(ScheduleRenameAndUniquifyCallback( | 1067 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 1056 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); | 1068 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); |
| 1057 EXPECT_CALL(*download_file, Cancel()) | 1069 EXPECT_CALL(*download_file, Cancel()) |
| 1058 .Times(1); | 1070 .Times(1); |
| 1059 | 1071 |
| 1060 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1072 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1061 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 1073 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 1074 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1062 RunAllPendingInMessageLoops(); | 1075 RunAllPendingInMessageLoops(); |
| 1063 // All the callbacks should have happened by now. | 1076 // All the callbacks should have happened by now. |
| 1064 ::testing::Mock::VerifyAndClearExpectations(download_file); | 1077 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 1065 mock_delegate()->VerifyAndClearExpectations(); | 1078 mock_delegate()->VerifyAndClearExpectations(); |
| 1066 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); | 1079 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 1067 EXPECT_TRUE(item->GetFullPath().empty()); | 1080 EXPECT_TRUE(item->GetFullPath().empty()); |
| 1068 EXPECT_EQ(final_path, item->GetTargetFilePath()); | 1081 EXPECT_EQ(final_path, item->GetTargetFilePath()); |
| 1069 } | 1082 } |
| 1070 | 1083 |
| 1071 // As above. But if the download can be resumed by continuing, then the | 1084 // As above. But if the download can be resumed by continuing, then the |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 1086 base::FilePath new_intermediate_path( | 1099 base::FilePath new_intermediate_path( |
| 1087 final_path.InsertBeforeExtensionASCII("y")); | 1100 final_path.InsertBeforeExtensionASCII("y")); |
| 1088 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 1101 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 1089 .WillOnce(ScheduleRenameAndUniquifyCallback( | 1102 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 1090 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); | 1103 DOWNLOAD_INTERRUPT_REASON_NONE, new_intermediate_path)); |
| 1091 EXPECT_CALL(*download_file, FullPath()) | 1104 EXPECT_CALL(*download_file, FullPath()) |
| 1092 .WillOnce(ReturnRefOfCopy(base::FilePath(new_intermediate_path))); | 1105 .WillOnce(ReturnRefOfCopy(base::FilePath(new_intermediate_path))); |
| 1093 EXPECT_CALL(*download_file, Detach()); | 1106 EXPECT_CALL(*download_file, Detach()); |
| 1094 | 1107 |
| 1095 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1108 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1096 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 1109 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 1110 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1097 RunAllPendingInMessageLoops(); | 1111 RunAllPendingInMessageLoops(); |
| 1098 // All the callbacks should have happened by now. | 1112 // All the callbacks should have happened by now. |
| 1099 ::testing::Mock::VerifyAndClearExpectations(download_file); | 1113 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 1100 mock_delegate()->VerifyAndClearExpectations(); | 1114 mock_delegate()->VerifyAndClearExpectations(); |
| 1101 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); | 1115 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 1102 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); | 1116 EXPECT_EQ(new_intermediate_path, item->GetFullPath()); |
| 1103 EXPECT_EQ(final_path, item->GetTargetFilePath()); | 1117 EXPECT_EQ(final_path, item->GetTargetFilePath()); |
| 1104 } | 1118 } |
| 1105 | 1119 |
| 1106 // As above. If the intermediate rename fails, then the interrupt reason should | 1120 // As above. If the intermediate rename fails, then the interrupt reason should |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 1119 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); | 1133 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); |
| 1120 base::FilePath new_intermediate_path( | 1134 base::FilePath new_intermediate_path( |
| 1121 final_path.InsertBeforeExtensionASCII("y")); | 1135 final_path.InsertBeforeExtensionASCII("y")); |
| 1122 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) | 1136 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) |
| 1123 .WillOnce(ScheduleRenameAndUniquifyCallback( | 1137 .WillOnce(ScheduleRenameAndUniquifyCallback( |
| 1124 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, new_intermediate_path)); | 1138 DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, new_intermediate_path)); |
| 1125 EXPECT_CALL(*download_file, Cancel()) | 1139 EXPECT_CALL(*download_file, Cancel()) |
| 1126 .Times(1); | 1140 .Times(1); |
| 1127 | 1141 |
| 1128 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1142 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1129 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); | 1143 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path, |
| 1144 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1130 RunAllPendingInMessageLoops(); | 1145 RunAllPendingInMessageLoops(); |
| 1131 // All the callbacks should have happened by now. | 1146 // All the callbacks should have happened by now. |
| 1132 ::testing::Mock::VerifyAndClearExpectations(download_file); | 1147 ::testing::Mock::VerifyAndClearExpectations(download_file); |
| 1133 mock_delegate()->VerifyAndClearExpectations(); | 1148 mock_delegate()->VerifyAndClearExpectations(); |
| 1134 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); | 1149 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); |
| 1135 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, item->GetLastReason()); | 1150 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, item->GetLastReason()); |
| 1136 EXPECT_TRUE(item->GetFullPath().empty()); | 1151 EXPECT_TRUE(item->GetFullPath().empty()); |
| 1137 EXPECT_EQ(final_path, item->GetTargetFilePath()); | 1152 EXPECT_EQ(final_path, item->GetTargetFilePath()); |
| 1138 } | 1153 } |
| 1139 | 1154 |
| 1140 TEST_F(DownloadItemTest, Canceled) { | 1155 TEST_F(DownloadItemTest, Canceled) { |
| 1141 DownloadItemImpl* item = CreateDownloadItem(); | 1156 DownloadItemImpl* item = CreateDownloadItem(); |
| 1142 DownloadItemImplDelegate::DownloadTargetCallback target_callback; | 1157 DownloadItemImplDelegate::DownloadTargetCallback target_callback; |
| 1143 MockDownloadFile* download_file = | 1158 MockDownloadFile* download_file = |
| 1144 CallDownloadItemStart(item, &target_callback); | 1159 CallDownloadItemStart(item, &target_callback); |
| 1145 | 1160 |
| 1146 // Confirm cancel sets state properly. | 1161 // Confirm cancel sets state properly. |
| 1147 EXPECT_CALL(*download_file, Cancel()); | 1162 EXPECT_CALL(*download_file, Cancel()); |
| 1148 item->Cancel(true); | 1163 item->Cancel(true); |
| 1149 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); | 1164 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); |
| 1150 } | 1165 } |
| 1151 | 1166 |
| 1167 TEST_F(DownloadItemTest, DownloadTargetDetermined_Cancel) { | |
| 1168 DownloadItemImpl* item = CreateDownloadItem(); | |
| 1169 DownloadItemImplDelegate::DownloadTargetCallback callback; | |
| 1170 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); | |
| 1171 | |
| 1172 EXPECT_CALL(*download_file, Cancel()); | |
| 1173 callback.Run(base::FilePath(FILE_PATH_LITERAL("foo")), | |
| 1174 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1175 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | |
| 1176 base::FilePath(FILE_PATH_LITERAL("bar")), | |
| 1177 DOWNLOAD_INTERRUPT_REASON_USER_CANCELED); | |
| 1178 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); | |
| 1179 } | |
| 1180 | |
| 1181 TEST_F(DownloadItemTest, DownloadTargetDetermined_CancelWithEmptyName) { | |
| 1182 DownloadItemImpl* item = CreateDownloadItem(); | |
| 1183 DownloadItemImplDelegate::DownloadTargetCallback callback; | |
| 1184 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); | |
| 1185 | |
| 1186 EXPECT_CALL(*download_file, Cancel()); | |
| 1187 callback.Run(base::FilePath(), DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1188 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, base::FilePath(), | |
| 1189 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1190 EXPECT_EQ(DownloadItem::CANCELLED, item->GetState()); | |
| 1191 } | |
| 1192 | |
| 1193 TEST_F(DownloadItemTest, DownloadTargetDetermined_Conflict) { | |
| 1194 DownloadItemImpl* item = CreateDownloadItem(); | |
| 1195 DownloadItemImplDelegate::DownloadTargetCallback callback; | |
| 1196 MockDownloadFile* download_file = CallDownloadItemStart(item, &callback); | |
| 1197 base::FilePath target_path(FILE_PATH_LITERAL("/foo/bar")); | |
| 1198 | |
| 1199 EXPECT_CALL(*download_file, Cancel()); | |
| 1200 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, | |
| 1201 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, target_path, | |
| 1202 DOWNLOAD_INTERRUPT_REASON_FILE_SAME_AS_SOURCE); | |
| 1203 EXPECT_EQ(DownloadItem::INTERRUPTED, item->GetState()); | |
| 1204 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_FILE_SAME_AS_SOURCE, | |
| 1205 item->GetLastReason()); | |
| 1206 } | |
| 1207 | |
| 1152 TEST_F(DownloadItemTest, FileRemoved) { | 1208 TEST_F(DownloadItemTest, FileRemoved) { |
| 1153 DownloadItemImpl* item = CreateDownloadItem(); | 1209 DownloadItemImpl* item = CreateDownloadItem(); |
| 1154 | 1210 |
| 1155 EXPECT_FALSE(item->GetFileExternallyRemoved()); | 1211 EXPECT_FALSE(item->GetFileExternallyRemoved()); |
| 1156 item->OnDownloadedFileRemoved(); | 1212 item->OnDownloadedFileRemoved(); |
| 1157 EXPECT_TRUE(item->GetFileExternallyRemoved()); | 1213 EXPECT_TRUE(item->GetFileExternallyRemoved()); |
| 1158 } | 1214 } |
| 1159 | 1215 |
| 1160 TEST_F(DownloadItemTest, DestinationUpdate) { | 1216 TEST_F(DownloadItemTest, DestinationUpdate) { |
| 1161 DownloadItemImpl* item = CreateDownloadItem(); | 1217 DownloadItemImpl* item = CreateDownloadItem(); |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1869 initialize_callback.Run(DOWNLOAD_INTERRUPT_REASON_NONE); | 1925 initialize_callback.Run(DOWNLOAD_INTERRUPT_REASON_NONE); |
| 1870 initialize_completion_loop.Run(); | 1926 initialize_completion_loop.Run(); |
| 1871 | 1927 |
| 1872 RunAllPendingInMessageLoops(); | 1928 RunAllPendingInMessageLoops(); |
| 1873 | 1929 |
| 1874 ASSERT_FALSE(target_callback.is_null()); | 1930 ASSERT_FALSE(target_callback.is_null()); |
| 1875 ScheduleObservations(PostTargetDeterminationObservations(), | 1931 ScheduleObservations(PostTargetDeterminationObservations(), |
| 1876 destination_observer); | 1932 destination_observer); |
| 1877 target_callback.Run(base::FilePath(), | 1933 target_callback.Run(base::FilePath(), |
| 1878 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1934 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1879 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, base::FilePath()); | 1935 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, base::FilePath(), |
| 1936 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1880 EXPECT_EQ(DownloadItem::CANCELLED, item_->GetState()); | 1937 EXPECT_EQ(DownloadItem::CANCELLED, item_->GetState()); |
| 1881 RunAllPendingInMessageLoops(); | 1938 RunAllPendingInMessageLoops(); |
| 1882 } | 1939 } |
| 1883 | 1940 |
| 1884 // Run through the DII workflow, but the intermediate rename fails. | 1941 // Run through the DII workflow, but the intermediate rename fails. |
| 1885 TEST_P(DownloadItemDestinationUpdateRaceTest, IntermediateRenameFails) { | 1942 TEST_P(DownloadItemDestinationUpdateRaceTest, IntermediateRenameFails) { |
| 1886 // Expect that the download file and the request will be cancelled as a | 1943 // Expect that the download file and the request will be cancelled as a |
| 1887 // result. | 1944 // result. |
| 1888 EXPECT_CALL(*file_, Cancel()); | 1945 EXPECT_CALL(*file_, Cancel()); |
| 1889 EXPECT_CALL(*request_handle_, CancelRequest()); | 1946 EXPECT_CALL(*request_handle_, CancelRequest()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1922 initialize_completion_loop.Run(); | 1979 initialize_completion_loop.Run(); |
| 1923 | 1980 |
| 1924 RunAllPendingInMessageLoops(); | 1981 RunAllPendingInMessageLoops(); |
| 1925 ASSERT_FALSE(target_callback.is_null()); | 1982 ASSERT_FALSE(target_callback.is_null()); |
| 1926 | 1983 |
| 1927 ScheduleObservations(PostTargetDeterminationObservations(), | 1984 ScheduleObservations(PostTargetDeterminationObservations(), |
| 1928 destination_observer); | 1985 destination_observer); |
| 1929 target_callback.Run(base::FilePath(kDummyTargetPath), | 1986 target_callback.Run(base::FilePath(kDummyTargetPath), |
| 1930 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 1987 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 1931 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 1988 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 1932 base::FilePath(kDummyIntermediatePath)); | 1989 base::FilePath(kDummyIntermediatePath), |
| 1990 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 1933 | 1991 |
| 1934 intermediate_rename_loop.Run(); | 1992 intermediate_rename_loop.Run(); |
| 1935 ASSERT_FALSE(intermediate_rename_callback.is_null()); | 1993 ASSERT_FALSE(intermediate_rename_callback.is_null()); |
| 1936 | 1994 |
| 1937 ScheduleObservations(PostIntermediateRenameObservations(), | 1995 ScheduleObservations(PostIntermediateRenameObservations(), |
| 1938 destination_observer); | 1996 destination_observer); |
| 1939 intermediate_rename_callback.Run(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, | 1997 intermediate_rename_callback.Run(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, |
| 1940 base::FilePath()); | 1998 base::FilePath()); |
| 1941 RunAllPendingInMessageLoops(); | 1999 RunAllPendingInMessageLoops(); |
| 1942 | 2000 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1991 initialize_completion_loop.Run(); | 2049 initialize_completion_loop.Run(); |
| 1992 | 2050 |
| 1993 RunAllPendingInMessageLoops(); | 2051 RunAllPendingInMessageLoops(); |
| 1994 ASSERT_FALSE(target_callback.is_null()); | 2052 ASSERT_FALSE(target_callback.is_null()); |
| 1995 | 2053 |
| 1996 ScheduleObservations(PostTargetDeterminationObservations(), | 2054 ScheduleObservations(PostTargetDeterminationObservations(), |
| 1997 destination_observer); | 2055 destination_observer); |
| 1998 target_callback.Run(base::FilePath(kDummyTargetPath), | 2056 target_callback.Run(base::FilePath(kDummyTargetPath), |
| 1999 DownloadItem::TARGET_DISPOSITION_OVERWRITE, | 2057 DownloadItem::TARGET_DISPOSITION_OVERWRITE, |
| 2000 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 2058 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 2001 base::FilePath(kDummyIntermediatePath)); | 2059 base::FilePath(kDummyIntermediatePath), |
| 2060 DOWNLOAD_INTERRUPT_REASON_NONE); | |
| 2002 | 2061 |
| 2003 intermediate_rename_loop.Run(); | 2062 intermediate_rename_loop.Run(); |
| 2004 ASSERT_FALSE(intermediate_rename_callback.is_null()); | 2063 ASSERT_FALSE(intermediate_rename_callback.is_null()); |
| 2005 | 2064 |
| 2006 // This may or may not be called, depending on whether there are any errors in | 2065 // This may or may not be called, depending on whether there are any errors in |
| 2007 // our action list. | 2066 // our action list. |
| 2008 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) | 2067 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(_, _)) |
| 2009 .Times(::testing::AnyNumber()); | 2068 .Times(::testing::AnyNumber()); |
| 2010 | 2069 |
| 2011 ScheduleObservations(PostIntermediateRenameObservations(), | 2070 ScheduleObservations(PostIntermediateRenameObservations(), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 2026 | 2085 |
| 2027 item_->Cancel(true); | 2086 item_->Cancel(true); |
| 2028 RunAllPendingInMessageLoops(); | 2087 RunAllPendingInMessageLoops(); |
| 2029 } | 2088 } |
| 2030 | 2089 |
| 2031 TEST(MockDownloadItem, Compiles) { | 2090 TEST(MockDownloadItem, Compiles) { |
| 2032 MockDownloadItem mock_item; | 2091 MockDownloadItem mock_item; |
| 2033 } | 2092 } |
| 2034 | 2093 |
| 2035 } // namespace content | 2094 } // namespace content |
| OLD | NEW |