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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 | 82 |
83 } // namespace | 83 } // namespace |
84 | 84 |
85 class PermissionDecisionAutoBlockerUnitTest | 85 class PermissionDecisionAutoBlockerUnitTest |
86 : public ChromeRenderViewHostTestHarness { | 86 : public ChromeRenderViewHostTestHarness { |
87 protected: | 87 protected: |
88 void SetUp() override { | 88 void SetUp() override { |
89 ChromeRenderViewHostTestHarness::SetUp(); | 89 ChromeRenderViewHostTestHarness::SetUp(); |
90 autoblocker_ = PermissionDecisionAutoBlocker::GetForProfile(profile()); | 90 autoblocker_ = PermissionDecisionAutoBlocker::GetForProfile(profile()); |
91 feature_list_.InitWithFeatures({features::kBlockPromptsIfDismissedOften, | 91 feature_list_.InitWithFeatures({features::kBlockPromptsIfDismissedOften, |
| 92 features::kBlockPromptsIfIgnoredOften, |
92 features::kPermissionsBlacklist}, | 93 features::kPermissionsBlacklist}, |
93 {}); | 94 {}); |
94 last_embargoed_status_ = false; | 95 last_embargoed_status_ = false; |
95 std::unique_ptr<base::SimpleTestClock> clock = | 96 std::unique_ptr<base::SimpleTestClock> clock = |
96 base::MakeUnique<base::SimpleTestClock>(); | 97 base::MakeUnique<base::SimpleTestClock>(); |
97 clock_ = clock.get(); | 98 clock_ = clock.get(); |
98 autoblocker_->SetClockForTesting(std::move(clock)); | 99 autoblocker_->SetClockForTesting(std::move(clock)); |
99 callback_was_run_ = false; | 100 callback_was_run_ = false; |
100 } | 101 } |
101 | 102 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 184 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
184 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 185 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
185 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 186 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
186 | 187 |
187 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 188 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
188 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 189 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
189 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 190 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
190 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 191 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
191 | 192 |
192 // Record some ignores. | 193 // Record some ignores. |
| 194 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 195 url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
193 EXPECT_EQ( | 196 EXPECT_EQ( |
194 1, autoblocker()->RecordIgnore(url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 197 1, autoblocker()->GetIgnoreCount(url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
195 EXPECT_EQ(1, autoblocker()->RecordIgnore( | 198 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 199 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 200 EXPECT_EQ(1, autoblocker()->GetIgnoreCount( |
196 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); | 201 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
197 EXPECT_EQ( | 202 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
198 1, autoblocker()->RecordIgnore(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 203 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
199 EXPECT_EQ( | 204 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
200 2, autoblocker()->RecordIgnore(url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 205 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 206 EXPECT_EQ(2, autoblocker()->GetIgnoreCount( |
| 207 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
201 | 208 |
202 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterGoogle)); | 209 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterGoogle)); |
203 | 210 |
204 // Expect that url1's actions are gone, but url2's remain. | 211 // Expect that url1's actions are gone, but url2's remain. |
205 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 212 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
206 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 213 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
207 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 214 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
208 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 215 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
209 EXPECT_EQ( | 216 EXPECT_EQ( |
210 0, autoblocker()->GetIgnoreCount(url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | 217 0, autoblocker()->GetIgnoreCount(url1, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
(...skipping 14 matching lines...) Expand all Loading... |
225 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 232 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
226 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 233 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
227 EXPECT_EQ(1, autoblocker()->GetDismissCount( | 234 EXPECT_EQ(1, autoblocker()->GetDismissCount( |
228 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 235 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
229 | 236 |
230 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 237 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
231 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 238 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
232 EXPECT_EQ(2, autoblocker()->GetDismissCount( | 239 EXPECT_EQ(2, autoblocker()->GetDismissCount( |
233 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 240 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
234 | 241 |
| 242 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 243 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 244 EXPECT_EQ(1, autoblocker()->GetIgnoreCount( |
| 245 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 246 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 247 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 248 EXPECT_EQ(1, autoblocker()->GetIgnoreCount( |
| 249 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
| 250 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 251 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 252 EXPECT_EQ(1, autoblocker()->GetIgnoreCount( |
| 253 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); |
| 254 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 255 url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
235 EXPECT_EQ( | 256 EXPECT_EQ( |
236 1, autoblocker()->RecordIgnore(url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 257 1, autoblocker()->GetIgnoreCount(url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
237 EXPECT_EQ(1, autoblocker()->RecordIgnore( | |
238 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | |
239 EXPECT_EQ(1, autoblocker()->RecordIgnore( | |
240 url1, CONTENT_SETTINGS_TYPE_DURABLE_STORAGE)); | |
241 EXPECT_EQ( | |
242 1, autoblocker()->RecordIgnore(url2, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); | |
243 | 258 |
244 // Remove everything and expect that it's all gone. | 259 // Remove everything and expect that it's all gone. |
245 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterAll)); | 260 autoblocker()->RemoveCountsByUrl(base::Bind(&FilterAll)); |
246 | 261 |
247 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 262 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
248 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 263 url1, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
249 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 264 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
250 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); | 265 url1, CONTENT_SETTINGS_TYPE_NOTIFICATIONS)); |
251 EXPECT_EQ(0, autoblocker()->GetDismissCount( | 266 EXPECT_EQ(0, autoblocker()->GetDismissCount( |
252 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 267 url2, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
(...skipping 27 matching lines...) Expand all Loading... |
280 EXPECT_TRUE(callback_was_run()); | 295 EXPECT_TRUE(callback_was_run()); |
281 EXPECT_TRUE(last_embargoed_status()); | 296 EXPECT_TRUE(last_embargoed_status()); |
282 histograms.ExpectUniqueSample( | 297 histograms.ExpectUniqueSample( |
283 "Permissions.AutoBlocker.SafeBrowsingResponse", | 298 "Permissions.AutoBlocker.SafeBrowsingResponse", |
284 static_cast<int>(SafeBrowsingResponse::BLACKLISTED), 1); | 299 static_cast<int>(SafeBrowsingResponse::BLACKLISTED), 1); |
285 histograms.ExpectTotalCount( | 300 histograms.ExpectTotalCount( |
286 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 301 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
287 } | 302 } |
288 | 303 |
289 // Test that an origin that is blacklisted for a permission will not be placed | 304 // Test that an origin that is blacklisted for a permission will not be placed |
290 // under embargoed for another. | 305 // under embargo for another permission. |
291 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestRequestNotBlacklisted) { | 306 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestRequestNotBlacklisted) { |
292 GURL url("https://www.google.com"); | 307 GURL url("https://www.google.com"); |
293 clock()->SetNow(base::Time::Now()); | 308 clock()->SetNow(base::Time::Now()); |
294 base::HistogramTester histograms; | 309 base::HistogramTester histograms; |
295 | 310 |
296 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 311 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
297 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, | 312 new MockSafeBrowsingDatabaseManager(true /* perform_callback */, |
298 true /* enabled */); | 313 true /* enabled */); |
299 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; | 314 std::set<std::string> blacklisted_permissions{"GEOLOCATION"}; |
300 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 315 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 result = | 446 result = |
432 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 447 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
433 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 448 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
434 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 449 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
435 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 450 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
436 0); | 451 0); |
437 histograms.ExpectTotalCount( | 452 histograms.ExpectTotalCount( |
438 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 453 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
439 } | 454 } |
440 | 455 |
| 456 // Tests the alternating pattern of the block on multiple ignores behaviour. |
| 457 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestIgnoreEmbargoBackoff) { |
| 458 GURL url("https://www.google.com"); |
| 459 clock()->SetNow(base::Time::Now()); |
| 460 base::HistogramTester histograms; |
| 461 |
| 462 // Record some ignores. |
| 463 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 464 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 465 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 466 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 467 |
| 468 // A request with < 4 prior ignores should not be automatically blocked. |
| 469 PermissionResult result = |
| 470 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 471 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 472 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 473 |
| 474 // After the 4th ignore subsequent permission requests should be autoblocked. |
| 475 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 476 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 477 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 478 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 479 result = |
| 480 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 481 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 482 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 483 |
| 484 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 485 0); |
| 486 histograms.ExpectTotalCount( |
| 487 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 488 // Accelerate time forward, check that the embargo status is lifted and the |
| 489 // request won't be automatically blocked. |
| 490 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 491 result = |
| 492 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 493 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 494 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 495 |
| 496 // Record another dismiss, subsequent requests should be autoblocked again. |
| 497 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 498 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 499 result = |
| 500 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 501 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 502 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 503 |
| 504 // Accelerate time again, check embargo is lifted and another permission |
| 505 // request is let through. |
| 506 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 507 result = |
| 508 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 509 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 510 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 511 |
| 512 // Record another dismiss, subsequent requests should be autoblocked again. |
| 513 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 514 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 515 result = |
| 516 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 517 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 518 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 519 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 520 0); |
| 521 histograms.ExpectTotalCount( |
| 522 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 523 } |
| 524 |
441 // Test the logic for a combination of blacklisting and dismissal embargo. | 525 // Test the logic for a combination of blacklisting and dismissal embargo. |
442 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { | 526 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiringOverlappingEmbargo) { |
443 GURL url("https://www.google.com"); | 527 GURL url("https://www.google.com"); |
444 clock()->SetNow(base::Time::Now()); | 528 clock()->SetNow(base::Time::Now()); |
445 | 529 |
446 // Place under blacklist embargo and check the status. | 530 // Place under blacklist embargo and check the status. |
447 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 531 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
448 clock()->Advance(base::TimeDelta::FromDays(5)); | 532 clock()->Advance(base::TimeDelta::FromDays(5)); |
449 PermissionResult result = | 533 PermissionResult result = |
450 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 534 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
451 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 535 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
452 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | 536 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
453 | 537 |
454 // Record dismisses to place it under dismissal embargo. | 538 // Record dismisses to place it under dismissal embargo. |
455 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 539 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
456 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 540 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
457 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 541 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
458 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 542 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
459 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 543 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
460 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 544 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
461 | 545 |
462 // Accelerate time to a point where the blacklist embargo should be expired | 546 // Accelerate time to a point where the blacklist embargo should be expired |
463 // and check that dismissal embargo is still set. | 547 // and check that dismissal embargo is still set. |
464 clock()->Advance(base::TimeDelta::FromDays(3)); | 548 clock()->Advance(base::TimeDelta::FromDays(3)); |
465 result = | 549 result = |
466 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 550 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
467 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 551 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
468 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 552 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
| 553 |
| 554 // Record an ignore embargo. |
| 555 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 556 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 557 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 558 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 559 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 560 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 561 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 562 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 563 |
| 564 // Ensure the ignore embargo is still set. |
| 565 clock()->Advance(base::TimeDelta::FromDays(5)); |
| 566 result = |
| 567 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 568 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 569 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
469 } | 570 } |
470 | 571 |
471 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { | 572 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
472 GURL url("https://www.google.com"); | 573 GURL url("https://www.google.com"); |
473 clock()->SetNow(base::Time::Now()); | 574 clock()->SetNow(base::Time::Now()); |
474 base::HistogramTester histograms; | 575 base::HistogramTester histograms; |
475 | 576 |
476 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 577 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
477 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, | 578 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, |
478 true /* enabled */); | 579 true /* enabled */); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 718 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
618 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 719 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
619 0 /* timeout in ms */); | 720 0 /* timeout in ms */); |
620 | 721 |
621 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 722 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
622 EXPECT_FALSE(last_embargoed_status()); | 723 EXPECT_FALSE(last_embargoed_status()); |
623 histograms.ExpectUniqueSample( | 724 histograms.ExpectUniqueSample( |
624 "Permissions.AutoBlocker.SafeBrowsingResponse", | 725 "Permissions.AutoBlocker.SafeBrowsingResponse", |
625 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); | 726 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); |
626 } | 727 } |
OLD | NEW |