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 "chrome/browser/safe_browsing/download_protection_service.h" | 5 #include "chrome/browser/safe_browsing/download_protection_service.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 .WillRepeatedly(Return(true)); | 525 .WillRepeatedly(Return(true)); |
526 | 526 |
527 // With no referrer and just the bad url, should be marked DANGEROUS. | 527 // With no referrer and just the bad url, should be marked DANGEROUS. |
528 url_chain.push_back(GURL("http://www.evil.com/bla.exe")); | 528 url_chain.push_back(GURL("http://www.evil.com/bla.exe")); |
529 download_service_->CheckClientDownload( | 529 download_service_->CheckClientDownload( |
530 &item, | 530 &item, |
531 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 531 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
532 base::Unretained(this))); | 532 base::Unretained(this))); |
533 MessageLoop::current()->Run(); | 533 MessageLoop::current()->Run(); |
534 | 534 |
535 #if defined(OS_WIN) || defined(OS_MACOSX) | 535 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
536 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 536 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
537 EXPECT_TRUE(HasClientDownloadRequest()); | 537 EXPECT_TRUE(HasClientDownloadRequest()); |
538 ClearClientDownloadRequest(); | 538 ClearClientDownloadRequest(); |
539 #else | 539 #else |
540 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 540 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
541 EXPECT_FALSE(HasClientDownloadRequest()); | 541 EXPECT_FALSE(HasClientDownloadRequest()); |
542 #endif | 542 #endif |
543 | 543 |
544 // Check that the referrer is not matched against the whitelist. | 544 // Check that the referrer is not matched against the whitelist. |
545 referrer = GURL("http://www.google.com/"); | 545 referrer = GURL("http://www.google.com/"); |
546 download_service_->CheckClientDownload( | 546 download_service_->CheckClientDownload( |
547 &item, | 547 &item, |
548 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 548 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
549 base::Unretained(this))); | 549 base::Unretained(this))); |
550 MessageLoop::current()->Run(); | 550 MessageLoop::current()->Run(); |
551 | 551 |
552 #if defined(OS_WIN) || defined(OS_MACOSX) | 552 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
553 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 553 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
554 EXPECT_TRUE(HasClientDownloadRequest()); | 554 EXPECT_TRUE(HasClientDownloadRequest()); |
555 ClearClientDownloadRequest(); | 555 ClearClientDownloadRequest(); |
556 #else | 556 #else |
557 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 557 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
558 EXPECT_FALSE(HasClientDownloadRequest()); | 558 EXPECT_FALSE(HasClientDownloadRequest()); |
559 #endif | 559 #endif |
560 | 560 |
561 // Redirect from a site shouldn't be checked either. | 561 // Redirect from a site shouldn't be checked either. |
562 url_chain.insert(url_chain.begin(), GURL("http://www.google.com/redirect")); | 562 url_chain.insert(url_chain.begin(), GURL("http://www.google.com/redirect")); |
563 download_service_->CheckClientDownload( | 563 download_service_->CheckClientDownload( |
564 &item, | 564 &item, |
565 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 565 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
566 base::Unretained(this))); | 566 base::Unretained(this))); |
567 MessageLoop::current()->Run(); | 567 MessageLoop::current()->Run(); |
568 | 568 |
569 #if defined(OS_WIN) || defined(OS_MACOSX) | 569 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
570 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 570 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
571 EXPECT_TRUE(HasClientDownloadRequest()); | 571 EXPECT_TRUE(HasClientDownloadRequest()); |
572 ClearClientDownloadRequest(); | 572 ClearClientDownloadRequest(); |
573 #else | 573 #else |
574 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 574 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
575 EXPECT_FALSE(HasClientDownloadRequest()); | 575 EXPECT_FALSE(HasClientDownloadRequest()); |
576 #endif | 576 #endif |
577 | 577 |
578 // Only if the final url is whitelisted should it be SAFE. | 578 // Only if the final url is whitelisted should it be SAFE. |
579 url_chain.push_back(GURL("http://www.google.com/a.exe")); | 579 url_chain.push_back(GURL("http://www.google.com/a.exe")); |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 ExtractImageFeatures( | 671 ExtractImageFeatures( |
672 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 672 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
673 .Times(6); | 673 .Times(6); |
674 | 674 |
675 download_service_->CheckClientDownload( | 675 download_service_->CheckClientDownload( |
676 &item, | 676 &item, |
677 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 677 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
678 base::Unretained(this))); | 678 base::Unretained(this))); |
679 MessageLoop::current()->Run(); | 679 MessageLoop::current()->Run(); |
680 | 680 |
681 #if defined(OS_WIN) || defined(OS_MACOSX) | 681 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
682 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 682 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
683 EXPECT_TRUE(HasClientDownloadRequest()); | 683 EXPECT_TRUE(HasClientDownloadRequest()); |
684 ClearClientDownloadRequest(); | 684 ClearClientDownloadRequest(); |
685 #else | 685 #else |
686 // On !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence all | 686 // On !(OS_WIN || OS_MACOSX) || defined(OS_CHROMEOS), |
| 687 // no file types are currently supported. Hence all |
687 // requests to CheckClientDownload() result in a verdict of UNKNOWN. | 688 // requests to CheckClientDownload() result in a verdict of UNKNOWN. |
688 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 689 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
689 EXPECT_FALSE(HasClientDownloadRequest()); | 690 EXPECT_FALSE(HasClientDownloadRequest()); |
690 #endif | 691 #endif |
691 | 692 |
692 // Invalid response should result in UNKNOWN. | 693 // Invalid response should result in UNKNOWN. |
693 response.Clear(); | 694 response.Clear(); |
694 factory.SetFakeResponse( | 695 factory.SetFakeResponse( |
695 DownloadProtectionService::GetDownloadRequestUrl(), | 696 DownloadProtectionService::GetDownloadRequestUrl(), |
696 response.SerializePartialAsString(), | 697 response.SerializePartialAsString(), |
697 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 698 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
698 | 699 |
699 download_service_->CheckClientDownload( | 700 download_service_->CheckClientDownload( |
700 &item, | 701 &item, |
701 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 702 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
702 base::Unretained(this))); | 703 base::Unretained(this))); |
703 MessageLoop::current()->Run(); | 704 MessageLoop::current()->Run(); |
704 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 705 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
705 #if defined(OS_WIN) || defined(OS_MACOSX) | 706 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
706 EXPECT_TRUE(HasClientDownloadRequest()); | 707 EXPECT_TRUE(HasClientDownloadRequest()); |
707 ClearClientDownloadRequest(); | 708 ClearClientDownloadRequest(); |
708 #else | 709 #else |
709 EXPECT_FALSE(HasClientDownloadRequest()); | 710 EXPECT_FALSE(HasClientDownloadRequest()); |
710 #endif | 711 #endif |
711 std::string feedback_ping; | 712 std::string feedback_ping; |
712 std::string feedback_response; | 713 std::string feedback_response; |
713 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 714 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
714 item, &feedback_ping, &feedback_response)); | 715 item, &feedback_ping, &feedback_response)); |
715 | 716 |
716 // If the response is dangerous the result should also be marked as dangerous. | 717 // If the response is dangerous the result should also be marked as dangerous. |
717 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 718 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
718 factory.SetFakeResponse( | 719 factory.SetFakeResponse( |
719 DownloadProtectionService::GetDownloadRequestUrl(), | 720 DownloadProtectionService::GetDownloadRequestUrl(), |
720 response.SerializeAsString(), | 721 response.SerializeAsString(), |
721 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 722 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
722 | 723 |
723 download_service_->CheckClientDownload( | 724 download_service_->CheckClientDownload( |
724 &item, | 725 &item, |
725 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 726 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
726 base::Unretained(this))); | 727 base::Unretained(this))); |
727 MessageLoop::current()->Run(); | 728 MessageLoop::current()->Run(); |
728 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 729 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
729 item, &feedback_ping, &feedback_response)); | 730 item, &feedback_ping, &feedback_response)); |
730 | 731 |
731 #if defined(OS_WIN) || defined(OS_MACOSX) | 732 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
732 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 733 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
733 EXPECT_TRUE(HasClientDownloadRequest()); | 734 EXPECT_TRUE(HasClientDownloadRequest()); |
734 ClearClientDownloadRequest(); | 735 ClearClientDownloadRequest(); |
735 #else | 736 #else |
736 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 737 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
737 EXPECT_FALSE(HasClientDownloadRequest()); | 738 EXPECT_FALSE(HasClientDownloadRequest()); |
738 #endif | 739 #endif |
739 | 740 |
740 // If the response is uncommon the result should also be marked as uncommon. | 741 // If the response is uncommon the result should also be marked as uncommon. |
741 response.set_verdict(ClientDownloadResponse::UNCOMMON); | 742 response.set_verdict(ClientDownloadResponse::UNCOMMON); |
742 factory.SetFakeResponse( | 743 factory.SetFakeResponse( |
743 DownloadProtectionService::GetDownloadRequestUrl(), | 744 DownloadProtectionService::GetDownloadRequestUrl(), |
744 response.SerializeAsString(), | 745 response.SerializeAsString(), |
745 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 746 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
746 | 747 |
747 download_service_->CheckClientDownload( | 748 download_service_->CheckClientDownload( |
748 &item, | 749 &item, |
749 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 750 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
750 base::Unretained(this))); | 751 base::Unretained(this))); |
751 MessageLoop::current()->Run(); | 752 MessageLoop::current()->Run(); |
752 #if defined(OS_WIN) || defined(OS_MACOSX) | 753 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
753 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); | 754 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); |
754 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 755 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
755 item, &feedback_ping, &feedback_response)); | 756 item, &feedback_ping, &feedback_response)); |
756 ClientDownloadRequest decoded_request; | 757 ClientDownloadRequest decoded_request; |
757 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); | 758 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); |
758 EXPECT_EQ(url_chain.back().spec(), decoded_request.url()); | 759 EXPECT_EQ(url_chain.back().spec(), decoded_request.url()); |
759 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 760 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
760 EXPECT_TRUE(HasClientDownloadRequest()); | 761 EXPECT_TRUE(HasClientDownloadRequest()); |
761 ClearClientDownloadRequest(); | 762 ClearClientDownloadRequest(); |
762 #else | 763 #else |
763 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 764 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
764 #endif | 765 #endif |
765 | 766 |
766 // If the response is dangerous_host the result should also be marked as | 767 // If the response is dangerous_host the result should also be marked as |
767 // dangerous_host. | 768 // dangerous_host. |
768 response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); | 769 response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
769 factory.SetFakeResponse( | 770 factory.SetFakeResponse( |
770 DownloadProtectionService::GetDownloadRequestUrl(), | 771 DownloadProtectionService::GetDownloadRequestUrl(), |
771 response.SerializeAsString(), | 772 response.SerializeAsString(), |
772 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 773 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
773 | 774 |
774 download_service_->CheckClientDownload( | 775 download_service_->CheckClientDownload( |
775 &item, | 776 &item, |
776 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 777 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
777 base::Unretained(this))); | 778 base::Unretained(this))); |
778 MessageLoop::current()->Run(); | 779 MessageLoop::current()->Run(); |
779 #if defined(OS_WIN) || defined(OS_MACOSX) | 780 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
780 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); | 781 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); |
781 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 782 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
782 item, &feedback_ping, &feedback_response)); | 783 item, &feedback_ping, &feedback_response)); |
783 EXPECT_EQ(response.SerializeAsString(), feedback_response); | 784 EXPECT_EQ(response.SerializeAsString(), feedback_response); |
784 EXPECT_TRUE(HasClientDownloadRequest()); | 785 EXPECT_TRUE(HasClientDownloadRequest()); |
785 ClearClientDownloadRequest(); | 786 ClearClientDownloadRequest(); |
786 #else | 787 #else |
787 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 788 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
788 #endif | 789 #endif |
789 | 790 |
790 // If the response is POTENTIALLY_UNWANTED the result should also be marked as | 791 // If the response is POTENTIALLY_UNWANTED the result should also be marked as |
791 // POTENTIALLY_UNWANTED. | 792 // POTENTIALLY_UNWANTED. |
792 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); | 793 response.set_verdict(ClientDownloadResponse::POTENTIALLY_UNWANTED); |
793 factory.SetFakeResponse( | 794 factory.SetFakeResponse( |
794 DownloadProtectionService::GetDownloadRequestUrl(), | 795 DownloadProtectionService::GetDownloadRequestUrl(), |
795 response.SerializeAsString(), | 796 response.SerializeAsString(), |
796 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 797 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
797 | 798 |
798 download_service_->CheckClientDownload( | 799 download_service_->CheckClientDownload( |
799 &item, | 800 &item, |
800 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 801 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
801 base::Unretained(this))); | 802 base::Unretained(this))); |
802 MessageLoop::current()->Run(); | 803 MessageLoop::current()->Run(); |
803 | 804 |
804 #if defined(OS_WIN) || defined(OS_MACOSX) | 805 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
805 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); | 806 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); |
806 EXPECT_TRUE(HasClientDownloadRequest()); | 807 EXPECT_TRUE(HasClientDownloadRequest()); |
807 ClearClientDownloadRequest(); | 808 ClearClientDownloadRequest(); |
808 #else | 809 #else |
809 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 810 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
810 EXPECT_FALSE(HasClientDownloadRequest()); | 811 EXPECT_FALSE(HasClientDownloadRequest()); |
811 #endif | 812 #endif |
812 } | 813 } |
813 | 814 |
814 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 815 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 ExtractImageFeatures( | 850 ExtractImageFeatures( |
850 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 851 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
851 .Times(1); | 852 .Times(1); |
852 | 853 |
853 download_service_->CheckClientDownload( | 854 download_service_->CheckClientDownload( |
854 &item, | 855 &item, |
855 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 856 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
856 base::Unretained(this))); | 857 base::Unretained(this))); |
857 MessageLoop::current()->Run(); | 858 MessageLoop::current()->Run(); |
858 | 859 |
859 #if defined(OS_WIN) || defined(OS_MACOSX) | 860 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
860 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 861 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
861 EXPECT_TRUE(HasClientDownloadRequest()); | 862 EXPECT_TRUE(HasClientDownloadRequest()); |
862 ClearClientDownloadRequest(); | 863 ClearClientDownloadRequest(); |
863 #else | 864 #else |
864 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 865 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
865 EXPECT_FALSE(HasClientDownloadRequest()); | 866 EXPECT_FALSE(HasClientDownloadRequest()); |
866 #endif | 867 #endif |
867 } | 868 } |
868 | 869 |
869 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) { | 870 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
903 ExtractImageFeatures( | 904 ExtractImageFeatures( |
904 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 905 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
905 .Times(1); | 906 .Times(1); |
906 | 907 |
907 download_service_->CheckClientDownload( | 908 download_service_->CheckClientDownload( |
908 &item, | 909 &item, |
909 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 910 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
910 base::Unretained(this))); | 911 base::Unretained(this))); |
911 MessageLoop::current()->Run(); | 912 MessageLoop::current()->Run(); |
912 | 913 |
913 #if defined(OS_WIN) || defined(OS_MACOSX) | 914 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
914 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 915 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
915 EXPECT_TRUE(HasClientDownloadRequest()); | 916 EXPECT_TRUE(HasClientDownloadRequest()); |
916 ClearClientDownloadRequest(); | 917 ClearClientDownloadRequest(); |
917 #else | 918 #else |
918 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 919 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
919 EXPECT_FALSE(HasClientDownloadRequest()); | 920 EXPECT_FALSE(HasClientDownloadRequest()); |
920 #endif | 921 #endif |
921 } | 922 } |
922 | 923 |
923 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadData) { | 924 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadData) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 ExtractImageFeatures( | 962 ExtractImageFeatures( |
962 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 963 a_tmp, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
963 .Times(1); | 964 .Times(1); |
964 | 965 |
965 download_service_->CheckClientDownload( | 966 download_service_->CheckClientDownload( |
966 &item, | 967 &item, |
967 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 968 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
968 base::Unretained(this))); | 969 base::Unretained(this))); |
969 MessageLoop::current()->Run(); | 970 MessageLoop::current()->Run(); |
970 | 971 |
971 #if defined(OS_WIN) || defined(OS_MACOSX) | 972 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
972 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 973 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
973 ASSERT_TRUE(HasClientDownloadRequest()); | 974 ASSERT_TRUE(HasClientDownloadRequest()); |
974 const ClientDownloadRequest& request = *GetClientDownloadRequest(); | 975 const ClientDownloadRequest& request = *GetClientDownloadRequest(); |
975 const char kExpectedUrl[] = | 976 const char kExpectedUrl[] = |
976 "data:application/octet-stream:base64," | 977 "data:application/octet-stream:base64," |
977 "ACBF6DFC6F907662F566CA0241DFE8690C48661F440BA1BBD0B86C582845CCC8"; | 978 "ACBF6DFC6F907662F566CA0241DFE8690C48661F440BA1BBD0B86C582845CCC8"; |
978 const char kExpectedRedirect1[] = "data:text/html:base64,"; | 979 const char kExpectedRedirect1[] = "data:text/html:base64,"; |
979 const char kExpectedRedirect2[] = | 980 const char kExpectedRedirect2[] = |
980 "data:text/html:base64," | 981 "data:text/html:base64," |
981 "620680767E15717A57DB11D94D1BEBD32B3344EBC5994DF4FB07B0D473F4EF6B"; | 982 "620680767E15717A57DB11D94D1BEBD32B3344EBC5994DF4FB07B0D473F4EF6B"; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1063 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1064 EXPECT_CALL(*sb_service_->mock_database_manager(), |
1064 MatchDownloadWhitelistUrl(_)) | 1065 MatchDownloadWhitelistUrl(_)) |
1065 .WillRepeatedly(Return(false)); | 1066 .WillRepeatedly(Return(false)); |
1066 | 1067 |
1067 download_service_->CheckClientDownload( | 1068 download_service_->CheckClientDownload( |
1068 &item, | 1069 &item, |
1069 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1070 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1070 base::Unretained(this))); | 1071 base::Unretained(this))); |
1071 MessageLoop::current()->Run(); | 1072 MessageLoop::current()->Run(); |
1072 | 1073 |
1073 #if defined(OS_WIN) || defined(OS_MACOSX) | 1074 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
1074 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1075 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
1075 EXPECT_TRUE(HasClientDownloadRequest()); | 1076 EXPECT_TRUE(HasClientDownloadRequest()); |
1076 const ClientDownloadRequest& request = *GetClientDownloadRequest(); | 1077 const ClientDownloadRequest& request = *GetClientDownloadRequest(); |
1077 EXPECT_TRUE(request.has_download_type()); | 1078 EXPECT_TRUE(request.has_download_type()); |
1078 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, | 1079 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, |
1079 request.download_type()); | 1080 request.download_type()); |
1080 EXPECT_EQ(1, request.archived_binary_size()); | 1081 EXPECT_EQ(1, request.archived_binary_size()); |
1081 const ClientDownloadRequest_ArchivedBinary* archived_binary = | 1082 const ClientDownloadRequest_ArchivedBinary* archived_binary = |
1082 GetRequestArchivedBinary(request, "file.exe"); | 1083 GetRequestArchivedBinary(request, "file.exe"); |
1083 ASSERT_NE(nullptr, archived_binary); | 1084 ASSERT_NE(nullptr, archived_binary); |
1084 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, | 1085 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, |
1085 archived_binary->download_type()); | 1086 archived_binary->download_type()); |
1086 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), | 1087 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), |
1087 archived_binary->length()); | 1088 archived_binary->length()); |
1088 ClearClientDownloadRequest(); | 1089 ClearClientDownloadRequest(); |
1089 #else | 1090 #else |
1090 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence | 1091 // For !(OS_WIN || OS_MACOSX) || defined(OS_CHROMEOS), |
| 1092 // no file types are currently supported. Hence |
1091 // the resulting verdict is UNKNOWN. | 1093 // the resulting verdict is UNKNOWN. |
1092 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1094 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1093 EXPECT_FALSE(HasClientDownloadRequest()); | 1095 EXPECT_FALSE(HasClientDownloadRequest()); |
1094 #endif | 1096 #endif |
1095 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1097 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
1096 | 1098 |
1097 // If the response is dangerous the result should also be marked as | 1099 // If the response is dangerous the result should also be marked as |
1098 // dangerous. | 1100 // dangerous. |
1099 response.set_verdict(ClientDownloadResponse::DANGEROUS); | 1101 response.set_verdict(ClientDownloadResponse::DANGEROUS); |
1100 factory.SetFakeResponse( | 1102 factory.SetFakeResponse( |
1101 DownloadProtectionService::GetDownloadRequestUrl(), | 1103 DownloadProtectionService::GetDownloadRequestUrl(), |
1102 response.SerializeAsString(), | 1104 response.SerializeAsString(), |
1103 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 1105 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
1104 | 1106 |
1105 download_service_->CheckClientDownload( | 1107 download_service_->CheckClientDownload( |
1106 &item, | 1108 &item, |
1107 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1109 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1108 base::Unretained(this))); | 1110 base::Unretained(this))); |
1109 MessageLoop::current()->Run(); | 1111 MessageLoop::current()->Run(); |
1110 | 1112 |
1111 #if defined(OS_WIN) || defined(OS_MACOSX) | 1113 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
1112 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1114 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
1113 EXPECT_TRUE(HasClientDownloadRequest()); | 1115 EXPECT_TRUE(HasClientDownloadRequest()); |
1114 ClearClientDownloadRequest(); | 1116 ClearClientDownloadRequest(); |
1115 #else | 1117 #else |
1116 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1118 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1117 EXPECT_FALSE(HasClientDownloadRequest()); | 1119 EXPECT_FALSE(HasClientDownloadRequest()); |
1118 #endif | 1120 #endif |
1119 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1121 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
1120 | 1122 |
1121 // Repeat the test with an archive inside the zip file in addition to the | 1123 // Repeat the test with an archive inside the zip file in addition to the |
1122 // executable. | 1124 // executable. |
1123 ASSERT_EQ(static_cast<int>(file_contents.size()), | 1125 ASSERT_EQ(static_cast<int>(file_contents.size()), |
1124 base::WriteFile( | 1126 base::WriteFile( |
1125 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")), | 1127 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")), |
1126 file_contents.data(), file_contents.size())); | 1128 file_contents.data(), file_contents.size())); |
1127 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | 1129 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); |
1128 | 1130 |
1129 download_service_->CheckClientDownload( | 1131 download_service_->CheckClientDownload( |
1130 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1132 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1131 base::Unretained(this))); | 1133 base::Unretained(this))); |
1132 MessageLoop::current()->Run(); | 1134 MessageLoop::current()->Run(); |
1133 | 1135 |
1134 #if defined(OS_WIN) || defined(OS_MACOSX) | 1136 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
1135 ASSERT_TRUE(HasClientDownloadRequest()); | 1137 ASSERT_TRUE(HasClientDownloadRequest()); |
1136 EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size()); | 1138 EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size()); |
1137 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); | 1139 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); |
1138 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, | 1140 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, |
1139 GetClientDownloadRequest()->download_type()); | 1141 GetClientDownloadRequest()->download_type()); |
1140 ClearClientDownloadRequest(); | 1142 ClearClientDownloadRequest(); |
1141 #else | 1143 #else |
1142 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence | 1144 // For !(OS_WIN || OS_MACOSX) || defined(OS_CHROMEOS), |
| 1145 // no file types are currently supported. Hence |
1143 // the resulting verdict is UNKNOWN. | 1146 // the resulting verdict is UNKNOWN. |
1144 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1147 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1145 EXPECT_FALSE(HasClientDownloadRequest()); | 1148 EXPECT_FALSE(HasClientDownloadRequest()); |
1146 #endif | 1149 #endif |
1147 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1150 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
1148 | 1151 |
1149 // Repeat the test with just the archive inside the zip file. | 1152 // Repeat the test with just the archive inside the zip file. |
1150 ASSERT_TRUE( | 1153 ASSERT_TRUE( |
1151 base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false)); | 1154 base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false)); |
1152 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); | 1155 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); |
1153 | 1156 |
1154 download_service_->CheckClientDownload( | 1157 download_service_->CheckClientDownload( |
1155 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1158 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1156 base::Unretained(this))); | 1159 base::Unretained(this))); |
1157 MessageLoop::current()->Run(); | 1160 MessageLoop::current()->Run(); |
1158 | 1161 |
1159 #if defined(OS_WIN) || defined(OS_MACOSX) | 1162 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
1160 ASSERT_TRUE(HasClientDownloadRequest()); | 1163 ASSERT_TRUE(HasClientDownloadRequest()); |
1161 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); | 1164 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); |
1162 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); | 1165 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); |
1163 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE, | 1166 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE, |
1164 GetClientDownloadRequest()->download_type()); | 1167 GetClientDownloadRequest()->download_type()); |
1165 ClearClientDownloadRequest(); | 1168 ClearClientDownloadRequest(); |
1166 #else | 1169 #else |
1167 // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence | 1170 // For !(OS_WIN || OS_MACOSX) || defined(OS_CHROMEOS), |
| 1171 // no file types are currently supported. Hence |
1168 // the resulting verdict is UNKNOWN. | 1172 // the resulting verdict is UNKNOWN. |
1169 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1173 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1170 EXPECT_FALSE(HasClientDownloadRequest()); | 1174 EXPECT_FALSE(HasClientDownloadRequest()); |
1171 #endif | 1175 #endif |
1172 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1176 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
1173 } | 1177 } |
1174 | 1178 |
1175 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { | 1179 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { |
1176 base::ScopedTempDir download_dir; | 1180 base::ScopedTempDir download_dir; |
1177 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); | 1181 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1296 EXPECT_CALL( | 1300 EXPECT_CALL( |
1297 *binary_feature_extractor_.get(), | 1301 *binary_feature_extractor_.get(), |
1298 ExtractImageFeatures(tmp_path, BinaryFeatureExtractor::kDefaultOptions, | 1302 ExtractImageFeatures(tmp_path, BinaryFeatureExtractor::kDefaultOptions, |
1299 _, _)) | 1303 _, _)) |
1300 .WillOnce(SetDosHeaderContents("dummy dos header")); | 1304 .WillOnce(SetDosHeaderContents("dummy dos header")); |
1301 download_service_->CheckClientDownload( | 1305 download_service_->CheckClientDownload( |
1302 &item, | 1306 &item, |
1303 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1307 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1304 base::Unretained(this))); | 1308 base::Unretained(this))); |
1305 | 1309 |
1306 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1310 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
1307 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1311 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1308 MessageLoop::current()->Run(); | 1312 MessageLoop::current()->Run(); |
1309 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1313 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1310 EXPECT_EQ(NULL, fetcher); | 1314 EXPECT_EQ(NULL, fetcher); |
1311 EXPECT_FALSE(HasClientDownloadRequest()); | 1315 EXPECT_FALSE(HasClientDownloadRequest()); |
1312 #else | 1316 #else |
1313 // Run the message loop(s) until SendRequest is called. | 1317 // Run the message loop(s) until SendRequest is called. |
1314 FlushThreadMessageLoops(); | 1318 FlushThreadMessageLoops(); |
1315 EXPECT_TRUE(HasClientDownloadRequest()); | 1319 EXPECT_TRUE(HasClientDownloadRequest()); |
1316 ClearClientDownloadRequest(); | 1320 ClearClientDownloadRequest(); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1386 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)); | 1390 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path, _)); |
1387 EXPECT_CALL(*binary_feature_extractor_.get(), | 1391 EXPECT_CALL(*binary_feature_extractor_.get(), |
1388 ExtractImageFeatures(tmp_path, | 1392 ExtractImageFeatures(tmp_path, |
1389 BinaryFeatureExtractor::kDefaultOptions, | 1393 BinaryFeatureExtractor::kDefaultOptions, |
1390 _, _)); | 1394 _, _)); |
1391 download_service_->CheckClientDownload( | 1395 download_service_->CheckClientDownload( |
1392 &item, | 1396 &item, |
1393 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1397 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1394 base::Unretained(this))); | 1398 base::Unretained(this))); |
1395 | 1399 |
1396 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1400 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
1397 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1401 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1398 MessageLoop::current()->Run(); | 1402 MessageLoop::current()->Run(); |
1399 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1403 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1400 EXPECT_EQ(NULL, fetcher); | 1404 EXPECT_EQ(NULL, fetcher); |
1401 EXPECT_FALSE(HasClientDownloadRequest()); | 1405 EXPECT_FALSE(HasClientDownloadRequest()); |
1402 #else | 1406 #else |
1403 // Run the message loop(s) until SendRequest is called. | 1407 // Run the message loop(s) until SendRequest is called. |
1404 FlushThreadMessageLoops(); | 1408 FlushThreadMessageLoops(); |
1405 EXPECT_TRUE(HasClientDownloadRequest()); | 1409 EXPECT_TRUE(HasClientDownloadRequest()); |
1406 ClearClientDownloadRequest(); | 1410 ClearClientDownloadRequest(); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 .WillRepeatedly(SetDosHeaderContents("dummy dos header")); | 1483 .WillRepeatedly(SetDosHeaderContents("dummy dos header")); |
1480 | 1484 |
1481 // First test with no history match for the tab URL. | 1485 // First test with no history match for the tab URL. |
1482 { | 1486 { |
1483 TestURLFetcherWatcher fetcher_watcher(&factory); | 1487 TestURLFetcherWatcher fetcher_watcher(&factory); |
1484 download_service_->CheckClientDownload( | 1488 download_service_->CheckClientDownload( |
1485 &item, | 1489 &item, |
1486 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1490 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1487 base::Unretained(this))); | 1491 base::Unretained(this))); |
1488 | 1492 |
1489 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1493 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
1490 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1494 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1491 MessageLoop::current()->Run(); | 1495 MessageLoop::current()->Run(); |
1492 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1496 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1493 EXPECT_EQ(NULL, fetcher); | 1497 EXPECT_EQ(NULL, fetcher); |
1494 EXPECT_FALSE(HasClientDownloadRequest()); | 1498 EXPECT_FALSE(HasClientDownloadRequest()); |
1495 #else | 1499 #else |
1496 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); | 1500 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); |
1497 EXPECT_TRUE(HasClientDownloadRequest()); | 1501 EXPECT_TRUE(HasClientDownloadRequest()); |
1498 ClearClientDownloadRequest(); | 1502 ClearClientDownloadRequest(); |
1499 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1503 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1558 redirects, | 1562 redirects, |
1559 ui::PAGE_TRANSITION_TYPED, | 1563 ui::PAGE_TRANSITION_TYPED, |
1560 history::SOURCE_BROWSED, | 1564 history::SOURCE_BROWSED, |
1561 false); | 1565 false); |
1562 | 1566 |
1563 TestURLFetcherWatcher fetcher_watcher(&factory); | 1567 TestURLFetcherWatcher fetcher_watcher(&factory); |
1564 download_service_->CheckClientDownload( | 1568 download_service_->CheckClientDownload( |
1565 &item, | 1569 &item, |
1566 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1570 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1567 base::Unretained(this))); | 1571 base::Unretained(this))); |
1568 #if !defined(OS_WIN) && !defined(OS_MACOSX) | 1572 #if !defined(OS_WIN) && !defined(OS_MACOSX) && !defined(OS_CHROMEOS) |
1569 // SendRequest is not called. Wait for FinishRequest to call our callback. | 1573 // SendRequest is not called. Wait for FinishRequest to call our callback. |
1570 MessageLoop::current()->Run(); | 1574 MessageLoop::current()->Run(); |
1571 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1575 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
1572 EXPECT_EQ(NULL, fetcher); | 1576 EXPECT_EQ(NULL, fetcher); |
1573 EXPECT_FALSE(HasClientDownloadRequest()); | 1577 EXPECT_FALSE(HasClientDownloadRequest()); |
1574 #else | 1578 #else |
1575 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); | 1579 EXPECT_EQ(0, fetcher_watcher.WaitForRequest()); |
1576 EXPECT_TRUE(HasClientDownloadRequest()); | 1580 EXPECT_TRUE(HasClientDownloadRequest()); |
1577 ClearClientDownloadRequest(); | 1581 ClearClientDownloadRequest(); |
1578 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); | 1582 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1724 download_service_->download_request_timeout_ms_ = 10; | 1728 download_service_->download_request_timeout_ms_ = 10; |
1725 download_service_->CheckClientDownload( | 1729 download_service_->CheckClientDownload( |
1726 &item, | 1730 &item, |
1727 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1731 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
1728 base::Unretained(this))); | 1732 base::Unretained(this))); |
1729 | 1733 |
1730 // The request should time out because the HTTP request hasn't returned | 1734 // The request should time out because the HTTP request hasn't returned |
1731 // anything yet. | 1735 // anything yet. |
1732 MessageLoop::current()->Run(); | 1736 MessageLoop::current()->Run(); |
1733 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1737 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
1734 #if defined(OS_WIN) || defined(OS_MACOSX) | 1738 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_CHROMEOS) |
1735 EXPECT_TRUE(HasClientDownloadRequest()); | 1739 EXPECT_TRUE(HasClientDownloadRequest()); |
1736 ClearClientDownloadRequest(); | 1740 ClearClientDownloadRequest(); |
1737 #else | 1741 #else |
1738 EXPECT_FALSE(HasClientDownloadRequest()); | 1742 EXPECT_FALSE(HasClientDownloadRequest()); |
1739 #endif | 1743 #endif |
1740 } | 1744 } |
1741 | 1745 |
1742 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { | 1746 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { |
1743 net::TestURLFetcherFactory factory; | 1747 net::TestURLFetcherFactory factory; |
1744 | 1748 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 | 1949 |
1946 EXPECT_CALL(mock_download_item, GetDangerType()) | 1950 EXPECT_CALL(mock_download_item, GetDangerType()) |
1947 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); | 1951 .WillOnce(Return(content::DOWNLOAD_DANGER_TYPE_DANGEROUS_HOST)); |
1948 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); | 1952 EXPECT_CALL(mock_page_navigator, OpenURL(OpenURLParamsWithContextValue("7"))); |
1949 | 1953 |
1950 download_service_->ShowDetailsForDownload(mock_download_item, | 1954 download_service_->ShowDetailsForDownload(mock_download_item, |
1951 &mock_page_navigator); | 1955 &mock_page_navigator); |
1952 } | 1956 } |
1953 | 1957 |
1954 } // namespace safe_browsing | 1958 } // namespace safe_browsing |
OLD | NEW |