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

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

Issue 2769703006: Reporting: Plumb into UrlRequest{HttpJob,Context}. (Closed)
Patch Set: Fix unittest failure. Created 3 years, 8 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/url_request_http_job.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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 #include "net/log/net_log_source.h" 85 #include "net/log/net_log_source.h"
86 #include "net/log/test_net_log.h" 86 #include "net/log/test_net_log.h"
87 #include "net/log/test_net_log_entry.h" 87 #include "net/log/test_net_log_entry.h"
88 #include "net/log/test_net_log_util.h" 88 #include "net/log/test_net_log_util.h"
89 #include "net/net_features.h" 89 #include "net/net_features.h"
90 #include "net/nqe/external_estimate_provider.h" 90 #include "net/nqe/external_estimate_provider.h"
91 #include "net/proxy/proxy_server.h" 91 #include "net/proxy/proxy_server.h"
92 #include "net/proxy/proxy_service.h" 92 #include "net/proxy/proxy_service.h"
93 #include "net/quic/chromium/mock_crypto_client_stream_factory.h" 93 #include "net/quic/chromium/mock_crypto_client_stream_factory.h"
94 #include "net/quic/chromium/quic_server_info.h" 94 #include "net/quic/chromium/quic_server_info.h"
95 #include "net/reporting/reporting_service.h"
95 #include "net/socket/socket_test_util.h" 96 #include "net/socket/socket_test_util.h"
96 #include "net/socket/ssl_client_socket.h" 97 #include "net/socket/ssl_client_socket.h"
97 #include "net/ssl/channel_id_service.h" 98 #include "net/ssl/channel_id_service.h"
98 #include "net/ssl/default_channel_id_store.h" 99 #include "net/ssl/default_channel_id_store.h"
99 #include "net/ssl/ssl_connection_status_flags.h" 100 #include "net/ssl/ssl_connection_status_flags.h"
100 #include "net/ssl/ssl_server_config.h" 101 #include "net/ssl/ssl_server_config.h"
101 #include "net/ssl/token_binding.h" 102 #include "net/ssl/token_binding.h"
102 #include "net/test/cert_test_util.h" 103 #include "net/test/cert_test_util.h"
103 #include "net/test/embedded_test_server/embedded_test_server.h" 104 #include "net/test/embedded_test_server/embedded_test_server.h"
104 #include "net/test/embedded_test_server/http_request.h" 105 #include "net/test/embedded_test_server/http_request.h"
(...skipping 6428 matching lines...) Expand 10 before | Expand all | Expand 10 after
6533 replace_host.SetHostStr(kExpectCTStaticHostname); 6534 replace_host.SetHostStr(kExpectCTStaticHostname);
6534 url = url.ReplaceComponents(replace_host); 6535 url = url.ReplaceComponents(replace_host);
6535 std::unique_ptr<URLRequest> violating_request( 6536 std::unique_ptr<URLRequest> violating_request(
6536 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); 6537 context.CreateRequest(url, DEFAULT_PRIORITY, &d));
6537 violating_request->Start(); 6538 violating_request->Start();
6538 base::RunLoop().Run(); 6539 base::RunLoop().Run();
6539 6540
6540 EXPECT_EQ(1u, reporter.num_failures()); 6541 EXPECT_EQ(1u, reporter.num_failures());
6541 } 6542 }
6542 6543
6544 namespace {
6545
6546 class TestReportingService : public ReportingService {
6547 public:
6548 struct Header {
6549 GURL url;
6550 std::string header_value;
6551 };
6552
6553 ~TestReportingService() override {}
6554
6555 const std::vector<Header>& headers() { return headers_; }
6556
6557 void QueueReport(const GURL& url,
6558 const std::string& group,
6559 const std::string& type,
6560 std::unique_ptr<const base::Value> body) override {
6561 NOTIMPLEMENTED();
6562 }
6563
6564 void ProcessHeader(const GURL& url,
6565 const std::string& header_value) override {
6566 headers_.push_back({url, header_value});
6567 }
6568
6569 private:
6570 std::vector<Header> headers_;
6571 };
6572
6573 std::unique_ptr<test_server::HttpResponse> SendReportToHeader(
6574 const test_server::HttpRequest& request) {
6575 std::unique_ptr<test_server::BasicHttpResponse> http_response(
6576 new test_server::BasicHttpResponse);
6577 http_response->set_code(HTTP_OK);
6578 http_response->AddCustomHeader("Report-To", "foo");
6579 http_response->AddCustomHeader("Report-To", "bar");
6580 return std::move(http_response);
6581 }
6582
6583 } // namespace
6584
6585 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderNoService) {
6586 http_test_server()->RegisterRequestHandler(base::Bind(&SendReportToHeader));
6587 ASSERT_TRUE(http_test_server()->Start());
6588 GURL request_url = http_test_server()->GetURL("/");
6589
6590 TestNetworkDelegate network_delegate;
6591 TestURLRequestContext context(true);
6592 context.set_network_delegate(&network_delegate);
6593 context.Init();
6594
6595 TestDelegate d;
6596 std::unique_ptr<URLRequest> request(
6597 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d));
6598 request->Start();
6599 base::RunLoop().Run();
6600 }
6601
6602 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderHTTP) {
6603 http_test_server()->RegisterRequestHandler(base::Bind(&SendReportToHeader));
6604 ASSERT_TRUE(http_test_server()->Start());
6605 GURL request_url = http_test_server()->GetURL("/");
6606
6607 TestNetworkDelegate network_delegate;
6608 TestReportingService reporting_service;
6609 TestURLRequestContext context(true);
6610 context.set_network_delegate(&network_delegate);
6611 context.set_reporting_service(&reporting_service);
6612 context.Init();
6613
6614 TestDelegate d;
6615 std::unique_ptr<URLRequest> request(
6616 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d));
6617 request->Start();
6618 base::RunLoop().Run();
6619
6620 EXPECT_TRUE(reporting_service.headers().empty());
6621 }
6622
6623 TEST_F(URLRequestTestHTTP, ProcessReportToHeaderHTTPS) {
6624 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
6625 https_test_server.RegisterRequestHandler(base::Bind(&SendReportToHeader));
6626 ASSERT_TRUE(https_test_server.Start());
6627 GURL request_url = https_test_server.GetURL("/");
6628
6629 TestNetworkDelegate network_delegate;
6630 TestReportingService reporting_service;
6631 TestURLRequestContext context(true);
6632 context.set_network_delegate(&network_delegate);
6633 context.set_reporting_service(&reporting_service);
6634 context.Init();
6635
6636 TestDelegate d;
6637 std::unique_ptr<URLRequest> request(
6638 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d));
6639 request->Start();
6640 base::RunLoop().Run();
6641
6642 ASSERT_EQ(1u, reporting_service.headers().size());
6643 EXPECT_EQ(request_url, reporting_service.headers()[0].url);
6644 EXPECT_EQ("foo, bar", reporting_service.headers()[0].header_value);
6645 }
6646
6647 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderInvalidHTTPS) {
6648 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS);
6649 https_test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME);
6650 https_test_server.RegisterRequestHandler(base::Bind(&SendReportToHeader));
6651 ASSERT_TRUE(https_test_server.Start());
6652 GURL request_url = https_test_server.GetURL("/");
6653
6654 TestNetworkDelegate network_delegate;
6655 TestReportingService reporting_service;
6656 TestURLRequestContext context(true);
6657 context.set_network_delegate(&network_delegate);
6658 context.set_reporting_service(&reporting_service);
6659 context.Init();
6660
6661 TestDelegate d;
6662 d.set_allow_certificate_errors(true);
6663 std::unique_ptr<URLRequest> request(
6664 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d));
6665 request->Start();
6666 base::RunLoop().Run();
6667
6668 EXPECT_TRUE(d.have_certificate_errors());
6669 EXPECT_TRUE(IsCertStatusError(request->ssl_info().cert_status));
6670 EXPECT_TRUE(reporting_service.headers().empty());
6671 }
6672
6543 #endif // !defined(OS_IOS) 6673 #endif // !defined(OS_IOS)
6544 6674
6545 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { 6675 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) {
6546 ASSERT_TRUE(http_test_server()->Start()); 6676 ASSERT_TRUE(http_test_server()->Start());
6547 6677
6548 TestDelegate d; 6678 TestDelegate d;
6549 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( 6679 std::unique_ptr<URLRequest> req(default_context_.CreateRequest(
6550 http_test_server()->GetURL("/content-type-normalization.html"), 6680 http_test_server()->GetURL("/content-type-normalization.html"),
6551 DEFAULT_PRIORITY, &d)); 6681 DEFAULT_PRIORITY, &d));
6552 req->Start(); 6682 req->Start();
(...skipping 4319 matching lines...) Expand 10 before | Expand all | Expand 10 after
10872 AddTestInterceptor()->set_main_intercept_job(std::move(job)); 11002 AddTestInterceptor()->set_main_intercept_job(std::move(job));
10873 11003
10874 req->Start(); 11004 req->Start();
10875 req->Cancel(); 11005 req->Cancel();
10876 base::RunLoop().RunUntilIdle(); 11006 base::RunLoop().RunUntilIdle();
10877 EXPECT_EQ(ERR_ABORTED, d.request_status()); 11007 EXPECT_EQ(ERR_ABORTED, d.request_status());
10878 EXPECT_EQ(0, d.received_redirect_count()); 11008 EXPECT_EQ(0, d.received_redirect_count());
10879 } 11009 }
10880 11010
10881 } // namespace net 11011 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request_http_job.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698