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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include "net/base/host_cache.h" | 7 #include "net/base/host_cache.h" |
8 #include "net/base/ip_endpoint.h" | 8 #include "net/base/ip_endpoint.h" |
9 #include "net/base/net_log_unittest.h" | 9 #include "net/base/net_log_unittest.h" |
10 #include "net/spdy/spdy_io_buffer.h" | 10 #include "net/spdy/spdy_io_buffer.h" |
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 MEDIUM, /* priority, not important */ | 1191 MEDIUM, /* priority, not important */ |
1192 &spdy_stream2, | 1192 &spdy_stream2, |
1193 BoundNetLog(), | 1193 BoundNetLog(), |
1194 callback1.callback())); | 1194 callback1.callback())); |
1195 | 1195 |
1196 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); | 1196 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); |
1197 spdy_stream2->Cancel(); | 1197 spdy_stream2->Cancel(); |
1198 spdy_stream2 = NULL; | 1198 spdy_stream2 = NULL; |
1199 } | 1199 } |
1200 | 1200 |
| 1201 TEST_F(SpdySessionSpdy3Test, OutOfOrderSynStreams) { |
| 1202 // Construct the request. |
| 1203 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1204 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); |
| 1205 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 5, LOWEST)); |
| 1206 MockWrite writes[] = { |
| 1207 CreateMockWrite(*req1, 1), |
| 1208 CreateMockWrite(*req2, 2), |
| 1209 }; |
| 1210 |
| 1211 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1212 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); |
| 1213 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1214 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); |
| 1215 MockRead reads[] = { |
| 1216 CreateMockRead(*resp1, 3), |
| 1217 CreateMockRead(*body1, 4), |
| 1218 CreateMockRead(*resp2, 5), |
| 1219 CreateMockRead(*body2, 6), |
| 1220 MockRead(ASYNC, 0, 7) // EOF |
| 1221 }; |
| 1222 |
| 1223 SpdySessionDependencies session_deps; |
| 1224 session_deps.host_resolver->set_synchronous_mode(true); |
| 1225 |
| 1226 StaticSocketDataProvider data(reads, arraysize(reads), |
| 1227 writes, arraysize(writes)); |
| 1228 data.set_connect_data(connect_data); |
| 1229 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 1230 |
| 1231 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 1232 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1233 |
| 1234 scoped_refptr<HttpNetworkSession> http_session( |
| 1235 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 1236 |
| 1237 const std::string kTestHost("www.foo.com"); |
| 1238 const int kTestPort = 80; |
| 1239 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 1240 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 1241 |
| 1242 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 1243 |
| 1244 // Create a session. |
| 1245 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 1246 scoped_refptr<SpdySession> session = |
| 1247 spdy_session_pool->Get(pair, BoundNetLog()); |
| 1248 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 1249 |
| 1250 scoped_refptr<TransportSocketParams> transport_params( |
| 1251 new TransportSocketParams(test_host_port_pair, |
| 1252 MEDIUM, |
| 1253 false, |
| 1254 false)); |
| 1255 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 1256 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 1257 transport_params, MEDIUM, CompletionCallback(), |
| 1258 http_session->GetTransportSocketPool( |
| 1259 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 1260 BoundNetLog())); |
| 1261 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1262 |
| 1263 scoped_refptr<SpdyStream> spdy_stream1; |
| 1264 TestCompletionCallback callback1; |
| 1265 GURL url1("http://www.google.com"); |
| 1266 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, |
| 1267 BoundNetLog(), callback1.callback())); |
| 1268 EXPECT_EQ(1u, spdy_stream1->stream_id()); |
| 1269 |
| 1270 scoped_refptr<SpdyStream> spdy_stream2; |
| 1271 TestCompletionCallback callback2; |
| 1272 GURL url2("http://www.google.com"); |
| 1273 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, |
| 1274 BoundNetLog(), callback2.callback())); |
| 1275 EXPECT_EQ(3u, spdy_stream2->stream_id()); |
| 1276 |
| 1277 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| 1278 (*headers)[":method"] = "GET"; |
| 1279 (*headers)[":scheme"] = url1.scheme(); |
| 1280 (*headers)[":host"] = url1.host(); |
| 1281 (*headers)[":path"] = url1.path(); |
| 1282 (*headers)[":version"] = "HTTP/1.1"; |
| 1283 spdy_stream1->set_spdy_headers(headers); |
| 1284 EXPECT_TRUE(spdy_stream1->HasUrl()); |
| 1285 |
| 1286 spdy_stream2->set_spdy_headers(headers); |
| 1287 EXPECT_TRUE(spdy_stream2->HasUrl()); |
| 1288 |
| 1289 spdy_stream1->SendRequest(false); |
| 1290 spdy_stream2->SendRequest(false); |
| 1291 MessageLoop::current()->RunAllPending(); |
| 1292 |
| 1293 EXPECT_EQ(5u, spdy_stream1->stream_id()); |
| 1294 EXPECT_EQ(3u, spdy_stream2->stream_id()); |
| 1295 |
| 1296 spdy_stream1->Cancel(); |
| 1297 spdy_stream1 = NULL; |
| 1298 |
| 1299 spdy_stream2->Cancel(); |
| 1300 spdy_stream2 = NULL; |
| 1301 } |
| 1302 |
1201 } // namespace net | 1303 } // namespace net |
OLD | NEW |