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

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

Issue 184563006: Move WriteFile and WriteFileDescriptor from file_util to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 692 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 703 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
704 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 704 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
705 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 705 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
706 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 706 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
707 707
708 // Write out a zip archive to the temporary file. In this case, it 708 // Write out a zip archive to the temporary file. In this case, it
709 // only contains a text file. 709 // only contains a text file.
710 base::ScopedTempDir zip_source_dir; 710 base::ScopedTempDir zip_source_dir;
711 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); 711 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir());
712 std::string file_contents = "dummy file"; 712 std::string file_contents = "dummy file";
713 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 713 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile(
714 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")), 714 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")),
715 file_contents.data(), file_contents.size())); 715 file_contents.data(), file_contents.size()));
716 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); 716 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
717 717
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 MessageLoop::current()->Run();
723 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 723 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
724 Mock::VerifyAndClearExpectations(sb_service_.get()); 724 Mock::VerifyAndClearExpectations(sb_service_.get());
725 Mock::VerifyAndClearExpectations(signature_util_.get()); 725 Mock::VerifyAndClearExpectations(signature_util_.get());
726 726
727 // Now check with an executable in the zip file as well. 727 // Now check with an executable in the zip file as well.
728 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 728 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile(
729 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), 729 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")),
730 file_contents.data(), file_contents.size())); 730 file_contents.data(), file_contents.size()));
731 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false)); 731 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
732 732
733 EXPECT_CALL(*sb_service_->mock_database_manager(), 733 EXPECT_CALL(*sb_service_->mock_database_manager(),
734 MatchDownloadWhitelistUrl(_)) 734 MatchDownloadWhitelistUrl(_))
735 .WillRepeatedly(Return(false)); 735 .WillRepeatedly(Return(false));
736 736
737 download_service_->CheckClientDownload( 737 download_service_->CheckClientDownload(
738 &item, 738 &item,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp)); 780 EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
781 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip)); 781 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip));
782 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 782 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
783 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 783 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
784 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash)); 784 EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
785 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100)); 785 EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
786 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true)); 786 EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
787 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return("")); 787 EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
788 788
789 std::string file_contents = "corrupt zip file"; 789 std::string file_contents = "corrupt zip file";
790 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 790 ASSERT_EQ(static_cast<int>(file_contents.size()), base::WriteFile(
791 a_tmp, file_contents.data(), file_contents.size())); 791 a_tmp, file_contents.data(), file_contents.size()));
792 792
793 download_service_->CheckClientDownload( 793 download_service_->CheckClientDownload(
794 &item, 794 &item,
795 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 795 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
796 base::Unretained(this))); 796 base::Unretained(this)));
797 MessageLoop::current()->Run(); 797 MessageLoop::current()->Run();
798 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 798 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
799 Mock::VerifyAndClearExpectations(sb_service_.get()); 799 Mock::VerifyAndClearExpectations(sb_service_.get());
800 Mock::VerifyAndClearExpectations(signature_util_.get()); 800 Mock::VerifyAndClearExpectations(signature_util_.get());
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1216 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1217 1217
1218 cert = ReadTestCertificate("test_c.pem"); 1218 cert = ReadTestCertificate("test_c.pem");
1219 ASSERT_TRUE(cert.get()); 1219 ASSERT_TRUE(cert.get());
1220 whitelist_strings.clear(); 1220 whitelist_strings.clear();
1221 GetCertificateWhitelistStrings( 1221 GetCertificateWhitelistStrings(
1222 *cert.get(), *issuer_cert.get(), &whitelist_strings); 1222 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1223 EXPECT_THAT(whitelist_strings, ElementsAre()); 1223 EXPECT_THAT(whitelist_strings, ElementsAre());
1224 } 1224 }
1225 } // namespace safe_browsing 1225 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « chrome/browser/safe_browsing/download_feedback_unittest.cc ('k') | chrome/browser/shell_integration_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698