| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains download browser tests that are known to be runnable | 5 // This file contains download browser tests that are known to be runnable |
| 6 // in a pure content context. Over time tests should be migrated here. | 6 // in a pure content context. Over time tests should be migrated here. |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 1036 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 // Characterization risk: The next portion of the test examines the requests | 1047 // Characterization risk: The next portion of the test examines the requests |
| 1048 // that were sent out while downloading our resource. These requests | 1048 // that were sent out while downloading our resource. These requests |
| 1049 // correspond to the requests that were generated by the browser and the | 1049 // correspond to the requests that were generated by the browser and the |
| 1050 // downloads system and may change as implementation details change. | 1050 // downloads system and may change as implementation details change. |
| 1051 TestDownloadRequestHandler::CompletedRequests requests; | 1051 TestDownloadRequestHandler::CompletedRequests requests; |
| 1052 request_handler.GetCompletedRequestInfo(&requests); | 1052 request_handler.GetCompletedRequestInfo(&requests); |
| 1053 | 1053 |
| 1054 ASSERT_EQ(2u, requests.size()); | 1054 ASSERT_EQ(2u, requests.size()); |
| 1055 | 1055 |
| 1056 // The first request only transferrs bytes up until the interruption point. | 1056 // The first request only transferrs bytes up until the interruption point. |
| 1057 EXPECT_EQ(interruption.offset, requests[0].transferred_byte_count); | 1057 EXPECT_EQ(interruption.offset, requests[0]->transferred_byte_count); |
| 1058 | 1058 |
| 1059 // The next request should only have transferred the remainder of the | 1059 // The next request should only have transferred the remainder of the |
| 1060 // resource. | 1060 // resource. |
| 1061 EXPECT_EQ(parameters.size - interruption.offset, | 1061 EXPECT_EQ(parameters.size - interruption.offset, |
| 1062 requests[1].transferred_byte_count); | 1062 requests[1]->transferred_byte_count); |
| 1063 | 1063 |
| 1064 std::string value; | 1064 std::string value; |
| 1065 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1065 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1066 net::HttpRequestHeaders::kIfRange, &value)); | 1066 net::HttpRequestHeaders::kIfRange, &value)); |
| 1067 EXPECT_EQ(parameters.etag, value); | 1067 EXPECT_EQ(parameters.etag, value); |
| 1068 | 1068 |
| 1069 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1069 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1070 net::HttpRequestHeaders::kRange, &value)); | 1070 net::HttpRequestHeaders::kRange, &value)); |
| 1071 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1071 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
| 1072 value); | 1072 value); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 // Resumption should only attempt to contact the final URL if the download has a | 1075 // Resumption should only attempt to contact the final URL if the download has a |
| 1076 // URL chain. | 1076 // URL chain. |
| 1077 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectBeforeResume) { | 1077 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectBeforeResume) { |
| 1078 TestDownloadRequestHandler request_handler_1( | 1078 TestDownloadRequestHandler request_handler_1( |
| 1079 GURL("http://example.com/first-url")); | 1079 GURL("http://example.com/first-url")); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1174 // that were sent out while downloading our resource. These requests | 1174 // that were sent out while downloading our resource. These requests |
| 1175 // correspond to the requests that were generated by the browser and the | 1175 // correspond to the requests that were generated by the browser and the |
| 1176 // downloads system and may change as implementation details change. | 1176 // downloads system and may change as implementation details change. |
| 1177 TestDownloadRequestHandler::CompletedRequests requests; | 1177 TestDownloadRequestHandler::CompletedRequests requests; |
| 1178 request_handler.GetCompletedRequestInfo(&requests); | 1178 request_handler.GetCompletedRequestInfo(&requests); |
| 1179 | 1179 |
| 1180 ASSERT_EQ(3u, requests.size()); | 1180 ASSERT_EQ(3u, requests.size()); |
| 1181 | 1181 |
| 1182 // None of the request should have transferred the entire resource. The | 1182 // None of the request should have transferred the entire resource. The |
| 1183 // redirect response shows up as a response with 0 bytes transferred. | 1183 // redirect response shows up as a response with 0 bytes transferred. |
| 1184 EXPECT_GT(parameters.size, requests[0].transferred_byte_count); | 1184 EXPECT_GT(parameters.size, requests[0]->transferred_byte_count); |
| 1185 EXPECT_EQ(0, requests[1].transferred_byte_count); | 1185 EXPECT_EQ(0, requests[1]->transferred_byte_count); |
| 1186 EXPECT_GT(parameters.size, requests[2].transferred_byte_count); | 1186 EXPECT_GT(parameters.size, requests[2]->transferred_byte_count); |
| 1187 } | 1187 } |
| 1188 | 1188 |
| 1189 // If the server response for the resumption request specifies a bad range (i.e. | 1189 // If the server response for the resumption request specifies a bad range (i.e. |
| 1190 // not the range that was requested or an invalid or missing Content-Range | 1190 // not the range that was requested or an invalid or missing Content-Range |
| 1191 // header), then the download should be marked as interrupted again without | 1191 // header), then the download should be marked as interrupted again without |
| 1192 // discarding the partial state. | 1192 // discarding the partial state. |
| 1193 IN_PROC_BROWSER_TEST_F(DownloadContentTest, BadRangeHeader) { | 1193 IN_PROC_BROWSER_TEST_F(DownloadContentTest, BadRangeHeader) { |
| 1194 TestDownloadRequestHandler request_handler; | 1194 TestDownloadRequestHandler request_handler; |
| 1195 TestDownloadRequestHandler::Parameters parameters = | 1195 TestDownloadRequestHandler::Parameters parameters = |
| 1196 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1196 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1246 // Characterization risk: The next portion of the test examines the requests | 1246 // Characterization risk: The next portion of the test examines the requests |
| 1247 // that were sent out while downloading our resource. These requests | 1247 // that were sent out while downloading our resource. These requests |
| 1248 // correspond to the requests that were generated by the browser and the | 1248 // correspond to the requests that were generated by the browser and the |
| 1249 // downloads system and may change as implementation details change. | 1249 // downloads system and may change as implementation details change. |
| 1250 TestDownloadRequestHandler::CompletedRequests requests; | 1250 TestDownloadRequestHandler::CompletedRequests requests; |
| 1251 request_handler.GetCompletedRequestInfo(&requests); | 1251 request_handler.GetCompletedRequestInfo(&requests); |
| 1252 | 1252 |
| 1253 ASSERT_EQ(5u, requests.size()); | 1253 ASSERT_EQ(5u, requests.size()); |
| 1254 | 1254 |
| 1255 // None of the request should have transferred the entire resource. | 1255 // None of the request should have transferred the entire resource. |
| 1256 EXPECT_GT(parameters.size, requests[0].transferred_byte_count); | 1256 EXPECT_GT(parameters.size, requests[0]->transferred_byte_count); |
| 1257 EXPECT_EQ(0, requests[1].transferred_byte_count); | 1257 EXPECT_EQ(0, requests[1]->transferred_byte_count); |
| 1258 EXPECT_EQ(0, requests[2].transferred_byte_count); | 1258 EXPECT_EQ(0, requests[2]->transferred_byte_count); |
| 1259 EXPECT_EQ(0, requests[3].transferred_byte_count); | 1259 EXPECT_EQ(0, requests[3]->transferred_byte_count); |
| 1260 EXPECT_GT(parameters.size, requests[4].transferred_byte_count); | 1260 EXPECT_GT(parameters.size, requests[4]->transferred_byte_count); |
| 1261 } | 1261 } |
| 1262 | 1262 |
| 1263 // A partial resumption results in an HTTP 200 response. I.e. the server ignored | 1263 // A partial resumption results in an HTTP 200 response. I.e. the server ignored |
| 1264 // the range request and sent the entire resource instead. For If-Range requests | 1264 // the range request and sent the entire resource instead. For If-Range requests |
| 1265 // (as opposed to If-Match), the behavior for a precondition failure is also to | 1265 // (as opposed to If-Match), the behavior for a precondition failure is also to |
| 1266 // respond with a 200. So this test case covers both validation failure and | 1266 // respond with a 200. So this test case covers both validation failure and |
| 1267 // ignoring the range request. | 1267 // ignoring the range request. |
| 1268 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNotPartialResponse) { | 1268 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNotPartialResponse) { |
| 1269 const int kOriginalPatternGeneratorSeed = 1; | 1269 const int kOriginalPatternGeneratorSeed = 1; |
| 1270 const int kNewPatternGeneratorSeed = 2; | 1270 const int kNewPatternGeneratorSeed = 2; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 // response without restarting. On the network, we should deterministically | 1303 // response without restarting. On the network, we should deterministically |
| 1304 // see two requests: | 1304 // see two requests: |
| 1305 // * The original request which transfers upto our interruption point. | 1305 // * The original request which transfers upto our interruption point. |
| 1306 // * The resumption attempt, which receives the entire entity. | 1306 // * The resumption attempt, which receives the entire entity. |
| 1307 TestDownloadRequestHandler::CompletedRequests requests; | 1307 TestDownloadRequestHandler::CompletedRequests requests; |
| 1308 request_handler.GetCompletedRequestInfo(&requests); | 1308 request_handler.GetCompletedRequestInfo(&requests); |
| 1309 | 1309 |
| 1310 ASSERT_EQ(2u, requests.size()); | 1310 ASSERT_EQ(2u, requests.size()); |
| 1311 | 1311 |
| 1312 // The first request only transfers data up to the interruption point. | 1312 // The first request only transfers data up to the interruption point. |
| 1313 EXPECT_EQ(interruption.offset, requests[0].transferred_byte_count); | 1313 EXPECT_EQ(interruption.offset, requests[0]->transferred_byte_count); |
| 1314 | 1314 |
| 1315 // The second request transfers the entire response. | 1315 // The second request transfers the entire response. |
| 1316 EXPECT_EQ(parameters.size, requests[1].transferred_byte_count); | 1316 EXPECT_EQ(parameters.size, requests[1]->transferred_byte_count); |
| 1317 | 1317 |
| 1318 std::string value; | 1318 std::string value; |
| 1319 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1319 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1320 net::HttpRequestHeaders::kIfRange, &value)); | 1320 net::HttpRequestHeaders::kIfRange, &value)); |
| 1321 EXPECT_EQ(parameters.etag, value); | 1321 EXPECT_EQ(parameters.etag, value); |
| 1322 | 1322 |
| 1323 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1323 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1324 net::HttpRequestHeaders::kRange, &value)); | 1324 net::HttpRequestHeaders::kRange, &value)); |
| 1325 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1325 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
| 1326 value); | 1326 value); |
| 1327 } | 1327 } |
| 1328 | 1328 |
| 1329 // Confirm we restart if we don't have a verifier. | 1329 // Confirm we restart if we don't have a verifier. |
| 1330 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoETag) { | 1330 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoETag) { |
| 1331 const int kOriginalPatternGeneratorSeed = 1; | 1331 const int kOriginalPatternGeneratorSeed = 1; |
| 1332 const int kNewPatternGeneratorSeed = 2; | 1332 const int kNewPatternGeneratorSeed = 2; |
| 1333 | 1333 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1355 ASSERT_NO_FATAL_FAILURE( | 1355 ASSERT_NO_FATAL_FAILURE( |
| 1356 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, | 1356 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, |
| 1357 download->GetTargetFilePath())); | 1357 download->GetTargetFilePath())); |
| 1358 | 1358 |
| 1359 TestDownloadRequestHandler::CompletedRequests requests; | 1359 TestDownloadRequestHandler::CompletedRequests requests; |
| 1360 request_handler.GetCompletedRequestInfo(&requests); | 1360 request_handler.GetCompletedRequestInfo(&requests); |
| 1361 | 1361 |
| 1362 // Neither If-Range nor Range headers should be present in the second request. | 1362 // Neither If-Range nor Range headers should be present in the second request. |
| 1363 ASSERT_EQ(2u, requests.size()); | 1363 ASSERT_EQ(2u, requests.size()); |
| 1364 std::string value; | 1364 std::string value; |
| 1365 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1365 EXPECT_FALSE(requests[1]->request_headers.GetHeader( |
| 1366 net::HttpRequestHeaders::kIfRange, &value)); | 1366 net::HttpRequestHeaders::kIfRange, &value)); |
| 1367 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1367 EXPECT_FALSE(requests[1]->request_headers.GetHeader( |
| 1368 net::HttpRequestHeaders::kRange, &value)); | 1368 net::HttpRequestHeaders::kRange, &value)); |
| 1369 } | 1369 } |
| 1370 | 1370 |
| 1371 // Partial file goes missing before the download is resumed. The download should | 1371 // Partial file goes missing before the download is resumed. The download should |
| 1372 // restart. | 1372 // restart. |
| 1373 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoPartialFile) { | 1373 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoPartialFile) { |
| 1374 TestDownloadRequestHandler::Parameters parameters = | 1374 TestDownloadRequestHandler::Parameters parameters = |
| 1375 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1375 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1376 | 1376 |
| 1377 TestDownloadRequestHandler request_handler; | 1377 TestDownloadRequestHandler request_handler; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1861 // | 1861 // |
| 1862 // The second request reads the entire entity. | 1862 // The second request reads the entire entity. |
| 1863 // | 1863 // |
| 1864 // N.b. we can't make any assumptions about how many bytes are transferred by | 1864 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 1865 // the first request since response data will be bufferred until DownloadFile | 1865 // the first request since response data will be bufferred until DownloadFile |
| 1866 // is done initializing. | 1866 // is done initializing. |
| 1867 // | 1867 // |
| 1868 // TODO(asanka): Ideally we'll check that the intermediate file matches | 1868 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 1869 // expectations prior to issuing the first resumption request. | 1869 // expectations prior to issuing the first resumption request. |
| 1870 ASSERT_EQ(2u, completed_requests.size()); | 1870 ASSERT_EQ(2u, completed_requests.size()); |
| 1871 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); | 1871 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoHash) { | 1874 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoHash) { |
| 1875 TestDownloadRequestHandler request_handler; | 1875 TestDownloadRequestHandler request_handler; |
| 1876 TestDownloadRequestHandler::Parameters parameters; | 1876 TestDownloadRequestHandler::Parameters parameters; |
| 1877 request_handler.StartServing(parameters); | 1877 request_handler.StartServing(parameters); |
| 1878 | 1878 |
| 1879 base::FilePath intermediate_file_path = | 1879 base::FilePath intermediate_file_path = |
| 1880 GetDownloadDirectory().AppendASCII("intermediate"); | 1880 GetDownloadDirectory().AppendASCII("intermediate"); |
| 1881 std::vector<GURL> url_chain; | 1881 std::vector<GURL> url_chain; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 parameters.size, | 1921 parameters.size, |
| 1922 download->GetTargetFilePath()); | 1922 download->GetTargetFilePath()); |
| 1923 | 1923 |
| 1924 TestDownloadRequestHandler::CompletedRequests completed_requests; | 1924 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 1925 request_handler.GetCompletedRequestInfo(&completed_requests); | 1925 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 1926 | 1926 |
| 1927 // There's only one network request issued, and that is for the remainder of | 1927 // There's only one network request issued, and that is for the remainder of |
| 1928 // the file. | 1928 // the file. |
| 1929 ASSERT_EQ(1u, completed_requests.size()); | 1929 ASSERT_EQ(1u, completed_requests.size()); |
| 1930 EXPECT_EQ(parameters.size - kIntermediateSize, | 1930 EXPECT_EQ(parameters.size - kIntermediateSize, |
| 1931 completed_requests[0].transferred_byte_count); | 1931 completed_requests[0]->transferred_byte_count); |
| 1932 } | 1932 } |
| 1933 | 1933 |
| 1934 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1934 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1935 ResumeRestoredDownload_EtagMismatch) { | 1935 ResumeRestoredDownload_EtagMismatch) { |
| 1936 TestDownloadRequestHandler request_handler; | 1936 TestDownloadRequestHandler request_handler; |
| 1937 TestDownloadRequestHandler::Parameters parameters; | 1937 TestDownloadRequestHandler::Parameters parameters; |
| 1938 request_handler.StartServing(parameters); | 1938 request_handler.StartServing(parameters); |
| 1939 | 1939 |
| 1940 base::FilePath intermediate_file_path = | 1940 base::FilePath intermediate_file_path = |
| 1941 GetDownloadDirectory().AppendASCII("intermediate"); | 1941 GetDownloadDirectory().AppendASCII("intermediate"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1982 parameters.size, | 1982 parameters.size, |
| 1983 download->GetTargetFilePath()); | 1983 download->GetTargetFilePath()); |
| 1984 | 1984 |
| 1985 TestDownloadRequestHandler::CompletedRequests completed_requests; | 1985 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 1986 request_handler.GetCompletedRequestInfo(&completed_requests); | 1986 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 1987 | 1987 |
| 1988 // There's only one network request issued. The If-Range header allows the | 1988 // There's only one network request issued. The If-Range header allows the |
| 1989 // server to respond with the entire entity in one go. The existing contents | 1989 // server to respond with the entire entity in one go. The existing contents |
| 1990 // of the file should be discarded, and overwritten by the new contents. | 1990 // of the file should be discarded, and overwritten by the new contents. |
| 1991 ASSERT_EQ(1u, completed_requests.size()); | 1991 ASSERT_EQ(1u, completed_requests.size()); |
| 1992 EXPECT_EQ(parameters.size, completed_requests[0].transferred_byte_count); | 1992 EXPECT_EQ(parameters.size, completed_requests[0]->transferred_byte_count); |
| 1993 } | 1993 } |
| 1994 | 1994 |
| 1995 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1995 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1996 ResumeRestoredDownload_CorrectHash) { | 1996 ResumeRestoredDownload_CorrectHash) { |
| 1997 TestDownloadRequestHandler request_handler; | 1997 TestDownloadRequestHandler request_handler; |
| 1998 TestDownloadRequestHandler::Parameters parameters; | 1998 TestDownloadRequestHandler::Parameters parameters; |
| 1999 request_handler.StartServing(parameters); | 1999 request_handler.StartServing(parameters); |
| 2000 | 2000 |
| 2001 base::FilePath intermediate_file_path = | 2001 base::FilePath intermediate_file_path = |
| 2002 GetDownloadDirectory().AppendASCII("intermediate"); | 2002 GetDownloadDirectory().AppendASCII("intermediate"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2048 parameters.size, | 2048 parameters.size, |
| 2049 download->GetTargetFilePath()); | 2049 download->GetTargetFilePath()); |
| 2050 | 2050 |
| 2051 TestDownloadRequestHandler::CompletedRequests completed_requests; | 2051 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 2052 request_handler.GetCompletedRequestInfo(&completed_requests); | 2052 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 2053 | 2053 |
| 2054 // There's only one network request issued, and that is for the remainder of | 2054 // There's only one network request issued, and that is for the remainder of |
| 2055 // the file. | 2055 // the file. |
| 2056 ASSERT_EQ(1u, completed_requests.size()); | 2056 ASSERT_EQ(1u, completed_requests.size()); |
| 2057 EXPECT_EQ(parameters.size - kIntermediateSize, | 2057 EXPECT_EQ(parameters.size - kIntermediateSize, |
| 2058 completed_requests[0].transferred_byte_count); | 2058 completed_requests[0]->transferred_byte_count); |
| 2059 | 2059 |
| 2060 // SHA-256 hash of the entire 102400 bytes in the target file. | 2060 // SHA-256 hash of the entire 102400 bytes in the target file. |
| 2061 static const uint8_t kFullHash[] = { | 2061 static const uint8_t kFullHash[] = { |
| 2062 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, | 2062 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, |
| 2063 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, | 2063 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, |
| 2064 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; | 2064 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; |
| 2065 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), | 2065 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), |
| 2066 download->GetHash()); | 2066 download->GetHash()); |
| 2067 } | 2067 } |
| 2068 | 2068 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2133 // | 2133 // |
| 2134 // The second request reads the entire entity. | 2134 // The second request reads the entire entity. |
| 2135 // | 2135 // |
| 2136 // N.b. we can't make any assumptions about how many bytes are transferred by | 2136 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 2137 // the first request since response data will be bufferred until DownloadFile | 2137 // the first request since response data will be bufferred until DownloadFile |
| 2138 // is done initializing. | 2138 // is done initializing. |
| 2139 // | 2139 // |
| 2140 // TODO(asanka): Ideally we'll check that the intermediate file matches | 2140 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2141 // expectations prior to issuing the first resumption request. | 2141 // expectations prior to issuing the first resumption request. |
| 2142 ASSERT_EQ(2u, completed_requests.size()); | 2142 ASSERT_EQ(2u, completed_requests.size()); |
| 2143 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); | 2143 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 2144 | 2144 |
| 2145 // SHA-256 hash of the entire 102400 bytes in the target file. | 2145 // SHA-256 hash of the entire 102400 bytes in the target file. |
| 2146 static const uint8_t kFullHash[] = { | 2146 static const uint8_t kFullHash[] = { |
| 2147 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, | 2147 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, |
| 2148 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, | 2148 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, |
| 2149 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; | 2149 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; |
| 2150 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), | 2150 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), |
| 2151 download->GetHash()); | 2151 download->GetHash()); |
| 2152 } | 2152 } |
| 2153 | 2153 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2215 // | 2215 // |
| 2216 // The second request reads the entire entity. | 2216 // The second request reads the entire entity. |
| 2217 // | 2217 // |
| 2218 // N.b. we can't make any assumptions about how many bytes are transferred by | 2218 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 2219 // the first request since response data will be bufferred until DownloadFile | 2219 // the first request since response data will be bufferred until DownloadFile |
| 2220 // is done initializing. | 2220 // is done initializing. |
| 2221 // | 2221 // |
| 2222 // TODO(asanka): Ideally we'll check that the intermediate file matches | 2222 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2223 // expectations prior to issuing the first resumption request. | 2223 // expectations prior to issuing the first resumption request. |
| 2224 ASSERT_EQ(2u, completed_requests.size()); | 2224 ASSERT_EQ(2u, completed_requests.size()); |
| 2225 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); | 2225 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 2226 } | 2226 } |
| 2227 | 2227 |
| 2228 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) { | 2228 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) { |
| 2229 // These numbers are sufficiently large that the intermediate file won't be | 2229 // These numbers are sufficiently large that the intermediate file won't be |
| 2230 // read in a single Read(). | 2230 // read in a single Read(). |
| 2231 const int kFileSize = 1024 * 1024; | 2231 const int kFileSize = 1024 * 1024; |
| 2232 const int kIntermediateSize = kFileSize / 2 + 111; | 2232 const int kIntermediateSize = kFileSize / 2 + 111; |
| 2233 | 2233 |
| 2234 TestDownloadRequestHandler request_handler; | 2234 TestDownloadRequestHandler request_handler; |
| 2235 TestDownloadRequestHandler::Parameters parameters; | 2235 TestDownloadRequestHandler::Parameters parameters; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2283 TestDownloadRequestHandler::CompletedRequests completed_requests; | 2283 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 2284 request_handler.GetCompletedRequestInfo(&completed_requests); | 2284 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 2285 | 2285 |
| 2286 // There should be only one request. The intermediate file should be truncated | 2286 // There should be only one request. The intermediate file should be truncated |
| 2287 // to the expected size, and the request should be issued for the remainder. | 2287 // to the expected size, and the request should be issued for the remainder. |
| 2288 // | 2288 // |
| 2289 // TODO(asanka): Ideally we'll check that the intermediate file matches | 2289 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2290 // expectations prior to issuing the first resumption request. | 2290 // expectations prior to issuing the first resumption request. |
| 2291 ASSERT_EQ(1u, completed_requests.size()); | 2291 ASSERT_EQ(1u, completed_requests.size()); |
| 2292 EXPECT_EQ(parameters.size - kIntermediateSize, | 2292 EXPECT_EQ(parameters.size - kIntermediateSize, |
| 2293 completed_requests[0].transferred_byte_count); | 2293 completed_requests[0]->transferred_byte_count); |
| 2294 } |
| 2295 |
| 2296 // Test that the referrer header is set correctly for a download that's resumed |
| 2297 // partially. |
| 2298 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) { |
| 2299 TestDownloadRequestHandler request_handler; |
| 2300 TestDownloadRequestHandler::Parameters parameters = |
| 2301 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 2302 request_handler.StartServing(parameters); |
| 2303 |
| 2304 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2305 GURL document_url = embedded_test_server()->GetURL( |
| 2306 std::string("/download/download-link.html?dl=") |
| 2307 .append(request_handler.url().spec())); |
| 2308 |
| 2309 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
| 2310 WaitForInterrupt(download); |
| 2311 |
| 2312 download->Resume(); |
| 2313 WaitForCompletion(download); |
| 2314 |
| 2315 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
| 2316 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 2317 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
| 2318 parameters.pattern_generator_seed, parameters.size, |
| 2319 download->GetTargetFilePath())); |
| 2320 |
| 2321 TestDownloadRequestHandler::CompletedRequests requests; |
| 2322 request_handler.GetCompletedRequestInfo(&requests); |
| 2323 |
| 2324 ASSERT_GE(2u, requests.size()); |
| 2325 EXPECT_EQ(document_url.spec(), requests.back()->referrer); |
| 2294 } | 2326 } |
| 2295 | 2327 |
| 2296 // Check that the cookie policy is correctly updated when downloading a file | 2328 // Check that the cookie policy is correctly updated when downloading a file |
| 2297 // that redirects cross origin. | 2329 // that redirects cross origin. |
| 2298 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { | 2330 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { |
| 2299 net::EmbeddedTestServer origin_one; | 2331 net::EmbeddedTestServer origin_one; |
| 2300 net::EmbeddedTestServer origin_two; | 2332 net::EmbeddedTestServer origin_two; |
| 2301 ASSERT_TRUE(origin_one.Start()); | 2333 ASSERT_TRUE(origin_one.Start()); |
| 2302 ASSERT_TRUE(origin_two.Start()); | 2334 ASSERT_TRUE(origin_two.Start()); |
| 2303 | 2335 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2537 | 2569 |
| 2538 std::vector<DownloadItem*> downloads; | 2570 std::vector<DownloadItem*> downloads; |
| 2539 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2571 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2540 ASSERT_EQ(1u, downloads.size()); | 2572 ASSERT_EQ(1u, downloads.size()); |
| 2541 | 2573 |
| 2542 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2574 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 2543 downloads[0]->GetTargetFilePath().BaseName().value()); | 2575 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2544 } | 2576 } |
| 2545 | 2577 |
| 2546 } // namespace content | 2578 } // namespace content |
| OLD | NEW |