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

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

Issue 2007373004: Fix test expectations to use bool checks rather than null compares (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_network_transaction_unittest.cc ('k') | net/spdy/spdy_session_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) 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 const std::string kTestHost1("http://www.a.com"); 157 const std::string kTestHost1("http://www.a.com");
158 HostPortPair test_host_port_pair1(kTestHost1, 80); 158 HostPortPair test_host_port_pair1(kTestHost1, 80);
159 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(), 159 SpdySessionKey key1(test_host_port_pair1, ProxyServer::Direct(),
160 PRIVACY_MODE_DISABLED); 160 PRIVACY_MODE_DISABLED);
161 base::WeakPtr<SpdySession> session1 = 161 base::WeakPtr<SpdySession> session1 =
162 CreateInsecureSpdySession(http_session_.get(), key1, BoundNetLog()); 162 CreateInsecureSpdySession(http_session_.get(), key1, BoundNetLog());
163 GURL url1(kTestHost1); 163 GURL url1(kTestHost1);
164 base::WeakPtr<SpdyStream> spdy_stream1 = 164 base::WeakPtr<SpdyStream> spdy_stream1 =
165 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 165 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
166 session1, url1, MEDIUM, BoundNetLog()); 166 session1, url1, MEDIUM, BoundNetLog());
167 ASSERT_TRUE(spdy_stream1.get() != NULL); 167 ASSERT_TRUE(spdy_stream1);
168 168
169 // Set up session 2 169 // Set up session 2
170 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0); 170 StaticSocketDataProvider data2(reads, arraysize(reads), nullptr, 0);
171 data2.set_connect_data(connect_data); 171 data2.set_connect_data(connect_data);
172 session_deps_.socket_factory->AddSocketDataProvider(&data2); 172 session_deps_.socket_factory->AddSocketDataProvider(&data2);
173 const std::string kTestHost2("http://www.b.com"); 173 const std::string kTestHost2("http://www.b.com");
174 HostPortPair test_host_port_pair2(kTestHost2, 80); 174 HostPortPair test_host_port_pair2(kTestHost2, 80);
175 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(), 175 SpdySessionKey key2(test_host_port_pair2, ProxyServer::Direct(),
176 PRIVACY_MODE_DISABLED); 176 PRIVACY_MODE_DISABLED);
177 base::WeakPtr<SpdySession> session2 = 177 base::WeakPtr<SpdySession> session2 =
178 CreateInsecureSpdySession(http_session_.get(), key2, BoundNetLog()); 178 CreateInsecureSpdySession(http_session_.get(), key2, BoundNetLog());
179 GURL url2(kTestHost2); 179 GURL url2(kTestHost2);
180 base::WeakPtr<SpdyStream> spdy_stream2 = 180 base::WeakPtr<SpdyStream> spdy_stream2 =
181 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 181 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
182 session2, url2, MEDIUM, BoundNetLog()); 182 session2, url2, MEDIUM, BoundNetLog());
183 ASSERT_TRUE(spdy_stream2.get() != NULL); 183 ASSERT_TRUE(spdy_stream2);
184 184
185 // Set up session 3 185 // Set up session 3
186 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0); 186 StaticSocketDataProvider data3(reads, arraysize(reads), nullptr, 0);
187 data3.set_connect_data(connect_data); 187 data3.set_connect_data(connect_data);
188 session_deps_.socket_factory->AddSocketDataProvider(&data3); 188 session_deps_.socket_factory->AddSocketDataProvider(&data3);
189 const std::string kTestHost3("http://www.c.com"); 189 const std::string kTestHost3("http://www.c.com");
190 HostPortPair test_host_port_pair3(kTestHost3, 80); 190 HostPortPair test_host_port_pair3(kTestHost3, 80);
191 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(), 191 SpdySessionKey key3(test_host_port_pair3, ProxyServer::Direct(),
192 PRIVACY_MODE_DISABLED); 192 PRIVACY_MODE_DISABLED);
193 base::WeakPtr<SpdySession> session3 = 193 base::WeakPtr<SpdySession> session3 =
194 CreateInsecureSpdySession(http_session_.get(), key3, BoundNetLog()); 194 CreateInsecureSpdySession(http_session_.get(), key3, BoundNetLog());
195 GURL url3(kTestHost3); 195 GURL url3(kTestHost3);
196 base::WeakPtr<SpdyStream> spdy_stream3 = 196 base::WeakPtr<SpdyStream> spdy_stream3 =
197 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 197 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
198 session3, url3, MEDIUM, BoundNetLog()); 198 session3, url3, MEDIUM, BoundNetLog());
199 ASSERT_TRUE(spdy_stream3.get() != NULL); 199 ASSERT_TRUE(spdy_stream3);
200 200
201 // All sessions are active and not closed 201 // All sessions are active and not closed
202 EXPECT_TRUE(session1->is_active()); 202 EXPECT_TRUE(session1->is_active());
203 EXPECT_TRUE(session1->IsAvailable()); 203 EXPECT_TRUE(session1->IsAvailable());
204 EXPECT_TRUE(session2->is_active()); 204 EXPECT_TRUE(session2->is_active());
205 EXPECT_TRUE(session2->IsAvailable()); 205 EXPECT_TRUE(session2->IsAvailable());
206 EXPECT_TRUE(session3->is_active()); 206 EXPECT_TRUE(session3->is_active());
207 EXPECT_TRUE(session3->IsAvailable()); 207 EXPECT_TRUE(session3->IsAvailable());
208 208
209 // Should not do anything, all are active 209 // Should not do anything, all are active
210 spdy_session_pool_->CloseCurrentIdleSessions(); 210 spdy_session_pool_->CloseCurrentIdleSessions();
211 EXPECT_TRUE(session1->is_active()); 211 EXPECT_TRUE(session1->is_active());
212 EXPECT_TRUE(session1->IsAvailable()); 212 EXPECT_TRUE(session1->IsAvailable());
213 EXPECT_TRUE(session2->is_active()); 213 EXPECT_TRUE(session2->is_active());
214 EXPECT_TRUE(session2->IsAvailable()); 214 EXPECT_TRUE(session2->IsAvailable());
215 EXPECT_TRUE(session3->is_active()); 215 EXPECT_TRUE(session3->is_active());
216 EXPECT_TRUE(session3->IsAvailable()); 216 EXPECT_TRUE(session3->IsAvailable());
217 217
218 // Make sessions 1 and 3 inactive, but keep them open. 218 // Make sessions 1 and 3 inactive, but keep them open.
219 // Session 2 still open and active 219 // Session 2 still open and active
220 session1->CloseCreatedStream(spdy_stream1, OK); 220 session1->CloseCreatedStream(spdy_stream1, OK);
221 EXPECT_EQ(NULL, spdy_stream1.get()); 221 EXPECT_FALSE(spdy_stream1);
222 session3->CloseCreatedStream(spdy_stream3, OK); 222 session3->CloseCreatedStream(spdy_stream3, OK);
223 EXPECT_EQ(NULL, spdy_stream3.get()); 223 EXPECT_FALSE(spdy_stream3);
224 EXPECT_FALSE(session1->is_active()); 224 EXPECT_FALSE(session1->is_active());
225 EXPECT_TRUE(session1->IsAvailable()); 225 EXPECT_TRUE(session1->IsAvailable());
226 EXPECT_TRUE(session2->is_active()); 226 EXPECT_TRUE(session2->is_active());
227 EXPECT_TRUE(session2->IsAvailable()); 227 EXPECT_TRUE(session2->IsAvailable());
228 EXPECT_FALSE(session3->is_active()); 228 EXPECT_FALSE(session3->is_active());
229 EXPECT_TRUE(session3->IsAvailable()); 229 EXPECT_TRUE(session3->IsAvailable());
230 230
231 // Should close session 1 and 3, 2 should be left open 231 // Should close session 1 and 3, 2 should be left open
232 spdy_session_pool_->CloseCurrentIdleSessions(); 232 spdy_session_pool_->CloseCurrentIdleSessions();
233 base::MessageLoop::current()->RunUntilIdle(); 233 base::MessageLoop::current()->RunUntilIdle();
234 234
235 EXPECT_TRUE(session1 == NULL); 235 EXPECT_FALSE(session1);
236 EXPECT_TRUE(session2->is_active()); 236 EXPECT_TRUE(session2->is_active());
237 EXPECT_TRUE(session2->IsAvailable()); 237 EXPECT_TRUE(session2->IsAvailable());
238 EXPECT_TRUE(session3 == NULL); 238 EXPECT_FALSE(session3);
239 239
240 // Should not do anything 240 // Should not do anything
241 spdy_session_pool_->CloseCurrentIdleSessions(); 241 spdy_session_pool_->CloseCurrentIdleSessions();
242 base::MessageLoop::current()->RunUntilIdle(); 242 base::MessageLoop::current()->RunUntilIdle();
243 243
244 EXPECT_TRUE(session2->is_active()); 244 EXPECT_TRUE(session2->is_active());
245 EXPECT_TRUE(session2->IsAvailable()); 245 EXPECT_TRUE(session2->IsAvailable());
246 246
247 // Make 2 not active 247 // Make 2 not active
248 session2->CloseCreatedStream(spdy_stream2, OK); 248 session2->CloseCreatedStream(spdy_stream2, OK);
249 base::MessageLoop::current()->RunUntilIdle(); 249 base::MessageLoop::current()->RunUntilIdle();
250 250
251 EXPECT_EQ(NULL, spdy_stream2.get()); 251 EXPECT_FALSE(spdy_stream2);
252 EXPECT_FALSE(session2->is_active()); 252 EXPECT_FALSE(session2->is_active());
253 EXPECT_TRUE(session2->IsAvailable()); 253 EXPECT_TRUE(session2->IsAvailable());
254 254
255 // This should close session 2 255 // This should close session 2
256 spdy_session_pool_->CloseCurrentIdleSessions(); 256 spdy_session_pool_->CloseCurrentIdleSessions();
257 base::MessageLoop::current()->RunUntilIdle(); 257 base::MessageLoop::current()->RunUntilIdle();
258 258
259 EXPECT_TRUE(session2 == NULL); 259 EXPECT_FALSE(session2);
260 } 260 }
261 261
262 // Set up a SpdyStream to create a new session when it is closed. 262 // Set up a SpdyStream to create a new session when it is closed.
263 // CloseAllSessions should close the newly-created session. 263 // CloseAllSessions should close the newly-created session.
264 TEST_P(SpdySessionPoolTest, CloseAllSessions) { 264 TEST_P(SpdySessionPoolTest, CloseAllSessions) {
265 const char kTestHost[] = "www.foo.com"; 265 const char kTestHost[] = "www.foo.com";
266 const int kTestPort = 80; 266 const int kTestPort = 80;
267 267
268 session_deps_.host_resolver->set_synchronous_mode(true); 268 session_deps_.host_resolver->set_synchronous_mode(true);
269 269
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 // Expire the host cache 428 // Expire the host cache
429 session_deps_.host_resolver->GetHostCache()->clear(); 429 session_deps_.host_resolver->GetHostCache()->clear();
430 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 430 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
431 431
432 // Cleanup the sessions. 432 // Cleanup the sessions.
433 switch (close_sessions_type) { 433 switch (close_sessions_type) {
434 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY: 434 case SPDY_POOL_CLOSE_SESSIONS_MANUALLY:
435 session->CloseSessionOnError(ERR_ABORTED, std::string()); 435 session->CloseSessionOnError(ERR_ABORTED, std::string());
436 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 436 session2->CloseSessionOnError(ERR_ABORTED, std::string());
437 base::MessageLoop::current()->RunUntilIdle(); 437 base::MessageLoop::current()->RunUntilIdle();
438 EXPECT_TRUE(session == NULL); 438 EXPECT_FALSE(session);
439 EXPECT_TRUE(session2 == NULL); 439 EXPECT_FALSE(session2);
440 break; 440 break;
441 case SPDY_POOL_CLOSE_CURRENT_SESSIONS: 441 case SPDY_POOL_CLOSE_CURRENT_SESSIONS:
442 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 442 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
443 break; 443 break;
444 case SPDY_POOL_CLOSE_IDLE_SESSIONS: 444 case SPDY_POOL_CLOSE_IDLE_SESSIONS:
445 GURL url(test_hosts[0].url); 445 GURL url(test_hosts[0].url);
446 base::WeakPtr<SpdyStream> spdy_stream = 446 base::WeakPtr<SpdyStream> spdy_stream =
447 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 447 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
448 session, url, MEDIUM, BoundNetLog()); 448 session, url, MEDIUM, BoundNetLog());
449 GURL url1(test_hosts[1].url); 449 GURL url1(test_hosts[1].url);
450 base::WeakPtr<SpdyStream> spdy_stream1 = 450 base::WeakPtr<SpdyStream> spdy_stream1 =
451 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 451 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
452 session1, url1, MEDIUM, BoundNetLog()); 452 session1, url1, MEDIUM, BoundNetLog());
453 GURL url2(test_hosts[2].url); 453 GURL url2(test_hosts[2].url);
454 base::WeakPtr<SpdyStream> spdy_stream2 = 454 base::WeakPtr<SpdyStream> spdy_stream2 =
455 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 455 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
456 session2, url2, MEDIUM, BoundNetLog()); 456 session2, url2, MEDIUM, BoundNetLog());
457 457
458 // Close streams to make spdy_session and spdy_session1 inactive. 458 // Close streams to make spdy_session and spdy_session1 inactive.
459 session->CloseCreatedStream(spdy_stream, OK); 459 session->CloseCreatedStream(spdy_stream, OK);
460 EXPECT_EQ(NULL, spdy_stream.get()); 460 EXPECT_FALSE(spdy_stream);
461 session1->CloseCreatedStream(spdy_stream1, OK); 461 session1->CloseCreatedStream(spdy_stream1, OK);
462 EXPECT_EQ(NULL, spdy_stream1.get()); 462 EXPECT_FALSE(spdy_stream1);
463 463
464 // Check spdy_session and spdy_session1 are not closed. 464 // Check spdy_session and spdy_session1 are not closed.
465 EXPECT_FALSE(session->is_active()); 465 EXPECT_FALSE(session->is_active());
466 EXPECT_TRUE(session->IsAvailable()); 466 EXPECT_TRUE(session->IsAvailable());
467 EXPECT_FALSE(session1->is_active()); 467 EXPECT_FALSE(session1->is_active());
468 EXPECT_TRUE(session1->IsAvailable()); 468 EXPECT_TRUE(session1->IsAvailable());
469 EXPECT_TRUE(session2->is_active()); 469 EXPECT_TRUE(session2->is_active());
470 EXPECT_TRUE(session2->IsAvailable()); 470 EXPECT_TRUE(session2->IsAvailable());
471 471
472 // Test that calling CloseIdleSessions, does not cause a crash. 472 // Test that calling CloseIdleSessions, does not cause a crash.
473 // http://crbug.com/181400 473 // http://crbug.com/181400
474 spdy_session_pool_->CloseCurrentIdleSessions(); 474 spdy_session_pool_->CloseCurrentIdleSessions();
475 base::MessageLoop::current()->RunUntilIdle(); 475 base::MessageLoop::current()->RunUntilIdle();
476 476
477 // Verify spdy_session and spdy_session1 are closed. 477 // Verify spdy_session and spdy_session1 are closed.
478 EXPECT_TRUE(session == NULL); 478 EXPECT_FALSE(session);
479 EXPECT_TRUE(session1 == NULL); 479 EXPECT_FALSE(session1);
480 EXPECT_TRUE(session2->is_active()); 480 EXPECT_TRUE(session2->is_active());
481 EXPECT_TRUE(session2->IsAvailable()); 481 EXPECT_TRUE(session2->IsAvailable());
482 482
483 spdy_stream2->Cancel(); 483 spdy_stream2->Cancel();
484 EXPECT_EQ(NULL, spdy_stream.get()); 484 EXPECT_FALSE(spdy_stream);
485 EXPECT_EQ(NULL, spdy_stream1.get()); 485 EXPECT_FALSE(spdy_stream1);
486 EXPECT_EQ(NULL, spdy_stream2.get()); 486 EXPECT_FALSE(spdy_stream2);
487 487
488 session2->CloseSessionOnError(ERR_ABORTED, std::string()); 488 session2->CloseSessionOnError(ERR_ABORTED, std::string());
489 base::MessageLoop::current()->RunUntilIdle(); 489 base::MessageLoop::current()->RunUntilIdle();
490 EXPECT_TRUE(session2 == NULL); 490 EXPECT_FALSE(session2);
491 break; 491 break;
492 } 492 }
493 493
494 // Verify that the map is all cleaned up. 494 // Verify that the map is all cleaned up.
495 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key)); 495 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[0].key));
496 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key)); 496 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[1].key));
497 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key)); 497 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, test_hosts[2].key));
498 } 498 }
499 499
500 TEST_P(SpdySessionPoolTest, IPPooling) { 500 TEST_P(SpdySessionPoolTest, IPPooling) {
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. 663 // there is no pushed stream on any sessions owned by |spdy_session_pool_|.
664 base::WeakPtr<SpdySession> session2 = 664 base::WeakPtr<SpdySession> session2 =
665 spdy_session_pool_->FindAvailableSession( 665 spdy_session_pool_->FindAvailableSession(
666 key, GURL("http://news.example.org/foo.html"), BoundNetLog()); 666 key, GURL("http://news.example.org/foo.html"), BoundNetLog());
667 EXPECT_EQ(session.get(), session2.get()); 667 EXPECT_EQ(session.get(), session2.get());
668 668
669 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); 669 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED);
670 } 670 }
671 671
672 } // namespace net 672 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_network_transaction_unittest.cc ('k') | net/spdy/spdy_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698