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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 182 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
183 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 183 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
184 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 184 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
185 | 185 |
186 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 186 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
187 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 187 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
188 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 188 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
189 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 189 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
190 | 190 |
191 // Record some ignores. | 191 // Record some ignores. |
192 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 192 EXPECT_EQ( |
193 url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 193 1, autoblocker()->RecordIgnore(url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
194 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 194 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
195 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); | 195 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
196 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 196 EXPECT_EQ( |
197 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 197 1, autoblocker()->RecordIgnore(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
198 EXPECT_EQ(2, autoblocker()->RecordIgnore( | 198 EXPECT_EQ( |
199 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 199 2, autoblocker()->RecordIgnore(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
200 | 200 |
201 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterGoogle)); | 201 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterGoogle)); |
202 | 202 |
203 // Expect that url1's actions are gone, but url2's remain. | 203 // Expect that url1's actions are gone, but url2's remain. |
204 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 204 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
205 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 205 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
206 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 206 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
207 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 207 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
208 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 208 EXPECT_EQ( |
209 url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 209 0, autoblocker()->GetIgnoreCount(url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
210 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 210 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
211 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); | 211 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
212 | 212 |
213 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 213 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
214 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 214 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
215 EXPECT_EQ(2, autoblocker()->GetIgnoreCount( | 215 EXPECT_EQ(2, autoblocker()->GetIgnoreCount( |
216 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 216 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
217 | 217 |
218 // Add some more actions. | 218 // Add some more actions. |
219 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 219 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
220 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 220 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
221 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 221 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
222 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 222 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
223 | 223 |
224 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 224 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
225 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 225 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
226 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 226 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
227 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 227 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
228 | 228 |
229 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 229 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
230 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 230 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
231 EXPECT_EQ(2, autoblocker()->GetDismissCount( | 231 EXPECT_EQ(2, autoblocker()->GetDismissCount( |
232 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 232 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
233 | 233 |
234 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 234 EXPECT_EQ( |
235 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 235 1, autoblocker()->RecordIgnore(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
236 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 236 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
237 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 237 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
238 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 238 EXPECT_EQ(1, autoblocker()->RecordIgnore( |
239 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); | 239 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
240 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 240 EXPECT_EQ( |
241 url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 241 1, autoblocker()->RecordIgnore(url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
242 | 242 |
243 // Remove everything and expect that it's all gone. | 243 // Remove everything and expect that it's all gone. |
244 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterAll)); | 244 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterAll)); |
245 | 245 |
246 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 246 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
247 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 247 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
248 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 248 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
249 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 249 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
250 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 250 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
251 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 251 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
252 | 252 |
253 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 253 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
254 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 254 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
255 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 255 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
256 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 256 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
257 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 257 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
258 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 258 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
259 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 259 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( |
260 url2, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); | 260 url2, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
261 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 261 EXPECT_EQ( |
262 url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 262 0, autoblocker()->GetIgnoreCount(url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
263 } | 263 } |
264 | 264 |
265 // Test that an origin that has been blacklisted for a permission is embargoed. | 265 // Test that an origin that has been blacklisted for a permission is embargoed. |
266 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) { | 266 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestUpdateEmbargoBlacklist) { |
267 GURL url("https://www.google.com"); | 267 GURL url("https://www.google.com"); |
268 base::HistogramTester histograms; | 268 base::HistogramTester histograms; |
269 | 269 |
270 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 270 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
271 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, | 271 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, |
272 true /* enabled */); | 272 true /* enabled */); |
(...skipping 27 matching lines...) Expand all Loading... |
300 0 /* timeout in ms */); | 300 0 /* timeout in ms */); |
301 | 301 |
302 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); | 302 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
303 EXPECT_FALSE(last_embargoed_status()); | 303 EXPECT_FALSE(last_embargoed_status()); |
304 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 304 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
305 SafeBrowsingResponse::NOT_BLACKLISTED, 1); | 305 SafeBrowsingResponse::NOT_BLACKLISTED, 1); |
306 histograms.ExpectTotalCount( | 306 histograms.ExpectTotalCount( |
307 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 307 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
308 } | 308 } |
309 | 309 |
310 // Check that IsUnderEmbargo returns the correct value when the embargo is set | 310 // Check that GetEmbargoResult returns the correct value when the embargo is set |
311 // and expires. | 311 // and expires. |
312 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { | 312 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { |
313 GURL url("https://www.google.com"); | 313 GURL url("https://www.google.com"); |
314 clock()->SetNow(base::Time::Now()); | 314 clock()->SetNow(base::Time::Now()); |
315 | 315 |
| 316 // Check the default state. |
| 317 PermissionResult result = |
| 318 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 319 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 320 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 321 |
| 322 // Place under embargo and verify. |
316 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); | 323 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
317 EXPECT_TRUE( | 324 result = |
318 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 325 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 326 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 327 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
319 | 328 |
320 // Check that the origin is not under embargo for a different permission. | 329 // Check that the origin is not under embargo for a different permission. |
321 EXPECT_FALSE( | 330 result = |
322 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url)); | 331 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
| 332 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 333 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
323 | 334 |
324 // Confirm embargo status during the embargo period. | 335 // Confirm embargo status during the embargo period. |
325 clock()->Advance(base::TimeDelta::FromDays(5)); | 336 clock()->Advance(base::TimeDelta::FromDays(5)); |
326 EXPECT_TRUE( | 337 result = |
327 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 338 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 339 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 340 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
328 | 341 |
329 // Check embargo is lifted on expiry day. A small offset after the exact | 342 // Check embargo is lifted on expiry day. A small offset after the exact |
330 // embargo expiration date has been added to account for any precision errors | 343 // embargo expiration date has been added to account for any precision errors |
331 // when removing the date stored as a double from the permission dictionary. | 344 // when removing the date stored as a double from the permission dictionary. |
332 clock()->Advance(base::TimeDelta::FromHours(3 * 24 + 1)); | 345 clock()->Advance(base::TimeDelta::FromHours(3 * 24 + 1)); |
333 EXPECT_FALSE( | 346 result = |
334 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 347 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 348 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 349 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
335 | 350 |
336 // Check embargo is lifted well after the expiry day. | 351 // Check embargo is lifted well after the expiry day. |
337 clock()->Advance(base::TimeDelta::FromDays(1)); | 352 clock()->Advance(base::TimeDelta::FromDays(1)); |
338 EXPECT_FALSE( | 353 result = |
339 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 354 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 355 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 356 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
340 | 357 |
341 // Place under embargo again and verify the embargo status. | 358 // Place under embargo again and verify the embargo status. |
342 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); | 359 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
343 clock()->Advance(base::TimeDelta::FromDays(1)); | 360 clock()->Advance(base::TimeDelta::FromDays(1)); |
344 EXPECT_TRUE( | 361 result = |
345 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url)); | 362 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
| 363 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 364 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
346 } | 365 } |
347 | 366 |
348 // Tests the alternating pattern of the block on multiple dismiss behaviour. On | 367 // Tests the alternating pattern of the block on multiple dismiss behaviour. On |
349 // N dismissals, the origin to be embargoed for the requested permission and | 368 // N dismissals, the origin to be embargoed for the requested permission and |
350 // automatically blocked. Each time the embargo is lifted, the site gets another | 369 // automatically blocked. Each time the embargo is lifted, the site gets another |
351 // chance to request the permission, but if it is again dismissed it is placed | 370 // chance to request the permission, but if it is again dismissed it is placed |
352 // under embargo again and its permission requests blocked. | 371 // under embargo again and its permission requests blocked. |
353 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { | 372 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestDismissEmbargoBackoff) { |
354 GURL url("https://www.google.com"); | 373 GURL url("https://www.google.com"); |
355 clock()->SetNow(base::Time::Now()); | 374 clock()->SetNow(base::Time::Now()); |
356 base::HistogramTester histograms; | 375 base::HistogramTester histograms; |
357 | 376 |
358 // Record some dismisses. | 377 // Record some dismisses. |
359 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 378 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
360 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 379 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
361 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 380 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
362 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 381 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
363 | 382 |
364 // A request with < 3 prior dismisses should not be automatically blocked. | 383 // A request with < 3 prior dismisses should not be automatically blocked. |
365 EXPECT_FALSE( | 384 PermissionResult result = |
366 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 385 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 386 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 387 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
367 | 388 |
368 // After the 3rd dismiss subsequent permission requests should be autoblocked. | 389 // After the 3rd dismiss subsequent permission requests should be autoblocked. |
369 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 390 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
370 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 391 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
371 EXPECT_TRUE( | 392 result = |
372 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 393 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 394 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 395 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
373 | 396 |
374 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 397 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
375 0); | 398 0); |
376 histograms.ExpectTotalCount( | 399 histograms.ExpectTotalCount( |
377 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 400 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
378 // Accelerate time forward, check that the embargo status is lifted and the | 401 // Accelerate time forward, check that the embargo status is lifted and the |
379 // request won't be automatically blocked. | 402 // request won't be automatically blocked. |
380 clock()->Advance(base::TimeDelta::FromDays(8)); | 403 clock()->Advance(base::TimeDelta::FromDays(8)); |
381 EXPECT_FALSE( | 404 result = |
382 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 405 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 406 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 407 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
383 | 408 |
384 // Record another dismiss, subsequent requests should be autoblocked again. | 409 // Record another dismiss, subsequent requests should be autoblocked again. |
385 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 410 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
386 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 411 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
387 EXPECT_TRUE( | 412 result = |
388 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 413 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 414 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 415 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
389 | 416 |
390 // Accelerate time again, check embargo is lifted and another permission | 417 // Accelerate time again, check embargo is lifted and another permission |
391 // request is let through. | 418 // request is let through. |
392 clock()->Advance(base::TimeDelta::FromDays(8)); | 419 clock()->Advance(base::TimeDelta::FromDays(8)); |
393 EXPECT_FALSE( | 420 result = |
394 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 421 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 422 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 423 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
395 | 424 |
396 // Record another dismiss, subsequent requests should be autoblocked again. | 425 // Record another dismiss, subsequent requests should be autoblocked again. |
397 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 426 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
398 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 427 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
399 EXPECT_TRUE( | 428 result = |
400 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 429 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 430 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 431 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
401 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 432 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
402 0); | 433 0); |
403 histograms.ExpectTotalCount( | 434 histograms.ExpectTotalCount( |
404 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 435 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
405 } | 436 } |
406 | 437 |
407 // Test the logic for a combination of blacklisting and dismissal embargo. | 438 // Test the logic for a combination of blacklisting and dismissal embargo. |
408 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { | 439 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { |
409 GURL url("https://www.google.com"); | 440 GURL url("https://www.google.com"); |
410 clock()->SetNow(base::Time::Now()); | 441 clock()->SetNow(base::Time::Now()); |
411 | 442 |
412 // Place under blacklist embargo and check the status. | 443 // Place under blacklist embargo and check the status. |
413 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); | 444 PlaceUnderBlacklistEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
414 clock()->Advance(base::TimeDelta::FromDays(5)); | 445 clock()->Advance(base::TimeDelta::FromDays(5)); |
415 EXPECT_TRUE( | 446 PermissionResult result = |
416 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 447 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 448 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 449 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
417 | 450 |
418 // Record dismisses to place it under dismissal embargo. | 451 // Record dismisses to place it under dismissal embargo. |
419 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 452 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
420 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 453 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
421 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 454 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
422 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 455 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
423 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 456 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
424 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 457 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
425 | 458 |
426 // Accelerate time to a point where the blacklist embargo should be expired | 459 // Accelerate time to a point where the blacklist embargo should be expired |
427 // and check that dismissal embargo is still set. | 460 // and check that dismissal embargo is still set. |
428 clock()->Advance(base::TimeDelta::FromDays(3)); | 461 clock()->Advance(base::TimeDelta::FromDays(3)); |
429 EXPECT_TRUE( | 462 result = |
430 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 463 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 464 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 465 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
431 } | 466 } |
432 | 467 |
433 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { | 468 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
434 GURL url("https://www.google.com"); | 469 GURL url("https://www.google.com"); |
435 clock()->SetNow(base::Time::Now()); | 470 clock()->SetNow(base::Time::Now()); |
436 base::HistogramTester histograms; | 471 base::HistogramTester histograms; |
437 | 472 |
438 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 473 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
439 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, | 474 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, |
440 true /* enabled */); | 475 true /* enabled */); |
441 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 476 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
442 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 477 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
443 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 478 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
444 0 /* timeout in ms */); | 479 0 /* timeout in ms */); |
445 | 480 |
446 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); | 481 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
447 EXPECT_TRUE(callback_was_run()); | 482 EXPECT_TRUE(callback_was_run()); |
448 EXPECT_FALSE(last_embargoed_status()); | 483 EXPECT_FALSE(last_embargoed_status()); |
449 EXPECT_FALSE( | 484 |
450 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 485 PermissionResult result = |
| 486 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 487 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 488 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 489 |
451 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 490 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
452 SafeBrowsingResponse::TIMEOUT, 1); | 491 SafeBrowsingResponse::TIMEOUT, 1); |
453 histograms.ExpectTotalCount( | 492 histograms.ExpectTotalCount( |
454 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 493 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
455 db_manager->SetPerformCallback(true); | 494 db_manager->SetPerformCallback(true); |
456 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 495 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
457 2000 /* timeout in ms */); | 496 2000 /* timeout in ms */); |
458 | 497 |
459 clock()->Advance(base::TimeDelta::FromDays(1)); | 498 clock()->Advance(base::TimeDelta::FromDays(1)); |
460 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); | 499 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
461 EXPECT_TRUE(callback_was_run()); | 500 EXPECT_TRUE(callback_was_run()); |
462 EXPECT_TRUE(last_embargoed_status()); | 501 EXPECT_TRUE(last_embargoed_status()); |
463 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 502 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
464 2); | 503 2); |
465 histograms.ExpectTotalCount( | 504 histograms.ExpectTotalCount( |
466 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 2); | 505 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 2); |
467 histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 506 histograms.ExpectBucketCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
468 SafeBrowsingResponse::BLACKLISTED, 1); | 507 SafeBrowsingResponse::BLACKLISTED, 1); |
469 clock()->Advance(base::TimeDelta::FromDays(1)); | 508 clock()->Advance(base::TimeDelta::FromDays(1)); |
470 EXPECT_TRUE( | 509 result = |
471 autoblocker()->IsUnderEmbargo(CONTENT_SETTINGS_TYPE_GEOLOCATION, url)); | 510 autoblocker()->GetEmbargoResult(CONTENT_SETTINGS_TYPE_GEOLOCATION, url); |
| 511 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 512 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
472 } | 513 } |
473 | 514 |
474 // TODO(raymes): See crbug.com/681709. Remove after M60. | 515 // TODO(raymes): See crbug.com/681709. Remove after M60. |
475 TEST_F(PermissionDecisionAutoBlockerUnitTest, | 516 TEST_F(PermissionDecisionAutoBlockerUnitTest, |
476 MigrateNoDecisionCountToPermissionAutoBlockerData) { | 517 MigrateNoDecisionCountToPermissionAutoBlockerData) { |
477 GURL url("https://www.google.com"); | 518 GURL url("https://www.google.com"); |
478 auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); | 519 auto* map = HostContentSettingsMapFactory::GetForProfile(profile()); |
479 | 520 |
480 // Write to the old content setting. | 521 // Write to the old content setting. |
481 base::DictionaryValue permissions_dict; | 522 base::DictionaryValue permissions_dict; |
482 permissions_dict.SetInteger(GetDismissKey(), 100); | 523 permissions_dict.SetInteger(GetDismissKey(), 100); |
483 permissions_dict.SetInteger(GetIgnoreKey(), 50); | 524 permissions_dict.SetInteger(GetIgnoreKey(), 50); |
484 | 525 |
485 base::DictionaryValue origin_dict; | 526 base::DictionaryValue origin_dict; |
486 origin_dict.Set( | 527 origin_dict.Set( |
487 PermissionUtil::GetPermissionString(CONTENT_SETTINGS_TYPE_GEOLOCATION), | 528 PermissionUtil::GetPermissionString(CONTENT_SETTINGS_TYPE_GEOLOCATION), |
488 permissions_dict.CreateDeepCopy()); | 529 permissions_dict.CreateDeepCopy()); |
489 map->SetWebsiteSettingDefaultScope( | 530 map->SetWebsiteSettingDefaultScope( |
490 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, | 531 url, GURL(), CONTENT_SETTINGS_TYPE_PROMPT_NO_DECISION_COUNT, |
491 std::string(), origin_dict.CreateDeepCopy()); | 532 std::string(), origin_dict.CreateDeepCopy()); |
492 | 533 |
493 // Nothing should be migrated yet, so the current values should be 0. | 534 // Nothing should be migrated yet, so the current values should be 0. |
494 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 535 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
495 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 536 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
496 EXPECT_EQ(0, autoblocker()->GetIgnoreCount( | 537 EXPECT_EQ( |
497 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 538 0, autoblocker()->GetIgnoreCount(url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
498 | 539 |
499 // Trigger pref migration which happens at the creation of the | 540 // Trigger pref migration which happens at the creation of the |
500 // HostContentSettingsMap. | 541 // HostContentSettingsMap. |
501 { | 542 { |
502 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap( | 543 scoped_refptr<HostContentSettingsMap> temp_map(new HostContentSettingsMap( |
503 profile()->GetPrefs(), false /* is_incognito_profile */, | 544 profile()->GetPrefs(), false /* is_incognito_profile */, |
504 false /* is_guest_profile */)); | 545 false /* is_guest_profile */)); |
505 temp_map->ShutdownOnUIThread(); | 546 temp_map->ShutdownOnUIThread(); |
506 } | 547 } |
507 | 548 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 611 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
571 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 612 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
572 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 613 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
573 0 /* timeout in ms */); | 614 0 /* timeout in ms */); |
574 | 615 |
575 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); | 616 UpdateEmbargoedStatus(CONTENT_SETTINGS_TYPE_NOTIFICATIONS, url); |
576 EXPECT_FALSE(last_embargoed_status()); | 617 EXPECT_FALSE(last_embargoed_status()); |
577 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", | 618 histograms.ExpectUniqueSample("Permissions.AutoBlocker.SafeBrowsingResponse", |
578 SafeBrowsingResponse::NOT_BLACKLISTED, 1); | 619 SafeBrowsingResponse::NOT_BLACKLISTED, 1); |
579 } | 620 } |
OLD | NEW |