| 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 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 // Sets up |database_manager_| and |requests_| as needed. | 166 // Sets up |database_manager_| and |requests_| as needed. |
| 167 void InitializeAndStartPasswordOnFocusRequest(bool match_whitelist, | 167 void InitializeAndStartPasswordOnFocusRequest(bool match_whitelist, |
| 168 int timeout_in_ms) { | 168 int timeout_in_ms) { |
| 169 GURL target_url(kTargetUrl); | 169 GURL target_url(kTargetUrl); |
| 170 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 170 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 171 .WillRepeatedly(testing::Return(match_whitelist)); | 171 .WillRepeatedly(testing::Return(match_whitelist)); |
| 172 | 172 |
| 173 request_ = new PasswordProtectionRequest( | 173 request_ = new PasswordProtectionRequest( |
| 174 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl), | 174 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl), |
| 175 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, | 175 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, |
| 176 password_protection_service_.get(), timeout_in_ms); | 176 true, password_protection_service_.get(), timeout_in_ms); |
| 177 request_->Start(); | 177 request_->Start(); |
| 178 } | 178 } |
| 179 | 179 |
| 180 void InitializeAndStartPasswordEntryRequest(const std::string& saved_domain, | 180 void InitializeAndStartPasswordEntryRequest(const std::string& saved_domain, |
| 181 bool match_whitelist, | 181 bool match_whitelist, |
| 182 int timeout_in_ms) { | 182 int timeout_in_ms) { |
| 183 GURL target_url(kTargetUrl); | 183 GURL target_url(kTargetUrl); |
| 184 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 184 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 185 .WillRepeatedly(testing::Return(match_whitelist)); | 185 .WillRepeatedly(testing::Return(match_whitelist)); |
| 186 | 186 |
| 187 request_ = new PasswordProtectionRequest( | 187 request_ = new PasswordProtectionRequest( |
| 188 nullptr, target_url, GURL(), GURL(), saved_domain, | 188 nullptr, target_url, GURL(), GURL(), saved_domain, |
| 189 LoginReputationClientRequest::PASSWORD_REUSE_EVENT, | 189 LoginReputationClientRequest::PASSWORD_REUSE_EVENT, true, |
| 190 password_protection_service_.get(), timeout_in_ms); | 190 password_protection_service_.get(), timeout_in_ms); |
| 191 request_->Start(); | 191 request_->Start(); |
| 192 } | 192 } |
| 193 | 193 |
| 194 bool PathVariantsMatchCacheExpression(const GURL& url, | 194 bool PathVariantsMatchCacheExpression(const GURL& url, |
| 195 const std::string& cache_expression) { | 195 const std::string& cache_expression) { |
| 196 std::vector<std::string> paths; | 196 std::vector<std::string> paths; |
| 197 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); | 197 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); |
| 198 return PasswordProtectionService::PathVariantsMatchCacheExpression( | 198 return PasswordProtectionService::PathVariantsMatchCacheExpression( |
| 199 paths, | 199 paths, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 } | 543 } |
| 544 | 544 |
| 545 TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) { | 545 TEST_F(PasswordProtectionServiceTest, TestTearDownWithPendingRequests) { |
| 546 histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); | 546 histograms_.ExpectTotalCount(kPasswordOnFocusRequestOutcomeHistogramName, 0); |
| 547 GURL target_url(kTargetUrl); | 547 GURL target_url(kTargetUrl); |
| 548 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) | 548 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) |
| 549 .WillRepeatedly(testing::Return(false)); | 549 .WillRepeatedly(testing::Return(false)); |
| 550 password_protection_service_->StartRequest( | 550 password_protection_service_->StartRequest( |
| 551 nullptr, target_url, GURL("http://foo.com/submit"), | 551 nullptr, target_url, GURL("http://foo.com/submit"), |
| 552 GURL("http://foo.com/frame"), std::string(), | 552 GURL("http://foo.com/frame"), std::string(), |
| 553 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE); | 553 LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, true); |
| 554 | 554 |
| 555 // Destroy password_protection_service_ while there is one request pending. | 555 // Destroy password_protection_service_ while there is one request pending. |
| 556 password_protection_service_.reset(); | 556 password_protection_service_.reset(); |
| 557 base::RunLoop().RunUntilIdle(); | 557 base::RunLoop().RunUntilIdle(); |
| 558 | 558 |
| 559 EXPECT_THAT( | 559 EXPECT_THAT( |
| 560 histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), | 560 histograms_.GetAllSamples(kPasswordOnFocusRequestOutcomeHistogramName), |
| 561 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); | 561 testing::ElementsAre(base::Bucket(2 /* CANCELED */, 1))); |
| 562 } | 562 } |
| 563 | 563 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 request_->OnURLFetchComplete(&fetcher); | 646 request_->OnURLFetchComplete(&fetcher); |
| 647 base::RunLoop().RunUntilIdle(); | 647 base::RunLoop().RunUntilIdle(); |
| 648 | 648 |
| 649 const LoginReputationClientRequest* actual_request = | 649 const LoginReputationClientRequest* actual_request = |
| 650 password_protection_service_->GetLatestRequestProto(); | 650 password_protection_service_->GetLatestRequestProto(); |
| 651 EXPECT_EQ(kTargetUrl, actual_request->page_url()); | 651 EXPECT_EQ(kTargetUrl, actual_request->page_url()); |
| 652 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, | 652 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, |
| 653 actual_request->trigger_type()); | 653 actual_request->trigger_type()); |
| 654 EXPECT_EQ(1, actual_request->frames_size()); | 654 EXPECT_EQ(1, actual_request->frames_size()); |
| 655 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); | 655 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); |
| 656 EXPECT_TRUE(actual_request->frames(0).has_password_field()); |
| 656 ASSERT_TRUE(actual_request->has_password_reuse_event()); | 657 ASSERT_TRUE(actual_request->has_password_reuse_event()); |
| 657 ASSERT_TRUE( | 658 ASSERT_TRUE( |
| 658 actual_request->password_reuse_event().is_chrome_signin_password()); | 659 actual_request->password_reuse_event().is_chrome_signin_password()); |
| 659 | 660 |
| 660 // Initialize request triggered by saved password reuse. | 661 // Initialize request triggered by saved password reuse. |
| 661 InitializeAndStartPasswordEntryRequest(std::string(kSavedDomain), | 662 InitializeAndStartPasswordEntryRequest(std::string(kSavedDomain), |
| 662 false /* match whitelist */, | 663 false /* match whitelist */, |
| 663 100000 /* timeout in ms*/); | 664 100000 /* timeout in ms*/); |
| 664 base::RunLoop().RunUntilIdle(); | 665 base::RunLoop().RunUntilIdle(); |
| 665 request_->OnURLFetchComplete(&fetcher); | 666 request_->OnURLFetchComplete(&fetcher); |
| 666 base::RunLoop().RunUntilIdle(); | 667 base::RunLoop().RunUntilIdle(); |
| 667 | 668 |
| 668 actual_request = password_protection_service_->GetLatestRequestProto(); | 669 actual_request = password_protection_service_->GetLatestRequestProto(); |
| 669 ASSERT_TRUE(actual_request->has_password_reuse_event()); | 670 ASSERT_TRUE(actual_request->has_password_reuse_event()); |
| 670 ASSERT_FALSE( | 671 ASSERT_FALSE( |
| 671 actual_request->password_reuse_event().is_chrome_signin_password()); | 672 actual_request->password_reuse_event().is_chrome_signin_password()); |
| 672 } | 673 } |
| 673 | 674 |
| 674 } // namespace safe_browsing | 675 } // namespace safe_browsing |
| OLD | NEW |