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 <string> | 7 #include <string> |
8 #include <vector> | |
8 | 9 |
9 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
10 #include "net/base/net_log.h" | 11 #include "net/base/net_log.h" |
11 #include "net/base/test_completion_callback.h" | 12 #include "net/base/test_completion_callback.h" |
12 #include "net/cert/mock_cert_verifier.h" | 13 #include "net/cert/mock_cert_verifier.h" |
13 #include "net/dns/mock_host_resolver.h" | 14 #include "net/dns/mock_host_resolver.h" |
14 #include "net/http/http_auth_handler_factory.h" | 15 #include "net/http/http_auth_handler_factory.h" |
15 #include "net/http/http_network_session.h" | 16 #include "net/http/http_network_session.h" |
16 #include "net/http/http_network_session_peer.h" | 17 #include "net/http/http_network_session_peer.h" |
17 #include "net/http/http_network_transaction.h" | 18 #include "net/http/http_network_transaction.h" |
18 #include "net/http/http_request_info.h" | 19 #include "net/http/http_request_info.h" |
20 #include "net/http/http_server_properties.h" | |
19 #include "net/http/http_server_properties_impl.h" | 21 #include "net/http/http_server_properties_impl.h" |
20 #include "net/http/http_stream.h" | 22 #include "net/http/http_stream.h" |
21 #include "net/proxy/proxy_info.h" | 23 #include "net/proxy/proxy_info.h" |
22 #include "net/proxy/proxy_service.h" | 24 #include "net/proxy/proxy_service.h" |
25 #include "net/socket/client_socket_handle.h" | |
23 #include "net/socket/mock_client_socket_pool_manager.h" | 26 #include "net/socket/mock_client_socket_pool_manager.h" |
27 #include "net/socket/next_proto.h" | |
24 #include "net/socket/socket_test_util.h" | 28 #include "net/socket/socket_test_util.h" |
25 #include "net/spdy/spdy_session.h" | 29 #include "net/spdy/spdy_session.h" |
26 #include "net/spdy/spdy_session_pool.h" | 30 #include "net/spdy/spdy_session_pool.h" |
31 #include "net/spdy/spdy_test_util_common.h" | |
32 #include "net/ssl/ssl_config_service.h" | |
27 #include "net/ssl/ssl_config_service_defaults.h" | 33 #include "net/ssl/ssl_config_service_defaults.h" |
34 // This file can be included from net/http even though | |
35 // it is in net/websockets because it doesn't | |
36 // introduce any link dependency to net/websockets. | |
37 #include "net/websockets/websocket_stream_base.h" | |
28 #include "testing/gtest/include/gtest/gtest.h" | 38 #include "testing/gtest/include/gtest/gtest.h" |
29 | 39 |
30 namespace net { | 40 namespace net { |
31 | 41 |
42 class WebSocketStream : public WebSocketStreamBase { | |
mmenke
2013/06/05 00:01:20
This doesn't work. Once you have a WebSocketStrea
yhirano
2013/06/06 14:06:43
Done.
| |
43 public: | |
44 enum StreamType { | |
45 kStreamTypeBasic, | |
46 kStreamTypeSpdy, | |
47 }; | |
48 explicit WebSocketStream(StreamType type) : type_(type) {} | |
mmenke
2013/06/05 00:01:20
nit: Mind adding a couple blank lines here, for l
mmenke
2013/06/05 00:01:20
Speaking of which...you should have a virtual dest
yhirano
2013/06/06 14:06:43
Done.
yhirano
2013/06/06 14:06:43
Done (constructor, you mean?).
mmenke
2013/06/10 20:26:03
Actually, I meant the destructor that I suggested
| |
49 virtual WebSocketStream* AsWebSocketStream() OVERRIDE {return this;} | |
mmenke
2013/06/05 00:01:20
nit: "{ return this; }"
yhirano
2013/06/06 14:06:43
Done.
| |
50 StreamType type() const { | |
51 return type_; | |
52 } | |
53 private: | |
mmenke
2013/06/05 00:01:20
nit: Line break before private.
yhirano
2013/06/06 14:06:43
Done.
| |
54 const StreamType type_; | |
55 }; | |
56 | |
32 namespace { | 57 namespace { |
33 | 58 |
34 class MockHttpStreamFactoryImpl : public HttpStreamFactoryImpl { | 59 class MockHttpStreamFactoryImplForPreconnect : public HttpStreamFactoryImpl { |
mmenke
2013/06/05 00:01:20
Mind adding a comment here, while you're renaming
yhirano
2013/06/06 14:06:43
Done.
| |
35 public: | 60 public: |
36 MockHttpStreamFactoryImpl(HttpNetworkSession* session) | 61 MockHttpStreamFactoryImplForPreconnect(HttpNetworkSession* session, |
37 : HttpStreamFactoryImpl(session), | 62 bool for_websockets) |
63 : HttpStreamFactoryImpl(session, for_websockets), | |
38 preconnect_done_(false), | 64 preconnect_done_(false), |
39 waiting_for_preconnect_(false) {} | 65 waiting_for_preconnect_(false) {} |
40 | 66 |
41 | 67 |
42 void WaitForPreconnects() { | 68 void WaitForPreconnects() { |
43 while (!preconnect_done_) { | 69 while (!preconnect_done_) { |
44 waiting_for_preconnect_ = true; | 70 waiting_for_preconnect_ = true; |
45 base::MessageLoop::current()->Run(); | 71 base::MessageLoop::current()->Run(); |
46 waiting_for_preconnect_ = false; | 72 waiting_for_preconnect_ = false; |
47 } | 73 } |
(...skipping 21 matching lines...) Expand all Loading... | |
69 | 95 |
70 virtual void OnStreamReady( | 96 virtual void OnStreamReady( |
71 const SSLConfig& used_ssl_config, | 97 const SSLConfig& used_ssl_config, |
72 const ProxyInfo& used_proxy_info, | 98 const ProxyInfo& used_proxy_info, |
73 HttpStreamBase* stream) OVERRIDE { | 99 HttpStreamBase* stream) OVERRIDE { |
74 stream_done_ = true; | 100 stream_done_ = true; |
75 if (waiting_for_stream_) | 101 if (waiting_for_stream_) |
76 base::MessageLoop::current()->Quit(); | 102 base::MessageLoop::current()->Quit(); |
77 stream_.reset(stream); | 103 stream_.reset(stream); |
78 used_ssl_config_ = used_ssl_config; | 104 used_ssl_config_ = used_ssl_config; |
105 used_proxy_info_ = used_proxy_info; | |
106 } | |
107 | |
108 virtual void OnWebSocketStreamReady( | |
109 const SSLConfig& used_ssl_config, | |
110 const ProxyInfo& used_proxy_info, | |
111 WebSocketStreamBase* stream) OVERRIDE { | |
112 stream_done_ = true; | |
113 if (waiting_for_stream_) | |
114 base::MessageLoop::current()->Quit(); | |
115 websocket_stream_.reset(stream); | |
116 used_ssl_config_ = used_ssl_config; | |
117 used_proxy_info_ = used_proxy_info; | |
79 } | 118 } |
80 | 119 |
81 virtual void OnStreamFailed( | 120 virtual void OnStreamFailed( |
82 int status, | 121 int status, |
83 const SSLConfig& used_ssl_config) OVERRIDE {} | 122 const SSLConfig& used_ssl_config) OVERRIDE {} |
84 | 123 |
85 virtual void OnCertificateError( | 124 virtual void OnCertificateError( |
86 int status, | 125 int status, |
87 const SSLConfig& used_ssl_config, | 126 const SSLConfig& used_ssl_config, |
88 const SSLInfo& ssl_info) OVERRIDE {} | 127 const SSLInfo& ssl_info) OVERRIDE {} |
(...skipping 16 matching lines...) Expand all Loading... | |
105 waiting_for_stream_ = true; | 144 waiting_for_stream_ = true; |
106 base::MessageLoop::current()->Run(); | 145 base::MessageLoop::current()->Run(); |
107 waiting_for_stream_ = false; | 146 waiting_for_stream_ = false; |
108 } | 147 } |
109 } | 148 } |
110 | 149 |
111 const SSLConfig& used_ssl_config() const { | 150 const SSLConfig& used_ssl_config() const { |
112 return used_ssl_config_; | 151 return used_ssl_config_; |
113 } | 152 } |
114 | 153 |
154 const ProxyInfo& used_proxy_info() const { | |
155 return used_proxy_info_; | |
156 } | |
157 | |
115 HttpStreamBase* stream() { | 158 HttpStreamBase* stream() { |
116 return stream_.get(); | 159 return stream_.get(); |
117 } | 160 } |
118 | 161 |
162 WebSocketStreamBase* websocket_stream() { | |
163 return websocket_stream_.get(); | |
164 } | |
165 | |
166 bool stream_done() const { return stream_done_; } | |
119 | 167 |
120 private: | 168 private: |
121 bool waiting_for_stream_; | 169 bool waiting_for_stream_; |
122 bool stream_done_; | 170 bool stream_done_; |
123 scoped_ptr<HttpStreamBase> stream_; | 171 scoped_ptr<HttpStreamBase> stream_; |
172 scoped_ptr<WebSocketStreamBase> websocket_stream_; | |
124 SSLConfig used_ssl_config_; | 173 SSLConfig used_ssl_config_; |
174 ProxyInfo used_proxy_info_; | |
125 | 175 |
126 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); | 176 DISALLOW_COPY_AND_ASSIGN(StreamRequestWaiter); |
127 }; | 177 }; |
128 | 178 |
179 class WebSocketSpdyStream : public WebSocketStream { | |
180 public: | |
181 explicit WebSocketSpdyStream(SpdySession* spdy_session): | |
mmenke
2013/06/05 00:01:20
nit: Colon should go on next line (Also, if it go
yhirano
2013/06/06 14:06:43
Done.
| |
182 WebSocketStream(kStreamTypeSpdy), spdy_session_(spdy_session) {} | |
183 SpdySession* spdy_session() {return spdy_session_.get();} | |
mmenke
2013/06/05 00:01:20
nit: { return spdy_session_.get(); }
yhirano
2013/06/06 14:06:43
Done.
| |
184 | |
185 private: | |
186 scoped_refptr<SpdySession> spdy_session_; | |
187 }; | |
188 | |
189 class WebSocketBasicStream : public WebSocketStream { | |
190 public: | |
191 explicit WebSocketBasicStream(ClientSocketHandle* connection): | |
192 WebSocketStream(kStreamTypeBasic), connection_(connection) {} | |
193 ClientSocketHandle* connection() {return connection_.get();} | |
mmenke
2013/06/05 00:01:20
nit: { return connection_.get(); }
yhirano
2013/06/06 14:06:43
Done.
| |
194 | |
195 private: | |
196 scoped_ptr<ClientSocketHandle> connection_; | |
197 }; | |
198 | |
199 class WebSocketStreamFactory : public WebSocketStreamBase::Factory { | |
200 public: | |
201 virtual WebSocketStreamBase* CreateBasicStream(ClientSocketHandle* connection, | |
202 bool using_proxy) OVERRIDE { | |
203 return new WebSocketBasicStream(connection); | |
204 } | |
205 virtual WebSocketStreamBase* CreateSpdyStream( | |
206 SpdySession* spdy_session, | |
207 bool use_relative_url) OVERRIDE { | |
208 return new WebSocketSpdyStream(spdy_session); | |
209 } | |
210 }; | |
211 | |
129 struct SessionDependencies { | 212 struct SessionDependencies { |
130 // Custom proxy service dependency. | 213 // Custom proxy service dependency. |
131 explicit SessionDependencies(ProxyService* proxy_service) | 214 explicit SessionDependencies(ProxyService* proxy_service) |
132 : host_resolver(new MockHostResolver), | 215 : host_resolver(new MockHostResolver), |
133 cert_verifier(new MockCertVerifier), | 216 cert_verifier(new MockCertVerifier), |
134 proxy_service(proxy_service), | 217 proxy_service(proxy_service), |
135 ssl_config_service(new SSLConfigServiceDefaults), | 218 ssl_config_service(new SSLConfigServiceDefaults), |
136 http_auth_handler_factory( | 219 http_auth_handler_factory( |
137 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 220 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
138 net_log(NULL) {} | 221 net_log(NULL) {} |
(...skipping 12 matching lines...) Expand all Loading... | |
151 HttpNetworkSession::Params params; | 234 HttpNetworkSession::Params params; |
152 params.host_resolver = session_deps->host_resolver.get(); | 235 params.host_resolver = session_deps->host_resolver.get(); |
153 params.cert_verifier = session_deps->cert_verifier.get(); | 236 params.cert_verifier = session_deps->cert_verifier.get(); |
154 params.proxy_service = session_deps->proxy_service.get(); | 237 params.proxy_service = session_deps->proxy_service.get(); |
155 params.ssl_config_service = session_deps->ssl_config_service.get(); | 238 params.ssl_config_service = session_deps->ssl_config_service.get(); |
156 params.client_socket_factory = &session_deps->socket_factory; | 239 params.client_socket_factory = &session_deps->socket_factory; |
157 params.http_auth_handler_factory = | 240 params.http_auth_handler_factory = |
158 session_deps->http_auth_handler_factory.get(); | 241 session_deps->http_auth_handler_factory.get(); |
159 params.net_log = session_deps->net_log; | 242 params.net_log = session_deps->net_log; |
160 params.http_server_properties = &session_deps->http_server_properties; | 243 params.http_server_properties = &session_deps->http_server_properties; |
244 | |
161 return new HttpNetworkSession(params); | 245 return new HttpNetworkSession(params); |
162 } | 246 } |
163 | 247 |
164 struct TestCase { | 248 struct TestCase { |
165 int num_streams; | 249 int num_streams; |
166 bool ssl; | 250 bool ssl; |
167 }; | 251 }; |
168 | 252 |
169 TestCase kTests[] = { | 253 TestCase kTests[] = { |
170 { 1, false }, | 254 { 1, false }, |
171 { 2, false }, | 255 { 2, false }, |
172 { 1, true}, | 256 { 1, true}, |
173 { 2, true}, | 257 { 2, true}, |
174 }; | 258 }; |
175 | 259 |
176 void PreconnectHelperForURL(int num_streams, | 260 void PreconnectHelperForURL(int num_streams, |
177 const GURL& url, | 261 const GURL& url, |
178 HttpNetworkSession* session) { | 262 HttpNetworkSession* session) { |
179 HttpNetworkSessionPeer peer(session); | 263 HttpNetworkSessionPeer peer(session); |
180 MockHttpStreamFactoryImpl* mock_factory = | 264 MockHttpStreamFactoryImplForPreconnect* mock_factory = |
181 new MockHttpStreamFactoryImpl(session); | 265 new MockHttpStreamFactoryImplForPreconnect(session, false); |
182 peer.SetHttpStreamFactory(mock_factory); | 266 peer.SetHttpStreamFactory(mock_factory); |
183 SSLConfig ssl_config; | 267 SSLConfig ssl_config; |
184 session->ssl_config_service()->GetSSLConfig(&ssl_config); | 268 session->ssl_config_service()->GetSSLConfig(&ssl_config); |
185 | 269 |
186 HttpRequestInfo request; | 270 HttpRequestInfo request; |
187 request.method = "GET"; | 271 request.method = "GET"; |
188 request.url = url; | 272 request.url = url; |
189 request.load_flags = 0; | 273 request.load_flags = 0; |
190 | 274 |
191 session->http_stream_factory()->PreconnectStreams( | 275 session->http_stream_factory()->PreconnectStreams( |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
453 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); | 537 socket_data1.set_connect_data(MockConnect(ASYNC, ERR_ADDRESS_UNREACHABLE)); |
454 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); | 538 session_deps.socket_factory.AddSocketDataProvider(&socket_data1); |
455 | 539 |
456 // Second connection attempt succeeds | 540 // Second connection attempt succeeds |
457 StaticSocketDataProvider socket_data2; | 541 StaticSocketDataProvider socket_data2; |
458 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); | 542 socket_data2.set_connect_data(MockConnect(ASYNC, OK)); |
459 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); | 543 session_deps.socket_factory.AddSocketDataProvider(&socket_data2); |
460 | 544 |
461 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | 545 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); |
462 | 546 |
463 // Now request a stream. It should succeed using the second proxy in the | 547 // Now request a stream. |
464 // list. | |
mmenke
2013/06/05 00:01:20
Why are you removing this comment? It looks corre
| |
465 HttpRequestInfo request_info; | 548 HttpRequestInfo request_info; |
466 request_info.method = "GET"; | 549 request_info.method = "GET"; |
467 request_info.url = GURL("http://www.google.com"); | 550 request_info.url = GURL("http://www.google.com"); |
468 | 551 |
469 SSLConfig ssl_config; | 552 SSLConfig ssl_config; |
470 StreamRequestWaiter waiter; | 553 StreamRequestWaiter waiter; |
471 scoped_ptr<HttpStreamRequest> request( | 554 scoped_ptr<HttpStreamRequest> request( |
472 session->http_stream_factory()->RequestStream( | 555 session->http_stream_factory()->RequestStream( |
473 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 556 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
474 &waiter, BoundNetLog())); | 557 &waiter, BoundNetLog())); |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
603 scoped_ptr<HttpStreamRequest> request( | 686 scoped_ptr<HttpStreamRequest> request( |
604 session->http_stream_factory()->RequestStream( | 687 session->http_stream_factory()->RequestStream( |
605 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, | 688 request_info, DEFAULT_PRIORITY, ssl_config, ssl_config, |
606 &waiter, BoundNetLog())); | 689 &waiter, BoundNetLog())); |
607 | 690 |
608 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); | 691 EXPECT_EQ(LOAD_STATE_RESOLVING_HOST, request->GetLoadState()); |
609 | 692 |
610 waiter.WaitForStream(); | 693 waiter.WaitForStream(); |
611 } | 694 } |
612 | 695 |
696 TEST(HttpStreamFactoryTest, RequestHttpStream) { | |
697 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
698 | |
699 StaticSocketDataProvider socket_data; | |
700 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
701 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
702 | |
703 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
704 | |
705 // Now request a stream. It should succeed using the second proxy in the | |
706 // list. | |
707 HttpRequestInfo request_info; | |
708 request_info.method = "GET"; | |
709 request_info.url = GURL("http://www.google.com"); | |
710 request_info.load_flags = 0; | |
711 | |
712 SSLConfig ssl_config; | |
713 StreamRequestWaiter waiter; | |
714 scoped_ptr<HttpStreamRequest> request( | |
715 session->http_stream_factory()->RequestStream( | |
716 request_info, | |
717 DEFAULT_PRIORITY, | |
718 ssl_config, | |
719 ssl_config, | |
720 &waiter, | |
721 BoundNetLog())); | |
722 waiter.WaitForStream(); | |
723 EXPECT_TRUE(waiter.stream_done()); | |
724 EXPECT_TRUE(NULL != waiter.stream()); | |
725 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
726 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
727 | |
728 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
729 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
730 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSSLSocketPool( | |
731 HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
732 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
733 } | |
734 | |
735 TEST(HttpStreamFactoryTest, RequestHttpStreamOverSSL) { | |
736 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
737 | |
738 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
739 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
740 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
741 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
742 | |
743 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
744 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
745 | |
746 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
747 | |
748 // Now request a stream. | |
749 HttpRequestInfo request_info; | |
750 request_info.method = "GET"; | |
751 request_info.url = GURL("https://www.google.com"); | |
752 request_info.load_flags = 0; | |
753 | |
754 SSLConfig ssl_config; | |
755 StreamRequestWaiter waiter; | |
756 scoped_ptr<HttpStreamRequest> request( | |
757 session->http_stream_factory()->RequestStream( | |
758 request_info, | |
759 DEFAULT_PRIORITY, | |
760 ssl_config, | |
761 ssl_config, | |
762 &waiter, | |
763 BoundNetLog())); | |
764 waiter.WaitForStream(); | |
765 EXPECT_TRUE(waiter.stream_done()); | |
766 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
767 EXPECT_TRUE(NULL != waiter.stream()); | |
768 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
769 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
770 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
771 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
772 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
773 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
774 } | |
775 | |
776 TEST(HttpStreamFactoryTest, RequestHttpStreamOverProxy) { | |
777 SessionDependencies session_deps(ProxyService::CreateFixed("myproxy:8888")); | |
778 | |
779 StaticSocketDataProvider socket_data; | |
780 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
781 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
782 | |
783 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
784 | |
785 // Now request a stream. It should succeed using the second proxy in the | |
786 // list. | |
787 HttpRequestInfo request_info; | |
788 request_info.method = "GET"; | |
789 request_info.url = GURL("http://www.google.com"); | |
790 request_info.load_flags = 0; | |
791 | |
792 SSLConfig ssl_config; | |
793 StreamRequestWaiter waiter; | |
794 scoped_ptr<HttpStreamRequest> request( | |
795 session->http_stream_factory()->RequestStream( | |
796 request_info, | |
797 DEFAULT_PRIORITY, | |
798 ssl_config, | |
799 ssl_config, | |
800 &waiter, | |
801 BoundNetLog())); | |
802 waiter.WaitForStream(); | |
803 EXPECT_TRUE(waiter.stream_done()); | |
804 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
805 EXPECT_TRUE(NULL != waiter.stream()); | |
806 EXPECT_FALSE(waiter.stream()->IsSpdyHttpStream()); | |
807 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
808 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
809 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
810 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
811 EXPECT_EQ(1, GetSocketPoolGroupCount(session->GetSocketPoolForHTTPProxy( | |
812 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
813 HostPortPair("myproxy", 8888)))); | |
814 EXPECT_EQ(0, GetSocketPoolGroupCount(session->GetSocketPoolForSSLWithProxy( | |
815 HttpNetworkSession::NORMAL_SOCKET_POOL, | |
816 HostPortPair("myproxy", 8888)))); | |
817 EXPECT_FALSE(waiter.used_proxy_info().is_direct()); | |
818 } | |
819 | |
820 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStream) { | |
821 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
822 | |
823 StaticSocketDataProvider socket_data; | |
824 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
825 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
826 | |
827 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
828 | |
829 // Now request a stream. | |
830 HttpRequestInfo request_info; | |
831 request_info.method = "GET"; | |
832 request_info.url = GURL("ws://www.google.com"); | |
833 request_info.load_flags = 0; | |
834 | |
835 SSLConfig ssl_config; | |
836 StreamRequestWaiter waiter; | |
837 WebSocketStreamFactory factory; | |
838 scoped_ptr<HttpStreamRequest> request( | |
839 session->websocket_stream_factory()->RequestWebSocketStream( | |
840 request_info, | |
841 DEFAULT_PRIORITY, | |
842 ssl_config, | |
843 ssl_config, | |
844 &waiter, | |
845 &factory, | |
846 BoundNetLog())); | |
847 waiter.WaitForStream(); | |
848 EXPECT_TRUE(waiter.stream_done()); | |
849 EXPECT_TRUE(NULL == waiter.stream()); | |
850 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
851 EXPECT_EQ(WebSocketStream::kStreamTypeBasic, | |
852 waiter.websocket_stream()->AsWebSocketStream()->type()); | |
853 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
854 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
855 EXPECT_EQ(0, GetSocketPoolGroupCount( | |
856 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
857 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
858 } | |
859 | |
860 TEST(HttpStreamFactoryTest, RequestWebSocketBasicStreamOverSSL) { | |
861 SessionDependencies session_deps(ProxyService::CreateDirect()); | |
862 | |
863 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
864 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
865 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
866 session_deps.socket_factory.AddSocketDataProvider(&socket_data); | |
867 | |
868 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
869 session_deps.socket_factory.AddSSLSocketDataProvider(&ssl_socket_data); | |
870 | |
871 scoped_refptr<HttpNetworkSession> session(CreateSession(&session_deps)); | |
872 | |
873 // Now request a stream. | |
874 HttpRequestInfo request_info; | |
875 request_info.method = "GET"; | |
876 request_info.url = GURL("wss://www.google.com"); | |
877 request_info.load_flags = 0; | |
878 | |
879 SSLConfig ssl_config; | |
880 StreamRequestWaiter waiter; | |
881 WebSocketStreamFactory factory; | |
882 scoped_ptr<HttpStreamRequest> request( | |
883 session->websocket_stream_factory()->RequestWebSocketStream( | |
884 request_info, | |
885 DEFAULT_PRIORITY, | |
886 ssl_config, | |
887 ssl_config, | |
888 &waiter, | |
889 &factory, | |
890 BoundNetLog())); | |
891 waiter.WaitForStream(); | |
892 EXPECT_TRUE(waiter.stream_done()); | |
893 EXPECT_TRUE(NULL == waiter.stream()); | |
894 EXPECT_TRUE(NULL != waiter.websocket_stream()); | |
895 EXPECT_EQ(WebSocketStream::kStreamTypeBasic, | |
896 waiter.websocket_stream()->AsWebSocketStream()->type()); | |
897 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
898 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
899 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
900 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
901 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
902 } | |
903 | |
904 TEST(HttpStreamFactoryTest, RequestSpdyHttpStream) { | |
905 SpdySessionDependencies session_deps(kProtoSPDY3, | |
906 ProxyService::CreateDirect()); | |
907 | |
908 MockRead mock_read(ASYNC, OK); | |
909 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
910 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
911 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
912 | |
913 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
914 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
915 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
916 | |
917 HostPortPair host_port_pair("www.google.com", 443); | |
918 scoped_refptr<HttpNetworkSession> | |
919 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
920 | |
921 // Now request a stream. | |
922 HttpRequestInfo request_info; | |
923 request_info.method = "GET"; | |
924 request_info.url = GURL("https://www.google.com"); | |
925 request_info.load_flags = 0; | |
926 | |
927 SSLConfig ssl_config; | |
928 StreamRequestWaiter waiter; | |
929 scoped_ptr<HttpStreamRequest> request( | |
930 session->http_stream_factory()->RequestStream( | |
931 request_info, | |
932 DEFAULT_PRIORITY, | |
933 ssl_config, | |
934 ssl_config, | |
935 &waiter, | |
936 BoundNetLog())); | |
937 waiter.WaitForStream(); | |
938 EXPECT_TRUE(waiter.stream_done()); | |
939 EXPECT_TRUE(NULL == waiter.websocket_stream()); | |
940 EXPECT_TRUE(NULL != waiter.stream()); | |
941 EXPECT_TRUE(waiter.stream()->IsSpdyHttpStream()); | |
942 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
943 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
944 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
945 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
946 EXPECT_TRUE(waiter.used_proxy_info().is_direct()); | |
947 } | |
948 | |
949 TEST(HttpStreamFactoryTest, RequestWebSocketSpdyStream) { | |
950 SpdySessionDependencies session_deps(kProtoSPDY3, | |
951 ProxyService::CreateDirect()); | |
952 | |
953 MockRead mock_read(ASYNC, ERR_IO_PENDING); | |
954 StaticSocketDataProvider socket_data(&mock_read, 1, NULL, 0); | |
955 socket_data.set_connect_data(MockConnect(ASYNC, OK)); | |
956 session_deps.socket_factory->AddSocketDataProvider(&socket_data); | |
957 | |
958 SSLSocketDataProvider ssl_socket_data(ASYNC, OK); | |
959 ssl_socket_data.SetNextProto(kProtoSPDY3); | |
960 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl_socket_data); | |
961 | |
962 HostPortPair host_port_pair("www.google.com", 80); | |
963 scoped_refptr<HttpNetworkSession> | |
964 session(SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
965 | |
966 // Now request a stream. | |
967 HttpRequestInfo request_info; | |
968 request_info.method = "GET"; | |
969 request_info.url = GURL("wss://www.google.com"); | |
970 request_info.load_flags = 0; | |
971 | |
972 SSLConfig ssl_config; | |
973 StreamRequestWaiter waiter1; | |
974 WebSocketStreamFactory factory; | |
975 scoped_ptr<HttpStreamRequest> request1( | |
976 session->websocket_stream_factory()->RequestWebSocketStream( | |
977 request_info, | |
978 DEFAULT_PRIORITY, | |
979 ssl_config, | |
980 ssl_config, | |
981 &waiter1, | |
982 &factory, | |
983 BoundNetLog())); | |
984 waiter1.WaitForStream(); | |
985 EXPECT_TRUE(waiter1.stream_done()); | |
986 EXPECT_TRUE(NULL != waiter1.websocket_stream()); | |
987 EXPECT_EQ(WebSocketStream::kStreamTypeSpdy, | |
988 waiter1.websocket_stream()->AsWebSocketStream()->type()); | |
989 EXPECT_TRUE(NULL == waiter1.stream()); | |
990 | |
991 StreamRequestWaiter waiter2; | |
992 scoped_ptr<HttpStreamRequest> request2( | |
993 session->websocket_stream_factory()->RequestWebSocketStream( | |
994 request_info, | |
995 DEFAULT_PRIORITY, | |
996 ssl_config, | |
997 ssl_config, | |
998 &waiter2, | |
999 &factory, | |
1000 BoundNetLog())); | |
1001 waiter2.WaitForStream(); | |
1002 EXPECT_TRUE(waiter2.stream_done()); | |
1003 EXPECT_TRUE(NULL != waiter2.websocket_stream()); | |
1004 EXPECT_EQ(WebSocketStream::kStreamTypeSpdy, | |
1005 waiter2.websocket_stream()->AsWebSocketStream()->type()); | |
1006 EXPECT_TRUE(NULL == waiter2.stream()); | |
1007 EXPECT_NE(waiter2.websocket_stream(), waiter1.websocket_stream()); | |
1008 EXPECT_EQ(static_cast<WebSocketSpdyStream*>(waiter2.websocket_stream())-> | |
1009 spdy_session(), | |
1010 static_cast<WebSocketSpdyStream*>(waiter1.websocket_stream())-> | |
1011 spdy_session()); | |
1012 | |
1013 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
1014 session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
1015 EXPECT_EQ(1, GetSocketPoolGroupCount( | |
1016 session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL))); | |
1017 EXPECT_TRUE(waiter1.used_proxy_info().is_direct()); | |
1018 } | |
1019 | |
613 } // namespace | 1020 } // namespace |
614 | 1021 |
615 } // namespace net | 1022 } // namespace net |
OLD | NEW |