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

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: clean up DEPS file 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
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/safe_browsing/password_protection/password_protection_reque st.h" 13 #include "components/safe_browsing/password_protection/password_protection_reque st.h"
14 #include "components/safe_browsing_db/test_database_manager.h" 14 #include "components/safe_browsing_db/test_database_manager.h"
15 #include "components/sync_preferences/testing_pref_service_syncable.h" 15 #include "components/sync_preferences/testing_pref_service_syncable.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 16 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "google_apis/gaia/gaia_urls.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
23 const char kFormActionUrl[] = "https://form_action.com/"; 24 const char kFormActionUrl[] = "https://form_action.com/";
24 const char kPasswordFrameUrl[] = "https://password_frame.com/"; 25 const char kPasswordFrameUrl[] = "https://password_frame.com/";
25 const char kSavedDomain[] = "saved_domain.com"; 26 const char kSavedDomain[] = "saved_domain.com";
26 const char kTargetUrl[] = "http://foo.com/"; 27 const char kTargetUrl[] = "http://foo.com/";
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) 165 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url))
165 .WillRepeatedly(testing::Return(match_whitelist)); 166 .WillRepeatedly(testing::Return(match_whitelist));
166 167
167 request_ = new PasswordProtectionRequest( 168 request_ = new PasswordProtectionRequest(
168 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl), 169 nullptr, target_url, GURL(kFormActionUrl), GURL(kPasswordFrameUrl),
169 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, 170 std::string(), LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE,
170 password_protection_service_.get(), timeout_in_ms); 171 password_protection_service_.get(), timeout_in_ms);
171 request_->Start(); 172 request_->Start();
172 } 173 }
173 174
174 void InitializeAndStartPasswordEntryRequest(bool match_whitelist, 175 void InitializeAndStartPasswordEntryRequest(const std::string& saved_domain,
176 bool match_whitelist,
175 int timeout_in_ms) { 177 int timeout_in_ms) {
176 GURL target_url(kTargetUrl); 178 GURL target_url(kTargetUrl);
177 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url)) 179 EXPECT_CALL(*database_manager_.get(), MatchCsdWhitelistUrl(target_url))
178 .WillRepeatedly(testing::Return(match_whitelist)); 180 .WillRepeatedly(testing::Return(match_whitelist));
179 181
180 request_ = new PasswordProtectionRequest( 182 request_ = new PasswordProtectionRequest(
181 nullptr, target_url, GURL(), GURL(), std::string(kSavedDomain), 183 nullptr, target_url, GURL(), GURL(), saved_domain,
182 LoginReputationClientRequest::PASSWORD_REUSE_EVENT, 184 LoginReputationClientRequest::PASSWORD_REUSE_EVENT,
183 password_protection_service_.get(), timeout_in_ms); 185 password_protection_service_.get(), timeout_in_ms);
184 request_->Start(); 186 request_->Start();
185 } 187 }
186 188
187 bool PathVariantsMatchCacheExpression(const GURL& url, 189 bool PathVariantsMatchCacheExpression(const GURL& url,
188 const std::string& cache_expression) { 190 const std::string& cache_expression) {
189 std::vector<std::string> paths; 191 std::vector<std::string> paths;
190 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths); 192 PasswordProtectionService::GeneratePathVariantsWithoutQuery(url, &paths);
191 return PasswordProtectionService::PathVariantsMatchCacheExpression( 193 return PasswordProtectionService::PathVariantsMatchCacheExpression(
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 actual_request->trigger_type()); 618 actual_request->trigger_type());
617 ASSERT_EQ(2, actual_request->frames_size()); 619 ASSERT_EQ(2, actual_request->frames_size());
618 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); 620 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
619 EXPECT_EQ(kPasswordFrameUrl, actual_request->frames(1).url()); 621 EXPECT_EQ(kPasswordFrameUrl, actual_request->frames(1).url());
620 EXPECT_EQ(true, actual_request->frames(1).has_password_field()); 622 EXPECT_EQ(true, actual_request->frames(1).has_password_field());
621 ASSERT_EQ(1, actual_request->frames(1).forms_size()); 623 ASSERT_EQ(1, actual_request->frames(1).forms_size());
622 EXPECT_EQ(kFormActionUrl, actual_request->frames(1).forms(0).action_url()); 624 EXPECT_EQ(kFormActionUrl, actual_request->frames(1).forms(0).action_url());
623 } 625 }
624 626
625 TEST_F(PasswordProtectionServiceTest, 627 TEST_F(PasswordProtectionServiceTest,
626 VerifyProtectedPasswordEntryRequestProto) { 628 VerifyChromeSiginPasswordEntryRequestProto) {
627 // Set up valid response. 629 // Set up valid response.
628 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr); 630 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr);
629 fetcher.set_status( 631 fetcher.set_status(
630 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); 632 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
631 fetcher.set_response_code(200); 633 fetcher.set_response_code(200);
632 LoginReputationClientResponse expected_response = CreateVerdictProto( 634 LoginReputationClientResponse expected_response = CreateVerdictProto(
633 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host()); 635 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host());
634 fetcher.SetResponseString(expected_response.SerializeAsString()); 636 fetcher.SetResponseString(expected_response.SerializeAsString());
635 InitializeAndStartPasswordEntryRequest(false /* match whitelist */, 637 InitializeAndStartPasswordEntryRequest(
638 GaiaUrls::GetInstance()->gaia_url().GetOrigin().spec(),
639 false /* match whitelist */, 100000 /* timeout in ms*/);
640 base::RunLoop().RunUntilIdle();
641 request_->OnURLFetchComplete(&fetcher);
642 base::RunLoop().RunUntilIdle();
643
644 LoginReputationClientRequest* actual_request =
645 password_protection_service_->GetLatestRequestProto();
646 EXPECT_EQ(kTargetUrl, actual_request->page_url());
647 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT,
648 actual_request->trigger_type());
649 EXPECT_EQ(1, actual_request->frames_size());
650 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
651 ASSERT_TRUE(actual_request->has_password_reuse_event());
652 EXPECT_TRUE(
vakh (use Gerrit instead) 2017/06/01 00:02:25 I think this should be an ASSERT
Jialiu Lin 2017/06/01 01:22:01 Done.
653 actual_request->password_reuse_event().is_chrome_signin_password());
654 }
655
656 TEST_F(PasswordProtectionServiceTest,
657 VerifyPasswordManagerPasswordEntryRequestProto) {
658 // Set up valid response.
659 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr);
vakh (use Gerrit instead) 2017/06/01 00:02:25 There's plenty of overlap in these tests. Do you t
Jialiu Lin 2017/06/01 01:22:01 I'll combine these two tests, such that they can s
660 fetcher.set_status(
661 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
662 fetcher.set_response_code(200);
663 LoginReputationClientResponse expected_response = CreateVerdictProto(
664 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host());
665 fetcher.SetResponseString(expected_response.SerializeAsString());
666 InitializeAndStartPasswordEntryRequest(std::string(kSavedDomain),
667 false /* match whitelist */,
636 100000 /* timeout in ms*/); 668 100000 /* timeout in ms*/);
637 base::RunLoop().RunUntilIdle(); 669 base::RunLoop().RunUntilIdle();
638 request_->OnURLFetchComplete(&fetcher); 670 request_->OnURLFetchComplete(&fetcher);
639 base::RunLoop().RunUntilIdle(); 671 base::RunLoop().RunUntilIdle();
640 672
641 LoginReputationClientRequest* actual_request = 673 LoginReputationClientRequest* actual_request =
642 password_protection_service_->GetLatestRequestProto(); 674 password_protection_service_->GetLatestRequestProto();
643 EXPECT_EQ(kTargetUrl, actual_request->page_url()); 675 EXPECT_EQ(kTargetUrl, actual_request->page_url());
644 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, 676 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT,
645 actual_request->trigger_type()); 677 actual_request->trigger_type());
646 EXPECT_EQ(1, actual_request->frames_size()); 678 EXPECT_EQ(1, actual_request->frames_size());
647 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); 679 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
648 // TODO(jialiul): Update this test when we're ready to fill more fields. 680 ASSERT_TRUE(actual_request->has_password_reuse_event());
649 ASSERT_FALSE(actual_request->has_password_reuse_event()); 681 EXPECT_FALSE(
682 actual_request->password_reuse_event().is_chrome_signin_password());
650 } 683 }
651 684
652 } // namespace safe_browsing 685 } // namespace safe_browsing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698