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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Invokes ChromeDownloadManagerDelegate::CheckForFileExistence and waits for | 232 // Invokes ChromeDownloadManagerDelegate::CheckForFileExistence and waits for |
233 // the asynchronous callback. The result passed into | 233 // the asynchronous callback. The result passed into |
234 // content::CheckForFileExistenceCallback is the return value from this | 234 // content::CheckForFileExistenceCallback is the return value from this |
235 // method. | 235 // method. |
236 bool CheckForFileExistence(DownloadItem* download); | 236 bool CheckForFileExistence(DownloadItem* download); |
237 | 237 |
238 const base::FilePath& default_download_path() const; | 238 const base::FilePath& default_download_path() const; |
239 TestChromeDownloadManagerDelegate* delegate(); | 239 TestChromeDownloadManagerDelegate* delegate(); |
240 content::MockDownloadManager* download_manager(); | 240 content::MockDownloadManager* download_manager(); |
241 DownloadPrefs* download_prefs(); | 241 DownloadPrefs* download_prefs(); |
| 242 PrefService* pref_service(); |
242 | 243 |
243 private: | 244 private: |
244 sync_preferences::TestingPrefServiceSyncable* pref_service_; | 245 sync_preferences::TestingPrefServiceSyncable* pref_service_; |
245 base::ScopedTempDir test_download_dir_; | 246 base::ScopedTempDir test_download_dir_; |
246 std::unique_ptr<content::MockDownloadManager> download_manager_; | 247 std::unique_ptr<content::MockDownloadManager> download_manager_; |
247 std::unique_ptr<TestChromeDownloadManagerDelegate> delegate_; | 248 std::unique_ptr<TestChromeDownloadManagerDelegate> delegate_; |
248 MockWebContentsDelegate web_contents_delegate_; | 249 MockWebContentsDelegate web_contents_delegate_; |
249 }; | 250 }; |
250 | 251 |
251 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() | 252 ChromeDownloadManagerDelegateTest::ChromeDownloadManagerDelegateTest() |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 386 |
386 content::MockDownloadManager* | 387 content::MockDownloadManager* |
387 ChromeDownloadManagerDelegateTest::download_manager() { | 388 ChromeDownloadManagerDelegateTest::download_manager() { |
388 return download_manager_.get(); | 389 return download_manager_.get(); |
389 } | 390 } |
390 | 391 |
391 DownloadPrefs* ChromeDownloadManagerDelegateTest::download_prefs() { | 392 DownloadPrefs* ChromeDownloadManagerDelegateTest::download_prefs() { |
392 return delegate_->download_prefs(); | 393 return delegate_->download_prefs(); |
393 } | 394 } |
394 | 395 |
| 396 PrefService* ChromeDownloadManagerDelegateTest::pref_service() { |
| 397 return pref_service_; |
| 398 } |
| 399 |
395 } // namespace | 400 } // namespace |
396 | 401 |
397 TEST_F(ChromeDownloadManagerDelegateTest, LastSavePath) { | 402 TEST_F(ChromeDownloadManagerDelegateTest, LastSavePath) { |
398 GURL download_url("http://example.com/foo.txt"); | 403 GURL download_url("http://example.com/foo.txt"); |
399 | 404 |
400 std::unique_ptr<content::MockDownloadItem> save_as_download = | 405 std::unique_ptr<content::MockDownloadItem> save_as_download = |
401 CreateActiveDownloadItem(0); | 406 CreateActiveDownloadItem(0); |
402 EXPECT_CALL(*save_as_download, GetURL()) | 407 EXPECT_CALL(*save_as_download, GetURL()) |
403 .Times(AnyNumber()) | 408 .Times(AnyNumber()) |
404 .WillRepeatedly(ReturnRef(download_url)); | 409 .WillRepeatedly(ReturnRef(download_url)); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
567 EXPECT_CALL(*download_item, GetTargetFilePath()) | 572 EXPECT_CALL(*download_item, GetTargetFilePath()) |
568 .WillRepeatedly(ReturnRef(existing_path)); | 573 .WillRepeatedly(ReturnRef(existing_path)); |
569 EXPECT_TRUE(CheckForFileExistence(download_item.get())); | 574 EXPECT_TRUE(CheckForFileExistence(download_item.get())); |
570 | 575 |
571 download_item = CreateActiveDownloadItem(1); | 576 download_item = CreateActiveDownloadItem(1); |
572 EXPECT_CALL(*download_item, GetTargetFilePath()) | 577 EXPECT_CALL(*download_item, GetTargetFilePath()) |
573 .WillRepeatedly(ReturnRef(non_existent_path)); | 578 .WillRepeatedly(ReturnRef(non_existent_path)); |
574 EXPECT_FALSE(CheckForFileExistence(download_item.get())); | 579 EXPECT_FALSE(CheckForFileExistence(download_item.get())); |
575 } | 580 } |
576 | 581 |
| 582 TEST_F(ChromeDownloadManagerDelegateTest, BlockedByPolicy) { |
| 583 const GURL kUrl("http://example.com/foo"); |
| 584 const std::string kTargetDisposition("attachment; filename=\"foo.txt\""); |
| 585 |
| 586 std::unique_ptr<content::MockDownloadItem> download_item = |
| 587 CreateActiveDownloadItem(0); |
| 588 EXPECT_CALL(*download_item, GetURL()).WillRepeatedly(ReturnRef(kUrl)); |
| 589 EXPECT_CALL(*download_item, GetContentDisposition()) |
| 590 .WillRepeatedly(Return(kTargetDisposition)); |
| 591 |
| 592 base::FilePath kExpectedPath = GetPathInDownloadDir("bar.txt"); |
| 593 |
| 594 DetermineDownloadTargetResult result; |
| 595 |
| 596 EXPECT_CALL(*delegate(), MockReserveVirtualPath(_, _, _, _, _)) |
| 597 .WillOnce(DoAll(SetArgPointee<4>(PathValidationResult::CONFLICT), |
| 598 ReturnArg<1>())); |
| 599 EXPECT_CALL( |
| 600 *delegate(), |
| 601 RequestConfirmation(_, _, DownloadConfirmationReason::TARGET_CONFLICT, _)) |
| 602 .WillOnce(WithArg<3>(ScheduleCallback2( |
| 603 DownloadConfirmationResult::CONFIRMED, kExpectedPath))); |
| 604 |
| 605 pref_service()->SetInteger( |
| 606 prefs::kDownloadRestrictions, |
| 607 static_cast<int>(DownloadPrefs::DownloadRestriction::ALL_FILES)); |
| 608 |
| 609 DetermineDownloadTarget(download_item.get(), &result); |
| 610 EXPECT_EQ(content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED, |
| 611 result.interrupt_reason); |
| 612 |
| 613 VerifyAndClearExpectations(); |
| 614 } |
| 615 |
577 #if defined(FULL_SAFE_BROWSING) | 616 #if defined(FULL_SAFE_BROWSING) |
578 namespace { | 617 namespace { |
579 | 618 |
580 struct SafeBrowsingTestParameters { | 619 struct SafeBrowsingTestParameters { |
581 content::DownloadDangerType initial_danger_type; | 620 content::DownloadDangerType initial_danger_type; |
582 DownloadFileType::DangerLevel initial_danger_level; | 621 DownloadFileType::DangerLevel initial_danger_level; |
583 safe_browsing::DownloadProtectionService::DownloadCheckResult verdict; | 622 safe_browsing::DownloadProtectionService::DownloadCheckResult verdict; |
| 623 DownloadPrefs::DownloadRestriction download_restriction; |
584 | 624 |
585 content::DownloadDangerType expected_danger_type; | 625 content::DownloadDangerType expected_danger_type; |
| 626 bool blocked; |
586 }; | 627 }; |
587 | 628 |
588 class TestDownloadProtectionService | 629 class TestDownloadProtectionService |
589 : public safe_browsing::DownloadProtectionService { | 630 : public safe_browsing::DownloadProtectionService { |
590 public: | 631 public: |
591 TestDownloadProtectionService() : DownloadProtectionService(nullptr) {} | 632 TestDownloadProtectionService() : DownloadProtectionService(nullptr) {} |
592 | 633 |
593 void CheckClientDownload(DownloadItem* download_item, | 634 void CheckClientDownload(DownloadItem* download_item, |
594 const CheckDownloadCallback& callback) override { | 635 const CheckDownloadCallback& callback) override { |
595 callback.Run(MockCheckClientDownload()); | 636 callback.Run(MockCheckClientDownload()); |
(...skipping 28 matching lines...) Expand all Loading... |
624 void ChromeDownloadManagerDelegateTestWithSafeBrowsing::TearDown() { | 665 void ChromeDownloadManagerDelegateTestWithSafeBrowsing::TearDown() { |
625 test_download_protection_service_.reset(); | 666 test_download_protection_service_.reset(); |
626 ChromeDownloadManagerDelegateTest::TearDown(); | 667 ChromeDownloadManagerDelegateTest::TearDown(); |
627 } | 668 } |
628 | 669 |
629 const SafeBrowsingTestParameters kSafeBrowsingTestCases[] = { | 670 const SafeBrowsingTestParameters kSafeBrowsingTestCases[] = { |
630 // SAFE verdict for a safe file. | 671 // SAFE verdict for a safe file. |
631 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 672 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
632 DownloadFileType::NOT_DANGEROUS, | 673 DownloadFileType::NOT_DANGEROUS, |
633 safe_browsing::DownloadProtectionService::SAFE, | 674 safe_browsing::DownloadProtectionService::SAFE, |
| 675 DownloadPrefs::DownloadRestriction::NONE, |
634 | 676 |
635 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS}, | 677 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 678 /*blocked=*/false}, |
636 | 679 |
637 // UNKNOWN verdict for a safe file. | 680 // UNKNOWN verdict for a safe file. |
638 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 681 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
639 DownloadFileType::NOT_DANGEROUS, | 682 DownloadFileType::NOT_DANGEROUS, |
640 safe_browsing::DownloadProtectionService::UNKNOWN, | 683 safe_browsing::DownloadProtectionService::UNKNOWN, |
| 684 DownloadPrefs::DownloadRestriction::NONE, |
641 | 685 |
642 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS}, | 686 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 687 /*blocked=*/false}, |
643 | 688 |
644 // DANGEROUS verdict for a safe file. | 689 // DANGEROUS verdict for a safe file. |
645 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 690 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
646 DownloadFileType::NOT_DANGEROUS, | 691 DownloadFileType::NOT_DANGEROUS, |
647 safe_browsing::DownloadProtectionService::DANGEROUS, | 692 safe_browsing::DownloadProtectionService::DANGEROUS, |
| 693 DownloadPrefs::DownloadRestriction::NONE, |
648 | 694 |
649 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT}, | 695 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT, |
| 696 /*blocked=*/false}, |
650 | 697 |
651 // UNCOMMON verdict for a safe file. | 698 // UNCOMMON verdict for a safe file. |
652 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 699 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
653 DownloadFileType::NOT_DANGEROUS, | 700 DownloadFileType::NOT_DANGEROUS, |
654 safe_browsing::DownloadProtectionService::UNCOMMON, | 701 safe_browsing::DownloadProtectionService::UNCOMMON, |
| 702 DownloadPrefs::DownloadRestriction::NONE, |
655 | 703 |
656 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT}, | 704 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT, |
| 705 /*blocked=*/false}, |
657 | 706 |
658 // POTENTIALLY_UNWANTED verdict for a safe file. | 707 // POTENTIALLY_UNWANTED verdict for a safe file. |
659 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, | 708 {content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
660 DownloadFileType::NOT_DANGEROUS, | 709 DownloadFileType::NOT_DANGEROUS, |
661 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, | 710 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, |
| 711 DownloadPrefs::DownloadRestriction::NONE, |
662 | 712 |
663 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED}, | 713 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED, |
| 714 /*blocked=*/false}, |
664 | 715 |
665 // SAFE verdict for a potentially dangerous file. | 716 // SAFE verdict for a potentially dangerous file. |
666 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 717 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
667 DownloadFileType::ALLOW_ON_USER_GESTURE, | 718 DownloadFileType::ALLOW_ON_USER_GESTURE, |
668 safe_browsing::DownloadProtectionService::SAFE, | 719 safe_browsing::DownloadProtectionService::SAFE, |
| 720 DownloadPrefs::DownloadRestriction::NONE, |
669 | 721 |
670 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS}, | 722 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 723 /*blocked=*/false}, |
671 | 724 |
672 // UNKNOWN verdict for a potentially dangerous file. | 725 // UNKNOWN verdict for a potentially dangerous file. |
673 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 726 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
674 DownloadFileType::ALLOW_ON_USER_GESTURE, | 727 DownloadFileType::ALLOW_ON_USER_GESTURE, |
675 safe_browsing::DownloadProtectionService::UNKNOWN, | 728 safe_browsing::DownloadProtectionService::UNKNOWN, |
| 729 DownloadPrefs::DownloadRestriction::NONE, |
676 | 730 |
677 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE}, | 731 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 732 /*blocked=*/false}, |
| 733 |
| 734 // UNKNOWN verdict for a potentially dangerous file blocked by policy. |
| 735 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 736 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 737 safe_browsing::DownloadProtectionService::UNKNOWN, |
| 738 DownloadPrefs::DownloadRestriction::DANGEROUS_FILES, |
| 739 |
| 740 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 741 /*blocked=*/true}, |
678 | 742 |
679 // DANGEROUS verdict for a potentially dangerous file. | 743 // DANGEROUS verdict for a potentially dangerous file. |
680 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 744 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
681 DownloadFileType::ALLOW_ON_USER_GESTURE, | 745 DownloadFileType::ALLOW_ON_USER_GESTURE, |
682 safe_browsing::DownloadProtectionService::DANGEROUS, | 746 safe_browsing::DownloadProtectionService::DANGEROUS, |
| 747 DownloadPrefs::DownloadRestriction::NONE, |
683 | 748 |
684 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT}, | 749 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT, |
| 750 /*blocked=*/false}, |
685 | 751 |
686 // UNCOMMON verdict for a potentially dangerous file. | 752 // UNCOMMON verdict for a potentially dangerous file. |
687 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 753 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
688 DownloadFileType::ALLOW_ON_USER_GESTURE, | 754 DownloadFileType::ALLOW_ON_USER_GESTURE, |
689 safe_browsing::DownloadProtectionService::UNCOMMON, | 755 safe_browsing::DownloadProtectionService::UNCOMMON, |
| 756 DownloadPrefs::DownloadRestriction::NONE, |
690 | 757 |
691 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT}, | 758 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT, |
| 759 /*blocked=*/false}, |
692 | 760 |
693 // POTENTIALLY_UNWANTED verdict for a potentially dangerous file. | 761 // POTENTIALLY_UNWANTED verdict for a potentially dangerous file. |
694 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 762 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
695 DownloadFileType::ALLOW_ON_USER_GESTURE, | 763 DownloadFileType::ALLOW_ON_USER_GESTURE, |
696 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, | 764 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, |
| 765 DownloadPrefs::DownloadRestriction::NONE, |
697 | 766 |
698 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED}, | 767 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED, |
| 768 /*blocked=*/false}, |
| 769 |
| 770 // POTENTIALLY_UNWANTED verdict for a potentially dangerous file, blocked by |
| 771 // policy. |
| 772 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 773 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 774 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, |
| 775 DownloadPrefs::DownloadRestriction::POTENTIALLY_DANGEROUS_FILES, |
| 776 |
| 777 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED, |
| 778 /*blocked=*/true}, |
| 779 |
| 780 // POTENTIALLY_UNWANTED verdict for a potentially dangerous file, not |
| 781 // blocked by policy. |
| 782 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
| 783 DownloadFileType::ALLOW_ON_USER_GESTURE, |
| 784 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, |
| 785 DownloadPrefs::DownloadRestriction::DANGEROUS_FILES, |
| 786 |
| 787 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED, |
| 788 /*blocked=*/false}, |
699 | 789 |
700 // SAFE verdict for a dangerous file. | 790 // SAFE verdict for a dangerous file. |
701 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 791 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
702 DownloadFileType::DANGEROUS, | 792 DownloadFileType::DANGEROUS, |
703 safe_browsing::DownloadProtectionService::SAFE, | 793 safe_browsing::DownloadProtectionService::SAFE, |
| 794 DownloadPrefs::DownloadRestriction::NONE, |
704 | 795 |
705 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE}, | 796 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 797 /*blocked=*/false}, |
706 | 798 |
707 // UNKNOWN verdict for a dangerous file. | 799 // UNKNOWN verdict for a dangerous file. |
708 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 800 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
709 DownloadFileType::DANGEROUS, | 801 DownloadFileType::DANGEROUS, |
710 safe_browsing::DownloadProtectionService::UNKNOWN, | 802 safe_browsing::DownloadProtectionService::UNKNOWN, |
| 803 DownloadPrefs::DownloadRestriction::NONE, |
711 | 804 |
712 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE}, | 805 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_FILE, |
| 806 /*blocked=*/false}, |
713 | 807 |
714 // DANGEROUS verdict for a dangerous file. | 808 // DANGEROUS verdict for a dangerous file. |
715 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 809 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
716 DownloadFileType::DANGEROUS, | 810 DownloadFileType::DANGEROUS, |
717 safe_browsing::DownloadProtectionService::DANGEROUS, | 811 safe_browsing::DownloadProtectionService::DANGEROUS, |
| 812 DownloadPrefs::DownloadRestriction::NONE, |
718 | 813 |
719 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT}, | 814 content::DOWNLOAD_DANGER_TYPE_DANGEROUS_CONTENT, |
| 815 /*blocked=*/false}, |
720 | 816 |
721 // UNCOMMON verdict for a dangerous file. | 817 // UNCOMMON verdict for a dangerous file. |
722 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 818 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
723 DownloadFileType::DANGEROUS, | 819 DownloadFileType::DANGEROUS, |
724 safe_browsing::DownloadProtectionService::UNCOMMON, | 820 safe_browsing::DownloadProtectionService::UNCOMMON, |
| 821 DownloadPrefs::DownloadRestriction::NONE, |
725 | 822 |
726 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT}, | 823 content::DOWNLOAD_DANGER_TYPE_UNCOMMON_CONTENT, |
| 824 /*blocked=*/false}, |
727 | 825 |
728 // POTENTIALLY_UNWANTED verdict for a dangerous file. | 826 // POTENTIALLY_UNWANTED verdict for a dangerous file. |
729 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, | 827 {content::DOWNLOAD_DANGER_TYPE_MAYBE_DANGEROUS_CONTENT, |
730 DownloadFileType::DANGEROUS, | 828 DownloadFileType::DANGEROUS, |
731 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, | 829 safe_browsing::DownloadProtectionService::POTENTIALLY_UNWANTED, |
| 830 DownloadPrefs::DownloadRestriction::NONE, |
732 | 831 |
733 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED}, | 832 content::DOWNLOAD_DANGER_TYPE_POTENTIALLY_UNWANTED, |
| 833 /*blocked=*/false}, |
734 }; | 834 }; |
735 | 835 |
736 INSTANTIATE_TEST_CASE_P(_, | 836 INSTANTIATE_TEST_CASE_P(_, |
737 ChromeDownloadManagerDelegateTestWithSafeBrowsing, | 837 ChromeDownloadManagerDelegateTestWithSafeBrowsing, |
738 ::testing::ValuesIn(kSafeBrowsingTestCases)); | 838 ::testing::ValuesIn(kSafeBrowsingTestCases)); |
739 | 839 |
740 } // namespace | 840 } // namespace |
741 | 841 |
742 TEST_P(ChromeDownloadManagerDelegateTestWithSafeBrowsing, CheckClientDownload) { | 842 TEST_P(ChromeDownloadManagerDelegateTestWithSafeBrowsing, CheckClientDownload) { |
743 const SafeBrowsingTestParameters& kParameters = GetParam(); | 843 const SafeBrowsingTestParameters& kParameters = GetParam(); |
744 | 844 |
745 std::unique_ptr<content::MockDownloadItem> download_item = | 845 std::unique_ptr<content::MockDownloadItem> download_item = |
746 CreateActiveDownloadItem(0); | 846 CreateActiveDownloadItem(0); |
747 EXPECT_CALL(*delegate(), GetDownloadProtectionService()); | 847 EXPECT_CALL(*delegate(), GetDownloadProtectionService()); |
748 EXPECT_CALL(*download_protection_service(), MockCheckClientDownload()) | 848 EXPECT_CALL(*download_protection_service(), MockCheckClientDownload()) |
749 .WillOnce(Return(kParameters.verdict)); | 849 .WillOnce(Return(kParameters.verdict)); |
750 EXPECT_CALL(*download_item, GetDangerType()) | 850 EXPECT_CALL(*download_item, GetDangerType()) |
751 .WillRepeatedly(Return(kParameters.initial_danger_type)); | 851 .WillRepeatedly(Return(kParameters.initial_danger_type)); |
752 | 852 |
753 if (kParameters.initial_danger_level != DownloadFileType::NOT_DANGEROUS) { | 853 if (kParameters.initial_danger_level != DownloadFileType::NOT_DANGEROUS) { |
754 DownloadItemModel(download_item.get()) | 854 DownloadItemModel(download_item.get()) |
755 .SetDangerLevel(kParameters.initial_danger_level); | 855 .SetDangerLevel(kParameters.initial_danger_level); |
756 } | 856 } |
757 | 857 |
758 if (kParameters.expected_danger_type != | 858 if (kParameters.expected_danger_type != |
759 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { | 859 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS) { |
760 EXPECT_CALL(*download_item, | 860 if (kParameters.blocked) { |
761 OnContentCheckCompleted(kParameters.expected_danger_type)); | 861 EXPECT_CALL(*download_item, |
| 862 OnContentCheckCompleted( |
| 863 // Specifying a dangerous type here would take precendence |
| 864 // over the blocking of the file. |
| 865 content::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 866 content::DOWNLOAD_INTERRUPT_REASON_FILE_BLOCKED)); |
| 867 } else { |
| 868 EXPECT_CALL(*download_item, OnContentCheckCompleted( |
| 869 kParameters.expected_danger_type, |
| 870 content::DOWNLOAD_INTERRUPT_REASON_NONE)); |
| 871 } |
762 } else { | 872 } else { |
763 EXPECT_CALL(*download_item, OnContentCheckCompleted(_)).Times(0); | 873 EXPECT_CALL(*download_item, OnContentCheckCompleted(_, _)).Times(0); |
764 } | 874 } |
765 | 875 |
| 876 pref_service()->SetInteger( |
| 877 prefs::kDownloadRestrictions, |
| 878 static_cast<int>(kParameters.download_restriction)); |
| 879 |
766 base::RunLoop run_loop; | 880 base::RunLoop run_loop; |
767 ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), | 881 ASSERT_FALSE(delegate()->ShouldCompleteDownload(download_item.get(), |
768 run_loop.QuitClosure())); | 882 run_loop.QuitClosure())); |
769 run_loop.Run(); | 883 run_loop.Run(); |
770 } | 884 } |
771 | 885 |
772 #endif // FULL_SAFE_BROWSING | 886 #endif // FULL_SAFE_BROWSING |
773 | 887 |
774 #if defined(OS_ANDROID) | 888 #if defined(OS_ANDROID) |
775 | 889 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
891 test_case.path == ExpectPath::FULL ? fake_path : base::FilePath()); | 1005 test_case.path == ExpectPath::FULL ? fake_path : base::FilePath()); |
892 delegate()->RequestConfirmation(download_item.get(), fake_path, | 1006 delegate()->RequestConfirmation(download_item.get(), fake_path, |
893 test_case.confirmation_reason, callback); | 1007 test_case.confirmation_reason, callback); |
894 loop.Run(); | 1008 loop.Run(); |
895 | 1009 |
896 EXPECT_EQ(test_case.info_bar == ExpectInfoBar::YES ? 1 : 0, | 1010 EXPECT_EQ(test_case.info_bar == ExpectInfoBar::YES ? 1 : 0, |
897 infobar_counter.CheckAndResetInfobarCount()); | 1011 infobar_counter.CheckAndResetInfobarCount()); |
898 } | 1012 } |
899 } | 1013 } |
900 #endif // OS_ANDROID | 1014 #endif // OS_ANDROID |
OLD | NEW |