Chromium Code Reviews| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 | 262 |
| 262 // Set a bunch of positive signals. | 263 // Set a bunch of positive signals. |
| 263 service->ResetScoreForURL(url1, 5); | 264 service->ResetScoreForURL(url1, 5); |
| 264 AddBookmark(url1); | 265 AddBookmark(url2); |
| 265 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 266 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
| 266 url1); | 267 url1); |
| 267 | 268 |
| 268 // Important fetch 1. | 269 // Important fetch 1. |
| 269 std::vector<ImportantDomainInfo> important_sites = | 270 std::vector<ImportantDomainInfo> important_sites = |
| 270 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | 271 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), |
| 271 kNumImportantSites); | 272 kNumImportantSites); |
| 272 std::vector<std::string> expected_sorted_domains = {"google.com"}; | 273 std::vector<std::string> expected_sorted_domains = {"google.com", |
| 273 std::vector<GURL> expected_sorted_origins = {url1}; | 274 "gmail.com"}; |
| 275 std::vector<GURL> expected_sorted_origins = {url1, url2}; | |
| 274 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | 276 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, |
| 275 important_sites); | 277 important_sites); |
| 276 ASSERT_EQ(1u, important_sites.size()); | 278 ASSERT_EQ(2u, important_sites.size()); |
| 277 // Record ignore twice. | 279 // Record ignore twice. |
| 278 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 280 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 279 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 281 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 280 {"google.com"}, {important_sites[0].reason_bitfield}); | 282 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 281 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 283 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 282 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 284 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 283 {"google.com"}, {important_sites[0].reason_bitfield}); | 285 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 284 | 286 |
| 285 // Important fetch 2. | 287 // Important fetch 2. |
| 286 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 288 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
| 287 profile(), kNumImportantSites); | 289 profile(), kNumImportantSites); |
| 288 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | 290 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, |
| 289 important_sites); | 291 important_sites); |
| 290 // We shouldn't blacklist after first two times. | 292 // We shouldn't blacklist after first two times. |
| 291 ASSERT_EQ(1u, important_sites.size()); | 293 ASSERT_EQ(2u, important_sites.size()); |
| 292 | 294 |
| 293 // Record ignore 3rd time. | 295 // Record ignore 3rd time. |
| 294 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 296 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 295 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 297 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 296 {"google.com"}, {important_sites[0].reason_bitfield}); | 298 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 297 | 299 |
| 298 // Important fetch 3. We should be blacklisted now. | 300 // Important fetch 3. Google.com should be blacklisted now. |
| 299 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 301 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
| 300 profile(), kNumImportantSites); | 302 profile(), kNumImportantSites); |
| 301 ASSERT_EQ(0u, important_sites.size()); | 303 |
| 304 ASSERT_EQ(1u, important_sites.size()); | |
| 305 expected_sorted_domains = {"gmail.com"}; | |
| 306 expected_sorted_origins = {url2}; | |
| 307 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | |
| 308 important_sites); | |
| 302 } | 309 } |
| 303 | 310 |
| 304 TEST_F(ImportantSitesUtilTest, BlacklistingReset) { | 311 TEST_F(ImportantSitesUtilTest, BlacklistingReset) { |
| 305 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 312 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 306 ASSERT_TRUE(service); | 313 ASSERT_TRUE(service); |
| 307 | 314 |
| 308 GURL url1("http://www.google.com/"); | 315 GURL url1("http://www.google.com/"); |
| 316 GURL url2("http://www.gmail.com/"); | |
| 309 | 317 |
| 310 // Set a bunch of positive signals. | 318 // Set a bunch of positive signals. |
| 311 service->ResetScoreForURL(url1, 5); | 319 service->ResetScoreForURL(url1, 5); |
| 312 AddBookmark(url1); | 320 AddBookmark(url2); |
| 313 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 321 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
| 314 url1); | 322 url1); |
| 315 | 323 |
| 324 // Important fetch 1. | |
| 316 std::vector<ImportantDomainInfo> important_sites = | 325 std::vector<ImportantDomainInfo> important_sites = |
| 317 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | 326 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), |
| 318 kNumImportantSites); | 327 kNumImportantSites); |
| 319 | 328 ASSERT_EQ(2u, important_sites.size()); |
| 320 // Record ignored twice. | 329 // Record ignore twice. |
| 321 ASSERT_EQ(1u, important_sites.size()); | |
| 322 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 330 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 323 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 331 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 324 {"google.com"}, {important_sites[0].reason_bitfield}); | 332 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 325 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 333 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 326 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 334 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 327 {"google.com"}, {important_sites[0].reason_bitfield}); | 335 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 328 | 336 |
| 329 // Important fetch, we should still be there. | 337 // Important fetch, we should still be there. |
| 330 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 338 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
| 331 profile(), kNumImportantSites); | 339 profile(), kNumImportantSites); |
| 332 std::vector<std::string> expected_sorted_domains = {"google.com"}; | 340 std::vector<std::string> expected_sorted_domains = {"google.com", |
| 333 std::vector<GURL> expected_sorted_origins = {url1}; | 341 "gmail.com"}; |
| 334 ASSERT_EQ(1u, important_sites.size()); | 342 std::vector<GURL> expected_sorted_origins = {url1, url2}; |
| 343 ASSERT_EQ(2u, important_sites.size()); | |
| 335 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | 344 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, |
| 336 important_sites); | 345 important_sites); |
| 337 | 346 |
| 338 // Record NOT ignored. | 347 // Record NOT ignored. |
| 339 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 348 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 340 profile(), {"google.com"}, {important_sites[0].reason_bitfield}, | 349 profile(), {"google.com", "gmail.com"}, |
| 350 {important_sites[0].reason_bitfield, important_sites[1].reason_bitfield}, | |
| 341 std::vector<std::string>(), std::vector<int32_t>()); | 351 std::vector<std::string>(), std::vector<int32_t>()); |
| 342 | 352 |
| 343 // Record ignored twice again. | 353 // Record ignored twice again |
| 344 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 354 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 345 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 355 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 346 {"google.com"}, {important_sites[0].reason_bitfield}); | 356 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 347 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 357 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 348 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 358 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 349 {"google.com"}, {important_sites[0].reason_bitfield}); | 359 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 350 | 360 |
| 351 // Important fetch, we should still be there. | 361 // Important fetch, we should still be there. |
| 352 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 362 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
| 353 profile(), kNumImportantSites); | 363 profile(), kNumImportantSites); |
| 354 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | 364 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, |
| 355 important_sites); | 365 important_sites); |
| 356 | 366 |
| 357 // Record ignored 3rd time in a row. | 367 // Record ignored 3rd time in a row. |
| 358 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | 368 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( |
| 359 profile(), std::vector<std::string>(), std::vector<int32_t>(), | 369 profile(), {"gmail.com"}, {important_sites[1].reason_bitfield}, |
| 360 {"google.com"}, {important_sites[0].reason_bitfield}); | 370 {"google.com"}, {important_sites[0].reason_bitfield}); |
| 361 | 371 |
| 362 // Blacklisted now. | 372 // Blacklisted now. |
| 363 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | 373 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( |
| 364 profile(), kNumImportantSites); | 374 profile(), kNumImportantSites); |
| 365 EXPECT_EQ(0u, important_sites.size()); | 375 ASSERT_EQ(1u, important_sites.size()); |
| 376 expected_sorted_domains = {"gmail.com"}; | |
| 377 expected_sorted_origins = {url2}; | |
| 378 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | |
| 379 important_sites); | |
| 366 } | 380 } |
| 367 | 381 |
| 368 TEST_F(ImportantSitesUtilTest, Metrics) { | 382 TEST_F(ImportantSitesUtilTest, Metrics) { |
| 369 SiteEngagementService* service = SiteEngagementService::Get(profile()); | 383 SiteEngagementService* service = SiteEngagementService::Get(profile()); |
| 370 ASSERT_TRUE(service); | 384 ASSERT_TRUE(service); |
| 371 base::HistogramTester histogram_tester; | 385 base::HistogramTester histogram_tester; |
| 372 | 386 |
| 373 GURL url1("http://www.google.com/"); | 387 GURL url1("http://www.google.com/"); |
| 374 service->ResetScoreForURL(url1, 5); | 388 service->ResetScoreForURL(url1, 5); |
| 375 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | 389 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 400 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDIgnoredReason"), | 414 histogram_tester.GetAllSamples("Storage.ImportantSites.CBDIgnoredReason"), |
| 401 testing::ElementsAre(base::Bucket(BOOKMARKS, 1))); | 415 testing::ElementsAre(base::Bucket(BOOKMARKS, 1))); |
| 402 | 416 |
| 403 // Bookmarks are "unknown", as they were added after the crossed reasons. | 417 // Bookmarks are "unknown", as they were added after the crossed reasons. |
| 404 EXPECT_THAT(histogram_tester.GetAllSamples( | 418 EXPECT_THAT(histogram_tester.GetAllSamples( |
| 405 "Storage.BlacklistedImportantSites.Reason"), | 419 "Storage.BlacklistedImportantSites.Reason"), |
| 406 testing::ElementsAre( | 420 testing::ElementsAre( |
| 407 base::Bucket(CROSSED_NOTIFICATIONS_AND_ENGAGEMENT, 1), | 421 base::Bucket(CROSSED_NOTIFICATIONS_AND_ENGAGEMENT, 1), |
| 408 base::Bucket(CROSSED_REASON_UNKNOWN, 1))); | 422 base::Bucket(CROSSED_REASON_UNKNOWN, 1))); |
| 409 } | 423 } |
| 424 | |
| 425 TEST_F(ImportantSitesUtilTest, DialogBlacklisting) { | |
| 426 SiteEngagementService* service = SiteEngagementService::Get(profile()); | |
| 427 ASSERT_TRUE(service); | |
| 428 | |
| 429 GURL url1("http://www.google.com/"); | |
| 430 GURL url2("http://www.yahoo.com/"); | |
| 431 | |
| 432 // Set a bunch of positive signals. | |
| 433 service->ResetScoreForURL(url2, 5); | |
| 434 AddBookmark(url1); | |
| 435 AddContentSetting(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, CONTENT_SETTING_ALLOW, | |
| 436 url1); | |
| 437 | |
| 438 // Start off not disabled. | |
| 439 EXPECT_FALSE(ImportantSitesUtil::IsDialogDisabled(profile())); | |
| 440 | |
| 441 // Important fetch 1. | |
| 442 std::vector<ImportantDomainInfo> important_sites = | |
| 443 ImportantSitesUtil::GetImportantRegisterableDomains(profile(), | |
| 444 kNumImportantSites); | |
| 445 std::vector<std::string> expected_sorted_domains = {"google.com", | |
| 446 "yahoo.com"}; | |
| 447 std::vector<GURL> expected_sorted_origins = {url1, url2}; | |
| 448 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | |
| 449 important_sites); | |
| 450 ASSERT_EQ(2u, important_sites.size()); | |
| 451 // Ignore all sites 3 times. | |
|
dominickn
2017/02/03 21:14:51
Nit: we ignore twice first
dmurph
2017/02/04 00:52:25
Done.
| |
| 452 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | |
| 453 profile(), std::vector<std::string>(), std::vector<int32_t>(), | |
| 454 {"google.com", "yahoo.com"}, | |
| 455 {important_sites[0].reason_bitfield, important_sites[1].reason_bitfield}); | |
| 456 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | |
| 457 profile(), std::vector<std::string>(), std::vector<int32_t>(), | |
| 458 {"google.com", "yahoo.com"}, | |
| 459 {important_sites[0].reason_bitfield, important_sites[1].reason_bitfield}); | |
| 460 | |
| 461 // Still not disabled... | |
| 462 EXPECT_FALSE(ImportantSitesUtil::IsDialogDisabled(profile())); | |
| 463 | |
| 464 ImportantSitesUtil::RecordBlacklistedAndIgnoredImportantSites( | |
|
dominickn
2017/02/03 21:14:51
Nit: this is the third ignore
dmurph
2017/02/04 00:52:25
Done.
| |
| 465 profile(), std::vector<std::string>(), std::vector<int32_t>(), | |
| 466 {"google.com", "yahoo.com"}, | |
| 467 {important_sites[0].reason_bitfield, important_sites[1].reason_bitfield}); | |
| 468 | |
| 469 // Items should still be present. | |
| 470 important_sites = ImportantSitesUtil::GetImportantRegisterableDomains( | |
| 471 profile(), kNumImportantSites); | |
| 472 ExpectImportantResultsEq(expected_sorted_domains, expected_sorted_origins, | |
| 473 important_sites); | |
| 474 | |
| 475 // Dialog should be blacklisted. | |
| 476 EXPECT_TRUE(ImportantSitesUtil::IsDialogDisabled(profile())); | |
| 477 } | |
| OLD | NEW |