| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyGoAway()); | 120 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyGoAway()); |
| 121 MockRead reads[] = { | 121 MockRead reads[] = { |
| 122 CreateMockRead(*goaway), | 122 CreateMockRead(*goaway), |
| 123 MockRead(SYNCHRONOUS, 0, 0) // EOF | 123 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 124 }; | 124 }; |
| 125 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 125 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 126 data.set_connect_data(connect_data); | 126 data.set_connect_data(connect_data); |
| 127 session_deps.socket_factory->AddSocketDataProvider(&data); | 127 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 128 | 128 |
| 129 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 129 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 130 ssl.SetNextProto(SSLClientSocket::kProtoSPDY2); |
| 130 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 131 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 131 | 132 |
| 132 scoped_refptr<HttpNetworkSession> http_session( | 133 scoped_refptr<HttpNetworkSession> http_session( |
| 133 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 134 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 134 | 135 |
| 135 const std::string kTestHost("www.foo.com"); | 136 const std::string kTestHost("www.foo.com"); |
| 136 const int kTestPort = 80; | 137 const int kTestPort = 80; |
| 137 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 138 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 138 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 139 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 139 | 140 |
| 140 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 141 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 141 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 142 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 142 scoped_refptr<SpdySession> session = | 143 scoped_refptr<SpdySession> session = |
| 143 spdy_session_pool->Get(pair, BoundNetLog()); | 144 spdy_session_pool->Get(pair, BoundNetLog()); |
| 144 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 145 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 145 | 146 |
| 146 scoped_refptr<TransportSocketParams> transport_params( | 147 scoped_refptr<TransportSocketParams> transport_params( |
| 147 new TransportSocketParams(test_host_port_pair, | 148 new TransportSocketParams(test_host_port_pair, |
| 148 MEDIUM, | 149 MEDIUM, |
| 149 false, | 150 false, |
| 150 false)); | 151 false)); |
| 151 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 152 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 152 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), | 153 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 153 transport_params, MEDIUM, CompletionCallback(), | 154 transport_params, MEDIUM, CompletionCallback(), |
| 154 http_session->GetTransportSocketPool(), | 155 http_session->GetTransportSocketPool(), |
| 155 BoundNetLog())); | 156 BoundNetLog())); |
| 156 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 157 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 158 EXPECT_EQ(2, session->GetProtocolVersion()); |
| 157 | 159 |
| 158 // Flush the SpdySession::OnReadComplete() task. | 160 // Flush the SpdySession::OnReadComplete() task. |
| 159 MessageLoop::current()->RunAllPending(); | 161 MessageLoop::current()->RunAllPending(); |
| 160 | 162 |
| 161 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 163 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 162 | 164 |
| 163 scoped_refptr<SpdySession> session2 = | 165 scoped_refptr<SpdySession> session2 = |
| 164 spdy_session_pool->Get(pair, BoundNetLog()); | 166 spdy_session_pool->Get(pair, BoundNetLog()); |
| 165 | 167 |
| 166 // Delete the first session. | 168 // Delete the first session. |
| (...skipping 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 MockConnect connect_data(SYNCHRONOUS, OK); | 936 MockConnect connect_data(SYNCHRONOUS, OK); |
| 935 MockRead reads[] = { | 937 MockRead reads[] = { |
| 936 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 938 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 937 }; | 939 }; |
| 938 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 940 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 939 data.set_connect_data(connect_data); | 941 data.set_connect_data(connect_data); |
| 940 session_deps.socket_factory->AddSocketDataProvider(&data); | 942 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 941 | 943 |
| 942 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 944 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 943 ssl.origin_bound_cert_type = CLIENT_CERT_ECDSA_SIGN; | 945 ssl.origin_bound_cert_type = CLIENT_CERT_ECDSA_SIGN; |
| 944 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY3; | 946 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY2; |
| 945 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 947 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 946 | 948 |
| 947 scoped_refptr<HttpNetworkSession> http_session( | 949 scoped_refptr<HttpNetworkSession> http_session( |
| 948 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 950 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 949 | 951 |
| 950 const std::string kTestHost("www.foo.com"); | 952 const std::string kTestHost("www.foo.com"); |
| 951 const int kTestPort = 80; | 953 const int kTestPort = 80; |
| 952 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 954 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 953 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 955 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 954 | 956 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 980 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), | 982 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 981 ssl_params, MEDIUM, CompletionCallback(), | 983 ssl_params, MEDIUM, CompletionCallback(), |
| 982 http_session->GetSSLSocketPool(), | 984 http_session->GetSSLSocketPool(), |
| 983 BoundNetLog())); | 985 BoundNetLog())); |
| 984 | 986 |
| 985 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); | 987 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); |
| 986 | 988 |
| 987 EXPECT_FALSE(session->NeedsCredentials(test_host_port_pair)); | 989 EXPECT_FALSE(session->NeedsCredentials(test_host_port_pair)); |
| 988 const std::string kTestHost2("www.bar.com"); | 990 const std::string kTestHost2("www.bar.com"); |
| 989 HostPortPair test_host_port_pair2(kTestHost2, kTestPort); | 991 HostPortPair test_host_port_pair2(kTestHost2, kTestPort); |
| 990 EXPECT_TRUE(session->NeedsCredentials(test_host_port_pair2)); | 992 EXPECT_FALSE(session->NeedsCredentials(test_host_port_pair2)); |
| 991 | 993 |
| 992 // Flush the SpdySession::OnReadComplete() task. | 994 // Flush the SpdySession::OnReadComplete() task. |
| 993 MessageLoop::current()->RunAllPending(); | 995 MessageLoop::current()->RunAllPending(); |
| 994 | |
| 995 spdy_session_pool->Remove(session); | |
| 996 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | |
| 997 } | |
| 998 | |
| 999 TEST_F(SpdySessionSpdy2Test, SendCredentials) { | |
| 1000 SpdySessionDependencies session_deps; | |
| 1001 | |
| 1002 MockConnect connect_data(SYNCHRONOUS, OK); | |
| 1003 MockRead reads[] = { | |
| 1004 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | |
| 1005 }; | |
| 1006 spdy::SpdySettings settings; | |
| 1007 scoped_ptr<spdy::SpdyFrame> settings_frame( | |
| 1008 ConstructSpdySettings(settings)); | |
| 1009 MockWrite writes[] = { | |
| 1010 CreateMockWrite(*settings_frame), | |
| 1011 }; | |
| 1012 StaticSocketDataProvider data(reads, arraysize(reads), | |
| 1013 writes, arraysize(writes)); | |
| 1014 data.set_connect_data(connect_data); | |
| 1015 session_deps.socket_factory->AddSocketDataProvider(&data); | |
| 1016 | |
| 1017 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | |
| 1018 ssl.origin_bound_cert_type = CLIENT_CERT_ECDSA_SIGN; | |
| 1019 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY3; | |
| 1020 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | |
| 1021 | |
| 1022 scoped_refptr<HttpNetworkSession> http_session( | |
| 1023 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | |
| 1024 | |
| 1025 const std::string kTestHost("www.foo.com"); | |
| 1026 const int kTestPort = 80; | |
| 1027 HostPortPair test_host_port_pair(kTestHost, kTestPort); | |
| 1028 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | |
| 1029 | |
| 1030 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | |
| 1031 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | |
| 1032 scoped_refptr<SpdySession> session = | |
| 1033 spdy_session_pool->Get(pair, BoundNetLog()); | |
| 1034 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | |
| 1035 | |
| 1036 SSLConfig ssl_config; | |
| 1037 scoped_refptr<TransportSocketParams> transport_params( | |
| 1038 new TransportSocketParams(test_host_port_pair, | |
| 1039 MEDIUM, | |
| 1040 false, | |
| 1041 false)); | |
| 1042 scoped_refptr<SOCKSSocketParams> socks_params; | |
| 1043 scoped_refptr<HttpProxySocketParams> http_proxy_params; | |
| 1044 scoped_refptr<SSLSocketParams> ssl_params( | |
| 1045 new SSLSocketParams(transport_params, | |
| 1046 socks_params, | |
| 1047 http_proxy_params, | |
| 1048 ProxyServer::SCHEME_DIRECT, | |
| 1049 test_host_port_pair, | |
| 1050 ssl_config, | |
| 1051 0, | |
| 1052 false, | |
| 1053 false)); | |
| 1054 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | |
| 1055 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), | |
| 1056 ssl_params, MEDIUM, CompletionCallback(), | |
| 1057 http_session->GetSSLSocketPool(), | |
| 1058 BoundNetLog())); | |
| 1059 | |
| 1060 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), true, OK)); | |
| 1061 | |
| 1062 EXPECT_FALSE(session->NeedsCredentials(test_host_port_pair)); | |
| 1063 const std::string kTestHost2("www.bar.com"); | |
| 1064 HostPortPair test_host_port_pair2(kTestHost2, kTestPort); | |
| 1065 EXPECT_TRUE(session->NeedsCredentials(test_host_port_pair2)); | |
| 1066 | |
| 1067 // Flush the SpdySession::OnReadComplete() task. | |
| 1068 MessageLoop::current()->RunAllPending(); | |
| 1069 | 996 |
| 1070 spdy_session_pool->Remove(session); | 997 spdy_session_pool->Remove(session); |
| 1071 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 998 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 1072 } | 999 } |
| 1073 | 1000 |
| 1074 TEST_F(SpdySessionSpdy2Test, CloseSessionOnError) { | 1001 TEST_F(SpdySessionSpdy2Test, CloseSessionOnError) { |
| 1075 SpdySessionDependencies session_deps; | 1002 SpdySessionDependencies session_deps; |
| 1076 session_deps.host_resolver->set_synchronous_mode(true); | 1003 session_deps.host_resolver->set_synchronous_mode(true); |
| 1077 | 1004 |
| 1078 MockConnect connect_data(SYNCHRONOUS, OK); | 1005 MockConnect connect_data(SYNCHRONOUS, OK); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1134 net::NetLog::PHASE_NONE); | 1061 net::NetLog::PHASE_NONE); |
| 1135 | 1062 |
| 1136 CapturingNetLog::Entry entry = entries[pos]; | 1063 CapturingNetLog::Entry entry = entries[pos]; |
| 1137 NetLogSpdySessionCloseParameter* request_params = | 1064 NetLogSpdySessionCloseParameter* request_params = |
| 1138 static_cast<NetLogSpdySessionCloseParameter*>( | 1065 static_cast<NetLogSpdySessionCloseParameter*>( |
| 1139 entry.extra_parameters.get()); | 1066 entry.extra_parameters.get()); |
| 1140 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); | 1067 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); |
| 1141 } | 1068 } |
| 1142 | 1069 |
| 1143 } // namespace net | 1070 } // namespace net |
| OLD | NEW |