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

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

Issue 2727143005: Change FindNextSliceToDownload() into FindSlicesToDownload() (Closed)
Patch Set: adding TODO and comments Created 3 years, 9 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 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_utils.h" 5 #include "content/browser/download/parallel_download_utils.h"
6 6
7 #include "content/public/browser/download_save_info.h" 7 #include "content/public/browser/download_save_info.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 TEST(ParallelDownloadUtilsTest, FindNextSliceToDownload) { 12 TEST(ParallelDownloadUtilsTest, FindSlicesToDownload) {
13 std::vector<DownloadItem::ReceivedSlice> slices; 13 std::vector<DownloadItem::ReceivedSlice> downloaded_slices;
14 DownloadItem::ReceivedSlice slice = FindNextSliceToDownload(slices); 14 std::vector<DownloadItem::ReceivedSlice> slices_to_download =
15 EXPECT_EQ(0, slice.offset); 15 FindSlicesToDownload(downloaded_slices);
16 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, slice.received_bytes); 16 EXPECT_EQ(1u, slices_to_download.size());
17 EXPECT_EQ(0, slices_to_download[0].offset);
18 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent,
19 slices_to_download[0].received_bytes);
17 20
18 slices.emplace_back(0, 500); 21 downloaded_slices.emplace_back(0, 500);
19 slice = FindNextSliceToDownload(slices); 22 slices_to_download = FindSlicesToDownload(downloaded_slices);
20 EXPECT_EQ(500, slice.offset); 23 EXPECT_EQ(1u, slices_to_download.size());
21 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, slice.received_bytes); 24 EXPECT_EQ(500, slices_to_download[0].offset);
25 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent,
26 slices_to_download[0].received_bytes);
22 27
23 // Create a gap between slices. 28 // Create a gap between slices.
24 slices.emplace_back(1000, 500); 29 downloaded_slices.emplace_back(1000, 500);
25 slice = FindNextSliceToDownload(slices); 30 slices_to_download = FindSlicesToDownload(downloaded_slices);
26 EXPECT_EQ(500, slice.offset); 31 EXPECT_EQ(2u, slices_to_download.size());
27 EXPECT_EQ(500, slice.received_bytes); 32 EXPECT_EQ(500, slices_to_download[0].offset);
33 EXPECT_EQ(500, slices_to_download[0].received_bytes);
34 EXPECT_EQ(1500, slices_to_download[1].offset);
35 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent,
36 slices_to_download[1].received_bytes);
28 37
29 // Fill the gap. 38 // Fill the gap.
30 slices.emplace(slices.begin() + 1, slice); 39 downloaded_slices.emplace(
31 slice = FindNextSliceToDownload(slices); 40 downloaded_slices.begin() + 1, slices_to_download[0]);
32 EXPECT_EQ(1500, slice.offset); 41 slices_to_download = FindSlicesToDownload(downloaded_slices);
33 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, slice.received_bytes); 42 EXPECT_EQ(1u, slices_to_download.size());
43 EXPECT_EQ(1500, slices_to_download[0].offset);
44 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent,
45 slices_to_download[0].received_bytes);
34 46
35 // Create a new gap at the beginning. 47 // Create a new gap at the beginning.
36 slices.erase(slices.begin()); 48 downloaded_slices.erase(downloaded_slices.begin());
37 slice = FindNextSliceToDownload(slices); 49 slices_to_download = FindSlicesToDownload(downloaded_slices);
38 EXPECT_EQ(0, slice.offset); 50 EXPECT_EQ(2u, slices_to_download.size());
39 EXPECT_EQ(500, slice.received_bytes); 51 EXPECT_EQ(0, slices_to_download[0].offset);
52 EXPECT_EQ(500, slices_to_download[0].received_bytes);
53 EXPECT_EQ(1500, slices_to_download[1].offset);
xingliu 2017/03/03 21:37:44 The last slice returned, e.g. [1500, 0]. How does
qinmin 2017/03/03 22:09:43 Yes, it has to figure it out by itself. This issue
54 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent,
55 slices_to_download[1].received_bytes);
40 } 56 }
41 57
42 } // namespace content 58 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698