Chromium Code Reviews| Index: chrome/browser/android/most_visited_sites_unittest.cc |
| diff --git a/chrome/browser/android/most_visited_sites_unittest.cc b/chrome/browser/android/most_visited_sites_unittest.cc |
| index f95918a3308432900c9295978f1308d6a66dd11a..b0befe7cfd5bcbba3ea7b54f9a231d9d8a4a629b 100644 |
| --- a/chrome/browser/android/most_visited_sites_unittest.cc |
| +++ b/chrome/browser/android/most_visited_sites_unittest.cc |
| @@ -12,11 +12,14 @@ |
| namespace { |
| struct TitleURL { |
| - TitleURL(const std::string& title, const std::string& url) |
| - : title(base::UTF8ToUTF16(title)), url(url) {} |
| + TitleURL(const std::string& title, |
| + const std::string& url, |
| + const std::string& source) |
| + : title(base::UTF8ToUTF16(title)), url(url), source(source) {} |
| base::string16 title; |
| std::string url; |
| + std::string source; |
| }; |
| std::vector<base::string16> GetTitles(const std::vector<TitleURL>& data) { |
| @@ -33,6 +36,13 @@ std::vector<std::string> GetURLs(const std::vector<TitleURL>& data) { |
| return urls; |
| } |
| +std::vector<std::string> GetSources(const std::vector<TitleURL>& data) { |
| + std::vector<std::string> sources; |
| + for (const TitleURL& item : data) |
| + sources.push_back(item.source); |
| + return sources; |
| +} |
| + |
| static const int kNumSites = 4; |
| } // namespace |
| @@ -44,34 +54,36 @@ class MostVisitedSitesTest : public testing::Test { |
| const std::vector<TitleURL>& expected) { |
| std::vector<base::string16> titles(GetTitles(personal)); |
| std::vector<std::string> urls(GetURLs(personal)); |
| + std::vector<std::string> sources(GetSources(personal)); |
| std::vector<base::string16> popular_titles(GetTitles(popular)); |
| std::vector<std::string> popular_urls(GetURLs(popular)); |
| MostVisitedSites::AddPopularSitesImpl( |
| - kNumSites, &titles, &urls, popular_titles, popular_urls); |
| + kNumSites, &titles, &urls, &sources, popular_titles, popular_urls); |
| EXPECT_EQ(GetTitles(expected), titles); |
| EXPECT_EQ(GetURLs(expected), urls); |
| + EXPECT_EQ(GetSources(expected), sources); |
| } |
| }; |
| TEST_F(MostVisitedSitesTest, PopularSitesAppend) { |
| TitleURL popular[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| }; |
| TitleURL personal[] = { |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| + TitleURL("Site 3", "https://www.site3.com/", "server8"), |
| + TitleURL("Site 4", "https://www.site4.com/", "server8"), |
| }; |
| // Popular suggestions should keep their positions, with personal suggestions |
| // appended at the end. |
| TitleURL expected[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| + TitleURL("Site 3", "https://www.site3.com/", "server8"), |
| + TitleURL("Site 4", "https://www.site4.com/", "server8"), |
| }; |
| Check(std::vector<TitleURL>(popular, popular + arraysize(popular)), |
| @@ -81,22 +93,22 @@ TEST_F(MostVisitedSitesTest, PopularSitesAppend) { |
| TEST_F(MostVisitedSitesTest, PopularSitesOverflow) { |
| TitleURL popular[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| + TitleURL("Site 3", "https://www.site3.com/", "popular"), |
| }; |
| TitleURL personal[] = { |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| - TitleURL("Site 5", "https://www.site5.com/"), |
| + TitleURL("Site 4", "https://www.site4.com/", "server8"), |
| + TitleURL("Site 5", "https://www.site5.com/", "server8"), |
| }; |
| // When there are more total suggestions than slots, the personal suggestions |
| // should win, with the remaining popular suggestions still retaining their |
| // positions. |
| TitleURL expected[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| - TitleURL("Site 5", "https://www.site5.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| + TitleURL("Site 4", "https://www.site4.com/", "server8"), |
| + TitleURL("Site 5", "https://www.site5.com/", "server8"), |
| }; |
| Check(std::vector<TitleURL>(popular, popular + arraysize(popular)), |
| @@ -106,19 +118,19 @@ TEST_F(MostVisitedSitesTest, PopularSitesOverflow) { |
| TEST_F(MostVisitedSitesTest, PopularSitesOverwrite) { |
| TitleURL popular[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| + TitleURL("Site 3", "https://www.site3.com/", "popular"), |
| }; |
| TitleURL personal[] = { |
| - TitleURL("Site 2 subpage", "https://www.site2.com/path"), |
| + TitleURL("Site 2 subpage", "https://www.site2.com/path", "server8"), |
| }; |
| // When a personal suggestions matches the host of a popular one, it should |
| // overwrite that suggestion (in its original position). |
| TitleURL expected[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2 subpage", "https://www.site2.com/path"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2 subpage", "https://www.site2.com/path", "server8"), |
| + TitleURL("Site 3", "https://www.site3.com/", "popular"), |
| }; |
| Check(std::vector<TitleURL>(popular, popular + arraysize(popular)), |
| @@ -128,24 +140,24 @@ TEST_F(MostVisitedSitesTest, PopularSitesOverwrite) { |
| TEST_F(MostVisitedSitesTest, PopularSitesOrdering) { |
| TitleURL popular[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| + TitleURL("Site 3", "https://www.site3.com/", "popular"), |
| + TitleURL("Site 4", "https://www.site4.com/", "popular"), |
| }; |
| TitleURL personal[] = { |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| + TitleURL("Site 3", "https://www.site3.com/", "server8"), |
| + TitleURL("Site 4", "https://www.site4.com/", "server8"), |
| + TitleURL("Site 1", "https://www.site1.com/", "server8"), |
| + TitleURL("Site 2", "https://www.site2.com/", "server8"), |
| }; |
| - // The order of the popular sites should win (since presumably they were |
| - // there first). |
| + // The personal sites should replace the popular ones, but theorder of the |
|
Bernhard Bauer
2015/08/25 13:55:10
Nit: "the order"
Marc Treib
2015/08/25 14:13:23
Done.
|
| + // popular sites should win (since presumably they were there first). |
| TitleURL expected[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| - TitleURL("Site 4", "https://www.site4.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "server8"), |
| + TitleURL("Site 2", "https://www.site2.com/", "server8"), |
| + TitleURL("Site 3", "https://www.site3.com/", "server8"), |
| + TitleURL("Site 4", "https://www.site4.com/", "server8"), |
| }; |
| Check(std::vector<TitleURL>(popular, popular + arraysize(popular)), |
| @@ -155,24 +167,24 @@ TEST_F(MostVisitedSitesTest, PopularSitesOrdering) { |
| TEST_F(MostVisitedSitesTest, PopularSitesComplex) { |
| TitleURL popular[] = { |
| - TitleURL("Site 1", "https://www.site1.com/"), |
| - TitleURL("Site 2", "https://www.site2.com/"), |
| - TitleURL("Site 3", "https://www.site3.com/"), |
| + TitleURL("Site 1", "https://www.site1.com/", "popular"), |
| + TitleURL("Site 2", "https://www.site2.com/", "popular"), |
| + TitleURL("Site 3", "https://www.site3.com/", "popular"), |
| }; |
| TitleURL personal[] = { |
| - TitleURL("Site 3 subpage", "https://www.site3.com/path"), |
| - TitleURL("Site 1 subpage", "https://www.site1.com/path"), |
| - TitleURL("Site 5", "https://www.site5.com/"), |
| - TitleURL("Site 6", "https://www.site6.com/"), |
| + TitleURL("Site 3 subpage", "https://www.site3.com/path", "server8"), |
| + TitleURL("Site 1 subpage", "https://www.site1.com/path", "server8"), |
| + TitleURL("Site 5", "https://www.site5.com/", "server8"), |
| + TitleURL("Site 6", "https://www.site6.com/", "server8"), |
| }; |
| // Combination of behaviors: Personal suggestions replace matching popular |
| // ones while keeping the position of the popular suggestion. Remaining |
| // personal suggestions evict popular ones and retain their relative order. |
| TitleURL expected[] = { |
| - TitleURL("Site 1 subpage", "https://www.site1.com/path"), |
| - TitleURL("Site 5", "https://www.site5.com/"), |
| - TitleURL("Site 3 subpage", "https://www.site3.com/path"), |
| - TitleURL("Site 6", "https://www.site6.com/"), |
| + TitleURL("Site 1 subpage", "https://www.site1.com/path", "server8"), |
| + TitleURL("Site 5", "https://www.site5.com/", "server8"), |
| + TitleURL("Site 3 subpage", "https://www.site3.com/path", "server8"), |
| + TitleURL("Site 6", "https://www.site6.com/", "server8"), |
| }; |
| Check(std::vector<TitleURL>(popular, popular + arraysize(popular)), |