| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "components/safe_browsing/password_protection/password_protection_servi
ce.h" | 4 #include "components/safe_browsing/password_protection/password_protection_servi
ce.h" |
| 5 | 5 |
| 6 #include "base/memory/ptr_util.h" | 6 #include "base/memory/ptr_util.h" |
| 7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "base/test/histogram_tester.h" | 9 #include "base/test/histogram_tester.h" |
| 10 #include "base/test/null_task_runner.h" | 10 #include "base/test/null_task_runner.h" |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 password_protection_service_->GetCachedVerdict( | 360 password_protection_service_->GetCachedVerdict( |
| 361 GURL("http://test.com/xyz/foo.jsp"), &actual_verdict)); | 361 GURL("http://test.com/xyz/foo.jsp"), &actual_verdict)); |
| 362 | 362 |
| 363 // Return VERDICT_TYPE_UNSPECIFIED if look up for a URL whose variants match | 363 // Return VERDICT_TYPE_UNSPECIFIED if look up for a URL whose variants match |
| 364 // test.com/def, but the corresponding verdict is expired. | 364 // test.com/def, but the corresponding verdict is expired. |
| 365 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, | 365 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, |
| 366 password_protection_service_->GetCachedVerdict( | 366 password_protection_service_->GetCachedVerdict( |
| 367 GURL("http://test.com/def/ghi/index.html"), &actual_verdict)); | 367 GURL("http://test.com/def/ghi/index.html"), &actual_verdict)); |
| 368 } | 368 } |
| 369 | 369 |
| 370 TEST_F(PasswordProtectionServiceTest, TestCleanUpCachedVerdicts) { | 370 TEST_F(PasswordProtectionServiceTest, TestRemoveCachedVerdictOnURLsDeleted) { |
| 371 ASSERT_EQ(0U, GetStoredVerdictCount()); | 371 ASSERT_EQ(0U, GetStoredVerdictCount()); |
| 372 // Prepare 2 verdicts. One is for origin "http://foo.com", and the other is | 372 // Prepare 2 verdicts. One is for origin "http://foo.com", and the other is |
| 373 // for "http://bar.com". | 373 // for "http://bar.com". |
| 374 base::Time now = base::Time::Now(); | 374 base::Time now = base::Time::Now(); |
| 375 CacheVerdict(GURL("http://foo.com/abc/index.jsp"), | 375 CacheVerdict(GURL("http://foo.com/abc/index.jsp"), |
| 376 LoginReputationClientResponse::LOW_REPUTATION, 10 * 60, | 376 LoginReputationClientResponse::LOW_REPUTATION, 10 * 60, |
| 377 "foo.com/abc", now); | 377 "foo.com/abc", now); |
| 378 CacheVerdict(GURL("http://bar.com/index.jsp"), | 378 CacheVerdict(GURL("http://bar.com/index.jsp"), |
| 379 LoginReputationClientResponse::PHISHING, 10 * 60, "bar.com", | 379 LoginReputationClientResponse::PHISHING, 10 * 60, "bar.com", |
| 380 now); | 380 now); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 396 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, | 396 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, |
| 397 password_protection_service_->GetCachedVerdict( | 397 password_protection_service_->GetCachedVerdict( |
| 398 GURL("http://bar.com"), &actual_verdict)); | 398 GURL("http://bar.com"), &actual_verdict)); |
| 399 | 399 |
| 400 // If delete all history. All password protection content settings should be | 400 // If delete all history. All password protection content settings should be |
| 401 // gone. | 401 // gone. |
| 402 password_protection_service_->RemoveContentSettingsOnURLsDeleted( | 402 password_protection_service_->RemoveContentSettingsOnURLsDeleted( |
| 403 true /* all_history */, history::URLRows()); | 403 true /* all_history */, history::URLRows()); |
| 404 EXPECT_EQ(0U, GetStoredVerdictCount()); | 404 EXPECT_EQ(0U, GetStoredVerdictCount()); |
| 405 } | 405 } |
| 406 |
| 406 TEST_F(PasswordProtectionServiceTest, | 407 TEST_F(PasswordProtectionServiceTest, |
| 407 TestNoRequestCreatedIfMainFrameURLIsNotValid) { | 408 TestNoRequestCreatedIfMainFrameURLIsNotValid) { |
| 408 ASSERT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); | 409 ASSERT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); |
| 409 password_protection_service_->MaybeStartLowReputationRequest( | 410 password_protection_service_->MaybeStartLowReputationRequest( |
| 410 GURL(), GURL("http://foo.com/submit"), GURL("http://foo.com/frame")); | 411 GURL(), GURL("http://foo.com/submit"), GURL("http://foo.com/frame")); |
| 411 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); | 412 EXPECT_EQ(0u, password_protection_service_->GetPendingRequestsCount()); |
| 412 } | 413 } |
| 413 | 414 |
| 414 TEST_F(PasswordProtectionServiceTest, | 415 TEST_F(PasswordProtectionServiceTest, |
| 415 TestNoRequestCreatedIfMainFrameURLIsNotHttpOrHttps) { | 416 TestNoRequestCreatedIfMainFrameURLIsNotHttpOrHttps) { |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 target_url, GURL("http://foo.com/submit"), GURL("http://foo.com/frame"), | 532 target_url, GURL("http://foo.com/submit"), GURL("http://foo.com/frame"), |
| 532 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); | 533 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); |
| 533 | 534 |
| 534 // Destroy password_protection_service_ while there is one request pending. | 535 // Destroy password_protection_service_ while there is one request pending. |
| 535 password_protection_service_.reset(); | 536 password_protection_service_.reset(); |
| 536 base::RunLoop().RunUntilIdle(); | 537 base::RunLoop().RunUntilIdle(); |
| 537 | 538 |
| 538 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), | 539 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), |
| 539 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); | 540 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); |
| 540 } | 541 } |
| 542 |
| 543 TEST_F(PasswordProtectionServiceTest, TestCleanUpExpiredVerdict) { |
| 544 ASSERT_EQ(0U, GetStoredVerdictCount()); |
| 545 // Prepare 4 verdicts: |
| 546 // (1) "foo.com/abc" valid |
| 547 // (2) "foo.com/def" expired |
| 548 // (3) "bar.com/abc" expired |
| 549 // (4) "bar.com/def" expired |
| 550 base::Time now = base::Time::Now(); |
| 551 CacheVerdict(GURL("https://foo.com/abc/index.jsp"), |
| 552 LoginReputationClientResponse::LOW_REPUTATION, 10 * 60, |
| 553 "foo.com/abc", now); |
| 554 CacheVerdict(GURL("https://foo.com/def/index.jsp"), |
| 555 LoginReputationClientResponse::LOW_REPUTATION, 0, "foo.com/def", |
| 556 now); |
| 557 CacheVerdict(GURL("https://bar.com/abc/index.jsp"), |
| 558 LoginReputationClientResponse::PHISHING, 0, "bar.com/abc", now); |
| 559 CacheVerdict(GURL("https://bar.com/def/index.jsp"), |
| 560 LoginReputationClientResponse::PHISHING, 0, "bar.com/def", now); |
| 561 ASSERT_EQ(4U, GetStoredVerdictCount()); |
| 562 |
| 563 password_protection_service_->CleanUpExpiredVerdicts(); |
| 564 |
| 565 ASSERT_EQ(1U, GetStoredVerdictCount()); |
| 566 LoginReputationClientResponse actual_verdict; |
| 567 // Has cached verdict for foo.com/abc. |
| 568 EXPECT_EQ(LoginReputationClientResponse::LOW_REPUTATION, |
| 569 password_protection_service_->GetCachedVerdict( |
| 570 GURL("https://foo.com/abc/test.jsp"), &actual_verdict)); |
| 571 // No cached verdict for foo.com/def. |
| 572 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, |
| 573 password_protection_service_->GetCachedVerdict( |
| 574 GURL("https://foo.com/def/index.jsp"), &actual_verdict)); |
| 575 // Nothing in content setting for bar.com. |
| 576 EXPECT_EQ(nullptr, content_setting_map_->GetWebsiteSetting( |
| 577 GURL("https://bar.com"), GURL(), |
| 578 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 579 std::string(), nullptr)); |
| 580 } |
| 541 } // namespace safe_browsing | 581 } // namespace safe_browsing |
| OLD | NEW |