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

Side by Side Diff: components/download/internal/entry_utils_unittest.cc

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Rebased Created 3 years, 6 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
« no previous file with comments | « components/download/internal/entry_utils.cc ('k') | components/download/internal/model.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "components/download/internal/entry_utils.h"
6
7 #include <algorithm>
8
9 #include "base/guid.h"
10 #include "base/memory/ptr_util.h"
11 #include "components/download/internal/test/entry_utils.h"
12 #include "components/download/public/clients.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace download {
16
17 TEST(DownloadServiceEntryUtilsTest, TestGetNumberOfEntriesForClient_NoEntries) {
18 Entry entry1 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
19 Entry entry2 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
20 Entry entry3 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
21
22 std::vector<Entry*> entries = {&entry1, &entry2, &entry3};
23
24 EXPECT_EQ(
25 0U, util::GetNumberOfEntriesForClient(DownloadClient::INVALID, entries));
26 EXPECT_EQ(3U,
27 util::GetNumberOfEntriesForClient(DownloadClient::TEST, entries));
28 }
29
30 TEST(DownloadServiceEntryUtilsTest, MapEntriesToClients) {
31 Entry entry1 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
32 Entry entry2 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
33 Entry entry3 = test::BuildEntry(DownloadClient::TEST, base::GenerateGUID());
34
35 std::vector<Entry*> entries = {&entry1, &entry2, &entry3};
36 std::vector<std::string> expected_list = {entry1.guid, entry2.guid,
37 entry3.guid};
38
39 // If DownloadClient::TEST isn't a valid Client, all of the associated entries
40 // should move to the DownloadClient::INVALID bucket.
41 auto mapped1 = util::MapEntriesToClients(std::set<DownloadClient>(), entries);
42 EXPECT_EQ(1U, mapped1.size());
43 EXPECT_NE(mapped1.end(), mapped1.find(DownloadClient::INVALID));
44 EXPECT_EQ(mapped1.end(), mapped1.find(DownloadClient::TEST));
45
46 auto list1 = mapped1.find(DownloadClient::INVALID)->second;
47 EXPECT_EQ(3U, list1.size());
48 EXPECT_TRUE(
49 std::equal(expected_list.begin(), expected_list.end(), list1.begin()));
50
51 // If DownloadClient::TEST is a valid Client, it should have the associated
52 // entries.
53 std::set<DownloadClient> clients = {DownloadClient::TEST};
54 auto mapped2 = util::MapEntriesToClients(clients, entries);
55 EXPECT_EQ(1U, mapped2.size());
56 EXPECT_NE(mapped2.end(), mapped2.find(DownloadClient::TEST));
57 EXPECT_EQ(mapped2.end(), mapped2.find(DownloadClient::INVALID));
58
59 auto list2 = mapped2.find(DownloadClient::TEST)->second;
60 EXPECT_EQ(3U, list2.size());
61 EXPECT_TRUE(
62 std::equal(expected_list.begin(), expected_list.end(), list2.begin()));
63 }
64
65 } // namespace download
OLDNEW
« 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