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

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

Issue 12313141: Use DownloadItem directly in DownloadProtectionService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review fixes Created 7 years, 10 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
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 66703fa06fd9f39d104034e4b918542bb3986f9c..2eb3f03fdc78e9bbb1d4b18ff8c0448e6b91b499 100644
--- a/chrome/browser/safe_browsing/download_protection_service_unittest.cc
+++ b/chrome/browser/safe_browsing/download_protection_service_unittest.cc
@@ -24,7 +24,7 @@
#include "chrome/browser/safe_browsing/signature_util.h"
#include "chrome/common/safe_browsing/csd.pb.h"
#include "chrome/common/zip.h"
-#include "content/public/browser/download_item.h"
+#include "content/public/test/mock_download_item.h"
#include "content/public/test/test_browser_thread.h"
#include "googleurl/src/gurl.h"
#include "net/base/x509_certificate.h"
@@ -39,6 +39,7 @@ using ::testing::ElementsAre;
using ::testing::Mock;
using ::testing::NotNull;
using ::testing::Return;
+using ::testing::ReturnRef;
using ::testing::SaveArg;
using ::testing::StrictMock;
using ::testing::_;
@@ -309,19 +310,35 @@ class DownloadProtectionServiceTest : public testing::Test {
};
TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) {
- DownloadProtectionService::DownloadInfo info;
+ base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
+ std::vector<GURL> url_chain;
+ GURL referrer("http://www.google.com/");
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_));
+ EXPECT_CALL(item, RemoveObserver(_));
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
-
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
- info.download_url_chain.push_back(GURL("file://www.google.com/"));
+ Mock::VerifyAndClearExpectations(&item);
+
+ url_chain.push_back(GURL("file://www.google.com/"));
+ EXPECT_CALL(item, AddObserver(_));
+ EXPECT_CALL(item, RemoveObserver(_));
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -329,33 +346,40 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadInvalidUrl) {
}
TEST_F(DownloadProtectionServiceTest, CheckClientDownloadWhitelistedUrl) {
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
- info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe"));
- info.download_url_chain.push_back(GURL("http://www.google.com/a.exe"));
- info.referrer_url = GURL("http://www.google.com/");
-
+ base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/bla.exe"));
+ url_chain.push_back(GURL("http://www.google.com/a.exe"));
+ GURL referrer("http://www.google.com/");
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(2);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(2);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(GURL("http://www.google.com/a.exe")))
.WillRepeatedly(Return(true));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(2);
+ EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(2);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
EXPECT_TRUE(IsResult(DownloadProtectionService::SAFE));
// Check that the referrer is matched against the whitelist.
- info.download_url_chain.pop_back();
- info.referrer_url = GURL("http://www.google.com/a.exe");
+ url_chain.pop_back();
+ referrer = GURL("http://www.google.com/a.exe");
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -368,19 +392,32 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadFetchFailed) {
factory.SetFakeResponse(
DownloadProtectionService::GetDownloadRequestUrl(), "", false);
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
- info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
- info.referrer_url = GURL("http://www.google.com/");
+ base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/a.exe"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_));
+ EXPECT_CALL(item, RemoveObserver(_));
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
+ EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -397,19 +434,32 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
response.SerializeAsString(),
true);
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
- info.download_url_chain.push_back(GURL("http://www.evil.com/a.exe"));
- info.referrer_url = GURL("http://www.google.com/");
+ base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/a.exe"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(5);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(5);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(5);
+ EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(5);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -423,7 +473,7 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
true);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -437,7 +487,7 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
true);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -455,7 +505,7 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
true);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -474,7 +524,7 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadSuccess) {
true);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -494,19 +544,32 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadHTTPS) {
response.SerializeAsString(),
true);
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
- info.download_url_chain.push_back(GURL("https://www.evil.com/a.exe"));
- info.referrer_url = GURL("http://www.google.com/");
+ base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath a_exe(FILE_PATH_LITERAL("a.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/a.exe"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(1);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(1);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_exe));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1);
+ EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(1);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -530,11 +593,24 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
base::ScopedTempDir download_dir;
ASSERT_TRUE(download_dir.CreateUniqueTempDir());
- DownloadProtectionService::DownloadInfo info;
- info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.zip"));
- info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip"));
- info.referrer_url = GURL("http://www.google.com/");
+ base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")));
+ base::FilePath a_zip(FILE_PATH_LITERAL("a.zip"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/a.zip"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(3);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(3);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
// Write out a zip archive to the temporary file. In this case, it
// only contains a text file.
@@ -544,10 +620,10 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
zip_source_dir.path().Append(FILE_PATH_LITERAL("file.txt")),
file_contents.data(), file_contents.size()));
- ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false));
+ ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -559,14 +635,14 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
zip_source_dir.path().Append(FILE_PATH_LITERAL("file.exe")),
file_contents.data(), file_contents.size()));
- ASSERT_TRUE(zip::Zip(zip_source_dir.path(), info.local_file, false));
+ ASSERT_TRUE(zip::Zip(zip_source_dir.path(), a_tmp, false));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -582,7 +658,7 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadZip) {
true);
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -598,19 +674,31 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadCorruptZip) {
base::ScopedTempDir download_dir;
ASSERT_TRUE(download_dir.CreateUniqueTempDir());
- DownloadProtectionService::DownloadInfo info;
- info.local_file = download_dir.path().Append(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.zip"));
- info.download_url_chain.push_back(GURL("http://www.evil.com/a.zip"));
- info.referrer_url = GURL("http://www.google.com/");
+ base::FilePath a_tmp(download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")));
+ base::FilePath a_zip(FILE_PATH_LITERAL("a.zip"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/a.zip"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(1);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(1);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_zip));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
std::string file_contents = "corrupt zip file";
ASSERT_EQ(static_cast<int>(file_contents.size()), file_util::WriteFile(
- download_dir.path().Append(FILE_PATH_LITERAL("a.tmp")),
- file_contents.data(), file_contents.size()));
+ a_tmp, file_contents.data(), file_contents.size()));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -632,20 +720,33 @@ TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) {
response.SerializeAsString(),
true);
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.crx"));
- info.download_url_chain.push_back(GURL("http://www.evil.com/a.crx"));
- info.referrer_url = GURL("http://www.google.com/");
+ base::FilePath a_tmp(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath a_crx(FILE_PATH_LITERAL("a.crx"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/a.crx"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(1);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(1);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(a_tmp));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(a_crx));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _)).Times(1);
+ EXPECT_CALL(*signature_util_, CheckSignature(a_tmp, _)).Times(1);
- EXPECT_FALSE(download_service_->IsSupportedDownload(info));
+ EXPECT_FALSE(download_service_->IsSupportedDownload(item, a_crx));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -655,24 +756,34 @@ TEST_F(DownloadProtectionServiceTest, CheckClientCrxDownloadSuccess) {
TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
net::TestURLFetcherFactory factory;
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("bla.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("bla.exe"));
- info.download_url_chain.push_back(GURL("http://www.google.com/"));
- info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
- info.referrer_url = GURL("http://www.google.com/");
- info.sha256_hash = "hash";
- info.total_bytes = 100;
- info.user_initiated = true;
- info.remote_address = "10.11.12.13";
+ base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp"));
+ base::FilePath final_path(FILE_PATH_LITERAL("bla.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.google.com/"));
+ url_chain.push_back(GURL("http://www.google.com/bla.exe"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+ std::string remote_address = "10.11.12.13";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(1);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(1);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(final_path));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _))
+ EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _))
.WillOnce(SetCertificateContents("dummy cert data"));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
@@ -689,10 +800,10 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
ClientDownloadRequest request;
EXPECT_TRUE(request.ParseFromString(fetcher->upload_data()));
EXPECT_EQ("http://www.google.com/bla.exe", request.url());
- EXPECT_EQ(info.sha256_hash, request.digests().sha256());
- EXPECT_EQ(info.total_bytes, request.length());
- EXPECT_EQ(info.user_initiated, request.user_initiated());
- EXPECT_TRUE(RequestContainsServerIp(request, info.remote_address));
+ EXPECT_EQ(hash, request.digests().sha256());
+ EXPECT_EQ(item.GetReceivedBytes(), request.length());
+ EXPECT_EQ(item.HasUserGesture(), request.user_initiated());
+ EXPECT_TRUE(RequestContainsServerIp(request, remote_address));
EXPECT_EQ(2, request.resources_size());
EXPECT_TRUE(RequestContainsResource(request,
ClientDownloadRequest::DOWNLOAD_REDIRECT,
@@ -700,7 +811,7 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
EXPECT_TRUE(RequestContainsResource(request,
ClientDownloadRequest::DOWNLOAD_URL,
"http://www.google.com/bla.exe",
- info.referrer_url.spec()));
+ referrer.spec()));
EXPECT_TRUE(request.has_signature());
ASSERT_EQ(1, request.signature().certificate_chain_size());
const ClientDownloadRequest_CertificateChain& chain =
@@ -722,22 +833,33 @@ TEST_F(DownloadProtectionServiceTest,
CheckClientDownloadValidateRequestNoSignature) {
net::TestURLFetcherFactory factory;
- DownloadProtectionService::DownloadInfo info;
- info.local_file = base::FilePath(FILE_PATH_LITERAL("bla.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("bla.exe"));
- info.download_url_chain.push_back(GURL("http://www.google.com/"));
- info.download_url_chain.push_back(GURL("ftp://www.google.com/bla.exe"));
- info.referrer_url = GURL("http://www.google.com/");
- info.sha256_hash = "hash";
- info.total_bytes = 100;
- info.user_initiated = false;
+ base::FilePath tmp_path(FILE_PATH_LITERAL("bla.tmp"));
+ base::FilePath final_path(FILE_PATH_LITERAL("bla.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.google.com/"));
+ url_chain.push_back(GURL("ftp://www.google.com/bla.exe"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+ std::string remote_address = "10.11.12.13";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(1);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(1);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(final_path));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(remote_address));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
+ EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _));
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
@@ -754,9 +876,9 @@ TEST_F(DownloadProtectionServiceTest,
ClientDownloadRequest request;
EXPECT_TRUE(request.ParseFromString(fetcher->upload_data()));
EXPECT_EQ("ftp://www.google.com/bla.exe", request.url());
- EXPECT_EQ(info.sha256_hash, request.digests().sha256());
- EXPECT_EQ(info.total_bytes, request.length());
- EXPECT_EQ(info.user_initiated, request.user_initiated());
+ EXPECT_EQ(hash, request.digests().sha256());
+ EXPECT_EQ(item.GetReceivedBytes(), request.length());
+ EXPECT_EQ(item.HasUserGesture(), request.user_initiated());
EXPECT_EQ(2, request.resources_size());
EXPECT_TRUE(RequestContainsResource(request,
ClientDownloadRequest::DOWNLOAD_REDIRECT,
@@ -764,7 +886,7 @@ TEST_F(DownloadProtectionServiceTest,
EXPECT_TRUE(RequestContainsResource(request,
ClientDownloadRequest::DOWNLOAD_URL,
"ftp://www.google.com/bla.exe",
- info.referrer_url.spec()));
+ referrer.spec()));
EXPECT_TRUE(request.has_signature());
EXPECT_EQ(0, request.signature().certificate_chain_size());
@@ -778,20 +900,25 @@ TEST_F(DownloadProtectionServiceTest,
}
TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
- DownloadProtectionService::DownloadInfo info;
- info.download_url_chain.push_back(GURL("http://www.google.com/"));
- info.download_url_chain.push_back(GURL("http://www.google.com/bla.exe"));
- info.referrer_url = GURL("http://www.google.com/");
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.google.com/"));
+ url_chain.push_back(GURL("http://www.google.com/bla.exe"));
+ GURL referrer("http://www.google.com/");
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
// CheckDownloadURL returns immediately which means the client object callback
// will never be called. Nevertheless the callback provided to
// CheckClientDownload must still be called.
EXPECT_CALL(*sb_service_->mock_database_manager(),
- CheckDownloadUrl(ContainerEq(info.download_url_chain),
- NotNull()))
+ CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
.WillOnce(Return(true));
download_service_->CheckDownloadUrl(
- info,
+ item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -799,12 +926,11 @@ TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
Mock::VerifyAndClearExpectations(sb_service_);
EXPECT_CALL(*sb_service_->mock_database_manager(),
- CheckDownloadUrl(ContainerEq(info.download_url_chain),
- NotNull()))
+ CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
.WillOnce(DoAll(CheckDownloadUrlDone(SB_THREAT_TYPE_SAFE),
Return(false)));
download_service_->CheckDownloadUrl(
- info,
+ item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -812,13 +938,12 @@ TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
Mock::VerifyAndClearExpectations(sb_service_);
EXPECT_CALL(*sb_service_->mock_database_manager(),
- CheckDownloadUrl(ContainerEq(info.download_url_chain),
- NotNull()))
+ CheckDownloadUrl(ContainerEq(url_chain), NotNull()))
.WillOnce(DoAll(
CheckDownloadUrlDone(SB_THREAT_TYPE_URL_MALWARE),
Return(false)));
download_service_->CheckDownloadUrl(
- info,
+ item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -826,13 +951,13 @@ TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
Mock::VerifyAndClearExpectations(sb_service_);
EXPECT_CALL(*sb_service_->mock_database_manager(),
- CheckDownloadUrl(ContainerEq(info.download_url_chain),
+ CheckDownloadUrl(ContainerEq(url_chain),
NotNull()))
.WillOnce(DoAll(
CheckDownloadUrlDone(SB_THREAT_TYPE_BINARY_MALWARE_URL),
Return(false)));
download_service_->CheckDownloadUrl(
- info,
+ item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
msg_loop_.Run();
@@ -842,20 +967,33 @@ TEST_F(DownloadProtectionServiceTest, TestCheckDownloadUrl) {
TEST_F(DownloadProtectionServiceTest, TestDownloadRequestTimeout) {
net::TestURLFetcherFactory factory;
- DownloadProtectionService::DownloadInfo info;
- info.download_url_chain.push_back(GURL("http://www.evil.com/bla.exe"));
- info.referrer_url = GURL("http://www.google.com/");
- info.local_file = base::FilePath(FILE_PATH_LITERAL("a.tmp"));
- info.target_file = base::FilePath(FILE_PATH_LITERAL("a.exe"));
+ std::vector<GURL> url_chain;
+ url_chain.push_back(GURL("http://www.evil.com/bla.exe"));
+ GURL referrer("http://www.google.com/");
+ base::FilePath tmp_path(FILE_PATH_LITERAL("a.tmp"));
+ base::FilePath final_path(FILE_PATH_LITERAL("a.exe"));
+ std::string hash = "hash";
+
+ content::MockDownloadItem item;
+ EXPECT_CALL(item, AddObserver(_)).Times(1);
+ EXPECT_CALL(item, RemoveObserver(_)).Times(1);
+ EXPECT_CALL(item, GetFullPath()).WillRepeatedly(ReturnRef(tmp_path));
+ EXPECT_CALL(item, GetTargetFilePath()).WillRepeatedly(ReturnRef(final_path));
+ EXPECT_CALL(item, GetUrlChain()).WillRepeatedly(ReturnRef(url_chain));
+ EXPECT_CALL(item, GetReferrerUrl()).WillRepeatedly(ReturnRef(referrer));
+ EXPECT_CALL(item, GetHash()).WillRepeatedly(ReturnRef(hash));
+ EXPECT_CALL(item, GetReceivedBytes()).WillRepeatedly(Return(100));
+ EXPECT_CALL(item, HasUserGesture()).WillRepeatedly(Return(true));
+ EXPECT_CALL(item, GetRemoteAddress()).WillRepeatedly(Return(""));
EXPECT_CALL(*sb_service_->mock_database_manager(),
MatchDownloadWhitelistUrl(_))
.WillRepeatedly(Return(false));
- EXPECT_CALL(*signature_util_, CheckSignature(info.local_file, _));
+ EXPECT_CALL(*signature_util_, CheckSignature(tmp_path, _));
download_service_->download_request_timeout_ms_ = 10;
download_service_->CheckClientDownload(
- info,
+ &item,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
« no previous file with comments | « chrome/browser/safe_browsing/download_protection_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698