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

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

Issue 1444253003: Use If-Range instead of If-Match/If-Unmodified-Since for partial requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make it obvious that the interrupt reason is obsolete. Created 5 years 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 "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/files/file_path.h" 9 #include "base/files/file_path.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
(...skipping 1163 matching lines...) Expand 10 before | Expand all | Expand 10 after
1174 {DownloadItem::IN_PROGRESS, GetSafeBufferChunk()}, 1174 {DownloadItem::IN_PROGRESS, GetSafeBufferChunk()},
1175 // Notification of receiving whole file. 1175 // Notification of receiving whole file.
1176 {DownloadItem::IN_PROGRESS, 0}, 1176 {DownloadItem::IN_PROGRESS, 0},
1177 // Completion. 1177 // Completion.
1178 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3}, 1178 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3},
1179 }; 1179 };
1180 1180
1181 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record)); 1181 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record));
1182 } 1182 }
1183 1183
1184 // Confirm restart fallback happens if a precondition is failed.
1185 IN_PROC_BROWSER_TEST_F(DownloadContentTest,
1186 ResumeInterruptedDownloadBadPrecondition) {
1187 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1188 switches::kEnableDownloadResumption);
1189 ASSERT_TRUE(spawned_test_server()->Start());
1190
1191 GURL url = spawned_test_server()->GetURL(base::StringPrintf(
1192 // First download hits an RST, rest don't, precondition fail.
1193 "rangereset?size=%d&rst_boundary=%d&"
1194 "token=BadPrecondition&rst_limit=1&fail_precondition=2",
1195 GetSafeBufferChunk() * 3, GetSafeBufferChunk()));
1196
1197 // Start the download and wait for first data chunk.
1198 DownloadItem* download(StartDownloadAndReturnItem(url));
1199 WaitForData(download, GetSafeBufferChunk());
1200
1201 RecordingDownloadObserver recorder(download);
1202
1203 ReleaseRSTAndConfirmInterruptForResume(download);
1204 ConfirmFileStatusForResume(
1205 download, true, GetSafeBufferChunk(), GetSafeBufferChunk() * 3,
1206 base::FilePath(FILE_PATH_LITERAL("rangereset.crdownload")));
1207 EXPECT_EQ("BadPrecondition2", download->GetETag());
1208
1209 DownloadUpdatedObserver completion_observer(
1210 download, base::Bind(DownloadCompleteFilter));
1211 download->Resume();
1212 completion_observer.WaitForEvent();
1213
1214 ConfirmFileStatusForResume(
1215 download, true, GetSafeBufferChunk() * 3, GetSafeBufferChunk() * 3,
1216 base::FilePath(FILE_PATH_LITERAL("rangereset")));
1217 EXPECT_EQ("BadPrecondition0", download->GetETag());
1218
1219 static const RecordingDownloadObserver::RecordStruct expected_record[] = {
1220 // Result of RST
1221 {DownloadItem::INTERRUPTED, GetSafeBufferChunk()},
1222 // Starting continuation
1223 {DownloadItem::IN_PROGRESS, GetSafeBufferChunk()},
1224 // Server precondition fail.
1225 {DownloadItem::INTERRUPTED, 0},
1226 // Notification of successful restart.
1227 {DownloadItem::IN_PROGRESS, 0},
1228 // Completion.
1229 {DownloadItem::COMPLETE, GetSafeBufferChunk() * 3},
1230 };
1231
1232 recorder.CompareToExpectedRecord(expected_record, arraysize(expected_record));
1233 }
1234
1235 // Confirm we don't try to resume if we don't have a verifier. 1184 // Confirm we don't try to resume if we don't have a verifier.
1236 IN_PROC_BROWSER_TEST_F(DownloadContentTest, 1185 IN_PROC_BROWSER_TEST_F(DownloadContentTest,
1237 ResumeInterruptedDownloadNoVerifiers) { 1186 ResumeInterruptedDownloadNoVerifiers) {
1238 base::CommandLine::ForCurrentProcess()->AppendSwitch( 1187 base::CommandLine::ForCurrentProcess()->AppendSwitch(
1239 switches::kEnableDownloadResumption); 1188 switches::kEnableDownloadResumption);
1240 ASSERT_TRUE(spawned_test_server()->Start()); 1189 ASSERT_TRUE(spawned_test_server()->Start());
1241 1190
1242 GURL url = spawned_test_server()->GetURL(base::StringPrintf( 1191 GURL url = spawned_test_server()->GetURL(base::StringPrintf(
1243 // First download hits an RST, rest don't, no verifiers. 1192 // First download hits an RST, rest don't, no verifiers.
1244 "rangereset?size=%d&rst_boundary=%d&" 1193 "rangereset?size=%d&rst_boundary=%d&"
(...skipping 570 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 1764
1816 std::vector<DownloadItem*> downloads; 1765 std::vector<DownloadItem*> downloads;
1817 DownloadManagerForShell(shell())->GetAllDownloads(&downloads); 1766 DownloadManagerForShell(shell())->GetAllDownloads(&downloads);
1818 ASSERT_EQ(1u, downloads.size()); 1767 ASSERT_EQ(1u, downloads.size());
1819 1768
1820 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"), 1769 EXPECT_EQ(FILE_PATH_LITERAL("Jumboshrimp.txt"),
1821 downloads[0]->GetTargetFilePath().BaseName().value()); 1770 downloads[0]->GetTargetFilePath().BaseName().value());
1822 } 1771 }
1823 1772
1824 } // namespace content 1773 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698