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

Side by Side Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 16290004: Update chrome/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/safe_browsing/download_protection_service.h" 5 #include "chrome/browser/safe_browsing/download_protection_service.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_paths.h" 10 #include "base/base_paths.h"
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); 366 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
367 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe)); 367 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
368 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 368 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
369 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 369 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
370 EXPECT_CALL(*sb_service_->mock_database_manager(), 370 EXPECT_CALL(*sb_service_->mock_database_manager(),
371 MatchDownloadWhitelistUrl(_)) 371 MatchDownloadWhitelistUrl(_))
372 .WillRepeatedly(Return(false)); 372 .WillRepeatedly(Return(false));
373 EXPECT_CALL(*sb_service_->mock_database_manager(), 373 EXPECT_CALL(*sb_service_->mock_database_manager(),
374 MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe"))) 374 MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe")))
375 .WillRepeatedly(Return(true)); 375 .WillRepeatedly(Return(true));
376 EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(2); 376 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(2);
377 377
378 download_service_->CheckClientDownload( 378 download_service_->CheckClientDownload(
379 &item, 379 &item,
380 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 380 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
381 base::Unretained(this))); 381 base::Unretained(this)));
382 msg_loop_.Run(); 382 msg_loop_.Run();
383 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 383 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
384 384
385 // Check that the referrer is matched against the whitelist. 385 // Check that the referrer is matched against the whitelist.
386 url_chain.pop_back(); 386 url_chain.pop_back();
(...skipping 27 matching lines...) Expand all
414 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 414 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
415 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 415 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
416 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 416 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
417 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 417 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
418 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 418 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
419 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 419 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
420 420
421 EXPECT_CALL(*sb_service_->mock_database_manager(), 421 EXPECT_CALL(*sb_service_->mock_database_manager(),
422 MatchDownloadWhitelistUrl(_)) 422 MatchDownloadWhitelistUrl(_))
423 .WillRepeatedly(Return(false)); 423 .WillRepeatedly(Return(false));
424 EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)); 424 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _));
425 425
426 download_service_->CheckClientDownload( 426 download_service_->CheckClientDownload(
427 &item, 427 &item,
428 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 428 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
429 base::Unretained(this))); 429 base::Unretained(this)));
430 msg_loop_.Run(); 430 msg_loop_.Run();
431 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 431 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
432 } 432 }
433 433
434 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) { 434 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
(...skipping 21 matching lines...) Expand all
456 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 456 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
457 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 457 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
458 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 458 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
459 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 459 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
460 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 460 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
461 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 461 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
462 462
463 EXPECT_CALL(*sb_service_->mock_database_manager(), 463 EXPECT_CALL(*sb_service_->mock_database_manager(),
464 MatchDownloadWhitelistUrl(_)) 464 MatchDownloadWhitelistUrl(_))
465 .WillRepeatedly(Return(false)); 465 .WillRepeatedly(Return(false));
466 EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(5); 466 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(5);
467 467
468 download_service_->CheckClientDownload( 468 download_service_->CheckClientDownload(
469 &item, 469 &item,
470 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 470 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
471 base::Unretained(this))); 471 base::Unretained(this)));
472 msg_loop_.Run(); 472 msg_loop_.Run();
473 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 473 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
474 474
475 // Invalid response should be safe too. 475 // Invalid response should be safe too.
476 response.Clear(); 476 response.Clear();
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 566 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
567 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 567 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
568 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 568 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
569 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 569 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
570 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 570 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
571 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 571 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
572 572
573 EXPECT_CALL(*sb_service_->mock_database_manager(), 573 EXPECT_CALL(*sb_service_->mock_database_manager(),
574 MatchDownloadWhitelistUrl(_)) 574 MatchDownloadWhitelistUrl(_))
575 .WillRepeatedly(Return(false)); 575 .WillRepeatedly(Return(false));
576 EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(1); 576 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(1);
577 577
578 download_service_->CheckClientDownload( 578 download_service_->CheckClientDownload(
579 &item, 579 &item,
580 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 580 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
581 base::Unretained(this))); 581 base::Unretained(this)));
582 msg_loop_.Run(); 582 msg_loop_.Run();
583 #if defined(OS_WIN) 583 #if defined(OS_WIN)
584 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 584 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
585 #else 585 #else
586 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 586 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
628 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), 628 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")),
629 file_contents.data(), file_contents.size())); 629 file_contents.data(), file_contents.size()));
630 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); 630 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
631 631
632 download_service_->CheckClientDownload( 632 download_service_->CheckClientDownload(
633 &item, 633 &item,
634 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 634 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
635 base::Unretained(this))); 635 base::Unretained(this)));
636 msg_loop_.Run(); 636 msg_loop_.Run();
637 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 637 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
638 Mock::VerifyAndClearExpectations(sb_service_); 638 Mock::VerifyAndClearExpectations(sb_service_.get());
639 Mock::VerifyAndClearExpectations(signature_util_); 639 Mock::VerifyAndClearExpectations(signature_util_.get());
640 640
641 // Now check with an executable in the zip file as well. 641 // Now check with an executable in the zip file as well.
642 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 642 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
643 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), 643 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")),
644 file_contents.data(), file_contents.size())); 644 file_contents.data(), file_contents.size()));
645 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); 645 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
646 646
647 EXPECT_CALL(*sb_service_->mock_database_manager(), 647 EXPECT_CALL(*sb_service_->mock_database_manager(),
648 MatchDownloadWhitelistUrl(_)) 648 MatchDownloadWhitelistUrl(_))
649 .WillRepeatedly(Return(false)); 649 .WillRepeatedly(Return(false));
650 650
651 download_service_->CheckClientDownload( 651 download_service_->CheckClientDownload(
652 &item, 652 &item,
653 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 653 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
654 base::Unretained(this))); 654 base::Unretained(this)));
655 msg_loop_.Run(); 655 msg_loop_.Run();
656 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 656 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
657 Mock::VerifyAndClearExpectations(signature_util_); 657 Mock::VerifyAndClearExpectations(signature_util_.get());
658 658
659 // If the response is dangerous the result should also be marked as 659 // If the response is dangerous the result should also be marked as
660 // dangerous. 660 // dangerous.
661 response.set_verdict(ClientDownloadResponse::DANGEROUS); 661 response.set_verdict(ClientDownloadResponse::DANGEROUS);
662 factory.SetFakeResponse( 662 factory.SetFakeResponse(
663 DownloadProtectionService::GetDownloadRequestUrl(), 663 DownloadProtectionService::GetDownloadRequestUrl(),
664 response.SerializeAsString(), 664 response.SerializeAsString(),
665 true); 665 true);
666 666
667 download_service_->CheckClientDownload( 667 download_service_->CheckClientDownload(
668 &item, 668 &item,
669 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 669 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
670 base::Unretained(this))); 670 base::Unretained(this)));
671 msg_loop_.Run(); 671 msg_loop_.Run();
672 #if defined(OS_WIN) 672 #if defined(OS_WIN)
673 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS)); 673 EXPECT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
674 #else 674 #else
675 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 675 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
676 #endif 676 #endif
677 Mock::VerifyAndClearExpectations(signature_util_); 677 Mock::VerifyAndClearExpectations(signature_util_.get());
678 } 678 }
679 679
680 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) { 680 TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) {
681 base::ScopedTempDir download_dir; 681 base::ScopedTempDir download_dir;
682 ASSERT_TRUE(download_dir.CreateUniqueTempDir()); 682 ASSERT_TRUE(download_dir.CreateUniqueTempDir());
683 683
684 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"))); 684 base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")));
685 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip")); 685 base::FilePath a_zip(FILE_PATH_LITERAL("a.zip"));
686 std::vector<GURL> url_chain; 686 std::vector<GURL> url_chain;
687 url_chain.push_back(GURL("http://www.evil.com/a.zip")); 687 url_chain.push_back(GURL("http://www.evil.com/a.zip"));
(...skipping 15 matching lines...) Expand all
703 std::string file_contents = "corrupt zip file"; 703 std::string file_contents = "corrupt zip file";
704 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 704 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
705 a_tmp, file_contents.data(), file_contents.size())); 705 a_tmp, file_contents.data(), file_contents.size()));
706 706
707 download_service_->CheckClientDownload( 707 download_service_->CheckClientDownload(
708 &item, 708 &item,
709 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 709 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
710 base::Unretained(this))); 710 base::Unretained(this)));
711 msg_loop_.Run(); 711 msg_loop_.Run();
712 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 712 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
713 Mock::VerifyAndClearExpectations(sb_service_); 713 Mock::VerifyAndClearExpectations(sb_service_.get());
714 Mock::VerifyAndClearExpectations(signature_util_); 714 Mock::VerifyAndClearExpectations(signature_util_.get());
715 } 715 }
716 716
717 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) { 717 TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) {
718 ClientDownloadResponse response; 718 ClientDownloadResponse response;
719 // Even if the server verdict is dangerous we should return SAFE because 719 // Even if the server verdict is dangerous we should return SAFE because
720 // DownloadProtectionService::IsSupportedDownload() will return false 720 // DownloadProtectionService::IsSupportedDownload() will return false
721 // for crx downloads. 721 // for crx downloads.
722 response.set_verdict(ClientDownloadResponse::DANGEROUS); 722 response.set_verdict(ClientDownloadResponse::DANGEROUS);
723 net::FakeURLFetcherFactory factory(NULL); 723 net::FakeURLFetcherFactory factory(NULL);
724 // Empty response means SAFE. 724 // Empty response means SAFE.
(...skipping 17 matching lines...) Expand all
742 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 742 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
743 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 743 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
744 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 744 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
745 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 745 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
746 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 746 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
747 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 747 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
748 748
749 EXPECT_CALL(*sb_service_->mock_database_manager(), 749 EXPECT_CALL(*sb_service_->mock_database_manager(),
750 MatchDownloadWhitelistUrl(_)) 750 MatchDownloadWhitelistUrl(_))
751 .WillRepeatedly(Return(false)); 751 .WillRepeatedly(Return(false));
752 EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(1); 752 EXPECT_CALL(*signature_util_.get(), CheckSignature(a_tmp, _)).Times(1);
753 753
754 EXPECT_FALSE(download_service_->IsSupportedDownload(item, a_crx)); 754 EXPECT_FALSE(download_service_->IsSupportedDownload(item, a_crx));
755 download_service_->CheckClientDownload( 755 download_service_->CheckClientDownload(
756 &item, 756 &item,
757 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 757 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
758 base::Unretained(this))); 758 base::Unretained(this)));
759 msg_loop_.Run(); 759 msg_loop_.Run();
760 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 760 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
761 } 761 }
762 762
(...skipping 17 matching lines...) Expand all
780 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 780 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
781 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 781 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
782 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 782 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
783 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 783 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
784 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 784 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
785 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); 785 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address));
786 786
787 EXPECT_CALL(*sb_service_->mock_database_manager(), 787 EXPECT_CALL(*sb_service_->mock_database_manager(),
788 MatchDownloadWhitelistUrl(_)) 788 MatchDownloadWhitelistUrl(_))
789 .WillRepeatedly(Return(false)); 789 .WillRepeatedly(Return(false));
790 EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _)) 790 EXPECT_CALL(*signature_util_.get(), CheckSignature(tmp_path, _))
791 .WillOnce(SetCertificateContents("dummy cert data")); 791 .WillOnce(SetCertificateContents("dummy cert data"));
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 796
797 #if !defined(OS_WIN) 797 #if !defined(OS_WIN)
798 // SendRequest is not called. Wait for FinishRequest to call our callback. 798 // SendRequest is not called. Wait for FinishRequest to call our callback.
799 msg_loop_.Run(); 799 msg_loop_.Run();
800 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 800 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
857 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 857 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
858 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 858 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
859 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 859 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
860 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 860 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
861 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 861 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
862 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address)); 862 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address));
863 863
864 EXPECT_CALL(*sb_service_->mock_database_manager(), 864 EXPECT_CALL(*sb_service_->mock_database_manager(),
865 MatchDownloadWhitelistUrl(_)) 865 MatchDownloadWhitelistUrl(_))
866 .WillRepeatedly(Return(false)); 866 .WillRepeatedly(Return(false));
867 EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _)); 867 EXPECT_CALL(*signature_util_.get(), CheckSignature(tmp_path, _));
868 download_service_->CheckClientDownload( 868 download_service_->CheckClientDownload(
869 &item, 869 &item,
870 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 870 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
871 base::Unretained(this))); 871 base::Unretained(this)));
872 872
873 #if !defined(OS_WIN) 873 #if !defined(OS_WIN)
874 // SendRequest is not called. Wait for FinishRequest to call our callback. 874 // SendRequest is not called. Wait for FinishRequest to call our callback.
875 msg_loop_.Run(); 875 msg_loop_.Run();
876 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0); 876 net::TestURLFetcher* fetcher = factory.GetFetcherByID(0);
877 EXPECT_EQ(NULL, fetcher); 877 EXPECT_EQ(NULL, fetcher);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 // CheckClientDownload must still be called. 923 // CheckClientDownload must still be called.
924 EXPECT_CALL(*sb_service_->mock_database_manager(), 924 EXPECT_CALL(*sb_service_->mock_database_manager(),
925 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 925 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
926 .WillOnce(Return(true)); 926 .WillOnce(Return(true));
927 download_service_->CheckDownloadUrl( 927 download_service_->CheckDownloadUrl(
928 item, 928 item,
929 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 929 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
930 base::Unretained(this))); 930 base::Unretained(this)));
931 msg_loop_.Run(); 931 msg_loop_.Run();
932 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 932 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
933 Mock::VerifyAndClearExpectations(sb_service_); 933 Mock::VerifyAndClearExpectations(sb_service_.get());
934 934
935 EXPECT_CALL(*sb_service_->mock_database_manager(), 935 EXPECT_CALL(*sb_service_->mock_database_manager(),
936 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 936 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
937 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE), 937 .WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE),
938 Return(false))); 938 Return(false)));
939 download_service_->CheckDownloadUrl( 939 download_service_->CheckDownloadUrl(
940 item, 940 item,
941 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 941 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
942 base::Unretained(this))); 942 base::Unretained(this)));
943 msg_loop_.Run(); 943 msg_loop_.Run();
944 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 944 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
945 Mock::VerifyAndClearExpectations(sb_service_); 945 Mock::VerifyAndClearExpectations(sb_service_.get());
946 946
947 EXPECT_CALL(*sb_service_->mock_database_manager(), 947 EXPECT_CALL(*sb_service_->mock_database_manager(),
948 CheckDownloadUrl(ContainerEq(url_chain), NotNull())) 948 CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
949 .WillOnce(DoAll( 949 .WillOnce(DoAll(
950 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE), 950 CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE),
951 Return(false))); 951 Return(false)));
952 download_service_->CheckDownloadUrl( 952 download_service_->CheckDownloadUrl(
953 item, 953 item,
954 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 954 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
955 base::Unretained(this))); 955 base::Unretained(this)));
956 msg_loop_.Run(); 956 msg_loop_.Run();
957 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 957 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
958 Mock::VerifyAndClearExpectations(sb_service_); 958 Mock::VerifyAndClearExpectations(sb_service_.get());
959 959
960 EXPECT_CALL(*sb_service_->mock_database_manager(), 960 EXPECT_CALL(*sb_service_->mock_database_manager(),
961 CheckDownloadUrl(ContainerEq(url_chain), 961 CheckDownloadUrl(ContainerEq(url_chain),
962 NotNull())) 962 NotNull()))
963 .WillOnce(DoAll( 963 .WillOnce(DoAll(
964 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL), 964 CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL),
965 Return(false))); 965 Return(false)));
966 download_service_->CheckDownloadUrl( 966 download_service_->CheckDownloadUrl(
967 item, 967 item,
968 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 968 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
(...skipping 20 matching lines...) Expand all
989 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 989 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
990 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 990 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
991 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 991 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
992 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 992 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
993 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 993 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
994 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 994 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
995 995
996 EXPECT_CALL(*sb_service_->mock_database_manager(), 996 EXPECT_CALL(*sb_service_->mock_database_manager(),
997 MatchDownloadWhitelistUrl(_)) 997 MatchDownloadWhitelistUrl(_))
998 .WillRepeatedly(Return(false)); 998 .WillRepeatedly(Return(false));
999 EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _)); 999 EXPECT_CALL(*signature_util_.get(), CheckSignature(tmp_path, _));
1000 1000
1001 download_service_->download_request_timeout_ms_ = 10; 1001 download_service_->download_request_timeout_ms_ = 10;
1002 download_service_->CheckClientDownload( 1002 download_service_->CheckClientDownload(
1003 &item, 1003 &item,
1004 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 1004 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
1005 base::Unretained(this))); 1005 base::Unretained(this)));
1006 1006
1007 // The request should time out because the HTTP request hasn't returned 1007 // The request should time out because the HTTP request hasn't returned
1008 // anything yet. 1008 // anything yet.
1009 msg_loop_.Run(); 1009 msg_loop_.Run();
(...skipping 20 matching lines...) Expand all
1030 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 1030 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
1031 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 1031 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
1032 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 1032 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
1033 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 1033 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
1034 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 1034 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
1035 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 1035 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
1036 1036
1037 EXPECT_CALL(*sb_service_->mock_database_manager(), 1037 EXPECT_CALL(*sb_service_->mock_database_manager(),
1038 MatchDownloadWhitelistUrl(_)) 1038 MatchDownloadWhitelistUrl(_))
1039 .WillRepeatedly(Return(false)); 1039 .WillRepeatedly(Return(false));
1040 EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _)); 1040 EXPECT_CALL(*signature_util_.get(), CheckSignature(tmp_path, _));
1041 1041
1042 download_service_->CheckClientDownload( 1042 download_service_->CheckClientDownload(
1043 &item, 1043 &item,
1044 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, 1044 base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback,
1045 base::Unretained(this))); 1045 base::Unretained(this)));
1046 1046
1047 ASSERT_TRUE(observer != NULL); 1047 ASSERT_TRUE(observer != NULL);
1048 observer->OnDownloadDestroyed(&item); 1048 observer->OnDownloadDestroyed(&item);
1049 1049
1050 EXPECT_TRUE(observer == NULL); 1050 EXPECT_TRUE(observer == NULL);
1051 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 1051 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
1052 } 1052 }
1053 1053
1054 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) { 1054 TEST_F(DownloadProtectionServiceTest, GetCertificateWhitelistStrings) {
1055 // We'll pass this cert in as the "issuer", even though it isn't really 1055 // We'll pass this cert in as the "issuer", even though it isn't really
1056 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care 1056 // used to sign the certs below. GetCertificateWhitelistStirngs doesn't care
1057 // about this. 1057 // about this.
1058 scoped_refptr<net::X509Certificate> issuer_cert( 1058 scoped_refptr<net::X509Certificate> issuer_cert(
1059 ReadTestCertificate("issuer.pem")); 1059 ReadTestCertificate("issuer.pem"));
1060 ASSERT_TRUE(issuer_cert.get()); 1060 ASSERT_TRUE(issuer_cert.get());
1061 std::string cert_base = "cert/" + base::HexEncode( 1061 std::string cert_base = "cert/" + base::HexEncode(
1062 issuer_cert->fingerprint().data, 1062 issuer_cert->fingerprint().data,
1063 sizeof(issuer_cert->fingerprint().data)); 1063 sizeof(issuer_cert->fingerprint().data));
1064 1064
1065 scoped_refptr<net::X509Certificate> cert(ReadTestCertificate("test_cn.pem")); 1065 scoped_refptr<net::X509Certificate> cert(ReadTestCertificate("test_cn.pem"));
1066 ASSERT_TRUE(cert.get()); 1066 ASSERT_TRUE(cert.get());
1067 std::vector<std::string> whitelist_strings; 1067 std::vector<std::string> whitelist_strings;
1068 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1068 GetCertificateWhitelistStrings(
1069 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1069 // This also tests escaping of characters in the certificate attributes. 1070 // This also tests escaping of characters in the certificate attributes.
1070 EXPECT_THAT(whitelist_strings, ElementsAre( 1071 EXPECT_THAT(whitelist_strings, ElementsAre(
1071 cert_base + "/CN=subject%2F%251")); 1072 cert_base + "/CN=subject%2F%251"));
1072 1073
1073 cert = ReadTestCertificate("test_cn_o.pem"); 1074 cert = ReadTestCertificate("test_cn_o.pem");
1074 ASSERT_TRUE(cert.get()); 1075 ASSERT_TRUE(cert.get());
1075 whitelist_strings.clear(); 1076 whitelist_strings.clear();
1076 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1077 GetCertificateWhitelistStrings(
1077 EXPECT_THAT(whitelist_strings, ElementsAre( 1078 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1078 cert_base + "/CN=subject", 1079 EXPECT_THAT(whitelist_strings,
1079 cert_base + "/CN=subject/O=org", 1080 ElementsAre(cert_base + "/CN=subject",
1080 cert_base + "/O=org")); 1081 cert_base + "/CN=subject/O=org",
1082 cert_base + "/O=org"));
1081 1083
1082 cert = ReadTestCertificate("test_cn_o_ou.pem"); 1084 cert = ReadTestCertificate("test_cn_o_ou.pem");
1083 ASSERT_TRUE(cert.get()); 1085 ASSERT_TRUE(cert.get());
1084 whitelist_strings.clear(); 1086 whitelist_strings.clear();
1085 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1087 GetCertificateWhitelistStrings(
1086 EXPECT_THAT(whitelist_strings, ElementsAre( 1088 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1087 cert_base + "/CN=subject", 1089 EXPECT_THAT(whitelist_strings,
1088 cert_base + "/CN=subject/O=org", 1090 ElementsAre(cert_base + "/CN=subject",
1089 cert_base + "/CN=subject/O=org/OU=unit", 1091 cert_base + "/CN=subject/O=org",
1090 cert_base + "/CN=subject/OU=unit", 1092 cert_base + "/CN=subject/O=org/OU=unit",
1091 cert_base + "/O=org", 1093 cert_base + "/CN=subject/OU=unit",
1092 cert_base + "/O=org/OU=unit", 1094 cert_base + "/O=org",
1093 cert_base + "/OU=unit")); 1095 cert_base + "/O=org/OU=unit",
1096 cert_base + "/OU=unit"));
1094 1097
1095 cert = ReadTestCertificate("test_cn_ou.pem"); 1098 cert = ReadTestCertificate("test_cn_ou.pem");
1096 ASSERT_TRUE(cert.get()); 1099 ASSERT_TRUE(cert.get());
1097 whitelist_strings.clear(); 1100 whitelist_strings.clear();
1098 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1101 GetCertificateWhitelistStrings(
1099 EXPECT_THAT(whitelist_strings, ElementsAre( 1102 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1100 cert_base + "/CN=subject", 1103 EXPECT_THAT(whitelist_strings,
1101 cert_base + "/CN=subject/OU=unit", 1104 ElementsAre(cert_base + "/CN=subject",
1102 cert_base + "/OU=unit")); 1105 cert_base + "/CN=subject/OU=unit",
1106 cert_base + "/OU=unit"));
1103 1107
1104 cert = ReadTestCertificate("test_o.pem"); 1108 cert = ReadTestCertificate("test_o.pem");
1105 ASSERT_TRUE(cert.get()); 1109 ASSERT_TRUE(cert.get());
1106 whitelist_strings.clear(); 1110 whitelist_strings.clear();
1107 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1111 GetCertificateWhitelistStrings(
1112 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1108 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/O=org")); 1113 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/O=org"));
1109 1114
1110 cert = ReadTestCertificate("test_o_ou.pem"); 1115 cert = ReadTestCertificate("test_o_ou.pem");
1111 ASSERT_TRUE(cert.get()); 1116 ASSERT_TRUE(cert.get());
1112 whitelist_strings.clear(); 1117 whitelist_strings.clear();
1113 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1118 GetCertificateWhitelistStrings(
1114 EXPECT_THAT(whitelist_strings, ElementsAre( 1119 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1115 cert_base + "/O=org", 1120 EXPECT_THAT(whitelist_strings,
1116 cert_base + "/O=org/OU=unit", 1121 ElementsAre(cert_base + "/O=org",
1117 cert_base + "/OU=unit")); 1122 cert_base + "/O=org/OU=unit",
1123 cert_base + "/OU=unit"));
1118 1124
1119 cert = ReadTestCertificate("test_ou.pem"); 1125 cert = ReadTestCertificate("test_ou.pem");
1120 ASSERT_TRUE(cert.get()); 1126 ASSERT_TRUE(cert.get());
1121 whitelist_strings.clear(); 1127 whitelist_strings.clear();
1122 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1128 GetCertificateWhitelistStrings(
1129 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1123 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1130 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1124 1131
1125 cert = ReadTestCertificate("test_c.pem"); 1132 cert = ReadTestCertificate("test_c.pem");
1126 ASSERT_TRUE(cert.get()); 1133 ASSERT_TRUE(cert.get());
1127 whitelist_strings.clear(); 1134 whitelist_strings.clear();
1128 GetCertificateWhitelistStrings(*cert, *issuer_cert, &whitelist_strings); 1135 GetCertificateWhitelistStrings(
1136 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1129 EXPECT_THAT(whitelist_strings, ElementsAre()); 1137 EXPECT_THAT(whitelist_strings, ElementsAre());
1130 } 1138 }
1131 } // namespace safe_browsing 1139 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | chrome/browser/safe_browsing/malware_details.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698