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..ed1decf8a92a00033090f2468b832f915594ce57 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,7 +2042,27 @@ 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; |
| + EXPECT_CALL(*sb_service_->mock_database_manager(), |
| + MatchDownloadWhitelistUrl(_)) |
| + .WillRepeatedly(Return(true)); |
| + 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(); |
| + |
| + 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; |
| @@ -2046,6 +2071,7 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) { |
| .WillRepeatedly(Return(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(); |
| @@ -2053,6 +2079,30 @@ TEST_F(DownloadProtectionServiceTest, PPAPIDownloadRequest_WhitelistedURL) { |
| ASSERT_TRUE(IsResult(DownloadProtectionService::SAFE)); |
|
asanka
2016/07/14 20:44:32
Did you verify that these two tests reliably fail
Jialiu Lin
2016/07/14 21:35:41
Added some code (and comments) to make these test
|
| } |
| +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)); |
| + 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(); |
| + |
| + 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 +2112,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 +2133,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 +2154,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 +2216,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(); |