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

Unified Diff: content/browser/download/parallel_download_utils_unittest.cc

Issue 2728673003: Add a utility function to calculate the next slice to download (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
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
new file mode 100644
index 0000000000000000000000000000000000000000..5282454d5d9e7e44775cf43110a0f4109f9cd972
--- /dev/null
+++ b/content/browser/download/parallel_download_utils_unittest.cc
@@ -0,0 +1,36 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/download/parallel_download_utils.h"
+
+#include "content/public/browser/download_save_info.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+TEST(ParallelDownloadUtilsTest, FindNextSliceToDownload) {
+ std::vector<DownloadItem::ReceivedSlice> slices;
+ DownloadItem::ReceivedSlice slice = FindNextSliceToDownload(slices);
+ EXPECT_EQ(0, slice.offset);
+ EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, slice.received_bytes);
+
+ slices.emplace_back(0, 500);
+ slice = FindNextSliceToDownload(slices);
+ EXPECT_EQ(500, slice.offset);
+ EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, slice.received_bytes);
+
+ // Create a gap between slices.
+ slices.emplace_back(1000, 500);
+ slice = FindNextSliceToDownload(slices);
+ EXPECT_EQ(500, slice.offset);
+ EXPECT_EQ(500, slice.received_bytes);
+
+ // Fill the gap.
+ slices.emplace(slices.begin() + 1, slice);
+ slice = FindNextSliceToDownload(slices);
+ EXPECT_EQ(1500, slice.offset);
+ EXPECT_EQ(DownloadSaveInfo::kLengthFullContent, slice.received_bytes);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698