Chromium Code Reviews| Index: chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| diff --git a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| index 852696e16d94cb56fbd1af3605ddc2b8ac315513..7c936eaaf8917af2b914d726cfbce6de3ca0aefa 100644 |
| --- a/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| +++ b/chrome/browser/permissions/permission_decision_auto_blocker_unittest.cc |
| @@ -5,10 +5,15 @@ |
| #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
| #include "base/bind.h" |
| +#include "base/time/time.h" |
| +#include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
| #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "chrome/test/base/testing_profile.h" |
| +#include "components/safe_browsing_db/test_database_manager.h" |
| #include "content/public/browser/permission_type.h" |
| +class HostContentSettingsMap; |
| + |
| namespace { |
| bool FilterGoogle(const GURL& url) { |
| @@ -44,6 +49,14 @@ class PermissionDecisionAutoBlockerUnitTest |
| return PermissionDecisionAutoBlocker::RecordIgnore(url, permission, |
| profile()); |
| } |
| + |
| + void PlaceUnderEmbargo(content::PermissionType permission, |
| + const GURL& url, |
| + HostContentSettingsMap* map, |
| + base::Time current_time) { |
| + PermissionDecisionAutoBlocker::PlaceUnderEmbargo(permission, url, map, |
| + current_time); |
| + } |
| }; |
| TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
| @@ -100,3 +113,39 @@ TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
| EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::DURABLE_STORAGE)); |
| EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::MIDI_SYSEX)); |
| } |
| + |
| +TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { |
| + GURL url("https://www.google.com"); |
| + HostContentSettingsMap* map = |
| + HostContentSettingsMapFactory::GetForProfile(profile()); |
| + base::Time time_now = base::Time::Now(); |
| + PlaceUnderEmbargo(content::PermissionType::GEOLOCATION, url, map, time_now); |
| + |
| + EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| + content::PermissionType::GEOLOCATION, profile(), url, time_now)); |
| + |
| + // Check that the origin is not under embargo for another permission. |
| + EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| + content::PermissionType::NOTIFICATIONS, profile(), url, time_now)); |
| + |
| + EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| + content::PermissionType::GEOLOCATION, profile(), url, |
| + time_now + base::TimeDelta::FromDays(5))); |
| + |
| + // Check embargo is lifted on expiry day. |
| + EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| + content::PermissionType::GEOLOCATION, profile(), url, |
| + time_now + base::TimeDelta::FromDays(7))); |
| + |
| + // Check embargo is lifted well after the expiry day. |
| + EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| + content::PermissionType::GEOLOCATION, profile(), url, |
| + time_now + base::TimeDelta::FromDays(8))); |
| + |
| + // Place under embargo again. |
| + time_now = base::Time::Now(); |
| + PlaceUnderEmbargo(content::PermissionType::NOTIFICATIONS, url, map, time_now); |
| + |
| + EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| + content::PermissionType::NOTIFICATIONS, profile(), url, time_now)); |
| +} |
|
raymes
2017/01/12 03:19:30
Could we add a simple test for the function to upd
meredithl
2017/01/12 05:59:19
PlaceUnderEmbargo is what updates the embargo stat
raymes
2017/01/16 02:23:42
Yep for ShouldAutomaticallyBlock
meredithl
2017/01/16 04:28:19
Done.
|