| 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/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/test/histogram_tester.h" | 10 #include "base/test/histogram_tester.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 // Sets up |database_manager_| and |requests_| as needed. | 165 // Sets up |database_manager_| and |requests_| as needed. |
| 166 void InitializeAndStartPasswordOnFocusRequest(bool match_whitelist, | 166 void InitializeAndStartPasswordOnFocusRequest(bool match_whitelist, |
| 167 int timeout_in_ms) { | 167 int timeout_in_ms) { |
| 168 GURL target_url(kTargetUrl); | 168 GURL target_url(kTargetUrl); |
| 169 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 169 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 170 .WillRepeatedly(testing::Return(match_whitelist)); | 170 .WillRepeatedly(testing::Return(match_whitelist)); |
| 171 | 171 |
| 172 request_ = new PasswordProtectionRequest( | 172 request_ = new PasswordProtectionRequest( |
| 173 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl), | 173 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl), |
| 174 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, | 174 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, |
| 175 password_protection_service_.get(), timeout_in_ms); | 175 true, password_protection_service_.get(), timeout_in_ms); |
| 176 request_->Start(); | 176 request_->Start(); |
| 177 } | 177 } |
| 178 | 178 |
| 179 void InitializeAndStartPasswordEntryRequest(bool match_whitelist, | 179 void InitializeAndStartPasswordEntryRequest(bool match_whitelist, |
| 180 int timeout_in_ms) { | 180 int timeout_in_ms) { |
| 181 GURL target_url(kTargetUrl); | 181 GURL target_url(kTargetUrl); |
| 182 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 182 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 183 .WillRepeatedly(testing::Return(match_whitelist)); | 183 .WillRepeatedly(testing::Return(match_whitelist)); |
| 184 | 184 |
| 185 request_ = new PasswordProtectionRequest( | 185 request_ = new PasswordProtectionRequest( |
| 186 nullptr, target_url, GURL(), GURL(), std::string(kSavedDomain), | 186 nullptr, target_url, GURL(), GURL(), std::string(kSavedDomain), |
| 187 LoginReputationClientRequest::PASSWORD_REUSE_EVENT, | 187 LoginReputationClientRequest::PASSWORD_REUSE_EVENT, true, |
| 188 password_protection_service_.get(), timeout_in_ms); | 188 password_protection_service_.get(), timeout_in_ms); |
| 189 request_->Start(); | 189 request_->Start(); |
| 190 } | 190 } |
| 191 | 191 |
| 192 bool PathVariantsMatchCacheExpression(const GURL& url, | 192 bool PathVariantsMatchCacheExpression(const GURL& url, |
| 193 const std::string& cache_expression) { | 193 const std::string& cache_expression) { |
| 194 std::vector<std::string> paths; | 194 std::vector<std::string> paths; |
| 195 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); | 195 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); |
| 196 return PasswordProtectionService::PathVariantsMatchCacheExpression( | 196 return PasswordProtectionService::PathVariantsMatchCacheExpression( |
| 197 paths, | 197 paths, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 541 } |
| 542 | 542 |
| 543 TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) { | 543 TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) { |
| 544 histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); | 544 histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
| 545 GURL target_url(kTargetUrl); | 545 GURL target_url(kTargetUrl); |
| 546 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 546 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 547 .WillRepeatedly(testing::Return(false)); | 547 .WillRepeatedly(testing::Return(false)); |
| 548 password_protection_service_->StartRequest( | 548 password_protection_service_->StartRequest( |
| 549 nullptr, target_url, GURL("http://foo.com/submit"), | 549 nullptr, target_url, GURL("http://foo.com/submit"), |
| 550 GURL("http://foo.com/frame"), std::string(), | 550 GURL("http://foo.com/frame"), std::string(), |
| 551 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); | 551 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, true); |
| 552 | 552 |
| 553 // Destroy password_protection_service_ while there is one request pending. | 553 // Destroy password_protection_service_ while there is one request pending. |
| 554 password_protection_service_.reset(); | 554 password_protection_service_.reset(); |
| 555 base::RunLoop().RunUntilIdle(); | 555 base::RunLoop().RunUntilIdle(); |
| 556 | 556 |
| 557 EXPECT_THAT( | 557 EXPECT_THAT( |
| 558 histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), | 558 histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
| 559 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); | 559 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); |
| 560 } | 560 } |
| 561 | 561 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 request_->OnURLFetchComplete(&fetcher); | 643 request_->OnURLFetchComplete(&fetcher); |
| 644 base::RunLoop().RunUntilIdle(); | 644 base::RunLoop().RunUntilIdle(); |
| 645 | 645 |
| 646 const LoginReputationClientRequest* actual_request = | 646 const LoginReputationClientRequest* actual_request = |
| 647 password_protection_service_->GetLatestRequestProto(); | 647 password_protection_service_->GetLatestRequestProto(); |
| 648 EXPECT_EQ(kTargetUrl, actual_request->page_url()); | 648 EXPECT_EQ(kTargetUrl, actual_request->page_url()); |
| 649 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, | 649 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, |
| 650 actual_request->trigger_type()); | 650 actual_request->trigger_type()); |
| 651 EXPECT_EQ(1, actual_request->frames_size()); | 651 EXPECT_EQ(1, actual_request->frames_size()); |
| 652 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); | 652 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); |
| 653 EXPECT_TRUE(actual_request->frames(0).has_password_field()); |
| 653 // TODO(jialiul): Update this test when we're ready to fill more fields. | 654 // TODO(jialiul): Update this test when we're ready to fill more fields. |
| 654 ASSERT_FALSE(actual_request->has_password_reuse_event()); | 655 ASSERT_FALSE(actual_request->has_password_reuse_event()); |
| 655 } | 656 } |
| 656 | 657 |
| 657 } // namespace safe_browsing | 658 } // namespace safe_browsing |
| OLD | NEW |