Commit 155b96f5 authored by Daniel Rubery's avatar Daniel Rubery Committed by Commit Bot

Fix long unit tests in DownloadProtectionServiceTest

We had a few tests that wanted to inspect the ClientDownloadRequest,
but didn't do anything with the TestURLLoaderFactory. This led to the
test waiting for 7 seconds, until the timeout kicks in. This CL adds
calls to PrepareResponse, to mock out the network response, so that
we no longer wait for a timeout. All unit tests under
DownloadProtectionServiceTest now take <1s, with the worst around 200ms.

Bug: 896796
Change-Id: I1c8f24c962fbb5d13e2a86ecfda6f80c1d19d1f4
Reviewed-on: https://chromium-review.googlesource.com/c/1299502Reviewed-by: default avatarNathan Parker <nparker@chromium.org>
Commit-Queue: Daniel Rubery <drubery@chromium.org>
Cr-Commit-Position: refs/heads/master@{#603511}
parent d29c1236
...@@ -190,7 +190,6 @@ void CheckClientDownloadRequest::Cancel(bool download_destroyed) { ...@@ -190,7 +190,6 @@ void CheckClientDownloadRequest::Cancel(bool download_destroyed) {
void CheckClientDownloadRequest::OnDownloadDestroyed( void CheckClientDownloadRequest::OnDownloadDestroyed(
download::DownloadItem* download) { download::DownloadItem* download) {
Cancel(/*download_destroyed=*/true); Cancel(/*download_destroyed=*/true);
DCHECK(item_ == NULL);
} }
// TODO: this method puts "DownloadProtectionService::" in front of a lot of // TODO: this method puts "DownloadProtectionService::" in front of a lot of
......
...@@ -1755,6 +1755,10 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) { ...@@ -1755,6 +1755,10 @@ TEST_F(DownloadProtectionServiceTest, CheckClientDownloadValidateRequest) {
tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)) tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _))
.WillOnce(SetDosHeaderContents("dummy dos header")); .WillOnce(SetDosHeaderContents("dummy dos header"));
#endif // OS_MACOSX #endif // OS_MACOSX
PrepareResponse(ClientDownloadResponse::SAFE, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
RunLoop run_loop; RunLoop run_loop;
download_service_->CheckClientDownload( download_service_->CheckClientDownload(
&item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
...@@ -1828,6 +1832,9 @@ TEST_F(DownloadProtectionServiceTest, ...@@ -1828,6 +1832,9 @@ TEST_F(DownloadProtectionServiceTest,
tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _)); tmp_path_, BinaryFeatureExtractor::kDefaultOptions, _, _));
#endif // OS_MACOSX #endif // OS_MACOSX
PrepareResponse(ClientDownloadResponse::SAFE, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
RunLoop run_loop; RunLoop run_loop;
download_service_->CheckClientDownload( download_service_->CheckClientDownload(
&item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
...@@ -1896,6 +1903,9 @@ TEST_F(DownloadProtectionServiceTest, ...@@ -1896,6 +1903,9 @@ TEST_F(DownloadProtectionServiceTest,
interceptor_run_loop.Quit(); interceptor_run_loop.Quit();
})); }));
PrepareResponse(ClientDownloadResponse::SAFE, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
RunLoop run_loop; RunLoop run_loop;
download_service_->CheckClientDownload( download_service_->CheckClientDownload(
&item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
...@@ -1964,6 +1974,9 @@ TEST_F(DownloadProtectionServiceTest, ...@@ -1964,6 +1974,9 @@ TEST_F(DownloadProtectionServiceTest,
reinterpret_cast<history::ContextID>(1), 0, GURL(), redirects, reinterpret_cast<history::ContextID>(1), 0, GURL(), redirects,
ui::PAGE_TRANSITION_TYPED, history::SOURCE_BROWSED, false); ui::PAGE_TRANSITION_TYPED, history::SOURCE_BROWSED, false);
PrepareResponse(ClientDownloadResponse::SAFE, net::HTTP_OK,
net::URLRequestStatus::SUCCESS);
RunLoop run_loop; RunLoop run_loop;
download_service_->CheckClientDownload( download_service_->CheckClientDownload(
&item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback, &item, base::Bind(&DownloadProtectionServiceTest::CheckDoneCallback,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment