| 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 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 146 |
| 147 void TearDown() override { content_setting_map_->ShutdownOnUIThread(); } | 147 void TearDown() override { content_setting_map_->ShutdownOnUIThread(); } |
| 148 | 148 |
| 149 // Sets up |database_manager_| and |requests_| as needed. | 149 // Sets up |database_manager_| and |requests_| as needed. |
| 150 void InitializeAndStartRequest(bool match_whitelist, int timeout_in_ms) { | 150 void InitializeAndStartRequest(bool match_whitelist, int timeout_in_ms) { |
| 151 GURL target_url(kTargetUrl); | 151 GURL target_url(kTargetUrl); |
| 152 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 152 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 153 .WillRepeatedly(testing::Return(match_whitelist)); | 153 .WillRepeatedly(testing::Return(match_whitelist)); |
| 154 | 154 |
| 155 request_ = new PasswordProtectionRequest( | 155 request_ = new PasswordProtectionRequest( |
| 156 target_url, GURL(), GURL(), | 156 target_url, GURL(), GURL(), std::string(), |
| 157 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, | 157 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, |
| 158 password_protection_service_.get(), timeout_in_ms); | 158 password_protection_service_.get(), timeout_in_ms); |
| 159 request_->Start(); | 159 request_->Start(); |
| 160 } | 160 } |
| 161 | 161 |
| 162 bool PathVariantsMatchCacheExpression(const GURL& url, | 162 bool PathVariantsMatchCacheExpression(const GURL& url, |
| 163 const std::string& cache_expression) { | 163 const std::string& cache_expression) { |
| 164 std::vector<std::string> paths; | 164 std::vector<std::string> paths; |
| 165 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); | 165 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); |
| 166 return PasswordProtectionService::PathVariantsMatchCacheExpression( | 166 return PasswordProtectionService::PathVariantsMatchCacheExpression( |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 actual_response->cache_duration_sec()); | 523 actual_response->cache_duration_sec()); |
| 524 } | 524 } |
| 525 | 525 |
| 526 TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) { | 526 TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) { |
| 527 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0); | 527 histograms_.ExpectTotalCount(kRequestOutcomeHistogramName, 0); |
| 528 GURL target_url(kTargetUrl); | 528 GURL target_url(kTargetUrl); |
| 529 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 529 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 530 .WillRepeatedly(testing::Return(false)); | 530 .WillRepeatedly(testing::Return(false)); |
| 531 password_protection_service_->StartRequest( | 531 password_protection_service_->StartRequest( |
| 532 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"), |
| 533 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); | 533 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); |
| 534 | 534 |
| 535 // Destroy password_protection_service_ while there is one request pending. | 535 // Destroy password_protection_service_ while there is one request pending. |
| 536 password_protection_service_.reset(); | 536 password_protection_service_.reset(); |
| 537 base::RunLoop().RunUntilIdle(); | 537 base::RunLoop().RunUntilIdle(); |
| 538 | 538 |
| 539 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), | 539 EXPECT_THAT(histograms_.GetAllSamples(kRequestOutcomeHistogramName), |
| 540 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); | 540 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); |
| 541 } | 541 } |
| 542 | 542 |
| 543 TEST_F(PasswordProtectionServiceTest, TestCleanUpExpiredVerdict) { | 543 TEST_F(PasswordProtectionServiceTest, TestCleanUpExpiredVerdict) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 572 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, | 572 EXPECT_EQ(LoginReputationClientResponse::VERDICT_TYPE_UNSPECIFIED, |
| 573 password_protection_service_->GetCachedVerdict( | 573 password_protection_service_->GetCachedVerdict( |
| 574 GURL("https://foo.com/def/index.jsp"), &actual_verdict)); | 574 GURL("https://foo.com/def/index.jsp"), &actual_verdict)); |
| 575 // Nothing in content setting for bar.com. | 575 // Nothing in content setting for bar.com. |
| 576 EXPECT_EQ(nullptr, content_setting_map_->GetWebsiteSetting( | 576 EXPECT_EQ(nullptr, content_setting_map_->GetWebsiteSetting( |
| 577 GURL("https://bar.com"), GURL(), | 577 GURL("https://bar.com"), GURL(), |
| 578 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, | 578 CONTENT_SETTINGS_TYPE_PASSWORD_PROTECTION, |
| 579 std::string(), nullptr)); | 579 std::string(), nullptr)); |
| 580 } | 580 } |
| 581 } // namespace safe_browsing | 581 } // namespace safe_browsing |
| OLD | NEW |