| 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); |
| 301 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 316 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 302 0 /* timeout in ms */); | 317 0 /* timeout in ms */); |
| 303 | 318 |
| 304 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 319 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 305 EXPECT_FALSE(last_embargoed_status()); | 320 EXPECT_FALSE(last_embargoed_status()); |
| 306 histograms.ExpectUniqueSample( | 321 histograms.ExpectUniqueSample( |
| 307 "Permissions.AutoBlocker.SafeBrowsingResponse", | 322 "Permissions.AutoBlocker.SafeBrowsingResponse", |
| 308 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); | 323 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); |
| 309 histograms.ExpectTotalCount( | 324 histograms.ExpectTotalCount( |
| 310 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); | 325 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 1); |
| 311 } | 326 } |
| 312 | 327 |
| 313 // Check that we do not apply embargo to the plugins content type, as prompts | 328 // Check that we do not apply embargo to the plugins content type, as prompts |
| 314 // should be triggered only when necessary by Html5ByDefault. | 329 // should be triggered only when necessary by Html5ByDefault. |
| 315 TEST_F(PermissionDecisionAutoBlockerUnitTest, | 330 TEST_F(PermissionDecisionAutoBlockerUnitTest, |
| 316 PluginsNotEmbargoedByMultipleDismisses) { | 331 PluginsNotEmbargoedByMultipleDismissesOrIgnores) { |
| 317 GURL url("https://www.google.com"); | 332 GURL url("https://www.google.com"); |
| 333 |
| 334 // Check dismisses first. |
| 318 autoblocker()->RecordDismissAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 335 autoblocker()->RecordDismissAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 319 autoblocker()->RecordDismissAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 336 autoblocker()->RecordDismissAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 320 PermissionResult result = | 337 PermissionResult result = |
| 321 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 338 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 322 | 339 |
| 323 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | 340 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 324 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | 341 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 325 EXPECT_EQ(2, | 342 EXPECT_EQ(2, |
| 326 autoblocker()->GetDismissCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); | 343 autoblocker()->GetDismissCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 327 | 344 |
| 328 // The third dismiss would normally embargo, but this shouldn't happen for | 345 // The third dismiss would normally embargo, but this shouldn't happen for |
| 329 // plugins. | 346 // plugins. |
| 330 autoblocker()->RecordDismissAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 347 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 348 url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 331 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 349 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 332 | 350 |
| 333 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | 351 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 334 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | 352 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 335 EXPECT_EQ(3, | 353 EXPECT_EQ(3, |
| 336 autoblocker()->GetDismissCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); | 354 autoblocker()->GetDismissCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 337 | 355 |
| 338 // Extra one for sanity checking. | 356 // Extra one for sanity checking. |
| 339 autoblocker()->RecordDismissAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 357 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 358 url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 340 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); | 359 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 341 | 360 |
| 342 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); | 361 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 343 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); | 362 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 344 EXPECT_EQ(4, | 363 EXPECT_EQ(4, |
| 345 autoblocker()->GetDismissCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); | 364 autoblocker()->GetDismissCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 365 |
| 366 // Check ignores. |
| 367 autoblocker()->RecordIgnoreAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 368 autoblocker()->RecordIgnoreAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 369 autoblocker()->RecordIgnoreAndEmbargo(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 370 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 371 |
| 372 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 373 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 374 EXPECT_EQ(3, |
| 375 autoblocker()->GetIgnoreCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 376 |
| 377 // The fourth ignore would normally embargo, but this shouldn't happen for |
| 378 // plugins. |
| 379 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 380 url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 381 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 382 |
| 383 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 384 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 385 EXPECT_EQ(4, |
| 386 autoblocker()->GetIgnoreCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 387 |
| 388 // Extra one for sanity checking. |
| 389 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 390 url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 391 result = autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_PLUGINS); |
| 392 |
| 393 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 394 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 395 EXPECT_EQ(5, |
| 396 autoblocker()->GetIgnoreCount(url, CONTENT_SETTINGS_TYPE_PLUGINS)); |
| 346 } | 397 } |
| 347 | 398 |
| 348 // Check that GetEmbargoResult returns the correct value when the embargo is set | 399 // Check that GetEmbargoResult returns the correct value when the embargo is set |
| 349 // and expires. | 400 // and expires. |
| 350 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { | 401 TEST_F(PermissionDecisionAutoBlockerUnitTest, CheckEmbargoStatus) { |
| 351 GURL url("https://www.google.com"); | 402 GURL url("https://www.google.com"); |
| 352 clock()->SetNow(base::Time::Now()); | 403 clock()->SetNow(base::Time::Now()); |
| 353 | 404 |
| 354 // Check the default state. | 405 // Check the default state. |
| 355 PermissionResult result = | 406 PermissionResult result = |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 result = | 517 result = |
| 467 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 518 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 468 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 519 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 469 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 520 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
| 470 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", | 521 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 471 0); | 522 0); |
| 472 histograms.ExpectTotalCount( | 523 histograms.ExpectTotalCount( |
| 473 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); | 524 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 474 } | 525 } |
| 475 | 526 |
| 527 // Tests the alternating pattern of the block on multiple ignores behaviour. |
| 528 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestIgnoreEmbargoBackoff) { |
| 529 GURL url("https://www.google.com"); |
| 530 clock()->SetNow(base::Time::Now()); |
| 531 base::HistogramTester histograms; |
| 532 |
| 533 // Record some ignores. |
| 534 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 535 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 536 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 537 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 538 |
| 539 // A request with < 4 prior ignores should not be automatically blocked. |
| 540 PermissionResult result = |
| 541 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 542 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 543 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 544 |
| 545 // After the 4th ignore subsequent permission requests should be autoblocked. |
| 546 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 547 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 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 |
| 555 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 556 0); |
| 557 histograms.ExpectTotalCount( |
| 558 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 559 // Accelerate time forward, check that the embargo status is lifted and the |
| 560 // request won't be automatically blocked. |
| 561 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 562 result = |
| 563 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 564 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 565 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 566 |
| 567 // Record another dismiss, subsequent requests should be autoblocked again. |
| 568 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 569 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 570 result = |
| 571 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 572 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 573 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 574 |
| 575 // Accelerate time again, check embargo is lifted and another permission |
| 576 // request is let through. |
| 577 clock()->Advance(base::TimeDelta::FromDays(8)); |
| 578 result = |
| 579 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 580 EXPECT_EQ(CONTENT_SETTING_ASK, result.content_setting); |
| 581 EXPECT_EQ(PermissionStatusSource::UNSPECIFIED, result.source); |
| 582 |
| 583 // Record another dismiss, subsequent requests should be autoblocked again. |
| 584 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 585 url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX)); |
| 586 result = |
| 587 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_MIDI_SYSEX); |
| 588 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 589 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 590 histograms.ExpectTotalCount("Permissions.AutoBlocker.SafeBrowsingResponse", |
| 591 0); |
| 592 histograms.ExpectTotalCount( |
| 593 "Permissions.AutoBlocker.SafeBrowsingResponseTime", 0); |
| 594 } |
| 595 |
| 476 // Test the logic for a combination of blacklisting and dismissal embargo. | 596 // Test the logic for a combination of blacklisting and dismissal embargo. |
| 477 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiredBlacklistEmbargo) { | 597 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestExpiringOverlappingEmbargo) { |
| 478 GURL url("https://www.google.com"); | 598 GURL url("https://www.google.com"); |
| 479 clock()->SetNow(base::Time::Now()); | 599 clock()->SetNow(base::Time::Now()); |
| 480 | 600 |
| 481 // Place under blacklist embargo and check the status. | 601 // Place under blacklist embargo and check the status. |
| 482 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 602 PlaceUnderBlacklistEmbargo(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 483 clock()->Advance(base::TimeDelta::FromDays(5)); | 603 clock()->Advance(base::TimeDelta::FromDays(5)); |
| 484 PermissionResult result = | 604 PermissionResult result = |
| 485 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 605 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 486 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 606 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 487 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); | 607 EXPECT_EQ(PermissionStatusSource::SAFE_BROWSING_BLACKLIST, result.source); |
| 488 | 608 |
| 489 // Record dismisses to place it under dismissal embargo. | 609 // Record dismisses to place it under dismissal embargo. |
| 490 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 610 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 491 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 611 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 492 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( | 612 EXPECT_FALSE(autoblocker()->RecordDismissAndEmbargo( |
| 493 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 613 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 494 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( | 614 EXPECT_TRUE(autoblocker()->RecordDismissAndEmbargo( |
| 495 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); | 615 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 496 | 616 |
| 497 // Accelerate time to a point where the blacklist embargo should be expired | 617 // Accelerate time to a point where the blacklist embargo should be expired |
| 498 // and check that dismissal embargo is still set. | 618 // and check that dismissal embargo is still set. |
| 499 clock()->Advance(base::TimeDelta::FromDays(3)); | 619 clock()->Advance(base::TimeDelta::FromDays(3)); |
| 500 result = | 620 result = |
| 501 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); | 621 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 502 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); | 622 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 503 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); | 623 EXPECT_EQ(PermissionStatusSource::MULTIPLE_DISMISSALS, result.source); |
| 624 |
| 625 // Record an ignore embargo. |
| 626 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 627 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 628 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 629 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 630 EXPECT_FALSE(autoblocker()->RecordIgnoreAndEmbargo( |
| 631 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 632 EXPECT_TRUE(autoblocker()->RecordIgnoreAndEmbargo( |
| 633 url, CONTENT_SETTINGS_TYPE_GEOLOCATION)); |
| 634 |
| 635 // Ensure the ignore embargo is still set. |
| 636 clock()->Advance(base::TimeDelta::FromDays(5)); |
| 637 result = |
| 638 autoblocker()->GetEmbargoResult(url, CONTENT_SETTINGS_TYPE_GEOLOCATION); |
| 639 EXPECT_EQ(CONTENT_SETTING_BLOCK, result.content_setting); |
| 640 EXPECT_EQ(PermissionStatusSource::MULTIPLE_IGNORES, result.source); |
| 504 } | 641 } |
| 505 | 642 |
| 506 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { | 643 TEST_F(PermissionDecisionAutoBlockerUnitTest, TestSafeBrowsingTimeout) { |
| 507 GURL url("https://www.google.com"); | 644 GURL url("https://www.google.com"); |
| 508 clock()->SetNow(base::Time::Now()); | 645 clock()->SetNow(base::Time::Now()); |
| 509 base::HistogramTester histograms; | 646 base::HistogramTester histograms; |
| 510 | 647 |
| 511 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = | 648 scoped_refptr<MockSafeBrowsingDatabaseManager> db_manager = |
| 512 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, | 649 new MockSafeBrowsingDatabaseManager(false /* perform_callback */, |
| 513 true /* enabled */); | 650 true /* enabled */); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 652 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); | 789 db_manager->BlacklistUrlPermissions(url, blacklisted_permissions); |
| 653 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, | 790 SetSafeBrowsingDatabaseManagerAndTimeoutForTesting(db_manager, |
| 654 0 /* timeout in ms */); | 791 0 /* timeout in ms */); |
| 655 | 792 |
| 656 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); | 793 CheckSafeBrowsingBlacklist(url, CONTENT_SETTINGS_TYPE_NOTIFICATIONS); |
| 657 EXPECT_FALSE(last_embargoed_status()); | 794 EXPECT_FALSE(last_embargoed_status()); |
| 658 histograms.ExpectUniqueSample( | 795 histograms.ExpectUniqueSample( |
| 659 "Permissions.AutoBlocker.SafeBrowsingResponse", | 796 "Permissions.AutoBlocker.SafeBrowsingResponse", |
| 660 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); | 797 static_cast<int>(SafeBrowsingResponse::NOT_BLACKLISTED), 1); |
| 661 } | 798 } |
| OLD | NEW |