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