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

Unified Diff: chrome/browser/safe_browsing/download_protection_service_unittest.cc

Issue 1262753002: [SafeBrowsing] Send pings for Zip files that contain other archives. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/safe_browsing/download_protection_service_unittest.cc
diff --git a/chrome/browser/safe_browsing/download_protection_service_unittest.cc b/chrome/browser/safe_browsing/download_protection_service_unittest.cc
index 53d3bb2fe5e3601653cbbef97b72475d5e02516d..cd27712f50375a0af74f718dea7ce5121f8fb9a9 100644
--- a/chrome/browser/safe_browsing/download_protection_service_unittest.cc
+++ b/chrome/browser/safe_browsing/download_protection_service_unittest.cc
@@ -1074,6 +1074,9 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
EXPECT_TRUE(HasClientDownloadRequest());
const ClientDownloadRequest& request = *GetClientDownloadRequest();
+ EXPECT_TRUE(request.has_download_type());
+ EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE,
+ request.download_type());
EXPECT_EQ(1, request.archived_binary_size());
const ClientDownloadRequest_ArchivedBinary* archived_binary =
GetRequestArchivedBinary(request, "file.exe");
@@ -1114,6 +1117,59 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
EXPECT_FALSE(HasClientDownloadRequest());
#endif
Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
+
+ // Repeat the test with an archive inside the zip file in addition to the
+ // executable.
+ ASSERT_EQ(static_cast<int>(file_contents.size()),
+ base::WriteFile(
+ zip_source_dir.path().Append(FILE_PATH_LITERAL("file.rar")),
+ file_contents.data(), file_contents.size()));
+ ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
+
+ download_service_->CheckClientDownload(
+ &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ MessageLoop::current()->Run();
+
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ ASSERT_TRUE(HasClientDownloadRequest());
+ EXPECT_EQ(1, GetClientDownloadRequest()->archived_binary_size());
+ EXPECT_TRUE(GetClientDownloadRequest()->has_download_type());
+ EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_EXECUTABLE,
+ GetClientDownloadRequest()->download_type());
+ ClearClientDownloadRequest();
+#else
+ // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence
+ // the resulting verdict is UNKNOWN.
+ EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
+ EXPECT_FALSE(HasClientDownloadRequest());
+#endif
+ Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
+
+ // Repeat the test with just the archive inside the zip file.
+ ASSERT_TRUE(
+ base::DeleteFile(zip_source_dir.path().AppendASCII("file.exe"), false));
+ ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
+
+ download_service_->CheckClientDownload(
+ &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ MessageLoop::current()->Run();
+
+#if defined(OS_WIN) || defined(OS_MACOSX)
+ ASSERT_TRUE(HasClientDownloadRequest());
+ EXPECT_EQ(0, GetClientDownloadRequest()->archived_binary_size());
+ EXPECT_TRUE(GetClientDownloadRequest()->has_download_type());
+ EXPECT_EQ(ClientDownloadRequest_DownloadType_ZIPPED_ARCHIVE,
+ GetClientDownloadRequest()->download_type());
+ ClearClientDownloadRequest();
+#else
+ // For !(OS_WIN || OS_MACOSX), no file types are currently supported. Hence
+ // the resulting verdict is UNKNOWN.
+ EXPECT_TRUE(IsResult(DownloadProtectionService::UNKNOWN));
+ EXPECT_FALSE(HasClientDownloadRequest());
+#endif
+ Mock::VerifyAndClearExpectations(binary_feature_extractor_.get());
}
TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) {

Powered by Google App Engine
This is Rietveld 408576698