| OLD | NEW |
| 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 8716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8727 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); | 8727 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8728 scoped_ptr<HttpTransaction> trans( | 8728 scoped_ptr<HttpTransaction> trans( |
| 8729 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); | 8729 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8730 | 8730 |
| 8731 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); | 8731 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8732 EXPECT_EQ(ERR_IO_PENDING, rv); | 8732 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8733 | 8733 |
| 8734 HostPortPair http_host_port_pair("www.google.com", 80); | 8734 HostPortPair http_host_port_pair("www.google.com", 80); |
| 8735 HttpServerProperties& http_server_properties = | 8735 HttpServerProperties& http_server_properties = |
| 8736 *session->http_server_properties(); | 8736 *session->http_server_properties(); |
| 8737 AlternateProtocolInfo alternate = | 8737 AlternativeService alternative_service = |
| 8738 http_server_properties.GetAlternateProtocol(http_host_port_pair); | 8738 http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8739 EXPECT_EQ(alternate.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); | 8739 EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
| 8740 | 8740 |
| 8741 EXPECT_EQ(OK, callback.WaitForResult()); | 8741 EXPECT_EQ(OK, callback.WaitForResult()); |
| 8742 | 8742 |
| 8743 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8743 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8744 ASSERT_TRUE(response != NULL); | 8744 ASSERT_TRUE(response != NULL); |
| 8745 ASSERT_TRUE(response->headers.get() != NULL); | 8745 ASSERT_TRUE(response->headers.get() != NULL); |
| 8746 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8746 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8747 EXPECT_FALSE(response->was_fetched_via_spdy); | 8747 EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8748 EXPECT_FALSE(response->was_npn_negotiated); | 8748 EXPECT_FALSE(response->was_npn_negotiated); |
| 8749 | 8749 |
| 8750 std::string response_data; | 8750 std::string response_data; |
| 8751 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8751 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8752 EXPECT_EQ("hello world", response_data); | 8752 EXPECT_EQ("hello world", response_data); |
| 8753 | 8753 |
| 8754 alternate = http_server_properties.GetAlternateProtocol(http_host_port_pair); | 8754 alternative_service = |
| 8755 EXPECT_EQ(443, alternate.port); | 8755 http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8756 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), alternate.protocol); | 8756 EXPECT_EQ(443, alternative_service.port); |
| 8757 EXPECT_EQ(1.0, alternate.probability); | 8757 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8758 alternative_service.protocol); |
| 8758 } | 8759 } |
| 8759 | 8760 |
| 8760 TEST_P(HttpNetworkTransactionTest, | 8761 TEST_P(HttpNetworkTransactionTest, |
| 8761 MarkBrokenAlternateProtocolAndFallback) { | 8762 MarkBrokenAlternateProtocolAndFallback) { |
| 8762 session_deps_.use_alternate_protocols = true; | 8763 session_deps_.use_alternate_protocols = true; |
| 8763 | 8764 |
| 8764 HttpRequestInfo request; | 8765 HttpRequestInfo request; |
| 8765 request.method = "GET"; | 8766 request.method = "GET"; |
| 8766 request.url = GURL("http://www.google.com/"); | 8767 request.url = GURL("http://www.google.com/"); |
| 8767 request.load_flags = 0; | 8768 request.load_flags = 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8801 | 8802 |
| 8802 const HttpResponseInfo* response = trans->GetResponseInfo(); | 8803 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8803 ASSERT_TRUE(response != NULL); | 8804 ASSERT_TRUE(response != NULL); |
| 8804 ASSERT_TRUE(response->headers.get() != NULL); | 8805 ASSERT_TRUE(response->headers.get() != NULL); |
| 8805 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); | 8806 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8806 | 8807 |
| 8807 std::string response_data; | 8808 std::string response_data; |
| 8808 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); | 8809 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8809 EXPECT_EQ("hello world", response_data); | 8810 EXPECT_EQ("hello world", response_data); |
| 8810 | 8811 |
| 8811 const AlternateProtocolInfo alternate = | 8812 const AlternativeService alternative_service = |
| 8812 http_server_properties->GetAlternateProtocol(host_port_pair); | 8813 http_server_properties->GetAlternativeService(host_port_pair); |
| 8813 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternate.protocol); | 8814 EXPECT_NE(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service.protocol); |
| 8814 const AlternativeService alternative_service( | |
| 8815 alternate.protocol, host_port_pair.host(), alternate.port); | |
| 8816 EXPECT_TRUE( | 8815 EXPECT_TRUE( |
| 8817 http_server_properties->IsAlternativeServiceBroken(alternative_service)); | 8816 http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 8818 } | 8817 } |
| 8819 | 8818 |
| 8820 TEST_P(HttpNetworkTransactionTest, | 8819 TEST_P(HttpNetworkTransactionTest, |
| 8821 AlternateProtocolPortRestrictedBlocked) { | 8820 AlternateProtocolPortRestrictedBlocked) { |
| 8822 // Ensure that we're not allowed to redirect traffic via an alternate | 8821 // Ensure that we're not allowed to redirect traffic via an alternate |
| 8823 // protocol to an unrestricted (port >= 1024) when the original traffic was | 8822 // protocol to an unrestricted (port >= 1024) when the original traffic was |
| 8824 // on a restricted port (port < 1024). Ensure that we can redirect in all | 8823 // on a restricted port (port < 1024). Ensure that we can redirect in all |
| 8825 // other cases. | 8824 // other cases. |
| (...skipping 4955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13781 ASSERT_TRUE(response); | 13780 ASSERT_TRUE(response); |
| 13782 ASSERT_TRUE(response->headers.get()); | 13781 ASSERT_TRUE(response->headers.get()); |
| 13783 | 13782 |
| 13784 EXPECT_EQ(101, response->headers->response_code()); | 13783 EXPECT_EQ(101, response->headers->response_code()); |
| 13785 | 13784 |
| 13786 trans.reset(); | 13785 trans.reset(); |
| 13787 session->CloseAllConnections(); | 13786 session->CloseAllConnections(); |
| 13788 } | 13787 } |
| 13789 | 13788 |
| 13790 } // namespace net | 13789 } // namespace net |
| OLD | NEW |