OLD | NEW |
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 657 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
668 }; | 668 }; |
669 | 669 |
670 // A mock ReportSenderInterface that just remembers the latest report | 670 // A mock ReportSenderInterface that just remembers the latest report |
671 // URI and report to be sent. | 671 // URI and report to be sent. |
672 class MockCertificateReportSender | 672 class MockCertificateReportSender |
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, |
| 679 const std::string& content_type, |
| 680 const std::string& report) override { |
679 latest_report_uri_ = report_uri; | 681 latest_report_uri_ = report_uri; |
680 latest_report_ = report; | 682 latest_report_ = report; |
| 683 latest_content_type_ = content_type; |
681 } | 684 } |
682 | 685 |
683 void SetErrorCallback( | 686 void SetErrorCallback( |
684 const base::Callback<void(const GURL&, int)>& error_callback) override {} | 687 const base::Callback<void(const GURL&, int)>& error_callback) override {} |
685 | 688 |
686 const GURL& latest_report_uri() { return latest_report_uri_; } | 689 const GURL& latest_report_uri() { return latest_report_uri_; } |
687 const std::string& latest_report() { return latest_report_; } | 690 const std::string& latest_report() { return latest_report_; } |
| 691 const std::string& latest_content_type() { return latest_content_type_; } |
688 | 692 |
689 private: | 693 private: |
690 GURL latest_report_uri_; | 694 GURL latest_report_uri_; |
691 std::string latest_report_; | 695 std::string latest_report_; |
| 696 std::string latest_content_type_; |
692 }; | 697 }; |
693 | 698 |
694 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { | 699 class TestExperimentalFeaturesNetworkDelegate : public TestNetworkDelegate { |
695 public: | 700 public: |
696 bool OnAreExperimentalCookieFeaturesEnabled() const override { return true; } | 701 bool OnAreExperimentalCookieFeaturesEnabled() const override { return true; } |
697 bool OnAreStrictSecureCookiesEnabled() const override { return true; } | 702 bool OnAreStrictSecureCookiesEnabled() const override { return true; } |
698 }; | 703 }; |
699 | 704 |
700 // OCSPErrorTestDelegate caches the SSLInfo passed to OnSSLCertificateError. | 705 // OCSPErrorTestDelegate caches the SSLInfo passed to OnSSLCertificateError. |
701 // This is needed because after the certificate failure, the URLRequest will | 706 // This is needed because after the certificate failure, the URLRequest will |
(...skipping 5313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6015 // Now send a request to trigger the violation. | 6020 // Now send a request to trigger the violation. |
6016 TestDelegate d; | 6021 TestDelegate d; |
6017 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( | 6022 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
6018 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); | 6023 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); |
6019 violating_request->Start(); | 6024 violating_request->Start(); |
6020 base::RunLoop().Run(); | 6025 base::RunLoop().Run(); |
6021 | 6026 |
6022 // Check that a report was sent. | 6027 // Check that a report was sent. |
6023 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); | 6028 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); |
6024 ASSERT_FALSE(mock_report_sender.latest_report().empty()); | 6029 ASSERT_FALSE(mock_report_sender.latest_report().empty()); |
| 6030 EXPECT_EQ("application/json", mock_report_sender.latest_content_type()); |
6025 std::unique_ptr<base::Value> value( | 6031 std::unique_ptr<base::Value> value( |
6026 base::JSONReader::Read(mock_report_sender.latest_report())); | 6032 base::JSONReader::Read(mock_report_sender.latest_report())); |
6027 ASSERT_TRUE(value); | 6033 ASSERT_TRUE(value); |
6028 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 6034 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
6029 base::DictionaryValue* report_dict; | 6035 base::DictionaryValue* report_dict; |
6030 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 6036 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
6031 std::string report_hostname; | 6037 std::string report_hostname; |
6032 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 6038 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
6033 EXPECT_EQ(test_server_hostname, report_hostname); | 6039 EXPECT_EQ(test_server_hostname, report_hostname); |
6034 } | 6040 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6078 TestDelegate d; | 6084 TestDelegate d; |
6079 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( | 6085 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
6080 https_test_server.GetURL("/hpkp-headers-report-only.html"), | 6086 https_test_server.GetURL("/hpkp-headers-report-only.html"), |
6081 DEFAULT_PRIORITY, &d)); | 6087 DEFAULT_PRIORITY, &d)); |
6082 violating_request->Start(); | 6088 violating_request->Start(); |
6083 base::RunLoop().Run(); | 6089 base::RunLoop().Run(); |
6084 | 6090 |
6085 // Check that a report was sent. | 6091 // Check that a report was sent. |
6086 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); | 6092 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); |
6087 ASSERT_FALSE(mock_report_sender.latest_report().empty()); | 6093 ASSERT_FALSE(mock_report_sender.latest_report().empty()); |
| 6094 EXPECT_EQ("application/json", mock_report_sender.latest_content_type()); |
6088 std::unique_ptr<base::Value> value( | 6095 std::unique_ptr<base::Value> value( |
6089 base::JSONReader::Read(mock_report_sender.latest_report())); | 6096 base::JSONReader::Read(mock_report_sender.latest_report())); |
6090 ASSERT_TRUE(value); | 6097 ASSERT_TRUE(value); |
6091 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 6098 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
6092 base::DictionaryValue* report_dict; | 6099 base::DictionaryValue* report_dict; |
6093 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 6100 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
6094 std::string report_hostname; | 6101 std::string report_hostname; |
6095 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 6102 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
6096 EXPECT_EQ(test_server_hostname, report_hostname); | 6103 EXPECT_EQ(test_server_hostname, report_hostname); |
6097 } | 6104 } |
(...skipping 4104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10202 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 10209 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
10203 | 10210 |
10204 req->Start(); | 10211 req->Start(); |
10205 req->Cancel(); | 10212 req->Cancel(); |
10206 base::RunLoop().RunUntilIdle(); | 10213 base::RunLoop().RunUntilIdle(); |
10207 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 10214 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
10208 EXPECT_EQ(0, d.received_redirect_count()); | 10215 EXPECT_EQ(0, d.received_redirect_count()); |
10209 } | 10216 } |
10210 | 10217 |
10211 } // namespace net | 10218 } // namespace net |
OLD | NEW |