Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: components/safe_browsing/password_protection/password_protection_service_unittest.cc

Issue 2912383004: Fill is_chrome_signin_password field in the password entry pings. (Closed)
Patch Set: address nparker's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/safe_browsing/password_protection/password_protection_request.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/test/null_task_runner.h" 11 #include "base/test/null_task_runner.h"
12 #include "components/content_settings/core/browser/host_content_settings_map.h" 12 #include "components/content_settings/core/browser/host_content_settings_map.h"
13 #include "components/password_manager/core/browser/password_reuse_detector.h"
13 #include "components/safe_browsing/password_protection/password_protection_reque st.h" 14 #include "components/safe_browsing/password_protection/password_protection_reque st.h"
14 #include "components/safe_browsing_db/test_database_manager.h" 15 #include "components/safe_browsing_db/test_database_manager.h"
15 #include "components/sync_preferences/testing_pref_service_syncable.h" 16 #include "components/sync_preferences/testing_pref_service_syncable.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 17 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "net/url_request/test_url_fetcher_factory.h" 18 #include "net/url_request/test_url_fetcher_factory.h"
18 #include "testing/gmock/include/gmock/gmock.h" 19 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace { 22 namespace {
22 23
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) 170 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url))
170 .WillRepeatedly(testing::Return(match_whitelist)); 171 .WillRepeatedly(testing::Return(match_whitelist));
171 172
172 request_ = new PasswordProtectionRequest( 173 request_ = new PasswordProtectionRequest(
173 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl), 174 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl),
174 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, 175 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE,
175 password_protection_service_.get(), timeout_in_ms); 176 password_protection_service_.get(), timeout_in_ms);
176 request_->Start(); 177 request_->Start();
177 } 178 }
178 179
179 void InitializeAndStartPasswordEntryRequest(bool match_whitelist, 180 void InitializeAndStartPasswordEntryRequest(const std::string& saved_domain,
181 bool match_whitelist,
180 int timeout_in_ms) { 182 int timeout_in_ms) {
181 GURL target_url(kTargetUrl); 183 GURL target_url(kTargetUrl);
182 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) 184 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url))
183 .WillRepeatedly(testing::Return(match_whitelist)); 185 .WillRepeatedly(testing::Return(match_whitelist));
184 186
185 request_ = new PasswordProtectionRequest( 187 request_ = new PasswordProtectionRequest(
186 nullptr, target_url, GURL(), GURL(), std::string(kSavedDomain), 188 nullptr, target_url, GURL(), GURL(), saved_domain,
187 LoginReputationClientRequest::PASSWORD_REUSE_EVENT, 189 LoginReputationClientRequest::PASSWORD_REUSE_EVENT,
188 password_protection_service_.get(), timeout_in_ms); 190 password_protection_service_.get(), timeout_in_ms);
189 request_->Start(); 191 request_->Start();
190 } 192 }
191 193
192 bool PathVariantsMatchCacheExpression(const GURL& url, 194 bool PathVariantsMatchCacheExpression(const GURL& url,
193 const std::string& cache_expression) { 195 const std::string& cache_expression) {
194 std::vector<std::string> paths; 196 std::vector<std::string> paths;
195 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); 197 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths);
196 return PasswordProtectionService::PathVariantsMatchCacheExpression( 198 return PasswordProtectionService::PathVariantsMatchCacheExpression(
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 EXPECT_EQ(LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, 622 EXPECT_EQ(LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE,
621 actual_request->trigger_type()); 623 actual_request->trigger_type());
622 ASSERT_EQ(2, actual_request->frames_size()); 624 ASSERT_EQ(2, actual_request->frames_size());
623 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); 625 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
624 EXPECT_EQ(kPasswordFrameUrl, actual_request->frames(1).url()); 626 EXPECT_EQ(kPasswordFrameUrl, actual_request->frames(1).url());
625 EXPECT_EQ(true, actual_request->frames(1).has_password_field()); 627 EXPECT_EQ(true, actual_request->frames(1).has_password_field());
626 ASSERT_EQ(1, actual_request->frames(1).forms_size()); 628 ASSERT_EQ(1, actual_request->frames(1).forms_size());
627 EXPECT_EQ(kFormActionUrl, actual_request->frames(1).forms(0).action_url()); 629 EXPECT_EQ(kFormActionUrl, actual_request->frames(1).forms(0).action_url());
628 } 630 }
629 631
630 TEST_F(PasswordProtectionServiceTest, 632 TEST_F(PasswordProtectionServiceTest, VerifyPasswordProtectionRequestProto) {
631 VerifyProtectedPasswordEntryRequestProto) {
632 // Set up valid response. 633 // Set up valid response.
633 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr); 634 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr);
634 fetcher.set_status( 635 fetcher.set_status(
635 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); 636 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
636 fetcher.set_response_code(200); 637 fetcher.set_response_code(200);
637 LoginReputationClientResponse expected_response = CreateVerdictProto( 638 LoginReputationClientResponse expected_response = CreateVerdictProto(
638 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host()); 639 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host());
639 fetcher.SetResponseString(expected_response.SerializeAsString()); 640 fetcher.SetResponseString(expected_response.SerializeAsString());
640 InitializeAndStartPasswordEntryRequest(false /* match whitelist */, 641 // Initialize request triggered by chrome sync password reuse.
641 100000 /* timeout in ms*/); 642 InitializeAndStartPasswordEntryRequest(
643 std::string(password_manager::kSyncPasswordDomain),
644 false /* match whitelist */, 100000 /* timeout in ms*/);
642 base::RunLoop().RunUntilIdle(); 645 base::RunLoop().RunUntilIdle();
643 request_->OnURLFetchComplete(&fetcher); 646 request_->OnURLFetchComplete(&fetcher);
644 base::RunLoop().RunUntilIdle(); 647 base::RunLoop().RunUntilIdle();
645 648
646 const LoginReputationClientRequest* actual_request = 649 const LoginReputationClientRequest* actual_request =
647 password_protection_service_->GetLatestRequestProto(); 650 password_protection_service_->GetLatestRequestProto();
648 EXPECT_EQ(kTargetUrl, actual_request->page_url()); 651 EXPECT_EQ(kTargetUrl, actual_request->page_url());
649 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, 652 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT,
650 actual_request->trigger_type()); 653 actual_request->trigger_type());
651 EXPECT_EQ(1, actual_request->frames_size()); 654 EXPECT_EQ(1, actual_request->frames_size());
652 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); 655 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
653 // TODO(jialiul): Update this test when we're ready to fill more fields. 656 ASSERT_TRUE(actual_request->has_password_reuse_event());
654 ASSERT_FALSE(actual_request->has_password_reuse_event()); 657 ASSERT_TRUE(
658 actual_request->password_reuse_event().is_chrome_signin_password());
659
660 // Initialize request triggered by saved password reuse.
661 InitializeAndStartPasswordEntryRequest(std::string(kSavedDomain),
662 false /* match whitelist */,
663 100000 /* timeout in ms*/);
664 base::RunLoop().RunUntilIdle();
665 request_->OnURLFetchComplete(&fetcher);
666 base::RunLoop().RunUntilIdle();
667
668 actual_request = password_protection_service_->GetLatestRequestProto();
669 ASSERT_TRUE(actual_request->has_password_reuse_event());
670 ASSERT_FALSE(
671 actual_request->password_reuse_event().is_chrome_signin_password());
655 } 672 }
656 673
657 } // namespace safe_browsing 674 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing/password_protection/password_protection_request.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698