Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(305)

Side by Side Diff: content/browser/download/download_item_impl_unittest.cc

Issue 12213066: Use base namespace for FilePath in content/browser (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop.h" 6 #include "base/message_loop.h"
7 #include "base/stl_util.h" 7 #include "base/stl_util.h"
8 #include "base/threading/thread.h" 8 #include "base/threading/thread.h"
9 #include "content/browser/download/byte_stream.h" 9 #include "content/browser/download/byte_stream.h"
10 #include "content/browser/download/download_create_info.h" 10 #include "content/browser/download/download_create_info.h"
(...skipping 17 matching lines...) Expand all
28 using ::testing::Property; 28 using ::testing::Property;
29 using ::testing::Return; 29 using ::testing::Return;
30 using ::testing::SaveArg; 30 using ::testing::SaveArg;
31 using ::testing::StrictMock; 31 using ::testing::StrictMock;
32 32
33 namespace { 33 namespace {
34 34
35 const int kDownloadChunkSize = 1000; 35 const int kDownloadChunkSize = 1000;
36 const int kDownloadSpeed = 1000; 36 const int kDownloadSpeed = 1000;
37 const int kDummyDBHandle = 10; 37 const int kDummyDBHandle = 10;
38 const FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath"); 38 const base::FilePath::CharType kDummyPath[] = FILE_PATH_LITERAL("/testpath");
39 39
40 } // namespace 40 } // namespace
41 41
42 namespace content { 42 namespace content {
43 43
44 namespace { 44 namespace {
45 45
46 DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain"; 46 DownloadId::Domain kValidDownloadItemIdDomain = "valid DownloadId::Domain";
47 47
48 class MockDelegate : public DownloadItemImplDelegate { 48 class MockDelegate : public DownloadItemImplDelegate {
49 public: 49 public:
50 MockDelegate() : DownloadItemImplDelegate() { 50 MockDelegate() : DownloadItemImplDelegate() {
51 SetDefaultExpectations(); 51 SetDefaultExpectations();
52 } 52 }
53 53
54 MOCK_METHOD2(DetermineDownloadTarget, void( 54 MOCK_METHOD2(DetermineDownloadTarget, void(
55 DownloadItemImpl*, const DownloadTargetCallback&)); 55 DownloadItemImpl*, const DownloadTargetCallback&));
56 MOCK_METHOD2(ShouldCompleteDownload, 56 MOCK_METHOD2(ShouldCompleteDownload,
57 bool(DownloadItemImpl*, const base::Closure&)); 57 bool(DownloadItemImpl*, const base::Closure&));
58 MOCK_METHOD2(ShouldOpenDownload, 58 MOCK_METHOD2(ShouldOpenDownload,
59 bool(DownloadItemImpl*, const ShouldOpenDownloadCallback&)); 59 bool(DownloadItemImpl*, const ShouldOpenDownloadCallback&));
60 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const FilePath&)); 60 MOCK_METHOD1(ShouldOpenFileBasedOnExtension, bool(const base::FilePath&));
61 MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl*)); 61 MOCK_METHOD1(CheckForFileRemoval, void(DownloadItemImpl*));
62 62
63 virtual void ResumeInterruptedDownload( 63 virtual void ResumeInterruptedDownload(
64 scoped_ptr<DownloadUrlParameters> params, DownloadId id) OVERRIDE { 64 scoped_ptr<DownloadUrlParameters> params, DownloadId id) OVERRIDE {
65 MockResumeInterruptedDownload(params.get(), id); 65 MockResumeInterruptedDownload(params.get(), id);
66 } 66 }
67 MOCK_METHOD2(MockResumeInterruptedDownload, 67 MOCK_METHOD2(MockResumeInterruptedDownload,
68 void(DownloadUrlParameters* params, DownloadId id)); 68 void(DownloadUrlParameters* params, DownloadId id));
69 69
70 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*()); 70 MOCK_CONST_METHOD0(GetBrowserContext, BrowserContext*());
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 276
277 // Perform the intermediate rename for |item|. The target path for the 277 // Perform the intermediate rename for |item|. The target path for the
278 // download will be set to kDummyPath. Returns the MockDownloadFile* that was 278 // download will be set to kDummyPath. Returns the MockDownloadFile* that was
279 // added to the DownloadItem. 279 // added to the DownloadItem.
280 MockDownloadFile* DoIntermediateRename(DownloadItemImpl* item) { 280 MockDownloadFile* DoIntermediateRename(DownloadItemImpl* item) {
281 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 281 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
282 EXPECT_TRUE(item->GetTargetFilePath().empty()); 282 EXPECT_TRUE(item->GetTargetFilePath().empty());
283 DownloadItemImplDelegate::DownloadTargetCallback callback; 283 DownloadItemImplDelegate::DownloadTargetCallback callback;
284 MockDownloadFile* download_file = 284 MockDownloadFile* download_file =
285 AddDownloadFileToDownloadItem(item, &callback); 285 AddDownloadFileToDownloadItem(item, &callback);
286 FilePath target_path(kDummyPath); 286 base::FilePath target_path(kDummyPath);
287 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 287 base::FilePath intermediate_path(
288 target_path.InsertBeforeExtensionASCII("x"));
288 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) 289 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _))
289 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 290 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
290 intermediate_path)); 291 intermediate_path));
291 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(_)); 292 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(_));
292 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 293 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
293 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 294 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
294 RunAllPendingInMessageLoops(); 295 RunAllPendingInMessageLoops();
295 return download_file; 296 return download_file;
296 } 297 }
297 298
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // DownloadFile::Rename(). Once the rename 558 // DownloadFile::Rename(). Once the rename
558 // completes, DownloadItemImpl receives a notification with the new file 559 // completes, DownloadItemImpl receives a notification with the new file
559 // name. Check that observers are updated when the new filename is available and 560 // name. Check that observers are updated when the new filename is available and
560 // not before. 561 // not before.
561 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) { 562 TEST_F(DownloadItemTest, NotificationAfterOnDownloadTargetDetermined) {
562 DownloadItemImpl* item = CreateDownloadItem(); 563 DownloadItemImpl* item = CreateDownloadItem();
563 DownloadItemImplDelegate::DownloadTargetCallback callback; 564 DownloadItemImplDelegate::DownloadTargetCallback callback;
564 MockDownloadFile* download_file = 565 MockDownloadFile* download_file =
565 AddDownloadFileToDownloadItem(item, &callback); 566 AddDownloadFileToDownloadItem(item, &callback);
566 MockObserver observer(item); 567 MockObserver observer(item);
567 FilePath target_path(kDummyPath); 568 base::FilePath target_path(kDummyPath);
568 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 569 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
569 FilePath new_intermediate_path(target_path.InsertBeforeExtensionASCII("y")); 570 base::FilePath new_intermediate_path(
571 target_path.InsertBeforeExtensionASCII("y"));
570 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) 572 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _))
571 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 573 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
572 new_intermediate_path)); 574 new_intermediate_path));
573 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(_)); 575 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(_));
574 576
575 // Currently, a notification would be generated if the danger type is anything 577 // Currently, a notification would be generated if the danger type is anything
576 // other than NOT_DANGEROUS. 578 // other than NOT_DANGEROUS.
577 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 579 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
578 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 580 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
579 EXPECT_FALSE(observer.CheckUpdated()); 581 EXPECT_FALSE(observer.CheckUpdated());
(...skipping 27 matching lines...) Expand all
607 RunAllPendingInMessageLoops(); 609 RunAllPendingInMessageLoops();
608 610
609 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); 611 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
610 } 612 }
611 613
612 TEST_F(DownloadItemTest, DisplayName) { 614 TEST_F(DownloadItemTest, DisplayName) {
613 DownloadItemImpl* item = CreateDownloadItem(); 615 DownloadItemImpl* item = CreateDownloadItem();
614 DownloadItemImplDelegate::DownloadTargetCallback callback; 616 DownloadItemImplDelegate::DownloadTargetCallback callback;
615 MockDownloadFile* download_file = 617 MockDownloadFile* download_file =
616 AddDownloadFileToDownloadItem(item, &callback); 618 AddDownloadFileToDownloadItem(item, &callback);
617 FilePath target_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 619 base::FilePath target_path(base::FilePath(kDummyPath).AppendASCII("foo.bar"));
618 FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x")); 620 base::FilePath intermediate_path(target_path.InsertBeforeExtensionASCII("x"));
619 EXPECT_EQ(FILE_PATH_LITERAL(""), 621 EXPECT_EQ(FILE_PATH_LITERAL(""),
620 item->GetFileNameToReportUser().value()); 622 item->GetFileNameToReportUser().value());
621 EXPECT_CALL(*download_file, RenameAndUniquify(_, _)) 623 EXPECT_CALL(*download_file, RenameAndUniquify(_, _))
622 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 624 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
623 intermediate_path)); 625 intermediate_path));
624 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 626 callback.Run(target_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
625 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 627 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
626 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(_)); 628 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(_));
627 RunAllPendingInMessageLoops(); 629 RunAllPendingInMessageLoops();
628 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"), 630 EXPECT_EQ(FILE_PATH_LITERAL("foo.bar"),
629 item->GetFileNameToReportUser().value()); 631 item->GetFileNameToReportUser().value());
630 item->SetDisplayName(FilePath(FILE_PATH_LITERAL("new.name"))); 632 item->SetDisplayName(base::FilePath(FILE_PATH_LITERAL("new.name")));
631 EXPECT_EQ(FILE_PATH_LITERAL("new.name"), 633 EXPECT_EQ(FILE_PATH_LITERAL("new.name"),
632 item->GetFileNameToReportUser().value()); 634 item->GetFileNameToReportUser().value());
633 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS); 635 CleanupItem(item, download_file, DownloadItem::IN_PROGRESS);
634 } 636 }
635 637
636 // Test to make sure that Start method calls DF initialize properly. 638 // Test to make sure that Start method calls DF initialize properly.
637 TEST_F(DownloadItemTest, Start) { 639 TEST_F(DownloadItemTest, Start) {
638 MockDownloadFile* mock_download_file(new MockDownloadFile); 640 MockDownloadFile* mock_download_file(new MockDownloadFile);
639 scoped_ptr<DownloadFile> download_file(mock_download_file); 641 scoped_ptr<DownloadFile> download_file(mock_download_file);
640 DownloadItemImpl* item = CreateDownloadItem(); 642 DownloadItemImpl* item = CreateDownloadItem();
641 EXPECT_CALL(*mock_download_file, Initialize(_)); 643 EXPECT_CALL(*mock_download_file, Initialize(_));
642 scoped_ptr<DownloadRequestHandleInterface> request_handle( 644 scoped_ptr<DownloadRequestHandleInterface> request_handle(
643 new NiceMock<MockRequestHandle>); 645 new NiceMock<MockRequestHandle>);
644 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _)); 646 EXPECT_CALL(*mock_delegate(), DetermineDownloadTarget(item, _));
645 item->Start(download_file.Pass(), request_handle.Pass()); 647 item->Start(download_file.Pass(), request_handle.Pass());
646 648
647 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS); 649 CleanupItem(item, mock_download_file, DownloadItem::IN_PROGRESS);
648 } 650 }
649 651
650 // Test that the delegate is invoked after the download file is renamed. 652 // Test that the delegate is invoked after the download file is renamed.
651 TEST_F(DownloadItemTest, CallbackAfterRename) { 653 TEST_F(DownloadItemTest, CallbackAfterRename) {
652 DownloadItemImpl* item = CreateDownloadItem(); 654 DownloadItemImpl* item = CreateDownloadItem();
653 DownloadItemImplDelegate::DownloadTargetCallback callback; 655 DownloadItemImplDelegate::DownloadTargetCallback callback;
654 MockDownloadFile* download_file = 656 MockDownloadFile* download_file =
655 AddDownloadFileToDownloadItem(item, &callback); 657 AddDownloadFileToDownloadItem(item, &callback);
656 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 658 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar"));
657 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 659 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
658 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); 660 base::FilePath new_intermediate_path(
661 final_path.InsertBeforeExtensionASCII("y"));
659 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) 662 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _))
660 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 663 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
661 new_intermediate_path)); 664 new_intermediate_path));
662 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(item)) 665 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(item))
663 .Times(1); 666 .Times(1);
664 667
665 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 668 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
666 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 669 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
667 RunAllPendingInMessageLoops(); 670 RunAllPendingInMessageLoops();
668 // All the callbacks should have happened by now. 671 // All the callbacks should have happened by now.
(...skipping 12 matching lines...) Expand all
681 mock_delegate()->VerifyAndClearExpectations(); 684 mock_delegate()->VerifyAndClearExpectations();
682 } 685 }
683 686
684 // Test that the delegate is invoked after the download file is renamed and the 687 // Test that the delegate is invoked after the download file is renamed and the
685 // download item is in an interrupted state. 688 // download item is in an interrupted state.
686 TEST_F(DownloadItemTest, CallbackAfterInterruptedRename) { 689 TEST_F(DownloadItemTest, CallbackAfterInterruptedRename) {
687 DownloadItemImpl* item = CreateDownloadItem(); 690 DownloadItemImpl* item = CreateDownloadItem();
688 DownloadItemImplDelegate::DownloadTargetCallback callback; 691 DownloadItemImplDelegate::DownloadTargetCallback callback;
689 MockDownloadFile* download_file = 692 MockDownloadFile* download_file =
690 AddDownloadFileToDownloadItem(item, &callback); 693 AddDownloadFileToDownloadItem(item, &callback);
691 FilePath final_path(FilePath(kDummyPath).AppendASCII("foo.bar")); 694 base::FilePath final_path(base::FilePath(kDummyPath).AppendASCII("foo.bar"));
692 FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x")); 695 base::FilePath intermediate_path(final_path.InsertBeforeExtensionASCII("x"));
693 FilePath new_intermediate_path(final_path.InsertBeforeExtensionASCII("y")); 696 base::FilePath new_intermediate_path(
697 final_path.InsertBeforeExtensionASCII("y"));
694 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _)) 698 EXPECT_CALL(*download_file, RenameAndUniquify(intermediate_path, _))
695 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED, 699 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_FILE_FAILED,
696 new_intermediate_path)); 700 new_intermediate_path));
697 EXPECT_CALL(*download_file, Cancel()) 701 EXPECT_CALL(*download_file, Cancel())
698 .Times(1); 702 .Times(1);
699 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(item)) 703 EXPECT_CALL(*mock_delegate(), ShowDownloadInBrowser(item))
700 .Times(1); 704 .Times(1);
701 705
702 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE, 706 callback.Run(final_path, DownloadItem::TARGET_DISPOSITION_OVERWRITE,
703 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path); 707 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, intermediate_path);
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 834
831 // InProgress 835 // InProgress
832 ASSERT_TRUE(item->IsInProgress()); 836 ASSERT_TRUE(item->IsInProgress());
833 ASSERT_FALSE(item->GetTargetFilePath().empty()); 837 ASSERT_FALSE(item->GetTargetFilePath().empty());
834 EXPECT_TRUE(item->CanShowInFolder()); 838 EXPECT_TRUE(item->CanShowInFolder());
835 EXPECT_TRUE(item->CanOpenDownload()); 839 EXPECT_TRUE(item->CanOpenDownload());
836 840
837 // Complete 841 // Complete
838 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) 842 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _))
839 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 843 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
840 FilePath(kDummyPath))); 844 base::FilePath(kDummyPath)));
841 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) 845 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _))
842 .WillOnce(Return(true)); 846 .WillOnce(Return(true));
843 EXPECT_CALL(*download_file, Detach()); 847 EXPECT_CALL(*download_file, Detach());
844 item->DestinationObserverAsWeakPtr()->DestinationCompleted(""); 848 item->DestinationObserverAsWeakPtr()->DestinationCompleted("");
845 RunAllPendingInMessageLoops(); 849 RunAllPendingInMessageLoops();
846 850
847 ASSERT_TRUE(item->IsComplete()); 851 ASSERT_TRUE(item->IsComplete());
848 EXPECT_TRUE(item->CanShowInFolder()); 852 EXPECT_TRUE(item->CanShowInFolder());
849 EXPECT_TRUE(item->CanOpenDownload()); 853 EXPECT_TRUE(item->CanOpenDownload());
850 } 854 }
851 855
852 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) { 856 TEST_F(DownloadItemTest, EnabledActionsForTemporaryDownload) {
853 DownloadItemImpl* item = CreateDownloadItem(); 857 DownloadItemImpl* item = CreateDownloadItem();
854 MockDownloadFile* download_file = DoIntermediateRename(item); 858 MockDownloadFile* download_file = DoIntermediateRename(item);
855 item->SetIsTemporary(true); 859 item->SetIsTemporary(true);
856 860
857 // InProgress Temporary 861 // InProgress Temporary
858 ASSERT_TRUE(item->IsInProgress()); 862 ASSERT_TRUE(item->IsInProgress());
859 ASSERT_FALSE(item->GetTargetFilePath().empty()); 863 ASSERT_FALSE(item->GetTargetFilePath().empty());
860 ASSERT_TRUE(item->IsTemporary()); 864 ASSERT_TRUE(item->IsTemporary());
861 EXPECT_FALSE(item->CanShowInFolder()); 865 EXPECT_FALSE(item->CanShowInFolder());
862 EXPECT_FALSE(item->CanOpenDownload()); 866 EXPECT_FALSE(item->CanOpenDownload());
863 867
864 // Complete Temporary 868 // Complete Temporary
865 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) 869 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _))
866 .WillOnce(Return(true)); 870 .WillOnce(Return(true));
867 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _)) 871 EXPECT_CALL(*download_file, RenameAndAnnotate(_, _))
868 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 872 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
869 FilePath(kDummyPath))); 873 base::FilePath(kDummyPath)));
870 EXPECT_CALL(*download_file, Detach()); 874 EXPECT_CALL(*download_file, Detach());
871 item->DestinationObserverAsWeakPtr()->DestinationCompleted(""); 875 item->DestinationObserverAsWeakPtr()->DestinationCompleted("");
872 RunAllPendingInMessageLoops(); 876 RunAllPendingInMessageLoops();
873 877
874 ASSERT_TRUE(item->IsComplete()); 878 ASSERT_TRUE(item->IsComplete());
875 EXPECT_FALSE(item->CanShowInFolder()); 879 EXPECT_FALSE(item->CanShowInFolder());
876 EXPECT_FALSE(item->CanOpenDownload()); 880 EXPECT_FALSE(item->CanOpenDownload());
877 } 881 }
878 882
879 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) { 883 TEST_F(DownloadItemTest, EnabledActionsForInterruptedDownload) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
914 MockDownloadFile* download_file = DoIntermediateRename(item); 918 MockDownloadFile* download_file = DoIntermediateRename(item);
915 919
916 // Drive the delegate interaction. 920 // Drive the delegate interaction.
917 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _)) 921 EXPECT_CALL(*mock_delegate(), ShouldCompleteDownload(item, _))
918 .WillOnce(Return(true)); 922 .WillOnce(Return(true));
919 item->DestinationObserverAsWeakPtr()->DestinationCompleted(""); 923 item->DestinationObserverAsWeakPtr()->DestinationCompleted("");
920 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 924 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
921 EXPECT_FALSE(item->IsDangerous()); 925 EXPECT_FALSE(item->IsDangerous());
922 926
923 // Make sure the download can complete. 927 // Make sure the download can complete.
924 EXPECT_CALL(*download_file, RenameAndAnnotate(FilePath(kDummyPath), _)) 928 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _))
925 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 929 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
926 FilePath(kDummyPath))); 930 base::FilePath(kDummyPath)));
927 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) 931 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _))
928 .WillOnce(Return(true)); 932 .WillOnce(Return(true));
929 EXPECT_CALL(*download_file, Detach()); 933 EXPECT_CALL(*download_file, Detach());
930 RunAllPendingInMessageLoops(); 934 RunAllPendingInMessageLoops();
931 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); 935 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState());
932 } 936 }
933 937
934 // Just delaying completion. 938 // Just delaying completion.
935 TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) { 939 TEST_F(DownloadItemTest, CompleteDelegate_BlockOnce) {
936 // Test to confirm that if we have a callback that returns true, 940 // Test to confirm that if we have a callback that returns true,
(...skipping 12 matching lines...) Expand all
949 ASSERT_FALSE(delegate_callback.is_null()); 953 ASSERT_FALSE(delegate_callback.is_null());
950 copy_delegate_callback = delegate_callback; 954 copy_delegate_callback = delegate_callback;
951 delegate_callback.Reset(); 955 delegate_callback.Reset();
952 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 956 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
953 copy_delegate_callback.Run(); 957 copy_delegate_callback.Run();
954 ASSERT_TRUE(delegate_callback.is_null()); 958 ASSERT_TRUE(delegate_callback.is_null());
955 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 959 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
956 EXPECT_FALSE(item->IsDangerous()); 960 EXPECT_FALSE(item->IsDangerous());
957 961
958 // Make sure the download can complete. 962 // Make sure the download can complete.
959 EXPECT_CALL(*download_file, RenameAndAnnotate(FilePath(kDummyPath), _)) 963 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _))
960 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 964 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
961 FilePath(kDummyPath))); 965 base::FilePath(kDummyPath)));
962 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) 966 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _))
963 .WillOnce(Return(true)); 967 .WillOnce(Return(true));
964 EXPECT_CALL(*download_file, Detach()); 968 EXPECT_CALL(*download_file, Detach());
965 RunAllPendingInMessageLoops(); 969 RunAllPendingInMessageLoops();
966 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); 970 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState());
967 } 971 }
968 972
969 // Delay and set danger. 973 // Delay and set danger.
970 TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) { 974 TEST_F(DownloadItemTest, CompleteDelegate_SetDanger) {
971 // Test to confirm that if we have a callback that returns true, 975 // Test to confirm that if we have a callback that returns true,
(...skipping 15 matching lines...) Expand all
987 EXPECT_FALSE(item->IsDangerous()); 991 EXPECT_FALSE(item->IsDangerous());
988 item->OnContentCheckCompleted( 992 item->OnContentCheckCompleted(
989 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE); 993 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE);
990 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 994 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
991 copy_delegate_callback.Run(); 995 copy_delegate_callback.Run();
992 ASSERT_TRUE(delegate_callback.is_null()); 996 ASSERT_TRUE(delegate_callback.is_null());
993 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 997 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
994 EXPECT_TRUE(item->IsDangerous()); 998 EXPECT_TRUE(item->IsDangerous());
995 999
996 // Make sure the download doesn't complete until we've validated it. 1000 // Make sure the download doesn't complete until we've validated it.
997 EXPECT_CALL(*download_file, RenameAndAnnotate(FilePath(kDummyPath), _)) 1001 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _))
998 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 1002 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
999 FilePath(kDummyPath))); 1003 base::FilePath(kDummyPath)));
1000 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) 1004 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _))
1001 .WillOnce(Return(true)); 1005 .WillOnce(Return(true));
1002 EXPECT_CALL(*download_file, Detach()); 1006 EXPECT_CALL(*download_file, Detach());
1003 RunAllPendingInMessageLoops(); 1007 RunAllPendingInMessageLoops();
1004 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 1008 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
1005 EXPECT_TRUE(item->IsDangerous()); 1009 EXPECT_TRUE(item->IsDangerous());
1006 1010
1007 item->DangerousDownloadValidated(); 1011 item->DangerousDownloadValidated();
1008 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_USER_VALIDATED, item->GetDangerType()); 1012 EXPECT_EQ(DOWNLOAD_DANGER_TYPE_USER_VALIDATED, item->GetDangerType());
1009 RunAllPendingInMessageLoops(); 1013 RunAllPendingInMessageLoops();
(...skipping 25 matching lines...) Expand all
1035 ASSERT_FALSE(delegate_callback.is_null()); 1039 ASSERT_FALSE(delegate_callback.is_null());
1036 copy_delegate_callback = delegate_callback; 1040 copy_delegate_callback = delegate_callback;
1037 delegate_callback.Reset(); 1041 delegate_callback.Reset();
1038 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 1042 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
1039 copy_delegate_callback.Run(); 1043 copy_delegate_callback.Run();
1040 ASSERT_TRUE(delegate_callback.is_null()); 1044 ASSERT_TRUE(delegate_callback.is_null());
1041 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState()); 1045 EXPECT_EQ(DownloadItem::IN_PROGRESS, item->GetState());
1042 EXPECT_FALSE(item->IsDangerous()); 1046 EXPECT_FALSE(item->IsDangerous());
1043 1047
1044 // Make sure the download can complete. 1048 // Make sure the download can complete.
1045 EXPECT_CALL(*download_file, RenameAndAnnotate(FilePath(kDummyPath), _)) 1049 EXPECT_CALL(*download_file, RenameAndAnnotate(base::FilePath(kDummyPath), _))
1046 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE, 1050 .WillOnce(ScheduleRenameCallback(DOWNLOAD_INTERRUPT_REASON_NONE,
1047 FilePath(kDummyPath))); 1051 base::FilePath(kDummyPath)));
1048 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _)) 1052 EXPECT_CALL(*mock_delegate(), ShouldOpenDownload(item, _))
1049 .WillOnce(Return(true)); 1053 .WillOnce(Return(true));
1050 EXPECT_CALL(*download_file, Detach()); 1054 EXPECT_CALL(*download_file, Detach());
1051 RunAllPendingInMessageLoops(); 1055 RunAllPendingInMessageLoops();
1052 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState()); 1056 EXPECT_EQ(DownloadItem::COMPLETE, item->GetState());
1053 } 1057 }
1054 1058
1055 TEST(MockDownloadItem, Compiles) { 1059 TEST(MockDownloadItem, Compiles) {
1056 MockDownloadItem mock_item; 1060 MockDownloadItem mock_item;
1057 } 1061 }
1058 1062
1059 } // namespace content 1063 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/download_item_impl_delegate.cc ('k') | content/browser/download/download_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698