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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 867 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
855 EXPECT_TRUE(item->CanShowInFolder()); | 868 EXPECT_TRUE(item->CanShowInFolder()); |
856 EXPECT_TRUE(item->CanOpenDownload()); | 869 EXPECT_TRUE(item->CanOpenDownload()); |
857 | 870 |
858 // Complete | 871 // Complete |
859 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) | 872 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
860 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 873 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
861 base::FilePath(kDummyPath))); | 874 base::FilePath(kDummyPath))); |
862 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 875 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
863 .WillOnce(Return(true)); | 876 .WillOnce(Return(true)); |
| 877 EXPECT_CALL(*download_file, FullPath()) |
| 878 .WillOnce(Return(base::FilePath())); |
864 EXPECT_CALL(*download_file, Detach()); | 879 EXPECT_CALL(*download_file, Detach()); |
865 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 880 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
866 RunAllPendingInMessageLoops(); | 881 RunAllPendingInMessageLoops(); |
867 | 882 |
868 ASSERT_TRUE(item->IsComplete()); | 883 ASSERT_TRUE(item->IsComplete()); |
869 EXPECT_TRUE(item->CanShowInFolder()); | 884 EXPECT_TRUE(item->CanShowInFolder()); |
870 EXPECT_TRUE(item->CanOpenDownload()); | 885 EXPECT_TRUE(item->CanOpenDownload()); |
871 } | 886 } |
872 | 887 |
873 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { | 888 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { |
874 DownloadItemImpl* item = CreateDownloadItem(); | 889 DownloadItemImpl* item = CreateDownloadItem(); |
875 MockDownloadFile* download_file = DoIntermediateRename(item); | 890 MockDownloadFile* download_file = DoIntermediateRename(item); |
876 item->SetIsTemporary(true); | 891 item->SetIsTemporary(true); |
877 | 892 |
878 // InProgress Temporary | 893 // InProgress Temporary |
879 ASSERT_TRUE(item->IsInProgress()); | 894 ASSERT_TRUE(item->IsInProgress()); |
880 ASSERT_FALSE(item->GetTargetFilePath().empty()); | 895 ASSERT_FALSE(item->GetTargetFilePath().empty()); |
881 ASSERT_TRUE(item->IsTemporary()); | 896 ASSERT_TRUE(item->IsTemporary()); |
882 EXPECT_FALSE(item->CanShowInFolder()); | 897 EXPECT_FALSE(item->CanShowInFolder()); |
883 EXPECT_FALSE(item->CanOpenDownload()); | 898 EXPECT_FALSE(item->CanOpenDownload()); |
884 | 899 |
885 // Complete Temporary | 900 // Complete Temporary |
886 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) | 901 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) |
887 .WillOnce(Return(true)); | 902 .WillOnce(Return(true)); |
888 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) | 903 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) |
889 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 904 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
890 base::FilePath(kDummyPath))); | 905 base::FilePath(kDummyPath))); |
| 906 EXPECT_CALL(*download_file, FullPath()) |
| 907 .WillOnce(Return(base::FilePath())); |
891 EXPECT_CALL(*download_file, Detach()); | 908 EXPECT_CALL(*download_file, Detach()); |
892 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 909 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
893 RunAllPendingInMessageLoops(); | 910 RunAllPendingInMessageLoops(); |
894 | 911 |
895 ASSERT_TRUE(item->IsComplete()); | 912 ASSERT_TRUE(item->IsComplete()); |
896 EXPECT_FALSE(item->CanShowInFolder()); | 913 EXPECT_FALSE(item->CanShowInFolder()); |
897 EXPECT_FALSE(item->CanOpenDownload()); | 914 EXPECT_FALSE(item->CanOpenDownload()); |
898 } | 915 } |
899 | 916 |
900 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { | 917 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); | 957 item->DestinationObserverAsWeakPtr()->DestinationCompleted(std::string()); |
941 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 958 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
942 EXPECT_FALSE(item->IsDangerous()); | 959 EXPECT_FALSE(item->IsDangerous()); |
943 | 960 |
944 // Make sure the download can complete. | 961 // Make sure the download can complete. |
945 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 962 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
946 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 963 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
947 base::FilePath(kDummyPath))); | 964 base::FilePath(kDummyPath))); |
948 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 965 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
949 .WillOnce(Return(true)); | 966 .WillOnce(Return(true)); |
| 967 EXPECT_CALL(*download_file, FullPath()) |
| 968 .WillOnce(Return(base::FilePath())); |
950 EXPECT_CALL(*download_file, Detach()); | 969 EXPECT_CALL(*download_file, Detach()); |
951 RunAllPendingInMessageLoops(); | 970 RunAllPendingInMessageLoops(); |
952 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 971 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
953 } | 972 } |
954 | 973 |
955 // Just delaying completion. | 974 // Just delaying completion. |
956 TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) { | 975 TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) { |
957 // Test to confirm that if we have a callback that returns true, | 976 // Test to confirm that if we have a callback that returns true, |
958 // we complete immediately. | 977 // we complete immediately. |
959 DownloadItemImpl* item = CreateDownloadItem(); | 978 DownloadItemImpl* item = CreateDownloadItem(); |
(...skipping 15 matching lines...) Expand all Loading... |
975 ASSERT_TRUE(delegate_callback.is_null()); | 994 ASSERT_TRUE(delegate_callback.is_null()); |
976 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 995 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
977 EXPECT_FALSE(item->IsDangerous()); | 996 EXPECT_FALSE(item->IsDangerous()); |
978 | 997 |
979 // Make sure the download can complete. | 998 // Make sure the download can complete. |
980 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 999 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
981 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1000 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
982 base::FilePath(kDummyPath))); | 1001 base::FilePath(kDummyPath))); |
983 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1002 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
984 .WillOnce(Return(true)); | 1003 .WillOnce(Return(true)); |
| 1004 EXPECT_CALL(*download_file, FullPath()) |
| 1005 .WillOnce(Return(base::FilePath())); |
985 EXPECT_CALL(*download_file, Detach()); | 1006 EXPECT_CALL(*download_file, Detach()); |
986 RunAllPendingInMessageLoops(); | 1007 RunAllPendingInMessageLoops(); |
987 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1008 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
988 } | 1009 } |
989 | 1010 |
990 // Delay and set danger. | 1011 // Delay and set danger. |
991 TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) { | 1012 TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) { |
992 // Test to confirm that if we have a callback that returns true, | 1013 // Test to confirm that if we have a callback that returns true, |
993 // we complete immediately. | 1014 // we complete immediately. |
994 DownloadItemImpl* item = CreateDownloadItem(); | 1015 DownloadItemImpl* item = CreateDownloadItem(); |
(...skipping 18 matching lines...) Expand all Loading... |
1013 ASSERT_TRUE(delegate_callback.is_null()); | 1034 ASSERT_TRUE(delegate_callback.is_null()); |
1014 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1035 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1015 EXPECT_TRUE(item->IsDangerous()); | 1036 EXPECT_TRUE(item->IsDangerous()); |
1016 | 1037 |
1017 // Make sure the download doesn't complete until we've validated it. | 1038 // Make sure the download doesn't complete until we've validated it. |
1018 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 1039 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
1019 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1040 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
1020 base::FilePath(kDummyPath))); | 1041 base::FilePath(kDummyPath))); |
1021 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1042 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
1022 .WillOnce(Return(true)); | 1043 .WillOnce(Return(true)); |
| 1044 EXPECT_CALL(*download_file, FullPath()) |
| 1045 .WillOnce(Return(base::FilePath())); |
1023 EXPECT_CALL(*download_file, Detach()); | 1046 EXPECT_CALL(*download_file, Detach()); |
1024 RunAllPendingInMessageLoops(); | 1047 RunAllPendingInMessageLoops(); |
1025 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1048 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1026 EXPECT_TRUE(item->IsDangerous()); | 1049 EXPECT_TRUE(item->IsDangerous()); |
1027 | 1050 |
1028 item->DangerousDownloadValidated(); | 1051 item->DangerousDownloadValidated(); |
1029 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_USER_VALIDATED, item->GetDangerType()); | 1052 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_USER_VALIDATED, item->GetDangerType()); |
1030 RunAllPendingInMessageLoops(); | 1053 RunAllPendingInMessageLoops(); |
1031 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1054 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
1032 } | 1055 } |
(...skipping 28 matching lines...) Expand all Loading... |
1061 ASSERT_TRUE(delegate_callback.is_null()); | 1084 ASSERT_TRUE(delegate_callback.is_null()); |
1062 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); | 1085 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); |
1063 EXPECT_FALSE(item->IsDangerous()); | 1086 EXPECT_FALSE(item->IsDangerous()); |
1064 | 1087 |
1065 // Make sure the download can complete. | 1088 // Make sure the download can complete. |
1066 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) | 1089 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _)) |
1067 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, | 1090 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, |
1068 base::FilePath(kDummyPath))); | 1091 base::FilePath(kDummyPath))); |
1069 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) | 1092 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) |
1070 .WillOnce(Return(true)); | 1093 .WillOnce(Return(true)); |
| 1094 EXPECT_CALL(*download_file, FullPath()) |
| 1095 .WillOnce(Return(base::FilePath())); |
1071 EXPECT_CALL(*download_file, Detach()); | 1096 EXPECT_CALL(*download_file, Detach()); |
1072 RunAllPendingInMessageLoops(); | 1097 RunAllPendingInMessageLoops(); |
1073 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); | 1098 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); |
1074 } | 1099 } |
1075 | 1100 |
| 1101 TEST_F(DownloadItemTest, AcquireFileAndDeleteDownload) { |
| 1102 DownloadItemImpl* item = CreateDownloadItem(); |
| 1103 MockDownloadFile* download_file = DoIntermediateRename(item); |
| 1104 base::FilePath full_path(FILE_PATH_LITERAL("foo.txt")); |
| 1105 |
| 1106 EXPECT_CALL(*download_file, FullPath()) |
| 1107 .WillOnce(Return(full_path)); |
| 1108 EXPECT_CALL(*download_file, Detach()); |
| 1109 EXPECT_CALL(*mock_delegate(), DownloadRemoved(_)); |
| 1110 |
| 1111 base::WeakPtrFactory<DownloadItemTest> weak_ptr_factory(this); |
| 1112 base::FilePath returned_path; |
| 1113 item->AcquireFileAndDeleteDownload( |
| 1114 base::Bind(&DownloadItemTest::OnDownloadFileAcquired, |
| 1115 weak_ptr_factory.GetWeakPtr(), |
| 1116 base::Unretained(&returned_path))); |
| 1117 RunAllPendingInMessageLoops(); |
| 1118 EXPECT_EQ(full_path, returned_path); |
| 1119 } |
| 1120 |
1076 TEST(MockDownloadItem, Compiles) { | 1121 TEST(MockDownloadItem, Compiles) { |
1077 MockDownloadItem mock_item; | 1122 MockDownloadItem mock_item; |
1078 } | 1123 } |
1079 | 1124 |
1080 } // namespace content | 1125 } // namespace content |
OLD | NEW |