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

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, 10 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 1176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1187
1188 PrepareToResume(); 1188 PrepareToResume();
1189 download->Resume(); 1189 download->Resume();
1190 WaitForCompletion(download); 1190 WaitForCompletion(download);
1191 1191
1192 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents( 1192 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents(
1193 parameters.pattern_generator_seed, parameters.size, 1193 parameters.pattern_generator_seed, parameters.size,
1194 download->GetTargetFilePath())); 1194 download->GetTargetFilePath()));
1195 } 1195 }
1196 1196
1197 // If a resumption request results in a redirect, the response should be ignored
1198 // and the download should be marked as interrupted again.
1199 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, RedirectWhileResume) {
1200 TestDownloadRequestHandler request_handler(
1201 GURL("http://example.com/first-url"));
1202 TestDownloadRequestHandler::Parameters parameters =
1203 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1204 ++parameters.pattern_generator_seed;
1205 request_handler.StartServing(parameters);
1206
1207 // We should never send a request to the decoy. If we do, the request will
1208 // always succeed, which results in behavior that diverges from what we want,
1209 // which is for the download to return to being interrupted.
1210 TestDownloadRequestHandler decoy_request_handler(
1211 GURL("http://example.com/decoy"));
1212 decoy_request_handler.StartServing(TestDownloadRequestHandler::Parameters());
1213
1214 DownloadItem* download = StartDownloadAndReturnItem(
1215 initiator_shell_for_resumption(), request_handler.url());
1216 WaitForInterrupt(download);
1217
1218 // Upon resumption, the server starts responding with a redirect. This
1219 // response should not be accepted.
1220 request_handler.StartServingStaticResponse(
1221 "HTTP/1.1 302 Redirect\r\n"
1222 "Location: http://example.com/decoy\r\n"
1223 "\r\n");
1224 PrepareToResume();
1225 download->Resume();
1226 WaitForInterrupt(download);
1227 EXPECT_EQ(DOWNLOAD_INTERRUPT_REASON_SERVER_UNREACHABLE,
1228 download->GetLastReason());
1229
1230 // Back to the original request handler. Resumption should now succeed, and
1231 // use the partial data it had prior to the first interruption.
1232 request_handler.StartServing(parameters);
1233 download->Resume();
1234 WaitForCompletion(download);
1235
1236 ASSERT_EQ(parameters.size, download->GetReceivedBytes());
1237 ASSERT_EQ(parameters.size, download->GetTotalBytes());
1238 ASSERT_NO_FATAL_FAILURE(ReadAndVerifyFileContents(
1239 parameters.pattern_generator_seed, parameters.size,
1240 download->GetTargetFilePath()));
1241
1242 // Characterization risk: The next portion of the test examines the requests
1243 // that were sent out while downloading our resource. These requests
1244 // correspond to the requests that were generated by the browser and the
1245 // downloads system and may change as implementation details change.
1246 TestDownloadRequestHandler::CompletedRequests requests;
1247 request_handler.GetCompletedRequestInfo(&requests);
1248
1249 ASSERT_EQ(3u, requests.size());
1250
1251 // None of the request should have transferred the entire resource. The
1252 // redirect response shows up as a response with 0 bytes transferred.
1253 EXPECT_GT(parameters.size, requests[0].transferred_byte_count);
1254 EXPECT_EQ(0, requests[1].transferred_byte_count);
1255 EXPECT_GT(parameters.size, requests[2].transferred_byte_count);
1256 }
1257
1197 // If the server response for the resumption request specifies a bad range (i.e. 1258 // If the server response for the resumption request specifies a bad range (i.e.
1198 // not the range that was requested or an invalid or missing Content-Range 1259 // not the range that was requested or an invalid or missing Content-Range
1199 // header), then the download should be marked as interrupted again without 1260 // header), then the download should be marked as interrupted again without
1200 // discarding the partial state. 1261 // discarding the partial state.
1201 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, BadRangeHeader) { 1262 IN_PROC_BROWSER_TEST_P(DownloadResumptionContentTest, BadRangeHeader) {
1202 TestDownloadRequestHandler request_handler; 1263 TestDownloadRequestHandler request_handler;
1203 TestDownloadRequestHandler::Parameters parameters = 1264 TestDownloadRequestHandler::Parameters parameters =
1204 TestDownloadRequestHandler::Parameters::WithSingleInterruption(); 1265 TestDownloadRequestHandler::Parameters::WithSingleInterruption();
1205 request_handler.StartServing(parameters); 1266 request_handler.StartServing(parameters);
1206 1267
(...skipping 869 matching lines...) Expand 10 before | Expand all | Expand 10 after
2076 2137
2077 std::vector<DownloadItem*> downloads; 2138 std::vector<DownloadItem*> downloads;
2078 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 2139 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
2079 ASSERT_EQ(1u, downloads.size()); 2140 ASSERT_EQ(1u, downloads.size());
2080 2141
2081 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 2142 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
2082 downloads[0]->GetTargetFilePath().BaseName().value()); 2143 downloads[0]->GetTargetFilePath().BaseName().value());
2083 } 2144 }
2084 2145
2085 } // namespace content 2146 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698