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

Side by Side Diff: content/browser/download/download_browsertest.cc

Issue 1544603003: [Downloads] Do not store error responses during resumption. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify-downloader-core
Patch Set: Created 4 years, 11 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 unified diff | Download patch
OLDNEW
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 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 ASSERT_TRUE(requests[1].request_headers.GetHeader( 1114 ASSERT_TRUE(requests[1].request_headers.GetHeader(
1115 net::HttpRequestHeaders::kIfRange, &value)); 1115 net::HttpRequestHeaders::kIfRange, &value));
1116 EXPECT_EQ(parameters.etag, value); 1116 EXPECT_EQ(parameters.etag, value);
1117 1117
1118 ASSERT_TRUE(requests[1].request_headers.GetHeader( 1118 ASSERT_TRUE(requests[1].request_headers.GetHeader(
1119 net::HttpRequestHeaders::kRange, &value)); 1119 net::HttpRequestHeaders::kRange, &value));
1120 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset), 1120 EXPECT_EQ(base::StringPrintf("bytes=%" PRId64 "-", interruption.offset),
1121 value); 1121 value);
1122 } 1122 }
1123 1123
1124 // Resumption should only attempt to contact the final URL if the download has a
1125 // URL chain.
1126 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RedirectBeforeResume) {
1127 TestDownloadRequestHandler request_handler_1(
1128 GURL("http://example.com/first-url"));
1129 request_handler_1.StartServingStaticResponse(
1130 "HTTP/1.1 302 Redirect\r\n"
1131 "Location: http://example.com/second-url\r\n"
1132 "\r\n");
1133
1134 TestDownloadRequestHandler request_handler_2(
1135 GURL("http://example.com/second-url"));
1136 request_handler_2.StartServingStaticResponse(
1137 "HTTP/1.1 302 Redirect\r\n"
1138 "Location: http://example.com/third-url\r\n"
1139 "\r\n");
1140
1141 TestDownloadRequestHandler request_handler_3(
1142 GURL("http://example.com/third-url"));
1143 request_handler_3.StartServingStaticResponse(
1144 "HTTP/1.1 302 Redirect\r\n"
1145 "Location: http://example.com/download\r\n"
1146 "\r\n");
1147
1148 TestDownloadRequestHandler resumable_request_handler(
1149 GURL("http://example.com/download"));
1150 TestDownloadRequestHandler::Parameters parameters =
1151 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1152 resumable_request_handler.StartServing(parameters);
1153
1154 DownloadItem* download = StartDownloadAndReturnItem(
1155 initiator_shell_for_resumption(), request_handler_1.url());
1156 WaitForInterrupt(download);
1157
1158 EXPECT_EQ(4u, download->GetUrlChain().size());
1159 EXPECT_EQ(request_handler_1.url(), download->GetOriginalUrl());
1160 EXPECT_EQ(resumable_request_handler.url(), download->GetURL());
1161
1162 // Now that the download is interrupted, make all intermediate servers return
1163 // a 404. The only way a resumption request would succeed if the resumption
1164 // request is sent to the final server in the chain.
1165 const char k404Response[] = "HTTP/1.1 404 Not found\r\n\r\n";
1166 request_handler_1.StartServingStaticResponse(k404Response);
1167 request_handler_2.StartServingStaticResponse(k404Response);
1168 request_handler_3.StartServingStaticResponse(k404Response);
1169
1170 PrepareToResume();
1171 download->Resume();
1172 WaitForCompletion(download);
1173
1174 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents(
1175 parameters.pattern_generator_seed, parameters.size,
1176 download->GetTargetFilePath()));
1177 }
1178
1179 // If a resumption request results in a redirect, the response should be ignored
1180 // and the download should be marked as interrupted again.
1181 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RedirectWhileResume) {
1182 TestDownloadRequestHandler request_handler(
1183 GURL("http://example.com/first-url"));
1184 TestDownloadRequestHandler::Parameters parameters =
1185 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1186 ++parameters.pattern_generator_seed;
1187 request_handler.StartServing(parameters);
1188
1189 // We should never send a request to the decoy. If we do, the request will
1190 // always succeed, which results in behavior that diverges from what we want,
1191 // which is for the download to return to being interrupted.
1192 TestDownloadRequestHandler decoy_request_handler(
1193 GURL("http://example.com/decoy"));
1194 decoy_request_handler.StartServing(TestDownloadRequestHandler::Parameters());
1195
1196 DownloadItem* download = StartDownloadAndReturnItem(
1197 initiator_shell_for_resumption(), request_handler.url());
1198 WaitForInterrupt(download);
1199
1200 // Upon resumption, the server starts responding with a redirect. This
1201 // response should not be accepted.
1202 request_handler.StartServingStaticResponse(
1203 "HTTP/1.1 302 Redirect\r\n"
1204 "Location: http://example.com/decoy\r\n"
1205 "\r\n");
1206 PrepareToResume();
1207 download->Resume();
1208 WaitForInterrupt(download);
1209 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE,
1210 download->GetLastReason());
1211
1212 // Back to the original request handler. Resumption should now succeed, and
1213 // use the partial data it had prior to the first interruption.
1214 request_handler.StartServing(parameters);
1215 download->Resume();
1216 WaitForCompletion(download);
1217
1218 ASSERT_EQ(parameters.size, download->GetReceivedBytes());
1219 ASSERT_EQ(parameters.size, download->GetTotalBytes());
1220 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents(
1221 parameters.pattern_generator_seed, parameters.size,
1222 download->GetTargetFilePath()));
1223
1224 // Characterization risk: The next portion of the test examines the requests
1225 // that were sent out while downloading our resource. These requests
1226 // correspond to the requests that were generated by the browser and the
1227 // downloads system and may change as implementation details change.
1228 TestDownloadRequestHandler::CompletedRequests requests;
1229 request_handler.GetCompletedRequestInfo(&requests);
1230
1231 ASSERT_EQ(3u, requests.size());
1232
1233 // None of the request should have transferred the entire resource. The
1234 // redirect response shows up as a response with 0 bytes transferred.
1235 EXPECT_GT(parameters.size, requests[0].transferred_byte_count);
1236 EXPECT_EQ(0, requests[1].transferred_byte_count);
1237 EXPECT_GT(parameters.size, requests[2].transferred_byte_count);
1238 }
1239
1240 // If the server response for the resumption request specifies a bad range (i.e.
1241 // not the range that was requested or an invalid or missing Content-Range
1242 // header), then the download should be marked as interrupted again without
1243 // discarding the partial state.
1244 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, BadRangeHeader) {
1245 TestDownloadRequestHandler request_handler;
1246 TestDownloadRequestHandler::Parameters parameters =
1247 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1248 request_handler.StartServing(parameters);
1249
1250 DownloadItem* download = StartDownloadAndReturnItem(
1251 initiator_shell_for_resumption(), request_handler.url());
1252 WaitForInterrupt(download);
1253
1254 // Upon resumption, the server starts responding with a bad range header.
1255 request_handler.StartServingStaticResponse(
1256 "HTTP/1.1 206 Partial Content\r\n"
1257 "Content-Range: bytes 1000000-2000000/3000000\r\n"
1258 "\r\n");
1259 PrepareToResume();
1260 download->Resume();
1261 WaitForInterrupt(download);
1262 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
1263 download->GetLastReason());
1264
1265 // Or this time, the server sends a response with an invalid Content-Range
1266 // header.
1267 request_handler.StartServingStaticResponse(
1268 "HTTP/1.1 206 Partial Content\r\n"
1269 "Content-Range: ooga-booga-booga-booga\r\n"
1270 "\r\n");
1271 download->Resume();
1272 WaitForInterrupt(download);
1273 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
1274 download->GetLastReason());
1275
1276 // Or no Content-Range header at all.
1277 request_handler.StartServingStaticResponse(
1278 "HTTP/1.1 206 Partial Content\r\n"
1279 "Some-Headers: ooga-booga-booga-booga\r\n"
1280 "\r\n");
1281 download->Resume();
1282 WaitForInterrupt(download);
1283 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_BAD_CONTENT,
1284 download->GetLastReason());
1285
1286 // Back to the original request handler. Resumption should now succeed, and
1287 // use the partial data it had prior to the first interruption.
1288 request_handler.StartServing(parameters);
1289 download->Resume();
1290 WaitForCompletion(download);
1291
1292 ASSERT_EQ(parameters.size, download->GetReceivedBytes());
1293 ASSERT_EQ(parameters.size, download->GetTotalBytes());
1294 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents(
1295 parameters.pattern_generator_seed, parameters.size,
1296 download->GetTargetFilePath()));
1297
1298 // Characterization risk: The next portion of the test examines the requests
1299 // that were sent out while downloading our resource. These requests
1300 // correspond to the requests that were generated by the browser and the
1301 // downloads system and may change as implementation details change.
1302 TestDownloadRequestHandler::CompletedRequests requests;
1303 request_handler.GetCompletedRequestInfo(&requests);
1304
1305 ASSERT_EQ(5u, requests.size());
1306
1307 // None of the request should have transferred the entire resource.
1308 EXPECT_GT(parameters.size, requests[0].transferred_byte_count);
1309 EXPECT_EQ(0, requests[1].transferred_byte_count);
1310 EXPECT_EQ(0, requests[2].transferred_byte_count);
1311 EXPECT_EQ(0, requests[3].transferred_byte_count);
1312 EXPECT_GT(parameters.size, requests[4].transferred_byte_count);
1313 }
1314
1124 // A partial resumption results in an HTTP 200 response. I.e. the server ignored 1315 // A partial resumption results in an HTTP 200 response. I.e. the server ignored
1125 // the range request and sent the entire resource instead. For If-Range requests 1316 // the range request and sent the entire resource instead. For If-Range requests
1126 // (as opposed to If-Match), the behavior for a precondition failure is also to 1317 // (as opposed to If-Match), the behavior for a precondition failure is also to
1127 // respond with a 200. So this test case covers both validation failure and 1318 // respond with a 200. So this test case covers both validation failure and
1128 // ignoring the range request. 1319 // ignoring the range request.
1129 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, 1320 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest,
1130 RestartIfNotPartialResponse) { 1321 RestartIfNotPartialResponse) {
1131 const int kOriginalPatternGeneratorSeed = 1; 1322 const int kOriginalPatternGeneratorSeed = 1;
1132 const int kNewPatternGeneratorSeed = 2; 1323 const int kNewPatternGeneratorSeed = 2;
1133 1324
(...skipping 676 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 2001
1811 std::vector<DownloadItem*> downloads; 2002 std::vector<DownloadItem*> downloads;
1812 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2003 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
1813 ASSERT_EQ(1u, downloads.size()); 2004 ASSERT_EQ(1u, downloads.size());
1814 2005
1815 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2006 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
1816 downloads[0]->GetTargetFilePath().BaseName().value()); 2007 downloads[0]->GetTargetFilePath().BaseName().value());
1817 } 2008 }
1818 2009
1819 } // namespace content 2010 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698