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 <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
152 } | 152 } |
153 | 153 |
154 private: | 154 private: |
155 PermissionDecisionAutoBlocker* autoblocker_; | 155 PermissionDecisionAutoBlocker* autoblocker_; |
156 base::test::ScopedFeatureList feature_list_; | 156 base::test::ScopedFeatureList feature_list_; |
157 base::SimpleTestClock* clock_; | 157 base::SimpleTestClock* clock_; |
158 bool last_embargoed_status_; | 158 bool last_embargoed_status_; |
159 bool callback_was_run_; | 159 bool callback_was_run_; |
160 }; | 160 }; |
161 | 161 |
162 // Check removing the the embargo for a single permission on a site works, and | |
163 // that it doesn't interfere with other embargoed permissions or the same | |
164 // permission embargoed on other sites. | |
165 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveEmbargoByUrl) { | |
166 GURL url1("https://www.google.com"); | |
167 GURL url2("https://www.example.com"); | |
168 | |
169 // Record dismissals for location and notifications in |url1|. | |
170 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
171 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
172 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
173 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
174 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | |
175 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
176 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
177 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | |
178 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
179 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | |
180 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | |
181 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | |
182 // Record dismissals for location in |url2|. | |
183 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
184 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
185 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
186 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
187 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | |
188 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
189 | |
190 // Verify all dismissals recorded above resulted in embargo. | |
191 PermissionResult result = | |
192 autoblocker()->GetEmbargoResult(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
193 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
194 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
195 result = autoblocker()->GetEmbargoResult(url1, | |
196 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
197 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
198 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
199 result = | |
200 autoblocker()->GetEmbargoResult(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
201 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
202 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
203 | |
204 // Remove the embargo on notifications. Verify it is no longer under embargo, | |
205 // but location still is. | |
206 autoblocker()->RemoveEmbargoByUrl(url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
207 result = | |
208 autoblocker()->GetEmbargoResult(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
209 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
210 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
211 // Notification's default setting is |CONTENT_SETTING_ASK|. | |
raymes
2017/04/06 04:45:35
nit: I think it's not that notifications default i
Patti Lor
2017/04/06 05:31:46
Oh, you're totally right - thanks. Updated the com
| |
212 result = autoblocker()->GetEmbargoResult(url1, | |
213 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
214 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | |
215 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | |
216 // Verify |url2|'s embargo is still intact as well. | |
217 result = | |
218 autoblocker()->GetEmbargoResult(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
219 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
220 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
221 } | |
222 | |
223 // Test that removing embargo from blacklisted permissions also works. | |
224 TEST_F(PermissionDecisionAutoBlockerUnitTest, | |
225 RemoveEmbargoByUrlForBlacklistedPermission) { | |
226 GURL url("https://www.example.com"); | |
227 | |
228 // Place under embargo and verify. | |
229 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
230 PermissionResult result = | |
231 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
232 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
233 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | |
234 | |
235 // Remove embargo and verify. | |
236 autoblocker()->RemoveEmbargoByUrl(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
237 result = | |
238 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
239 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | |
240 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | |
241 } | |
242 | |
243 // Test it still only takes one more dismissal to re-trigger embargo after | |
244 // removing the embargo status for a site. | |
245 TEST_F(PermissionDecisionAutoBlockerUnitTest, | |
246 DismissAfterRemovingEmbargoByURL) { | |
247 GURL url("https://www.example.com"); | |
248 | |
249 // Record dismissals for location. | |
250 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
251 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
252 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | |
253 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
254 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | |
255 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | |
256 | |
257 // Verify location is under embargo. | |
258 PermissionResult result = | |
259 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
260 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
261 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
262 | |
263 // Remove embargo and verify this is true. | |
264 autoblocker()->RemoveEmbargoByUrl(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
265 result = | |
266 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
267 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | |
268 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | |
269 | |
270 // Record another dismissal and verify location is under embargo again. | |
271 autoblocker()->RecordDismissAndEmbargo(url, | |
272 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
273 result = | |
274 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
275 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
276 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
277 } | |
278 | |
162 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { | 279 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
163 GURL url1("https://www.google.com"); | 280 GURL url1("https://www.google.com"); |
164 GURL url2("https://www.example.com"); | 281 GURL url2("https://www.example.com"); |
165 | 282 |
166 // Record some dismissals. | 283 // Record some dismissals. |
167 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 284 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
168 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 285 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
169 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 286 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
170 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 287 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
171 | 288 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
652 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 769 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
653 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 770 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
654 0 /* timeout in ms */); | 771 0 /* timeout in ms */); |
655 | 772 |
656 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 773 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
657 EXPECT_FALSE(last_embargoed_status()); | 774 EXPECT_FALSE(last_embargoed_status()); |
658 histograms.ExpectUniqueSample( | 775 histograms.ExpectUniqueSample( |
659 "Permissions.AutoBlocker.SafeBrowsingResponse", | 776 "Permissions.AutoBlocker.SafeBrowsingResponse", |
660 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); | 777 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); |
661 } | 778 } |
OLD | NEW |