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

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

Issue 2146703002: Sample 1% url whitelisted PPAPI downloads to ping safe browsing server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix browser_tests Created 4 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 939f32d56a613192e364a2106c871ece0240e253..cb91e93f8ebef80fdff050c9334eaaaae4a84531 100644
--- a/chrome/browser/safe_browsing/download_protection_service_unittest.cc
+++ b/chrome/browser/safe_browsing/download_protection_service_unittest.cc
@@ -1980,6 +1980,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Unsupported) {
FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".asdfasdf")};
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback,
base::Unretained(this)));
ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE));
@@ -2011,6 +2012,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedDefault) {
net::URLRequestStatus::SUCCESS);
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
@@ -2030,6 +2032,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) {
.WillRepeatedly(Return(false));
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
@@ -2037,7 +2040,8 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) {
ASSERT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
}
-TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) {
+TEST_F(DownloadProtectionServiceTest,
+ PPAPIDownloadRequest_WhitelistedURLNotExtendedReporting) {
net::FakeURLFetcherFactory factory(nullptr);
base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
std::vector<base::FilePath::StringType> alternate_extensions;
@@ -2046,6 +2050,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) {
.WillRepeatedly(Return(true));
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
@@ -2053,6 +2058,46 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) {
ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE));
}
+TEST_F(DownloadProtectionServiceTest,
+ PPAPIDownloadRequest_WhitelistedURLIncognito) {
+ net::FakeURLFetcherFactory factory(nullptr);
+ base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
+ std::vector<base::FilePath::StringType> alternate_extensions;
+ EXPECT_CALL(*sb_service_->mock_database_manager(),
+ MatchDownloadWhitelistUrl(_))
+ .WillRepeatedly(Return(true));
+ download_service_->CheckPPAPIDownloadRequest(
+ GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ true, true, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ MessageLoop::current()->Run();
+
+ ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE));
+}
+
+TEST_F(DownloadProtectionServiceTest,
+ PPAPIDownloadRequest_SampleWhitelistedURL) {
+ net::FakeURLFetcherFactory factory(nullptr);
+ base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
+ std::vector<base::FilePath::StringType> alternate_extensions;
+ // Configs "server" side response to DANGEROUS.
+ PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK,
+ net::URLRequestStatus::SUCCESS);
+ // Sets the sample rate to 1.00 to trigger ClientDownloadRequest.
+ SetWhitelistedDownloadSampleRate(1.00);
+ EXPECT_CALL(*sb_service_->mock_database_manager(),
+ MatchDownloadWhitelistUrl(_))
+ .WillRepeatedly(Return(true));
+ download_service_->CheckPPAPIDownloadRequest(
+ GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ true, false, // In extended reporting group, and not in incognito mode.
+ base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
+ base::Unretained(this)));
+ MessageLoop::current()->Run();
+
+ ASSERT_TRUE(IsResult(DownloadProtectionService::DANGEROUS));
+}
+
TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) {
net::FakeURLFetcherFactory factory(nullptr);
base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.crx"));
@@ -2064,6 +2109,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) {
.WillRepeatedly(Return(false));
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
@@ -2083,6 +2129,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_InvalidResponse) {
.WillRepeatedly(Return(false));
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
@@ -2102,6 +2149,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Timeout) {
download_service_->download_request_timeout_ms_ = 0;
download_service_->CheckPPAPIDownloadRequest(
GURL("http://example.com/foo"), default_file_path, alternate_extensions,
+ false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();
@@ -2161,7 +2209,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Payload) {
net::URLRequestStatus::SUCCESS);
const GURL kRequestorUrl("http://example.com/foo");
download_service_->CheckPPAPIDownloadRequest(
- kRequestorUrl, default_file_path, alternate_extensions,
+ kRequestorUrl, default_file_path, alternate_extensions, false, false,
base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
base::Unretained(this)));
MessageLoop::current()->Run();

Powered by Google App Engine
This is Rietveld 408576698