| 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 8740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 alternative_service = | 8754 alternative_service = |
| 8755 http_server_properties.GetAlternativeService(http_host_port_pair); | 8755 http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8756 EXPECT_EQ(443, alternative_service.port); | 8756 EXPECT_EQ(443, alternative_service.port); |
| 8757 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), | 8757 EXPECT_EQ(AlternateProtocolFromNextProto(GetParam()), |
| 8758 alternative_service.protocol); | 8758 alternative_service.protocol); |
| 8759 } | 8759 } |
| 8760 | 8760 |
| 8761 TEST_P(HttpNetworkTransactionTest, EmptyAlternateProtocolHeader) { |
| 8762 session_deps_.next_protos = SpdyNextProtos(); |
| 8763 session_deps_.use_alternate_protocols = true; |
| 8764 |
| 8765 MockRead data_reads[] = { |
| 8766 MockRead("HTTP/1.1 200 OK\r\n"), |
| 8767 MockRead("Alternate-Protocol: \r\n\r\n"), |
| 8768 MockRead("hello world"), |
| 8769 MockRead(SYNCHRONOUS, OK), |
| 8770 }; |
| 8771 |
| 8772 HttpRequestInfo request; |
| 8773 request.method = "GET"; |
| 8774 request.url = GURL("http://www.google.com/"); |
| 8775 request.load_flags = 0; |
| 8776 |
| 8777 StaticSocketDataProvider data(data_reads, arraysize(data_reads), NULL, 0); |
| 8778 |
| 8779 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8780 |
| 8781 TestCompletionCallback callback; |
| 8782 |
| 8783 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8784 |
| 8785 HostPortPair http_host_port_pair("www.google.com", 80); |
| 8786 HttpServerProperties& http_server_properties = |
| 8787 *session->http_server_properties(); |
| 8788 http_server_properties.SetAlternateProtocol(http_host_port_pair, 80, QUIC, |
| 8789 1.0); |
| 8790 AlternativeService alternative_service = |
| 8791 http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8792 EXPECT_EQ(alternative_service.protocol, QUIC); |
| 8793 |
| 8794 scoped_ptr<HttpTransaction> trans( |
| 8795 new HttpNetworkTransaction(DEFAULT_PRIORITY, session.get())); |
| 8796 |
| 8797 int rv = trans->Start(&request, callback.callback(), BoundNetLog()); |
| 8798 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 8799 |
| 8800 EXPECT_EQ(OK, callback.WaitForResult()); |
| 8801 |
| 8802 const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 8803 ASSERT_TRUE(response != NULL); |
| 8804 ASSERT_TRUE(response->headers.get() != NULL); |
| 8805 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8806 EXPECT_FALSE(response->was_fetched_via_spdy); |
| 8807 EXPECT_FALSE(response->was_npn_negotiated); |
| 8808 |
| 8809 std::string response_data; |
| 8810 ASSERT_EQ(OK, ReadTransaction(trans.get(), &response_data)); |
| 8811 EXPECT_EQ("hello world", response_data); |
| 8812 |
| 8813 alternative_service = |
| 8814 http_server_properties.GetAlternativeService(http_host_port_pair); |
| 8815 EXPECT_EQ(alternative_service.protocol, UNINITIALIZED_ALTERNATE_PROTOCOL); |
| 8816 } |
| 8817 |
| 8761 TEST_P(HttpNetworkTransactionTest, | 8818 TEST_P(HttpNetworkTransactionTest, |
| 8762 MarkBrokenAlternateProtocolAndFallback) { | 8819 MarkBrokenAlternateProtocolAndFallback) { |
| 8763 session_deps_.use_alternate_protocols = true; | 8820 session_deps_.use_alternate_protocols = true; |
| 8764 | 8821 |
| 8765 HttpRequestInfo request; | 8822 HttpRequestInfo request; |
| 8766 request.method = "GET"; | 8823 request.method = "GET"; |
| 8767 request.url = GURL("http://www.google.com/"); | 8824 request.url = GURL("http://www.google.com/"); |
| 8768 request.load_flags = 0; | 8825 request.load_flags = 0; |
| 8769 | 8826 |
| 8770 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); | 8827 MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| (...skipping 5009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13780 ASSERT_TRUE(response); | 13837 ASSERT_TRUE(response); |
| 13781 ASSERT_TRUE(response->headers.get()); | 13838 ASSERT_TRUE(response->headers.get()); |
| 13782 | 13839 |
| 13783 EXPECT_EQ(101, response->headers->response_code()); | 13840 EXPECT_EQ(101, response->headers->response_code()); |
| 13784 | 13841 |
| 13785 trans.reset(); | 13842 trans.reset(); |
| 13786 session->CloseAllConnections(); | 13843 session->CloseAllConnections(); |
| 13787 } | 13844 } |
| 13788 | 13845 |
| 13789 } // namespace net | 13846 } // namespace net |
| OLD | NEW |