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

Unified Diff: chrome/browser/android/most_visited_sites_unittest.cc

Issue 1302363002: Popular sites on the NTP: Extend UMA histograms that track clicks and impressions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@filename_from_finch
Patch Set: asvitkine review Created 5 years, 4 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 | « chrome/browser/android/most_visited_sites.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..f2dc351c6734bfb7f4599e35b513383f8f44688f 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, popular_titles, popular_urls, &titles, &urls, &sources);
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 the order of the
+ // 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)),
« no previous file with comments | « chrome/browser/android/most_visited_sites.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698