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

Unified Diff: components/download/internal/entry_utils_unittest.cc

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Rebased Created 3 years, 7 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
« no previous file with comments | « components/download/internal/entry_utils.cc ('k') | components/download/internal/model.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/download/internal/entry_utils_unittest.cc
diff --git a/components/download/internal/entry_utils_unittest.cc b/components/download/internal/entry_utils_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e914ed9167af5dd85cde8630f321a853a28df9d6
--- /dev/null
+++ b/components/download/internal/entry_utils_unittest.cc
@@ -0,0 +1,65 @@
+// 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 "components/download/internal/entry_utils.h"
+
+#include <algorithm>
+
+#include "base/guid.h"
+#include "base/memory/ptr_util.h"
+#include "components/download/internal/test/entry_utils.h"
+#include "components/download/public/clients.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace download {
+
+TEST(DownloadServiceEntryUtilsTest, TestGetNumberOfEntriesForClient_NoEntries) {
+ Entry entry1 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+ Entry entry2 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+ Entry entry3 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+
+ std::vector<Entry*> entries = {&entry1, &entry2, &entry3};
+
+ EXPECT_EQ(
+ 0U, util::GetNumberOfEntriesForClient(DownloadClient::INVALID, entries));
+ EXPECT_EQ(3U,
+ util::GetNumberOfEntriesForClient(DownloadClient::TEST, entries));
+}
+
+TEST(DownloadServiceEntryUtilsTest, MapEntriesToClients) {
+ Entry entry1 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+ Entry entry2 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+ Entry entry3 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
+
+ std::vector<Entry*> entries = {&entry1, &entry2, &entry3};
+ std::vector<std::string> expected_list = {entry1.guid, entry2.guid,
+ entry3.guid};
+
+ // If DownloadClient::TEST isn't a valid Client, all of the associated entries
+ // should move to the DownloadClient::INVALID bucket.
+ auto mapped1 = util::MapEntriesToClients(std::set<DownloadClient>(), entries);
+ EXPECT_EQ(1U, mapped1.size());
+ EXPECT_NE(mapped1.end(), mapped1.find(DownloadClient::INVALID));
+ EXPECT_EQ(mapped1.end(), mapped1.find(DownloadClient::TEST));
+
+ auto list1 = mapped1.find(DownloadClient::INVALID)->second;
+ EXPECT_EQ(3U, list1.size());
+ EXPECT_TRUE(
+ std::equal(expected_list.begin(), expected_list.end(), list1.begin()));
+
+ // If DownloadClient::TEST is a valid Client, it should have the associated
+ // entries.
+ std::set<DownloadClient> clients = {DownloadClient::TEST};
+ auto mapped2 = util::MapEntriesToClients(clients, entries);
+ EXPECT_EQ(1U, mapped2.size());
+ EXPECT_NE(mapped2.end(), mapped2.find(DownloadClient::TEST));
+ EXPECT_EQ(mapped2.end(), mapped2.find(DownloadClient::INVALID));
+
+ auto list2 = mapped2.find(DownloadClient::TEST)->second;
+ EXPECT_EQ(3U, list2.size());
+ EXPECT_TRUE(
+ std::equal(expected_list.begin(), expected_list.end(), list2.begin()));
+}
+
+} // namespace download
« no previous file with comments | « components/download/internal/entry_utils.cc ('k') | components/download/internal/model.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698