Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: net/spdy/spdy_session_unittest.cc

Issue 1342613002: Revert of Remove reference counting from HttpNetworkSession. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/spdy/spdy_session_pool_unittest.cc ('k') | net/spdy/spdy_stream_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 void CreateNetworkSession() { 128 void CreateNetworkSession() {
129 DCHECK(!http_session_); 129 DCHECK(!http_session_);
130 DCHECK(!spdy_session_pool_); 130 DCHECK(!spdy_session_pool_);
131 http_session_ = 131 http_session_ =
132 SpdySessionDependencies::SpdyCreateSession(&session_deps_); 132 SpdySessionDependencies::SpdyCreateSession(&session_deps_);
133 spdy_session_pool_ = http_session_->spdy_session_pool(); 133 spdy_session_pool_ = http_session_->spdy_session_pool();
134 } 134 }
135 135
136 void CreateInsecureSpdySession() { 136 void CreateInsecureSpdySession() {
137 DCHECK(!session_); 137 DCHECK(!session_);
138 session_ = ::net::CreateInsecureSpdySession(http_session_.get(), key_, 138 session_ =
139 log_.bound()); 139 ::net::CreateInsecureSpdySession(http_session_, key_, log_.bound());
140 } 140 }
141 141
142 void StallSessionSend() { 142 void StallSessionSend() {
143 // Reduce the send window size to 0 to stall. 143 // Reduce the send window size to 0 to stall.
144 while (session_->session_send_window_size_ > 0) { 144 while (session_->session_send_window_size_ > 0) {
145 session_->DecreaseSendWindowSize(std::min( 145 session_->DecreaseSendWindowSize(std::min(
146 kMaxSpdyFrameChunkSize, session_->session_send_window_size_)); 146 kMaxSpdyFrameChunkSize, session_->session_send_window_size_));
147 } 147 }
148 } 148 }
149 149
(...skipping 17 matching lines...) Expand all
167 const base::Callback<void(SpdyStream*)>& stall_function, 167 const base::Callback<void(SpdyStream*)>& stall_function,
168 const base::Callback<void(SpdyStream*, int32)>& unstall_function); 168 const base::Callback<void(SpdyStream*, int32)>& unstall_function);
169 169
170 // Original socket limits. Some tests set these. Safest to always restore 170 // Original socket limits. Some tests set these. Safest to always restore
171 // them once each test has been run. 171 // them once each test has been run.
172 int old_max_group_sockets_; 172 int old_max_group_sockets_;
173 int old_max_pool_sockets_; 173 int old_max_pool_sockets_;
174 174
175 SpdyTestUtil spdy_util_; 175 SpdyTestUtil spdy_util_;
176 SpdySessionDependencies session_deps_; 176 SpdySessionDependencies session_deps_;
177 scoped_ptr<HttpNetworkSession> http_session_; 177 scoped_refptr<HttpNetworkSession> http_session_;
178 base::WeakPtr<SpdySession> session_; 178 base::WeakPtr<SpdySession> session_;
179 SpdySessionPool* spdy_session_pool_; 179 SpdySessionPool* spdy_session_pool_;
180 GURL test_url_; 180 GURL test_url_;
181 HostPortPair test_host_port_pair_; 181 HostPortPair test_host_port_pair_;
182 SpdySessionKey key_; 182 SpdySessionKey key_;
183 BoundTestNetLog log_; 183 BoundTestNetLog log_;
184 }; 184 };
185 185
186 INSTANTIATE_TEST_CASE_P(NextProto, 186 INSTANTIATE_TEST_CASE_P(NextProto,
187 SpdySessionTest, 187 SpdySessionTest,
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); 307 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1));
308 MockRead reads[] = { 308 MockRead reads[] = {
309 CreateMockRead(*goaway, 0, SYNCHRONOUS), MockRead(ASYNC, 0, 1) // EOF 309 CreateMockRead(*goaway, 0, SYNCHRONOUS), MockRead(ASYNC, 0, 1) // EOF
310 }; 310 };
311 SequencedSocketData data(reads, arraysize(reads), nullptr, 0); 311 SequencedSocketData data(reads, arraysize(reads), nullptr, 0);
312 session_deps_.socket_factory->AddSocketDataProvider(&data); 312 session_deps_.socket_factory->AddSocketDataProvider(&data);
313 313
314 CreateNetworkSession(); 314 CreateNetworkSession();
315 315
316 session_ = TryCreateInsecureSpdySessionExpectingFailure( 316 session_ = TryCreateInsecureSpdySessionExpectingFailure(
317 http_session_.get(), key_, ERR_CONNECTION_CLOSED, BoundNetLog()); 317 http_session_, key_, ERR_CONNECTION_CLOSED, BoundNetLog());
318 base::RunLoop().RunUntilIdle(); 318 base::RunLoop().RunUntilIdle();
319 319
320 EXPECT_FALSE(session_); 320 EXPECT_FALSE(session_);
321 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 321 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
322 EXPECT_FALSE(data.AllReadDataConsumed()); 322 EXPECT_FALSE(data.AllReadDataConsumed());
323 } 323 }
324 324
325 // A session receiving a GOAWAY frame with active streams should close 325 // A session receiving a GOAWAY frame with active streams should close
326 // when the last active stream is closed. 326 // when the last active stream is closed.
327 TEST_P(SpdySessionTest, GoAwayWithActiveStreams) { 327 TEST_P(SpdySessionTest, GoAwayWithActiveStreams) {
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
2185 scoped_refptr<X509Certificate> test_cert( 2185 scoped_refptr<X509Certificate> test_cert(
2186 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); 2186 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
2187 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); 2187 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get());
2188 2188
2189 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2189 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2190 ssl.cert = test_cert; 2190 ssl.cert = test_cert;
2191 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 2191 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
2192 2192
2193 CreateNetworkSession(); 2193 CreateNetworkSession();
2194 2194
2195 session_ = CreateSecureSpdySession(http_session_.get(), key_, BoundNetLog()); 2195 session_ = CreateSecureSpdySession(http_session_, key_, BoundNetLog());
2196 2196
2197 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org")); 2197 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org"));
2198 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org")); 2198 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org"));
2199 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.com")); 2199 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.com"));
2200 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com")); 2200 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com"));
2201 } 2201 }
2202 2202
2203 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) { 2203 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) {
2204 session_deps_.host_resolver->set_synchronous_mode(true); 2204 session_deps_.host_resolver->set_synchronous_mode(true);
2205 2205
2206 SequencedSocketData data(nullptr, 0, nullptr, 0); 2206 SequencedSocketData data(nullptr, 0, nullptr, 0);
2207 session_deps_.socket_factory->AddSocketDataProvider(&data); 2207 session_deps_.socket_factory->AddSocketDataProvider(&data);
2208 2208
2209 // Load a cert that is valid for: 2209 // Load a cert that is valid for:
2210 // www.example.org 2210 // www.example.org
2211 // mail.example.org 2211 // mail.example.org
2212 // www.example.com 2212 // www.example.com
2213 base::FilePath certs_dir = GetTestCertsDirectory(); 2213 base::FilePath certs_dir = GetTestCertsDirectory();
2214 scoped_refptr<X509Certificate> test_cert( 2214 scoped_refptr<X509Certificate> test_cert(
2215 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); 2215 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
2216 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get()); 2216 ASSERT_NE(static_cast<X509Certificate*>(nullptr), test_cert.get());
2217 2217
2218 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2218 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2219 ssl.channel_id_sent = true; 2219 ssl.channel_id_sent = true;
2220 ssl.cert = test_cert; 2220 ssl.cert = test_cert;
2221 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 2221 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
2222 2222
2223 CreateNetworkSession(); 2223 CreateNetworkSession();
2224 2224
2225 session_ = CreateSecureSpdySession(http_session_.get(), key_, BoundNetLog()); 2225 session_ = CreateSecureSpdySession(http_session_, key_, BoundNetLog());
2226 2226
2227 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org")); 2227 EXPECT_TRUE(session_->VerifyDomainAuthentication("www.example.org"));
2228 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org")); 2228 EXPECT_TRUE(session_->VerifyDomainAuthentication("mail.example.org"));
2229 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.example.com")); 2229 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.example.com"));
2230 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com")); 2230 EXPECT_FALSE(session_->VerifyDomainAuthentication("mail.google.com"));
2231 } 2231 }
2232 2232
2233 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) { 2233 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) {
2234 // TODO(rtenneti): Define a helper class/methods and move the common code in 2234 // TODO(rtenneti): Define a helper class/methods and move the common code in
2235 // this file. 2235 // this file.
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 2960
2961 CreateNetworkSession(); 2961 CreateNetworkSession();
2962 2962
2963 TransportClientSocketPool* pool = 2963 TransportClientSocketPool* pool =
2964 http_session_->GetTransportSocketPool( 2964 http_session_->GetTransportSocketPool(
2965 HttpNetworkSession::NORMAL_SOCKET_POOL); 2965 HttpNetworkSession::NORMAL_SOCKET_POOL);
2966 2966
2967 // Create an idle SPDY session. 2967 // Create an idle SPDY session.
2968 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), 2968 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(),
2969 PRIVACY_MODE_DISABLED); 2969 PRIVACY_MODE_DISABLED);
2970 base::WeakPtr<SpdySession> session1 = ::net::CreateInsecureSpdySession( 2970 base::WeakPtr<SpdySession> session1 =
2971 http_session_.get(), key1, BoundNetLog()); 2971 ::net::CreateInsecureSpdySession(http_session_, key1, BoundNetLog());
2972 EXPECT_FALSE(pool->IsStalled()); 2972 EXPECT_FALSE(pool->IsStalled());
2973 2973
2974 // Set up an alias for the idle SPDY session, increasing its ref count to 2. 2974 // Set up an alias for the idle SPDY session, increasing its ref count to 2.
2975 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(), 2975 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(),
2976 PRIVACY_MODE_DISABLED); 2976 PRIVACY_MODE_DISABLED);
2977 HostResolver::RequestInfo info(key2.host_port_pair()); 2977 HostResolver::RequestInfo info(key2.host_port_pair());
2978 AddressList addresses; 2978 AddressList addresses;
2979 // Pre-populate the DNS cache, since a synchronous resolution is required in 2979 // Pre-populate the DNS cache, since a synchronous resolution is required in
2980 // order to create the alias. 2980 // order to create the alias.
2981 session_deps_.host_resolver->Resolve(info, DEFAULT_PRIORITY, &addresses, 2981 session_deps_.host_resolver->Resolve(info, DEFAULT_PRIORITY, &addresses,
(...skipping 2066 matching lines...) Expand 10 before | Expand all | Expand 10 after
5048 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), 5048 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(),
5049 "spdy_pooling.pem"); 5049 "spdy_pooling.pem");
5050 ssl_info.is_issued_by_known_root = true; 5050 ssl_info.is_issued_by_known_root = true;
5051 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); 5051 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin));
5052 5052
5053 EXPECT_TRUE(SpdySession::CanPool( 5053 EXPECT_TRUE(SpdySession::CanPool(
5054 &tss, ssl_info, "www.example.org", "mail.example.org")); 5054 &tss, ssl_info, "www.example.org", "mail.example.org"));
5055 } 5055 }
5056 5056
5057 } // namespace net 5057 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool_unittest.cc ('k') | net/spdy/spdy_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698