| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); | 435 .WillRepeatedly(ReturnRef(GURL::EmptyGURL())); |
| 436 EXPECT_CALL(*item, GetHash()).WillRepeatedly(ReturnRef(hash_)); | 436 EXPECT_CALL(*item, GetHash()).WillRepeatedly(ReturnRef(hash_)); |
| 437 EXPECT_CALL(*item, GetReceivedBytes()).WillRepeatedly(Return(100)); | 437 EXPECT_CALL(*item, GetReceivedBytes()).WillRepeatedly(Return(100)); |
| 438 EXPECT_CALL(*item, HasUserGesture()).WillRepeatedly(Return(true)); | 438 EXPECT_CALL(*item, HasUserGesture()).WillRepeatedly(Return(true)); |
| 439 EXPECT_CALL(*item, GetRemoteAddress()).WillRepeatedly(Return("")); | 439 EXPECT_CALL(*item, GetRemoteAddress()).WillRepeatedly(Return("")); |
| 440 } | 440 } |
| 441 | 441 |
| 442 private: | 442 private: |
| 443 // Helper functions for FlushThreadMessageLoops. | 443 // Helper functions for FlushThreadMessageLoops. |
| 444 void RunAllPendingAndQuitUI() { | 444 void RunAllPendingAndQuitUI() { |
| 445 base::MessageLoop::current()->RunUntilIdle(); | 445 base::RunLoop().RunUntilIdle(); |
| 446 BrowserThread::PostTask( | 446 BrowserThread::PostTask( |
| 447 BrowserThread::UI, | 447 BrowserThread::UI, |
| 448 FROM_HERE, | 448 FROM_HERE, |
| 449 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop, | 449 base::Bind(&DownloadProtectionServiceTest::QuitMessageLoop, |
| 450 base::Unretained(this))); | 450 base::Unretained(this))); |
| 451 } | 451 } |
| 452 | 452 |
| 453 void QuitMessageLoop() { base::MessageLoop::current()->QuitWhenIdle(); } | 453 void QuitMessageLoop() { base::MessageLoop::current()->QuitWhenIdle(); } |
| 454 | 454 |
| 455 void PostRunMessageLoopTask(BrowserThread::ID thread) { | 455 void PostRunMessageLoopTask(BrowserThread::ID thread) { |
| 456 BrowserThread::PostTask( | 456 BrowserThread::PostTask( |
| 457 thread, | 457 thread, |
| 458 FROM_HERE, | 458 FROM_HERE, |
| 459 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI, | 459 base::Bind(&DownloadProtectionServiceTest::RunAllPendingAndQuitUI, |
| 460 base::Unretained(this))); | 460 base::Unretained(this))); |
| 461 } | 461 } |
| 462 | 462 |
| 463 void FlushMessageLoop(BrowserThread::ID thread) { | 463 void FlushMessageLoop(BrowserThread::ID thread) { |
| 464 BrowserThread::PostTask( | 464 BrowserThread::PostTask( |
| 465 BrowserThread::UI, | 465 BrowserThread::UI, |
| 466 FROM_HERE, | 466 FROM_HERE, |
| 467 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, | 467 base::Bind(&DownloadProtectionServiceTest::PostRunMessageLoopTask, |
| 468 base::Unretained(this), thread)); | 468 base::Unretained(this), thread)); |
| 469 MessageLoop::current()->Run(); | 469 base::RunLoop().Run(); |
| 470 } | 470 } |
| 471 | 471 |
| 472 void OnClientDownloadRequest(content::DownloadItem* download, | 472 void OnClientDownloadRequest(content::DownloadItem* download, |
| 473 const ClientDownloadRequest* request) { | 473 const ClientDownloadRequest* request) { |
| 474 if (request) | 474 if (request) |
| 475 last_client_download_request_.reset(new ClientDownloadRequest(*request)); | 475 last_client_download_request_.reset(new ClientDownloadRequest(*request)); |
| 476 else | 476 else |
| 477 last_client_download_request_.reset(); | 477 last_client_download_request_.reset(); |
| 478 } | 478 } |
| 479 | 479 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 } | 573 } |
| 574 | 574 |
| 575 std::string file_contents = "corrupt zip file"; | 575 std::string file_contents = "corrupt zip file"; |
| 576 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | 576 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( |
| 577 tmp_path_, file_contents.data(), file_contents.size())); | 577 tmp_path_, file_contents.data(), file_contents.size())); |
| 578 | 578 |
| 579 download_service_->CheckClientDownload( | 579 download_service_->CheckClientDownload( |
| 580 &item, | 580 &item, |
| 581 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 581 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 582 base::Unretained(this))); | 582 base::Unretained(this))); |
| 583 MessageLoop::current()->Run(); | 583 base::RunLoop().Run(); |
| 584 | 584 |
| 585 const bool expect_request = is_extended_reporting && !is_incognito; | 585 const bool expect_request = is_extended_reporting && !is_incognito; |
| 586 | 586 |
| 587 if (expect_request) { | 587 if (expect_request) { |
| 588 ASSERT_TRUE(HasClientDownloadRequest()); | 588 ASSERT_TRUE(HasClientDownloadRequest()); |
| 589 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); | 589 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); |
| 590 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); | 590 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); |
| 591 EXPECT_EQ(ClientDownloadRequest_DownloadType_INVALID_ZIP, | 591 EXPECT_EQ(ClientDownloadRequest_DownloadType_INVALID_ZIP, |
| 592 GetClientDownloadRequest()->download_type()); | 592 GetClientDownloadRequest()->download_type()); |
| 593 ClearClientDownloadRequest(); | 593 ClearClientDownloadRequest(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 606 PrepareBasicDownloadItem( | 606 PrepareBasicDownloadItem( |
| 607 &item, | 607 &item, |
| 608 std::vector<std::string>(), // empty url_chain | 608 std::vector<std::string>(), // empty url_chain |
| 609 "http://www.google.com/", // referrer | 609 "http://www.google.com/", // referrer |
| 610 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 610 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 611 FILE_PATH_LITERAL("a.exe")); // final_path | 611 FILE_PATH_LITERAL("a.exe")); // final_path |
| 612 download_service_->CheckClientDownload( | 612 download_service_->CheckClientDownload( |
| 613 &item, | 613 &item, |
| 614 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 614 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 615 base::Unretained(this))); | 615 base::Unretained(this))); |
| 616 MessageLoop::current()->Run(); | 616 base::RunLoop().Run(); |
| 617 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 617 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 618 EXPECT_FALSE(HasClientDownloadRequest()); | 618 EXPECT_FALSE(HasClientDownloadRequest()); |
| 619 Mock::VerifyAndClearExpectations(&item); | 619 Mock::VerifyAndClearExpectations(&item); |
| 620 | 620 |
| 621 PrepareBasicDownloadItem( | 621 PrepareBasicDownloadItem( |
| 622 &item, | 622 &item, |
| 623 {"file://www.google.com/"}, // url_chain | 623 {"file://www.google.com/"}, // url_chain |
| 624 "http://www.google.com/", // referrer | 624 "http://www.google.com/", // referrer |
| 625 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 625 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 626 FILE_PATH_LITERAL("a.exe")); // final_path | 626 FILE_PATH_LITERAL("a.exe")); // final_path |
| 627 download_service_->CheckClientDownload( | 627 download_service_->CheckClientDownload( |
| 628 &item, | 628 &item, |
| 629 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 629 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 630 base::Unretained(this))); | 630 base::Unretained(this))); |
| 631 MessageLoop::current()->Run(); | 631 base::RunLoop().Run(); |
| 632 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 632 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 633 EXPECT_FALSE(HasClientDownloadRequest()); | 633 EXPECT_FALSE(HasClientDownloadRequest()); |
| 634 } | 634 } |
| 635 | 635 |
| 636 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadNotABinary) { | 636 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadNotABinary) { |
| 637 content::MockDownloadItem item; | 637 content::MockDownloadItem item; |
| 638 PrepareBasicDownloadItem( | 638 PrepareBasicDownloadItem( |
| 639 &item, | 639 &item, |
| 640 std::vector<std::string>(), // empty url_chain | 640 std::vector<std::string>(), // empty url_chain |
| 641 "http://www.google.com/", // referrer | 641 "http://www.google.com/", // referrer |
| 642 FILE_PATH_LITERAL("a.tmp"), // tmp_path | 642 FILE_PATH_LITERAL("a.tmp"), // tmp_path |
| 643 FILE_PATH_LITERAL("a.txt")); // final_path | 643 FILE_PATH_LITERAL("a.txt")); // final_path |
| 644 download_service_->CheckClientDownload( | 644 download_service_->CheckClientDownload( |
| 645 &item, | 645 &item, |
| 646 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 646 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 647 base::Unretained(this))); | 647 base::Unretained(this))); |
| 648 MessageLoop::current()->Run(); | 648 base::RunLoop().Run(); |
| 649 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 649 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 650 EXPECT_FALSE(HasClientDownloadRequest()); | 650 EXPECT_FALSE(HasClientDownloadRequest()); |
| 651 } | 651 } |
| 652 | 652 |
| 653 TEST_F(DownloadProtectionServiceTest, | 653 TEST_F(DownloadProtectionServiceTest, |
| 654 CheckClientDownloadWhitelistedUrlWithoutSampling) { | 654 CheckClientDownloadWhitelistedUrlWithoutSampling) { |
| 655 // Response to any requests will be DANGEROUS. | 655 // Response to any requests will be DANGEROUS. |
| 656 net::FakeURLFetcherFactory factory(NULL); | 656 net::FakeURLFetcherFactory factory(NULL); |
| 657 PrepareResponse( | 657 PrepareResponse( |
| 658 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 658 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 684 .WillRepeatedly(Return(true)); | 684 .WillRepeatedly(Return(true)); |
| 685 | 685 |
| 686 // With no referrer and just the bad url, should be marked DANGEROUS. | 686 // With no referrer and just the bad url, should be marked DANGEROUS. |
| 687 url_chain_.push_back(GURL("http://www.evil.com/bla.exe")); | 687 url_chain_.push_back(GURL("http://www.evil.com/bla.exe")); |
| 688 // Set sample rate to 0 to prevent sampling. | 688 // Set sample rate to 0 to prevent sampling. |
| 689 SetWhitelistedDownloadSampleRate(0); | 689 SetWhitelistedDownloadSampleRate(0); |
| 690 download_service_->CheckClientDownload( | 690 download_service_->CheckClientDownload( |
| 691 &item, | 691 &item, |
| 692 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 692 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 693 base::Unretained(this))); | 693 base::Unretained(this))); |
| 694 MessageLoop::current()->Run(); | 694 base::RunLoop().Run(); |
| 695 | 695 |
| 696 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 696 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 697 EXPECT_TRUE(HasClientDownloadRequest()); | 697 EXPECT_TRUE(HasClientDownloadRequest()); |
| 698 EXPECT_FALSE(GetClientDownloadRequest()->skipped_url_whitelist()); | 698 EXPECT_FALSE(GetClientDownloadRequest()->skipped_url_whitelist()); |
| 699 EXPECT_FALSE(GetClientDownloadRequest()->skipped_certificate_whitelist()); | 699 EXPECT_FALSE(GetClientDownloadRequest()->skipped_certificate_whitelist()); |
| 700 ClearClientDownloadRequest(); | 700 ClearClientDownloadRequest(); |
| 701 | 701 |
| 702 // Check that the referrer is not matched against the whitelist. | 702 // Check that the referrer is not matched against the whitelist. |
| 703 referrer_ = GURL("http://www.google.com/"); | 703 referrer_ = GURL("http://www.google.com/"); |
| 704 download_service_->CheckClientDownload( | 704 download_service_->CheckClientDownload( |
| 705 &item, | 705 &item, |
| 706 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 706 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 707 base::Unretained(this))); | 707 base::Unretained(this))); |
| 708 MessageLoop::current()->Run(); | 708 base::RunLoop().Run(); |
| 709 | 709 |
| 710 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 710 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 711 EXPECT_TRUE(HasClientDownloadRequest()); | 711 EXPECT_TRUE(HasClientDownloadRequest()); |
| 712 EXPECT_FALSE(GetClientDownloadRequest()->skipped_url_whitelist()); | 712 EXPECT_FALSE(GetClientDownloadRequest()->skipped_url_whitelist()); |
| 713 EXPECT_FALSE(GetClientDownloadRequest()->skipped_certificate_whitelist()); | 713 EXPECT_FALSE(GetClientDownloadRequest()->skipped_certificate_whitelist()); |
| 714 ClearClientDownloadRequest(); | 714 ClearClientDownloadRequest(); |
| 715 | 715 |
| 716 // Redirect from a site shouldn't be checked either. | 716 // Redirect from a site shouldn't be checked either. |
| 717 url_chain_.insert(url_chain_.begin(), GURL("http://www.google.com/redirect")); | 717 url_chain_.insert(url_chain_.begin(), GURL("http://www.google.com/redirect")); |
| 718 download_service_->CheckClientDownload( | 718 download_service_->CheckClientDownload( |
| 719 &item, | 719 &item, |
| 720 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 720 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 721 base::Unretained(this))); | 721 base::Unretained(this))); |
| 722 MessageLoop::current()->Run(); | 722 base::RunLoop().Run(); |
| 723 | 723 |
| 724 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 724 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 725 EXPECT_TRUE(HasClientDownloadRequest()); | 725 EXPECT_TRUE(HasClientDownloadRequest()); |
| 726 EXPECT_FALSE(GetClientDownloadRequest()->skipped_url_whitelist()); | 726 EXPECT_FALSE(GetClientDownloadRequest()->skipped_url_whitelist()); |
| 727 EXPECT_FALSE(GetClientDownloadRequest()->skipped_certificate_whitelist()); | 727 EXPECT_FALSE(GetClientDownloadRequest()->skipped_certificate_whitelist()); |
| 728 ClearClientDownloadRequest(); | 728 ClearClientDownloadRequest(); |
| 729 | 729 |
| 730 // Only if the final url is whitelisted should it be SAFE. | 730 // Only if the final url is whitelisted should it be SAFE. |
| 731 url_chain_.push_back(GURL("http://www.google.com/a.exe")); | 731 url_chain_.push_back(GURL("http://www.google.com/a.exe")); |
| 732 download_service_->CheckClientDownload( | 732 download_service_->CheckClientDownload( |
| 733 &item, | 733 &item, |
| 734 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 734 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 735 base::Unretained(this))); | 735 base::Unretained(this))); |
| 736 MessageLoop::current()->Run(); | 736 base::RunLoop().Run(); |
| 737 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 737 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 738 // TODO(grt): Make the service produce the request even when the URL is | 738 // TODO(grt): Make the service produce the request even when the URL is |
| 739 // whitelisted. | 739 // whitelisted. |
| 740 EXPECT_FALSE(HasClientDownloadRequest()); | 740 EXPECT_FALSE(HasClientDownloadRequest()); |
| 741 } | 741 } |
| 742 | 742 |
| 743 TEST_F(DownloadProtectionServiceTest, | 743 TEST_F(DownloadProtectionServiceTest, |
| 744 CheckClientDownloadWhitelistedUrlWithSampling) { | 744 CheckClientDownloadWhitelistedUrlWithSampling) { |
| 745 // Server responses "SAFE" to every requests coming from whitelisted | 745 // Server responses "SAFE" to every requests coming from whitelisted |
| 746 // download. | 746 // download. |
| (...skipping 27 matching lines...) Expand all Loading... |
| 774 SetWhitelistedDownloadSampleRate(1.00); | 774 SetWhitelistedDownloadSampleRate(1.00); |
| 775 // Case (1): is_extended_reporting && is_incognito. | 775 // Case (1): is_extended_reporting && is_incognito. |
| 776 // ClientDownloadRequest should NOT be sent. | 776 // ClientDownloadRequest should NOT be sent. |
| 777 SetExtendedReportingPreference(true); | 777 SetExtendedReportingPreference(true); |
| 778 EXPECT_CALL(item, GetBrowserContext()) | 778 EXPECT_CALL(item, GetBrowserContext()) |
| 779 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); | 779 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); |
| 780 download_service_->CheckClientDownload( | 780 download_service_->CheckClientDownload( |
| 781 &item, | 781 &item, |
| 782 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 782 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 783 base::Unretained(this))); | 783 base::Unretained(this))); |
| 784 MessageLoop::current()->Run(); | 784 base::RunLoop().Run(); |
| 785 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 785 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 786 EXPECT_FALSE(HasClientDownloadRequest()); | 786 EXPECT_FALSE(HasClientDownloadRequest()); |
| 787 | 787 |
| 788 // Case (2): is_extended_reporting && !is_incognito. | 788 // Case (2): is_extended_reporting && !is_incognito. |
| 789 // ClientDownloadRequest should be sent. | 789 // ClientDownloadRequest should be sent. |
| 790 EXPECT_CALL(item, GetBrowserContext()) | 790 EXPECT_CALL(item, GetBrowserContext()) |
| 791 .WillRepeatedly(Return(profile_.get())); | 791 .WillRepeatedly(Return(profile_.get())); |
| 792 download_service_->CheckClientDownload( | 792 download_service_->CheckClientDownload( |
| 793 &item, | 793 &item, |
| 794 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 794 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 795 base::Unretained(this))); | 795 base::Unretained(this))); |
| 796 MessageLoop::current()->Run(); | 796 base::RunLoop().Run(); |
| 797 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 797 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 798 EXPECT_TRUE(HasClientDownloadRequest()); | 798 EXPECT_TRUE(HasClientDownloadRequest()); |
| 799 EXPECT_TRUE(GetClientDownloadRequest()->skipped_url_whitelist()); | 799 EXPECT_TRUE(GetClientDownloadRequest()->skipped_url_whitelist()); |
| 800 ClearClientDownloadRequest(); | 800 ClearClientDownloadRequest(); |
| 801 | 801 |
| 802 // Case (3): !is_extended_reporting && is_incognito. | 802 // Case (3): !is_extended_reporting && is_incognito. |
| 803 // ClientDownloadRequest should NOT be sent. | 803 // ClientDownloadRequest should NOT be sent. |
| 804 SetExtendedReportingPreference(false); | 804 SetExtendedReportingPreference(false); |
| 805 EXPECT_CALL(item, GetBrowserContext()) | 805 EXPECT_CALL(item, GetBrowserContext()) |
| 806 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); | 806 .WillRepeatedly(Return(profile_->GetOffTheRecordProfile())); |
| 807 download_service_->CheckClientDownload( | 807 download_service_->CheckClientDownload( |
| 808 &item, | 808 &item, |
| 809 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 809 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 810 base::Unretained(this))); | 810 base::Unretained(this))); |
| 811 MessageLoop::current()->Run(); | 811 base::RunLoop().Run(); |
| 812 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 812 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 813 EXPECT_FALSE(HasClientDownloadRequest()); | 813 EXPECT_FALSE(HasClientDownloadRequest()); |
| 814 | 814 |
| 815 // Case (4): !is_extended_reporting && !is_incognito. | 815 // Case (4): !is_extended_reporting && !is_incognito. |
| 816 // ClientDownloadRequest should NOT be sent. | 816 // ClientDownloadRequest should NOT be sent. |
| 817 EXPECT_CALL(item, GetBrowserContext()) | 817 EXPECT_CALL(item, GetBrowserContext()) |
| 818 .WillRepeatedly(Return(profile_.get())); | 818 .WillRepeatedly(Return(profile_.get())); |
| 819 download_service_->CheckClientDownload( | 819 download_service_->CheckClientDownload( |
| 820 &item, | 820 &item, |
| 821 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 821 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 822 base::Unretained(this))); | 822 base::Unretained(this))); |
| 823 MessageLoop::current()->Run(); | 823 base::RunLoop().Run(); |
| 824 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 824 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 825 EXPECT_FALSE(HasClientDownloadRequest()); | 825 EXPECT_FALSE(HasClientDownloadRequest()); |
| 826 } | 826 } |
| 827 | 827 |
| 828 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSampledFile) { | 828 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSampledFile) { |
| 829 // Server response will be discarded. | 829 // Server response will be discarded. |
| 830 net::FakeURLFetcherFactory factory(NULL); | 830 net::FakeURLFetcherFactory factory(NULL); |
| 831 PrepareResponse( | 831 PrepareResponse( |
| 832 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 832 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| 833 net::URLRequestStatus::SUCCESS); | 833 net::URLRequestStatus::SUCCESS); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 937 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); | 937 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); |
| 938 EXPECT_CALL( | 938 EXPECT_CALL( |
| 939 *binary_feature_extractor_.get(), | 939 *binary_feature_extractor_.get(), |
| 940 ExtractImageFeatures(tmp_path_, BinaryFeatureExtractor::kDefaultOptions, | 940 ExtractImageFeatures(tmp_path_, BinaryFeatureExtractor::kDefaultOptions, |
| 941 _, _)); | 941 _, _)); |
| 942 | 942 |
| 943 download_service_->CheckClientDownload( | 943 download_service_->CheckClientDownload( |
| 944 &item, | 944 &item, |
| 945 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 945 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 946 base::Unretained(this))); | 946 base::Unretained(this))); |
| 947 MessageLoop::current()->Run(); | 947 base::RunLoop().Run(); |
| 948 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 948 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 949 } | 949 } |
| 950 | 950 |
| 951 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { | 951 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { |
| 952 net::FakeURLFetcherFactory factory(NULL); | 952 net::FakeURLFetcherFactory factory(NULL); |
| 953 PrepareResponse( | 953 PrepareResponse( |
| 954 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 954 &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 955 net::URLRequestStatus::SUCCESS); | 955 net::URLRequestStatus::SUCCESS); |
| 956 | 956 |
| 957 content::MockDownloadItem item; | 957 content::MockDownloadItem item; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 969 .Times(6); | 969 .Times(6); |
| 970 EXPECT_CALL(*binary_feature_extractor_.get(), | 970 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 971 ExtractImageFeatures( | 971 ExtractImageFeatures( |
| 972 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 972 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
| 973 .Times(6); | 973 .Times(6); |
| 974 | 974 |
| 975 download_service_->CheckClientDownload( | 975 download_service_->CheckClientDownload( |
| 976 &item, | 976 &item, |
| 977 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 977 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 978 base::Unretained(this))); | 978 base::Unretained(this))); |
| 979 MessageLoop::current()->Run(); | 979 base::RunLoop().Run(); |
| 980 | 980 |
| 981 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 981 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 982 EXPECT_TRUE(HasClientDownloadRequest()); | 982 EXPECT_TRUE(HasClientDownloadRequest()); |
| 983 ClearClientDownloadRequest(); | 983 ClearClientDownloadRequest(); |
| 984 | 984 |
| 985 // Invalid response should result in UNKNOWN. | 985 // Invalid response should result in UNKNOWN. |
| 986 ClientDownloadResponse invalid_response; | 986 ClientDownloadResponse invalid_response; |
| 987 factory.SetFakeResponse( | 987 factory.SetFakeResponse( |
| 988 DownloadProtectionService::GetDownloadRequestUrl(), | 988 DownloadProtectionService::GetDownloadRequestUrl(), |
| 989 invalid_response.SerializePartialAsString(), | 989 invalid_response.SerializePartialAsString(), |
| 990 net::HTTP_OK, net::URLRequestStatus::SUCCESS); | 990 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
| 991 | 991 |
| 992 download_service_->CheckClientDownload( | 992 download_service_->CheckClientDownload( |
| 993 &item, | 993 &item, |
| 994 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 994 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 995 base::Unretained(this))); | 995 base::Unretained(this))); |
| 996 MessageLoop::current()->Run(); | 996 base::RunLoop().Run(); |
| 997 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 997 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 998 EXPECT_TRUE(HasClientDownloadRequest()); | 998 EXPECT_TRUE(HasClientDownloadRequest()); |
| 999 ClearClientDownloadRequest(); | 999 ClearClientDownloadRequest(); |
| 1000 std::string feedback_ping; | 1000 std::string feedback_ping; |
| 1001 std::string feedback_response; | 1001 std::string feedback_response; |
| 1002 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 1002 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 1003 item, &feedback_ping, &feedback_response)); | 1003 item, &feedback_ping, &feedback_response)); |
| 1004 | 1004 |
| 1005 // If the response is dangerous the result should also be marked as dangerous. | 1005 // If the response is dangerous the result should also be marked as dangerous. |
| 1006 PrepareResponse( | 1006 PrepareResponse( |
| 1007 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1007 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| 1008 net::URLRequestStatus::SUCCESS); | 1008 net::URLRequestStatus::SUCCESS); |
| 1009 | 1009 |
| 1010 download_service_->CheckClientDownload( | 1010 download_service_->CheckClientDownload( |
| 1011 &item, | 1011 &item, |
| 1012 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1012 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1013 base::Unretained(this))); | 1013 base::Unretained(this))); |
| 1014 MessageLoop::current()->Run(); | 1014 base::RunLoop().Run(); |
| 1015 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 1015 EXPECT_FALSE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 1016 item, &feedback_ping, &feedback_response)); | 1016 item, &feedback_ping, &feedback_response)); |
| 1017 | 1017 |
| 1018 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1018 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1019 EXPECT_TRUE(HasClientDownloadRequest()); | 1019 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1020 ClearClientDownloadRequest(); | 1020 ClearClientDownloadRequest(); |
| 1021 | 1021 |
| 1022 // If the response is uncommon the result should also be marked as uncommon. | 1022 // If the response is uncommon the result should also be marked as uncommon. |
| 1023 PrepareResponse( | 1023 PrepareResponse( |
| 1024 &factory, ClientDownloadResponse::UNCOMMON, net::HTTP_OK, | 1024 &factory, ClientDownloadResponse::UNCOMMON, net::HTTP_OK, |
| 1025 net::URLRequestStatus::SUCCESS); | 1025 net::URLRequestStatus::SUCCESS); |
| 1026 | 1026 |
| 1027 download_service_->CheckClientDownload( | 1027 download_service_->CheckClientDownload( |
| 1028 &item, | 1028 &item, |
| 1029 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1029 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1030 base::Unretained(this))); | 1030 base::Unretained(this))); |
| 1031 MessageLoop::current()->Run(); | 1031 base::RunLoop().Run(); |
| 1032 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); | 1032 EXPECT_TRUE(IsResult(DownloadProtectionService::UNCOMMON)); |
| 1033 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 1033 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 1034 item, &feedback_ping, &feedback_response)); | 1034 item, &feedback_ping, &feedback_response)); |
| 1035 ClientDownloadRequest decoded_request; | 1035 ClientDownloadRequest decoded_request; |
| 1036 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); | 1036 EXPECT_TRUE(decoded_request.ParseFromString(feedback_ping)); |
| 1037 EXPECT_EQ(url_chain_.back().spec(), decoded_request.url()); | 1037 EXPECT_EQ(url_chain_.back().spec(), decoded_request.url()); |
| 1038 ClientDownloadResponse expected_response; | 1038 ClientDownloadResponse expected_response; |
| 1039 expected_response.set_verdict(ClientDownloadResponse::UNCOMMON); | 1039 expected_response.set_verdict(ClientDownloadResponse::UNCOMMON); |
| 1040 EXPECT_EQ(expected_response.SerializeAsString(), feedback_response); | 1040 EXPECT_EQ(expected_response.SerializeAsString(), feedback_response); |
| 1041 EXPECT_TRUE(HasClientDownloadRequest()); | 1041 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1042 ClearClientDownloadRequest(); | 1042 ClearClientDownloadRequest(); |
| 1043 | 1043 |
| 1044 // If the response is dangerous_host the result should also be marked as | 1044 // If the response is dangerous_host the result should also be marked as |
| 1045 // dangerous_host. | 1045 // dangerous_host. |
| 1046 PrepareResponse( | 1046 PrepareResponse( |
| 1047 &factory, ClientDownloadResponse::DANGEROUS_HOST, net::HTTP_OK, | 1047 &factory, ClientDownloadResponse::DANGEROUS_HOST, net::HTTP_OK, |
| 1048 net::URLRequestStatus::SUCCESS); | 1048 net::URLRequestStatus::SUCCESS); |
| 1049 | 1049 |
| 1050 download_service_->CheckClientDownload( | 1050 download_service_->CheckClientDownload( |
| 1051 &item, | 1051 &item, |
| 1052 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1052 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1053 base::Unretained(this))); | 1053 base::Unretained(this))); |
| 1054 MessageLoop::current()->Run(); | 1054 base::RunLoop().Run(); |
| 1055 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); | 1055 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS_HOST)); |
| 1056 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( | 1056 EXPECT_TRUE(DownloadFeedbackService::GetPingsForDownloadForTesting( |
| 1057 item, &feedback_ping, &feedback_response)); | 1057 item, &feedback_ping, &feedback_response)); |
| 1058 expected_response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); | 1058 expected_response.set_verdict(ClientDownloadResponse::DANGEROUS_HOST); |
| 1059 EXPECT_EQ(expected_response.SerializeAsString(), feedback_response); | 1059 EXPECT_EQ(expected_response.SerializeAsString(), feedback_response); |
| 1060 EXPECT_TRUE(HasClientDownloadRequest()); | 1060 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1061 ClearClientDownloadRequest(); | 1061 ClearClientDownloadRequest(); |
| 1062 | 1062 |
| 1063 // If the response is POTENTIALLY_UNWANTED the result should also be marked as | 1063 // If the response is POTENTIALLY_UNWANTED the result should also be marked as |
| 1064 // POTENTIALLY_UNWANTED. | 1064 // POTENTIALLY_UNWANTED. |
| 1065 PrepareResponse( | 1065 PrepareResponse( |
| 1066 &factory, ClientDownloadResponse::POTENTIALLY_UNWANTED, net::HTTP_OK, | 1066 &factory, ClientDownloadResponse::POTENTIALLY_UNWANTED, net::HTTP_OK, |
| 1067 net::URLRequestStatus::SUCCESS); | 1067 net::URLRequestStatus::SUCCESS); |
| 1068 | 1068 |
| 1069 download_service_->CheckClientDownload( | 1069 download_service_->CheckClientDownload( |
| 1070 &item, | 1070 &item, |
| 1071 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1071 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1072 base::Unretained(this))); | 1072 base::Unretained(this))); |
| 1073 MessageLoop::current()->Run(); | 1073 base::RunLoop().Run(); |
| 1074 | 1074 |
| 1075 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); | 1075 EXPECT_TRUE(IsResult(DownloadProtectionService::POTENTIALLY_UNWANTED)); |
| 1076 EXPECT_TRUE(HasClientDownloadRequest()); | 1076 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1077 ClearClientDownloadRequest(); | 1077 ClearClientDownloadRequest(); |
| 1078 } | 1078 } |
| 1079 | 1079 |
| 1080 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { | 1080 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) { |
| 1081 net::FakeURLFetcherFactory factory(NULL); | 1081 net::FakeURLFetcherFactory factory(NULL); |
| 1082 PrepareResponse( | 1082 PrepareResponse( |
| 1083 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1083 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1097 .Times(1); | 1097 .Times(1); |
| 1098 EXPECT_CALL(*binary_feature_extractor_.get(), | 1098 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1099 ExtractImageFeatures( | 1099 ExtractImageFeatures( |
| 1100 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 1100 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
| 1101 .Times(1); | 1101 .Times(1); |
| 1102 | 1102 |
| 1103 download_service_->CheckClientDownload( | 1103 download_service_->CheckClientDownload( |
| 1104 &item, | 1104 &item, |
| 1105 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1105 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1106 base::Unretained(this))); | 1106 base::Unretained(this))); |
| 1107 MessageLoop::current()->Run(); | 1107 base::RunLoop().Run(); |
| 1108 | 1108 |
| 1109 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1109 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1110 EXPECT_TRUE(HasClientDownloadRequest()); | 1110 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1111 ClearClientDownloadRequest(); | 1111 ClearClientDownloadRequest(); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) { | 1114 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadBlob) { |
| 1115 net::FakeURLFetcherFactory factory(NULL); | 1115 net::FakeURLFetcherFactory factory(NULL); |
| 1116 PrepareResponse( | 1116 PrepareResponse( |
| 1117 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1117 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1131 .Times(1); | 1131 .Times(1); |
| 1132 EXPECT_CALL(*binary_feature_extractor_.get(), | 1132 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1133 ExtractImageFeatures( | 1133 ExtractImageFeatures( |
| 1134 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 1134 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
| 1135 .Times(1); | 1135 .Times(1); |
| 1136 | 1136 |
| 1137 download_service_->CheckClientDownload( | 1137 download_service_->CheckClientDownload( |
| 1138 &item, | 1138 &item, |
| 1139 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1139 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1140 base::Unretained(this))); | 1140 base::Unretained(this))); |
| 1141 MessageLoop::current()->Run(); | 1141 base::RunLoop().Run(); |
| 1142 | 1142 |
| 1143 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1143 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1144 EXPECT_TRUE(HasClientDownloadRequest()); | 1144 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1145 ClearClientDownloadRequest(); | 1145 ClearClientDownloadRequest(); |
| 1146 } | 1146 } |
| 1147 | 1147 |
| 1148 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadData) { | 1148 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadData) { |
| 1149 net::FakeURLFetcherFactory factory(NULL); | 1149 net::FakeURLFetcherFactory factory(NULL); |
| 1150 PrepareResponse( | 1150 PrepareResponse( |
| 1151 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1151 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1166 .Times(1); | 1166 .Times(1); |
| 1167 EXPECT_CALL(*binary_feature_extractor_.get(), | 1167 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1168 ExtractImageFeatures( | 1168 ExtractImageFeatures( |
| 1169 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 1169 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
| 1170 .Times(1); | 1170 .Times(1); |
| 1171 | 1171 |
| 1172 download_service_->CheckClientDownload( | 1172 download_service_->CheckClientDownload( |
| 1173 &item, | 1173 &item, |
| 1174 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1174 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1175 base::Unretained(this))); | 1175 base::Unretained(this))); |
| 1176 MessageLoop::current()->Run(); | 1176 base::RunLoop().Run(); |
| 1177 | 1177 |
| 1178 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1178 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1179 ASSERT_TRUE(HasClientDownloadRequest()); | 1179 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1180 const ClientDownloadRequest& request = *GetClientDownloadRequest(); | 1180 const ClientDownloadRequest& request = *GetClientDownloadRequest(); |
| 1181 const char kExpectedUrl[] = | 1181 const char kExpectedUrl[] = |
| 1182 "data:application/octet-stream:base64," | 1182 "data:application/octet-stream:base64," |
| 1183 "ACBF6DFC6F907662F566CA0241DFE8690C48661F440BA1BBD0B86C582845CCC8"; | 1183 "ACBF6DFC6F907662F566CA0241DFE8690C48661F440BA1BBD0B86C582845CCC8"; |
| 1184 const char kExpectedRedirect1[] = "data:text/html:base64,"; | 1184 const char kExpectedRedirect1[] = "data:text/html:base64,"; |
| 1185 const char kExpectedRedirect2[] = | 1185 const char kExpectedRedirect2[] = |
| 1186 "data:text/html:base64," | 1186 "data:text/html:base64," |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 std::string file_contents = "dummy file"; | 1224 std::string file_contents = "dummy file"; |
| 1225 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | 1225 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( |
| 1226 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), | 1226 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), |
| 1227 file_contents.data(), file_contents.size())); | 1227 file_contents.data(), file_contents.size())); |
| 1228 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); | 1228 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); |
| 1229 | 1229 |
| 1230 download_service_->CheckClientDownload( | 1230 download_service_->CheckClientDownload( |
| 1231 &item, | 1231 &item, |
| 1232 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1232 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1233 base::Unretained(this))); | 1233 base::Unretained(this))); |
| 1234 MessageLoop::current()->Run(); | 1234 base::RunLoop().Run(); |
| 1235 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1235 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1236 EXPECT_FALSE(HasClientDownloadRequest()); | 1236 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1237 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1237 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1238 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1238 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1239 | 1239 |
| 1240 // Now check with an executable in the zip file as well. | 1240 // Now check with an executable in the zip file as well. |
| 1241 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( | 1241 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile( |
| 1242 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), | 1242 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), |
| 1243 file_contents.data(), file_contents.size())); | 1243 file_contents.data(), file_contents.size())); |
| 1244 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); | 1244 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); |
| 1245 | 1245 |
| 1246 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1246 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1247 MatchDownloadWhitelistUrl(_)) | 1247 MatchDownloadWhitelistUrl(_)) |
| 1248 .WillRepeatedly(Return(false)); | 1248 .WillRepeatedly(Return(false)); |
| 1249 | 1249 |
| 1250 download_service_->CheckClientDownload( | 1250 download_service_->CheckClientDownload( |
| 1251 &item, | 1251 &item, |
| 1252 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1252 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1253 base::Unretained(this))); | 1253 base::Unretained(this))); |
| 1254 MessageLoop::current()->Run(); | 1254 base::RunLoop().Run(); |
| 1255 | 1255 |
| 1256 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1256 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1257 EXPECT_TRUE(HasClientDownloadRequest()); | 1257 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1258 const ClientDownloadRequest& request = *GetClientDownloadRequest(); | 1258 const ClientDownloadRequest& request = *GetClientDownloadRequest(); |
| 1259 EXPECT_TRUE(request.has_download_type()); | 1259 EXPECT_TRUE(request.has_download_type()); |
| 1260 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, | 1260 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, |
| 1261 request.download_type()); | 1261 request.download_type()); |
| 1262 EXPECT_EQ(1, request.archived_binary_size()); | 1262 EXPECT_EQ(1, request.archived_binary_size()); |
| 1263 const ClientDownloadRequest_ArchivedBinary* archived_binary = | 1263 const ClientDownloadRequest_ArchivedBinary* archived_binary = |
| 1264 GetRequestArchivedBinary(request, "file.exe"); | 1264 GetRequestArchivedBinary(request, "file.exe"); |
| 1265 ASSERT_NE(nullptr, archived_binary); | 1265 ASSERT_NE(nullptr, archived_binary); |
| 1266 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, | 1266 EXPECT_EQ(ClientDownloadRequest_DownloadType_WIN_EXECUTABLE, |
| 1267 archived_binary->download_type()); | 1267 archived_binary->download_type()); |
| 1268 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), | 1268 EXPECT_EQ(static_cast<int64_t>(file_contents.size()), |
| 1269 archived_binary->length()); | 1269 archived_binary->length()); |
| 1270 ClearClientDownloadRequest(); | 1270 ClearClientDownloadRequest(); |
| 1271 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1271 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1272 | 1272 |
| 1273 // If the response is dangerous the result should also be marked as | 1273 // If the response is dangerous the result should also be marked as |
| 1274 // dangerous. | 1274 // dangerous. |
| 1275 PrepareResponse( | 1275 PrepareResponse( |
| 1276 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 1276 &factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| 1277 net::URLRequestStatus::SUCCESS); | 1277 net::URLRequestStatus::SUCCESS); |
| 1278 | 1278 |
| 1279 download_service_->CheckClientDownload( | 1279 download_service_->CheckClientDownload( |
| 1280 &item, | 1280 &item, |
| 1281 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1281 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1282 base::Unretained(this))); | 1282 base::Unretained(this))); |
| 1283 MessageLoop::current()->Run(); | 1283 base::RunLoop().Run(); |
| 1284 | 1284 |
| 1285 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1285 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1286 EXPECT_TRUE(HasClientDownloadRequest()); | 1286 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1287 ClearClientDownloadRequest(); | 1287 ClearClientDownloadRequest(); |
| 1288 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1288 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1289 | 1289 |
| 1290 // Repeat the test with an archive inside the zip file in addition to the | 1290 // Repeat the test with an archive inside the zip file in addition to the |
| 1291 // executable. | 1291 // executable. |
| 1292 ASSERT_EQ(static_cast<int>(file_contents.size()), | 1292 ASSERT_EQ(static_cast<int>(file_contents.size()), |
| 1293 base::WriteFile( | 1293 base::WriteFile( |
| 1294 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")), | 1294 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")), |
| 1295 file_contents.data(), file_contents.size())); | 1295 file_contents.data(), file_contents.size())); |
| 1296 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); | 1296 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); |
| 1297 | 1297 |
| 1298 download_service_->CheckClientDownload( | 1298 download_service_->CheckClientDownload( |
| 1299 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1299 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1300 base::Unretained(this))); | 1300 base::Unretained(this))); |
| 1301 MessageLoop::current()->Run(); | 1301 base::RunLoop().Run(); |
| 1302 | 1302 |
| 1303 ASSERT_TRUE(HasClientDownloadRequest()); | 1303 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1304 EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size()); | 1304 EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size()); |
| 1305 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); | 1305 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); |
| 1306 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, | 1306 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE, |
| 1307 GetClientDownloadRequest()->download_type()); | 1307 GetClientDownloadRequest()->download_type()); |
| 1308 ClearClientDownloadRequest(); | 1308 ClearClientDownloadRequest(); |
| 1309 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1309 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1310 | 1310 |
| 1311 // Repeat the test with just the archive inside the zip file. | 1311 // Repeat the test with just the archive inside the zip file. |
| 1312 ASSERT_TRUE( | 1312 ASSERT_TRUE( |
| 1313 base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false)); | 1313 base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false)); |
| 1314 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); | 1314 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), tmp_path_, false)); |
| 1315 | 1315 |
| 1316 download_service_->CheckClientDownload( | 1316 download_service_->CheckClientDownload( |
| 1317 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1317 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1318 base::Unretained(this))); | 1318 base::Unretained(this))); |
| 1319 MessageLoop::current()->Run(); | 1319 base::RunLoop().Run(); |
| 1320 | 1320 |
| 1321 ASSERT_TRUE(HasClientDownloadRequest()); | 1321 ASSERT_TRUE(HasClientDownloadRequest()); |
| 1322 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); | 1322 EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size()); |
| 1323 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); | 1323 EXPECT_TRUE(GetClientDownloadRequest()->has_download_type()); |
| 1324 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE, | 1324 EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE, |
| 1325 GetClientDownloadRequest()->download_type()); | 1325 GetClientDownloadRequest()->download_type()); |
| 1326 ClearClientDownloadRequest(); | 1326 ClearClientDownloadRequest(); |
| 1327 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); | 1327 Mock::VerifyAndClearExpectations(binary_feature_extractor_.get()); |
| 1328 } | 1328 } |
| 1329 | 1329 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 EXPECT_CALL(*binary_feature_extractor_.get(), | 1370 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1371 ExtractImageFeatures( | 1371 ExtractImageFeatures( |
| 1372 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) | 1372 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) |
| 1373 .Times(1); | 1373 .Times(1); |
| 1374 | 1374 |
| 1375 EXPECT_FALSE(download_service_->IsSupportedDownload(item, final_path_)); | 1375 EXPECT_FALSE(download_service_->IsSupportedDownload(item, final_path_)); |
| 1376 download_service_->CheckClientDownload( | 1376 download_service_->CheckClientDownload( |
| 1377 &item, | 1377 &item, |
| 1378 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1378 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1379 base::Unretained(this))); | 1379 base::Unretained(this))); |
| 1380 MessageLoop::current()->Run(); | 1380 base::RunLoop().Run(); |
| 1381 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1381 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1382 } | 1382 } |
| 1383 | 1383 |
| 1384 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { | 1384 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { |
| 1385 net::TestURLFetcherFactory factory; | 1385 net::TestURLFetcherFactory factory; |
| 1386 | 1386 |
| 1387 content::MockDownloadItem item; | 1387 content::MockDownloadItem item; |
| 1388 PrepareBasicDownloadItem( | 1388 PrepareBasicDownloadItem( |
| 1389 &item, | 1389 &item, |
| 1390 {"http://www.google.com/", | 1390 {"http://www.google.com/", |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1443 request.image_headers(); | 1443 request.image_headers(); |
| 1444 EXPECT_TRUE(headers.has_pe_headers()); | 1444 EXPECT_TRUE(headers.has_pe_headers()); |
| 1445 EXPECT_TRUE(headers.pe_headers().has_dos_header()); | 1445 EXPECT_TRUE(headers.pe_headers().has_dos_header()); |
| 1446 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); | 1446 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); |
| 1447 | 1447 |
| 1448 // Simulate the request finishing. | 1448 // Simulate the request finishing. |
| 1449 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1449 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1450 FROM_HERE, | 1450 FROM_HERE, |
| 1451 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1451 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 1452 base::Unretained(this), fetcher)); | 1452 base::Unretained(this), fetcher)); |
| 1453 MessageLoop::current()->Run(); | 1453 base::RunLoop().Run(); |
| 1454 } | 1454 } |
| 1455 | 1455 |
| 1456 // Similar to above, but with an unsigned binary. | 1456 // Similar to above, but with an unsigned binary. |
| 1457 TEST_F(DownloadProtectionServiceTest, | 1457 TEST_F(DownloadProtectionServiceTest, |
| 1458 CheckClientDownloadValidateRequestNoSignature) { | 1458 CheckClientDownloadValidateRequestNoSignature) { |
| 1459 net::TestURLFetcherFactory factory; | 1459 net::TestURLFetcherFactory factory; |
| 1460 | 1460 |
| 1461 content::MockDownloadItem item; | 1461 content::MockDownloadItem item; |
| 1462 PrepareBasicDownloadItem( | 1462 PrepareBasicDownloadItem( |
| 1463 &item, | 1463 &item, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1503 "ftp://www.google.com/bla.exe", | 1503 "ftp://www.google.com/bla.exe", |
| 1504 referrer_.spec())); | 1504 referrer_.spec())); |
| 1505 EXPECT_TRUE(request.has_signature()); | 1505 EXPECT_TRUE(request.has_signature()); |
| 1506 EXPECT_EQ(0, request.signature().certificate_chain_size()); | 1506 EXPECT_EQ(0, request.signature().certificate_chain_size()); |
| 1507 | 1507 |
| 1508 // Simulate the request finishing. | 1508 // Simulate the request finishing. |
| 1509 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1509 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1510 FROM_HERE, | 1510 FROM_HERE, |
| 1511 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1511 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 1512 base::Unretained(this), fetcher)); | 1512 base::Unretained(this), fetcher)); |
| 1513 MessageLoop::current()->Run(); | 1513 base::RunLoop().Run(); |
| 1514 } | 1514 } |
| 1515 | 1515 |
| 1516 // Similar to above, but with tab history. | 1516 // Similar to above, but with tab history. |
| 1517 TEST_F(DownloadProtectionServiceTest, | 1517 TEST_F(DownloadProtectionServiceTest, |
| 1518 CheckClientDownloadValidateRequestTabHistory) { | 1518 CheckClientDownloadValidateRequestTabHistory) { |
| 1519 net::TestURLFetcherFactory factory; | 1519 net::TestURLFetcherFactory factory; |
| 1520 | 1520 |
| 1521 content::MockDownloadItem item; | 1521 content::MockDownloadItem item; |
| 1522 PrepareBasicDownloadItem( | 1522 PrepareBasicDownloadItem( |
| 1523 &item, | 1523 &item, |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1591 request.image_headers(); | 1591 request.image_headers(); |
| 1592 EXPECT_TRUE(headers.has_pe_headers()); | 1592 EXPECT_TRUE(headers.has_pe_headers()); |
| 1593 EXPECT_TRUE(headers.pe_headers().has_dos_header()); | 1593 EXPECT_TRUE(headers.pe_headers().has_dos_header()); |
| 1594 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); | 1594 EXPECT_EQ("dummy dos header", headers.pe_headers().dos_header()); |
| 1595 | 1595 |
| 1596 // Simulate the request finishing. | 1596 // Simulate the request finishing. |
| 1597 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1597 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1598 FROM_HERE, | 1598 FROM_HERE, |
| 1599 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1599 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 1600 base::Unretained(this), fetcher)); | 1600 base::Unretained(this), fetcher)); |
| 1601 MessageLoop::current()->Run(); | 1601 base::RunLoop().Run(); |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 // Now try with a history match. | 1604 // Now try with a history match. |
| 1605 { | 1605 { |
| 1606 history::RedirectList redirects; | 1606 history::RedirectList redirects; |
| 1607 redirects.push_back(GURL("http://tab.com/ref1")); | 1607 redirects.push_back(GURL("http://tab.com/ref1")); |
| 1608 redirects.push_back(GURL("http://tab.com/ref2")); | 1608 redirects.push_back(GURL("http://tab.com/ref2")); |
| 1609 redirects.push_back(tab_url); | 1609 redirects.push_back(tab_url); |
| 1610 HistoryServiceFactory::GetForProfile(profile_.get(), | 1610 HistoryServiceFactory::GetForProfile(profile_.get(), |
| 1611 ServiceAccessType::EXPLICIT_ACCESS) | 1611 ServiceAccessType::EXPLICIT_ACCESS) |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1663 const ClientDownloadRequest_CertificateChain& chain = | 1663 const ClientDownloadRequest_CertificateChain& chain = |
| 1664 request.signature().certificate_chain(0); | 1664 request.signature().certificate_chain(0); |
| 1665 ASSERT_EQ(1, chain.element_size()); | 1665 ASSERT_EQ(1, chain.element_size()); |
| 1666 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); | 1666 EXPECT_EQ("dummy cert data", chain.element(0).certificate()); |
| 1667 | 1667 |
| 1668 // Simulate the request finishing. | 1668 // Simulate the request finishing. |
| 1669 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1669 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1670 FROM_HERE, | 1670 FROM_HERE, |
| 1671 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, | 1671 base::Bind(&DownloadProtectionServiceTest::SendURLFetchComplete, |
| 1672 base::Unretained(this), fetcher)); | 1672 base::Unretained(this), fetcher)); |
| 1673 MessageLoop::current()->Run(); | 1673 base::RunLoop().Run(); |
| 1674 } | 1674 } |
| 1675 } | 1675 } |
| 1676 | 1676 |
| 1677 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { | 1677 TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) { |
| 1678 net::TestURLFetcherFactory factory; | 1678 net::TestURLFetcherFactory factory; |
| 1679 | 1679 |
| 1680 std::vector<GURL> url_chain; | 1680 std::vector<GURL> url_chain; |
| 1681 url_chain.push_back(GURL("http://www.google.com/")); | 1681 url_chain.push_back(GURL("http://www.google.com/")); |
| 1682 url_chain.push_back(GURL("http://www.google.com/bla.exe")); | 1682 url_chain.push_back(GURL("http://www.google.com/bla.exe")); |
| 1683 GURL referrer("http://www.google.com/"); | 1683 GURL referrer("http://www.google.com/"); |
| 1684 std::string hash = "hash"; | 1684 std::string hash = "hash"; |
| 1685 | 1685 |
| 1686 content::MockDownloadItem item; | 1686 content::MockDownloadItem item; |
| 1687 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); | 1687 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); |
| 1688 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); | 1688 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); |
| 1689 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); | 1689 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); |
| 1690 | 1690 |
| 1691 // CheckDownloadURL returns immediately which means the client object callback | 1691 // CheckDownloadURL returns immediately which means the client object callback |
| 1692 // will never be called. Nevertheless the callback provided to | 1692 // will never be called. Nevertheless the callback provided to |
| 1693 // CheckClientDownload must still be called. | 1693 // CheckClientDownload must still be called. |
| 1694 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1694 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1695 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) | 1695 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) |
| 1696 .WillOnce(Return(true)); | 1696 .WillOnce(Return(true)); |
| 1697 download_service_->CheckDownloadUrl( | 1697 download_service_->CheckDownloadUrl( |
| 1698 item, | 1698 item, |
| 1699 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1699 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1700 base::Unretained(this))); | 1700 base::Unretained(this))); |
| 1701 MessageLoop::current()->Run(); | 1701 base::RunLoop().Run(); |
| 1702 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1702 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1703 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1703 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1704 | 1704 |
| 1705 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1705 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1706 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) | 1706 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) |
| 1707 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), | 1707 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), |
| 1708 Return(false))); | 1708 Return(false))); |
| 1709 download_service_->CheckDownloadUrl( | 1709 download_service_->CheckDownloadUrl( |
| 1710 item, | 1710 item, |
| 1711 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1711 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1712 base::Unretained(this))); | 1712 base::Unretained(this))); |
| 1713 MessageLoop::current()->Run(); | 1713 base::RunLoop().Run(); |
| 1714 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1714 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1715 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1715 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1716 | 1716 |
| 1717 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1717 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1718 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) | 1718 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) |
| 1719 .WillOnce(DoAll( | 1719 .WillOnce(DoAll( |
| 1720 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), | 1720 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), |
| 1721 Return(false))); | 1721 Return(false))); |
| 1722 download_service_->CheckDownloadUrl( | 1722 download_service_->CheckDownloadUrl( |
| 1723 item, | 1723 item, |
| 1724 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1724 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1725 base::Unretained(this))); | 1725 base::Unretained(this))); |
| 1726 MessageLoop::current()->Run(); | 1726 base::RunLoop().Run(); |
| 1727 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 1727 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 1728 Mock::VerifyAndClearExpectations(sb_service_.get()); | 1728 Mock::VerifyAndClearExpectations(sb_service_.get()); |
| 1729 | 1729 |
| 1730 EXPECT_CALL(*sb_service_->mock_database_manager(), | 1730 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 1731 CheckDownloadUrl(ContainerEq(url_chain), | 1731 CheckDownloadUrl(ContainerEq(url_chain), |
| 1732 NotNull())) | 1732 NotNull())) |
| 1733 .WillOnce(DoAll( | 1733 .WillOnce(DoAll( |
| 1734 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), | 1734 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), |
| 1735 Return(false))); | 1735 Return(false))); |
| 1736 download_service_->CheckDownloadUrl( | 1736 download_service_->CheckDownloadUrl( |
| 1737 item, | 1737 item, |
| 1738 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1738 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1739 base::Unretained(this))); | 1739 base::Unretained(this))); |
| 1740 MessageLoop::current()->Run(); | 1740 base::RunLoop().Run(); |
| 1741 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 1741 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 1742 } | 1742 } |
| 1743 | 1743 |
| 1744 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { | 1744 TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) { |
| 1745 net::TestURLFetcherFactory factory; | 1745 net::TestURLFetcherFactory factory; |
| 1746 | 1746 |
| 1747 content::MockDownloadItem item; | 1747 content::MockDownloadItem item; |
| 1748 PrepareBasicDownloadItem( | 1748 PrepareBasicDownloadItem( |
| 1749 &item, | 1749 &item, |
| 1750 {"http://www.evil.com/bla.exe"}, // url_chain | 1750 {"http://www.evil.com/bla.exe"}, // url_chain |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1762 _, _)); | 1762 _, _)); |
| 1763 | 1763 |
| 1764 download_service_->download_request_timeout_ms_ = 10; | 1764 download_service_->download_request_timeout_ms_ = 10; |
| 1765 download_service_->CheckClientDownload( | 1765 download_service_->CheckClientDownload( |
| 1766 &item, | 1766 &item, |
| 1767 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1767 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1768 base::Unretained(this))); | 1768 base::Unretained(this))); |
| 1769 | 1769 |
| 1770 // The request should time out because the HTTP request hasn't returned | 1770 // The request should time out because the HTTP request hasn't returned |
| 1771 // anything yet. | 1771 // anything yet. |
| 1772 MessageLoop::current()->Run(); | 1772 base::RunLoop().Run(); |
| 1773 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1773 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1774 EXPECT_TRUE(HasClientDownloadRequest()); | 1774 EXPECT_TRUE(HasClientDownloadRequest()); |
| 1775 ClearClientDownloadRequest(); | 1775 ClearClientDownloadRequest(); |
| 1776 } | 1776 } |
| 1777 | 1777 |
| 1778 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { | 1778 TEST_F(DownloadProtectionServiceTest, TestDownloadItemDestroyed) { |
| 1779 { | 1779 { |
| 1780 content::MockDownloadItem item; | 1780 content::MockDownloadItem item; |
| 1781 PrepareBasicDownloadItem( | 1781 PrepareBasicDownloadItem( |
| 1782 &item, | 1782 &item, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 EXPECT_CALL(*binary_feature_extractor_.get(), | 1830 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 1831 ExtractImageFeatures(tmp_path_, | 1831 ExtractImageFeatures(tmp_path_, |
| 1832 BinaryFeatureExtractor::kDefaultOptions, | 1832 BinaryFeatureExtractor::kDefaultOptions, |
| 1833 _, _)); | 1833 _, _)); |
| 1834 | 1834 |
| 1835 download_service_->CheckClientDownload( | 1835 download_service_->CheckClientDownload( |
| 1836 item.get(), | 1836 item.get(), |
| 1837 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 1837 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 1838 base::Unretained(this))); | 1838 base::Unretained(this))); |
| 1839 | 1839 |
| 1840 MessageLoop::current()->Run(); | 1840 base::RunLoop().Run(); |
| 1841 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 1841 EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 1842 EXPECT_FALSE(HasClientDownloadRequest()); | 1842 EXPECT_FALSE(HasClientDownloadRequest()); |
| 1843 } | 1843 } |
| 1844 | 1844 |
| 1845 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { | 1845 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { |
| 1846 // We'll pass this cert in as the "issuer", even though it isn't really | 1846 // We'll pass this cert in as the "issuer", even though it isn't really |
| 1847 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care | 1847 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care |
| 1848 // about this. | 1848 // about this. |
| 1849 scoped_refptr<net::X509Certificate> issuer_cert( | 1849 scoped_refptr<net::X509Certificate> issuer_cert( |
| 1850 ReadTestCertificate("issuer.pem")); | 1850 ReadTestCertificate("issuer.pem")); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 }; | 2006 }; |
| 2007 | 2007 |
| 2008 for (const auto& test_case : kExpectedResults) { | 2008 for (const auto& test_case : kExpectedResults) { |
| 2009 factory.ClearFakeResponses(); | 2009 factory.ClearFakeResponses(); |
| 2010 PrepareResponse(&factory, test_case.verdict, net::HTTP_OK, | 2010 PrepareResponse(&factory, test_case.verdict, net::HTTP_OK, |
| 2011 net::URLRequestStatus::SUCCESS); | 2011 net::URLRequestStatus::SUCCESS); |
| 2012 download_service_->CheckPPAPIDownloadRequest( | 2012 download_service_->CheckPPAPIDownloadRequest( |
| 2013 GURL("http://example.com/foo"), default_file_path, alternate_extensions, | 2013 GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| 2014 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2014 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2015 base::Unretained(this))); | 2015 base::Unretained(this))); |
| 2016 MessageLoop::current()->Run(); | 2016 base::RunLoop().Run(); |
| 2017 ASSERT_TRUE(IsResult(test_case.expected_result)); | 2017 ASSERT_TRUE(IsResult(test_case.expected_result)); |
| 2018 } | 2018 } |
| 2019 } | 2019 } |
| 2020 | 2020 |
| 2021 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) { | 2021 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) { |
| 2022 net::FakeURLFetcherFactory factory(nullptr); | 2022 net::FakeURLFetcherFactory factory(nullptr); |
| 2023 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt")); | 2023 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt")); |
| 2024 std::vector<base::FilePath::StringType> alternate_extensions{ | 2024 std::vector<base::FilePath::StringType> alternate_extensions{ |
| 2025 FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".crx")}; | 2025 FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".crx")}; |
| 2026 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 2026 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| 2027 net::URLRequestStatus::SUCCESS); | 2027 net::URLRequestStatus::SUCCESS); |
| 2028 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2028 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2029 MatchDownloadWhitelistUrl(_)) | 2029 MatchDownloadWhitelistUrl(_)) |
| 2030 .WillRepeatedly(Return(false)); | 2030 .WillRepeatedly(Return(false)); |
| 2031 download_service_->CheckPPAPIDownloadRequest( | 2031 download_service_->CheckPPAPIDownloadRequest( |
| 2032 GURL("http://example.com/foo"), default_file_path, alternate_extensions, | 2032 GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| 2033 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2033 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2034 base::Unretained(this))); | 2034 base::Unretained(this))); |
| 2035 MessageLoop::current()->Run(); | 2035 base::RunLoop().Run(); |
| 2036 | 2036 |
| 2037 ASSERT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2037 ASSERT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2038 } | 2038 } |
| 2039 | 2039 |
| 2040 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) { | 2040 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) { |
| 2041 net::FakeURLFetcherFactory factory(nullptr); | 2041 net::FakeURLFetcherFactory factory(nullptr); |
| 2042 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); | 2042 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); |
| 2043 std::vector<base::FilePath::StringType> alternate_extensions; | 2043 std::vector<base::FilePath::StringType> alternate_extensions; |
| 2044 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2044 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2045 MatchDownloadWhitelistUrl(_)) | 2045 MatchDownloadWhitelistUrl(_)) |
| 2046 .WillRepeatedly(Return(true)); | 2046 .WillRepeatedly(Return(true)); |
| 2047 download_service_->CheckPPAPIDownloadRequest( | 2047 download_service_->CheckPPAPIDownloadRequest( |
| 2048 GURL("http://example.com/foo"), default_file_path, alternate_extensions, | 2048 GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| 2049 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2049 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2050 base::Unretained(this))); | 2050 base::Unretained(this))); |
| 2051 MessageLoop::current()->Run(); | 2051 base::RunLoop().Run(); |
| 2052 | 2052 |
| 2053 ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE)); | 2053 ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| 2054 } | 2054 } |
| 2055 | 2055 |
| 2056 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) { | 2056 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) { |
| 2057 net::FakeURLFetcherFactory factory(nullptr); | 2057 net::FakeURLFetcherFactory factory(nullptr); |
| 2058 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); | 2058 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); |
| 2059 std::vector<base::FilePath::StringType> alternate_extensions; | 2059 std::vector<base::FilePath::StringType> alternate_extensions; |
| 2060 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, | 2060 PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| 2061 net::URLRequestStatus::FAILED); | 2061 net::URLRequestStatus::FAILED); |
| 2062 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2062 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2063 MatchDownloadWhitelistUrl(_)) | 2063 MatchDownloadWhitelistUrl(_)) |
| 2064 .WillRepeatedly(Return(false)); | 2064 .WillRepeatedly(Return(false)); |
| 2065 download_service_->CheckPPAPIDownloadRequest( | 2065 download_service_->CheckPPAPIDownloadRequest( |
| 2066 GURL("http://example.com/foo"), default_file_path, alternate_extensions, | 2066 GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| 2067 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2067 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2068 base::Unretained(this))); | 2068 base::Unretained(this))); |
| 2069 MessageLoop::current()->Run(); | 2069 base::RunLoop().Run(); |
| 2070 | 2070 |
| 2071 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 2071 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 2072 } | 2072 } |
| 2073 | 2073 |
| 2074 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_InvalidResponse) { | 2074 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_InvalidResponse) { |
| 2075 net::FakeURLFetcherFactory factory(nullptr); | 2075 net::FakeURLFetcherFactory factory(nullptr); |
| 2076 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); | 2076 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); |
| 2077 std::vector<base::FilePath::StringType> alternate_extensions; | 2077 std::vector<base::FilePath::StringType> alternate_extensions; |
| 2078 factory.SetFakeResponse(DownloadProtectionService::GetDownloadRequestUrl(), | 2078 factory.SetFakeResponse(DownloadProtectionService::GetDownloadRequestUrl(), |
| 2079 "Hello world!", net::HTTP_OK, | 2079 "Hello world!", net::HTTP_OK, |
| 2080 net::URLRequestStatus::SUCCESS); | 2080 net::URLRequestStatus::SUCCESS); |
| 2081 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2081 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2082 MatchDownloadWhitelistUrl(_)) | 2082 MatchDownloadWhitelistUrl(_)) |
| 2083 .WillRepeatedly(Return(false)); | 2083 .WillRepeatedly(Return(false)); |
| 2084 download_service_->CheckPPAPIDownloadRequest( | 2084 download_service_->CheckPPAPIDownloadRequest( |
| 2085 GURL("http://example.com/foo"), default_file_path, alternate_extensions, | 2085 GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| 2086 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2086 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2087 base::Unretained(this))); | 2087 base::Unretained(this))); |
| 2088 MessageLoop::current()->Run(); | 2088 base::RunLoop().Run(); |
| 2089 | 2089 |
| 2090 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 2090 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 2091 } | 2091 } |
| 2092 | 2092 |
| 2093 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Timeout) { | 2093 TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Timeout) { |
| 2094 net::FakeURLFetcherFactory factory(nullptr); | 2094 net::FakeURLFetcherFactory factory(nullptr); |
| 2095 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); | 2095 base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx")); |
| 2096 std::vector<base::FilePath::StringType> alternate_extensions; | 2096 std::vector<base::FilePath::StringType> alternate_extensions; |
| 2097 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2097 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2098 MatchDownloadWhitelistUrl(_)) | 2098 MatchDownloadWhitelistUrl(_)) |
| 2099 .WillRepeatedly(Return(false)); | 2099 .WillRepeatedly(Return(false)); |
| 2100 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 2100 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 2101 net::URLRequestStatus::SUCCESS); | 2101 net::URLRequestStatus::SUCCESS); |
| 2102 download_service_->download_request_timeout_ms_ = 0; | 2102 download_service_->download_request_timeout_ms_ = 0; |
| 2103 download_service_->CheckPPAPIDownloadRequest( | 2103 download_service_->CheckPPAPIDownloadRequest( |
| 2104 GURL("http://example.com/foo"), default_file_path, alternate_extensions, | 2104 GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| 2105 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2105 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2106 base::Unretained(this))); | 2106 base::Unretained(this))); |
| 2107 MessageLoop::current()->Run(); | 2107 base::RunLoop().Run(); |
| 2108 | 2108 |
| 2109 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); | 2109 ASSERT_TRUE(IsResult(DownloadProtectionService::UNKNOWN)); |
| 2110 } | 2110 } |
| 2111 | 2111 |
| 2112 namespace { | 2112 namespace { |
| 2113 | 2113 |
| 2114 std::unique_ptr<net::FakeURLFetcher> FakeURLFetcherCreatorFunc( | 2114 std::unique_ptr<net::FakeURLFetcher> FakeURLFetcherCreatorFunc( |
| 2115 std::string* upload_data_receiver, | 2115 std::string* upload_data_receiver, |
| 2116 const GURL& url, | 2116 const GURL& url, |
| 2117 net::URLFetcherDelegate* delegate, | 2117 net::URLFetcherDelegate* delegate, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2157 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2157 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2158 MatchDownloadWhitelistUrl(_)) | 2158 MatchDownloadWhitelistUrl(_)) |
| 2159 .WillRepeatedly(Return(false)); | 2159 .WillRepeatedly(Return(false)); |
| 2160 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, | 2160 PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| 2161 net::URLRequestStatus::SUCCESS); | 2161 net::URLRequestStatus::SUCCESS); |
| 2162 const GURL kRequestorUrl("http://example.com/foo"); | 2162 const GURL kRequestorUrl("http://example.com/foo"); |
| 2163 download_service_->CheckPPAPIDownloadRequest( | 2163 download_service_->CheckPPAPIDownloadRequest( |
| 2164 kRequestorUrl, default_file_path, alternate_extensions, | 2164 kRequestorUrl, default_file_path, alternate_extensions, |
| 2165 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2165 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2166 base::Unretained(this))); | 2166 base::Unretained(this))); |
| 2167 MessageLoop::current()->Run(); | 2167 base::RunLoop().Run(); |
| 2168 | 2168 |
| 2169 ASSERT_FALSE(upload_data.empty()); | 2169 ASSERT_FALSE(upload_data.empty()); |
| 2170 | 2170 |
| 2171 ClientDownloadRequest request; | 2171 ClientDownloadRequest request; |
| 2172 ASSERT_TRUE(request.ParseFromString(upload_data)); | 2172 ASSERT_TRUE(request.ParseFromString(upload_data)); |
| 2173 | 2173 |
| 2174 EXPECT_EQ(ClientDownloadRequest::PPAPI_SAVE_REQUEST, request.download_type()); | 2174 EXPECT_EQ(ClientDownloadRequest::PPAPI_SAVE_REQUEST, request.download_type()); |
| 2175 EXPECT_EQ(kRequestorUrl.spec(), request.url()); | 2175 EXPECT_EQ(kRequestorUrl.spec(), request.url()); |
| 2176 EXPECT_EQ("test.crx", request.file_basename()); | 2176 EXPECT_EQ("test.crx", request.file_basename()); |
| 2177 ASSERT_EQ(3, request.alternate_extensions_size()); | 2177 ASSERT_EQ(3, request.alternate_extensions_size()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2220 .WillRepeatedly(Return(false)); | 2220 .WillRepeatedly(Return(false)); |
| 2221 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); | 2221 EXPECT_CALL(*binary_feature_extractor_.get(), CheckSignature(tmp_path_, _)); |
| 2222 EXPECT_CALL(*binary_feature_extractor_.get(), | 2222 EXPECT_CALL(*binary_feature_extractor_.get(), |
| 2223 ExtractImageFeatures( | 2223 ExtractImageFeatures( |
| 2224 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)); | 2224 tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)); |
| 2225 | 2225 |
| 2226 download_service_->CheckClientDownload( | 2226 download_service_->CheckClientDownload( |
| 2227 &item, | 2227 &item, |
| 2228 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2228 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2229 base::Unretained(this))); | 2229 base::Unretained(this))); |
| 2230 MessageLoop::current()->Run(); | 2230 base::RunLoop().Run(); |
| 2231 | 2231 |
| 2232 EXPECT_FALSE(HasClientDownloadRequest()); | 2232 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2233 // Overriden by flag: | 2233 // Overriden by flag: |
| 2234 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2234 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2235 } | 2235 } |
| 2236 | 2236 |
| 2237 // Test a real .zip with a real .exe in it, where the .exe is manually | 2237 // Test a real .zip with a real .exe in it, where the .exe is manually |
| 2238 // blacklisted by hash. | 2238 // blacklisted by hash. |
| 2239 TEST_F(DownloadProtectionServiceFlagTest, | 2239 TEST_F(DownloadProtectionServiceFlagTest, |
| 2240 CheckClientDownloadZipOverridenByFlag) { | 2240 CheckClientDownloadZipOverridenByFlag) { |
| 2241 content::MockDownloadItem item; | 2241 content::MockDownloadItem item; |
| 2242 | 2242 |
| 2243 PrepareBasicDownloadItemWithFullPaths( | 2243 PrepareBasicDownloadItemWithFullPaths( |
| 2244 &item, {"http://www.evil.com/a.exe"}, // url_chain | 2244 &item, {"http://www.evil.com/a.exe"}, // url_chain |
| 2245 "http://www.google.com/", // referrer | 2245 "http://www.google.com/", // referrer |
| 2246 testdata_path_.AppendASCII( | 2246 testdata_path_.AppendASCII( |
| 2247 "zipfile_one_unsigned_binary.zip"), // tmp_path | 2247 "zipfile_one_unsigned_binary.zip"), // tmp_path |
| 2248 temp_dir_.path().Append(FILE_PATH_LITERAL("a.zip"))); // final_path | 2248 temp_dir_.path().Append(FILE_PATH_LITERAL("a.zip"))); // final_path |
| 2249 | 2249 |
| 2250 EXPECT_CALL(*sb_service_->mock_database_manager(), | 2250 EXPECT_CALL(*sb_service_->mock_database_manager(), |
| 2251 MatchDownloadWhitelistUrl(_)) | 2251 MatchDownloadWhitelistUrl(_)) |
| 2252 .WillRepeatedly(Return(false)); | 2252 .WillRepeatedly(Return(false)); |
| 2253 | 2253 |
| 2254 download_service_->CheckClientDownload( | 2254 download_service_->CheckClientDownload( |
| 2255 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, | 2255 &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| 2256 base::Unretained(this))); | 2256 base::Unretained(this))); |
| 2257 MessageLoop::current()->Run(); | 2257 base::RunLoop().Run(); |
| 2258 | 2258 |
| 2259 EXPECT_FALSE(HasClientDownloadRequest()); | 2259 EXPECT_FALSE(HasClientDownloadRequest()); |
| 2260 // Overriden by flag: | 2260 // Overriden by flag: |
| 2261 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); | 2261 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); |
| 2262 } | 2262 } |
| 2263 | 2263 |
| 2264 } // namespace safe_browsing | 2264 } // namespace safe_browsing |
| OLD | NEW |