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/permissions/permission_decision_auto_blocker.h" | 5 #include "chrome/browser/permissions/permission_decision_auto_blocker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/time/time.h" |
| 9 #include "chrome/browser/content_settings/host_content_settings_map_factory.h" |
8 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 10 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
9 #include "chrome/test/base/testing_profile.h" | 11 #include "chrome/test/base/testing_profile.h" |
| 12 #include "components/safe_browsing_db/test_database_manager.h" |
10 #include "content/public/browser/permission_type.h" | 13 #include "content/public/browser/permission_type.h" |
11 | 14 |
| 15 class HostContentSettingsMap; |
| 16 |
12 namespace { | 17 namespace { |
13 | 18 |
14 bool FilterGoogle(const GURL& url) { | 19 bool FilterGoogle(const GURL& url) { |
15 return url == "https://www.google.com/"; | 20 return url == "https://www.google.com/"; |
16 } | 21 } |
17 | 22 |
18 bool FilterAll(const GURL& url) { | 23 bool FilterAll(const GURL& url) { |
19 return true; | 24 return true; |
20 } | 25 } |
21 | 26 |
(...skipping 15 matching lines...) Expand all Loading... |
37 | 42 |
38 int RecordDismiss(const GURL& url, content::PermissionType permission) { | 43 int RecordDismiss(const GURL& url, content::PermissionType permission) { |
39 return PermissionDecisionAutoBlocker::RecordDismiss(url, permission, | 44 return PermissionDecisionAutoBlocker::RecordDismiss(url, permission, |
40 profile()); | 45 profile()); |
41 } | 46 } |
42 | 47 |
43 int RecordIgnore(const GURL& url, content::PermissionType permission) { | 48 int RecordIgnore(const GURL& url, content::PermissionType permission) { |
44 return PermissionDecisionAutoBlocker::RecordIgnore(url, permission, | 49 return PermissionDecisionAutoBlocker::RecordIgnore(url, permission, |
45 profile()); | 50 profile()); |
46 } | 51 } |
| 52 |
| 53 void PlaceUnderEmbargo(content::PermissionType permission, |
| 54 const GURL& url, |
| 55 HostContentSettingsMap* map, |
| 56 base::Time current_time) { |
| 57 PermissionDecisionAutoBlocker::PlaceUnderEmbargo(permission, url, map, |
| 58 current_time); |
| 59 } |
47 }; | 60 }; |
48 | 61 |
49 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { | 62 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
50 GURL url1("https://www.google.com"); | 63 GURL url1("https://www.google.com"); |
51 GURL url2("https://www.example.com"); | 64 GURL url2("https://www.example.com"); |
52 | 65 |
53 // Record some dismissals. | 66 // Record some dismissals. |
54 EXPECT_EQ(1, RecordDismiss(url1, content::PermissionType::GEOLOCATION)); | 67 EXPECT_EQ(1, RecordDismiss(url1, content::PermissionType::GEOLOCATION)); |
55 EXPECT_EQ(2, RecordDismiss(url1, content::PermissionType::GEOLOCATION)); | 68 EXPECT_EQ(2, RecordDismiss(url1, content::PermissionType::GEOLOCATION)); |
56 EXPECT_EQ(3, RecordDismiss(url1, content::PermissionType::GEOLOCATION)); | 69 EXPECT_EQ(3, RecordDismiss(url1, content::PermissionType::GEOLOCATION)); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::GEOLOCATION)); | 106 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::GEOLOCATION)); |
94 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); | 107 EXPECT_EQ(0, GetDismissalCount(url1, content::PermissionType::NOTIFICATIONS)); |
95 EXPECT_EQ(0, GetDismissalCount(url2, content::PermissionType::GEOLOCATION)); | 108 EXPECT_EQ(0, GetDismissalCount(url2, content::PermissionType::GEOLOCATION)); |
96 | 109 |
97 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::GEOLOCATION)); | 110 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::GEOLOCATION)); |
98 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::NOTIFICATIONS)); | 111 EXPECT_EQ(0, GetIgnoreCount(url1, content::PermissionType::NOTIFICATIONS)); |
99 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::GEOLOCATION)); | 112 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::GEOLOCATION)); |
100 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::DURABLE_STORAGE)); | 113 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::DURABLE_STORAGE)); |
101 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::MIDI_SYSEX)); | 114 EXPECT_EQ(0, GetIgnoreCount(url2, content::PermissionType::MIDI_SYSEX)); |
102 } | 115 } |
| 116 |
| 117 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { |
| 118 GURL url("https://www.google.com"); |
| 119 HostContentSettingsMap* map = |
| 120 HostContentSettingsMapFactory::GetForProfile(profile()); |
| 121 base::Time time_now = base::Time::Now(); |
| 122 PlaceUnderEmbargo(content::PermissionType::GEOLOCATION, url, map, time_now); |
| 123 |
| 124 EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| 125 content::PermissionType::GEOLOCATION, profile(), url, time_now)); |
| 126 |
| 127 // Check that the origin is not under embargo for another permission. |
| 128 EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| 129 content::PermissionType::NOTIFICATIONS, profile(), url, time_now)); |
| 130 |
| 131 EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| 132 content::PermissionType::GEOLOCATION, profile(), url, |
| 133 time_now + base::TimeDelta::FromDays(5))); |
| 134 |
| 135 // Check embargo is lifted on expiry day. |
| 136 EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| 137 content::PermissionType::GEOLOCATION, profile(), url, |
| 138 time_now + base::TimeDelta::FromDays(7))); |
| 139 |
| 140 // Check embargo is lifted well after the expiry day. |
| 141 EXPECT_FALSE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| 142 content::PermissionType::GEOLOCATION, profile(), url, |
| 143 time_now + base::TimeDelta::FromDays(8))); |
| 144 |
| 145 // Place under embargo again. |
| 146 time_now = base::Time::Now(); |
| 147 PlaceUnderEmbargo(content::PermissionType::NOTIFICATIONS, url, map, time_now); |
| 148 |
| 149 EXPECT_TRUE(PermissionDecisionAutoBlocker::IsUnderEmbargo( |
| 150 content::PermissionType::NOTIFICATIONS, profile(), url, time_now)); |
| 151 } |
OLD | NEW |