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

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

Issue 179963002: New Zip::ZipFromMemory API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments 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
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 17 matching lines...) Expand all
28 #include "content/public/test/mock_download_item.h" 28 #include "content/public/test/mock_download_item.h"
29 #include "content/public/test/test_browser_thread_bundle.h" 29 #include "content/public/test/test_browser_thread_bundle.h"
30 #include "content/public/test/test_utils.h" 30 #include "content/public/test/test_utils.h"
31 #include "net/cert/x509_certificate.h" 31 #include "net/cert/x509_certificate.h"
32 #include "net/http/http_status_code.h" 32 #include "net/http/http_status_code.h"
33 #include "net/url_request/test_url_fetcher_factory.h" 33 #include "net/url_request/test_url_fetcher_factory.h"
34 #include "net/url_request/url_fetcher_delegate.h" 34 #include "net/url_request/url_fetcher_delegate.h"
35 #include "net/url_request/url_request_status.h" 35 #include "net/url_request/url_request_status.h"
36 #include "testing/gmock/include/gmock/gmock.h" 36 #include "testing/gmock/include/gmock/gmock.h"
37 #include "testing/gtest/include/gtest/gtest.h" 37 #include "testing/gtest/include/gtest/gtest.h"
38 #include "third_party/zlib/google/zip.h" 38 #include "third_party/zlib/google/zip_writer.h"
39 #include "url/gurl.h" 39 #include "url/gurl.h"
40 40
41 using ::testing::Assign; 41 using ::testing::Assign;
42 using ::testing::ContainerEq; 42 using ::testing::ContainerEq;
43 using ::testing::DoAll; 43 using ::testing::DoAll;
44 using ::testing::ElementsAre; 44 using ::testing::ElementsAre;
45 using ::testing::Mock; 45 using ::testing::Mock;
46 using ::testing::NotNull; 46 using ::testing::NotNull;
47 using ::testing::Return; 47 using ::testing::Return;
48 using ::testing::ReturnRef; 48 using ::testing::ReturnRef;
(...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip)); 700 EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip));
701 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain)); 701 EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
702 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer)); 702 EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
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 zip::ZipWriter writer;
711 ASSERT_TRUE(zip_source_dir.CreateUniqueTempDir()); 711 writer.AddFile(base::FilePath(FILE_PATH_LITERAL("file.txt")),
712 std::string file_contents = "dummy file"; 712 base::StringPiece("dummy file", 10));
satorux1 2014/03/24 06:16:07 please drop ", 10". this should be unnecessary.
713 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 713 ASSERT_TRUE(writer.Commit(a_tmp, zip::ZipWriter::OverWrite));
714 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")),
715 file_contents.data(), file_contents.size()));
716 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
717 714
718 download_service_->CheckClientDownload( 715 download_service_->CheckClientDownload(
719 &item, 716 &item,
720 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 717 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
721 base::Unretained(this))); 718 base::Unretained(this)));
722 MessageLoop::current()->Run(); 719 MessageLoop::current()->Run();
723 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE)); 720 EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
724 Mock::VerifyAndClearExpectations(sb_service_.get()); 721 Mock::VerifyAndClearExpectations(sb_service_.get());
725 Mock::VerifyAndClearExpectations(signature_util_.get()); 722 Mock::VerifyAndClearExpectations(signature_util_.get());
726 723
727 // Now check with an executable in the zip file as well. 724 // Now check with an executable in the zip file as well.
728 ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile( 725 writer.AddFile(base::FilePath(FILE_PATH_LITERAL("file.exe")),
729 zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")), 726 base::StringPiece("dummy file", 10));
satorux1 2014/03/24 06:16:07 ditto
730 file_contents.data(), file_contents.size())); 727 ASSERT_TRUE(writer.Commit(a_tmp, zip::ZipWriter::OverWrite));
731 ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
732 728
733 EXPECT_CALL(*sb_service_->mock_database_manager(), 729 EXPECT_CALL(*sb_service_->mock_database_manager(),
734 MatchDownloadWhitelistUrl(_)) 730 MatchDownloadWhitelistUrl(_))
735 .WillRepeatedly(Return(false)); 731 .WillRepeatedly(Return(false));
736 732
737 download_service_->CheckClientDownload( 733 download_service_->CheckClientDownload(
738 &item, 734 &item,
739 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, 735 base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
740 base::Unretained(this))); 736 base::Unretained(this)));
741 MessageLoop::current()->Run(); 737 MessageLoop::current()->Run();
(...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after
1216 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit")); 1212 EXPECT_THAT(whitelist_strings, ElementsAre(cert_base + "/OU=unit"));
1217 1213
1218 cert = ReadTestCertificate("test_c.pem"); 1214 cert = ReadTestCertificate("test_c.pem");
1219 ASSERT_TRUE(cert.get()); 1215 ASSERT_TRUE(cert.get());
1220 whitelist_strings.clear(); 1216 whitelist_strings.clear();
1221 GetCertificateWhitelistStrings( 1217 GetCertificateWhitelistStrings(
1222 *cert.get(), *issuer_cert.get(), &whitelist_strings); 1218 *cert.get(), *issuer_cert.get(), &whitelist_strings);
1223 EXPECT_THAT(whitelist_strings, ElementsAre()); 1219 EXPECT_THAT(whitelist_strings, ElementsAre());
1224 } 1220 }
1225 } // namespace safe_browsing 1221 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698