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

Side by Side Diff: chrome/browser/android/preferences/important_sites_util_unittest.cc

Issue 2367153002: [ImportantSites] Limiting the # of Bookmark signals (Closed)
Patch Set: Changed constant to 5 as per product discussion Created 4 years, 2 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 | « chrome/browser/android/preferences/important_sites_util.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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "chrome/browser/android/preferences/important_sites_util.h" 5 #include "chrome/browser/android/preferences/important_sites_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 AddBookmark(url1); 178 AddBookmark(url1);
179 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( 179 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
180 profile(), kNumImportantSites); 180 profile(), kNumImportantSites);
181 expected_sorted_domains = {"youtube.com", "google.com", "foo.bar", 181 expected_sorted_domains = {"youtube.com", "google.com", "foo.bar",
182 "example.com", "chrome.com"}; 182 "example.com", "chrome.com"};
183 expected_sorted_origins = {url6, url3, url7, url5, url4}; 183 expected_sorted_origins = {url6, url3, url7, url5, url4};
184 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, 184 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins,
185 important_sites); 185 important_sites);
186 } 186 }
187 187
188 TEST_F(ImportantSitesUtilTest, TooManyBookmarks) {
189 SiteEngagementService* service = SiteEngagementService::Get(profile());
190 ASSERT_TRUE(service);
191
192 GURL url1("http://www.google.com/");
193 GURL url2("https://www.google.com/");
194 GURL url3("https://drive.google.com/");
195 GURL url4("https://www.chrome.com/");
196 GURL url5("https://www.example.com/");
197 GURL url6("https://youtube.com/");
198 GURL url7("https://foo.bar/");
199
200 // Add some as bookmarks.
201 AddBookmark(url1);
202 AddBookmark(url2);
203 AddBookmark(url3);
204 AddBookmark(url4);
205 AddBookmark(url5);
206
207 // We have just below our limit, so all sites are important (the first three
208 // origins collapse, so we end up with 3).
209 std::vector<ImportantDomainInfo> important_sites =
210 ImportantSitesUtil::GetImportantRegisterableDomains(profile(),
211 kNumImportantSites);
212 EXPECT_EQ(3u, important_sites.size());
213
214 // Add the rest, which should put us over the limit.
215 AddBookmark(url6);
216 AddBookmark(url7);
217 // Too many bookmarks! Nothing shows up now.
218 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
219 profile(), kNumImportantSites);
220 EXPECT_EQ(0u, important_sites.size());
221
222 // If we add some site engagement, these should show up in order (even though
223 // the engagement is too low for a signal by itself).
224 service->ResetScoreForURL(url1, 2);
225 service->ResetScoreForURL(url4, 3);
226 service->ResetScoreForURL(url7, 0);
227
228 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains(
229 profile(), kNumImportantSites);
230 ASSERT_EQ(2u, important_sites.size());
231 std::vector<std::string> expected_sorted_domains = {"google.com",
232 "chrome.com"};
233 std::vector<GURL> expected_sorted_origins = {url1, url4};
234 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins,
235 important_sites);
236 }
237
188 TEST_F(ImportantSitesUtilTest, Blacklisting) { 238 TEST_F(ImportantSitesUtilTest, Blacklisting) {
189 SiteEngagementService* service = SiteEngagementService::Get(profile()); 239 SiteEngagementService* service = SiteEngagementService::Get(profile());
190 ASSERT_TRUE(service); 240 ASSERT_TRUE(service);
191 241
192 GURL url1("http://www.google.com/"); 242 GURL url1("http://www.google.com/");
193 243
194 // Set a bunch of positive signals. 244 // Set a bunch of positive signals.
195 service->ResetScoreForURL(url1, 5); 245 service->ResetScoreForURL(url1, 5);
196 AddBookmark(url1); 246 AddBookmark(url1);
197 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, 247 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDIgnoredReason"), 374 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDIgnoredReason"),
325 testing::ElementsAre(base::Bucket(BOOKMARKS, 1))); 375 testing::ElementsAre(base::Bucket(BOOKMARKS, 1)));
326 376
327 // Bookmarks are "unknown", as they were added after the crossed reasons. 377 // Bookmarks are "unknown", as they were added after the crossed reasons.
328 EXPECT_THAT(histogram_tester.GetAllSamples( 378 EXPECT_THAT(histogram_tester.GetAllSamples(
329 "Storage.BlacklistedImportantSites.Reason"), 379 "Storage.BlacklistedImportantSites.Reason"),
330 testing::ElementsAre( 380 testing::ElementsAre(
331 base::Bucket(CROSSED_NOTIFICATIONS_AND_ENGAGEMENT, 1), 381 base::Bucket(CROSSED_NOTIFICATIONS_AND_ENGAGEMENT, 1),
332 base::Bucket(CROSSED_REASON_UNKNOWN, 1))); 382 base::Bucket(CROSSED_REASON_UNKNOWN, 1)));
333 } 383 }
OLDNEW
« no previous file with comments | « chrome/browser/android/preferences/important_sites_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698