Chromium Code Reviews| 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..7121cf24f762e1d555d94209eba369b16fa06623 100644 |
| --- a/chrome/browser/safe_browsing/download_protection_service_unittest.cc |
| +++ b/chrome/browser/safe_browsing/download_protection_service_unittest.cc |
| @@ -554,8 +554,7 @@ void DownloadProtectionServiceTest::CheckClientDownloadReportCorruptZip( |
| &factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| - profile_->GetPrefs()->SetBoolean(prefs::kSafeBrowsingExtendedReportingEnabled, |
| - is_extended_reporting); |
| + SetExtendedReportingPreference(is_extended_reporting); |
| content::MockDownloadItem item; |
| PrepareBasicDownloadItem( |
| &item, |
| @@ -1978,8 +1977,10 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Unsupported) { |
| base::FilePath default_file_path(FILE_PATH_LITERAL("/foo/bar/test.txt")); |
| std::vector<base::FilePath::StringType> alternate_extensions{ |
| FILE_PATH_LITERAL(".tmp"), FILE_PATH_LITERAL(".asdfasdf")}; |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::SyncCheckDoneCallback, |
| base::Unretained(this))); |
| ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
| @@ -2009,8 +2010,10 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedDefault) { |
| factory.ClearFakeResponses(); |
| PrepareResponse(&factory, test_case.verdict, net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |
| @@ -2028,8 +2031,10 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_SupportedAlternate) { |
| EXPECT_CALL(*sb_service_->mock_database_manager(), |
| MatchDownloadWhitelistUrl(_)) |
| .WillRepeatedly(Return(false)); |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |
| @@ -2037,22 +2042,82 @@ 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; |
| + // Configs "server" side response to DANGEROUS, in case a request is send out. |
| + PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| + net::URLRequestStatus::SUCCESS); |
| + EXPECT_CALL(*sb_service_->mock_database_manager(), |
| + MatchDownloadWhitelistUrl(_)) |
| + .WillRepeatedly(Return(true)); |
| + SetExtendedReportingPreference(false); |
| + // Sets the sample rate to 1.00. |
| + SetWhitelistedDownloadSampleRate(1.00); |
| + download_service_->CheckPPAPIDownloadRequest( |
| + GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| + base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| + base::Unretained(this))); |
| + MessageLoop::current()->Run(); |
| + |
| + // Result should be SAFE, since download matches whitelist but user is not in |
| + // extended reporting group (a.k.a no request sents out). |
| + 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; |
| + // Configs "server" side response to DANGEROUS, in case a request is send out. |
| + PrepareResponse(&factory, ClientDownloadResponse::DANGEROUS, net::HTTP_OK, |
| + net::URLRequestStatus::SUCCESS); |
| EXPECT_CALL(*sb_service_->mock_database_manager(), |
| MatchDownloadWhitelistUrl(_)) |
| .WillRepeatedly(Return(true)); |
| + SetExtendedReportingPreference(true); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_->GetOffTheRecordProfile(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |
| + // Result should still be SAFE, since download matches whitelist and user is |
| + // in incognito mode. |
| 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); |
| + EXPECT_CALL(*sb_service_->mock_database_manager(), |
| + MatchDownloadWhitelistUrl(_)) |
| + .WillRepeatedly(Return(true)); |
| + // Sets the sample rate to 1.00 to trigger ClientDownloadRequest. |
| + SetWhitelistedDownloadSampleRate(1.00); |
| + SetExtendedReportingPreference(true); |
| + download_service_->CheckPPAPIDownloadRequest( |
| + GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| + base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| + base::Unretained(this))); |
| + MessageLoop::current()->Run(); |
|
Lei Zhang
2016/07/14 23:56:11
This is deprecated. Use a base::RunLoop instead. S
Jialiu Lin
2016/07/15 01:20:06
Done.
|
| + |
| + // Result should be Dangerous, since we will sample this download and ping SB |
| + // Server (server returns DANGEROUS verdict). |
| + 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")); |
| @@ -2062,8 +2127,10 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_FetchFailed) { |
| EXPECT_CALL(*sb_service_->mock_database_manager(), |
| MatchDownloadWhitelistUrl(_)) |
| .WillRepeatedly(Return(false)); |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |
| @@ -2081,8 +2148,10 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_InvalidResponse) { |
| EXPECT_CALL(*sb_service_->mock_database_manager(), |
| MatchDownloadWhitelistUrl(_)) |
| .WillRepeatedly(Return(false)); |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |
| @@ -2100,8 +2169,10 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Timeout) { |
| PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| download_service_->download_request_timeout_ms_ = 0; |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| GURL("http://example.com/foo"), default_file_path, alternate_extensions, |
| + profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |
| @@ -2160,8 +2231,9 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_Payload) { |
| PrepareResponse(&factory, ClientDownloadResponse::SAFE, net::HTTP_OK, |
| net::URLRequestStatus::SUCCESS); |
| const GURL kRequestorUrl("http://example.com/foo"); |
| + SetExtendedReportingPreference(false); |
| download_service_->CheckPPAPIDownloadRequest( |
| - kRequestorUrl, default_file_path, alternate_extensions, |
| + kRequestorUrl, default_file_path, alternate_extensions, profile_.get(), |
| base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, |
| base::Unretained(this))); |
| MessageLoop::current()->Run(); |