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