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

Side by Side Diff: net/url_request/url_request_unittest.cc

Issue 2365353004: Add Content-Type header to net::ReportSender reports (Closed)
Patch Set: update some unit test subclasses Created 4 years, 2 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <memory> 5 #include <memory>
6 #include <utility> 6 #include <utility>
7 7
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 662 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 : public TransportSecurityState::ReportSenderInterface { 673 : public TransportSecurityState::ReportSenderInterface {
674 public: 674 public:
675 MockCertificateReportSender() {} 675 MockCertificateReportSender() {}
676 ~MockCertificateReportSender() override {} 676 ~MockCertificateReportSender() override {}
677 677
678 void Send(const GURL& report_uri, const std::string& report) override { 678 void Send(const GURL& report_uri, const std::string& report) override {
679 latest_report_uri_ = report_uri; 679 latest_report_uri_ = report_uri;
680 latest_report_ = report; 680 latest_report_ = report;
681 } 681 }
682 682
683 void SetContentTypeHeader(const std::string& content_type) override {
684 latest_content_type_ = content_type;
685 }
686
683 void SetErrorCallback( 687 void SetErrorCallback(
684 const base::Callback<void(const GURL&, int)>& error_callback) override {} 688 const base::Callback<void(const GURL&, int)>& error_callback) override {}
685 689
686 const GURL& latest_report_uri() { return latest_report_uri_; } 690 const GURL& latest_report_uri() { return latest_report_uri_; }
687 const std::string& latest_report() { return latest_report_; } 691 const std::string& latest_report() { return latest_report_; }
692 const std::string& latest_content_type() { return latest_content_type_; }
688 693
689 private: 694 private:
690 GURL latest_report_uri_; 695 GURL latest_report_uri_;
691 std::string latest_report_; 696 std::string latest_report_;
697 std::string latest_content_type_;
692 }; 698 };
693 699
694 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { 700 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate {
695 public: 701 public:
696 bool OnAreExperimentalCookieFeaturesEnabled() const override { return true; } 702 bool OnAreExperimentalCookieFeaturesEnabled() const override { return true; }
697 bool OnAreStrictSecureCookiesEnabled() const override { return true; } 703 bool OnAreStrictSecureCookiesEnabled() const override { return true; }
698 }; 704 };
699 705
700 // OCSPErrorTestDelegate caches the SSLInfo passed to OnSSLCertificateError. 706 // OCSPErrorTestDelegate caches the SSLInfo passed to OnSSLCertificateError.
701 // This is needed because after the certificate failure, the URLRequest will 707 // This is needed because after the certificate failure, the URLRequest will
(...skipping 5313 matching lines...) Expand 10 before | Expand all | Expand 10 after
6015 // Now send a request to trigger the violation. 6021 // Now send a request to trigger the violation.
6016 TestDelegate d; 6022 TestDelegate d;
6017 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( 6023 std::unique_ptr<URLRequest> violating_request(context.CreateRequest(
6018 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); 6024 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d));
6019 violating_request->Start(); 6025 violating_request->Start();
6020 base::RunLoop().Run(); 6026 base::RunLoop().Run();
6021 6027
6022 // Check that a report was sent. 6028 // Check that a report was sent.
6023 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); 6029 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri());
6024 ASSERT_FALSE(mock_report_sender.latest_report().empty()); 6030 ASSERT_FALSE(mock_report_sender.latest_report().empty());
6031 EXPECT_EQ("application/json", mock_report_sender.latest_content_type());
6025 std::unique_ptr<base::Value> value( 6032 std::unique_ptr<base::Value> value(
6026 base::JSONReader::Read(mock_report_sender.latest_report())); 6033 base::JSONReader::Read(mock_report_sender.latest_report()));
6027 ASSERT_TRUE(value); 6034 ASSERT_TRUE(value);
6028 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); 6035 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY));
6029 base::DictionaryValue* report_dict; 6036 base::DictionaryValue* report_dict;
6030 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); 6037 ASSERT_TRUE(value->GetAsDictionary(&report_dict));
6031 std::string report_hostname; 6038 std::string report_hostname;
6032 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); 6039 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname));
6033 EXPECT_EQ(test_server_hostname, report_hostname); 6040 EXPECT_EQ(test_server_hostname, report_hostname);
6034 } 6041 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6078 TestDelegate d; 6085 TestDelegate d;
6079 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( 6086 std::unique_ptr<URLRequest> violating_request(context.CreateRequest(
6080 https_test_server.GetURL("/hpkp-headers-report-only.html"), 6087 https_test_server.GetURL("/hpkp-headers-report-only.html"),
6081 DEFAULT_PRIORITY, &d)); 6088 DEFAULT_PRIORITY, &d));
6082 violating_request->Start(); 6089 violating_request->Start();
6083 base::RunLoop().Run(); 6090 base::RunLoop().Run();
6084 6091
6085 // Check that a report was sent. 6092 // Check that a report was sent.
6086 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); 6093 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri());
6087 ASSERT_FALSE(mock_report_sender.latest_report().empty()); 6094 ASSERT_FALSE(mock_report_sender.latest_report().empty());
6095 EXPECT_EQ("application/json", mock_report_sender.latest_content_type());
6088 std::unique_ptr<base::Value> value( 6096 std::unique_ptr<base::Value> value(
6089 base::JSONReader::Read(mock_report_sender.latest_report())); 6097 base::JSONReader::Read(mock_report_sender.latest_report()));
6090 ASSERT_TRUE(value); 6098 ASSERT_TRUE(value);
6091 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); 6099 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY));
6092 base::DictionaryValue* report_dict; 6100 base::DictionaryValue* report_dict;
6093 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); 6101 ASSERT_TRUE(value->GetAsDictionary(&report_dict));
6094 std::string report_hostname; 6102 std::string report_hostname;
6095 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); 6103 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname));
6096 EXPECT_EQ(test_server_hostname, report_hostname); 6104 EXPECT_EQ(test_server_hostname, report_hostname);
6097 } 6105 }
(...skipping 3132 matching lines...) Expand 10 before | Expand all | Expand 10 after
9230 GURL::Replacements replace_host; 9238 GURL::Replacements replace_host;
9231 replace_host.SetHostStr(kExpectStapleStaticHostname); 9239 replace_host.SetHostStr(kExpectStapleStaticHostname);
9232 url = url.ReplaceComponents(replace_host); 9240 url = url.ReplaceComponents(replace_host);
9233 std::unique_ptr<URLRequest> violating_request( 9241 std::unique_ptr<URLRequest> violating_request(
9234 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 9242 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
9235 violating_request->Start(); 9243 violating_request->Start();
9236 base::RunLoop().Run(); 9244 base::RunLoop().Run();
9237 9245
9238 // Confirm a report was sent. 9246 // Confirm a report was sent.
9239 EXPECT_FALSE(mock_report_sender.latest_report().empty()); 9247 EXPECT_FALSE(mock_report_sender.latest_report().empty());
9248 EXPECT_EQ("application/json", mock_report_sender.latest_content_type());
9240 EXPECT_EQ(GURL(kExpectStapleReportURI), 9249 EXPECT_EQ(GURL(kExpectStapleReportURI),
9241 mock_report_sender.latest_report_uri()); 9250 mock_report_sender.latest_report_uri());
9242 } 9251 }
9243 9252
9244 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) { 9253 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) {
9245 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); 9254 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
9246 https_test_server.SetSSLConfig( 9255 https_test_server.SetSSLConfig(
9247 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); 9256 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN);
9248 https_test_server.ServeFilesFromSourceDirectory( 9257 https_test_server.ServeFilesFromSourceDirectory(
9249 base::FilePath(kTestFilePath)); 9258 base::FilePath(kTestFilePath));
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after
10202 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10211 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10203 10212
10204 req->Start(); 10213 req->Start();
10205 req->Cancel(); 10214 req->Cancel();
10206 base::RunLoop().RunUntilIdle(); 10215 base::RunLoop().RunUntilIdle();
10207 EXPECT_EQ(ERR_ABORTED, d.request_status()); 10216 EXPECT_EQ(ERR_ABORTED, d.request_status());
10208 EXPECT_EQ(0, d.received_redirect_count()); 10217 EXPECT_EQ(0, d.received_redirect_count());
10209 } 10218 }
10210 10219
10211 } // namespace net 10220 } // namespace net
OLDNEW
« net/http/transport_security_state.h ('K') | « net/url_request/report_sender_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698