| 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 base::StringPiece content_type, |
| 680 base::StringPiece report) override { |
| 679 latest_report_uri_ = report_uri; | 681 latest_report_uri_ = report_uri; |
| 680 latest_report_ = report; | 682 report.CopyToString(&latest_report_); |
| 683 content_type.CopyToString(&latest_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; charset=utf-8", |
| 6031 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 Loading... |
| 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; charset=utf-8", |
| 6096 mock_report_sender.latest_content_type()); |
| 6088 std::unique_ptr<base::Value> value( | 6097 std::unique_ptr<base::Value> value( |
| 6089 base::JSONReader::Read(mock_report_sender.latest_report())); | 6098 base::JSONReader::Read(mock_report_sender.latest_report())); |
| 6090 ASSERT_TRUE(value); | 6099 ASSERT_TRUE(value); |
| 6091 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); | 6100 ASSERT_TRUE(value->IsType(base::Value::TYPE_DICTIONARY)); |
| 6092 base::DictionaryValue* report_dict; | 6101 base::DictionaryValue* report_dict; |
| 6093 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); | 6102 ASSERT_TRUE(value->GetAsDictionary(&report_dict)); |
| 6094 std::string report_hostname; | 6103 std::string report_hostname; |
| 6095 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); | 6104 EXPECT_TRUE(report_dict->GetString("hostname", &report_hostname)); |
| 6096 EXPECT_EQ(test_server_hostname, report_hostname); | 6105 EXPECT_EQ(test_server_hostname, report_hostname); |
| 6097 } | 6106 } |
| (...skipping 4104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |