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

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

Issue 2737033002: Update the received slices vector when stream is written to disk (Closed)
Patch Set: fix unit test 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 {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 downloaded_slices.erase(downloaded_slices.begin()); 48 downloaded_slices.erase(downloaded_slices.begin());
49 slices_to_download = FindSlicesToDownload(downloaded_slices); 49 slices_to_download = FindSlicesToDownload(downloaded_slices);
50 EXPECT_EQ(2u, slices_to_download.size()); 50 EXPECT_EQ(2u, slices_to_download.size());
51 EXPECT_EQ(0, slices_to_download[0].offset); 51 EXPECT_EQ(0, slices_to_download[0].offset);
52 EXPECT_EQ(500, slices_to_download[0].received_bytes); 52 EXPECT_EQ(500, slices_to_download[0].received_bytes);
53 EXPECT_EQ(1500, slices_to_download[1].offset); 53 EXPECT_EQ(1500, slices_to_download[1].offset);
54 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, 54 EXPECT_EQ(DownloadSaveInfo::kLengthFullContent,
55 slices_to_download[1].received_bytes); 55 slices_to_download[1].received_bytes);
56 } 56 }
57 57
58 TEST(ParallelDownloadUtilsTest, AddOrMergeReceivedSliceIntoSortedArray) {
59 std::vector<DownloadItem::ReceivedSlice> slices;
60 DownloadItem::ReceivedSlice slice1(500, 500);
61 EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice1, slices));
62 EXPECT_EQ(1u, slices.size());
63 EXPECT_EQ(slice1, slices[0]);
64
65 // Adding a slice that can be merged with existing slice.
66 DownloadItem::ReceivedSlice slice2(1000, 400);
67 EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice2, slices));
68 EXPECT_EQ(1u, slices.size());
69 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.
70 EXPECT_EQ(900, slices[0].received_bytes);
71
72 DownloadItem::ReceivedSlice slice3(0, 50);
73 EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice3, slices));
74 EXPECT_EQ(2u, slices.size());
75 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
76
77 DownloadItem::ReceivedSlice slice4(100, 50);
78 EXPECT_EQ(1u, AddOrMergeReceivedSliceIntoSortedArray(slice4, slices));
79 EXPECT_EQ(3u, slices.size());
80 EXPECT_EQ(slice3, slices[0]);
81 EXPECT_EQ(slice4, slices[1]);
82
83 // 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.
84 DownloadItem::ReceivedSlice slice5(50, 50);
85 EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice5, slices));
86 EXPECT_EQ(3u, slices.size());
87 EXPECT_EQ(0, slices[0].offset);
88 EXPECT_EQ(100, slices[0].received_bytes);
89 EXPECT_EQ(slice4, slices[1]);
90
91 }
92
58 } // namespace content 93 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698