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

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

Issue 2374253010: Add Content-Type header to net::ReportSender reports (Closed)
Patch Set: 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
« no previous file with comments | « net/url_request/report_sender_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 }; 667 };
668 668
669 // A mock ReportSenderInterface that just remembers the latest report 669 // A mock ReportSenderInterface that just remembers the latest report
670 // URI and report to be sent. 670 // URI and report to be sent.
671 class MockCertificateReportSender 671 class MockCertificateReportSender
672 : public TransportSecurityState::ReportSenderInterface { 672 : public TransportSecurityState::ReportSenderInterface {
673 public: 673 public:
674 MockCertificateReportSender() {} 674 MockCertificateReportSender() {}
675 ~MockCertificateReportSender() override {} 675 ~MockCertificateReportSender() override {}
676 676
677 void Send(const GURL& report_uri, const std::string& report) override { 677 void Send(const GURL& report_uri,
678 base::StringPiece content_type,
679 base::StringPiece report) override {
678 latest_report_uri_ = report_uri; 680 latest_report_uri_ = report_uri;
679 latest_report_ = report; 681 report.CopyToString(&latest_report_);
682 content_type.CopyToString(&latest_content_type_);
680 } 683 }
681 684
682 void SetErrorCallback( 685 void SetErrorCallback(
683 const base::Callback<void(const GURL&, int)>& error_callback) override {} 686 const base::Callback<void(const GURL&, int)>& error_callback) override {}
684 687
685 const GURL& latest_report_uri() { return latest_report_uri_; } 688 const GURL& latest_report_uri() { return latest_report_uri_; }
686 const std::string& latest_report() { return latest_report_; } 689 const std::string& latest_report() { return latest_report_; }
690 const std::string& latest_content_type() { return latest_content_type_; }
687 691
688 private: 692 private:
689 GURL latest_report_uri_; 693 GURL latest_report_uri_;
690 std::string latest_report_; 694 std::string latest_report_;
695 std::string latest_content_type_;
691 }; 696 };
692 697
693 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { 698 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate {
694 public: 699 public:
695 bool OnAreExperimentalCookieFeaturesEnabled() const override { return true; } 700 bool OnAreExperimentalCookieFeaturesEnabled() const override { return true; }
696 bool OnAreStrictSecureCookiesEnabled() const override { return true; } 701 bool OnAreStrictSecureCookiesEnabled() const override { return true; }
697 }; 702 };
698 703
699 // OCSPErrorTestDelegate caches the SSLInfo passed to OnSSLCertificateError. 704 // OCSPErrorTestDelegate caches the SSLInfo passed to OnSSLCertificateError.
700 // This is needed because after the certificate failure, the URLRequest will 705 // This is needed because after the certificate failure, the URLRequest will
(...skipping 5358 matching lines...) Expand 10 before | Expand all | Expand 10 after
6059 // Now send a request to trigger the violation. 6064 // Now send a request to trigger the violation.
6060 TestDelegate d; 6065 TestDelegate d;
6061 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( 6066 std::unique_ptr<URLRequest> violating_request(context.CreateRequest(
6062 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); 6067 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d));
6063 violating_request->Start(); 6068 violating_request->Start();
6064 base::RunLoop().Run(); 6069 base::RunLoop().Run();
6065 6070
6066 // Check that a report was sent. 6071 // Check that a report was sent.
6067 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); 6072 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri());
6068 ASSERT_FALSE(mock_report_sender.latest_report().empty()); 6073 ASSERT_FALSE(mock_report_sender.latest_report().empty());
6074 EXPECT_EQ("application/json; charset=utf-8",
6075 mock_report_sender.latest_content_type());
6069 std::unique_ptr<base::Value> value( 6076 std::unique_ptr<base::Value> value(
6070 base::JSONReader::Read(mock_report_sender.latest_report())); 6077 base::JSONReader::Read(mock_report_sender.latest_report()));
6071 ASSERT_TRUE(value); 6078 ASSERT_TRUE(value);
6072 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); 6079 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY));
6073 base::DictionaryValue* report_dict; 6080 base::DictionaryValue* report_dict;
6074 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); 6081 ASSERT_TRUE(value->GetAsDictionary(&report_dict));
6075 std::string report_hostname; 6082 std::string report_hostname;
6076 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); 6083 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname));
6077 EXPECT_EQ(test_server_hostname, report_hostname); 6084 EXPECT_EQ(test_server_hostname, report_hostname);
6078 } 6085 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
6122 TestDelegate d; 6129 TestDelegate d;
6123 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( 6130 std::unique_ptr<URLRequest> violating_request(context.CreateRequest(
6124 https_test_server.GetURL("/hpkp-headers-report-only.html"), 6131 https_test_server.GetURL("/hpkp-headers-report-only.html"),
6125 DEFAULT_PRIORITY, &d)); 6132 DEFAULT_PRIORITY, &d));
6126 violating_request->Start(); 6133 violating_request->Start();
6127 base::RunLoop().Run(); 6134 base::RunLoop().Run();
6128 6135
6129 // Check that a report was sent. 6136 // Check that a report was sent.
6130 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); 6137 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri());
6131 ASSERT_FALSE(mock_report_sender.latest_report().empty()); 6138 ASSERT_FALSE(mock_report_sender.latest_report().empty());
6139 EXPECT_EQ("application/json; charset=utf-8",
6140 mock_report_sender.latest_content_type());
6132 std::unique_ptr<base::Value> value( 6141 std::unique_ptr<base::Value> value(
6133 base::JSONReader::Read(mock_report_sender.latest_report())); 6142 base::JSONReader::Read(mock_report_sender.latest_report()));
6134 ASSERT_TRUE(value); 6143 ASSERT_TRUE(value);
6135 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); 6144 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY));
6136 base::DictionaryValue* report_dict; 6145 base::DictionaryValue* report_dict;
6137 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); 6146 ASSERT_TRUE(value->GetAsDictionary(&report_dict));
6138 std::string report_hostname; 6147 std::string report_hostname;
6139 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); 6148 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname));
6140 EXPECT_EQ(test_server_hostname, report_hostname); 6149 EXPECT_EQ(test_server_hostname, report_hostname);
6141 } 6150 }
(...skipping 4112 matching lines...) Expand 10 before | Expand all | Expand 10 after
10254 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 10263 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10255 10264
10256 req->Start(); 10265 req->Start();
10257 req->Cancel(); 10266 req->Cancel();
10258 base::RunLoop().RunUntilIdle(); 10267 base::RunLoop().RunUntilIdle();
10259 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 10268 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
10260 EXPECT_EQ(0, d.received_redirect_count()); 10269 EXPECT_EQ(0, d.received_redirect_count());
10261 } 10270 }
10262 10271
10263 } // namespace net 10272 } // namespace net
OLDNEW
« no previous file with comments | « 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