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

Side by Side Diff: net/http/http_network_transaction_unittest.cc

Issue 1216703002: Implement multiple alternative services per origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. Created 5 years, 5 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 | « no previous file | net/http/http_server_properties.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "net/http/http_network_transaction.h" 5 #include "net/http/http_network_transaction.h"
6 6
7 #include <math.h> // ceil 7 #include <math.h> // ceil
8 #include <stdarg.h> 8 #include <stdarg.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 8728 matching lines...) Expand 10 before | Expand all | Expand 10 after
8739 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8739 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8740 scoped_ptr<HttpTransaction> trans( 8740 scoped_ptr<HttpTransaction> trans(
8741 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8741 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8742 8742
8743 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 8743 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8744 EXPECT_EQ(ERR_IO_PENDING, rv); 8744 EXPECT_EQ(ERR_IO_PENDING, rv);
8745 8745
8746 HostPortPair http_host_port_pair("www.example.org", 80); 8746 HostPortPair http_host_port_pair("www.example.org", 80);
8747 HttpServerProperties& http_server_properties = 8747 HttpServerProperties& http_server_properties =
8748 *session->http_server_properties(); 8748 *session->http_server_properties();
8749 AlternativeService alternative_service = 8749 AlternativeServiceVector alternative_service_vector =
8750 http_server_properties.GetAlternativeService(http_host_port_pair); 8750 http_server_properties.GetAlternativeServices(http_host_port_pair);
8751 EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); 8751 EXPECT_TRUE(alternative_service_vector.empty());
8752 8752
8753 EXPECT_EQ(OK, callback.WaitForResult()); 8753 EXPECT_EQ(OK, callback.WaitForResult());
8754 8754
8755 const HttpResponseInfo* response = trans->GetResponseInfo(); 8755 const HttpResponseInfo* response = trans->GetResponseInfo();
8756 ASSERT_TRUE(response != NULL); 8756 ASSERT_TRUE(response != NULL);
8757 ASSERT_TRUE(response->headers.get() != NULL); 8757 ASSERT_TRUE(response->headers.get() != NULL);
8758 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8758 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8759 EXPECT_FALSE(response->was_fetched_via_spdy); 8759 EXPECT_FALSE(response->was_fetched_via_spdy);
8760 EXPECT_FALSE(response->was_npn_negotiated); 8760 EXPECT_FALSE(response->was_npn_negotiated);
8761 8761
8762 std::string response_data; 8762 std::string response_data;
8763 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 8763 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8764 EXPECT_EQ("hello world", response_data); 8764 EXPECT_EQ("hello world", response_data);
8765 8765
8766 alternative_service = 8766 alternative_service_vector =
8767 http_server_properties.GetAlternativeService(http_host_port_pair); 8767 http_server_properties.GetAlternativeServices(http_host_port_pair);
8768 EXPECT_EQ(443, alternative_service.port); 8768 ASSERT_EQ(1u, alternative_service_vector.size());
8769 EXPECT_EQ(443, alternative_service_vector[0].port);
8769 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), 8770 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()),
8770 alternative_service.protocol); 8771 alternative_service_vector[0].protocol);
8771 } 8772 }
8772 8773
8773 TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { 8774 TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) {
8774 session_deps_.next_protos = SpdyNextProtos(); 8775 session_deps_.next_protos = SpdyNextProtos();
8775 session_deps_.use_alternate_protocols = true; 8776 session_deps_.use_alternate_protocols = true;
8776 8777
8777 MockRead data_reads[] = { 8778 MockRead data_reads[] = {
8778 MockRead("HTTP/1.1 200 OK\r\n"), 8779 MockRead("HTTP/1.1 200 OK\r\n"),
8779 MockRead("Alternate-Protocol: \r\n\r\n"), 8780 MockRead("Alternate-Protocol: \r\n\r\n"),
8780 MockRead("hello world"), 8781 MockRead("hello world"),
(...skipping 13 matching lines...) Expand all
8794 8795
8795 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8796 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8796 8797
8797 HostPortPair http_host_port_pair("www.example.org", 80); 8798 HostPortPair http_host_port_pair("www.example.org", 80);
8798 HttpServerProperties& http_server_properties = 8799 HttpServerProperties& http_server_properties =
8799 *session->http_server_properties(); 8800 *session->http_server_properties();
8800 AlternativeService alternative_service(QUIC, "", 80); 8801 AlternativeService alternative_service(QUIC, "", 80);
8801 http_server_properties.SetAlternativeService(http_host_port_pair, 8802 http_server_properties.SetAlternativeService(http_host_port_pair,
8802 alternative_service, 1.0); 8803 alternative_service, 1.0);
8803 8804
8804 alternative_service = 8805 AlternativeServiceVector alternative_service_vector =
8805 http_server_properties.GetAlternativeService(http_host_port_pair); 8806 http_server_properties.GetAlternativeServices(http_host_port_pair);
8806 EXPECT_EQ(alternative_service.protocol, QUIC); 8807 ASSERT_EQ(1u, alternative_service_vector.size());
8808 EXPECT_EQ(QUIC, alternative_service_vector[0].protocol);
8807 8809
8808 scoped_ptr<HttpTransaction> trans( 8810 scoped_ptr<HttpTransaction> trans(
8809 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8811 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8810 8812
8811 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 8813 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8812 EXPECT_EQ(ERR_IO_PENDING, rv); 8814 EXPECT_EQ(ERR_IO_PENDING, rv);
8813 8815
8814 EXPECT_EQ(OK, callback.WaitForResult()); 8816 EXPECT_EQ(OK, callback.WaitForResult());
8815 8817
8816 const HttpResponseInfo* response = trans->GetResponseInfo(); 8818 const HttpResponseInfo* response = trans->GetResponseInfo();
8817 ASSERT_TRUE(response != NULL); 8819 ASSERT_TRUE(response != NULL);
8818 ASSERT_TRUE(response->headers.get() != NULL); 8820 ASSERT_TRUE(response->headers.get() != NULL);
8819 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8821 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8820 EXPECT_FALSE(response->was_fetched_via_spdy); 8822 EXPECT_FALSE(response->was_fetched_via_spdy);
8821 EXPECT_FALSE(response->was_npn_negotiated); 8823 EXPECT_FALSE(response->was_npn_negotiated);
8822 8824
8823 std::string response_data; 8825 std::string response_data;
8824 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 8826 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8825 EXPECT_EQ("hello world", response_data); 8827 EXPECT_EQ("hello world", response_data);
8826 8828
8827 alternative_service = 8829 alternative_service_vector =
8828 http_server_properties.GetAlternativeService(http_host_port_pair); 8830 http_server_properties.GetAlternativeServices(http_host_port_pair);
8829 EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); 8831 EXPECT_TRUE(alternative_service_vector.empty());
8830 } 8832 }
8831 8833
8832 TEST_P(HttpNetworkTransactionTest, 8834 TEST_P(HttpNetworkTransactionTest,
8833 MarkBrokenAlternateProtocolAndFallback) { 8835 MarkBrokenAlternateProtocolAndFallback) {
8834 session_deps_.use_alternate_protocols = true; 8836 session_deps_.use_alternate_protocols = true;
8835 8837
8836 HttpRequestInfo request; 8838 HttpRequestInfo request;
8837 request.method = "GET"; 8839 request.method = "GET";
8838 request.url = GURL("http://www.example.org/"); 8840 request.url = GURL("http://www.example.org/");
8839 request.load_flags = 0; 8841 request.load_flags = 0;
(...skipping 12 matching lines...) Expand all
8852 data_reads, arraysize(data_reads), NULL, 0); 8854 data_reads, arraysize(data_reads), NULL, 0);
8853 session_deps_.socket_factory->AddSocketDataProvider(&second_data); 8855 session_deps_.socket_factory->AddSocketDataProvider(&second_data);
8854 8856
8855 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); 8857 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_));
8856 8858
8857 base::WeakPtr<HttpServerProperties> http_server_properties = 8859 base::WeakPtr<HttpServerProperties> http_server_properties =
8858 session->http_server_properties(); 8860 session->http_server_properties();
8859 const HostPortPair host_port_pair = HostPortPair::FromURL(request.url); 8861 const HostPortPair host_port_pair = HostPortPair::FromURL(request.url);
8860 // Port must be < 1024, or the header will be ignored (since initial port was 8862 // Port must be < 1024, or the header will be ignored (since initial port was
8861 // port 80 (another restricted port). 8863 // port 80 (another restricted port).
8862 AlternativeService alternative_service( 8864 const AlternativeService alternative_service(
8863 AlternateProtocolFromNextProto(GetParam()), "www.example.org", 8865 AlternateProtocolFromNextProto(GetParam()), "www.example.org",
8864 666); /* port is ignored by MockConnect anyway */ 8866 666); // Port is ignored by MockConnect anyway.
8865 http_server_properties->SetAlternativeService(host_port_pair, 8867 http_server_properties->SetAlternativeService(host_port_pair,
8866 alternative_service, 1.0); 8868 alternative_service, 1.0);
8867 8869
8868 scoped_ptr<HttpTransaction> trans( 8870 scoped_ptr<HttpTransaction> trans(
8869 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); 8871 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get()));
8870 TestCompletionCallback callback; 8872 TestCompletionCallback callback;
8871 8873
8872 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); 8874 int rv = trans->Start(&request, callback.callback(), BoundNetLog());
8873 EXPECT_EQ(ERR_IO_PENDING, rv); 8875 EXPECT_EQ(ERR_IO_PENDING, rv);
8874 EXPECT_EQ(OK, callback.WaitForResult()); 8876 EXPECT_EQ(OK, callback.WaitForResult());
8875 8877
8876 const HttpResponseInfo* response = trans->GetResponseInfo(); 8878 const HttpResponseInfo* response = trans->GetResponseInfo();
8877 ASSERT_TRUE(response != NULL); 8879 ASSERT_TRUE(response != NULL);
8878 ASSERT_TRUE(response->headers.get() != NULL); 8880 ASSERT_TRUE(response->headers.get() != NULL);
8879 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 8881 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
8880 8882
8881 std::string response_data; 8883 std::string response_data;
8882 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); 8884 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data));
8883 EXPECT_EQ("hello world", response_data); 8885 EXPECT_EQ("hello world", response_data);
8884 8886
8885 alternative_service = 8887 const AlternativeServiceVector alternative_service_vector =
8886 http_server_properties->GetAlternativeService(host_port_pair); 8888 http_server_properties->GetAlternativeServices(host_port_pair);
8887 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); 8889 ASSERT_EQ(1u, alternative_service_vector.size());
8888 EXPECT_TRUE( 8890 EXPECT_EQ(alternative_service, alternative_service_vector[0]);
8889 http_server_properties->IsAlternativeServiceBroken(alternative_service)); 8891 EXPECT_TRUE(http_server_properties->IsAlternativeServiceBroken(
8892 alternative_service_vector[0]));
8890 } 8893 }
8891 8894
8892 TEST_P(HttpNetworkTransactionTest, 8895 TEST_P(HttpNetworkTransactionTest,
8893 AlternateProtocolPortRestrictedBlocked) { 8896 AlternateProtocolPortRestrictedBlocked) {
8894 // Ensure that we're not allowed to redirect traffic via an alternate 8897 // Ensure that we're not allowed to redirect traffic via an alternate
8895 // protocol to an unrestricted (port >= 1024) when the original traffic was 8898 // protocol to an unrestricted (port >= 1024) when the original traffic was
8896 // on a restricted port (port < 1024). Ensure that we can redirect in all 8899 // on a restricted port (port < 1024). Ensure that we can redirect in all
8897 // other cases. 8900 // other cases.
8898 session_deps_.use_alternate_protocols = true; 8901 session_deps_.use_alternate_protocols = true;
8899 8902
(...skipping 5273 matching lines...) Expand 10 before | Expand all | Expand 10 after
14173 ASSERT_TRUE(response); 14176 ASSERT_TRUE(response);
14174 ASSERT_TRUE(response->headers.get()); 14177 ASSERT_TRUE(response->headers.get());
14175 14178
14176 EXPECT_EQ(101, response->headers->response_code()); 14179 EXPECT_EQ(101, response->headers->response_code());
14177 14180
14178 trans.reset(); 14181 trans.reset();
14179 session->CloseAllConnections(); 14182 session->CloseAllConnections();
14180 } 14183 }
14181 14184
14182 } // namespace net 14185 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/http/http_server_properties.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698