| 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 1033 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1044 // Characterization risk: The next portion of the test examines the requests | 1044 // Characterization risk: The next portion of the test examines the requests |
| 1045 // that were sent out while downloading our resource. These requests | 1045 // that were sent out while downloading our resource. These requests |
| 1046 // correspond to the requests that were generated by the browser and the | 1046 // correspond to the requests that were generated by the browser and the |
| 1047 // downloads system and may change as implementation details change. | 1047 // downloads system and may change as implementation details change. |
| 1048 TestDownloadRequestHandler::CompletedRequests requests; | 1048 TestDownloadRequestHandler::CompletedRequests requests; |
| 1049 request_handler.GetCompletedRequestInfo(&requests); | 1049 request_handler.GetCompletedRequestInfo(&requests); |
| 1050 | 1050 |
| 1051 ASSERT_EQ(2u, requests.size()); | 1051 ASSERT_EQ(2u, requests.size()); |
| 1052 | 1052 |
| 1053 // The first request only transferrs bytes up until the interruption point. | 1053 // The first request only transferrs bytes up until the interruption point. |
| 1054 EXPECT_EQ(interruption.offset, requests[0].transferred_byte_count); | 1054 EXPECT_EQ(interruption.offset, requests[0]->transferred_byte_count); |
| 1055 | 1055 |
| 1056 // The next request should only have transferred the remainder of the | 1056 // The next request should only have transferred the remainder of the |
| 1057 // resource. | 1057 // resource. |
| 1058 EXPECT_EQ(parameters.size - interruption.offset, | 1058 EXPECT_EQ(parameters.size - interruption.offset, |
| 1059 requests[1].transferred_byte_count); | 1059 requests[1]->transferred_byte_count); |
| 1060 | 1060 |
| 1061 std::string value; | 1061 std::string value; |
| 1062 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1062 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1063 net::HttpRequestHeaders::kIfRange, &value)); | 1063 net::HttpRequestHeaders::kIfRange, &value)); |
| 1064 EXPECT_EQ(parameters.etag, value); | 1064 EXPECT_EQ(parameters.etag, value); |
| 1065 | 1065 |
| 1066 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1066 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1067 net::HttpRequestHeaders::kRange, &value)); | 1067 net::HttpRequestHeaders::kRange, &value)); |
| 1068 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1068 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
| 1069 value); | 1069 value); |
| 1070 } | 1070 } |
| 1071 | 1071 |
| 1072 // Resumption should only attempt to contact the final URL if the download has a | 1072 // Resumption should only attempt to contact the final URL if the download has a |
| 1073 // URL chain. | 1073 // URL chain. |
| 1074 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectBeforeResume) { | 1074 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RedirectBeforeResume) { |
| 1075 TestDownloadRequestHandler request_handler_1( | 1075 TestDownloadRequestHandler request_handler_1( |
| 1076 GURL("http://example.com/first-url")); | 1076 GURL("http://example.com/first-url")); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1171 // that were sent out while downloading our resource. These requests | 1171 // that were sent out while downloading our resource. These requests |
| 1172 // correspond to the requests that were generated by the browser and the | 1172 // correspond to the requests that were generated by the browser and the |
| 1173 // downloads system and may change as implementation details change. | 1173 // downloads system and may change as implementation details change. |
| 1174 TestDownloadRequestHandler::CompletedRequests requests; | 1174 TestDownloadRequestHandler::CompletedRequests requests; |
| 1175 request_handler.GetCompletedRequestInfo(&requests); | 1175 request_handler.GetCompletedRequestInfo(&requests); |
| 1176 | 1176 |
| 1177 ASSERT_EQ(3u, requests.size()); | 1177 ASSERT_EQ(3u, requests.size()); |
| 1178 | 1178 |
| 1179 // None of the request should have transferred the entire resource. The | 1179 // None of the request should have transferred the entire resource. The |
| 1180 // redirect response shows up as a response with 0 bytes transferred. | 1180 // redirect response shows up as a response with 0 bytes transferred. |
| 1181 EXPECT_GT(parameters.size, requests[0].transferred_byte_count); | 1181 EXPECT_GT(parameters.size, requests[0]->transferred_byte_count); |
| 1182 EXPECT_EQ(0, requests[1].transferred_byte_count); | 1182 EXPECT_EQ(0, requests[1]->transferred_byte_count); |
| 1183 EXPECT_GT(parameters.size, requests[2].transferred_byte_count); | 1183 EXPECT_GT(parameters.size, requests[2]->transferred_byte_count); |
| 1184 } | 1184 } |
| 1185 | 1185 |
| 1186 // If the server response for the resumption request specifies a bad range (i.e. | 1186 // If the server response for the resumption request specifies a bad range (i.e. |
| 1187 // not the range that was requested or an invalid or missing Content-Range | 1187 // not the range that was requested or an invalid or missing Content-Range |
| 1188 // header), then the download should be marked as interrupted again without | 1188 // header), then the download should be marked as interrupted again without |
| 1189 // discarding the partial state. | 1189 // discarding the partial state. |
| 1190 IN_PROC_BROWSER_TEST_F(DownloadContentTest, BadRangeHeader) { | 1190 IN_PROC_BROWSER_TEST_F(DownloadContentTest, BadRangeHeader) { |
| 1191 TestDownloadRequestHandler request_handler; | 1191 TestDownloadRequestHandler request_handler; |
| 1192 TestDownloadRequestHandler::Parameters parameters = | 1192 TestDownloadRequestHandler::Parameters parameters = |
| 1193 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1193 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1243 // Characterization risk: The next portion of the test examines the requests | 1243 // Characterization risk: The next portion of the test examines the requests |
| 1244 // that were sent out while downloading our resource. These requests | 1244 // that were sent out while downloading our resource. These requests |
| 1245 // correspond to the requests that were generated by the browser and the | 1245 // correspond to the requests that were generated by the browser and the |
| 1246 // downloads system and may change as implementation details change. | 1246 // downloads system and may change as implementation details change. |
| 1247 TestDownloadRequestHandler::CompletedRequests requests; | 1247 TestDownloadRequestHandler::CompletedRequests requests; |
| 1248 request_handler.GetCompletedRequestInfo(&requests); | 1248 request_handler.GetCompletedRequestInfo(&requests); |
| 1249 | 1249 |
| 1250 ASSERT_EQ(5u, requests.size()); | 1250 ASSERT_EQ(5u, requests.size()); |
| 1251 | 1251 |
| 1252 // None of the request should have transferred the entire resource. | 1252 // None of the request should have transferred the entire resource. |
| 1253 EXPECT_GT(parameters.size, requests[0].transferred_byte_count); | 1253 EXPECT_GT(parameters.size, requests[0]->transferred_byte_count); |
| 1254 EXPECT_EQ(0, requests[1].transferred_byte_count); | 1254 EXPECT_EQ(0, requests[1]->transferred_byte_count); |
| 1255 EXPECT_EQ(0, requests[2].transferred_byte_count); | 1255 EXPECT_EQ(0, requests[2]->transferred_byte_count); |
| 1256 EXPECT_EQ(0, requests[3].transferred_byte_count); | 1256 EXPECT_EQ(0, requests[3]->transferred_byte_count); |
| 1257 EXPECT_GT(parameters.size, requests[4].transferred_byte_count); | 1257 EXPECT_GT(parameters.size, requests[4]->transferred_byte_count); |
| 1258 } | 1258 } |
| 1259 | 1259 |
| 1260 // A partial resumption results in an HTTP 200 response. I.e. the server ignored | 1260 // A partial resumption results in an HTTP 200 response. I.e. the server ignored |
| 1261 // the range request and sent the entire resource instead. For If-Range requests | 1261 // the range request and sent the entire resource instead. For If-Range requests |
| 1262 // (as opposed to If-Match), the behavior for a precondition failure is also to | 1262 // (as opposed to If-Match), the behavior for a precondition failure is also to |
| 1263 // respond with a 200. So this test case covers both validation failure and | 1263 // respond with a 200. So this test case covers both validation failure and |
| 1264 // ignoring the range request. | 1264 // ignoring the range request. |
| 1265 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNotPartialResponse) { | 1265 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNotPartialResponse) { |
| 1266 const int kOriginalPatternGeneratorSeed = 1; | 1266 const int kOriginalPatternGeneratorSeed = 1; |
| 1267 const int kNewPatternGeneratorSeed = 2; | 1267 const int kNewPatternGeneratorSeed = 2; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 // response without restarting. On the network, we should deterministically | 1300 // response without restarting. On the network, we should deterministically |
| 1301 // see two requests: | 1301 // see two requests: |
| 1302 // * The original request which transfers upto our interruption point. | 1302 // * The original request which transfers upto our interruption point. |
| 1303 // * The resumption attempt, which receives the entire entity. | 1303 // * The resumption attempt, which receives the entire entity. |
| 1304 TestDownloadRequestHandler::CompletedRequests requests; | 1304 TestDownloadRequestHandler::CompletedRequests requests; |
| 1305 request_handler.GetCompletedRequestInfo(&requests); | 1305 request_handler.GetCompletedRequestInfo(&requests); |
| 1306 | 1306 |
| 1307 ASSERT_EQ(2u, requests.size()); | 1307 ASSERT_EQ(2u, requests.size()); |
| 1308 | 1308 |
| 1309 // The first request only transfers data up to the interruption point. | 1309 // The first request only transfers data up to the interruption point. |
| 1310 EXPECT_EQ(interruption.offset, requests[0].transferred_byte_count); | 1310 EXPECT_EQ(interruption.offset, requests[0]->transferred_byte_count); |
| 1311 | 1311 |
| 1312 // The second request transfers the entire response. | 1312 // The second request transfers the entire response. |
| 1313 EXPECT_EQ(parameters.size, requests[1].transferred_byte_count); | 1313 EXPECT_EQ(parameters.size, requests[1]->transferred_byte_count); |
| 1314 | 1314 |
| 1315 std::string value; | 1315 std::string value; |
| 1316 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1316 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1317 net::HttpRequestHeaders::kIfRange, &value)); | 1317 net::HttpRequestHeaders::kIfRange, &value)); |
| 1318 EXPECT_EQ(parameters.etag, value); | 1318 EXPECT_EQ(parameters.etag, value); |
| 1319 | 1319 |
| 1320 ASSERT_TRUE(requests[1].request_headers.GetHeader( | 1320 ASSERT_TRUE(requests[1]->request_headers.GetHeader( |
| 1321 net::HttpRequestHeaders::kRange, &value)); | 1321 net::HttpRequestHeaders::kRange, &value)); |
| 1322 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), | 1322 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), |
| 1323 value); | 1323 value); |
| 1324 } | 1324 } |
| 1325 | 1325 |
| 1326 // Confirm we restart if we don't have a verifier. | 1326 // Confirm we restart if we don't have a verifier. |
| 1327 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoETag) { | 1327 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoETag) { |
| 1328 const int kOriginalPatternGeneratorSeed = 1; | 1328 const int kOriginalPatternGeneratorSeed = 1; |
| 1329 const int kNewPatternGeneratorSeed = 2; | 1329 const int kNewPatternGeneratorSeed = 2; |
| 1330 | 1330 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1352 ASSERT_NO_FATAL_FAILURE( | 1352 ASSERT_NO_FATAL_FAILURE( |
| 1353 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, | 1353 ReadAndVerifyFileContents(kNewPatternGeneratorSeed, parameters.size, |
| 1354 download->GetTargetFilePath())); | 1354 download->GetTargetFilePath())); |
| 1355 | 1355 |
| 1356 TestDownloadRequestHandler::CompletedRequests requests; | 1356 TestDownloadRequestHandler::CompletedRequests requests; |
| 1357 request_handler.GetCompletedRequestInfo(&requests); | 1357 request_handler.GetCompletedRequestInfo(&requests); |
| 1358 | 1358 |
| 1359 // Neither If-Range nor Range headers should be present in the second request. | 1359 // Neither If-Range nor Range headers should be present in the second request. |
| 1360 ASSERT_EQ(2u, requests.size()); | 1360 ASSERT_EQ(2u, requests.size()); |
| 1361 std::string value; | 1361 std::string value; |
| 1362 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1362 EXPECT_FALSE(requests[1]->request_headers.GetHeader( |
| 1363 net::HttpRequestHeaders::kIfRange, &value)); | 1363 net::HttpRequestHeaders::kIfRange, &value)); |
| 1364 EXPECT_FALSE(requests[1].request_headers.GetHeader( | 1364 EXPECT_FALSE(requests[1]->request_headers.GetHeader( |
| 1365 net::HttpRequestHeaders::kRange, &value)); | 1365 net::HttpRequestHeaders::kRange, &value)); |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 // Partial file goes missing before the download is resumed. The download should | 1368 // Partial file goes missing before the download is resumed. The download should |
| 1369 // restart. | 1369 // restart. |
| 1370 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoPartialFile) { | 1370 IN_PROC_BROWSER_TEST_F(DownloadContentTest, RestartIfNoPartialFile) { |
| 1371 TestDownloadRequestHandler::Parameters parameters = | 1371 TestDownloadRequestHandler::Parameters parameters = |
| 1372 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); | 1372 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 1373 | 1373 |
| 1374 TestDownloadRequestHandler request_handler; | 1374 TestDownloadRequestHandler request_handler; |
| (...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 // | 1858 // |
| 1859 // The second request reads the entire entity. | 1859 // The second request reads the entire entity. |
| 1860 // | 1860 // |
| 1861 // N.b. we can't make any assumptions about how many bytes are transferred by | 1861 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 1862 // the first request since response data will be bufferred until DownloadFile | 1862 // the first request since response data will be bufferred until DownloadFile |
| 1863 // is done initializing. | 1863 // is done initializing. |
| 1864 // | 1864 // |
| 1865 // TODO(asanka): Ideally we'll check that the intermediate file matches | 1865 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 1866 // expectations prior to issuing the first resumption request. | 1866 // expectations prior to issuing the first resumption request. |
| 1867 ASSERT_EQ(2u, completed_requests.size()); | 1867 ASSERT_EQ(2u, completed_requests.size()); |
| 1868 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); | 1868 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 1869 } | 1869 } |
| 1870 | 1870 |
| 1871 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoHash) { | 1871 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_NoHash) { |
| 1872 TestDownloadRequestHandler request_handler; | 1872 TestDownloadRequestHandler request_handler; |
| 1873 TestDownloadRequestHandler::Parameters parameters; | 1873 TestDownloadRequestHandler::Parameters parameters; |
| 1874 request_handler.StartServing(parameters); | 1874 request_handler.StartServing(parameters); |
| 1875 | 1875 |
| 1876 base::FilePath intermediate_file_path = | 1876 base::FilePath intermediate_file_path = |
| 1877 GetDownloadDirectory().AppendASCII("intermediate"); | 1877 GetDownloadDirectory().AppendASCII("intermediate"); |
| 1878 std::vector<GURL> url_chain; | 1878 std::vector<GURL> url_chain; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 parameters.size, | 1918 parameters.size, |
| 1919 download->GetTargetFilePath()); | 1919 download->GetTargetFilePath()); |
| 1920 | 1920 |
| 1921 TestDownloadRequestHandler::CompletedRequests completed_requests; | 1921 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 1922 request_handler.GetCompletedRequestInfo(&completed_requests); | 1922 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 1923 | 1923 |
| 1924 // There's only one network request issued, and that is for the remainder of | 1924 // There's only one network request issued, and that is for the remainder of |
| 1925 // the file. | 1925 // the file. |
| 1926 ASSERT_EQ(1u, completed_requests.size()); | 1926 ASSERT_EQ(1u, completed_requests.size()); |
| 1927 EXPECT_EQ(parameters.size - kIntermediateSize, | 1927 EXPECT_EQ(parameters.size - kIntermediateSize, |
| 1928 completed_requests[0].transferred_byte_count); | 1928 completed_requests[0]->transferred_byte_count); |
| 1929 } | 1929 } |
| 1930 | 1930 |
| 1931 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1931 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1932 ResumeRestoredDownload_EtagMismatch) { | 1932 ResumeRestoredDownload_EtagMismatch) { |
| 1933 TestDownloadRequestHandler request_handler; | 1933 TestDownloadRequestHandler request_handler; |
| 1934 TestDownloadRequestHandler::Parameters parameters; | 1934 TestDownloadRequestHandler::Parameters parameters; |
| 1935 request_handler.StartServing(parameters); | 1935 request_handler.StartServing(parameters); |
| 1936 | 1936 |
| 1937 base::FilePath intermediate_file_path = | 1937 base::FilePath intermediate_file_path = |
| 1938 GetDownloadDirectory().AppendASCII("intermediate"); | 1938 GetDownloadDirectory().AppendASCII("intermediate"); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1979 parameters.size, | 1979 parameters.size, |
| 1980 download->GetTargetFilePath()); | 1980 download->GetTargetFilePath()); |
| 1981 | 1981 |
| 1982 TestDownloadRequestHandler::CompletedRequests completed_requests; | 1982 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 1983 request_handler.GetCompletedRequestInfo(&completed_requests); | 1983 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 1984 | 1984 |
| 1985 // There's only one network request issued. The If-Range header allows the | 1985 // There's only one network request issued. The If-Range header allows the |
| 1986 // server to respond with the entire entity in one go. The existing contents | 1986 // server to respond with the entire entity in one go. The existing contents |
| 1987 // of the file should be discarded, and overwritten by the new contents. | 1987 // of the file should be discarded, and overwritten by the new contents. |
| 1988 ASSERT_EQ(1u, completed_requests.size()); | 1988 ASSERT_EQ(1u, completed_requests.size()); |
| 1989 EXPECT_EQ(parameters.size, completed_requests[0].transferred_byte_count); | 1989 EXPECT_EQ(parameters.size, completed_requests[0]->transferred_byte_count); |
| 1990 } | 1990 } |
| 1991 | 1991 |
| 1992 IN_PROC_BROWSER_TEST_F(DownloadContentTest, | 1992 IN_PROC_BROWSER_TEST_F(DownloadContentTest, |
| 1993 ResumeRestoredDownload_CorrectHash) { | 1993 ResumeRestoredDownload_CorrectHash) { |
| 1994 TestDownloadRequestHandler request_handler; | 1994 TestDownloadRequestHandler request_handler; |
| 1995 TestDownloadRequestHandler::Parameters parameters; | 1995 TestDownloadRequestHandler::Parameters parameters; |
| 1996 request_handler.StartServing(parameters); | 1996 request_handler.StartServing(parameters); |
| 1997 | 1997 |
| 1998 base::FilePath intermediate_file_path = | 1998 base::FilePath intermediate_file_path = |
| 1999 GetDownloadDirectory().AppendASCII("intermediate"); | 1999 GetDownloadDirectory().AppendASCII("intermediate"); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 parameters.size, | 2045 parameters.size, |
| 2046 download->GetTargetFilePath()); | 2046 download->GetTargetFilePath()); |
| 2047 | 2047 |
| 2048 TestDownloadRequestHandler::CompletedRequests completed_requests; | 2048 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 2049 request_handler.GetCompletedRequestInfo(&completed_requests); | 2049 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 2050 | 2050 |
| 2051 // There's only one network request issued, and that is for the remainder of | 2051 // There's only one network request issued, and that is for the remainder of |
| 2052 // the file. | 2052 // the file. |
| 2053 ASSERT_EQ(1u, completed_requests.size()); | 2053 ASSERT_EQ(1u, completed_requests.size()); |
| 2054 EXPECT_EQ(parameters.size - kIntermediateSize, | 2054 EXPECT_EQ(parameters.size - kIntermediateSize, |
| 2055 completed_requests[0].transferred_byte_count); | 2055 completed_requests[0]->transferred_byte_count); |
| 2056 | 2056 |
| 2057 // SHA-256 hash of the entire 102400 bytes in the target file. | 2057 // SHA-256 hash of the entire 102400 bytes in the target file. |
| 2058 static const uint8_t kFullHash[] = { | 2058 static const uint8_t kFullHash[] = { |
| 2059 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, | 2059 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, |
| 2060 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, | 2060 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, |
| 2061 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; | 2061 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; |
| 2062 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), | 2062 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), |
| 2063 download->GetHash()); | 2063 download->GetHash()); |
| 2064 } | 2064 } |
| 2065 | 2065 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2130 // | 2130 // |
| 2131 // The second request reads the entire entity. | 2131 // The second request reads the entire entity. |
| 2132 // | 2132 // |
| 2133 // N.b. we can't make any assumptions about how many bytes are transferred by | 2133 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 2134 // the first request since response data will be bufferred until DownloadFile | 2134 // the first request since response data will be bufferred until DownloadFile |
| 2135 // is done initializing. | 2135 // is done initializing. |
| 2136 // | 2136 // |
| 2137 // TODO(asanka): Ideally we'll check that the intermediate file matches | 2137 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2138 // expectations prior to issuing the first resumption request. | 2138 // expectations prior to issuing the first resumption request. |
| 2139 ASSERT_EQ(2u, completed_requests.size()); | 2139 ASSERT_EQ(2u, completed_requests.size()); |
| 2140 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); | 2140 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 2141 | 2141 |
| 2142 // SHA-256 hash of the entire 102400 bytes in the target file. | 2142 // SHA-256 hash of the entire 102400 bytes in the target file. |
| 2143 static const uint8_t kFullHash[] = { | 2143 static const uint8_t kFullHash[] = { |
| 2144 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, | 2144 0xa7, 0x44, 0x49, 0x86, 0x24, 0xc6, 0x84, 0x6c, 0x89, 0xdf, 0xd8, |
| 2145 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, | 2145 0xec, 0xa0, 0xe0, 0x61, 0x12, 0xdc, 0x80, 0x13, 0xf2, 0x83, 0x49, |
| 2146 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; | 2146 0xa9, 0x14, 0x52, 0x32, 0xf0, 0x95, 0x20, 0xca, 0x5b, 0x30}; |
| 2147 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), | 2147 EXPECT_EQ(std::string(std::begin(kFullHash), std::end(kFullHash)), |
| 2148 download->GetHash()); | 2148 download->GetHash()); |
| 2149 } | 2149 } |
| 2150 | 2150 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2212 // | 2212 // |
| 2213 // The second request reads the entire entity. | 2213 // The second request reads the entire entity. |
| 2214 // | 2214 // |
| 2215 // N.b. we can't make any assumptions about how many bytes are transferred by | 2215 // N.b. we can't make any assumptions about how many bytes are transferred by |
| 2216 // the first request since response data will be bufferred until DownloadFile | 2216 // the first request since response data will be bufferred until DownloadFile |
| 2217 // is done initializing. | 2217 // is done initializing. |
| 2218 // | 2218 // |
| 2219 // TODO(asanka): Ideally we'll check that the intermediate file matches | 2219 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2220 // expectations prior to issuing the first resumption request. | 2220 // expectations prior to issuing the first resumption request. |
| 2221 ASSERT_EQ(2u, completed_requests.size()); | 2221 ASSERT_EQ(2u, completed_requests.size()); |
| 2222 EXPECT_EQ(parameters.size, completed_requests[1].transferred_byte_count); | 2222 EXPECT_EQ(parameters.size, completed_requests[1]->transferred_byte_count); |
| 2223 } |
| 2224 |
| 2225 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ResumeRestoredDownload_LongFile) { |
| 2226 // These numbers are sufficiently large that the intermediate file won't be |
| 2227 // read in a single Read(). |
| 2228 const int kFileSize = 1024 * 1024; |
| 2229 const int kIntermediateSize = kFileSize / 2 + 111; |
| 2230 |
| 2231 TestDownloadRequestHandler request_handler; |
| 2232 TestDownloadRequestHandler::Parameters parameters; |
| 2233 parameters.size = kFileSize; |
| 2234 request_handler.StartServing(parameters); |
| 2235 |
| 2236 base::FilePath intermediate_file_path = |
| 2237 GetDownloadDirectory().AppendASCII("intermediate"); |
| 2238 std::vector<GURL> url_chain; |
| 2239 |
| 2240 // Size of file is slightly longer than the size known to DownloadItem. |
| 2241 std::vector<char> buffer(kIntermediateSize + 100); |
| 2242 request_handler.GetPatternBytes( |
| 2243 parameters.pattern_generator_seed, 0, buffer.size(), buffer.data()); |
| 2244 ASSERT_EQ( |
| 2245 kIntermediateSize + 100, |
| 2246 base::WriteFile(intermediate_file_path, buffer.data(), buffer.size())); |
| 2247 url_chain.push_back(request_handler.url()); |
| 2248 |
| 2249 DownloadItem* download = DownloadManagerForShell(shell())->CreateDownloadItem( |
| 2250 "F7FB1F59-7DE1-4845-AFDB-8A688F70F583", |
| 2251 1, |
| 2252 intermediate_file_path, |
| 2253 base::FilePath(), |
| 2254 url_chain, |
| 2255 GURL(), |
| 2256 GURL(), |
| 2257 GURL(), |
| 2258 "application/octet-stream", |
| 2259 "application/octet-stream", |
| 2260 base::Time::Now(), |
| 2261 base::Time(), |
| 2262 parameters.etag, |
| 2263 std::string(), |
| 2264 kIntermediateSize, |
| 2265 parameters.size, |
| 2266 std::string(), |
| 2267 DownloadItem::INTERRUPTED, |
| 2268 DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, |
| 2269 DOWNLOAD_INTERRUPT_REASON_NETWORK_FAILED, |
| 2270 false); |
| 2271 |
| 2272 download->Resume(); |
| 2273 WaitForCompletion(download); |
| 2274 |
| 2275 EXPECT_FALSE(base::PathExists(intermediate_file_path)); |
| 2276 ReadAndVerifyFileContents(parameters.pattern_generator_seed, |
| 2277 parameters.size, |
| 2278 download->GetTargetFilePath()); |
| 2279 |
| 2280 TestDownloadRequestHandler::CompletedRequests completed_requests; |
| 2281 request_handler.GetCompletedRequestInfo(&completed_requests); |
| 2282 |
| 2283 // There should be only one request. The intermediate file should be truncated |
| 2284 // to the expected size, and the request should be issued for the remainder. |
| 2285 // |
| 2286 // TODO(asanka): Ideally we'll check that the intermediate file matches |
| 2287 // expectations prior to issuing the first resumption request. |
| 2288 ASSERT_EQ(1u, completed_requests.size()); |
| 2289 EXPECT_EQ(parameters.size - kIntermediateSize, |
| 2290 completed_requests[0]->transferred_byte_count); |
| 2291 } |
| 2292 |
| 2293 // Test that the referrer header is set correctly for a download that's resumed |
| 2294 // partially. |
| 2295 IN_PROC_BROWSER_TEST_F(DownloadContentTest, ReferrerForPartialResumption) { |
| 2296 TestDownloadRequestHandler request_handler; |
| 2297 TestDownloadRequestHandler::Parameters parameters = |
| 2298 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); |
| 2299 request_handler.StartServing(parameters); |
| 2300 |
| 2301 ASSERT_TRUE(embedded_test_server()->Start()); |
| 2302 GURL document_url = embedded_test_server()->GetURL( |
| 2303 std::string("/download/download-link.html?dl=") |
| 2304 .append(request_handler.url().spec())); |
| 2305 |
| 2306 DownloadItem* download = StartDownloadAndReturnItem(shell(), document_url); |
| 2307 WaitForInterrupt(download); |
| 2308 |
| 2309 download->Resume(); |
| 2310 WaitForCompletion(download); |
| 2311 |
| 2312 ASSERT_EQ(parameters.size, download->GetReceivedBytes()); |
| 2313 ASSERT_EQ(parameters.size, download->GetTotalBytes()); |
| 2314 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( |
| 2315 parameters.pattern_generator_seed, parameters.size, |
| 2316 download->GetTargetFilePath())); |
| 2317 |
| 2318 TestDownloadRequestHandler::CompletedRequests requests; |
| 2319 request_handler.GetCompletedRequestInfo(&requests); |
| 2320 |
| 2321 ASSERT_GE(2u, requests.size()); |
| 2322 EXPECT_EQ(document_url.spec(), requests.back()->referrer); |
| 2223 } | 2323 } |
| 2224 | 2324 |
| 2225 // Check that the cookie policy is correctly updated when downloading a file | 2325 // Check that the cookie policy is correctly updated when downloading a file |
| 2226 // that redirects cross origin. | 2326 // that redirects cross origin. |
| 2227 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { | 2327 IN_PROC_BROWSER_TEST_F(DownloadContentTest, CookiePolicy) { |
| 2228 net::EmbeddedTestServer origin_one; | 2328 net::EmbeddedTestServer origin_one; |
| 2229 net::EmbeddedTestServer origin_two; | 2329 net::EmbeddedTestServer origin_two; |
| 2230 ASSERT_TRUE(origin_one.Start()); | 2330 ASSERT_TRUE(origin_one.Start()); |
| 2231 ASSERT_TRUE(origin_two.Start()); | 2331 ASSERT_TRUE(origin_two.Start()); |
| 2232 | 2332 |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2466 | 2566 |
| 2467 std::vector<DownloadItem*> downloads; | 2567 std::vector<DownloadItem*> downloads; |
| 2468 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); | 2568 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); |
| 2469 ASSERT_EQ(1u, downloads.size()); | 2569 ASSERT_EQ(1u, downloads.size()); |
| 2470 | 2570 |
| 2471 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), | 2571 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), |
| 2472 downloads[0]->GetTargetFilePath().BaseName().value()); | 2572 downloads[0]->GetTargetFilePath().BaseName().value()); |
| 2473 } | 2573 } |
| 2474 | 2574 |
| 2475 } // namespace content | 2575 } // namespace content |
| OLD | NEW |