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

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

Issue 2964283002: Add chrome channel to cert logger reports (Closed)
Patch Set: Fix build errors Created 3 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 14 matching lines...) Expand all
25 25
26 namespace certificate_reporting_test_utils { 26 namespace certificate_reporting_test_utils {
27 27
28 // This is a test implementation of the interface that blocking pages use to 28 // This is a test implementation of the interface that blocking pages use to
29 // send certificate reports. It checks that the blocking page calls or does not 29 // send certificate reports. It checks that the blocking page calls or does not
30 // call the report method when a report should or should not be sent, 30 // call the report method when a report should or should not be sent,
31 // respectively. 31 // respectively.
32 class MockSSLCertReporter : public SSLCertReporter { 32 class MockSSLCertReporter : public SSLCertReporter {
33 public: 33 public:
34 MockSSLCertReporter( 34 MockSSLCertReporter(
35 const base::Callback<void(const std::string&)>& report_sent_callback, 35 const base::Callback<
36 void(const std::string&,
37 const certificate_reporting::CertLoggerRequest_ChromeChannel)>&
38 report_sent_callback,
36 ExpectReport expect_report) 39 ExpectReport expect_report)
37 : report_sent_callback_(report_sent_callback), 40 : report_sent_callback_(report_sent_callback),
38 expect_report_(expect_report), 41 expect_report_(expect_report),
39 reported_(false) {} 42 reported_(false) {}
40 43
41 ~MockSSLCertReporter() override { 44 ~MockSSLCertReporter() override {
42 if (expect_report_ == CERT_REPORT_EXPECTED) { 45 if (expect_report_ == CERT_REPORT_EXPECTED) {
43 EXPECT_TRUE(reported_); 46 EXPECT_TRUE(reported_);
44 } else { 47 } else {
45 EXPECT_FALSE(reported_); 48 EXPECT_FALSE(reported_);
46 } 49 }
47 } 50 }
48 51
49 // SSLCertReporter implementation. 52 // SSLCertReporter implementation.
50 void ReportInvalidCertificateChain( 53 void ReportInvalidCertificateChain(
51 const std::string& serialized_report) override { 54 const std::string& serialized_report) override {
52 reported_ = true; 55 reported_ = true;
53 certificate_reporting::ErrorReport report; 56 certificate_reporting::ErrorReport report;
54 EXPECT_TRUE(report.InitializeFromString(serialized_report)); 57 EXPECT_TRUE(report.InitializeFromString(serialized_report));
55 report_sent_callback_.Run(report.hostname()); 58 report_sent_callback_.Run(report.hostname(), report.chrome_channel());
56 } 59 }
57 60
58 private: 61 private:
59 const base::Callback<void(const std::string&)> report_sent_callback_; 62 const base::Callback<void(
63 const std::string&,
64 const certificate_reporting::CertLoggerRequest_ChromeChannel)>
65 report_sent_callback_;
60 const ExpectReport expect_report_; 66 const ExpectReport expect_report_;
61 bool reported_; 67 bool reported_;
62 68
63 DISALLOW_COPY_AND_ASSIGN(MockSSLCertReporter); 69 DISALLOW_COPY_AND_ASSIGN(MockSSLCertReporter);
64 }; 70 };
65 71
66 SSLCertReporterCallback::SSLCertReporterCallback(base::RunLoop* run_loop) 72 SSLCertReporterCallback::SSLCertReporterCallback(base::RunLoop* run_loop)
67 : run_loop_(run_loop) {} 73 : run_loop_(run_loop),
74 chrome_channel_(
75 certificate_reporting::CertLoggerRequest::CHROME_CHANNEL_NONE) {}
68 76
69 SSLCertReporterCallback::~SSLCertReporterCallback() {} 77 SSLCertReporterCallback::~SSLCertReporterCallback() {}
70 78
71 void SSLCertReporterCallback::ReportSent(const std::string& hostname) { 79 void SSLCertReporterCallback::ReportSent(
80 const std::string& hostname,
81 const certificate_reporting::CertLoggerRequest::ChromeChannel
82 chrome_channel) {
72 latest_hostname_reported_ = hostname; 83 latest_hostname_reported_ = hostname;
84 chrome_channel_ = chrome_channel;
73 run_loop_->Quit(); 85 run_loop_->Quit();
74 } 86 }
75 87
76 const std::string& SSLCertReporterCallback::GetLatestHostnameReported() const { 88 const std::string& SSLCertReporterCallback::GetLatestHostnameReported() const {
77 return latest_hostname_reported_; 89 return latest_hostname_reported_;
78 } 90 }
79 91
92 certificate_reporting::CertLoggerRequest::ChromeChannel
93 SSLCertReporterCallback::GetLatestChromeChannelReported() const {
94 return chrome_channel_;
95 }
96
80 void SetCertReportingOptIn(Browser* browser, OptIn opt_in) { 97 void SetCertReportingOptIn(Browser* browser, OptIn opt_in) {
81 safe_browsing::SetExtendedReportingPref(browser->profile()->GetPrefs(), 98 safe_browsing::SetExtendedReportingPref(browser->profile()->GetPrefs(),
82 opt_in == EXTENDED_REPORTING_OPT_IN); 99 opt_in == EXTENDED_REPORTING_OPT_IN);
83 } 100 }
84 101
85 std::unique_ptr<SSLCertReporter> CreateMockSSLCertReporter( 102 std::unique_ptr<SSLCertReporter> CreateMockSSLCertReporter(
86 const base::Callback<void(const std::string&)>& report_sent_callback, 103 const base::Callback<
104 void(const std::string&,
105 const certificate_reporting::CertLoggerRequest_ChromeChannel)>&
106 report_sent_callback,
87 ExpectReport expect_report) { 107 ExpectReport expect_report) {
88 return std::unique_ptr<SSLCertReporter>( 108 return std::unique_ptr<SSLCertReporter>(
89 new MockSSLCertReporter(report_sent_callback, expect_report)); 109 new MockSSLCertReporter(report_sent_callback, expect_report));
90 } 110 }
91 111
92 ExpectReport GetReportExpectedFromFinch() { 112 ExpectReport GetReportExpectedFromFinch() {
93 const std::string group_name = base::FieldTrialList::FindFullName( 113 const std::string group_name = base::FieldTrialList::FindFullName(
94 CertReportHelper::kFinchExperimentName); 114 CertReportHelper::kFinchExperimentName);
95 115
96 if (group_name == CertReportHelper::kFinchGroupShowPossiblySend) { 116 if (group_name == CertReportHelper::kFinchGroupShowPossiblySend) {
97 const std::string param = variations::GetVariationParamValue( 117 const std::string param = variations::GetVariationParamValue(
98 CertReportHelper::kFinchExperimentName, 118 CertReportHelper::kFinchExperimentName,
99 CertReportHelper::kFinchParamName); 119 CertReportHelper::kFinchParamName);
100 double sendingThreshold; 120 double sendingThreshold;
101 if (!base::StringToDouble(param, &sendingThreshold)) 121 if (!base::StringToDouble(param, &sendingThreshold))
102 return CERT_REPORT_NOT_EXPECTED; 122 return CERT_REPORT_NOT_EXPECTED;
103 123
104 if (sendingThreshold == 1.0) 124 if (sendingThreshold == 1.0)
105 return certificate_reporting_test_utils::CERT_REPORT_EXPECTED; 125 return certificate_reporting_test_utils::CERT_REPORT_EXPECTED;
106 } 126 }
107 return certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED; 127 return certificate_reporting_test_utils::CERT_REPORT_NOT_EXPECTED;
108 } 128 }
109 129
110 } // namespace certificate_reporting_test_utils 130 } // namespace certificate_reporting_test_utils
OLDNEW
« no previous file with comments | « chrome/browser/ssl/certificate_reporting_test_utils.h ('k') | chrome/browser/ssl/ssl_browser_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698