Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "content/browser/download/parallel_download_job.h" | 5 #include "content/browser/download/parallel_download_job.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 77 class ParallelDownloadJobTest : public testing::Test { | 77 class ParallelDownloadJobTest : public testing::Test { |
| 78 public: | 78 public: |
| 79 void CreateParallelJob(int64_t initial_request_offset, | 79 void CreateParallelJob(int64_t initial_request_offset, |
| 80 int64_t content_length, | 80 int64_t content_length, |
| 81 const DownloadItem::ReceivedSlices& slices, | 81 const DownloadItem::ReceivedSlices& slices, |
| 82 int request_count, | 82 int request_count, |
| 83 int64_t min_slice_size) { | 83 int64_t min_slice_size) { |
| 84 item_delegate_ = base::MakeUnique<DownloadItemImplDelegate>(); | 84 item_delegate_ = base::MakeUnique<DownloadItemImplDelegate>(); |
| 85 download_item_ = base::MakeUnique<NiceMock<MockDownloadItemImpl>>( | 85 download_item_ = base::MakeUnique<NiceMock<MockDownloadItemImpl>>( |
| 86 item_delegate_.get(), slices); | 86 item_delegate_.get(), slices); |
| 87 EXPECT_CALL(*download_item_, GetTotalBytes()) | |
| 88 .WillRepeatedly( | |
| 89 testing::Return(initial_request_offset + content_length)); | |
| 90 EXPECT_CALL(*download_item_, GetReceivedBytes()) | |
| 91 .WillRepeatedly(testing::Return(initial_request_offset)); | |
| 92 | |
| 87 DownloadCreateInfo info; | 93 DownloadCreateInfo info; |
| 88 info.offset = initial_request_offset; | 94 info.offset = initial_request_offset; |
| 89 info.total_bytes = content_length; | 95 info.total_bytes = content_length; |
| 90 std::unique_ptr<MockDownloadRequestHandle> request_handle = | 96 std::unique_ptr<MockDownloadRequestHandle> request_handle = |
| 91 base::MakeUnique<MockDownloadRequestHandle>(); | 97 base::MakeUnique<MockDownloadRequestHandle>(); |
| 92 mock_request_handle_ = request_handle.get(); | 98 mock_request_handle_ = request_handle.get(); |
| 93 job_ = base::MakeUnique<ParallelDownloadJobForTest>( | 99 job_ = base::MakeUnique<ParallelDownloadJobForTest>( |
| 94 download_item_.get(), std::move(request_handle), info, request_count, | 100 download_item_.get(), std::move(request_handle), info, request_count, |
| 95 min_slice_size); | 101 min_slice_size); |
| 96 } | 102 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 183 // Task 1: Range:44-70, for 27 bytes. | 189 // Task 1: Range:44-70, for 27 bytes. |
| 184 // Task 2: Range:71-, for 29 bytes. | 190 // Task 2: Range:71-, for 29 bytes. |
| 185 DownloadItem::ReceivedSlices slices = {DownloadItem::ReceivedSlice(0, 17)}; | 191 DownloadItem::ReceivedSlices slices = {DownloadItem::ReceivedSlice(0, 17)}; |
| 186 CreateParallelJob(12, 88, slices, 3, 1); | 192 CreateParallelJob(12, 88, slices, 3, 1); |
| 187 BuildParallelRequests(); | 193 BuildParallelRequests(); |
| 188 EXPECT_EQ(2, static_cast<int>(job_->workers().size())); | 194 EXPECT_EQ(2, static_cast<int>(job_->workers().size())); |
| 189 VerifyWorker(44, 27); | 195 VerifyWorker(44, 27); |
| 190 VerifyWorker(71, 0); | 196 VerifyWorker(71, 0); |
| 191 DestroyParallelJob(); | 197 DestroyParallelJob(); |
| 192 | 198 |
| 193 // File size: 100 bytes. | 199 // 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.
| |
| 194 // Received slices: [0, 98], Range:0-97. | 200 // Received slices: [0, 60], Range:0-59. |
| 195 // Original request: Range:98-. Content-length: 2. | 201 // Original request: Range:60-. Content-length: 40. |
| 196 // 2 bytes left for 4 requests. Only 1 additional request. | 202 // 40 bytes left for 4 requests. Only 1 additional request. |
| 197 // Original request: Range:98-99, for 1 bytes. | 203 // Original request: Range:60-79, for 20 bytes. |
| 198 // Task 1: Range:99-, for 1 bytes. | 204 // Task 1: Range:80-, for 20 bytes. |
| 199 slices = {DownloadItem::ReceivedSlice(0, 98)}; | 205 slices = {DownloadItem::ReceivedSlice(0, 60)}; |
| 200 CreateParallelJob(98, 2, slices, 4, 1); | 206 CreateParallelJob(60, 40, slices, 4, 20); |
| 201 BuildParallelRequests(); | 207 BuildParallelRequests(); |
| 202 EXPECT_EQ(1, static_cast<int>(job_->workers().size())); | 208 EXPECT_EQ(1, static_cast<int>(job_->workers().size())); |
| 203 VerifyWorker(99, 0); | 209 VerifyWorker(80, 0); |
| 204 DestroyParallelJob(); | 210 DestroyParallelJob(); |
| 205 | 211 |
| 206 // Content-Length is 0, no additional requests. | 212 // Content-Length is 0, no additional requests. |
| 207 slices = {DownloadItem::ReceivedSlice(0, 100)}; | 213 slices = {DownloadItem::ReceivedSlice(0, 100)}; |
| 208 CreateParallelJob(100, 0, slices, 3, 1); | 214 CreateParallelJob(100, 0, slices, 3, 1); |
| 209 BuildParallelRequests(); | 215 BuildParallelRequests(); |
| 210 EXPECT_TRUE(job_->workers().empty()); | 216 EXPECT_TRUE(job_->workers().empty()); |
| 211 DestroyParallelJob(); | 217 DestroyParallelJob(); |
| 212 | 218 |
| 213 // File size: 100 bytes. | 219 // File size: 100 bytes. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 EXPECT_CALL(*job_.get(), CountOnByteStreamReady()); | 295 EXPECT_CALL(*job_.get(), CountOnByteStreamReady()); |
| 290 std::unique_ptr<MockDownloadRequestHandle> mock_handle = | 296 std::unique_ptr<MockDownloadRequestHandle> mock_handle = |
| 291 base::MakeUnique<MockDownloadRequestHandle>(); | 297 base::MakeUnique<MockDownloadRequestHandle>(); |
| 292 EXPECT_CALL(*mock_handle.get(), PauseRequest()); | 298 EXPECT_CALL(*mock_handle.get(), PauseRequest()); |
| 293 MakeWorkerReady(worker.second.get(), std::move(mock_handle)); | 299 MakeWorkerReady(worker.second.get(), std::move(mock_handle)); |
| 294 } | 300 } |
| 295 | 301 |
| 296 DestroyParallelJob(); | 302 DestroyParallelJob(); |
| 297 } | 303 } |
| 298 | 304 |
| 305 // Test that parallel request is not created if the remaining content can be | |
| 306 // finish downloading soon. | |
| 307 TEST_F(ParallelDownloadJobTest, RemainingContentWillFinishSoon) { | |
| 308 DownloadItem::ReceivedSlices slices = {DownloadItem::ReceivedSlice(0, 99)}; | |
| 309 CreateParallelJob(99, 1, slices, 3, 1); | |
| 310 BuildParallelRequests(); | |
| 311 EXPECT_EQ(0, static_cast<int>(job_->workers().size())); | |
| 312 | |
| 313 DestroyParallelJob(); | |
| 314 } | |
| 315 | |
| 299 } // namespace content | 316 } // namespace content |
| OLD | NEW |