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

Unified Diff: content/browser/download/parallel_download_job_unittest.cc

Issue 2806923002: Don't create parallel request if download is about to complete (Closed)
Patch Set: Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/download/parallel_download_job_unittest.cc
diff --git a/content/browser/download/parallel_download_job_unittest.cc b/content/browser/download/parallel_download_job_unittest.cc
index de6da07deda379c106927e458ac183375c69ee02..9fa7646553e80f24c18e9a5dbc880773a1fad949 100644
--- a/content/browser/download/parallel_download_job_unittest.cc
+++ b/content/browser/download/parallel_download_job_unittest.cc
@@ -84,6 +84,12 @@ class ParallelDownloadJobTest : public testing::Test {
item_delegate_ = base::MakeUnique<DownloadItemImplDelegate>();
download_item_ = base::MakeUnique<NiceMock<MockDownloadItemImpl>>(
item_delegate_.get(), slices);
+ EXPECT_CALL(*download_item_, GetTotalBytes())
+ .WillRepeatedly(
+ testing::Return(initial_request_offset + content_length));
+ EXPECT_CALL(*download_item_, GetReceivedBytes())
+ .WillRepeatedly(testing::Return(initial_request_offset));
+
DownloadCreateInfo info;
info.offset = initial_request_offset;
info.total_bytes = content_length;
@@ -191,16 +197,16 @@ TEST_F(ParallelDownloadJobTest, CreateNewDownloadRequestsWithSlices) {
DestroyParallelJob();
// File size: 100 bytes.
xingliu 2017/04/08 02:21:05 nit: Can we add a TODO here to pass the minimum re
qinmin 2017/04/10 19:04:48 Done.
- // Received slices: [0, 98], Range:0-97.
- // Original request: Range:98-. Content-length: 2.
- // 2 bytes left for 4 requests. Only 1 additional request.
- // Original request: Range:98-99, for 1 bytes.
- // Task 1: Range:99-, for 1 bytes.
- slices = {DownloadItem::ReceivedSlice(0, 98)};
- CreateParallelJob(98, 2, slices, 4, 1);
+ // Received slices: [0, 60], Range:0-59.
+ // Original request: Range:60-. Content-length: 40.
+ // 40 bytes left for 4 requests. Only 1 additional request.
+ // Original request: Range:60-79, for 20 bytes.
+ // Task 1: Range:80-, for 20 bytes.
+ slices = {DownloadItem::ReceivedSlice(0, 60)};
+ CreateParallelJob(60, 40, slices, 4, 20);
BuildParallelRequests();
EXPECT_EQ(1, static_cast<int>(job_->workers().size()));
- VerifyWorker(99, 0);
+ VerifyWorker(80, 0);
DestroyParallelJob();
// Content-Length is 0, no additional requests.
@@ -296,4 +302,15 @@ TEST_F(ParallelDownloadJobTest, EarlyPauseBeforeByteStreamReady) {
DestroyParallelJob();
}
+// Test that parallel request is not created if the remaining content can be
+// finish downloading soon.
+TEST_F(ParallelDownloadJobTest, RemainingContentWillFinishSoon) {
+ DownloadItem::ReceivedSlices slices = {DownloadItem::ReceivedSlice(0, 99)};
+ CreateParallelJob(99, 1, slices, 3, 1);
+ BuildParallelRequests();
+ EXPECT_EQ(0, static_cast<int>(job_->workers().size()));
+
+ DestroyParallelJob();
+}
+
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698