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/command_line.h" | 6 #include "base/command_line.h" |
6 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
7 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
8 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
9 #include "content/browser/byte_stream.h" | 10 #include "content/browser/byte_stream.h" |
10 #include "content/browser/download/download_create_info.h" | 11 #include "content/browser/download/download_create_info.h" |
11 #include "content/browser/download/download_file_factory.h" | 12 #include "content/browser/download/download_file_factory.h" |
12 #include "content/browser/download/download_item_impl.h" | 13 #include "content/browser/download/download_item_impl.h" |
13 #include "content/browser/download/download_item_impl_delegate.h" | 14 #include "content/browser/download/download_item_impl_delegate.h" |
14 #include "content/browser/download/download_request_handle.h" | 15 #include "content/browser/download/download_request_handle.h" |
15 #include "content/browser/download/mock_download_file.h" | 16 #include "content/browser/download/mock_download_file.h" |
| 17 #include "content/public/browser/download_destination_observer.h" |
16 #include "content/public/browser/download_id.h" | 18 #include "content/public/browser/download_id.h" |
17 #include "content/public/browser/download_destination_observer.h" | |
18 #include "content/public/browser/download_interrupt_reasons.h" | 19 #include "content/public/browser/download_interrupt_reasons.h" |
19 #include "content/public/browser/download_url_parameters.h" | 20 #include "content/public/browser/download_url_parameters.h" |
20 #include "content/public/common/content_switches.h" | 21 #include "content/public/common/content_switches.h" |
21 #include "content/public/test/mock_download_item.h" | 22 #include "content/public/test/mock_download_item.h" |
22 #include "content/public/test/test_browser_thread.h" | 23 #include "content/public/test/test_browser_thread.h" |
23 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
25 | 26 |
26 using ::testing::_; | 27 using ::testing::_; |
27 using ::testing::NiceMock; | 28 using ::testing::NiceMock; |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 } | 318 } |
318 | 319 |
319 void RunAllPendingInMessageLoops() { | 320 void RunAllPendingInMessageLoops() { |
320 loop_.RunUntilIdle(); | 321 loop_.RunUntilIdle(); |
321 } | 322 } |
322 | 323 |
323 MockDelegate* mock_delegate() { | 324 MockDelegate* mock_delegate() { |
324 return &delegate_; | 325 return &delegate_; |
325 } | 326 } |
326 | 327 |
| 328 void OnDownloadFileAcquired(base::FilePath* return_path, |
| 329 const base::FilePath& path) { |
| 330 *return_path = path; |
| 331 } |
| 332 |
327 private: | 333 private: |
328 base::MessageLoopForUI loop_; | 334 base::MessageLoopForUI loop_; |
329 TestBrowserThread ui_thread_; // UI thread | 335 TestBrowserThread ui_thread_; // UI thread |
330 TestBrowserThread file_thread_; // FILE thread | 336 TestBrowserThread file_thread_; // FILE thread |
331 StrictMock<MockDelegate> delegate_; | 337 StrictMock<MockDelegate> delegate_; |
332 std::set<DownloadItem*> allocated_downloads_; | 338 std::set<DownloadItem*> allocated_downloads_; |
333 }; | 339 }; |
334 | 340 |
335 // Tests to ensure calls that change a DownloadItem generate an update to | 341 // Tests to ensure calls that change a DownloadItem generate an update to |
336 // observers. | 342 // observers. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 TEST_F(DownloadItemTest, ContinueAfterInterrupted) { | 429 TEST_F(DownloadItemTest, ContinueAfterInterrupted) { |
424 CommandLine::ForCurrentProcess()->AppendSwitch( | 430 CommandLine::ForCurrentProcess()->AppendSwitch( |
425 switches::kEnableDownloadResumption); | 431 switches::kEnableDownloadResumption); |
426 | 432 |
427 DownloadItemImpl* item = CreateDownloadItem(); | 433 DownloadItemImpl* item = CreateDownloadItem(); |
428 MockObserver observer(item); | 434 MockObserver observer(item); |
429 DownloadItemImplDelegate::DownloadTargetCallback callback; | 435 DownloadItemImplDelegate::DownloadTargetCallback callback; |
430 MockDownloadFile* download_file = DoIntermediateRename(item); | 436 MockDownloadFile* download_file = DoIntermediateRename(item); |
431 | 437 |
432 // Interrupt the download, using a continuable interrupt. | 438 // Interrupt the download, using a continuable interrupt. |
| 439 EXPECT_CALL(*download_file, FullPath()) |
| 440 .WillOnce(Return(base::FilePath())); |
433 EXPECT_CALL(*download_file, Detach()); | 441 EXPECT_CALL(*download_file, Detach()); |
434 item->DestinationObserverAsWeakPtr()->DestinationError( | 442 item->DestinationObserverAsWeakPtr()->DestinationError( |
435 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); | 443 DOWNLOAD_INTERRUPT_REASON_FILE_TRANSIENT_ERROR); |
436 ASSERT_TRUE(observer.CheckUpdated()); | 444 ASSERT_TRUE(observer.CheckUpdated()); |
437 // Should attempt to auto-resume. Because we don't have a mock WebContents, | 445 // Should attempt to auto-resume. Because we don't have a mock WebContents, |
438 // ResumeInterruptedDownload() will abort early, with another interrupt, | 446 // ResumeInterruptedDownload() will abort early, with another interrupt, |
439 // which will be ignored. | 447 // which will be ignored. |
440 ASSERT_EQ(1, observer.GetInterruptCount()); | 448 ASSERT_EQ(1, observer.GetInterruptCount()); |
441 ASSERT_EQ(0, observer.GetResumeCount()); | 449 ASSERT_EQ(0, observer.GetResumeCount()); |
442 RunAllPendingInMessageLoops(); | 450 RunAllPendingInMessageLoops(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) | 492 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)) |
485 .WillRepeatedly(SaveArg<1>(&callback)); | 493 .WillRepeatedly(SaveArg<1>(&callback)); |
486 for (int i = 0; i < (DownloadItemImpl::kMaxAutoResumeAttempts + 1); ++i) { | 494 for (int i = 0; i < (DownloadItemImpl::kMaxAutoResumeAttempts + 1); ++i) { |
487 DVLOG(20) << "Loop iteration " << i; | 495 DVLOG(20) << "Loop iteration " << i; |
488 | 496 |
489 mock_download_file = new NiceMock<MockDownloadFile>; | 497 mock_download_file = new NiceMock<MockDownloadFile>; |
490 download_file.reset(mock_download_file); | 498 download_file.reset(mock_download_file); |
491 mock_request_handle = new NiceMock<MockRequestHandle>; | 499 mock_request_handle = new NiceMock<MockRequestHandle>; |
492 request_handle.reset(mock_request_handle); | 500 request_handle.reset(mock_request_handle); |
493 | 501 |
| 502 ON_CALL(*mock_download_file, FullPath()) |
| 503 .WillByDefault(Return(base::FilePath())); |
| 504 |
494 // It's too complicated to set up a WebContents instance that would cause | 505 // It's too complicated to set up a WebContents instance that would cause |
495 // the MockDownloadItemDelegate's ResumeInterruptedDownload() function | 506 // the MockDownloadItemDelegate's ResumeInterruptedDownload() function |
496 // to be callled, so we simply verify that GetWebContents() is called. | 507 // to be callled, so we simply verify that GetWebContents() is called. |
497 if (i < (DownloadItemImpl::kMaxAutoResumeAttempts - 1)) { | 508 if (i < (DownloadItemImpl::kMaxAutoResumeAttempts - 1)) { |
498 EXPECT_CALL(*mock_request_handle, GetWebContents()) | 509 EXPECT_CALL(*mock_request_handle, GetWebContents()) |
499 .WillOnce(Return(static_cast<WebContents*>(NULL))); | 510 .WillOnce(Return(static_cast<WebContents*>(NULL))); |
500 } | 511 } |
501 | 512 |
502 // Copied key parts of DoIntermediateRename & AddDownloadFileToDownloadItem | 513 // Copied key parts of DoIntermediateRename & AddDownloadFileToDownloadItem |
503 // to allow for holding onto the request handle. | 514 // to allow for holding onto the request handle. |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 RunAllPendingInMessageLoops(); | 700 RunAllPendingInMessageLoops(); |
690 // All the callbacks should have happened by now. | 701 // All the callbacks should have happened by now. |
691 ::testing::Mock::VerifyAndClearExpectations(download_file); | 702 ::testing::Mock::VerifyAndClearExpectations(download_file); |
692 mock_delegate()->VerifyAndClearExpectations(); | 703 mock_delegate()->VerifyAndClearExpectations(); |
693 | 704 |
694 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 705 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
695 .WillOnce(Return(true)); | 706 .WillOnce(Return(true)); |
696 EXPECT_CALL(*download_file, RenameAndAnnotate(final_path, _)) | 707 EXPECT_CALL(*download_file, RenameAndAnnotate(final_path, _)) |
697 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 708 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
698 final_path)); | 709 final_path)); |
| 710 EXPECT_CALL(*download_file, FullPath()) |
| 711 .WillOnce(Return(base::FilePath())); |
699 EXPECT_CALL(*download_file, Detach()); | 712 EXPECT_CALL(*download_file, Detach()); |
700 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 713 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
701 RunAllPendingInMessageLoops(); | 714 RunAllPendingInMessageLoops(); |
702 ::testing::Mock::VerifyAndClearExpectations(download_file); | 715 ::testing::Mock::VerifyAndClearExpectations(download_file); |
703 mock_delegate()->VerifyAndClearExpectations(); | 716 mock_delegate()->VerifyAndClearExpectations(); |
704 } | 717 } |
705 | 718 |
706 // Test that the delegate is invoked after the download file is renamed and the | 719 // Test that the delegate is invoked after the download file is renamed and the |
707 // download item is in an interrupted state. | 720 // download item is in an interrupted state. |
708 TEST_F(DownloadItemTest, CallbackAfterInterruptedRename) { | 721 TEST_F(DownloadItemTest, CallbackAfterInterruptedRename) { |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 899 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
887 EXPECT_TRUE(item->CanShowInFolder()); | 900 EXPECT_TRUE(item->CanShowInFolder()); |
888 EXPECT_TRUE(item->CanOpenDownload()); | 901 EXPECT_TRUE(item->CanOpenDownload()); |
889 | 902 |
890 // Complete | 903 // Complete |
891 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) | 904 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
892 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 905 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
893 base::FilePath(kDummyPath))); | 906 base::FilePath(kDummyPath))); |
894 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 907 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
895 .WillOnce(Return(true)); | 908 .WillOnce(Return(true)); |
| 909 EXPECT_CALL(*download_file, FullPath()) |
| 910 .WillOnce(Return(base::FilePath())); |
896 EXPECT_CALL(*download_file, Detach()); | 911 EXPECT_CALL(*download_file, Detach()); |
897 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 912 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
898 RunAllPendingInMessageLoops(); | 913 RunAllPendingInMessageLoops(); |
899 | 914 |
900 ASSERT_TRUE(item->IsComplete()); | 915 ASSERT_TRUE(item->IsComplete()); |
901 EXPECT_TRUE(item->CanShowInFolder()); | 916 EXPECT_TRUE(item->CanShowInFolder()); |
902 EXPECT_TRUE(item->CanOpenDownload()); | 917 EXPECT_TRUE(item->CanOpenDownload()); |
903 } | 918 } |
904 | 919 |
905 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { | 920 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { |
906 DownloadItemImpl* item = CreateDownloadItem(); | 921 DownloadItemImpl* item = CreateDownloadItem(); |
907 MockDownloadFile* download_file = DoIntermediateRename(item); | 922 MockDownloadFile* download_file = DoIntermediateRename(item); |
908 item->SetIsTemporary(true); | 923 item->SetIsTemporary(true); |
909 | 924 |
910 // InProgress Temporary | 925 // InProgress Temporary |
911 ASSERT_TRUE(item->IsInProgress()); | 926 ASSERT_TRUE(item->IsInProgress()); |
912 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 927 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
913 ASSERT_TRUE(item->IsTemporary()); | 928 ASSERT_TRUE(item->IsTemporary()); |
914 EXPECT_FALSE(item->CanShowInFolder()); | 929 EXPECT_FALSE(item->CanShowInFolder()); |
915 EXPECT_FALSE(item->CanOpenDownload()); | 930 EXPECT_FALSE(item->CanOpenDownload()); |
916 | 931 |
917 // Complete Temporary | 932 // Complete Temporary |
918 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 933 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
919 .WillOnce(Return(true)); | 934 .WillOnce(Return(true)); |
920 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) | 935 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
921 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 936 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
922 base::FilePath(kDummyPath))); | 937 base::FilePath(kDummyPath))); |
| 938 EXPECT_CALL(*download_file, FullPath()) |
| 939 .WillOnce(Return(base::FilePath())); |
923 EXPECT_CALL(*download_file, Detach()); | 940 EXPECT_CALL(*download_file, Detach()); |
924 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 941 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
925 RunAllPendingInMessageLoops(); | 942 RunAllPendingInMessageLoops(); |
926 | 943 |
927 ASSERT_TRUE(item->IsComplete()); | 944 ASSERT_TRUE(item->IsComplete()); |
928 EXPECT_FALSE(item->CanShowInFolder()); | 945 EXPECT_FALSE(item->CanShowInFolder()); |
929 EXPECT_FALSE(item->CanOpenDownload()); | 946 EXPECT_FALSE(item->CanOpenDownload()); |
930 } | 947 } |
931 | 948 |
932 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { | 949 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
972 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 989 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
973 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 990 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
974 EXPECT_FALSE(item->IsDangerous()); | 991 EXPECT_FALSE(item->IsDangerous()); |
975 | 992 |
976 // Make sure the download can complete. | 993 // Make sure the download can complete. |
977 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 994 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
978 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 995 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
979 base::FilePath(kDummyPath))); | 996 base::FilePath(kDummyPath))); |
980 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 997 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
981 .WillOnce(Return(true)); | 998 .WillOnce(Return(true)); |
| 999 EXPECT_CALL(*download_file, FullPath()) |
| 1000 .WillOnce(Return(base::FilePath())); |
982 EXPECT_CALL(*download_file, Detach()); | 1001 EXPECT_CALL(*download_file, Detach()); |
983 RunAllPendingInMessageLoops(); | 1002 RunAllPendingInMessageLoops(); |
984 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1003 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
985 } | 1004 } |
986 | 1005 |
987 // Just delaying completion. | 1006 // Just delaying completion. |
988 TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) { | 1007 TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) { |
989 // Test to confirm that if we have a callback that returns true, | 1008 // Test to confirm that if we have a callback that returns true, |
990 // we complete immediately. | 1009 // we complete immediately. |
991 DownloadItemImpl* item = CreateDownloadItem(); | 1010 DownloadItemImpl* item = CreateDownloadItem(); |
(...skipping 15 matching lines...) Expand all Loading... |
1007 ASSERT_TRUE(delegate_callback.is_null()); | 1026 ASSERT_TRUE(delegate_callback.is_null()); |
1008 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1027 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1009 EXPECT_FALSE(item->IsDangerous()); | 1028 EXPECT_FALSE(item->IsDangerous()); |
1010 | 1029 |
1011 // Make sure the download can complete. | 1030 // Make sure the download can complete. |
1012 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 1031 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
1013 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1032 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
1014 base::FilePath(kDummyPath))); | 1033 base::FilePath(kDummyPath))); |
1015 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1034 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
1016 .WillOnce(Return(true)); | 1035 .WillOnce(Return(true)); |
| 1036 EXPECT_CALL(*download_file, FullPath()) |
| 1037 .WillOnce(Return(base::FilePath())); |
1017 EXPECT_CALL(*download_file, Detach()); | 1038 EXPECT_CALL(*download_file, Detach()); |
1018 RunAllPendingInMessageLoops(); | 1039 RunAllPendingInMessageLoops(); |
1019 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1040 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
1020 } | 1041 } |
1021 | 1042 |
1022 // Delay and set danger. | 1043 // Delay and set danger. |
1023 TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) { | 1044 TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) { |
1024 // Test to confirm that if we have a callback that returns true, | 1045 // Test to confirm that if we have a callback that returns true, |
1025 // we complete immediately. | 1046 // we complete immediately. |
1026 DownloadItemImpl* item = CreateDownloadItem(); | 1047 DownloadItemImpl* item = CreateDownloadItem(); |
(...skipping 18 matching lines...) Expand all Loading... |
1045 ASSERT_TRUE(delegate_callback.is_null()); | 1066 ASSERT_TRUE(delegate_callback.is_null()); |
1046 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1067 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1047 EXPECT_TRUE(item->IsDangerous()); | 1068 EXPECT_TRUE(item->IsDangerous()); |
1048 | 1069 |
1049 // Make sure the download doesn't complete until we've validated it. | 1070 // Make sure the download doesn't complete until we've validated it. |
1050 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 1071 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
1051 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1072 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
1052 base::FilePath(kDummyPath))); | 1073 base::FilePath(kDummyPath))); |
1053 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1074 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
1054 .WillOnce(Return(true)); | 1075 .WillOnce(Return(true)); |
| 1076 EXPECT_CALL(*download_file, FullPath()) |
| 1077 .WillOnce(Return(base::FilePath())); |
1055 EXPECT_CALL(*download_file, Detach()); | 1078 EXPECT_CALL(*download_file, Detach()); |
1056 RunAllPendingInMessageLoops(); | 1079 RunAllPendingInMessageLoops(); |
1057 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1080 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1058 EXPECT_TRUE(item->IsDangerous()); | 1081 EXPECT_TRUE(item->IsDangerous()); |
1059 | 1082 |
1060 item->DangerousDownloadValidated(); | 1083 item->DangerousDownloadValidated(); |
1061 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_USER_VALIDATED, item->GetDangerType()); | 1084 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_USER_VALIDATED, item->GetDangerType()); |
1062 RunAllPendingInMessageLoops(); | 1085 RunAllPendingInMessageLoops(); |
1063 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1086 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
1064 } | 1087 } |
(...skipping 28 matching lines...) Expand all Loading... |
1093 ASSERT_TRUE(delegate_callback.is_null()); | 1116 ASSERT_TRUE(delegate_callback.is_null()); |
1094 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1117 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1095 EXPECT_FALSE(item->IsDangerous()); | 1118 EXPECT_FALSE(item->IsDangerous()); |
1096 | 1119 |
1097 // Make sure the download can complete. | 1120 // Make sure the download can complete. |
1098 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 1121 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
1099 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1122 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
1100 base::FilePath(kDummyPath))); | 1123 base::FilePath(kDummyPath))); |
1101 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1124 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
1102 .WillOnce(Return(true)); | 1125 .WillOnce(Return(true)); |
| 1126 EXPECT_CALL(*download_file, FullPath()) |
| 1127 .WillOnce(Return(base::FilePath())); |
1103 EXPECT_CALL(*download_file, Detach()); | 1128 EXPECT_CALL(*download_file, Detach()); |
1104 RunAllPendingInMessageLoops(); | 1129 RunAllPendingInMessageLoops(); |
1105 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1130 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
1106 } | 1131 } |
1107 | 1132 |
| 1133 TEST_F(DownloadItemTest, AcquireFileAndDeleteDownload) { |
| 1134 DownloadItemImpl* item = CreateDownloadItem(); |
| 1135 MockDownloadFile* download_file = DoIntermediateRename(item); |
| 1136 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); |
| 1137 |
| 1138 EXPECT_CALL(*download_file, FullPath()) |
| 1139 .WillOnce(Return(full_path)); |
| 1140 EXPECT_CALL(*download_file, Detach()); |
| 1141 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
| 1142 |
| 1143 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
| 1144 base::FilePath returned_path; |
| 1145 item->AcquireFileAndDeleteDownload( |
| 1146 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
| 1147 weak_ptr_factory.GetWeakPtr(), |
| 1148 base::Unretained(&returned_path))); |
| 1149 RunAllPendingInMessageLoops(); |
| 1150 EXPECT_EQ(full_path, returned_path); |
| 1151 } |
| 1152 |
1108 TEST(MockDownloadItem, Compiles) { | 1153 TEST(MockDownloadItem, Compiles) { |
1109 MockDownloadItem mock_item; | 1154 MockDownloadItem mock_item; |
1110 } | 1155 } |
1111 | 1156 |
1112 } // namespace content | 1157 } // namespace content |
OLD | NEW |