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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 result = | 481 result = |
467 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 482 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
468 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 483 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
469 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 484 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
470 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 485 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
471 0); | 486 0); |
472 histograms.ExpectTotalCount( | 487 histograms.ExpectTotalCount( |
473 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 488 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
474 } | 489 } |
475 | 490 |
| 491 // Tests the alternating pattern of the block on multiple ignores behaviour. |
| 492 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestIgnoreEmbargoBackoff) { |
| 493 GURL url("https://www.google.com"); |
| 494 clock()->SetNow(base::Time::Now()); |
| 495 base::HistogramTester histograms; |
| 496 |
| 497 // Record some ignores. |
| 498 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 499 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 500 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 501 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 502 |
| 503 // A request with < 4 prior ignores should not be automatically blocked. |
| 504 PermissionResult result = |
| 505 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 506 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 507 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 508 |
| 509 // After the 4th ignore subsequent permission requests should be autoblocked. |
| 510 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 511 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 512 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 513 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 514 result = |
| 515 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 516 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 517 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 518 |
| 519 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 520 0); |
| 521 histograms.ExpectTotalCount( |
| 522 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 523 // Accelerate time forward, check that the embargo status is lifted and the |
| 524 // request won't be automatically blocked. |
| 525 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 526 result = |
| 527 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 528 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 529 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 530 |
| 531 // Record another dismiss, subsequent requests should be autoblocked again. |
| 532 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 533 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 534 result = |
| 535 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 536 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 537 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 538 |
| 539 // Accelerate time again, check embargo is lifted and another permission |
| 540 // request is let through. |
| 541 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 542 result = |
| 543 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 544 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 545 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 546 |
| 547 // Record another dismiss, subsequent requests should be autoblocked again. |
| 548 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 549 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 550 result = |
| 551 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 552 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 553 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 554 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 555 0); |
| 556 histograms.ExpectTotalCount( |
| 557 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 558 } |
| 559 |
476 // Test the logic for a combination of blacklisting and dismissal embargo. | 560 // Test the logic for a combination of blacklisting and dismissal embargo. |
477 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { | 561 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiringOverlappingEmbargo) { |
478 GURL url("https://www.google.com"); | 562 GURL url("https://www.google.com"); |
479 clock()->SetNow(base::Time::Now()); | 563 clock()->SetNow(base::Time::Now()); |
480 | 564 |
481 // Place under blacklist embargo and check the status. | 565 // Place under blacklist embargo and check the status. |
482 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 566 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
483 clock()->Advance(base::TimeDelta::FromDays(5)); | 567 clock()->Advance(base::TimeDelta::FromDays(5)); |
484 PermissionResult result = | 568 PermissionResult result = |
485 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 569 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
486 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 570 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
487 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | 571 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
488 | 572 |
489 // Record dismisses to place it under dismissal embargo. | 573 // Record dismisses to place it under dismissal embargo. |
490 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 574 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
491 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 575 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
492 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 576 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
493 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 577 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
494 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 578 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
495 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 579 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
496 | 580 |
497 // Accelerate time to a point where the blacklist embargo should be expired | 581 // Accelerate time to a point where the blacklist embargo should be expired |
498 // and check that dismissal embargo is still set. | 582 // and check that dismissal embargo is still set. |
499 clock()->Advance(base::TimeDelta::FromDays(3)); | 583 clock()->Advance(base::TimeDelta::FromDays(3)); |
500 result = | 584 result = |
501 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 585 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
502 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 586 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
503 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 587 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
| 588 |
| 589 // Record an ignore embargo. |
| 590 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 591 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 592 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 593 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 594 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 595 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 596 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 597 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 598 |
| 599 // Ensure the ignore embargo is still set. |
| 600 clock()->Advance(base::TimeDelta::FromDays(5)); |
| 601 result = |
| 602 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 603 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 604 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
504 } | 605 } |
505 | 606 |
506 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { | 607 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
507 GURL url("https://www.google.com"); | 608 GURL url("https://www.google.com"); |
508 clock()->SetNow(base::Time::Now()); | 609 clock()->SetNow(base::Time::Now()); |
509 base::HistogramTester histograms; | 610 base::HistogramTester histograms; |
510 | 611 |
511 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 612 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
512 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, | 613 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, |
513 true /* enabled */); | 614 true /* enabled */); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 753 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
653 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 754 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
654 0 /* timeout in ms */); | 755 0 /* timeout in ms */); |
655 | 756 |
656 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 757 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
657 EXPECT_FALSE(last_embargoed_status()); | 758 EXPECT_FALSE(last_embargoed_status()); |
658 histograms.ExpectUniqueSample( | 759 histograms.ExpectUniqueSample( |
659 "Permissions.AutoBlocker.SafeBrowsingResponse", | 760 "Permissions.AutoBlocker.SafeBrowsingResponse", |
660 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); | 761 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); |
661 } | 762 } |
OLD | NEW |