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

Side by Side Diff: chrome/browser/ssl/certificate_reporting_test_utils.cc

Issue 1212973002: Add net::CertificateReportSender for handling cert report sending (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: style fixes Created 5 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 4
5 #include "chrome/browser/ssl/certificate_reporting_test_utils.h" 5 #include "chrome/browser/ssl/certificate_reporting_test_utils.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/metrics/field_trial.h" 9 #include "base/metrics/field_trial.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
11 #include "base/run_loop.h" 11 #include "base/run_loop.h"
12 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/safe_browsing/ping_manager.h" 14 #include "chrome/browser/safe_browsing/ping_manager.h"
15 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 15 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
16 #include "chrome/browser/safe_browsing/ui_manager.h" 16 #include "chrome/browser/safe_browsing/ui_manager.h"
17 #include "chrome/browser/ssl/cert_report_helper.h" 17 #include "chrome/browser/ssl/cert_report_helper.h"
18 #include "chrome/browser/ssl/certificate_error_report.h" 18 #include "chrome/browser/ssl/certificate_error_report.h"
19 #include "chrome/browser/ssl/ssl_cert_reporter.h" 19 #include "chrome/browser/ssl/ssl_cert_reporter.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "components/variations/variations_associated_data.h" 22 #include "components/variations/variations_associated_data.h"
23 #include "net/http/certificate_report_sender.h"
24 #include "net/http/certificate_report_sender_impl.h"
23 #include "net/url_request/url_request_context.h" 25 #include "net/url_request/url_request_context.h"
24 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
25 #include "url/gurl.h" 27 #include "url/gurl.h"
26 28
27 using chrome_browser_net::CertificateErrorReporter; 29 using chrome_browser_net::CertificateErrorReporter;
28 30
29 namespace { 31 namespace {
30 32
31 void SetMockReporter(SafeBrowsingService* safe_browsing_service, 33 void SetMockReporter(SafeBrowsingService* safe_browsing_service,
32 scoped_ptr<CertificateErrorReporter> reporter) { 34 scoped_ptr<CertificateErrorReporter> reporter) {
33 safe_browsing_service->ping_manager()->SetCertificateErrorReporterForTesting( 35 safe_browsing_service->ping_manager()->SetCertificateErrorReporterForTesting(
34 reporter.Pass()); 36 reporter.Pass());
35 } 37 }
36 38
37 } // namespace 39 } // namespace
38 40
39 namespace CertificateReportingTestUtils { 41 namespace CertificateReportingTestUtils {
40 42
41 // This class is used to test invalid certificate chain reporting when 43 // This class is used to test invalid certificate chain reporting when
42 // the user opts in to do so on the interstitial. It keeps track of the 44 // the user opts in to do so on the interstitial. It keeps track of the
43 // most recent hostname for which a report would have been sent over the 45 // most recent hostname for which a report would have been sent over the
44 // network. 46 // network.
45 class MockReporter : public chrome_browser_net::CertificateErrorReporter { 47 class MockReporter : public chrome_browser_net::CertificateErrorReporter {
46 public: 48 public:
47 MockReporter(net::URLRequestContext* request_context, 49 MockReporter(
48 const GURL& upload_url, 50 net::URLRequestContext* request_context,
49 CookiesPreference cookies_preference); 51 const GURL& upload_url,
52 net::CertificateReportSenderImpl::CookiesPreference cookies_preference);
50 53
51 // CertificateErrorReporter implementation 54 // CertificateErrorReporter implementation
52 void SendReport(CertificateErrorReporter::ReportType type, 55 void SendReport(CertificateErrorReporter::ReportType type,
53 const std::string& serialized_report) override; 56 const std::string& serialized_report) override;
54 57
55 // Returns the hostname in the report for the last call to 58 // Returns the hostname in the report for the last call to
56 // |SendReport|. 59 // |SendReport|.
57 const std::string& latest_hostname_reported() { 60 const std::string& latest_hostname_reported() {
58 return latest_hostname_reported_; 61 return latest_hostname_reported_;
59 } 62 }
60 63
61 private: 64 private:
62 std::string latest_hostname_reported_; 65 std::string latest_hostname_reported_;
63 66
64 DISALLOW_COPY_AND_ASSIGN(MockReporter); 67 DISALLOW_COPY_AND_ASSIGN(MockReporter);
65 }; 68 };
66 69
67 MockReporter::MockReporter(net::URLRequestContext* request_context, 70 MockReporter::MockReporter(
68 const GURL& upload_url, 71 net::URLRequestContext* request_context,
69 CookiesPreference cookies_preference) 72 const GURL& upload_url,
73 net::CertificateReportSenderImpl::CookiesPreference cookies_preference)
70 : CertificateErrorReporter(request_context, 74 : CertificateErrorReporter(request_context,
71 upload_url, 75 upload_url,
72 cookies_preference) { 76 cookies_preference) {
73 } 77 }
74 78
75 void MockReporter::SendReport(CertificateErrorReporter::ReportType type, 79 void MockReporter::SendReport(CertificateErrorReporter::ReportType type,
76 const std::string& serialized_report) { 80 const std::string& serialized_report) {
77 CertificateErrorReport report; 81 CertificateErrorReport report;
78 ASSERT_TRUE(report.InitializeFromString(serialized_report)); 82 ASSERT_TRUE(report.InitializeFromString(serialized_report));
79 EXPECT_EQ(CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING, type); 83 EXPECT_EQ(CertificateErrorReporter::REPORT_TYPE_EXTENDED_REPORTING, type);
80 latest_hostname_reported_ = report.hostname(); 84 latest_hostname_reported_ = report.hostname();
81 } 85 }
82 86
83 void CertificateReportingTest::SetUpMockReporter() { 87 void CertificateReportingTest::SetUpMockReporter() {
84 // Set up the mock reporter to track the hostnames that reports get 88 // Set up the mock reporter to track the hostnames that reports get
85 // sent for. The request_context argument is null here 89 // sent for. The request_context argument is null here
86 // because the MockReporter doesn't actually use a 90 // because the MockReporter doesn't actually use a
87 // request_context. (In order to pass a real request_context, the 91 // request_context. (In order to pass a real request_context, the
88 // reporter would have to be constructed on the IO thread.) 92 // reporter would have to be constructed on the IO thread.)
89 reporter_ = new MockReporter(nullptr, GURL("http://example.test"), 93 reporter_ =
90 MockReporter::DO_NOT_SEND_COOKIES); 94 new MockReporter(nullptr, GURL("http://example.test"),
95 net::CertificateReportSenderImpl::DO_NOT_SEND_COOKIES);
91 96
92 scoped_refptr<SafeBrowsingService> safe_browsing_service = 97 scoped_refptr<SafeBrowsingService> safe_browsing_service =
93 g_browser_process->safe_browsing_service(); 98 g_browser_process->safe_browsing_service();
94 ASSERT_TRUE(safe_browsing_service); 99 ASSERT_TRUE(safe_browsing_service);
95 100
96 content::BrowserThread::PostTask( 101 content::BrowserThread::PostTask(
97 content::BrowserThread::IO, FROM_HERE, 102 content::BrowserThread::IO, FROM_HERE,
98 base::Bind( 103 base::Bind(
99 SetMockReporter, safe_browsing_service, 104 SetMockReporter, safe_browsing_service,
100 base::Passed(scoped_ptr<CertificateErrorReporter>(reporter_)))); 105 base::Passed(scoped_ptr<CertificateErrorReporter>(reporter_))));
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 group_name, params); 180 group_name, params);
176 } 181 }
177 } 182 }
178 183
179 // Helper function to set the Finch options in case we have no parameter. 184 // Helper function to set the Finch options in case we have no parameter.
180 void SetCertReportingFinchConfig(const std::string& group_name) { 185 void SetCertReportingFinchConfig(const std::string& group_name) {
181 SetCertReportingFinchConfig(group_name, std::string()); 186 SetCertReportingFinchConfig(group_name, std::string());
182 } 187 }
183 188
184 } // namespace CertificateReportingTestUtils 189 } // namespace CertificateReportingTestUtils
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698