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

Unified Diff: content/browser/download/download_browsertest.cc

Issue 1891623003: [Downloads] Set the Referrer header for resumed requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Catch up with ToT Created 4 years, 8 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 | « no previous file | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/download/download_browsertest.cc
diff --git a/content/browser/download/download_browsertest.cc b/content/browser/download/download_browsertest.cc
index d6521d73b8d8358d228c51caa4f890e80222cd97..c8d5b06cb9c0ae02fd4540ed8899bcb25144b69d 100644
--- a/content/browser/download/download_browsertest.cc
+++ b/content/browser/download/download_browsertest.cc
@@ -1054,19 +1054,19 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, StrongValidators) {
ASSERT_EQ(2u, requests.size());
// The first request only transferrs bytes up until the interruption point.
- EXPECT_EQ(interruption.offset, requests[0].transferred_byte_count);
+ EXPECT_EQ(interruption.offset, requests[0]->transferred_byte_count);
// The next request should only have transferred the remainder of the
// resource.
EXPECT_EQ(parameters.size - interruption.offset,
- requests[1].transferred_byte_count);
+ requests[1]->transferred_byte_count);
std::string value;
- ASSERT_TRUE(requests[1].request_headers.GetHeader(
+ ASSERT_TRUE(requests[1]->request_headers.GetHeader(
net::HttpRequestHeaders::kIfRange, &value));
EXPECT_EQ(parameters.etag, value);
- ASSERT_TRUE(requests[1].request_headers.GetHeader(
+ ASSERT_TRUE(requests[1]->request_headers.GetHeader(
net::HttpRequestHeaders::kRange, &value));
EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset),
value);
@@ -1181,9 +1181,9 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectWhileResume) {
// None of the request should have transferred the entire resource. The
// redirect response shows up as a response with 0 bytes transferred.
- EXPECT_GT(parameters.size, requests[0].transferred_byte_count);
- EXPECT_EQ(0, requests[1].transferred_byte_count);
- EXPECT_GT(parameters.size, requests[2].transferred_byte_count);
+ EXPECT_GT(parameters.size, requests[0]->transferred_byte_count);
+ EXPECT_EQ(0, requests[1]->transferred_byte_count);
+ EXPECT_GT(parameters.size, requests[2]->transferred_byte_count);
}
// If the server response for the resumption request specifies a bad range (i.e.
@@ -1253,11 +1253,11 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, BadRangeHeader) {
ASSERT_EQ(5u, requests.size());
// None of the request should have transferred the entire resource.
- EXPECT_GT(parameters.size, requests[0].transferred_byte_count);
- EXPECT_EQ(0, requests[1].transferred_byte_count);
- EXPECT_EQ(0, requests[2].transferred_byte_count);
- EXPECT_EQ(0, requests[3].transferred_byte_count);
- EXPECT_GT(parameters.size, requests[4].transferred_byte_count);
+ EXPECT_GT(parameters.size, requests[0]->transferred_byte_count);
+ EXPECT_EQ(0, requests[1]->transferred_byte_count);
+ EXPECT_EQ(0, requests[2]->transferred_byte_count);
+ EXPECT_EQ(0, requests[3]->transferred_byte_count);
+ EXPECT_GT(parameters.size, requests[4]->transferred_byte_count);
}
// A partial resumption results in an HTTP 200 response. I.e. the server ignored
@@ -1310,17 +1310,17 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNotPartialResponse) {
ASSERT_EQ(2u, requests.size());
// The first request only transfers data up to the interruption point.
- EXPECT_EQ(interruption.offset, requests[0].transferred_byte_count);
+ EXPECT_EQ(interruption.offset, requests[0]->transferred_byte_count);
// The second request transfers the entire response.
- EXPECT_EQ(parameters.size, requests[1].transferred_byte_count);
+ EXPECT_EQ(parameters.size, requests[1]->transferred_byte_count);
std::string value;
- ASSERT_TRUE(requests[1].request_headers.GetHeader(
+ ASSERT_TRUE(requests[1]->request_headers.GetHeader(
net::HttpRequestHeaders::kIfRange, &value));
EXPECT_EQ(parameters.etag, value);
- ASSERT_TRUE(requests[1].request_headers.GetHeader(
+ ASSERT_TRUE(requests[1]->request_headers.GetHeader(
net::HttpRequestHeaders::kRange, &value));
EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset),
value);
@@ -1362,9 +1362,9 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoETag) {
// Neither If-Range nor Range headers should be present in the second request.
ASSERT_EQ(2u, requests.size());
std::string value;
- EXPECT_FALSE(requests[1].request_headers.GetHeader(
+ EXPECT_FALSE(requests[1]->request_headers.GetHeader(
net::HttpRequestHeaders::kIfRange, &value));
- EXPECT_FALSE(requests[1].request_headers.GetHeader(
+ EXPECT_FALSE(requests[1]->request_headers.GetHeader(
net::HttpRequestHeaders::kRange, &value));
}
@@ -1868,7 +1868,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoFile) {
// TODO(asanka): Ideally we'll check that the intermediate file matches
// expectations prior to issuing the first resumption request.
ASSERT_EQ(2u, completed_requests.size());
- EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count);
+ EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count);
}
IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoHash) {
@@ -1928,7 +1928,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoHash) {
// the file.
ASSERT_EQ(1u, completed_requests.size());
EXPECT_EQ(parameters.size - kIntermediateSize,
- completed_requests[0].transferred_byte_count);
+ completed_requests[0]->transferred_byte_count);
}
IN_PROC_BROWSER_TEST_F(DownloadContentTest,
@@ -1989,7 +1989,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest,
// server to respond with the entire entity in one go. The existing contents
// of the file should be discarded, and overwritten by the new contents.
ASSERT_EQ(1u, completed_requests.size());
- EXPECT_EQ(parameters.size, completed_requests[0].transferred_byte_count);
+ EXPECT_EQ(parameters.size, completed_requests[0]->transferred_byte_count);
}
IN_PROC_BROWSER_TEST_F(DownloadContentTest,
@@ -2055,7 +2055,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest,
// the file.
ASSERT_EQ(1u, completed_requests.size());
EXPECT_EQ(parameters.size - kIntermediateSize,
- completed_requests[0].transferred_byte_count);
+ completed_requests[0]->transferred_byte_count);
// SHA-256 hash of the entire 102400 bytes in the target file.
static const uint8_t kFullHash[] = {
@@ -2140,7 +2140,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_WrongHash) {
// TODO(asanka): Ideally we'll check that the intermediate file matches
// expectations prior to issuing the first resumption request.
ASSERT_EQ(2u, completed_requests.size());
- EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count);
+ EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count);
// SHA-256 hash of the entire 102400 bytes in the target file.
static const uint8_t kFullHash[] = {
@@ -2222,7 +2222,7 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_ShortFile) {
// TODO(asanka): Ideally we'll check that the intermediate file matches
// expectations prior to issuing the first resumption request.
ASSERT_EQ(2u, completed_requests.size());
- EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count);
+ EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count);
}
IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) {
@@ -2290,7 +2290,39 @@ IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) {
// expectations prior to issuing the first resumption request.
ASSERT_EQ(1u, completed_requests.size());
EXPECT_EQ(parameters.size - kIntermediateSize,
- completed_requests[0].transferred_byte_count);
+ completed_requests[0]->transferred_byte_count);
+}
+
+// Test that the referrer header is set correctly for a download that's resumed
+// partially.
+IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) {
+ TestDownloadRequestHandler request_handler;
+ TestDownloadRequestHandler::Parameters parameters =
+ TestDownloadRequestHandler::Parameters::WithSingleInterruption();
+ request_handler.StartServing(parameters);
+
+ ASSERT_TRUE(embedded_test_server()->Start());
+ GURL document_url = embedded_test_server()->GetURL(
+ std::string("/download/download-link.html?dl=")
+ .append(request_handler.url().spec()));
+
+ DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url);
+ WaitForInterrupt(download);
+
+ download->Resume();
+ WaitForCompletion(download);
+
+ ASSERT_EQ(parameters.size, download->GetReceivedBytes());
+ ASSERT_EQ(parameters.size, download->GetTotalBytes());
+ ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents(
+ parameters.pattern_generator_seed, parameters.size,
+ download->GetTargetFilePath()));
+
+ TestDownloadRequestHandler::CompletedRequests requests;
+ request_handler.GetCompletedRequestInfo(&requests);
+
+ ASSERT_GE(2u, requests.size());
+ EXPECT_EQ(document_url.spec(), requests.back()->referrer);
}
// Check that the cookie policy is correctly updated when downloading a file
« no previous file with comments | « no previous file | content/browser/download/download_item_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698