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