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

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

Issue 2783473002: Fix issues and feature polishing for parallel download. (Closed)
Patch Set: Rebase. 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 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 EXPECT_EQ(slice4, slices[1]); 81 EXPECT_EQ(slice4, slices[1]);
82 82
83 // A new slice can only merge with an existing slice earlier in the file, not 83 // A new slice can only merge with an existing slice earlier in the file, not
84 // later in the file. 84 // later in the file.
85 DownloadItem::ReceivedSlice slice5(50, 50); 85 DownloadItem::ReceivedSlice slice5(50, 50);
86 EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice5, slices)); 86 EXPECT_EQ(0u, AddOrMergeReceivedSliceIntoSortedArray(slice5, slices));
87 EXPECT_EQ(3u, slices.size()); 87 EXPECT_EQ(3u, slices.size());
88 EXPECT_EQ(0, slices[0].offset); 88 EXPECT_EQ(0, slices[0].offset);
89 EXPECT_EQ(100, slices[0].received_bytes); 89 EXPECT_EQ(100, slices[0].received_bytes);
90 EXPECT_EQ(slice4, slices[1]); 90 EXPECT_EQ(slice4, slices[1]);
91 }
91 92
93 // Ensure the minimum slice size is correctly applied.
94 TEST(ParallelDownloadUtilsTest, FindSlicesForRemainingContentMinSliceSize) {
95 // Minimum slice size is smaller than total length, only one slice returned.
96 DownloadItem::ReceivedSlices slices =
97 FindSlicesForRemainingContent(0, 100, 3, 150);
98 EXPECT_EQ(1u, slices.size());
99 EXPECT_EQ(0, slices[0].offset);
100 EXPECT_EQ(0, slices[0].received_bytes);
101
102 // Request count is large, the minimum slice size should limit the number of
103 // slices returned.
104 slices = FindSlicesForRemainingContent(0, 100, 33, 50);
105 EXPECT_EQ(2u, slices.size());
106 EXPECT_EQ(0, slices[0].offset);
107 EXPECT_EQ(50, slices[0].received_bytes);
108 EXPECT_EQ(50, slices[1].offset);
109 EXPECT_EQ(0, slices[1].received_bytes);
110
111 // Can chunk 2 slices under minimum slice size, but request count is only 1,
112 // request count should win.
113 slices = FindSlicesForRemainingContent(0, 100, 1, 50);
114 EXPECT_EQ(1u, slices.size());
115 EXPECT_EQ(0, slices[0].offset);
116 EXPECT_EQ(0, slices[0].received_bytes);
117
118 // A total 100 bytes data and a 51 bytes minimum slice size, only one slice is
119 // returned.
120 slices = FindSlicesForRemainingContent(0, 100, 3, 51);
121 EXPECT_EQ(1u, slices.size());
122 EXPECT_EQ(0, slices[0].offset);
123 EXPECT_EQ(0, slices[0].received_bytes);
92 } 124 }
93 125
94 } // namespace content 126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698