OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/site_engagement_service.h" | 5 #include "chrome/browser/engagement/site_engagement_service.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/files/scoped_temp_dir.h" | 9 #include "base/files/scoped_temp_dir.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
13 #include "base/test/histogram_tester.h" | 13 #include "base/test/histogram_tester.h" |
14 #include "base/test/simple_test_clock.h" | 14 #include "base/test/simple_test_clock.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
17 #include "chrome/browser/engagement/site_engagement_helper.h" | 17 #include "chrome/browser/engagement/site_engagement_helper.h" |
18 #include "chrome/browser/engagement/site_engagement_metrics.h" | 18 #include "chrome/browser/engagement/site_engagement_metrics.h" |
19 #include "chrome/browser/engagement/site_engagement_score.h" | 19 #include "chrome/browser/engagement/site_engagement_score.h" |
20 #include "chrome/browser/history/history_service_factory.h" | 20 #include "chrome/browser/history/history_service_factory.h" |
21 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 21 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
22 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 24 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
25 #include "chrome/test/base/testing_profile.h" | 25 #include "chrome/test/base/testing_profile.h" |
26 #include "components/content_settings/core/browser/content_settings_observer.h" | 26 #include "components/content_settings/core/browser/content_settings_observer.h" |
27 #include "components/content_settings/core/browser/host_content_settings_map.h" | 27 #include "components/content_settings/core/browser/host_content_settings_map.h" |
| 28 #include "components/content_settings/core/common/content_settings.h" |
| 29 #include "components/content_settings/core/common/content_settings_types.h" |
28 #include "components/history/core/browser/history_database_params.h" | 30 #include "components/history/core/browser/history_database_params.h" |
29 #include "components/history/core/browser/history_service.h" | 31 #include "components/history/core/browser/history_service.h" |
30 #include "components/history/core/test/test_history_database.h" | 32 #include "components/history/core/test/test_history_database.h" |
31 #include "components/prefs/pref_service.h" | 33 #include "components/prefs/pref_service.h" |
32 #include "content/public/browser/browser_thread.h" | 34 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/navigation_entry.h" | 35 #include "content/public/browser/navigation_entry.h" |
34 #include "content/public/browser/page_navigator.h" | 36 #include "content/public/browser/page_navigator.h" |
35 #include "content/public/browser/web_contents.h" | 37 #include "content/public/browser/web_contents.h" |
36 #include "content/public/test/web_contents_tester.h" | 38 #include "content/public/test/web_contents_tester.h" |
37 #include "testing/gtest/include/gtest/gtest.h" | 39 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 service->AddPoints(url1, 1.0); | 477 service->AddPoints(url1, 1.0); |
476 clock->SetNow(GetReferenceTime() + base::TimeDelta::FromDays(10)); | 478 clock->SetNow(GetReferenceTime() + base::TimeDelta::FromDays(10)); |
477 EXPECT_DOUBLE_EQ(1.0, service->GetScore(url1)); | 479 EXPECT_DOUBLE_EQ(1.0, service->GetScore(url1)); |
478 EXPECT_DOUBLE_EQ(5.0, service->GetScore(url2)); | 480 EXPECT_DOUBLE_EQ(5.0, service->GetScore(url2)); |
479 | 481 |
480 clock->SetNow(GetReferenceTime() + base::TimeDelta::FromDays(11)); | 482 clock->SetNow(GetReferenceTime() + base::TimeDelta::FromDays(11)); |
481 EXPECT_DOUBLE_EQ(1.0, service->GetScore(url1)); | 483 EXPECT_DOUBLE_EQ(1.0, service->GetScore(url1)); |
482 EXPECT_DOUBLE_EQ(0.0, service->GetScore(url2)); | 484 EXPECT_DOUBLE_EQ(0.0, service->GetScore(url2)); |
483 } | 485 } |
484 | 486 |
| 487 TEST_F(SiteEngagementServiceTest, NotificationPermission) { |
| 488 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
| 489 std::unique_ptr<SiteEngagementService> service( |
| 490 new SiteEngagementService(profile(), base::WrapUnique(clock))); |
| 491 |
| 492 GURL url1("https://www.google.com/"); |
| 493 GURL url2("http://www.google.com/"); |
| 494 GURL url3("https://drive.google.com/"); |
| 495 clock->SetNow(GetReferenceTime()); |
| 496 |
| 497 EXPECT_EQ(0, service->GetScore(url1)); |
| 498 EXPECT_EQ(0, service->GetScore(url2)); |
| 499 EXPECT_EQ(0, service->GetScore(url3)); |
| 500 |
| 501 HostContentSettingsMap* settings_map = |
| 502 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 503 |
| 504 settings_map->SetContentSettingDefaultScope( |
| 505 url1, url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
| 506 CONTENT_SETTING_ALLOW); |
| 507 |
| 508 settings_map->SetContentSettingDefaultScope( |
| 509 url2, url2, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
| 510 CONTENT_SETTING_BLOCK); |
| 511 |
| 512 settings_map->SetContentSettingDefaultScope( |
| 513 url3, url3, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
| 514 CONTENT_SETTING_ASK); |
| 515 |
| 516 EXPECT_EQ(5, service->GetScore(url1)); |
| 517 EXPECT_EQ(0, service->GetScore(url2)); |
| 518 EXPECT_EQ(0, service->GetScore(url3)); |
| 519 |
| 520 service->AddPoints(url1, 1.0); |
| 521 service->AddPoints(url2, 3.0); |
| 522 EXPECT_EQ(6, service->GetScore(url1)); |
| 523 EXPECT_EQ(3, service->GetScore(url2)); |
| 524 |
| 525 settings_map->SetContentSettingDefaultScope( |
| 526 url1, url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS, std::string(), |
| 527 CONTENT_SETTING_BLOCK); |
| 528 |
| 529 EXPECT_EQ(1, service->GetScore(url1)); |
| 530 } |
| 531 |
485 TEST_F(SiteEngagementServiceTest, CheckHistograms) { | 532 TEST_F(SiteEngagementServiceTest, CheckHistograms) { |
486 base::HistogramTester histograms; | 533 base::HistogramTester histograms; |
487 | 534 |
488 base::SimpleTestClock* clock = new base::SimpleTestClock(); | 535 base::SimpleTestClock* clock = new base::SimpleTestClock(); |
489 std::unique_ptr<SiteEngagementService> service( | 536 std::unique_ptr<SiteEngagementService> service( |
490 new SiteEngagementService(profile(), base::WrapUnique(clock))); | 537 new SiteEngagementService(profile(), base::WrapUnique(clock))); |
491 | 538 |
492 base::Time current_day = GetReferenceTime(); | 539 base::Time current_day = GetReferenceTime(); |
493 clock->SetNow(current_day); | 540 clock->SetNow(current_day); |
494 | 541 |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1762 | 1809 |
1763 EXPECT_EQ(3, CheckScoreFromSettingsOnThread(content::BrowserThread::IO, | 1810 EXPECT_EQ(3, CheckScoreFromSettingsOnThread(content::BrowserThread::IO, |
1764 settings_map, url1)); | 1811 settings_map, url1)); |
1765 EXPECT_EQ(3, CheckScoreFromSettingsOnThread(content::BrowserThread::FILE, | 1812 EXPECT_EQ(3, CheckScoreFromSettingsOnThread(content::BrowserThread::FILE, |
1766 settings_map, url2)); | 1813 settings_map, url2)); |
1767 EXPECT_EQ(4, CheckScoreFromSettingsOnThread(content::BrowserThread::FILE, | 1814 EXPECT_EQ(4, CheckScoreFromSettingsOnThread(content::BrowserThread::FILE, |
1768 incognito_settings_map, url1)); | 1815 incognito_settings_map, url1)); |
1769 EXPECT_EQ(3, CheckScoreFromSettingsOnThread(content::BrowserThread::IO, | 1816 EXPECT_EQ(3, CheckScoreFromSettingsOnThread(content::BrowserThread::IO, |
1770 incognito_settings_map, url2)); | 1817 incognito_settings_map, url2)); |
1771 } | 1818 } |
OLD | NEW |