OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_pool.h" | 5 #include "net/spdy/spdy_session_pool.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 class SpdySessionPoolTest : public ::testing::Test, | 24 class SpdySessionPoolTest : public ::testing::Test, |
25 public ::testing::WithParamInterface<NextProto> { | 25 public ::testing::WithParamInterface<NextProto> { |
26 protected: | 26 protected: |
27 // Used by RunIPPoolingTest(). | 27 // Used by RunIPPoolingTest(). |
28 enum SpdyPoolCloseSessionsType { | 28 enum SpdyPoolCloseSessionsType { |
29 SPDY_POOL_CLOSE_SESSIONS_MANUALLY, | 29 SPDY_POOL_CLOSE_SESSIONS_MANUALLY, |
30 SPDY_POOL_CLOSE_CURRENT_SESSIONS, | 30 SPDY_POOL_CLOSE_CURRENT_SESSIONS, |
31 SPDY_POOL_CLOSE_IDLE_SESSIONS, | 31 SPDY_POOL_CLOSE_IDLE_SESSIONS, |
32 }; | 32 }; |
33 | 33 |
34 SpdySessionPoolTest() | 34 SpdySessionPoolTest() : session_deps_(GetParam()), spdy_session_pool_(NULL) {} |
35 : session_deps_(GetParam()), | |
36 spdy_session_pool_(NULL) {} | |
37 | 35 |
38 void CreateNetworkSession() { | 36 void CreateNetworkSession() { |
39 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); | 37 http_session_ = SpdySessionDependencies::SpdyCreateSession(&session_deps_); |
40 spdy_session_pool_ = http_session_->spdy_session_pool(); | 38 spdy_session_pool_ = http_session_->spdy_session_pool(); |
41 } | 39 } |
42 | 40 |
43 void RunIPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type); | 41 void RunIPPoolingTest(SpdyPoolCloseSessionsType close_sessions_type); |
44 | 42 |
45 SpdySessionDependencies session_deps_; | 43 SpdySessionDependencies session_deps_; |
46 scoped_refptr<HttpNetworkSession> http_session_; | 44 scoped_refptr<HttpNetworkSession> http_session_; |
47 SpdySessionPool* spdy_session_pool_; | 45 SpdySessionPool* spdy_session_pool_; |
48 }; | 46 }; |
49 | 47 |
50 INSTANTIATE_TEST_CASE_P( | 48 INSTANTIATE_TEST_CASE_P(NextProto, |
51 NextProto, | 49 SpdySessionPoolTest, |
52 SpdySessionPoolTest, | 50 testing::Values(kProtoDeprecatedSPDY2, |
53 testing::Values(kProtoDeprecatedSPDY2, | 51 kProtoSPDY3, |
54 kProtoSPDY3, kProtoSPDY31, kProtoSPDY4)); | 52 kProtoSPDY31, |
| 53 kProtoSPDY4)); |
55 | 54 |
56 // A delegate that opens a new session when it is closed. | 55 // A delegate that opens a new session when it is closed. |
57 class SessionOpeningDelegate : public SpdyStream::Delegate { | 56 class SessionOpeningDelegate : public SpdyStream::Delegate { |
58 public: | 57 public: |
59 SessionOpeningDelegate(SpdySessionPool* spdy_session_pool, | 58 SessionOpeningDelegate(SpdySessionPool* spdy_session_pool, |
60 const SpdySessionKey& key) | 59 const SpdySessionKey& key) |
61 : spdy_session_pool_(spdy_session_pool), | 60 : spdy_session_pool_(spdy_session_pool), key_(key) {} |
62 key_(key) {} | |
63 | 61 |
64 virtual ~SessionOpeningDelegate() {} | 62 virtual ~SessionOpeningDelegate() {} |
65 | 63 |
66 virtual void OnRequestHeadersSent() OVERRIDE {} | 64 virtual void OnRequestHeadersSent() OVERRIDE {} |
67 | 65 |
68 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( | 66 virtual SpdyResponseHeadersStatus OnResponseHeadersUpdated( |
69 const SpdyHeaderBlock& response_headers) OVERRIDE { | 67 const SpdyHeaderBlock& response_headers) OVERRIDE { |
70 return RESPONSE_HEADERS_ARE_COMPLETE; | 68 return RESPONSE_HEADERS_ARE_COMPLETE; |
71 } | 69 } |
72 | 70 |
(...skipping 12 matching lines...) Expand all Loading... |
85 | 83 |
86 // Set up a SpdyStream to create a new session when it is closed. | 84 // Set up a SpdyStream to create a new session when it is closed. |
87 // CloseCurrentSessions should not close the newly-created session. | 85 // CloseCurrentSessions should not close the newly-created session. |
88 TEST_P(SpdySessionPoolTest, CloseCurrentSessions) { | 86 TEST_P(SpdySessionPoolTest, CloseCurrentSessions) { |
89 const char kTestHost[] = "www.foo.com"; | 87 const char kTestHost[] = "www.foo.com"; |
90 const int kTestPort = 80; | 88 const int kTestPort = 80; |
91 | 89 |
92 session_deps_.host_resolver->set_synchronous_mode(true); | 90 session_deps_.host_resolver->set_synchronous_mode(true); |
93 | 91 |
94 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 92 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
95 SpdySessionKey test_key = | 93 SpdySessionKey test_key = SpdySessionKey( |
96 SpdySessionKey( | 94 test_host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
97 test_host_port_pair, ProxyServer::Direct(), | |
98 PRIVACY_MODE_DISABLED); | |
99 | 95 |
100 MockConnect connect_data(SYNCHRONOUS, OK); | 96 MockConnect connect_data(SYNCHRONOUS, OK); |
101 MockRead reads[] = { | 97 MockRead reads[] = { |
102 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 98 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
103 }; | 99 }; |
104 | 100 |
105 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 101 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
106 data.set_connect_data(connect_data); | 102 data.set_connect_data(connect_data); |
107 session_deps_.socket_factory->AddSocketDataProvider(&data); | 103 session_deps_.socket_factory->AddSocketDataProvider(&data); |
108 | 104 |
109 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 105 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
110 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 106 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
111 | 107 |
112 CreateNetworkSession(); | 108 CreateNetworkSession(); |
113 | 109 |
114 // Setup the first session to the first host. | 110 // Setup the first session to the first host. |
115 base::WeakPtr<SpdySession> session = | 111 base::WeakPtr<SpdySession> session = |
116 CreateInsecureSpdySession(http_session_, test_key, BoundNetLog()); | 112 CreateInsecureSpdySession(http_session_, test_key, BoundNetLog()); |
117 | 113 |
118 // Flush the SpdySession::OnReadComplete() task. | 114 // Flush the SpdySession::OnReadComplete() task. |
119 base::MessageLoop::current()->RunUntilIdle(); | 115 base::MessageLoop::current()->RunUntilIdle(); |
120 | 116 |
121 // Verify that we have sessions for everything. | 117 // Verify that we have sessions for everything. |
122 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 118 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
123 | 119 |
124 // Set the stream to create a new session when it is closed. | 120 // Set the stream to create a new session when it is closed. |
125 base::WeakPtr<SpdyStream> spdy_stream = | 121 base::WeakPtr<SpdyStream> spdy_stream = |
126 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 122 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, |
127 session, GURL("http://www.foo.com"), | 123 session, |
128 MEDIUM, BoundNetLog()); | 124 GURL("http://www.foo.com"), |
| 125 MEDIUM, |
| 126 BoundNetLog()); |
129 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); | 127 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); |
130 spdy_stream->SetDelegate(&delegate); | 128 spdy_stream->SetDelegate(&delegate); |
131 | 129 |
132 // Close the current session. | 130 // Close the current session. |
133 spdy_session_pool_->CloseCurrentSessions(net::ERR_ABORTED); | 131 spdy_session_pool_->CloseCurrentSessions(net::ERR_ABORTED); |
134 | 132 |
135 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 133 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
136 } | 134 } |
137 | 135 |
138 TEST_P(SpdySessionPoolTest, CloseCurrentIdleSessions) { | 136 TEST_P(SpdySessionPoolTest, CloseCurrentIdleSessions) { |
139 MockConnect connect_data(SYNCHRONOUS, OK); | 137 MockConnect connect_data(SYNCHRONOUS, OK); |
140 MockRead reads[] = { | 138 MockRead reads[] = { |
141 MockRead(ASYNC, 0, 0) // EOF | 139 MockRead(ASYNC, 0, 0) // EOF |
142 }; | 140 }; |
143 | 141 |
144 session_deps_.host_resolver->set_synchronous_mode(true); | 142 session_deps_.host_resolver->set_synchronous_mode(true); |
145 | 143 |
146 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 144 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
147 data.set_connect_data(connect_data); | 145 data.set_connect_data(connect_data); |
148 session_deps_.socket_factory->AddSocketDataProvider(&data); | 146 session_deps_.socket_factory->AddSocketDataProvider(&data); |
149 | 147 |
150 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 148 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
151 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 149 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
152 | 150 |
153 CreateNetworkSession(); | 151 CreateNetworkSession(); |
154 | 152 |
155 // Set up session 1 | 153 // Set up session 1 |
156 const std::string kTestHost1("http://www.a.com"); | 154 const std::string kTestHost1("http://www.a.com"); |
157 HostPortPair test_host_port_pair1(kTestHost1, 80); | 155 HostPortPair test_host_port_pair1(kTestHost1, 80); |
158 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), | 156 SpdySessionKey key1( |
159 PRIVACY_MODE_DISABLED); | 157 test_host_port_pair1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
160 base::WeakPtr<SpdySession> session1 = | 158 base::WeakPtr<SpdySession> session1 = |
161 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); | 159 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); |
162 GURL url1(kTestHost1); | 160 GURL url1(kTestHost1); |
163 base::WeakPtr<SpdyStream> spdy_stream1 = | 161 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( |
164 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 162 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, BoundNetLog()); |
165 session1, url1, MEDIUM, BoundNetLog()); | |
166 ASSERT_TRUE(spdy_stream1.get() != NULL); | 163 ASSERT_TRUE(spdy_stream1.get() != NULL); |
167 | 164 |
168 // Set up session 2 | 165 // Set up session 2 |
169 session_deps_.socket_factory->AddSocketDataProvider(&data); | 166 session_deps_.socket_factory->AddSocketDataProvider(&data); |
170 const std::string kTestHost2("http://www.b.com"); | 167 const std::string kTestHost2("http://www.b.com"); |
171 HostPortPair test_host_port_pair2(kTestHost2, 80); | 168 HostPortPair test_host_port_pair2(kTestHost2, 80); |
172 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), | 169 SpdySessionKey key2( |
173 PRIVACY_MODE_DISABLED); | 170 test_host_port_pair2, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
174 base::WeakPtr<SpdySession> session2 = | 171 base::WeakPtr<SpdySession> session2 = |
175 CreateInsecureSpdySession(http_session_, key2, BoundNetLog()); | 172 CreateInsecureSpdySession(http_session_, key2, BoundNetLog()); |
176 GURL url2(kTestHost2); | 173 GURL url2(kTestHost2); |
177 base::WeakPtr<SpdyStream> spdy_stream2 = | 174 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( |
178 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 175 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, BoundNetLog()); |
179 session2, url2, MEDIUM, BoundNetLog()); | |
180 ASSERT_TRUE(spdy_stream2.get() != NULL); | 176 ASSERT_TRUE(spdy_stream2.get() != NULL); |
181 | 177 |
182 // Set up session 3 | 178 // Set up session 3 |
183 session_deps_.socket_factory->AddSocketDataProvider(&data); | 179 session_deps_.socket_factory->AddSocketDataProvider(&data); |
184 const std::string kTestHost3("http://www.c.com"); | 180 const std::string kTestHost3("http://www.c.com"); |
185 HostPortPair test_host_port_pair3(kTestHost3, 80); | 181 HostPortPair test_host_port_pair3(kTestHost3, 80); |
186 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), | 182 SpdySessionKey key3( |
187 PRIVACY_MODE_DISABLED); | 183 test_host_port_pair3, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
188 base::WeakPtr<SpdySession> session3 = | 184 base::WeakPtr<SpdySession> session3 = |
189 CreateInsecureSpdySession(http_session_, key3, BoundNetLog()); | 185 CreateInsecureSpdySession(http_session_, key3, BoundNetLog()); |
190 GURL url3(kTestHost3); | 186 GURL url3(kTestHost3); |
191 base::WeakPtr<SpdyStream> spdy_stream3 = | 187 base::WeakPtr<SpdyStream> spdy_stream3 = CreateStreamSynchronously( |
192 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 188 SPDY_BIDIRECTIONAL_STREAM, session3, url3, MEDIUM, BoundNetLog()); |
193 session3, url3, MEDIUM, BoundNetLog()); | |
194 ASSERT_TRUE(spdy_stream3.get() != NULL); | 189 ASSERT_TRUE(spdy_stream3.get() != NULL); |
195 | 190 |
196 // All sessions are active and not closed | 191 // All sessions are active and not closed |
197 EXPECT_TRUE(session1->is_active()); | 192 EXPECT_TRUE(session1->is_active()); |
198 EXPECT_FALSE(session1->IsClosed()); | 193 EXPECT_FALSE(session1->IsClosed()); |
199 EXPECT_TRUE(session2->is_active()); | 194 EXPECT_TRUE(session2->is_active()); |
200 EXPECT_FALSE(session2->IsClosed()); | 195 EXPECT_FALSE(session2->IsClosed()); |
201 EXPECT_TRUE(session3->is_active()); | 196 EXPECT_TRUE(session3->is_active()); |
202 EXPECT_FALSE(session3->IsClosed()); | 197 EXPECT_FALSE(session3->IsClosed()); |
203 | 198 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 | 243 |
249 // Set up a SpdyStream to create a new session when it is closed. | 244 // Set up a SpdyStream to create a new session when it is closed. |
250 // CloseAllSessions should close the newly-created session. | 245 // CloseAllSessions should close the newly-created session. |
251 TEST_P(SpdySessionPoolTest, CloseAllSessions) { | 246 TEST_P(SpdySessionPoolTest, CloseAllSessions) { |
252 const char kTestHost[] = "www.foo.com"; | 247 const char kTestHost[] = "www.foo.com"; |
253 const int kTestPort = 80; | 248 const int kTestPort = 80; |
254 | 249 |
255 session_deps_.host_resolver->set_synchronous_mode(true); | 250 session_deps_.host_resolver->set_synchronous_mode(true); |
256 | 251 |
257 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 252 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
258 SpdySessionKey test_key = | 253 SpdySessionKey test_key = SpdySessionKey( |
259 SpdySessionKey( | 254 test_host_port_pair, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
260 test_host_port_pair, ProxyServer::Direct(), | |
261 PRIVACY_MODE_DISABLED); | |
262 | 255 |
263 MockConnect connect_data(SYNCHRONOUS, OK); | 256 MockConnect connect_data(SYNCHRONOUS, OK); |
264 MockRead reads[] = { | 257 MockRead reads[] = { |
265 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 258 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
266 }; | 259 }; |
267 | 260 |
268 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 261 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
269 data.set_connect_data(connect_data); | 262 data.set_connect_data(connect_data); |
270 session_deps_.socket_factory->AddSocketDataProvider(&data); | 263 session_deps_.socket_factory->AddSocketDataProvider(&data); |
271 | 264 |
272 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 265 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
273 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 266 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
274 | 267 |
275 CreateNetworkSession(); | 268 CreateNetworkSession(); |
276 | 269 |
277 // Setup the first session to the first host. | 270 // Setup the first session to the first host. |
278 base::WeakPtr<SpdySession> session = | 271 base::WeakPtr<SpdySession> session = |
279 CreateInsecureSpdySession(http_session_, test_key, BoundNetLog()); | 272 CreateInsecureSpdySession(http_session_, test_key, BoundNetLog()); |
280 | 273 |
281 // Flush the SpdySession::OnReadComplete() task. | 274 // Flush the SpdySession::OnReadComplete() task. |
282 base::MessageLoop::current()->RunUntilIdle(); | 275 base::MessageLoop::current()->RunUntilIdle(); |
283 | 276 |
284 // Verify that we have sessions for everything. | 277 // Verify that we have sessions for everything. |
285 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); | 278 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_key)); |
286 | 279 |
287 // Set the stream to create a new session when it is closed. | 280 // Set the stream to create a new session when it is closed. |
288 base::WeakPtr<SpdyStream> spdy_stream = | 281 base::WeakPtr<SpdyStream> spdy_stream = |
289 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 282 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, |
290 session, GURL("http://www.foo.com"), | 283 session, |
291 MEDIUM, BoundNetLog()); | 284 GURL("http://www.foo.com"), |
| 285 MEDIUM, |
| 286 BoundNetLog()); |
292 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); | 287 SessionOpeningDelegate delegate(spdy_session_pool_, test_key); |
293 spdy_stream->SetDelegate(&delegate); | 288 spdy_stream->SetDelegate(&delegate); |
294 | 289 |
295 // Close the current session. | 290 // Close the current session. |
296 spdy_session_pool_->CloseAllSessions(); | 291 spdy_session_pool_->CloseAllSessions(); |
297 | 292 |
298 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_key)); | 293 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_key)); |
299 } | 294 } |
300 | 295 |
301 // This test has three variants, one for each style of closing the connection. | 296 // This test has three variants, one for each style of closing the connection. |
302 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_SESSIONS_MANUALLY, | 297 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_SESSIONS_MANUALLY, |
303 // the sessions are closed manually, calling SpdySessionPool::Remove() directly. | 298 // the sessions are closed manually, calling SpdySessionPool::Remove() directly. |
304 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_CURRENT_SESSIONS, | 299 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_CURRENT_SESSIONS, |
305 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). | 300 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). |
306 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_IDLE_SESSIONS, | 301 // If |clean_via_close_current_sessions| is SPDY_POOL_CLOSE_IDLE_SESSIONS, |
307 // sessions are closed with SpdySessionPool::CloseIdleSessions(). | 302 // sessions are closed with SpdySessionPool::CloseIdleSessions(). |
308 void SpdySessionPoolTest::RunIPPoolingTest( | 303 void SpdySessionPoolTest::RunIPPoolingTest( |
309 SpdyPoolCloseSessionsType close_sessions_type) { | 304 SpdyPoolCloseSessionsType close_sessions_type) { |
310 const int kTestPort = 80; | 305 const int kTestPort = 80; |
311 struct TestHosts { | 306 struct TestHosts { |
312 std::string url; | 307 std::string url; |
313 std::string name; | 308 std::string name; |
314 std::string iplist; | 309 std::string iplist; |
315 SpdySessionKey key; | 310 SpdySessionKey key; |
316 AddressList addresses; | 311 AddressList addresses; |
317 } test_hosts[] = { | 312 } test_hosts[] = { |
318 { "http:://www.foo.com", | 313 {"http:://www.foo.com", "www.foo.com", |
319 "www.foo.com", | 314 "192.0.2.33,192.168.0.1,192.168.0.5"}, |
320 "192.0.2.33,192.168.0.1,192.168.0.5" | 315 {"http://js.foo.com", "js.foo.com", |
321 }, | 316 "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33"}, |
322 { "http://js.foo.com", | 317 {"http://images.foo.com", "images.foo.com", "192.168.0.4,192.168.0.3"}, |
323 "js.foo.com", | 318 }; |
324 "192.168.0.2,192.168.0.3,192.168.0.5,192.0.2.33" | |
325 }, | |
326 { "http://images.foo.com", | |
327 "images.foo.com", | |
328 "192.168.0.4,192.168.0.3" | |
329 }, | |
330 }; | |
331 | 319 |
332 session_deps_.host_resolver->set_synchronous_mode(true); | 320 session_deps_.host_resolver->set_synchronous_mode(true); |
333 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { | 321 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_hosts); i++) { |
334 session_deps_.host_resolver->rules()->AddIPLiteralRule( | 322 session_deps_.host_resolver->rules()->AddIPLiteralRule( |
335 test_hosts[i].name, test_hosts[i].iplist, std::string()); | 323 test_hosts[i].name, test_hosts[i].iplist, std::string()); |
336 | 324 |
337 // This test requires that the HostResolver cache be populated. Normal | 325 // This test requires that the HostResolver cache be populated. Normal |
338 // code would have done this already, but we do it manually. | 326 // code would have done this already, but we do it manually. |
339 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); | 327 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); |
340 session_deps_.host_resolver->Resolve(info, | 328 session_deps_.host_resolver->Resolve(info, |
341 DEFAULT_PRIORITY, | 329 DEFAULT_PRIORITY, |
342 &test_hosts[i].addresses, | 330 &test_hosts[i].addresses, |
343 CompletionCallback(), | 331 CompletionCallback(), |
344 NULL, | 332 NULL, |
345 BoundNetLog()); | 333 BoundNetLog()); |
346 | 334 |
347 // Setup a SpdySessionKey | 335 // Setup a SpdySessionKey |
348 test_hosts[i].key = SpdySessionKey( | 336 test_hosts[i].key = |
349 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct(), | 337 SpdySessionKey(HostPortPair(test_hosts[i].name, kTestPort), |
350 PRIVACY_MODE_DISABLED); | 338 ProxyServer::Direct(), |
| 339 PRIVACY_MODE_DISABLED); |
351 } | 340 } |
352 | 341 |
353 MockConnect connect_data(SYNCHRONOUS, OK); | 342 MockConnect connect_data(SYNCHRONOUS, OK); |
354 MockRead reads[] = { | 343 MockRead reads[] = { |
355 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 344 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
356 }; | 345 }; |
357 | 346 |
358 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 347 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
359 data.set_connect_data(connect_data); | 348 data.set_connect_data(connect_data); |
360 session_deps_.socket_factory->AddSocketDataProvider(&data); | 349 session_deps_.socket_factory->AddSocketDataProvider(&data); |
361 | 350 |
362 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 351 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
363 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); | 352 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
364 | 353 |
365 CreateNetworkSession(); | 354 CreateNetworkSession(); |
366 | 355 |
367 // Setup the first session to the first host. | 356 // Setup the first session to the first host. |
368 base::WeakPtr<SpdySession> session = | 357 base::WeakPtr<SpdySession> session = CreateInsecureSpdySession( |
369 CreateInsecureSpdySession( | 358 http_session_, test_hosts[0].key, BoundNetLog()); |
370 http_session_, test_hosts[0].key, BoundNetLog()); | |
371 | 359 |
372 // Flush the SpdySession::OnReadComplete() task. | 360 // Flush the SpdySession::OnReadComplete() task. |
373 base::MessageLoop::current()->RunUntilIdle(); | 361 base::MessageLoop::current()->RunUntilIdle(); |
374 | 362 |
375 // The third host has no overlap with the first, so it can't pool IPs. | 363 // The third host has no overlap with the first, so it can't pool IPs. |
376 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 364 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
377 | 365 |
378 // The second host overlaps with the first, and should IP pool. | 366 // The second host overlaps with the first, and should IP pool. |
379 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 367 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
380 | 368 |
381 // Verify that the second host, through a proxy, won't share the IP. | 369 // Verify that the second host, through a proxy, won't share the IP. |
382 SpdySessionKey proxy_key(test_hosts[1].key.host_port_pair(), | 370 SpdySessionKey proxy_key( |
| 371 test_hosts[1].key.host_port_pair(), |
383 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), | 372 ProxyServer::FromPacString("HTTP http://proxy.foo.com/"), |
384 PRIVACY_MODE_DISABLED); | 373 PRIVACY_MODE_DISABLED); |
385 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); | 374 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, proxy_key)); |
386 | 375 |
387 // Overlap between 2 and 3 does is not transitive to 1. | 376 // Overlap between 2 and 3 does is not transitive to 1. |
388 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 377 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
389 | 378 |
390 // Create a new session to host 2. | 379 // Create a new session to host 2. |
391 session_deps_.socket_factory->AddSocketDataProvider(&data); | 380 session_deps_.socket_factory->AddSocketDataProvider(&data); |
392 base::WeakPtr<SpdySession> session2 = | 381 base::WeakPtr<SpdySession> session2 = CreateInsecureSpdySession( |
393 CreateInsecureSpdySession( | 382 http_session_, test_hosts[2].key, BoundNetLog()); |
394 http_session_, test_hosts[2].key, BoundNetLog()); | |
395 | 383 |
396 // Verify that we have sessions for everything. | 384 // Verify that we have sessions for everything. |
397 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); | 385 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); |
398 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 386 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
399 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); | 387 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); |
400 | 388 |
401 // Grab the session to host 1 and verify that it is the same session | 389 // Grab the session to host 1 and verify that it is the same session |
402 // we got with host 0, and that is a different from host 2's session. | 390 // we got with host 0, and that is a different from host 2's session. |
403 base::WeakPtr<SpdySession> session1 = | 391 base::WeakPtr<SpdySession> session1 = |
404 spdy_session_pool_->FindAvailableSession( | 392 spdy_session_pool_->FindAvailableSession(test_hosts[1].key, |
405 test_hosts[1].key, BoundNetLog()); | 393 BoundNetLog()); |
406 EXPECT_EQ(session.get(), session1.get()); | 394 EXPECT_EQ(session.get(), session1.get()); |
407 EXPECT_NE(session2.get(), session1.get()); | 395 EXPECT_NE(session2.get(), session1.get()); |
408 | 396 |
409 // Remove the aliases and observe that we still have a session for host1. | 397 // Remove the aliases and observe that we still have a session for host1. |
410 SpdySessionPoolPeer pool_peer(spdy_session_pool_); | 398 SpdySessionPoolPeer pool_peer(spdy_session_pool_); |
411 pool_peer.RemoveAliases(test_hosts[0].key); | 399 pool_peer.RemoveAliases(test_hosts[0].key); |
412 pool_peer.RemoveAliases(test_hosts[1].key); | 400 pool_peer.RemoveAliases(test_hosts[1].key); |
413 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 401 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
414 | 402 |
415 // Expire the host cache | 403 // Expire the host cache |
416 session_deps_.host_resolver->GetHostCache()->clear(); | 404 session_deps_.host_resolver->GetHostCache()->clear(); |
417 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); | 405 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); |
418 | 406 |
419 // Cleanup the sessions. | 407 // Cleanup the sessions. |
420 switch (close_sessions_type) { | 408 switch (close_sessions_type) { |
421 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: | 409 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: |
422 session->CloseSessionOnError(ERR_ABORTED, std::string()); | 410 session->CloseSessionOnError(ERR_ABORTED, std::string()); |
423 EXPECT_TRUE(session == NULL); | 411 EXPECT_TRUE(session == NULL); |
424 session2->CloseSessionOnError(ERR_ABORTED, std::string()); | 412 session2->CloseSessionOnError(ERR_ABORTED, std::string()); |
425 EXPECT_TRUE(session2 == NULL); | 413 EXPECT_TRUE(session2 == NULL); |
426 break; | 414 break; |
427 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: | 415 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: |
428 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 416 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
429 break; | 417 break; |
430 case SPDY_POOL_CLOSE_IDLE_SESSIONS: | 418 case SPDY_POOL_CLOSE_IDLE_SESSIONS: |
431 GURL url(test_hosts[0].url); | 419 GURL url(test_hosts[0].url); |
432 base::WeakPtr<SpdyStream> spdy_stream = | 420 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
433 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 421 SPDY_BIDIRECTIONAL_STREAM, session, url, MEDIUM, BoundNetLog()); |
434 session, url, MEDIUM, BoundNetLog()); | |
435 GURL url1(test_hosts[1].url); | 422 GURL url1(test_hosts[1].url); |
436 base::WeakPtr<SpdyStream> spdy_stream1 = | 423 base::WeakPtr<SpdyStream> spdy_stream1 = CreateStreamSynchronously( |
437 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 424 SPDY_BIDIRECTIONAL_STREAM, session1, url1, MEDIUM, BoundNetLog()); |
438 session1, url1, MEDIUM, BoundNetLog()); | |
439 GURL url2(test_hosts[2].url); | 425 GURL url2(test_hosts[2].url); |
440 base::WeakPtr<SpdyStream> spdy_stream2 = | 426 base::WeakPtr<SpdyStream> spdy_stream2 = CreateStreamSynchronously( |
441 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 427 SPDY_BIDIRECTIONAL_STREAM, session2, url2, MEDIUM, BoundNetLog()); |
442 session2, url2, MEDIUM, BoundNetLog()); | |
443 | 428 |
444 // Close streams to make spdy_session and spdy_session1 inactive. | 429 // Close streams to make spdy_session and spdy_session1 inactive. |
445 session->CloseCreatedStream(spdy_stream, OK); | 430 session->CloseCreatedStream(spdy_stream, OK); |
446 EXPECT_EQ(NULL, spdy_stream.get()); | 431 EXPECT_EQ(NULL, spdy_stream.get()); |
447 session1->CloseCreatedStream(spdy_stream1, OK); | 432 session1->CloseCreatedStream(spdy_stream1, OK); |
448 EXPECT_EQ(NULL, spdy_stream1.get()); | 433 EXPECT_EQ(NULL, spdy_stream1.get()); |
449 | 434 |
450 // Check spdy_session and spdy_session1 are not closed. | 435 // Check spdy_session and spdy_session1 are not closed. |
451 EXPECT_FALSE(session->is_active()); | 436 EXPECT_FALSE(session->is_active()); |
452 EXPECT_FALSE(session->IsClosed()); | 437 EXPECT_FALSE(session->IsClosed()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
488 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); | 473 RunIPPoolingTest(SPDY_POOL_CLOSE_CURRENT_SESSIONS); |
489 } | 474 } |
490 | 475 |
491 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { | 476 TEST_P(SpdySessionPoolTest, IPPoolingCloseIdleSessions) { |
492 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); | 477 RunIPPoolingTest(SPDY_POOL_CLOSE_IDLE_SESSIONS); |
493 } | 478 } |
494 | 479 |
495 } // namespace | 480 } // namespace |
496 | 481 |
497 } // namespace net | 482 } // namespace net |
OLD | NEW |