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 emargo for a single permission on a site works, and | |
dominickn
2017/04/03 01:35:31
sp. embargo
Patti Lor
2017/04/05 08:34:27
Done.
| |
163 // that it doesn't interfere with other embargoed permissions or the same | |
164 // permission embargoed on other sites. | |
165 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveEmbargoByURL) { | |
dominickn
2017/04/03 01:35:30
Url
Patti Lor
2017/04/05 08:34:27
Done.
| |
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 autoblocker()->RecordDismissAndEmbargo(url1, | |
dominickn
2017/04/03 01:35:31
I'd EXPECT_FALSE / EXPECT_TRUE all of these calls
Patti Lor
2017/04/05 08:34:27
Done.
| |
171 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
172 autoblocker()->RecordDismissAndEmbargo(url1, | |
173 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
174 autoblocker()->RecordDismissAndEmbargo(url1, | |
175 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
176 autoblocker()->RecordDismissAndEmbargo(url1, | |
177 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
178 autoblocker()->RecordDismissAndEmbargo(url1, | |
179 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
180 autoblocker()->RecordDismissAndEmbargo(url1, | |
181 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
182 autoblocker()->RecordDismissAndEmbargo(url1, | |
183 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
184 autoblocker()->RecordDismissAndEmbargo(url1, | |
185 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
186 // Record dismissals for location in |url2|. | |
187 autoblocker()->RecordDismissAndEmbargo(url2, | |
188 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
189 autoblocker()->RecordDismissAndEmbargo(url2, | |
190 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
191 autoblocker()->RecordDismissAndEmbargo(url2, | |
192 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
193 autoblocker()->RecordDismissAndEmbargo(url2, | |
194 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
195 | |
196 // Verify all dismissals recorded above resulted in embargo. | |
197 PermissionResult result = | |
198 autoblocker()->GetEmbargoResult(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
199 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
200 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
201 result = autoblocker()->GetEmbargoResult(url1, | |
202 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
203 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
204 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
205 result = | |
206 autoblocker()->GetEmbargoResult(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
207 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
208 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
209 | |
210 // Remove the embargo on notifications. Verify it is no longer under embargo, | |
211 // but location still is. | |
212 autoblocker()->RemoveEmbargoByURL(url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
213 result = | |
214 autoblocker()->GetEmbargoResult(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
215 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
216 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
217 // Notification's default setting is |CONTENT_SETTING_ASK|. | |
218 result = autoblocker()->GetEmbargoResult(url1, | |
219 CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | |
220 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | |
221 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | |
222 // Verify |url2|'s embargo is still intact as well. | |
223 result = | |
224 autoblocker()->GetEmbargoResult(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
225 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
226 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
227 } | |
228 | |
229 // Test that removing embargo from blacklisted permissions also works. | |
230 TEST_F(PermissionDecisionAutoBlockerUnitTest, | |
231 RemoveEmbargoByURLForBlacklistedPermission) { | |
232 GURL url("https://www.example.com"); | |
233 | |
234 // Place under embargo and verify. | |
235 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
236 PermissionResult result = | |
237 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
238 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
239 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | |
240 | |
241 // Remove embargo and verify. | |
242 autoblocker()->RemoveEmbargoByURL(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
243 result = | |
244 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
245 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | |
246 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | |
247 } | |
248 | |
249 // Test it still only takes one more dismissal to re-trigger embargo after | |
250 // removing the embargo status for a site. | |
251 TEST_F(PermissionDecisionAutoBlockerUnitTest, | |
252 DismissAfterRemovingEmbargoByURL) { | |
253 GURL url("https://www.example.com"); | |
254 | |
255 // Record dismissals for location. | |
256 autoblocker()->RecordDismissAndEmbargo(url, | |
dominickn
2017/04/03 01:35:31
EXPECT_TRUE / EXPECT_FALSE these calls
Patti Lor
2017/04/05 08:34:27
Done.
| |
257 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
258 autoblocker()->RecordDismissAndEmbargo(url, | |
259 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
260 autoblocker()->RecordDismissAndEmbargo(url, | |
261 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
262 autoblocker()->RecordDismissAndEmbargo(url, | |
263 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
264 | |
265 // Verify location is under embargo. | |
266 PermissionResult result = | |
267 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
268 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
269 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
270 | |
271 // Remove embargo. | |
272 autoblocker()->RemoveEmbargoByURL(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
273 | |
dominickn
2017/04/03 01:35:31
Nit: verify that it's not under embargo here
Patti Lor
2017/04/05 08:34:27
Done.
| |
274 // Record another dismissal and verify location is under embargo again. | |
275 autoblocker()->RecordDismissAndEmbargo(url, | |
276 CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
277 result = | |
278 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | |
279 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | |
280 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | |
281 } | |
282 | |
162 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { | 283 TEST_F(PermissionDecisionAutoBlockerUnitTest, RemoveCountsByUrl) { |
163 GURL url1("https://www.google.com"); | 284 GURL url1("https://www.google.com"); |
164 GURL url2("https://www.example.com"); | 285 GURL url2("https://www.example.com"); |
165 | 286 |
166 // Record some dismissals. | 287 // Record some dismissals. |
167 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 288 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
168 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 289 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
169 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 290 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
170 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 291 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
171 | 292 |
(...skipping 445 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
617 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 738 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
618 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 739 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
619 0 /* timeout in ms */); | 740 0 /* timeout in ms */); |
620 | 741 |
621 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 742 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
622 EXPECT_FALSE(last_embargoed_status()); | 743 EXPECT_FALSE(last_embargoed_status()); |
623 histograms.ExpectUniqueSample( | 744 histograms.ExpectUniqueSample( |
624 "Permissions.AutoBlocker.SafeBrowsingResponse", | 745 "Permissions.AutoBlocker.SafeBrowsingResponse", |
625 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); | 746 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); |
626 } | 747 } |
OLD | NEW |