| 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 "net/http/http_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 15 #include "net/base/port_util.h" | 15 #include "net/base/port_util.h" |
| 16 #include "net/base/test_completion_callback.h" | 16 #include "net/base/test_completion_callback.h" |
| 17 #include "net/base/test_data_directory.h" | 17 #include "net/base/test_data_directory.h" |
| 18 #include "net/cert/mock_cert_verifier.h" | 18 #include "net/cert/mock_cert_verifier.h" |
| 19 #include "net/dns/mock_host_resolver.h" | 19 #include "net/dns/mock_host_resolver.h" |
| 20 #include "net/http/bidirectional_stream_job.h" | 20 #include "net/http/bidirectional_stream_impl.h" |
| 21 #include "net/http/bidirectional_stream_request_info.h" | 21 #include "net/http/bidirectional_stream_request_info.h" |
| 22 #include "net/http/http_auth_handler_factory.h" | 22 #include "net/http/http_auth_handler_factory.h" |
| 23 #include "net/http/http_network_session.h" | 23 #include "net/http/http_network_session.h" |
| 24 #include "net/http/http_network_session_peer.h" | 24 #include "net/http/http_network_session_peer.h" |
| 25 #include "net/http/http_network_transaction.h" | 25 #include "net/http/http_network_transaction.h" |
| 26 #include "net/http/http_request_info.h" | 26 #include "net/http/http_request_info.h" |
| 27 #include "net/http/http_server_properties.h" | 27 #include "net/http/http_server_properties.h" |
| 28 #include "net/http/http_server_properties_impl.h" | 28 #include "net/http/http_server_properties_impl.h" |
| 29 #include "net/http/http_stream.h" | 29 #include "net/http/http_stream.h" |
| 30 #include "net/http/transport_security_state.h" | 30 #include "net/http/transport_security_state.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 51 #include "net/test/cert_test_util.h" | 51 #include "net/test/cert_test_util.h" |
| 52 | 52 |
| 53 // This file can be included from net/http even though | 53 // This file can be included from net/http even though |
| 54 // it is in net/websockets because it doesn't | 54 // it is in net/websockets because it doesn't |
| 55 // introduce any link dependency to net/websockets. | 55 // introduce any link dependency to net/websockets. |
| 56 #include "net/websockets/websocket_handshake_stream_base.h" | 56 #include "net/websockets/websocket_handshake_stream_base.h" |
| 57 #include "testing/gtest/include/gtest/gtest.h" | 57 #include "testing/gtest/include/gtest/gtest.h" |
| 58 | 58 |
| 59 namespace net { | 59 namespace net { |
| 60 | 60 |
| 61 class BidirectionalStreamJob; | 61 class BidirectionalStreamImpl; |
| 62 | 62 |
| 63 namespace { | 63 namespace { |
| 64 | 64 |
| 65 class MockWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { | 65 class MockWebSocketHandshakeStream : public WebSocketHandshakeStreamBase { |
| 66 public: | 66 public: |
| 67 enum StreamType { | 67 enum StreamType { |
| 68 kStreamTypeBasic, | 68 kStreamTypeBasic, |
| 69 kStreamTypeSpdy, | 69 kStreamTypeSpdy, |
| 70 }; | 70 }; |
| 71 | 71 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 const ProxyInfo& used_proxy_info, | 180 const ProxyInfo& used_proxy_info, |
| 181 WebSocketHandshakeStreamBase* stream) override { | 181 WebSocketHandshakeStreamBase* stream) override { |
| 182 stream_done_ = true; | 182 stream_done_ = true; |
| 183 if (waiting_for_stream_) | 183 if (waiting_for_stream_) |
| 184 base::MessageLoop::current()->QuitWhenIdle(); | 184 base::MessageLoop::current()->QuitWhenIdle(); |
| 185 websocket_stream_.reset(stream); | 185 websocket_stream_.reset(stream); |
| 186 used_ssl_config_ = used_ssl_config; | 186 used_ssl_config_ = used_ssl_config; |
| 187 used_proxy_info_ = used_proxy_info; | 187 used_proxy_info_ = used_proxy_info; |
| 188 } | 188 } |
| 189 | 189 |
| 190 void OnBidirectionalStreamJobReady(const SSLConfig& used_ssl_config, | 190 void OnBidirectionalStreamImplReady( |
| 191 const ProxyInfo& used_proxy_info, | 191 const SSLConfig& used_ssl_config, |
| 192 BidirectionalStreamJob* stream) override { | 192 const ProxyInfo& used_proxy_info, |
| 193 BidirectionalStreamImpl* stream) override { |
| 193 stream_done_ = true; | 194 stream_done_ = true; |
| 194 if (waiting_for_stream_) | 195 if (waiting_for_stream_) |
| 195 base::MessageLoop::current()->QuitWhenIdle(); | 196 base::MessageLoop::current()->QuitWhenIdle(); |
| 196 bidirectional_stream_job_.reset(stream); | 197 bidirectional_stream_impl_.reset(stream); |
| 197 used_ssl_config_ = used_ssl_config; | 198 used_ssl_config_ = used_ssl_config; |
| 198 used_proxy_info_ = used_proxy_info; | 199 used_proxy_info_ = used_proxy_info; |
| 199 } | 200 } |
| 200 | 201 |
| 201 void OnStreamFailed(int status, | 202 void OnStreamFailed(int status, |
| 202 const SSLConfig& used_ssl_config, | 203 const SSLConfig& used_ssl_config, |
| 203 SSLFailureState ssl_failure_state) override { | 204 SSLFailureState ssl_failure_state) override { |
| 204 stream_done_ = true; | 205 stream_done_ = true; |
| 205 if (waiting_for_stream_) | 206 if (waiting_for_stream_) |
| 206 base::MessageLoop::current()->QuitWhenIdle(); | 207 base::MessageLoop::current()->QuitWhenIdle(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 } | 245 } |
| 245 | 246 |
| 246 HttpStream* stream() { | 247 HttpStream* stream() { |
| 247 return stream_.get(); | 248 return stream_.get(); |
| 248 } | 249 } |
| 249 | 250 |
| 250 MockWebSocketHandshakeStream* websocket_stream() { | 251 MockWebSocketHandshakeStream* websocket_stream() { |
| 251 return static_cast<MockWebSocketHandshakeStream*>(websocket_stream_.get()); | 252 return static_cast<MockWebSocketHandshakeStream*>(websocket_stream_.get()); |
| 252 } | 253 } |
| 253 | 254 |
| 254 BidirectionalStreamJob* bidirectional_stream_job() { | 255 BidirectionalStreamImpl* bidirectional_stream_impl() { |
| 255 return bidirectional_stream_job_.get(); | 256 return bidirectional_stream_impl_.get(); |
| 256 } | 257 } |
| 257 | 258 |
| 258 bool stream_done() const { return stream_done_; } | 259 bool stream_done() const { return stream_done_; } |
| 259 int error_status() const { return error_status_; } | 260 int error_status() const { return error_status_; } |
| 260 | 261 |
| 261 private: | 262 private: |
| 262 bool waiting_for_stream_; | 263 bool waiting_for_stream_; |
| 263 bool stream_done_; | 264 bool stream_done_; |
| 264 scoped_ptr<HttpStream> stream_; | 265 scoped_ptr<HttpStream> stream_; |
| 265 scoped_ptr<WebSocketHandshakeStreamBase> websocket_stream_; | 266 scoped_ptr<WebSocketHandshakeStreamBase> websocket_stream_; |
| 266 scoped_ptr<BidirectionalStreamJob> bidirectional_stream_job_; | 267 scoped_ptr<BidirectionalStreamImpl> bidirectional_stream_impl_; |
| 267 SSLConfig used_ssl_config_; | 268 SSLConfig used_ssl_config_; |
| 268 ProxyInfo used_proxy_info_; | 269 ProxyInfo used_proxy_info_; |
| 269 int error_status_; | 270 int error_status_; |
| 270 | 271 |
| 271 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); | 272 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
| 272 }; | 273 }; |
| 273 | 274 |
| 274 class WebSocketSpdyHandshakeStream : public MockWebSocketHandshakeStream { | 275 class WebSocketSpdyHandshakeStream : public MockWebSocketHandshakeStream { |
| 275 public: | 276 public: |
| 276 explicit WebSocketSpdyHandshakeStream( | 277 explicit WebSocketSpdyHandshakeStream( |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 const ProxyRetryInfoMap& retry_info = | 731 const ProxyRetryInfoMap& retry_info = |
| 731 session->proxy_service()->proxy_retry_info(); | 732 session->proxy_service()->proxy_retry_info(); |
| 732 EXPECT_EQ(1u, retry_info.size()) << mock_error[i]; | 733 EXPECT_EQ(1u, retry_info.size()) << mock_error[i]; |
| 733 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 734 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 734 | 735 |
| 735 ProxyRetryInfoMap::const_iterator iter = retry_info.find("quic://bad:99"); | 736 ProxyRetryInfoMap::const_iterator iter = retry_info.find("quic://bad:99"); |
| 736 EXPECT_TRUE(iter != retry_info.end()) << mock_error[i]; | 737 EXPECT_TRUE(iter != retry_info.end()) << mock_error[i]; |
| 737 } | 738 } |
| 738 } | 739 } |
| 739 | 740 |
| 740 // BidirectionalStreamJob::Delegate to wait until response headers are | 741 // BidirectionalStreamImpl::Delegate to wait until response headers are |
| 741 // received. | 742 // received. |
| 742 class TestBidirectionalDelegate : public BidirectionalStreamJob::Delegate { | 743 class TestBidirectionalDelegate : public BidirectionalStreamImpl::Delegate { |
| 743 public: | 744 public: |
| 744 void WaitUntilDone() { loop_.Run(); } | 745 void WaitUntilDone() { loop_.Run(); } |
| 745 | 746 |
| 746 const SpdyHeaderBlock& response_headers() const { return response_headers_; } | 747 const SpdyHeaderBlock& response_headers() const { return response_headers_; } |
| 747 | 748 |
| 748 private: | 749 private: |
| 749 void OnHeadersSent() override {} | 750 void OnHeadersSent() override {} |
| 750 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override { | 751 void OnHeadersReceived(const SpdyHeaderBlock& response_headers) override { |
| 751 response_headers_ = response_headers; | 752 response_headers_ = response_headers; |
| 752 loop_.Quit(); | 753 loop_.Quit(); |
| (...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1449 EXPECT_EQ(1, GetSocketPoolGroupCount( | 1450 EXPECT_EQ(1, GetSocketPoolGroupCount( |
| 1450 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1451 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1451 EXPECT_EQ(0, GetSocketPoolGroupCount( | 1452 EXPECT_EQ(0, GetSocketPoolGroupCount( |
| 1452 session->GetTransportSocketPool( | 1453 session->GetTransportSocketPool( |
| 1453 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1454 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1454 EXPECT_EQ(0, GetSocketPoolGroupCount( | 1455 EXPECT_EQ(0, GetSocketPoolGroupCount( |
| 1455 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1456 session->GetSSLSocketPool(HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1456 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1457 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 1457 } | 1458 } |
| 1458 | 1459 |
| 1459 TEST_P(HttpStreamFactoryTest, RequestBidirectionalStreamJob) { | 1460 TEST_P(HttpStreamFactoryTest, RequestBidirectionalStreamImpl) { |
| 1460 SpdySessionDependencies session_deps(GetParam(), | 1461 SpdySessionDependencies session_deps(GetParam(), |
| 1461 ProxyService::CreateDirect()); | 1462 ProxyService::CreateDirect()); |
| 1462 | 1463 |
| 1463 MockRead mock_read(ASYNC, OK); | 1464 MockRead mock_read(ASYNC, OK); |
| 1464 SequencedSocketData socket_data(&mock_read, 1, nullptr, 0); | 1465 SequencedSocketData socket_data(&mock_read, 1, nullptr, 0); |
| 1465 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | 1466 socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| 1466 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | 1467 session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
| 1467 | 1468 |
| 1468 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | 1469 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| 1469 ssl_socket_data.SetNextProto(GetParam()); | 1470 ssl_socket_data.SetNextProto(GetParam()); |
| 1470 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | 1471 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); |
| 1471 | 1472 |
| 1472 HostPortPair host_port_pair("www.google.com", 443); | 1473 HostPortPair host_port_pair("www.google.com", 443); |
| 1473 scoped_ptr<HttpNetworkSession> session( | 1474 scoped_ptr<HttpNetworkSession> session( |
| 1474 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 1475 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 1475 | 1476 |
| 1476 // Now request a stream. | 1477 // Now request a stream. |
| 1477 HttpRequestInfo request_info; | 1478 HttpRequestInfo request_info; |
| 1478 request_info.method = "GET"; | 1479 request_info.method = "GET"; |
| 1479 request_info.url = GURL("https://www.google.com"); | 1480 request_info.url = GURL("https://www.google.com"); |
| 1480 request_info.load_flags = 0; | 1481 request_info.load_flags = 0; |
| 1481 | 1482 |
| 1482 SSLConfig ssl_config; | 1483 SSLConfig ssl_config; |
| 1483 StreamRequestWaiter waiter; | 1484 StreamRequestWaiter waiter; |
| 1484 scoped_ptr<HttpStreamRequest> request( | 1485 scoped_ptr<HttpStreamRequest> request( |
| 1485 session->http_stream_factory()->RequestBidirectionalStreamJob( | 1486 session->http_stream_factory()->RequestBidirectionalStreamImpl( |
| 1486 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, | 1487 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, |
| 1487 BoundNetLog())); | 1488 BoundNetLog())); |
| 1488 waiter.WaitForStream(); | 1489 waiter.WaitForStream(); |
| 1489 EXPECT_TRUE(waiter.stream_done()); | 1490 EXPECT_TRUE(waiter.stream_done()); |
| 1490 EXPECT_FALSE(waiter.websocket_stream()); | 1491 EXPECT_FALSE(waiter.websocket_stream()); |
| 1491 ASSERT_FALSE(waiter.stream()); | 1492 ASSERT_FALSE(waiter.stream()); |
| 1492 ASSERT_TRUE(waiter.bidirectional_stream_job()); | 1493 ASSERT_TRUE(waiter.bidirectional_stream_impl()); |
| 1493 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool( | 1494 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool( |
| 1494 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1495 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1495 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool( | 1496 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool( |
| 1496 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1497 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1497 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool( | 1498 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool( |
| 1498 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1499 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1499 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( | 1500 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( |
| 1500 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1501 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1501 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1502 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 1502 ASSERT_EQ(0u, | 1503 ASSERT_EQ(0u, |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 scoped_ptr<ProxyService> proxy_service_; | 1582 scoped_ptr<ProxyService> proxy_service_; |
| 1582 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 1583 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
| 1583 HttpNetworkSession::Params params_; | 1584 HttpNetworkSession::Params params_; |
| 1584 }; | 1585 }; |
| 1585 | 1586 |
| 1586 INSTANTIATE_TEST_CASE_P(Version, | 1587 INSTANTIATE_TEST_CASE_P(Version, |
| 1587 HttpStreamFactoryBidirectionalQuicTest, | 1588 HttpStreamFactoryBidirectionalQuicTest, |
| 1588 ::testing::ValuesIn(QuicSupportedVersions())); | 1589 ::testing::ValuesIn(QuicSupportedVersions())); |
| 1589 | 1590 |
| 1590 TEST_P(HttpStreamFactoryBidirectionalQuicTest, | 1591 TEST_P(HttpStreamFactoryBidirectionalQuicTest, |
| 1591 RequestBidirectionalStreamJobQuicAlternative) { | 1592 RequestBidirectionalStreamImplQuicAlternative) { |
| 1592 GURL url = GURL("https://www.example.org"); | 1593 GURL url = GURL("https://www.example.org"); |
| 1593 | 1594 |
| 1594 MockQuicData mock_quic_data; | 1595 MockQuicData mock_quic_data; |
| 1595 SpdyPriority priority = | 1596 SpdyPriority priority = |
| 1596 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); | 1597 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 1597 size_t spdy_headers_frame_length; | 1598 size_t spdy_headers_frame_length; |
| 1598 mock_quic_data.AddWrite(packet_maker().MakeRequestHeadersPacket( | 1599 mock_quic_data.AddWrite(packet_maker().MakeRequestHeadersPacket( |
| 1599 1, test::kClientDataStreamId1, /*should_include_version=*/true, | 1600 1, test::kClientDataStreamId1, /*should_include_version=*/true, |
| 1600 /*fin=*/true, priority, | 1601 /*fin=*/true, priority, |
| 1601 packet_maker().GetRequestHeaders("GET", "https", "/"), | 1602 packet_maker().GetRequestHeaders("GET", "https", "/"), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1623 | 1624 |
| 1624 // Now request a stream. | 1625 // Now request a stream. |
| 1625 SSLConfig ssl_config; | 1626 SSLConfig ssl_config; |
| 1626 HttpRequestInfo request_info; | 1627 HttpRequestInfo request_info; |
| 1627 request_info.method = "GET"; | 1628 request_info.method = "GET"; |
| 1628 request_info.url = GURL("https://www.example.org"); | 1629 request_info.url = GURL("https://www.example.org"); |
| 1629 request_info.load_flags = 0; | 1630 request_info.load_flags = 0; |
| 1630 | 1631 |
| 1631 StreamRequestWaiter waiter; | 1632 StreamRequestWaiter waiter; |
| 1632 scoped_ptr<HttpStreamRequest> request( | 1633 scoped_ptr<HttpStreamRequest> request( |
| 1633 session()->http_stream_factory()->RequestBidirectionalStreamJob( | 1634 session()->http_stream_factory()->RequestBidirectionalStreamImpl( |
| 1634 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, | 1635 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, |
| 1635 BoundNetLog())); | 1636 BoundNetLog())); |
| 1636 | 1637 |
| 1637 waiter.WaitForStream(); | 1638 waiter.WaitForStream(); |
| 1638 EXPECT_TRUE(waiter.stream_done()); | 1639 EXPECT_TRUE(waiter.stream_done()); |
| 1639 EXPECT_FALSE(waiter.websocket_stream()); | 1640 EXPECT_FALSE(waiter.websocket_stream()); |
| 1640 ASSERT_FALSE(waiter.stream()); | 1641 ASSERT_FALSE(waiter.stream()); |
| 1641 ASSERT_TRUE(waiter.bidirectional_stream_job()); | 1642 ASSERT_TRUE(waiter.bidirectional_stream_impl()); |
| 1642 BidirectionalStreamJob* job = waiter.bidirectional_stream_job(); | 1643 BidirectionalStreamImpl* stream_impl = waiter.bidirectional_stream_impl(); |
| 1643 | 1644 |
| 1644 BidirectionalStreamRequestInfo bidi_request_info; | 1645 BidirectionalStreamRequestInfo bidi_request_info; |
| 1645 bidi_request_info.method = "GET"; | 1646 bidi_request_info.method = "GET"; |
| 1646 bidi_request_info.url = GURL("https://www.example.org/"); | 1647 bidi_request_info.url = GURL("https://www.example.org/"); |
| 1647 bidi_request_info.end_stream_on_headers = true; | 1648 bidi_request_info.end_stream_on_headers = true; |
| 1648 bidi_request_info.priority = LOWEST; | 1649 bidi_request_info.priority = LOWEST; |
| 1649 | 1650 |
| 1650 TestBidirectionalDelegate delegate; | 1651 TestBidirectionalDelegate delegate; |
| 1651 job->Start(&bidi_request_info, BoundNetLog(), &delegate, nullptr); | 1652 stream_impl->Start(&bidi_request_info, BoundNetLog(), &delegate, nullptr); |
| 1652 delegate.WaitUntilDone(); | 1653 delegate.WaitUntilDone(); |
| 1653 | 1654 |
| 1654 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1); | 1655 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1); |
| 1655 EXPECT_EQ(OK, job->ReadData(buffer.get(), 1)); | 1656 EXPECT_EQ(OK, stream_impl->ReadData(buffer.get(), 1)); |
| 1656 EXPECT_EQ(kProtoQUIC1SPDY3, job->GetProtocol()); | 1657 EXPECT_EQ(kProtoQUIC1SPDY3, stream_impl->GetProtocol()); |
| 1657 EXPECT_EQ("200", delegate.response_headers().find(":status")->second); | 1658 EXPECT_EQ("200", delegate.response_headers().find(":status")->second); |
| 1658 EXPECT_EQ(1, GetSocketPoolGroupCount(session()->GetTransportSocketPool( | 1659 EXPECT_EQ(1, GetSocketPoolGroupCount(session()->GetTransportSocketPool( |
| 1659 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1660 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1660 EXPECT_EQ(1, GetSocketPoolGroupCount(session()->GetSSLSocketPool( | 1661 EXPECT_EQ(1, GetSocketPoolGroupCount(session()->GetSSLSocketPool( |
| 1661 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1662 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1662 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( | 1663 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( |
| 1663 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1664 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1664 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( | 1665 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( |
| 1665 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1666 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1666 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1667 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 1667 } | 1668 } |
| 1668 | 1669 |
| 1669 // Tests that when QUIC is not enabled for bidirectional streaming, HTTP/2 is | 1670 // Tests that when QUIC is not enabled for bidirectional streaming, HTTP/2 is |
| 1670 // used instead. | 1671 // used instead. |
| 1671 TEST_P(HttpStreamFactoryBidirectionalQuicTest, | 1672 TEST_P(HttpStreamFactoryBidirectionalQuicTest, |
| 1672 RequestBidirectionalStreamJobQuicNotEnabled) { | 1673 RequestBidirectionalStreamImplQuicNotEnabled) { |
| 1673 GURL url = GURL("https://www.example.org"); | 1674 GURL url = GURL("https://www.example.org"); |
| 1674 | 1675 |
| 1675 // Make the http job fail. | 1676 // Make the http job fail. |
| 1676 scoped_ptr<StaticSocketDataProvider> http_job_data; | 1677 scoped_ptr<StaticSocketDataProvider> http_job_data; |
| 1677 http_job_data.reset(new StaticSocketDataProvider()); | 1678 http_job_data.reset(new StaticSocketDataProvider()); |
| 1678 MockConnect failed_connect(ASYNC, ERR_CONNECTION_REFUSED); | 1679 MockConnect failed_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 1679 http_job_data->set_connect_data(failed_connect); | 1680 http_job_data->set_connect_data(failed_connect); |
| 1680 socket_factory().AddSocketDataProvider(http_job_data.get()); | 1681 socket_factory().AddSocketDataProvider(http_job_data.get()); |
| 1681 SSLSocketDataProvider ssl_data(ASYNC, OK); | 1682 SSLSocketDataProvider ssl_data(ASYNC, OK); |
| 1682 socket_factory().AddSSLSocketDataProvider(&ssl_data); | 1683 socket_factory().AddSSLSocketDataProvider(&ssl_data); |
| 1683 | 1684 |
| 1684 // Set up QUIC as alternative_service. | 1685 // Set up QUIC as alternative_service. |
| 1685 AddQuicAlternativeService(); | 1686 AddQuicAlternativeService(); |
| 1686 DisableQuicBidirectionalStream(); | 1687 DisableQuicBidirectionalStream(); |
| 1687 Initialize(); | 1688 Initialize(); |
| 1688 | 1689 |
| 1689 // Now request a stream. | 1690 // Now request a stream. |
| 1690 SSLConfig ssl_config; | 1691 SSLConfig ssl_config; |
| 1691 HttpRequestInfo request_info; | 1692 HttpRequestInfo request_info; |
| 1692 request_info.method = "GET"; | 1693 request_info.method = "GET"; |
| 1693 request_info.url = GURL("https://www.example.org"); | 1694 request_info.url = GURL("https://www.example.org"); |
| 1694 request_info.load_flags = 0; | 1695 request_info.load_flags = 0; |
| 1695 | 1696 |
| 1696 StreamRequestWaiter waiter; | 1697 StreamRequestWaiter waiter; |
| 1697 scoped_ptr<HttpStreamRequest> request( | 1698 scoped_ptr<HttpStreamRequest> request( |
| 1698 session()->http_stream_factory()->RequestBidirectionalStreamJob( | 1699 session()->http_stream_factory()->RequestBidirectionalStreamImpl( |
| 1699 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, | 1700 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, |
| 1700 BoundNetLog())); | 1701 BoundNetLog())); |
| 1701 | 1702 |
| 1702 waiter.WaitForStream(); | 1703 waiter.WaitForStream(); |
| 1703 EXPECT_TRUE(waiter.stream_done()); | 1704 EXPECT_TRUE(waiter.stream_done()); |
| 1704 EXPECT_FALSE(waiter.websocket_stream()); | 1705 EXPECT_FALSE(waiter.websocket_stream()); |
| 1705 ASSERT_FALSE(waiter.stream()); | 1706 ASSERT_FALSE(waiter.stream()); |
| 1706 ASSERT_FALSE(waiter.bidirectional_stream_job()); | 1707 ASSERT_FALSE(waiter.bidirectional_stream_impl()); |
| 1707 // Since the alternative service job is not started, we will get the error | 1708 // Since the alternative service job is not started, we will get the error |
| 1708 // from the http job. | 1709 // from the http job. |
| 1709 ASSERT_EQ(ERR_CONNECTION_REFUSED, waiter.error_status()); | 1710 ASSERT_EQ(ERR_CONNECTION_REFUSED, waiter.error_status()); |
| 1710 } | 1711 } |
| 1711 | 1712 |
| 1712 // Tests that if Http job fails, but Quic job succeeds, we return | 1713 // Tests that if Http job fails, but Quic job succeeds, we return |
| 1713 // BidirectionalStreamQuicImpl. | 1714 // BidirectionalStreamQuicImpl. |
| 1714 TEST_P(HttpStreamFactoryBidirectionalQuicTest, | 1715 TEST_P(HttpStreamFactoryBidirectionalQuicTest, |
| 1715 RequestBidirectionalStreamJobHttpJobFailsQuicJobSucceeds) { | 1716 RequestBidirectionalStreamImplHttpJobFailsQuicJobSucceeds) { |
| 1716 GURL url = GURL("https://www.example.org"); | 1717 GURL url = GURL("https://www.example.org"); |
| 1717 | 1718 |
| 1718 // Set up Quic data. | 1719 // Set up Quic data. |
| 1719 MockQuicData mock_quic_data; | 1720 MockQuicData mock_quic_data; |
| 1720 SpdyPriority priority = | 1721 SpdyPriority priority = |
| 1721 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); | 1722 ConvertRequestPriorityToQuicPriority(DEFAULT_PRIORITY); |
| 1722 size_t spdy_headers_frame_length; | 1723 size_t spdy_headers_frame_length; |
| 1723 mock_quic_data.AddWrite(packet_maker().MakeRequestHeadersPacket( | 1724 mock_quic_data.AddWrite(packet_maker().MakeRequestHeadersPacket( |
| 1724 1, test::kClientDataStreamId1, /*should_include_version=*/true, | 1725 1, test::kClientDataStreamId1, /*should_include_version=*/true, |
| 1725 /*fin=*/true, priority, | 1726 /*fin=*/true, priority, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1748 | 1749 |
| 1749 // Now request a stream. | 1750 // Now request a stream. |
| 1750 SSLConfig ssl_config; | 1751 SSLConfig ssl_config; |
| 1751 HttpRequestInfo request_info; | 1752 HttpRequestInfo request_info; |
| 1752 request_info.method = "GET"; | 1753 request_info.method = "GET"; |
| 1753 request_info.url = GURL("https://www.example.org"); | 1754 request_info.url = GURL("https://www.example.org"); |
| 1754 request_info.load_flags = 0; | 1755 request_info.load_flags = 0; |
| 1755 | 1756 |
| 1756 StreamRequestWaiter waiter; | 1757 StreamRequestWaiter waiter; |
| 1757 scoped_ptr<HttpStreamRequest> request( | 1758 scoped_ptr<HttpStreamRequest> request( |
| 1758 session()->http_stream_factory()->RequestBidirectionalStreamJob( | 1759 session()->http_stream_factory()->RequestBidirectionalStreamImpl( |
| 1759 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, | 1760 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, |
| 1760 BoundNetLog())); | 1761 BoundNetLog())); |
| 1761 | 1762 |
| 1762 waiter.WaitForStream(); | 1763 waiter.WaitForStream(); |
| 1763 EXPECT_TRUE(waiter.stream_done()); | 1764 EXPECT_TRUE(waiter.stream_done()); |
| 1764 EXPECT_FALSE(waiter.websocket_stream()); | 1765 EXPECT_FALSE(waiter.websocket_stream()); |
| 1765 ASSERT_FALSE(waiter.stream()); | 1766 ASSERT_FALSE(waiter.stream()); |
| 1766 ASSERT_TRUE(waiter.bidirectional_stream_job()); | 1767 ASSERT_TRUE(waiter.bidirectional_stream_impl()); |
| 1767 BidirectionalStreamJob* job = waiter.bidirectional_stream_job(); | 1768 BidirectionalStreamImpl* stream_impl = waiter.bidirectional_stream_impl(); |
| 1768 | 1769 |
| 1769 BidirectionalStreamRequestInfo bidi_request_info; | 1770 BidirectionalStreamRequestInfo bidi_request_info; |
| 1770 bidi_request_info.method = "GET"; | 1771 bidi_request_info.method = "GET"; |
| 1771 bidi_request_info.url = GURL("https://www.example.org/"); | 1772 bidi_request_info.url = GURL("https://www.example.org/"); |
| 1772 bidi_request_info.end_stream_on_headers = true; | 1773 bidi_request_info.end_stream_on_headers = true; |
| 1773 bidi_request_info.priority = LOWEST; | 1774 bidi_request_info.priority = LOWEST; |
| 1774 | 1775 |
| 1775 TestBidirectionalDelegate delegate; | 1776 TestBidirectionalDelegate delegate; |
| 1776 job->Start(&bidi_request_info, BoundNetLog(), &delegate, nullptr); | 1777 stream_impl->Start(&bidi_request_info, BoundNetLog(), &delegate, nullptr); |
| 1777 delegate.WaitUntilDone(); | 1778 delegate.WaitUntilDone(); |
| 1778 | 1779 |
| 1779 // Make sure the BidirectionalStream negotiated goes through QUIC. | 1780 // Make sure the BidirectionalStream negotiated goes through QUIC. |
| 1780 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1); | 1781 scoped_refptr<IOBuffer> buffer = new net::IOBuffer(1); |
| 1781 EXPECT_EQ(OK, job->ReadData(buffer.get(), 1)); | 1782 EXPECT_EQ(OK, stream_impl->ReadData(buffer.get(), 1)); |
| 1782 EXPECT_EQ(kProtoQUIC1SPDY3, job->GetProtocol()); | 1783 EXPECT_EQ(kProtoQUIC1SPDY3, stream_impl->GetProtocol()); |
| 1783 EXPECT_EQ("200", delegate.response_headers().find(":status")->second); | 1784 EXPECT_EQ("200", delegate.response_headers().find(":status")->second); |
| 1784 // There is no Http2 socket pool. | 1785 // There is no Http2 socket pool. |
| 1785 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( | 1786 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( |
| 1786 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1787 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1787 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( | 1788 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( |
| 1788 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1789 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1789 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( | 1790 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetTransportSocketPool( |
| 1790 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1791 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1791 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( | 1792 EXPECT_EQ(0, GetSocketPoolGroupCount(session()->GetSSLSocketPool( |
| 1792 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1793 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1793 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 1794 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 1794 } | 1795 } |
| 1795 | 1796 |
| 1796 TEST_P(HttpStreamFactoryTest, RequestBidirectionalStreamJobFailure) { | 1797 TEST_P(HttpStreamFactoryTest, RequestBidirectionalStreamImplFailure) { |
| 1797 SpdySessionDependencies session_deps(GetParam(), | 1798 SpdySessionDependencies session_deps(GetParam(), |
| 1798 ProxyService::CreateDirect()); | 1799 ProxyService::CreateDirect()); |
| 1799 | 1800 |
| 1800 MockRead mock_read(ASYNC, OK); | 1801 MockRead mock_read(ASYNC, OK); |
| 1801 SequencedSocketData socket_data(&mock_read, 1, nullptr, 0); | 1802 SequencedSocketData socket_data(&mock_read, 1, nullptr, 0); |
| 1802 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | 1803 socket_data.set_connect_data(MockConnect(ASYNC, OK)); |
| 1803 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | 1804 session_deps.socket_factory->AddSocketDataProvider(&socket_data); |
| 1804 | 1805 |
| 1805 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | 1806 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); |
| 1806 | 1807 |
| 1807 // If HTTP/1 is used, BidirectionalStreamJob should not be obtained. | 1808 // If HTTP/1 is used, BidirectionalStreamImpl should not be obtained. |
| 1808 ssl_socket_data.SetNextProto(kProtoHTTP11); | 1809 ssl_socket_data.SetNextProto(kProtoHTTP11); |
| 1809 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | 1810 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); |
| 1810 | 1811 |
| 1811 HostPortPair host_port_pair("www.google.com", 443); | 1812 HostPortPair host_port_pair("www.google.com", 443); |
| 1812 scoped_ptr<HttpNetworkSession> session( | 1813 scoped_ptr<HttpNetworkSession> session( |
| 1813 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 1814 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 1814 | 1815 |
| 1815 // Now request a stream. | 1816 // Now request a stream. |
| 1816 HttpRequestInfo request_info; | 1817 HttpRequestInfo request_info; |
| 1817 request_info.method = "GET"; | 1818 request_info.method = "GET"; |
| 1818 request_info.url = GURL("https://www.google.com"); | 1819 request_info.url = GURL("https://www.google.com"); |
| 1819 request_info.load_flags = 0; | 1820 request_info.load_flags = 0; |
| 1820 | 1821 |
| 1821 SSLConfig ssl_config; | 1822 SSLConfig ssl_config; |
| 1822 StreamRequestWaiter waiter; | 1823 StreamRequestWaiter waiter; |
| 1823 scoped_ptr<HttpStreamRequest> request( | 1824 scoped_ptr<HttpStreamRequest> request( |
| 1824 session->http_stream_factory()->RequestBidirectionalStreamJob( | 1825 session->http_stream_factory()->RequestBidirectionalStreamImpl( |
| 1825 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, | 1826 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, &waiter, |
| 1826 BoundNetLog())); | 1827 BoundNetLog())); |
| 1827 waiter.WaitForStream(); | 1828 waiter.WaitForStream(); |
| 1828 EXPECT_TRUE(waiter.stream_done()); | 1829 EXPECT_TRUE(waiter.stream_done()); |
| 1829 ASSERT_EQ(ERR_FAILED, waiter.error_status()); | 1830 ASSERT_EQ(ERR_FAILED, waiter.error_status()); |
| 1830 EXPECT_FALSE(waiter.websocket_stream()); | 1831 EXPECT_FALSE(waiter.websocket_stream()); |
| 1831 ASSERT_FALSE(waiter.stream()); | 1832 ASSERT_FALSE(waiter.stream()); |
| 1832 ASSERT_FALSE(waiter.bidirectional_stream_job()); | 1833 ASSERT_FALSE(waiter.bidirectional_stream_impl()); |
| 1833 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool( | 1834 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetTransportSocketPool( |
| 1834 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1835 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1835 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool( | 1836 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSSLSocketPool( |
| 1836 HttpNetworkSession::NORMAL_SOCKET_POOL))); | 1837 HttpNetworkSession::NORMAL_SOCKET_POOL))); |
| 1837 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool( | 1838 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetTransportSocketPool( |
| 1838 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1839 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1839 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( | 1840 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( |
| 1840 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); | 1841 HttpNetworkSession::WEBSOCKET_SOCKET_POOL))); |
| 1841 ASSERT_EQ(0u, | 1842 ASSERT_EQ(0u, |
| 1842 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()) | 1843 static_cast<HttpStreamFactoryImpl*>(session->http_stream_factory()) |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | 2042 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); |
| 2042 | 2043 |
| 2043 // Make sure there is no orphaned job. it is already canceled. | 2044 // Make sure there is no orphaned job. it is already canceled. |
| 2044 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( | 2045 ASSERT_EQ(0u, static_cast<HttpStreamFactoryImpl*>( |
| 2045 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); | 2046 session->http_stream_factory_for_websocket())->num_orphaned_jobs()); |
| 2046 } | 2047 } |
| 2047 | 2048 |
| 2048 } // namespace | 2049 } // namespace |
| 2049 | 2050 |
| 2050 } // namespace net | 2051 } // namespace net |
| OLD | NEW |