OLD | NEW |
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/engagement/important_sites_util.h" | 5 #include "chrome/browser/engagement/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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 ASSERT_TRUE(service); | 147 ASSERT_TRUE(service); |
148 | 148 |
149 GURL url1("http://www.google.com/"); | 149 GURL url1("http://www.google.com/"); |
150 GURL url2("https://www.google.com/"); | 150 GURL url2("https://www.google.com/"); |
151 GURL url3("https://drive.google.com/"); | 151 GURL url3("https://drive.google.com/"); |
152 GURL url4("https://www.chrome.com/"); | 152 GURL url4("https://www.chrome.com/"); |
153 GURL url5("https://www.example.com/"); | 153 GURL url5("https://www.example.com/"); |
154 GURL url6("https://youtube.com/"); | 154 GURL url6("https://youtube.com/"); |
155 GURL url7("https://foo.bar/"); | 155 GURL url7("https://foo.bar/"); |
156 | 156 |
157 service->ResetScoreForURL(url1, 5); | 157 service->ResetBaseScoreForURL(url1, 5); |
158 service->ResetScoreForURL(url2, 2); // Below medium engagement (5). | 158 service->ResetBaseScoreForURL(url2, 2); // Below medium engagement (5). |
159 service->ResetScoreForURL(url3, 7); | 159 service->ResetBaseScoreForURL(url3, 7); |
160 service->ResetScoreForURL(url4, 8); | 160 service->ResetBaseScoreForURL(url4, 8); |
161 service->ResetScoreForURL(url5, 9); | 161 service->ResetBaseScoreForURL(url5, 9); |
162 service->ResetScoreForURL(url6, 1); // Below the medium engagement (5). | 162 service->ResetBaseScoreForURL(url6, 1); // Below the medium engagement (5). |
163 service->ResetScoreForURL(url7, 11); | 163 service->ResetBaseScoreForURL(url7, 11); |
164 | 164 |
165 // Here we should have: | 165 // Here we should have: |
166 // 1: removed domains below minimum engagement, | 166 // 1: removed domains below minimum engagement, |
167 // 2: combined the google.com entries, and | 167 // 2: combined the google.com entries, and |
168 // 3: sorted by the score. | 168 // 3: sorted by the score. |
169 std::vector<ImportantDomainInfo> important_sites = | 169 std::vector<ImportantDomainInfo> important_sites = |
170 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | 170 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), |
171 kNumImportantSites); | 171 kNumImportantSites); |
172 std::vector<std::string> expected_sorted_domains = { | 172 std::vector<std::string> expected_sorted_domains = { |
173 "foo.bar", "example.com", "chrome.com", "google.com"}; | 173 "foo.bar", "example.com", "chrome.com", "google.com"}; |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 // Add the rest, which should put us over the limit. | 232 // Add the rest, which should put us over the limit. |
233 AddBookmark(url6); | 233 AddBookmark(url6); |
234 AddBookmark(url7); | 234 AddBookmark(url7); |
235 // Too many bookmarks! Nothing shows up now. | 235 // Too many bookmarks! Nothing shows up now. |
236 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 236 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
237 profile(), kNumImportantSites); | 237 profile(), kNumImportantSites); |
238 EXPECT_EQ(0u, important_sites.size()); | 238 EXPECT_EQ(0u, important_sites.size()); |
239 | 239 |
240 // If we add some site engagement, they should show up (even though the site | 240 // If we add some site engagement, they should show up (even though the site |
241 // engagement score is too low for a signal by itself). | 241 // engagement score is too low for a signal by itself). |
242 service->ResetScoreForURL(url1, 2); | 242 service->ResetBaseScoreForURL(url1, 2); |
243 service->ResetScoreForURL(url4, 3); | 243 service->ResetBaseScoreForURL(url4, 3); |
244 service->ResetScoreForURL(url7, 0); | 244 service->ResetBaseScoreForURL(url7, 0); |
245 | 245 |
246 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 246 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
247 profile(), kNumImportantSites); | 247 profile(), kNumImportantSites); |
248 ASSERT_EQ(2u, important_sites.size()); | 248 ASSERT_EQ(2u, important_sites.size()); |
249 std::vector<std::string> expected_sorted_domains = {"google.com", | 249 std::vector<std::string> expected_sorted_domains = {"google.com", |
250 "chrome.com"}; | 250 "chrome.com"}; |
251 std::vector<GURL> expected_sorted_origins = {url1, url4}; | 251 std::vector<GURL> expected_sorted_origins = {url1, url4}; |
252 ExpectImportantResultsEqualUnordered( | 252 ExpectImportantResultsEqualUnordered( |
253 expected_sorted_domains, expected_sorted_origins, important_sites); | 253 expected_sorted_domains, expected_sorted_origins, important_sites); |
254 } | 254 } |
255 | 255 |
256 TEST_F(ImportantSitesUtilTest, Blacklisting) { | 256 TEST_F(ImportantSitesUtilTest, Blacklisting) { |
257 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 257 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
258 ASSERT_TRUE(service); | 258 ASSERT_TRUE(service); |
259 | 259 |
260 GURL url1("http://www.google.com/"); | 260 GURL url1("http://www.google.com/"); |
261 GURL url2("http://www.gmail.com/"); | 261 GURL url2("http://www.gmail.com/"); |
262 | 262 |
263 // Set a bunch of positive signals. | 263 // Set a bunch of positive signals. |
264 service->ResetScoreForURL(url1, 5); | 264 service->ResetBaseScoreForURL(url1, 5); |
265 AddBookmark(url2); | 265 AddBookmark(url2); |
266 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 266 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
267 url1); | 267 url1); |
268 | 268 |
269 // Important fetch 1. | 269 // Important fetch 1. |
270 std::vector<ImportantDomainInfo> important_sites = | 270 std::vector<ImportantDomainInfo> important_sites = |
271 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | 271 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), |
272 kNumImportantSites); | 272 kNumImportantSites); |
273 std::vector<std::string> expected_sorted_domains = {"google.com", | 273 std::vector<std::string> expected_sorted_domains = {"google.com", |
274 "gmail.com"}; | 274 "gmail.com"}; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 } | 309 } |
310 | 310 |
311 TEST_F(ImportantSitesUtilTest, BlacklistingReset) { | 311 TEST_F(ImportantSitesUtilTest, BlacklistingReset) { |
312 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 312 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
313 ASSERT_TRUE(service); | 313 ASSERT_TRUE(service); |
314 | 314 |
315 GURL url1("http://www.google.com/"); | 315 GURL url1("http://www.google.com/"); |
316 GURL url2("http://www.gmail.com/"); | 316 GURL url2("http://www.gmail.com/"); |
317 | 317 |
318 // Set a bunch of positive signals. | 318 // Set a bunch of positive signals. |
319 service->ResetScoreForURL(url1, 5); | 319 service->ResetBaseScoreForURL(url1, 5); |
320 AddBookmark(url2); | 320 AddBookmark(url2); |
321 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 321 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
322 url1); | 322 url1); |
323 | 323 |
324 // Important fetch 1. | 324 // Important fetch 1. |
325 std::vector<ImportantDomainInfo> important_sites = | 325 std::vector<ImportantDomainInfo> important_sites = |
326 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | 326 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), |
327 kNumImportantSites); | 327 kNumImportantSites); |
328 ASSERT_EQ(2u, important_sites.size()); | 328 ASSERT_EQ(2u, important_sites.size()); |
329 // Record ignore twice. | 329 // Record ignore twice. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | 378 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, |
379 important_sites); | 379 important_sites); |
380 } | 380 } |
381 | 381 |
382 TEST_F(ImportantSitesUtilTest, Metrics) { | 382 TEST_F(ImportantSitesUtilTest, Metrics) { |
383 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 383 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
384 ASSERT_TRUE(service); | 384 ASSERT_TRUE(service); |
385 base::HistogramTester histogram_tester; | 385 base::HistogramTester histogram_tester; |
386 | 386 |
387 GURL url1("http://www.google.com/"); | 387 GURL url1("http://www.google.com/"); |
388 service->ResetScoreForURL(url1, 5); | 388 service->ResetBaseScoreForURL(url1, 5); |
389 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 389 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
390 url1); | 390 url1); |
391 | 391 |
392 GURL url2("http://www.youtube.com/"); | 392 GURL url2("http://www.youtube.com/"); |
393 AddBookmark(url2); | 393 AddBookmark(url2); |
394 | 394 |
395 GURL url3("http://www.bad.com/"); | 395 GURL url3("http://www.bad.com/"); |
396 AddBookmark(url3); | 396 AddBookmark(url3); |
397 | 397 |
398 std::vector<ImportantDomainInfo> important_sites = | 398 std::vector<ImportantDomainInfo> important_sites = |
(...skipping 24 matching lines...) Expand all Loading... |
423 } | 423 } |
424 | 424 |
425 TEST_F(ImportantSitesUtilTest, DialogBlacklisting) { | 425 TEST_F(ImportantSitesUtilTest, DialogBlacklisting) { |
426 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 426 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
427 ASSERT_TRUE(service); | 427 ASSERT_TRUE(service); |
428 | 428 |
429 GURL url1("http://www.google.com/"); | 429 GURL url1("http://www.google.com/"); |
430 GURL url2("http://www.yahoo.com/"); | 430 GURL url2("http://www.yahoo.com/"); |
431 | 431 |
432 // Set a bunch of positive signals. | 432 // Set a bunch of positive signals. |
433 service->ResetScoreForURL(url2, 5); | 433 service->ResetBaseScoreForURL(url2, 5); |
434 AddBookmark(url1); | 434 AddBookmark(url1); |
435 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 435 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
436 url1); | 436 url1); |
437 | 437 |
438 // Start off not disabled. | 438 // Start off not disabled. |
439 EXPECT_FALSE(ImportantSitesUtil::IsDialogDisabled(profile())); | 439 EXPECT_FALSE(ImportantSitesUtil::IsDialogDisabled(profile())); |
440 | 440 |
441 // Important fetch 1. | 441 // Important fetch 1. |
442 std::vector<ImportantDomainInfo> important_sites = | 442 std::vector<ImportantDomainInfo> important_sites = |
443 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | 443 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), |
(...skipping 25 matching lines...) Expand all Loading... |
469 | 469 |
470 // Items should still be present. | 470 // Items should still be present. |
471 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 471 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
472 profile(), kNumImportantSites); | 472 profile(), kNumImportantSites); |
473 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | 473 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, |
474 important_sites); | 474 important_sites); |
475 | 475 |
476 // Dialog should be blacklisted. | 476 // Dialog should be blacklisted. |
477 EXPECT_TRUE(ImportantSitesUtil::IsDialogDisabled(profile())); | 477 EXPECT_TRUE(ImportantSitesUtil::IsDialogDisabled(profile())); |
478 } | 478 } |
OLD | NEW |