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 "base/base64.h" | 7 #include "base/base64.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 void CreateNetworkSession() { | 121 void CreateNetworkSession() { |
122 DCHECK(!http_session_); | 122 DCHECK(!http_session_); |
123 DCHECK(!spdy_session_pool_); | 123 DCHECK(!spdy_session_pool_); |
124 http_session_ = | 124 http_session_ = |
125 SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 125 SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
126 spdy_session_pool_ = http_session_->spdy_session_pool(); | 126 spdy_session_pool_ = http_session_->spdy_session_pool(); |
127 } | 127 } |
128 | 128 |
129 void CreateInsecureSpdySession() { | 129 void CreateInsecureSpdySession() { |
130 DCHECK(!session_); | 130 DCHECK(!session_); |
131 session_ = | 131 session_ = ::net::CreateInsecureSpdySession(http_session_.get(), key_, |
132 ::net::CreateInsecureSpdySession(http_session_, key_, log_.bound()); | 132 log_.bound()); |
133 } | 133 } |
134 | 134 |
135 void StallSessionSend() { | 135 void StallSessionSend() { |
136 // Reduce the send window size to 0 to stall. | 136 // Reduce the send window size to 0 to stall. |
137 while (session_->session_send_window_size_ > 0) { | 137 while (session_->session_send_window_size_ > 0) { |
138 session_->DecreaseSendWindowSize(std::min( | 138 session_->DecreaseSendWindowSize(std::min( |
139 kMaxSpdyFrameChunkSize, session_->session_send_window_size_)); | 139 kMaxSpdyFrameChunkSize, session_->session_send_window_size_)); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
(...skipping 17 matching lines...) Expand all Loading... |
160 const base::Callback<void(SpdyStream*)>& stall_function, | 160 const base::Callback<void(SpdyStream*)>& stall_function, |
161 const base::Callback<void(SpdyStream*, int32)>& unstall_function); | 161 const base::Callback<void(SpdyStream*, int32)>& unstall_function); |
162 | 162 |
163 // Original socket limits. Some tests set these. Safest to always restore | 163 // Original socket limits. Some tests set these. Safest to always restore |
164 // them once each test has been run. | 164 // them once each test has been run. |
165 int old_max_group_sockets_; | 165 int old_max_group_sockets_; |
166 int old_max_pool_sockets_; | 166 int old_max_pool_sockets_; |
167 | 167 |
168 SpdyTestUtil spdy_util_; | 168 SpdyTestUtil spdy_util_; |
169 SpdySessionDependencies session_deps_; | 169 SpdySessionDependencies session_deps_; |
170 scoped_refptr<HttpNetworkSession> http_session_; | 170 scoped_ptr<HttpNetworkSession> http_session_; |
171 base::WeakPtr<SpdySession> session_; | 171 base::WeakPtr<SpdySession> session_; |
172 SpdySessionPool* spdy_session_pool_; | 172 SpdySessionPool* spdy_session_pool_; |
173 GURL test_url_; | 173 GURL test_url_; |
174 HostPortPair test_host_port_pair_; | 174 HostPortPair test_host_port_pair_; |
175 SpdySessionKey key_; | 175 SpdySessionKey key_; |
176 BoundTestNetLog log_; | 176 BoundTestNetLog log_; |
177 }; | 177 }; |
178 | 178 |
179 INSTANTIATE_TEST_CASE_P(NextProto, | 179 INSTANTIATE_TEST_CASE_P(NextProto, |
180 SpdySessionTest, | 180 SpdySessionTest, |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 300 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
301 MockRead reads[] = { | 301 MockRead reads[] = { |
302 CreateMockRead(*goaway, 0, SYNCHRONOUS), MockRead(ASYNC, 0, 1) // EOF | 302 CreateMockRead(*goaway, 0, SYNCHRONOUS), MockRead(ASYNC, 0, 1) // EOF |
303 }; | 303 }; |
304 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); | 304 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); |
305 session_deps_.socket_factory->AddSocketDataProvider(&data); | 305 session_deps_.socket_factory->AddSocketDataProvider(&data); |
306 | 306 |
307 CreateNetworkSession(); | 307 CreateNetworkSession(); |
308 | 308 |
309 session_ = TryCreateInsecureSpdySessionExpectingFailure( | 309 session_ = TryCreateInsecureSpdySessionExpectingFailure( |
310 http_session_, key_, ERR_CONNECTION_CLOSED, BoundNetLog()); | 310 http_session_.get(), key_, ERR_CONNECTION_CLOSED, BoundNetLog()); |
311 base::RunLoop().RunUntilIdle(); | 311 base::RunLoop().RunUntilIdle(); |
312 | 312 |
313 EXPECT_FALSE(session_); | 313 EXPECT_FALSE(session_); |
314 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 314 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
315 EXPECT_FALSE(data.AllReadDataConsumed()); | 315 EXPECT_FALSE(data.AllReadDataConsumed()); |
316 } | 316 } |
317 | 317 |
318 // A session receiving a GOAWAY frame with active streams should close | 318 // A session receiving a GOAWAY frame with active streams should close |
319 // when the last active stream is closed. | 319 // when the last active stream is closed. |
320 TEST_P(SpdySessionTest, GoAwayWithActiveStreams) { | 320 TEST_P(SpdySessionTest, GoAwayWithActiveStreams) { |
(...skipping 1858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 scoped_refptr<X509Certificate> test_cert( | 2179 scoped_refptr<X509Certificate> test_cert( |
2180 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); | 2180 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
2181 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); | 2181 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
2182 | 2182 |
2183 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 2183 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
2184 ssl.cert = test_cert; | 2184 ssl.cert = test_cert; |
2185 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 2185 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
2186 | 2186 |
2187 CreateNetworkSession(); | 2187 CreateNetworkSession(); |
2188 | 2188 |
2189 session_ = CreateSecureSpdySession(http_session_, key_, BoundNetLog()); | 2189 session_ = CreateSecureSpdySession(http_session_.get(), key_, BoundNetLog()); |
2190 | 2190 |
2191 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org")); | 2191 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org")); |
2192 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org")); | 2192 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org")); |
2193 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.com")); | 2193 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.com")); |
2194 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com")); | 2194 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com")); |
2195 } | 2195 } |
2196 | 2196 |
2197 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) { | 2197 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) { |
2198 session_deps_.host_resolver->set_synchronous_mode(true); | 2198 session_deps_.host_resolver->set_synchronous_mode(true); |
2199 | 2199 |
2200 SequencedSocketData data(nullptr, 0, nullptr, 0); | 2200 SequencedSocketData data(nullptr, 0, nullptr, 0); |
2201 session_deps_.socket_factory->AddSocketDataProvider(&data); | 2201 session_deps_.socket_factory->AddSocketDataProvider(&data); |
2202 | 2202 |
2203 // Load a cert that is valid for: | 2203 // Load a cert that is valid for: |
2204 // www.example.org | 2204 // www.example.org |
2205 // mail.example.org | 2205 // mail.example.org |
2206 // www.example.com | 2206 // www.example.com |
2207 base::FilePath certs_dir = GetTestCertsDirectory(); | 2207 base::FilePath certs_dir = GetTestCertsDirectory(); |
2208 scoped_refptr<X509Certificate> test_cert( | 2208 scoped_refptr<X509Certificate> test_cert( |
2209 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); | 2209 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); |
2210 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); | 2210 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); |
2211 | 2211 |
2212 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 2212 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
2213 ssl.channel_id_sent = true; | 2213 ssl.channel_id_sent = true; |
2214 ssl.cert = test_cert; | 2214 ssl.cert = test_cert; |
2215 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 2215 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
2216 | 2216 |
2217 CreateNetworkSession(); | 2217 CreateNetworkSession(); |
2218 | 2218 |
2219 session_ = CreateSecureSpdySession(http_session_, key_, BoundNetLog()); | 2219 session_ = CreateSecureSpdySession(http_session_.get(), key_, BoundNetLog()); |
2220 | 2220 |
2221 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org")); | 2221 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org")); |
2222 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org")); | 2222 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org")); |
2223 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.example.com")); | 2223 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.example.com")); |
2224 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com")); | 2224 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com")); |
2225 } | 2225 } |
2226 | 2226 |
2227 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) { | 2227 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) { |
2228 // TODO(rtenneti): Define a helper class/methods and move the common code in | 2228 // TODO(rtenneti): Define a helper class/methods and move the common code in |
2229 // this file. | 2229 // this file. |
(...skipping 721 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2951 | 2951 |
2952 CreateNetworkSession(); | 2952 CreateNetworkSession(); |
2953 | 2953 |
2954 TransportClientSocketPool* pool = | 2954 TransportClientSocketPool* pool = |
2955 http_session_->GetTransportSocketPool( | 2955 http_session_->GetTransportSocketPool( |
2956 HttpNetworkSession::NORMAL_SOCKET_POOL); | 2956 HttpNetworkSession::NORMAL_SOCKET_POOL); |
2957 | 2957 |
2958 // Create an idle SPDY session. | 2958 // Create an idle SPDY session. |
2959 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), | 2959 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), |
2960 PRIVACY_MODE_DISABLED); | 2960 PRIVACY_MODE_DISABLED); |
2961 base::WeakPtr<SpdySession> session1 = | 2961 base::WeakPtr<SpdySession> session1 = ::net::CreateInsecureSpdySession( |
2962 ::net::CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); | 2962 http_session_.get(), key1, BoundNetLog()); |
2963 EXPECT_FALSE(pool->IsStalled()); | 2963 EXPECT_FALSE(pool->IsStalled()); |
2964 | 2964 |
2965 // Set up an alias for the idle SPDY session, increasing its ref count to 2. | 2965 // Set up an alias for the idle SPDY session, increasing its ref count to 2. |
2966 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(), | 2966 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(), |
2967 PRIVACY_MODE_DISABLED); | 2967 PRIVACY_MODE_DISABLED); |
2968 HostResolver::RequestInfo info(key2.host_port_pair()); | 2968 HostResolver::RequestInfo info(key2.host_port_pair()); |
2969 AddressList addresses; | 2969 AddressList addresses; |
2970 // Pre-populate the DNS cache, since a synchronous resolution is required in | 2970 // Pre-populate the DNS cache, since a synchronous resolution is required in |
2971 // order to create the alias. | 2971 // order to create the alias. |
2972 session_deps_.host_resolver->Resolve(info, DEFAULT_PRIORITY, &addresses, | 2972 session_deps_.host_resolver->Resolve(info, DEFAULT_PRIORITY, &addresses, |
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5039 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5039 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5040 "spdy_pooling.pem"); | 5040 "spdy_pooling.pem"); |
5041 ssl_info.is_issued_by_known_root = true; | 5041 ssl_info.is_issued_by_known_root = true; |
5042 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5042 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5043 | 5043 |
5044 EXPECT_TRUE(SpdySession::CanPool( | 5044 EXPECT_TRUE(SpdySession::CanPool( |
5045 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5045 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5046 } | 5046 } |
5047 | 5047 |
5048 } // namespace net | 5048 } // namespace net |
OLD | NEW |