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

Side by Side Diff: components/ntp_tiles/most_visited_sites_unittest.cc

Issue 2069263003: MostVisitedSites cleanup: kill SuggestionsPtrVector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 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/ntp_tiles/most_visited_sites.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/ntp_tiles/most_visited_sites.h" 5 #include "components/ntp_tiles/most_visited_sites.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 // - Removing blacklisted suggestions. 43 // - Removing blacklisted suggestions.
44 // - Correct host extraction from the URL. 44 // - Correct host extraction from the URL.
45 // - Ensuring personal suggestions are not duplicated in popular suggestions. 45 // - Ensuring personal suggestions are not duplicated in popular suggestions.
46 class MostVisitedSitesTest : public testing::Test { 46 class MostVisitedSitesTest : public testing::Test {
47 protected: 47 protected:
48 void Check(const std::vector<TitleURL>& popular_sites, 48 void Check(const std::vector<TitleURL>& popular_sites,
49 const std::vector<TitleURL>& whitelist_entry_points, 49 const std::vector<TitleURL>& whitelist_entry_points,
50 const std::vector<TitleURL>& personal_sites, 50 const std::vector<TitleURL>& personal_sites,
51 const std::vector<bool>& expected_sites_is_personal, 51 const std::vector<bool>& expected_sites_is_personal,
52 const std::vector<TitleURL>& expected_sites) { 52 const std::vector<TitleURL>& expected_sites) {
53 MostVisitedSites::SuggestionsPtrVector personal_suggestions; 53 MostVisitedSites::SuggestionsVector personal_suggestions;
54 for (const TitleURL& site : personal_sites) 54 for (const TitleURL& site : personal_sites)
55 personal_suggestions.push_back(MakeSuggestionFrom(site, true, false)); 55 personal_suggestions.push_back(MakeSuggestionFrom(site, true, false));
56 MostVisitedSites::SuggestionsPtrVector whitelist_suggestions; 56 MostVisitedSites::SuggestionsVector whitelist_suggestions;
57 for (const TitleURL& site : whitelist_entry_points) 57 for (const TitleURL& site : whitelist_entry_points)
58 whitelist_suggestions.push_back(MakeSuggestionFrom(site, false, true)); 58 whitelist_suggestions.push_back(MakeSuggestionFrom(site, false, true));
59 MostVisitedSites::SuggestionsPtrVector popular_suggestions; 59 MostVisitedSites::SuggestionsVector popular_suggestions;
60 for (const TitleURL& site : popular_sites) 60 for (const TitleURL& site : popular_sites)
61 popular_suggestions.push_back(MakeSuggestionFrom(site, false, false)); 61 popular_suggestions.push_back(MakeSuggestionFrom(site, false, false));
62 MostVisitedSites::SuggestionsPtrVector result_suggestions = 62 MostVisitedSites::SuggestionsVector result_suggestions =
63 MostVisitedSites::MergeSuggestions(&personal_suggestions, 63 MostVisitedSites::MergeSuggestions(std::move(personal_suggestions),
64 &whitelist_suggestions, 64 std::move(whitelist_suggestions),
65 &popular_suggestions); 65 std::move(popular_suggestions));
66 std::vector<TitleURL> result_sites; 66 std::vector<TitleURL> result_sites;
67 std::vector<bool> result_is_personal; 67 std::vector<bool> result_is_personal;
68 result_sites.reserve(result_suggestions.size()); 68 result_sites.reserve(result_suggestions.size());
69 result_is_personal.reserve(result_suggestions.size()); 69 result_is_personal.reserve(result_suggestions.size());
70 for (const auto& suggestion : result_suggestions) { 70 for (const auto& suggestion : result_suggestions) {
71 result_sites.push_back( 71 result_sites.push_back(TitleURL(suggestion.title, suggestion.url.spec()));
72 TitleURL(suggestion->title, suggestion->url.spec())); 72 result_is_personal.push_back(suggestion.source !=
73 result_is_personal.push_back(suggestion->source !=
74 MostVisitedSites::POPULAR); 73 MostVisitedSites::POPULAR);
75 } 74 }
76 EXPECT_EQ(expected_sites_is_personal, result_is_personal); 75 EXPECT_EQ(expected_sites_is_personal, result_is_personal);
77 EXPECT_EQ(expected_sites, result_sites); 76 EXPECT_EQ(expected_sites, result_sites);
78 } 77 }
79 static std::unique_ptr<MostVisitedSites::Suggestion> MakeSuggestionFrom( 78 static MostVisitedSites::Suggestion MakeSuggestionFrom(
80 const TitleURL& title_url, 79 const TitleURL& title_url,
81 bool is_personal, 80 bool is_personal,
82 bool whitelist) { 81 bool whitelist) {
83 std::unique_ptr<MostVisitedSites::Suggestion> suggestion = 82 MostVisitedSites::Suggestion suggestion;
84 base::WrapUnique(new MostVisitedSites::Suggestion()); 83 suggestion.title = title_url.title;
85 suggestion->title = title_url.title; 84 suggestion.url = GURL(title_url.url);
86 suggestion->url = GURL(title_url.url); 85 suggestion.source = whitelist ? MostVisitedSites::WHITELIST
87 suggestion->source = whitelist ? MostVisitedSites::WHITELIST 86 : (is_personal ? MostVisitedSites::TOP_SITES
88 : (is_personal ? MostVisitedSites::TOP_SITES 87 : MostVisitedSites::POPULAR);
89 : MostVisitedSites::POPULAR);
90 return suggestion; 88 return suggestion;
91 } 89 }
92 }; 90 };
93 91
94 TEST_F(MostVisitedSitesTest, PersonalSites) { 92 TEST_F(MostVisitedSitesTest, PersonalSites) {
95 std::vector<TitleURL> personal_sites{ 93 std::vector<TitleURL> personal_sites{
96 TitleURL("Site 1", "https://www.site1.com/"), 94 TitleURL("Site 1", "https://www.site1.com/"),
97 TitleURL("Site 2", "https://www.site2.com/"), 95 TitleURL("Site 2", "https://www.site2.com/"),
98 TitleURL("Site 3", "https://www.site3.com/"), 96 TitleURL("Site 3", "https://www.site3.com/"),
99 TitleURL("Site 4", "https://www.site4.com/"), 97 TitleURL("Site 4", "https://www.site4.com/"),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 TitleURL("Site 4", "https://www.site4.com/"), 132 TitleURL("Site 4", "https://www.site4.com/"),
135 TitleURL("Site 1", "https://www.site1.com/"), 133 TitleURL("Site 1", "https://www.site1.com/"),
136 TitleURL("Site 2", "https://www.site2.com/"), 134 TitleURL("Site 2", "https://www.site2.com/"),
137 }; 135 };
138 std::vector<bool> expected_sites_source{true, true, false, false}; 136 std::vector<bool> expected_sites_source{true, true, false, false};
139 Check(popular_sites, std::vector<TitleURL>(), personal_sites, 137 Check(popular_sites, std::vector<TitleURL>(), personal_sites,
140 expected_sites_source, expected_sites); 138 expected_sites_source, expected_sites);
141 } 139 }
142 140
143 } // namespace ntp_tiles 141 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/most_visited_sites.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698