Chromium Code Reviews| Index: content/browser/download/parallel_download_utils_unittest.cc |
| diff --git a/content/browser/download/parallel_download_utils_unittest.cc b/content/browser/download/parallel_download_utils_unittest.cc |
| index f6c52a9e38aa4fcf5b5af50000ad280e2efa3472..e978a5725614175408aeb1a66ebf15a96b2410a0 100644 |
| --- a/content/browser/download/parallel_download_utils_unittest.cc |
| +++ b/content/browser/download/parallel_download_utils_unittest.cc |
| @@ -55,4 +55,39 @@ TEST(ParallelDownloadUtilsTest, FindSlicesToDownload) { |
| slices_to_download[1].received_bytes); |
| } |
| +TEST(ParallelDownloadUtilsTest, AddOrMergeReceivedSliceIntoSortedArray) { |
| + std::vector<DownloadItem::ReceivedSlice> slices; |
| + DownloadItem::ReceivedSlice slice1(500, 500); |
| + EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice1, slices)); |
| + EXPECT_EQ(1u, slices.size()); |
| + EXPECT_EQ(slice1, slices[0]); |
| + |
| + // Adding a slice that can be merged with existing slice. |
| + DownloadItem::ReceivedSlice slice2(1000, 400); |
| + EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice2, slices)); |
| + EXPECT_EQ(1u, slices.size()); |
| + EXPECT_EQ(500, slices[0].offset); |
|
David Trainor- moved to gerrit
2017/03/09 17:44:03
EXPECT_EQ(slice1, slices[0])?
qinmin
2017/03/09 21:44:58
No, they are not equal. slice1 is (500, 1000), sli
David Trainor- moved to gerrit
2017/03/14 15:07:31
Ah yeah thanks! I forgot the merge somehow :D.
|
| + EXPECT_EQ(900, slices[0].received_bytes); |
| + |
| + DownloadItem::ReceivedSlice slice3(0, 50); |
| + EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice3, slices)); |
| + EXPECT_EQ(2u, slices.size()); |
| + EXPECT_EQ(slice3, slices[0]); |
|
David Trainor- moved to gerrit
2017/03/09 17:44:02
EXPECT_EQ(slice1, slices[1])?
qinmin
2017/03/09 21:44:58
same as above
|
| + |
| + DownloadItem::ReceivedSlice slice4(100, 50); |
| + EXPECT_EQ(1u, AddOrMergeReceivedSliceIntoSortedArray(slice4, slices)); |
| + EXPECT_EQ(3u, slices.size()); |
| + EXPECT_EQ(slice3, slices[0]); |
| + EXPECT_EQ(slice4, slices[1]); |
| + |
| + // A new slice can only merge with a slice in front of it, not behind it. |
|
David Trainor- moved to gerrit
2017/03/09 17:44:02
Is the comment flipped?
qinmin
2017/03/09 21:44:58
no, this is correct.
A new slice (50, 100) can on
David Trainor- moved to gerrit
2017/03/14 15:07:31
I think the wording regarding in front of and behi
qinmin
2017/03/14 18:32:39
Done.
|
| + DownloadItem::ReceivedSlice slice5(50, 50); |
| + EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice5, slices)); |
| + EXPECT_EQ(3u, slices.size()); |
| + EXPECT_EQ(0, slices[0].offset); |
| + EXPECT_EQ(100, slices[0].received_bytes); |
| + EXPECT_EQ(slice4, slices[1]); |
| + |
| +} |
| + |
| } // namespace content |