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 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1035 net::NetLog::TYPE_SPDY_SESSION_CLOSE, | 1035 net::NetLog::TYPE_SPDY_SESSION_CLOSE, |
1036 net::NetLog::PHASE_NONE); | 1036 net::NetLog::PHASE_NONE); |
1037 | 1037 |
1038 CapturingNetLog::Entry entry = entries[pos]; | 1038 CapturingNetLog::Entry entry = entries[pos]; |
1039 NetLogSpdySessionCloseParameter* request_params = | 1039 NetLogSpdySessionCloseParameter* request_params = |
1040 static_cast<NetLogSpdySessionCloseParameter*>( | 1040 static_cast<NetLogSpdySessionCloseParameter*>( |
1041 entry.extra_parameters.get()); | 1041 entry.extra_parameters.get()); |
1042 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); | 1042 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); |
1043 } | 1043 } |
1044 | 1044 |
| 1045 TEST_F(SpdySessionSpdy2Test, OutOfOrderSynStreams) { |
| 1046 // Construct the request. |
| 1047 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1048 scoped_ptr<SpdyFrame> req1(ConstructSpdyGet(NULL, 0, false, 3, HIGHEST)); |
| 1049 scoped_ptr<SpdyFrame> req2(ConstructSpdyGet(NULL, 0, false, 5, LOWEST)); |
| 1050 MockWrite writes[] = { |
| 1051 CreateMockWrite(*req1, 1), |
| 1052 CreateMockWrite(*req2, 2), |
| 1053 }; |
| 1054 |
| 1055 scoped_ptr<SpdyFrame> resp1(ConstructSpdyGetSynReply(NULL, 0, 3)); |
| 1056 scoped_ptr<SpdyFrame> body1(ConstructSpdyBodyFrame(3, true)); |
| 1057 scoped_ptr<SpdyFrame> resp2(ConstructSpdyGetSynReply(NULL, 0, 5)); |
| 1058 scoped_ptr<SpdyFrame> body2(ConstructSpdyBodyFrame(5, true)); |
| 1059 MockRead reads[] = { |
| 1060 CreateMockRead(*resp1, 3), |
| 1061 CreateMockRead(*body1, 4), |
| 1062 CreateMockRead(*resp2, 5), |
| 1063 CreateMockRead(*body2, 6), |
| 1064 MockRead(ASYNC, 0, 7) // EOF |
| 1065 }; |
| 1066 |
| 1067 SpdySessionDependencies session_deps; |
| 1068 session_deps.host_resolver->set_synchronous_mode(true); |
| 1069 |
| 1070 StaticSocketDataProvider data(reads, arraysize(reads), |
| 1071 writes, arraysize(writes)); |
| 1072 data.set_connect_data(connect_data); |
| 1073 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 1074 |
| 1075 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 1076 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1077 |
| 1078 scoped_refptr<HttpNetworkSession> http_session( |
| 1079 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 1080 |
| 1081 const std::string kTestHost("www.foo.com"); |
| 1082 const int kTestPort = 80; |
| 1083 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 1084 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 1085 |
| 1086 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 1087 |
| 1088 // Create a session. |
| 1089 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 1090 scoped_refptr<SpdySession> session = |
| 1091 spdy_session_pool->Get(pair, BoundNetLog()); |
| 1092 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 1093 |
| 1094 scoped_refptr<TransportSocketParams> transport_params( |
| 1095 new TransportSocketParams(test_host_port_pair, |
| 1096 MEDIUM, |
| 1097 false, |
| 1098 false)); |
| 1099 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 1100 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 1101 transport_params, MEDIUM, CompletionCallback(), |
| 1102 http_session->GetTransportSocketPool( |
| 1103 HttpNetworkSession::NORMAL_SOCKET_POOL), |
| 1104 BoundNetLog())); |
| 1105 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 1106 |
| 1107 scoped_refptr<SpdyStream> spdy_stream1; |
| 1108 TestCompletionCallback callback1; |
| 1109 GURL url1("http://www.google.com"); |
| 1110 EXPECT_EQ(OK, session->CreateStream(url1, LOWEST, &spdy_stream1, |
| 1111 BoundNetLog(), callback1.callback())); |
| 1112 EXPECT_EQ(1u, spdy_stream1->stream_id()); |
| 1113 |
| 1114 scoped_refptr<SpdyStream> spdy_stream2; |
| 1115 TestCompletionCallback callback2; |
| 1116 GURL url2("http://www.google.com"); |
| 1117 EXPECT_EQ(OK, session->CreateStream(url2, HIGHEST, &spdy_stream2, |
| 1118 BoundNetLog(), callback2.callback())); |
| 1119 EXPECT_EQ(3u, spdy_stream2->stream_id()); |
| 1120 |
| 1121 linked_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock); |
| 1122 (*headers)["method"] = "GET"; |
| 1123 (*headers)["scheme"] = url1.scheme(); |
| 1124 (*headers)["host"] = url1.host(); |
| 1125 (*headers)["url"] = url1.path(); |
| 1126 (*headers)["version"] = "HTTP/1.1"; |
| 1127 spdy_stream1->set_spdy_headers(headers); |
| 1128 EXPECT_TRUE(spdy_stream1->HasUrl()); |
| 1129 |
| 1130 spdy_stream2->set_spdy_headers(headers); |
| 1131 EXPECT_TRUE(spdy_stream2->HasUrl()); |
| 1132 |
| 1133 spdy_stream1->SendRequest(false); |
| 1134 spdy_stream2->SendRequest(false); |
| 1135 MessageLoop::current()->RunAllPending(); |
| 1136 |
| 1137 EXPECT_EQ(5u, spdy_stream1->stream_id()); |
| 1138 EXPECT_EQ(3u, spdy_stream2->stream_id()); |
| 1139 |
| 1140 spdy_stream1->Cancel(); |
| 1141 spdy_stream1 = NULL; |
| 1142 |
| 1143 spdy_stream2->Cancel(); |
| 1144 spdy_stream2 = NULL; |
| 1145 } |
| 1146 |
1045 } // namespace net | 1147 } // namespace net |
OLD | NEW |