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

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

Issue 2905343002: Show interstitial on a password on focus ping with PHISHING verdict. (Closed)
Patch Set: nit 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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 : PasswordProtectionService(database_manager, 71 : PasswordProtectionService(database_manager,
72 request_context_getter, 72 request_context_getter,
73 nullptr, 73 nullptr,
74 content_setting_map.get()), 74 content_setting_map.get()),
75 is_extended_reporting_(true), 75 is_extended_reporting_(true),
76 is_incognito_(false), 76 is_incognito_(false),
77 latest_request_(nullptr) {} 77 latest_request_(nullptr) {}
78 78
79 void RequestFinished( 79 void RequestFinished(
80 PasswordProtectionRequest* request, 80 PasswordProtectionRequest* request,
81 bool already_cached_unused,
81 std::unique_ptr<LoginReputationClientResponse> response) override { 82 std::unique_ptr<LoginReputationClientResponse> response) override {
82 latest_request_ = request; 83 latest_request_ = request;
83 latest_response_ = std::move(response); 84 latest_response_ = std::move(response);
84 } 85 }
85 86
86 // Since referrer chain logic has been thoroughly tested in 87 // Since referrer chain logic has been thoroughly tested in
87 // SBNavigationObserverBrowserTest class, we intentionally leave this function 88 // SBNavigationObserverBrowserTest class, we intentionally leave this function
88 // as a no-op here. 89 // as a no-op here.
89 void FillReferrerChain(const GURL& event_url, 90 void FillReferrerChain(const GURL& event_url,
90 int event_tab_id, 91 int event_tab_id,
91 LoginReputationClientRequest::Frame* frame) override {} 92 LoginReputationClientRequest::Frame* frame) override {}
92 93
93 bool IsExtendedReporting() override { return is_extended_reporting_; } 94 bool IsExtendedReporting() override { return is_extended_reporting_; }
94 95
95 bool IsIncognito() override { return is_incognito_; } 96 bool IsIncognito() override { return is_incognito_; }
96 97
97 void set_extended_reporting(bool enabled) { 98 void set_extended_reporting(bool enabled) {
98 is_extended_reporting_ = enabled; 99 is_extended_reporting_ = enabled;
99 } 100 }
100 101
101 void set_incognito(bool enabled) { is_incognito_ = enabled; } 102 void set_incognito(bool enabled) { is_incognito_ = enabled; }
102 103
103 bool IsPingingEnabled(const base::Feature& feature, 104 bool IsPingingEnabled(const base::Feature& feature,
104 RequestOutcome* reason) override { 105 RequestOutcome* reason) override {
105 return true; 106 return true;
106 } 107 }
107 108
109 void ShowPhishingInterstitial(const GURL& phishing_url,
110 const std::string& token,
111 content::WebContents* web_contents) override {}
112
108 bool IsHistorySyncEnabled() override { return false; } 113 bool IsHistorySyncEnabled() override { return false; }
109 114
110 LoginReputationClientResponse* latest_response() { 115 LoginReputationClientResponse* latest_response() {
111 return latest_response_.get(); 116 return latest_response_.get();
112 } 117 }
113 118
114 ~TestPasswordProtectionService() override {} 119 ~TestPasswordProtectionService() override {}
115 120
116 size_t GetPendingRequestsCount() { return requests_.size(); } 121 size_t GetPendingRequestsCount() { return requests_.size(); }
117 122
118 LoginReputationClientRequest* GetLatestRequestProto() { 123 const LoginReputationClientRequest* GetLatestRequestProto() {
119 return latest_request_ ? latest_request_->request_proto() : nullptr; 124 return latest_request_ ? latest_request_->request_proto() : nullptr;
120 } 125 }
121 126
122 private: 127 private:
123 bool is_extended_reporting_; 128 bool is_extended_reporting_;
124 bool is_incognito_; 129 bool is_incognito_;
125 PasswordProtectionRequest* latest_request_; 130 PasswordProtectionRequest* latest_request_;
126 std::unique_ptr<LoginReputationClientResponse> latest_response_; 131 std::unique_ptr<LoginReputationClientResponse> latest_response_;
127 DISALLOW_COPY_AND_ASSIGN(TestPasswordProtectionService); 132 DISALLOW_COPY_AND_ASSIGN(TestPasswordProtectionService);
128 }; 133 };
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 LoginReputationClientResponse expected_response = CreateVerdictProto( 607 LoginReputationClientResponse expected_response = CreateVerdictProto(
603 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host()); 608 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host());
604 fetcher.SetResponseString(expected_response.SerializeAsString()); 609 fetcher.SetResponseString(expected_response.SerializeAsString());
605 610
606 InitializeAndStartPasswordOnFocusRequest(false /* match whitelist */, 611 InitializeAndStartPasswordOnFocusRequest(false /* match whitelist */,
607 100000 /* timeout in ms*/); 612 100000 /* timeout in ms*/);
608 base::RunLoop().RunUntilIdle(); 613 base::RunLoop().RunUntilIdle();
609 request_->OnURLFetchComplete(&fetcher); 614 request_->OnURLFetchComplete(&fetcher);
610 base::RunLoop().RunUntilIdle(); 615 base::RunLoop().RunUntilIdle();
611 616
612 LoginReputationClientRequest* actual_request = 617 const LoginReputationClientRequest* actual_request =
613 password_protection_service_->GetLatestRequestProto(); 618 password_protection_service_->GetLatestRequestProto();
614 EXPECT_EQ(kTargetUrl, actual_request->page_url()); 619 EXPECT_EQ(kTargetUrl, actual_request->page_url());
615 EXPECT_EQ(LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE, 620 EXPECT_EQ(LoginReputationClientRequest::UNFAMILIAR_LOGIN_PAGE,
616 actual_request->trigger_type()); 621 actual_request->trigger_type());
617 ASSERT_EQ(2, actual_request->frames_size()); 622 ASSERT_EQ(2, actual_request->frames_size());
618 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); 623 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
619 EXPECT_EQ(kPasswordFrameUrl, actual_request->frames(1).url()); 624 EXPECT_EQ(kPasswordFrameUrl, actual_request->frames(1).url());
620 EXPECT_EQ(true, actual_request->frames(1).has_password_field()); 625 EXPECT_EQ(true, actual_request->frames(1).has_password_field());
621 ASSERT_EQ(1, actual_request->frames(1).forms_size()); 626 ASSERT_EQ(1, actual_request->frames(1).forms_size());
622 EXPECT_EQ(kFormActionUrl, actual_request->frames(1).forms(0).action_url()); 627 EXPECT_EQ(kFormActionUrl, actual_request->frames(1).forms(0).action_url());
623 } 628 }
624 629
625 TEST_F(PasswordProtectionServiceTest, 630 TEST_F(PasswordProtectionServiceTest,
626 VerifyProtectedPasswordEntryRequestProto) { 631 VerifyProtectedPasswordEntryRequestProto) {
627 // Set up valid response. 632 // Set up valid response.
628 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr); 633 net::TestURLFetcher fetcher(0, GURL("http://bar.com"), nullptr);
629 fetcher.set_status( 634 fetcher.set_status(
630 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK)); 635 net::URLRequestStatus(net::URLRequestStatus::SUCCESS, net::OK));
631 fetcher.set_response_code(200); 636 fetcher.set_response_code(200);
632 LoginReputationClientResponse expected_response = CreateVerdictProto( 637 LoginReputationClientResponse expected_response = CreateVerdictProto(
633 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host()); 638 LoginReputationClientResponse::PHISHING, 600, GURL(kTargetUrl).host());
634 fetcher.SetResponseString(expected_response.SerializeAsString()); 639 fetcher.SetResponseString(expected_response.SerializeAsString());
635 InitializeAndStartPasswordEntryRequest(false /* match whitelist */, 640 InitializeAndStartPasswordEntryRequest(false /* match whitelist */,
636 100000 /* timeout in ms*/); 641 100000 /* timeout in ms*/);
637 base::RunLoop().RunUntilIdle(); 642 base::RunLoop().RunUntilIdle();
638 request_->OnURLFetchComplete(&fetcher); 643 request_->OnURLFetchComplete(&fetcher);
639 base::RunLoop().RunUntilIdle(); 644 base::RunLoop().RunUntilIdle();
640 645
641 LoginReputationClientRequest* actual_request = 646 const LoginReputationClientRequest* actual_request =
642 password_protection_service_->GetLatestRequestProto(); 647 password_protection_service_->GetLatestRequestProto();
643 EXPECT_EQ(kTargetUrl, actual_request->page_url()); 648 EXPECT_EQ(kTargetUrl, actual_request->page_url());
644 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT, 649 EXPECT_EQ(LoginReputationClientRequest::PASSWORD_REUSE_EVENT,
645 actual_request->trigger_type()); 650 actual_request->trigger_type());
646 EXPECT_EQ(1, actual_request->frames_size()); 651 EXPECT_EQ(1, actual_request->frames_size());
647 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url()); 652 EXPECT_EQ(kTargetUrl, actual_request->frames(0).url());
648 // TODO(jialiul): Update this test when we're ready to fill more fields. 653 // TODO(jialiul): Update this test when we're ready to fill more fields.
649 ASSERT_FALSE(actual_request->has_password_reuse_event()); 654 ASSERT_FALSE(actual_request->has_password_reuse_event());
650 } 655 }
651 656
652 } // namespace safe_browsing 657 } // namespace safe_browsing
OLDNEW
« no previous file with comments | « components/safe_browsing/password_protection/password_protection_service.cc ('k') | components/safe_browsing_db/hit_report.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698