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

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

Issue 18546008: [SPDY] Use WeakPtr<SpdySession> everywhere but SpdySessionPool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix test, other minor formatting/comment changes Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_session_pool_unittest.cc ('k') | net/spdy/spdy_stream.h » ('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/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 }; 204 };
205 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); 205 DeterministicSocketData data(reads, arraysize(reads), NULL, 0);
206 data.set_connect_data(connect_data); 206 data.set_connect_data(connect_data);
207 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 207 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
208 208
209 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 209 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
210 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 210 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
211 211
212 CreateDeterministicNetworkSession(); 212 CreateDeterministicNetworkSession();
213 213
214 scoped_refptr<SpdySession> session = 214 base::WeakPtr<SpdySession> session =
215 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 215 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
216 216
217 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); 217 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion());
218 218
219 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); 219 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_));
220 220
221 // Read and process the GOAWAY frame. 221 // Read and process the GOAWAY frame.
222 data.RunFor(1); 222 data.RunFor(1);
223 223
224 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 224 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
225 225
226 // TODO(akalin): Once |session| is a WeakPtr, then simply assert 226 EXPECT_TRUE(session == NULL);
227 // that it's NULL here instead.
228 EXPECT_TRUE(session->IsClosed());
229
230 // Delete the session.
231 session = NULL;
232 } 227 }
233 228
234 // A session receiving a GOAWAY frame immediately with no active 229 // A session receiving a GOAWAY frame immediately with no active
235 // streams should then close. 230 // streams should then close.
236 TEST_P(SpdySessionTest, GoAwayImmediatelyWithNoActiveStreams) { 231 TEST_P(SpdySessionTest, GoAwayImmediatelyWithNoActiveStreams) {
237 session_deps_.host_resolver->set_synchronous_mode(true); 232 session_deps_.host_resolver->set_synchronous_mode(true);
238 233
239 MockConnect connect_data(SYNCHRONOUS, OK); 234 MockConnect connect_data(SYNCHRONOUS, OK);
240 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); 235 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1));
241 MockRead reads[] = { 236 MockRead reads[] = {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 DeterministicSocketData data(reads, arraysize(reads), 275 DeterministicSocketData data(reads, arraysize(reads),
281 writes, arraysize(writes)); 276 writes, arraysize(writes));
282 data.set_connect_data(connect_data); 277 data.set_connect_data(connect_data);
283 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 278 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
284 279
285 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 280 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
286 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 281 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
287 282
288 CreateDeterministicNetworkSession(); 283 CreateDeterministicNetworkSession();
289 284
290 scoped_refptr<SpdySession> session = 285 base::WeakPtr<SpdySession> session =
291 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 286 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
292 287
293 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); 288 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion());
294 289
295 GURL url("http://www.google.com"); 290 GURL url("http://www.google.com");
296 base::WeakPtr<SpdyStream> spdy_stream1 = 291 base::WeakPtr<SpdyStream> spdy_stream1 =
297 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 292 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
298 session, url, MEDIUM, BoundNetLog()); 293 session, url, MEDIUM, BoundNetLog());
299 test::StreamDelegateDoNothing delegate1(spdy_stream1); 294 test::StreamDelegateDoNothing delegate1(spdy_stream1);
300 spdy_stream1->SetDelegate(&delegate1); 295 spdy_stream1->SetDelegate(&delegate1);
(...skipping 28 matching lines...) Expand all
329 EXPECT_FALSE(session->IsStreamActive(3)); 324 EXPECT_FALSE(session->IsStreamActive(3));
330 EXPECT_EQ(NULL, spdy_stream2.get()); 325 EXPECT_EQ(NULL, spdy_stream2.get());
331 EXPECT_TRUE(session->IsStreamActive(1)); 326 EXPECT_TRUE(session->IsStreamActive(1));
332 327
333 EXPECT_FALSE(session->IsClosed()); 328 EXPECT_FALSE(session->IsClosed());
334 329
335 // Should close the session. 330 // Should close the session.
336 spdy_stream1->Close(); 331 spdy_stream1->Close();
337 EXPECT_EQ(NULL, spdy_stream1.get()); 332 EXPECT_EQ(NULL, spdy_stream1.get());
338 333
339 // TODO(akalin): Once |session| is a WeakPtr, then simply assert 334 EXPECT_TRUE(session == NULL);
340 // that it's NULL here instead.
341 EXPECT_TRUE(session->IsClosed());
342
343 // Delete the session.
344 session = NULL;
345 } 335 }
346 336
347 // Have a session receive two GOAWAY frames, with the last one causing 337 // Have a session receive two GOAWAY frames, with the last one causing
348 // the last active stream to be closed. The session should then be 338 // the last active stream to be closed. The session should then be
349 // closed after the second GOAWAY frame. 339 // closed after the second GOAWAY frame.
350 TEST_P(SpdySessionTest, GoAwayTwice) { 340 TEST_P(SpdySessionTest, GoAwayTwice) {
351 session_deps_.host_resolver->set_synchronous_mode(true); 341 session_deps_.host_resolver->set_synchronous_mode(true);
352 342
353 MockConnect connect_data(SYNCHRONOUS, OK); 343 MockConnect connect_data(SYNCHRONOUS, OK);
354 scoped_ptr<SpdyFrame> goaway1(spdy_util_.ConstructSpdyGoAway(1)); 344 scoped_ptr<SpdyFrame> goaway1(spdy_util_.ConstructSpdyGoAway(1));
(...skipping 14 matching lines...) Expand all
369 DeterministicSocketData data(reads, arraysize(reads), 359 DeterministicSocketData data(reads, arraysize(reads),
370 writes, arraysize(writes)); 360 writes, arraysize(writes));
371 data.set_connect_data(connect_data); 361 data.set_connect_data(connect_data);
372 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 362 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
373 363
374 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 364 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
375 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 365 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
376 366
377 CreateDeterministicNetworkSession(); 367 CreateDeterministicNetworkSession();
378 368
379 scoped_refptr<SpdySession> session = 369 base::WeakPtr<SpdySession> session =
380 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 370 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
381 371
382 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); 372 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion());
383 373
384 GURL url("http://www.google.com"); 374 GURL url("http://www.google.com");
385 base::WeakPtr<SpdyStream> spdy_stream1 = 375 base::WeakPtr<SpdyStream> spdy_stream1 =
386 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 376 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
387 session, url, MEDIUM, BoundNetLog()); 377 session, url, MEDIUM, BoundNetLog());
388 test::StreamDelegateDoNothing delegate1(spdy_stream1); 378 test::StreamDelegateDoNothing delegate1(spdy_stream1);
389 spdy_stream1->SetDelegate(&delegate1); 379 spdy_stream1->SetDelegate(&delegate1);
(...skipping 28 matching lines...) Expand all
418 EXPECT_FALSE(session->IsStreamActive(3)); 408 EXPECT_FALSE(session->IsStreamActive(3));
419 EXPECT_EQ(NULL, spdy_stream2.get()); 409 EXPECT_EQ(NULL, spdy_stream2.get());
420 EXPECT_TRUE(session->IsStreamActive(1)); 410 EXPECT_TRUE(session->IsStreamActive(1));
421 411
422 EXPECT_FALSE(session->IsClosed()); 412 EXPECT_FALSE(session->IsClosed());
423 413
424 // Read and process the second GOAWAY frame, which should close the 414 // Read and process the second GOAWAY frame, which should close the
425 // session. 415 // session.
426 data.RunFor(1); 416 data.RunFor(1);
427 417
428 // TODO(akalin): Once |session| is a WeakPtr, then simply assert 418 EXPECT_TRUE(session == NULL);
429 // that it's NULL here instead.
430 EXPECT_TRUE(session->IsClosed());
431
432 // Delete the session.
433 session = NULL;
434 } 419 }
435 420
436 // Have a session with active streams receive a GOAWAY frame and then 421 // Have a session with active streams receive a GOAWAY frame and then
437 // close it. It should handle the close properly (i.e., not try to 422 // close it. It should handle the close properly (i.e., not try to
438 // make itself unavailable in its pool twice). 423 // make itself unavailable in its pool twice).
439 TEST_P(SpdySessionTest, GoAwayWithActiveStreamsThenClose) { 424 TEST_P(SpdySessionTest, GoAwayWithActiveStreamsThenClose) {
440 session_deps_.host_resolver->set_synchronous_mode(true); 425 session_deps_.host_resolver->set_synchronous_mode(true);
441 426
442 MockConnect connect_data(SYNCHRONOUS, OK); 427 MockConnect connect_data(SYNCHRONOUS, OK);
443 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); 428 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1));
(...skipping 12 matching lines...) Expand all
456 DeterministicSocketData data(reads, arraysize(reads), 441 DeterministicSocketData data(reads, arraysize(reads),
457 writes, arraysize(writes)); 442 writes, arraysize(writes));
458 data.set_connect_data(connect_data); 443 data.set_connect_data(connect_data);
459 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 444 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
460 445
461 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 446 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
462 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 447 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
463 448
464 CreateDeterministicNetworkSession(); 449 CreateDeterministicNetworkSession();
465 450
466 scoped_refptr<SpdySession> session = 451 base::WeakPtr<SpdySession> session =
467 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 452 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
468 453
469 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); 454 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion());
470 455
471 GURL url("http://www.google.com"); 456 GURL url("http://www.google.com");
472 base::WeakPtr<SpdyStream> spdy_stream1 = 457 base::WeakPtr<SpdyStream> spdy_stream1 =
473 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 458 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
474 session, url, MEDIUM, BoundNetLog()); 459 session, url, MEDIUM, BoundNetLog());
475 test::StreamDelegateDoNothing delegate1(spdy_stream1); 460 test::StreamDelegateDoNothing delegate1(spdy_stream1);
476 spdy_stream1->SetDelegate(&delegate1); 461 spdy_stream1->SetDelegate(&delegate1);
(...skipping 27 matching lines...) Expand all
504 489
505 EXPECT_FALSE(session->IsStreamActive(3)); 490 EXPECT_FALSE(session->IsStreamActive(3));
506 EXPECT_EQ(NULL, spdy_stream2.get()); 491 EXPECT_EQ(NULL, spdy_stream2.get());
507 EXPECT_TRUE(session->IsStreamActive(1)); 492 EXPECT_TRUE(session->IsStreamActive(1));
508 493
509 EXPECT_FALSE(session->IsClosed()); 494 EXPECT_FALSE(session->IsClosed());
510 495
511 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); 496 session->CloseSessionOnError(ERR_ABORTED, "Aborting session");
512 497
513 EXPECT_EQ(NULL, spdy_stream1.get()); 498 EXPECT_EQ(NULL, spdy_stream1.get());
514 EXPECT_TRUE(session->IsClosed()); 499 EXPECT_TRUE(session == NULL);
515
516 // Delete the session.
517 session = NULL;
518 } 500 }
519 501
520 // Try to create a stream after receiving a GOAWAY frame. It should 502 // Try to create a stream after receiving a GOAWAY frame. It should
521 // fail. 503 // fail.
522 TEST_P(SpdySessionTest, CreateStreamAfterGoAway) { 504 TEST_P(SpdySessionTest, CreateStreamAfterGoAway) {
523 const char kStreamUrl[] = "http://www.google.com"; 505 const char kStreamUrl[] = "http://www.google.com";
524 session_deps_.host_resolver->set_synchronous_mode(true); 506 session_deps_.host_resolver->set_synchronous_mode(true);
525 507
526 MockConnect connect_data(SYNCHRONOUS, OK); 508 MockConnect connect_data(SYNCHRONOUS, OK);
527 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); 509 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1));
528 MockRead reads[] = { 510 MockRead reads[] = {
529 CreateMockRead(*goaway, 1), 511 CreateMockRead(*goaway, 1),
530 MockRead(ASYNC, 0, 2) // EOF 512 MockRead(ASYNC, 0, 2) // EOF
531 }; 513 };
532 scoped_ptr<SpdyFrame> req( 514 scoped_ptr<SpdyFrame> req(
533 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); 515 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true));
534 MockWrite writes[] = { 516 MockWrite writes[] = {
535 CreateMockWrite(*req, 0), 517 CreateMockWrite(*req, 0),
536 }; 518 };
537 DeterministicSocketData data(reads, arraysize(reads), 519 DeterministicSocketData data(reads, arraysize(reads),
538 writes, arraysize(writes)); 520 writes, arraysize(writes));
539 data.set_connect_data(connect_data); 521 data.set_connect_data(connect_data);
540 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 522 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
541 523
542 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 524 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
543 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 525 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
544 526
545 CreateDeterministicNetworkSession(); 527 CreateDeterministicNetworkSession();
546 528
547 scoped_refptr<SpdySession> session = 529 base::WeakPtr<SpdySession> session =
548 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 530 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
549 531
550 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); 532 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion());
551 533
552 GURL url(kStreamUrl); 534 GURL url(kStreamUrl);
553 base::WeakPtr<SpdyStream> spdy_stream = 535 base::WeakPtr<SpdyStream> spdy_stream =
554 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 536 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
555 session, url, MEDIUM, BoundNetLog()); 537 session, url, MEDIUM, BoundNetLog());
556 test::StreamDelegateDoNothing delegate(spdy_stream); 538 test::StreamDelegateDoNothing delegate(spdy_stream);
557 spdy_stream->SetDelegate(&delegate); 539 spdy_stream->SetDelegate(&delegate);
(...skipping 17 matching lines...) Expand all
575 557
576 SpdyStreamRequest stream_request; 558 SpdyStreamRequest stream_request;
577 int rv = stream_request.StartRequest( 559 int rv = stream_request.StartRequest(
578 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog(), 560 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog(),
579 CompletionCallback()); 561 CompletionCallback());
580 EXPECT_EQ(ERR_FAILED, rv); 562 EXPECT_EQ(ERR_FAILED, rv);
581 563
582 // Read and process EOF. 564 // Read and process EOF.
583 data.RunFor(1); 565 data.RunFor(1);
584 566
585 // Delete the first session. 567 EXPECT_TRUE(session == NULL);
586 session = NULL;
587 } 568 }
588 569
589 // Receiving a SYN_STREAM frame after a GOAWAY frame should result in 570 // Receiving a SYN_STREAM frame after a GOAWAY frame should result in
590 // the stream being refused. 571 // the stream being refused.
591 TEST_P(SpdySessionTest, SynStreamAfterGoAway) { 572 TEST_P(SpdySessionTest, SynStreamAfterGoAway) {
592 const char kStreamUrl[] = "http://www.google.com"; 573 const char kStreamUrl[] = "http://www.google.com";
593 session_deps_.host_resolver->set_synchronous_mode(true); 574 session_deps_.host_resolver->set_synchronous_mode(true);
594 575
595 MockConnect connect_data(SYNCHRONOUS, OK); 576 MockConnect connect_data(SYNCHRONOUS, OK);
596 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); 577 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1));
(...skipping 15 matching lines...) Expand all
612 DeterministicSocketData data(reads, arraysize(reads), 593 DeterministicSocketData data(reads, arraysize(reads),
613 writes, arraysize(writes)); 594 writes, arraysize(writes));
614 data.set_connect_data(connect_data); 595 data.set_connect_data(connect_data);
615 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 596 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
616 597
617 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 598 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
618 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 599 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
619 600
620 CreateDeterministicNetworkSession(); 601 CreateDeterministicNetworkSession();
621 602
622 scoped_refptr<SpdySession> session = 603 base::WeakPtr<SpdySession> session =
623 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 604 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
624 605
625 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); 606 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion());
626 607
627 GURL url(kStreamUrl); 608 GURL url(kStreamUrl);
628 base::WeakPtr<SpdyStream> spdy_stream = 609 base::WeakPtr<SpdyStream> spdy_stream =
629 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 610 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
630 session, url, MEDIUM, BoundNetLog()); 611 session, url, MEDIUM, BoundNetLog());
631 test::StreamDelegateDoNothing delegate(spdy_stream); 612 test::StreamDelegateDoNothing delegate(spdy_stream);
632 spdy_stream->SetDelegate(&delegate); 613 spdy_stream->SetDelegate(&delegate);
(...skipping 12 matching lines...) Expand all
645 // Read and process the GOAWAY frame. 626 // Read and process the GOAWAY frame.
646 data.RunFor(1); 627 data.RunFor(1);
647 628
648 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 629 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
649 EXPECT_TRUE(session->IsStreamActive(1)); 630 EXPECT_TRUE(session->IsStreamActive(1));
650 631
651 // Read and process the SYN_STREAM frame, the subsequent RST_STREAM, 632 // Read and process the SYN_STREAM frame, the subsequent RST_STREAM,
652 // and EOF. 633 // and EOF.
653 data.RunFor(3); 634 data.RunFor(3);
654 635
655 // Delete the first session. 636 EXPECT_TRUE(session == NULL);
656 session = NULL;
657 } 637 }
658 638
659 TEST_P(SpdySessionTest, ClientPing) { 639 TEST_P(SpdySessionTest, ClientPing) {
660 session_deps_.enable_ping = true; 640 session_deps_.enable_ping = true;
661 session_deps_.host_resolver->set_synchronous_mode(true); 641 session_deps_.host_resolver->set_synchronous_mode(true);
662 642
663 MockConnect connect_data(SYNCHRONOUS, OK); 643 MockConnect connect_data(SYNCHRONOUS, OK);
664 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1)); 644 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1));
665 MockRead reads[] = { 645 MockRead reads[] = {
666 CreateMockRead(*read_ping), 646 CreateMockRead(*read_ping, 1),
667 MockRead(SYNCHRONOUS, 0, 0) // EOF 647 MockRead(ASYNC, 0, 0, 2) // EOF
668 }; 648 };
669 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1)); 649 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1));
670 MockWrite writes[] = { 650 MockWrite writes[] = {
671 CreateMockWrite(*write_ping), 651 CreateMockWrite(*write_ping, 0),
672 }; 652 };
673 StaticSocketDataProvider data( 653 DeterministicSocketData data(
674 reads, arraysize(reads), writes, arraysize(writes)); 654 reads, arraysize(reads), writes, arraysize(writes));
675 data.set_connect_data(connect_data); 655 data.set_connect_data(connect_data);
676 session_deps_.socket_factory->AddSocketDataProvider(&data); 656 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
677 657
678 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 658 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
679 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 659 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
680 660
681 CreateNetworkSession(); 661 CreateDeterministicNetworkSession();
682 662
683 scoped_refptr<SpdySession> session = 663 base::WeakPtr<SpdySession> session =
684 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 664 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
685 665
686 base::WeakPtr<SpdyStream> spdy_stream1 = 666 base::WeakPtr<SpdyStream> spdy_stream1 =
687 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 667 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
688 session, test_url_, MEDIUM, BoundNetLog()); 668 session, test_url_, MEDIUM, BoundNetLog());
689 ASSERT_TRUE(spdy_stream1.get() != NULL); 669 ASSERT_TRUE(spdy_stream1.get() != NULL);
690 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL); 670 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL);
691 spdy_stream1->SetDelegate(&delegate); 671 spdy_stream1->SetDelegate(&delegate);
692 672
693 base::TimeTicks before_ping_time = base::TimeTicks::Now(); 673 base::TimeTicks before_ping_time = base::TimeTicks::Now();
694 674
695 session->set_connection_at_risk_of_loss_time( 675 session->set_connection_at_risk_of_loss_time(
696 base::TimeDelta::FromSeconds(-1)); 676 base::TimeDelta::FromSeconds(-1));
697 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50)); 677 session->set_hung_interval(base::TimeDelta::FromMilliseconds(50));
698 678
699 session->SendPrefacePingIfNoneInFlight(); 679 session->SendPrefacePingIfNoneInFlight();
700 680
701 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose()); 681 data.RunFor(2);
702 682
703 session->CheckPingStatus(before_ping_time); 683 session->CheckPingStatus(before_ping_time);
704 684
705 EXPECT_EQ(0, session->pings_in_flight()); 685 EXPECT_EQ(0, session->pings_in_flight());
706 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); 686 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1));
707 EXPECT_FALSE(session->check_ping_status_pending()); 687 EXPECT_FALSE(session->check_ping_status_pending());
708 EXPECT_GE(session->last_activity_time(), before_ping_time); 688 EXPECT_GE(session->last_activity_time(), before_ping_time);
709 689
690 data.RunFor(1);
691
692 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate.WaitForClose());
693
710 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 694 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
711 695 EXPECT_TRUE(session == NULL);
712 // Delete the first session.
713 session = NULL;
714 } 696 }
715 697
716 TEST_P(SpdySessionTest, ServerPing) { 698 TEST_P(SpdySessionTest, ServerPing) {
717 session_deps_.host_resolver->set_synchronous_mode(true); 699 session_deps_.host_resolver->set_synchronous_mode(true);
718 700
719 MockConnect connect_data(SYNCHRONOUS, OK); 701 MockConnect connect_data(SYNCHRONOUS, OK);
720 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(2)); 702 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(2));
721 MockRead reads[] = { 703 MockRead reads[] = {
722 CreateMockRead(*read_ping), 704 CreateMockRead(*read_ping),
723 MockRead(SYNCHRONOUS, 0, 0) // EOF 705 MockRead(SYNCHRONOUS, 0, 0) // EOF
724 }; 706 };
725 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(2)); 707 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(2));
726 MockWrite writes[] = { 708 MockWrite writes[] = {
727 CreateMockWrite(*write_ping), 709 CreateMockWrite(*write_ping),
728 }; 710 };
729 StaticSocketDataProvider data( 711 StaticSocketDataProvider data(
730 reads, arraysize(reads), writes, arraysize(writes)); 712 reads, arraysize(reads), writes, arraysize(writes));
731 data.set_connect_data(connect_data); 713 data.set_connect_data(connect_data);
732 session_deps_.socket_factory->AddSocketDataProvider(&data); 714 session_deps_.socket_factory->AddSocketDataProvider(&data);
733 715
734 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 716 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
735 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 717 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
736 718
737 CreateNetworkSession(); 719 CreateNetworkSession();
738 720
739 scoped_refptr<SpdySession> session = 721 base::WeakPtr<SpdySession> session =
740 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 722 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
741 723
742 base::WeakPtr<SpdyStream> spdy_stream1 = 724 base::WeakPtr<SpdyStream> spdy_stream1 =
743 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 725 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
744 session, test_url_, MEDIUM, BoundNetLog()); 726 session, test_url_, MEDIUM, BoundNetLog());
745 ASSERT_TRUE(spdy_stream1.get() != NULL); 727 ASSERT_TRUE(spdy_stream1.get() != NULL);
746 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL); 728 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL);
747 spdy_stream1->SetDelegate(&delegate); 729 spdy_stream1->SetDelegate(&delegate);
748 730
749 // Flush the read completion task. 731 // Flush the read completion task.
750 base::MessageLoop::current()->RunUntilIdle(); 732 base::MessageLoop::current()->RunUntilIdle();
751 733
752 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 734 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
753 735
754 // Delete the session. 736 EXPECT_TRUE(session == NULL);
755 session = NULL;
756 EXPECT_EQ(NULL, spdy_stream1.get()); 737 EXPECT_EQ(NULL, spdy_stream1.get());
757 } 738 }
758 739
759 // Cause a ping to be sent out while producing a write. The write loop 740 // Cause a ping to be sent out while producing a write. The write loop
760 // should handle this properly, i.e. another DoWriteLoop task should 741 // should handle this properly, i.e. another DoWriteLoop task should
761 // not be posted. This is a regression test for 742 // not be posted. This is a regression test for
762 // http://crbug.com/261043 . 743 // http://crbug.com/261043 .
763 TEST_P(SpdySessionTest, PingAndWriteLoop) { 744 TEST_P(SpdySessionTest, PingAndWriteLoop) {
764 session_deps_.enable_ping = true; 745 session_deps_.enable_ping = true;
765 session_deps_.time_func = TheNearFuture; 746 session_deps_.time_func = TheNearFuture;
(...skipping 16 matching lines...) Expand all
782 DeterministicSocketData data(reads, arraysize(reads), 763 DeterministicSocketData data(reads, arraysize(reads),
783 writes, arraysize(writes)); 764 writes, arraysize(writes));
784 data.set_connect_data(connect_data); 765 data.set_connect_data(connect_data);
785 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 766 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
786 767
787 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 768 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
788 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 769 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
789 770
790 CreateDeterministicNetworkSession(); 771 CreateDeterministicNetworkSession();
791 772
792 scoped_refptr<SpdySession> session = 773 base::WeakPtr<SpdySession> session =
793 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 774 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
794 775
795 GURL url("http://www.google.com"); 776 GURL url("http://www.google.com");
796 base::WeakPtr<SpdyStream> spdy_stream = 777 base::WeakPtr<SpdyStream> spdy_stream =
797 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 778 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
798 session, url, LOWEST, BoundNetLog()); 779 session, url, LOWEST, BoundNetLog());
799 test::StreamDelegateDoNothing delegate(spdy_stream); 780 test::StreamDelegateDoNothing delegate(spdy_stream);
800 spdy_stream->SetDelegate(&delegate); 781 spdy_stream->SetDelegate(&delegate);
801 782
802 scoped_ptr<SpdyHeaderBlock> headers( 783 scoped_ptr<SpdyHeaderBlock> headers(
803 spdy_util_.ConstructGetHeaderBlock(url.spec())); 784 spdy_util_.ConstructGetHeaderBlock(url.spec()));
804 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); 785 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND);
805 786
806 // Shift time so that a ping will be sent out. 787 // Shift time so that a ping will be sent out.
807 g_time_delta = base::TimeDelta::FromSeconds(11); 788 g_time_delta = base::TimeDelta::FromSeconds(11);
808 789
809 data.RunFor(2); 790 data.RunFor(2);
810 791
811 session->CloseSessionOnError(ERR_ABORTED, "Aborting"); 792 session->CloseSessionOnError(ERR_ABORTED, "Aborting");
812
813 data.RunFor(1);
814 } 793 }
815 794
816 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) { 795 TEST_P(SpdySessionTest, DeleteExpiredPushStreams) {
817 session_deps_.host_resolver->set_synchronous_mode(true); 796 session_deps_.host_resolver->set_synchronous_mode(true);
818 797
819 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 798 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
820 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 799 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
821 session_deps_.time_func = TheNearFuture; 800 session_deps_.time_func = TheNearFuture;
822 801
823 CreateNetworkSession(); 802 CreateNetworkSession();
824 803
825 scoped_refptr<SpdySession> session = 804 base::WeakPtr<SpdySession> session =
826 CreateFakeSpdySession(spdy_session_pool_, key_); 805 CreateFakeSpdySession(spdy_session_pool_, key_);
827 806
828 session->buffered_spdy_framer_.reset( 807 session->buffered_spdy_framer_.reset(
829 new BufferedSpdyFramer(spdy_util_.spdy_version(), false)); 808 new BufferedSpdyFramer(spdy_util_.spdy_version(), false));
830 809
831 // Create the associated stream and add to active streams. 810 // Create the associated stream and add to active streams.
832 scoped_ptr<SpdyHeaderBlock> request_headers( 811 scoped_ptr<SpdyHeaderBlock> request_headers(
833 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/")); 812 spdy_util_.ConstructGetHeaderBlock("http://www.google.com/"));
834 813
835 scoped_ptr<SpdyStream> stream(new SpdyStream(SPDY_REQUEST_RESPONSE_STREAM, 814 scoped_ptr<SpdyStream> stream(new SpdyStream(SPDY_REQUEST_RESPONSE_STREAM,
836 session.get(), 815 session,
837 GURL(), 816 GURL(),
838 DEFAULT_PRIORITY, 817 DEFAULT_PRIORITY,
839 kSpdyStreamInitialWindowSize, 818 kSpdyStreamInitialWindowSize,
840 kSpdyStreamInitialWindowSize, 819 kSpdyStreamInitialWindowSize,
841 session->net_log_)); 820 session->net_log_));
842 stream->SendRequestHeaders(request_headers.Pass(), NO_MORE_DATA_TO_SEND); 821 stream->SendRequestHeaders(request_headers.Pass(), NO_MORE_DATA_TO_SEND);
843 SpdyStream* stream_ptr = stream.get(); 822 SpdyStream* stream_ptr = stream.get();
844 session->InsertCreatedStream(stream.Pass()); 823 session->InsertCreatedStream(stream.Pass());
845 stream = session->ActivateCreatedStream(stream_ptr); 824 stream = session->ActivateCreatedStream(stream_ptr);
846 session->InsertActivatedStream(stream.Pass()); 825 session->InsertActivatedStream(stream.Pass());
(...skipping 19 matching lines...) Expand all
866 spdy_util_.AddUrlToHeaderBlock("http://www.google.com/b.dat", &headers); 845 spdy_util_.AddUrlToHeaderBlock("http://www.google.com/b.dat", &headers);
867 session->in_io_loop_ = true; 846 session->in_io_loop_ = true;
868 session->OnSynStream(4, 1, 0, 0, true, false, headers); 847 session->OnSynStream(4, 1, 0, 0, true, false, headers);
869 session->in_io_loop_ = false; 848 session->in_io_loop_ = false;
870 849
871 // Verify that the second pushed stream evicted the first pushed stream. 850 // Verify that the second pushed stream evicted the first pushed stream.
872 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams()); 851 EXPECT_EQ(1u, session->num_unclaimed_pushed_streams());
873 iter = session->unclaimed_pushed_streams_.find( 852 iter = session->unclaimed_pushed_streams_.find(
874 GURL("http://www.google.com/b.dat")); 853 GURL("http://www.google.com/b.dat"));
875 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter); 854 EXPECT_TRUE(session->unclaimed_pushed_streams_.end() != iter);
876
877 // Delete the session.
878 session = NULL;
879 } 855 }
880 856
881 TEST_P(SpdySessionTest, FailedPing) { 857 TEST_P(SpdySessionTest, FailedPing) {
882 session_deps_.host_resolver->set_synchronous_mode(true); 858 session_deps_.host_resolver->set_synchronous_mode(true);
883 859
884 MockConnect connect_data(SYNCHRONOUS, OK); 860 MockConnect connect_data(SYNCHRONOUS, OK);
885 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1));
886 MockRead reads[] = { 861 MockRead reads[] = {
887 CreateMockRead(*read_ping), 862 MockRead(ASYNC, 0, 0, 0) // EOF
888 MockRead(SYNCHRONOUS, 0, 0) // EOF
889 }; 863 };
890 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1)); 864 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1));
891 MockWrite writes[] = { 865 DeterministicSocketData data(reads, arraysize(reads), NULL, 0);
892 CreateMockWrite(*write_ping),
893 };
894 StaticSocketDataProvider data(
895 reads, arraysize(reads), writes, arraysize(writes));
896 data.set_connect_data(connect_data); 866 data.set_connect_data(connect_data);
897 session_deps_.socket_factory->AddSocketDataProvider(&data); 867 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
898 868
899 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 869 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
900 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 870 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
901 871
902 CreateNetworkSession(); 872 CreateDeterministicNetworkSession();
903 873
904 scoped_refptr<SpdySession> session = 874 base::WeakPtr<SpdySession> session =
905 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 875 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
906 876
907 base::WeakPtr<SpdyStream> spdy_stream1 = 877 base::WeakPtr<SpdyStream> spdy_stream1 =
908 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 878 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
909 session, test_url_, MEDIUM, BoundNetLog()); 879 session, test_url_, MEDIUM, BoundNetLog());
910 ASSERT_TRUE(spdy_stream1.get() != NULL); 880 ASSERT_TRUE(spdy_stream1.get() != NULL);
911 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL); 881 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL);
912 spdy_stream1->SetDelegate(&delegate); 882 spdy_stream1->SetDelegate(&delegate);
913 883
914 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); 884 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0));
915 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); 885 session->set_hung_interval(base::TimeDelta::FromSeconds(0));
916 886
917 // Send a PING frame. 887 // Send a PING frame.
918 session->WritePingFrame(1); 888 session->WritePingFrame(1);
919 EXPECT_LT(0, session->pings_in_flight()); 889 EXPECT_LT(0, session->pings_in_flight());
920 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); 890 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1));
921 EXPECT_TRUE(session->check_ping_status_pending()); 891 EXPECT_TRUE(session->check_ping_status_pending());
922 892
923 // Assert session is not closed. 893 // Assert session is not closed.
924 EXPECT_FALSE(session->IsClosed()); 894 EXPECT_FALSE(session->IsClosed());
925 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); 895 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams());
926 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); 896 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_));
927 897
928 // We set last time we have received any data in 1 sec less than now. 898 // We set last time we have received any data in 1 sec less than now.
929 // CheckPingStatus will trigger timeout because hung interval is zero. 899 // CheckPingStatus will trigger timeout because hung interval is zero.
930 base::TimeTicks now = base::TimeTicks::Now(); 900 base::TimeTicks now = base::TimeTicks::Now();
931 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); 901 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1);
932 session->CheckPingStatus(now); 902 session->CheckPingStatus(now);
933 903
934 EXPECT_TRUE(session->IsClosed()); 904 EXPECT_TRUE(session == NULL);
935 EXPECT_EQ(0u, session->num_active_streams());
936 EXPECT_EQ(0u, session->num_unclaimed_pushed_streams());
937 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 905 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
938 906
939 // Delete the first session. 907 data.RunFor(1);
940 session = NULL;
941 EXPECT_EQ(NULL, spdy_stream1.get()); 908 EXPECT_EQ(NULL, spdy_stream1.get());
942 } 909 }
943 910
944 // Start with max concurrent streams set to 1. Request two streams. Receive a 911 // Start with max concurrent streams set to 1. Request two streams. Receive a
945 // settings frame setting max concurrent streams to 2. Have the callback 912 // settings frame setting max concurrent streams to 2. Have the callback
946 // release the stream, which releases its reference (the last) to the session. 913 // release the stream, which releases its reference (the last) to the session.
947 // Make sure nothing blows up. 914 // Make sure nothing blows up.
948 // http://crbug.com/57331 915 // http://crbug.com/57331
949 TEST_P(SpdySessionTest, OnSettings) { 916 TEST_P(SpdySessionTest, OnSettings) {
950 session_deps_.host_resolver->set_synchronous_mode(true); 917 session_deps_.host_resolver->set_synchronous_mode(true);
951 918
919 const SpdySettingsIds kSpdySettingsIds = SETTINGS_MAX_CONCURRENT_STREAMS;
920
921 SettingsMap initial_settings;
922 const uint32 initial_max_concurrent_streams = 1;
923 initial_settings[kSpdySettingsIds] =
924 SettingsFlagsAndValue(SETTINGS_FLAG_PERSISTED,
925 initial_max_concurrent_streams);
926 scoped_ptr<SpdyFrame> initial_settings_frame(
927 spdy_util_.ConstructSpdySettings(initial_settings));
928 MockWrite writes[] = {
929 CreateMockWrite(*initial_settings_frame, 0),
930 };
931
952 SettingsMap new_settings; 932 SettingsMap new_settings;
953 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS;
954 const uint32 max_concurrent_streams = 2; 933 const uint32 max_concurrent_streams = 2;
955 new_settings[kSpdySettingsIds1] = 934 new_settings[kSpdySettingsIds] =
956 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); 935 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
957 936
958 // Set up the socket so we read a SETTINGS frame that raises max concurrent 937 // Set up the socket so we read a SETTINGS frame that raises max concurrent
959 // streams to 2. 938 // streams to 2.
960 MockConnect connect_data(SYNCHRONOUS, OK);
961 scoped_ptr<SpdyFrame> settings_frame( 939 scoped_ptr<SpdyFrame> settings_frame(
962 spdy_util_.ConstructSpdySettings(new_settings)); 940 spdy_util_.ConstructSpdySettings(new_settings));
963 MockRead reads[] = { 941 MockRead reads[] = {
964 CreateMockRead(*settings_frame), 942 CreateMockRead(*settings_frame, 1),
965 MockRead(SYNCHRONOUS, 0, 0) // EOF 943 MockRead(ASYNC, 0, 2),
966 }; 944 };
967 945
968 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 946 DeterministicSocketData data(
947 reads, arraysize(reads), writes, arraysize(writes));
948 MockConnect connect_data(SYNCHRONOUS, OK);
969 data.set_connect_data(connect_data); 949 data.set_connect_data(connect_data);
970 session_deps_.socket_factory->AddSocketDataProvider(&data); 950 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
971 951
972 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 952 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
973 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 953 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
974 954
975 CreateNetworkSession(); 955 CreateDeterministicNetworkSession();
976 956
977 // Initialize the SpdySetting with 1 max concurrent streams. 957 // Initialize the SpdySetting with 1 max concurrent streams.
978 spdy_session_pool_->http_server_properties()->SetSpdySetting( 958 spdy_session_pool_->http_server_properties()->SetSpdySetting(
979 test_host_port_pair_, 959 test_host_port_pair_,
980 kSpdySettingsIds1, 960 kSpdySettingsIds,
981 SETTINGS_FLAG_PLEASE_PERSIST, 961 SETTINGS_FLAG_PLEASE_PERSIST,
982 1); 962 initial_max_concurrent_streams);
983 963
984 scoped_refptr<SpdySession> session = 964 base::WeakPtr<SpdySession> session =
985 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 965 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
986 966
987 // Create 2 streams. First will succeed. Second will be pending. 967 // Create 2 streams. First will succeed. Second will be pending.
988 base::WeakPtr<SpdyStream> spdy_stream1 = 968 base::WeakPtr<SpdyStream> spdy_stream1 =
989 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 969 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
990 session, test_url_, MEDIUM, BoundNetLog()); 970 session, test_url_, MEDIUM, BoundNetLog());
991 ASSERT_TRUE(spdy_stream1.get() != NULL); 971 ASSERT_TRUE(spdy_stream1.get() != NULL);
992 972
993 StreamReleaserCallback stream_releaser; 973 StreamReleaserCallback stream_releaser;
994 SpdyStreamRequest request; 974 SpdyStreamRequest request;
995 ASSERT_EQ(ERR_IO_PENDING, 975 ASSERT_EQ(ERR_IO_PENDING,
996 request.StartRequest( 976 request.StartRequest(
997 SPDY_BIDIRECTIONAL_STREAM, session, test_url_, MEDIUM, 977 SPDY_BIDIRECTIONAL_STREAM, session, test_url_, MEDIUM,
998 BoundNetLog(), 978 BoundNetLog(),
999 stream_releaser.MakeCallback(&request))); 979 stream_releaser.MakeCallback(&request)));
1000 session = NULL;
1001 980
1002 EXPECT_EQ(ERR_ABORTED, stream_releaser.WaitForResult()); 981 data.RunFor(2);
982
983 EXPECT_EQ(OK, stream_releaser.WaitForResult());
984
985 data.RunFor(1);
986 EXPECT_TRUE(session == NULL);
1003 } 987 }
1004 988
1005 // Start with max concurrent streams set to 1 (that is persisted). Receive a 989 // Start with max concurrent streams set to 1 (that is persisted). Receive a
1006 // settings frame setting max concurrent streams to 2 and which also clears the 990 // settings frame setting max concurrent streams to 2 and which also clears the
1007 // persisted data. Verify that persisted data is correct. 991 // persisted data. Verify that persisted data is correct.
1008 TEST_P(SpdySessionTest, ClearSettings) { 992 TEST_P(SpdySessionTest, ClearSettings) {
1009 session_deps_.host_resolver->set_synchronous_mode(true); 993 session_deps_.host_resolver->set_synchronous_mode(true);
1010 994
995 const SpdySettingsIds kSpdySettingsIds = SETTINGS_MAX_CONCURRENT_STREAMS;
996
997 SettingsMap initial_settings;
998 const uint32 initial_max_concurrent_streams = 1;
999 initial_settings[kSpdySettingsIds] =
1000 SettingsFlagsAndValue(SETTINGS_FLAG_PERSISTED,
1001 initial_max_concurrent_streams);
1002 scoped_ptr<SpdyFrame> initial_settings_frame(
1003 spdy_util_.ConstructSpdySettings(initial_settings));
1004 MockWrite writes[] = {
1005 CreateMockWrite(*initial_settings_frame, 0),
1006 };
1007
1011 SettingsMap new_settings; 1008 SettingsMap new_settings;
1012 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS;
1013 const uint32 max_concurrent_streams = 2; 1009 const uint32 max_concurrent_streams = 2;
1014 new_settings[kSpdySettingsIds1] = 1010 new_settings[kSpdySettingsIds] =
1015 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); 1011 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams);
1016 1012
1017 // Set up the socket so we read a SETTINGS frame that raises max concurrent 1013 // Set up the socket so we read a SETTINGS frame that raises max concurrent
1018 // streams to 2 and clears previously persisted data. 1014 // streams to 2.
1019 MockConnect connect_data(SYNCHRONOUS, OK);
1020 scoped_ptr<SpdyFrame> settings_frame( 1015 scoped_ptr<SpdyFrame> settings_frame(
1021 spdy_util_.ConstructSpdySettings(new_settings)); 1016 spdy_util_.ConstructSpdySettings(new_settings));
1022 uint8 flags = SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS; 1017 uint8 flags = SETTINGS_FLAG_CLEAR_PREVIOUSLY_PERSISTED_SETTINGS;
1023 test::SetFrameFlags(settings_frame.get(), flags, spdy_util_.spdy_version()); 1018 test::SetFrameFlags(settings_frame.get(), flags, spdy_util_.spdy_version());
1024 MockRead reads[] = { 1019 MockRead reads[] = {
1025 CreateMockRead(*settings_frame), 1020 CreateMockRead(*settings_frame, 1),
1026 MockRead(SYNCHRONOUS, 0, 0) // EOF 1021 MockRead(ASYNC, 0, 2),
1027 }; 1022 };
1028 1023
1029 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 1024 DeterministicSocketData data(
1025 reads, arraysize(reads), writes, arraysize(writes));
1026 MockConnect connect_data(SYNCHRONOUS, OK);
1030 data.set_connect_data(connect_data); 1027 data.set_connect_data(connect_data);
1031 session_deps_.socket_factory->AddSocketDataProvider(&data); 1028 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1032 1029
1033 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1030 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1034 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 1031 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1035 1032
1036 CreateNetworkSession(); 1033 CreateDeterministicNetworkSession();
1037 1034
1038 // Initialize the SpdySetting with 1 max concurrent streams. 1035 // Initialize the SpdySetting with 1 max concurrent streams.
1039 spdy_session_pool_->http_server_properties()->SetSpdySetting( 1036 spdy_session_pool_->http_server_properties()->SetSpdySetting(
1040 test_host_port_pair_, 1037 test_host_port_pair_,
1041 kSpdySettingsIds1, 1038 kSpdySettingsIds,
1042 SETTINGS_FLAG_PLEASE_PERSIST, 1039 SETTINGS_FLAG_PLEASE_PERSIST,
1043 1); 1040 initial_max_concurrent_streams);
1044 1041
1045 EXPECT_EQ(1u, spdy_session_pool_->http_server_properties()->GetSpdySettings( 1042 EXPECT_EQ(1u, spdy_session_pool_->http_server_properties()->GetSpdySettings(
1046 test_host_port_pair_).size()); 1043 test_host_port_pair_).size());
1047 1044
1048 scoped_refptr<SpdySession> session = 1045 base::WeakPtr<SpdySession> session =
1049 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1046 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1050 1047
1051 // Create 2 streams. First will succeed. Second will be pending. 1048 // Create 2 streams. First will succeed. Second will be pending.
1052 base::WeakPtr<SpdyStream> spdy_stream1 = 1049 base::WeakPtr<SpdyStream> spdy_stream1 =
1053 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 1050 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
1054 session, test_url_, MEDIUM, BoundNetLog()); 1051 session, test_url_, MEDIUM, BoundNetLog());
1055 ASSERT_TRUE(spdy_stream1.get() != NULL); 1052 ASSERT_TRUE(spdy_stream1.get() != NULL);
1056 1053
1057 StreamReleaserCallback stream_releaser; 1054 StreamReleaserCallback stream_releaser;
1058 1055
1059 SpdyStreamRequest request; 1056 SpdyStreamRequest request;
1060 ASSERT_EQ(ERR_IO_PENDING, 1057 ASSERT_EQ(ERR_IO_PENDING,
1061 request.StartRequest( 1058 request.StartRequest(
1062 SPDY_BIDIRECTIONAL_STREAM, session, test_url_, MEDIUM, 1059 SPDY_BIDIRECTIONAL_STREAM, session, test_url_, MEDIUM,
1063 BoundNetLog(), 1060 BoundNetLog(),
1064 stream_releaser.MakeCallback(&request))); 1061 stream_releaser.MakeCallback(&request)));
1065 1062
1066 EXPECT_EQ(ERR_ABORTED, stream_releaser.WaitForResult()); 1063 data.RunFor(2);
1064
1065 EXPECT_EQ(OK, stream_releaser.WaitForResult());
1067 1066
1068 // Make sure that persisted data is cleared. 1067 // Make sure that persisted data is cleared.
1069 EXPECT_EQ(0u, spdy_session_pool_->http_server_properties()->GetSpdySettings( 1068 EXPECT_EQ(0u, spdy_session_pool_->http_server_properties()->GetSpdySettings(
1070 test_host_port_pair_).size()); 1069 test_host_port_pair_).size());
1071 1070
1072 // Make sure session's max_concurrent_streams is 2. 1071 // Make sure session's max_concurrent_streams is 2.
1073 EXPECT_EQ(2u, session->max_concurrent_streams()); 1072 EXPECT_EQ(2u, session->max_concurrent_streams());
1074 1073
1075 session = NULL; 1074 data.RunFor(1);
1075 EXPECT_TRUE(session == NULL);
1076 } 1076 }
1077 1077
1078 // Start with max concurrent streams set to 1. Request two streams. When the 1078 // Start with max concurrent streams set to 1. Request two streams. When the
1079 // first completes, have the callback close itself, which should trigger the 1079 // first completes, have the callback close itself, which should trigger the
1080 // second stream creation. Then cancel that one immediately. Don't crash. 1080 // second stream creation. Then cancel that one immediately. Don't crash.
1081 // http://crbug.com/63532 1081 // http://crbug.com/63532
1082 TEST_P(SpdySessionTest, CancelPendingCreateStream) { 1082 TEST_P(SpdySessionTest, CancelPendingCreateStream) {
1083 session_deps_.host_resolver->set_synchronous_mode(true); 1083 session_deps_.host_resolver->set_synchronous_mode(true);
1084 1084
1085 MockRead reads[] = { 1085 MockRead reads[] = {
(...skipping 11 matching lines...) Expand all
1097 1097
1098 CreateNetworkSession(); 1098 CreateNetworkSession();
1099 1099
1100 // Initialize the SpdySetting with 1 max concurrent streams. 1100 // Initialize the SpdySetting with 1 max concurrent streams.
1101 spdy_session_pool_->http_server_properties()->SetSpdySetting( 1101 spdy_session_pool_->http_server_properties()->SetSpdySetting(
1102 test_host_port_pair_, 1102 test_host_port_pair_,
1103 SETTINGS_MAX_CONCURRENT_STREAMS, 1103 SETTINGS_MAX_CONCURRENT_STREAMS,
1104 SETTINGS_FLAG_PLEASE_PERSIST, 1104 SETTINGS_FLAG_PLEASE_PERSIST,
1105 1); 1105 1);
1106 1106
1107 scoped_refptr<SpdySession> session = 1107 base::WeakPtr<SpdySession> session =
1108 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1108 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1109 1109
1110 // Create 2 streams. First will succeed. Second will be pending. 1110 // Create 2 streams. First will succeed. Second will be pending.
1111 base::WeakPtr<SpdyStream> spdy_stream1 = 1111 base::WeakPtr<SpdyStream> spdy_stream1 =
1112 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 1112 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
1113 session, test_url_, MEDIUM, BoundNetLog()); 1113 session, test_url_, MEDIUM, BoundNetLog());
1114 ASSERT_TRUE(spdy_stream1.get() != NULL); 1114 ASSERT_TRUE(spdy_stream1.get() != NULL);
1115 1115
1116 // Use scoped_ptr to let us invalidate the memory when we want to, to trigger 1116 // Use scoped_ptr to let us invalidate the memory when we want to, to trigger
1117 // a valgrind error if the callback is invoked when it's not supposed to be. 1117 // a valgrind error if the callback is invoked when it's not supposed to be.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 session_deps_.socket_factory->AddSocketDataProvider(&data); 1175 session_deps_.socket_factory->AddSocketDataProvider(&data);
1176 1176
1177 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1177 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1178 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 1178 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
1179 1179
1180 CreateNetworkSession(); 1180 CreateNetworkSession();
1181 1181
1182 SpdySessionPoolPeer pool_peer(spdy_session_pool_); 1182 SpdySessionPoolPeer pool_peer(spdy_session_pool_);
1183 pool_peer.EnableSendingInitialSettings(true); 1183 pool_peer.EnableSendingInitialSettings(true);
1184 1184
1185 scoped_refptr<SpdySession> session = 1185 base::WeakPtr<SpdySession> session =
1186 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1186 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1187 1187
1188 base::MessageLoop::current()->RunUntilIdle(); 1188 base::MessageLoop::current()->RunUntilIdle();
1189 EXPECT_TRUE(data.at_write_eof()); 1189 EXPECT_TRUE(data.at_write_eof());
1190 } 1190 }
1191 1191
1192 TEST_P(SpdySessionTest, SendSettingsOnNewSession) { 1192 TEST_P(SpdySessionTest, SendSettingsOnNewSession) {
1193 session_deps_.host_resolver->set_synchronous_mode(true); 1193 session_deps_.host_resolver->set_synchronous_mode(true);
1194 1194
1195 MockRead reads[] = { 1195 MockRead reads[] = {
(...skipping 25 matching lines...) Expand all
1221 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 1221 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
1222 1222
1223 CreateNetworkSession(); 1223 CreateNetworkSession();
1224 1224
1225 spdy_session_pool_->http_server_properties()->SetSpdySetting( 1225 spdy_session_pool_->http_server_properties()->SetSpdySetting(
1226 test_host_port_pair_, 1226 test_host_port_pair_,
1227 kSpdySettingsIds1, 1227 kSpdySettingsIds1,
1228 SETTINGS_FLAG_PLEASE_PERSIST, 1228 SETTINGS_FLAG_PLEASE_PERSIST,
1229 kBogusSettingValue); 1229 kBogusSettingValue);
1230 1230
1231 scoped_refptr<SpdySession> session = 1231 base::WeakPtr<SpdySession> session =
1232 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1232 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1233 1233
1234 base::MessageLoop::current()->RunUntilIdle(); 1234 base::MessageLoop::current()->RunUntilIdle();
1235 EXPECT_TRUE(data.at_write_eof()); 1235 EXPECT_TRUE(data.at_write_eof());
1236 } 1236 }
1237 1237
1238 TEST_P(SpdySessionTest, ClearSettingsStorageOnIPAddressChanged) { 1238 TEST_P(SpdySessionTest, ClearSettingsStorageOnIPAddressChanged) {
1239 CreateNetworkSession(); 1239 CreateNetworkSession();
1240 1240
1241 base::WeakPtr<HttpServerProperties> test_http_server_properties = 1241 base::WeakPtr<HttpServerProperties> test_http_server_properties =
(...skipping 23 matching lines...) Expand all
1265 1265
1266 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 1266 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
1267 data.set_connect_data(connect_data); 1267 data.set_connect_data(connect_data);
1268 session_deps_.socket_factory->AddSocketDataProvider(&data); 1268 session_deps_.socket_factory->AddSocketDataProvider(&data);
1269 1269
1270 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1270 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1271 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 1271 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
1272 1272
1273 CreateNetworkSession(); 1273 CreateNetworkSession();
1274 1274
1275 scoped_refptr<SpdySession> session = 1275 base::WeakPtr<SpdySession> session =
1276 CreateInsecureSpdySession(http_session_, key_, log.bound()); 1276 CreateInsecureSpdySession(http_session_, key_, log.bound());
1277 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); 1277 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_));
1278 1278
1279 // Flush the read completion task. 1279 // Flush the read completion task.
1280 base::MessageLoop::current()->RunUntilIdle(); 1280 base::MessageLoop::current()->RunUntilIdle();
1281 1281
1282 net::CapturingNetLog::CapturedEntryList entries; 1282 net::CapturingNetLog::CapturedEntryList entries;
1283 log.GetEntries(&entries); 1283 log.GetEntries(&entries);
1284 EXPECT_LT(0u, entries.size()); 1284 EXPECT_LT(0u, entries.size());
1285 1285
1286 // Check that we logged TYPE_SPDY_SESSION_INITIALIZED correctly. 1286 // Check that we logged TYPE_SPDY_SESSION_INITIALIZED correctly.
1287 int pos = net::ExpectLogContainsSomewhere( 1287 int pos = net::ExpectLogContainsSomewhere(
1288 entries, 0, 1288 entries, 0,
1289 net::NetLog::TYPE_SPDY_SESSION_INITIALIZED, 1289 net::NetLog::TYPE_SPDY_SESSION_INITIALIZED,
1290 net::NetLog::PHASE_NONE); 1290 net::NetLog::PHASE_NONE);
1291 EXPECT_LT(0, pos); 1291 EXPECT_LT(0, pos);
1292 1292
1293 CapturingNetLog::CapturedEntry entry = entries[pos]; 1293 CapturingNetLog::CapturedEntry entry = entries[pos];
1294 NetLog::Source socket_source; 1294 NetLog::Source socket_source;
1295 EXPECT_TRUE(NetLog::Source::FromEventParameters(entry.params.get(), 1295 EXPECT_TRUE(NetLog::Source::FromEventParameters(entry.params.get(),
1296 &socket_source)); 1296 &socket_source));
1297 EXPECT_TRUE(socket_source.IsValid()); 1297 EXPECT_TRUE(socket_source.IsValid());
1298 EXPECT_NE(log.bound().source().id, socket_source.id); 1298 EXPECT_NE(log.bound().source().id, socket_source.id);
1299
1300 session->CloseSessionOnError(ERR_ABORTED, std::string());
1301 } 1299 }
1302 1300
1303 TEST_P(SpdySessionTest, CloseSessionOnError) { 1301 TEST_P(SpdySessionTest, CloseSessionOnError) {
1304 session_deps_.host_resolver->set_synchronous_mode(true); 1302 session_deps_.host_resolver->set_synchronous_mode(true);
1305 1303
1306 MockConnect connect_data(SYNCHRONOUS, OK); 1304 MockConnect connect_data(SYNCHRONOUS, OK);
1307 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); 1305 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway());
1308 MockRead reads[] = { 1306 MockRead reads[] = {
1309 CreateMockRead(*goaway), 1307 CreateMockRead(*goaway),
1310 MockRead(SYNCHRONOUS, 0, 0) // EOF 1308 MockRead(SYNCHRONOUS, 0, 0) // EOF
1311 }; 1309 };
1312 1310
1313 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 1311 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
1314 data.set_connect_data(connect_data); 1312 data.set_connect_data(connect_data);
1315 session_deps_.socket_factory->AddSocketDataProvider(&data); 1313 session_deps_.socket_factory->AddSocketDataProvider(&data);
1316 1314
1317 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1315 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1318 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 1316 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
1319 1317
1320 CreateNetworkSession(); 1318 CreateNetworkSession();
1321 1319
1322 CapturingBoundNetLog log; 1320 CapturingBoundNetLog log;
1323 scoped_refptr<SpdySession> session = 1321 base::WeakPtr<SpdySession> session =
1324 CreateInsecureSpdySession(http_session_, key_, log.bound()); 1322 CreateInsecureSpdySession(http_session_, key_, log.bound());
1325 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); 1323 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_));
1326 1324
1327 // Flush the read completion task. 1325 // Flush the read completion task.
1328 base::MessageLoop::current()->RunUntilIdle(); 1326 base::MessageLoop::current()->RunUntilIdle();
1329 1327
1330 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 1328 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
1329 EXPECT_TRUE(session == NULL);
1331 1330
1332 // Check that the NetLog was filled reasonably. 1331 // Check that the NetLog was filled reasonably.
1333 net::CapturingNetLog::CapturedEntryList entries; 1332 net::CapturingNetLog::CapturedEntryList entries;
1334 log.GetEntries(&entries); 1333 log.GetEntries(&entries);
1335 EXPECT_LT(0u, entries.size()); 1334 EXPECT_LT(0u, entries.size());
1336 1335
1337 // Check that we logged SPDY_SESSION_CLOSE correctly. 1336 // Check that we logged SPDY_SESSION_CLOSE correctly.
1338 int pos = net::ExpectLogContainsSomewhere( 1337 int pos = net::ExpectLogContainsSomewhere(
1339 entries, 0, 1338 entries, 0,
1340 net::NetLog::TYPE_SPDY_SESSION_CLOSE, 1339 net::NetLog::TYPE_SPDY_SESSION_CLOSE,
1341 net::NetLog::PHASE_NONE); 1340 net::NetLog::PHASE_NONE);
1342 1341
1343 if (pos < static_cast<int>(entries.size())) { 1342 if (pos < static_cast<int>(entries.size())) {
1344 CapturingNetLog::CapturedEntry entry = entries[pos]; 1343 CapturingNetLog::CapturedEntry entry = entries[pos];
1345 int error_code = 0; 1344 int error_code = 0;
1346 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); 1345 ASSERT_TRUE(entry.GetNetErrorCode(&error_code));
1347 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); 1346 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code);
1348 } else { 1347 } else {
1349 ADD_FAILURE(); 1348 ADD_FAILURE();
1350 } 1349 }
1351
1352 // Release the last session reference here so it doesn't try to
1353 // access |log| after its destroyed.
1354 EXPECT_TRUE(session->HasOneRef());
1355 session = NULL;
1356 } 1350 }
1357 1351
1358 // Queue up a low-priority SYN_STREAM followed by a high-priority 1352 // Queue up a low-priority SYN_STREAM followed by a high-priority
1359 // one. The high priority one should still send first and receive 1353 // one. The high priority one should still send first and receive
1360 // first. 1354 // first.
1361 TEST_P(SpdySessionTest, OutOfOrderSynStreams) { 1355 TEST_P(SpdySessionTest, OutOfOrderSynStreams) {
1362 // Construct the request. 1356 // Construct the request.
1363 MockConnect connect_data(SYNCHRONOUS, OK); 1357 MockConnect connect_data(SYNCHRONOUS, OK);
1364 scoped_ptr<SpdyFrame> req_highest( 1358 scoped_ptr<SpdyFrame> req_highest(
1365 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, HIGHEST, true)); 1359 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, HIGHEST, true));
(...skipping 25 matching lines...) Expand all
1391 DeterministicSocketData data(reads, arraysize(reads), 1385 DeterministicSocketData data(reads, arraysize(reads),
1392 writes, arraysize(writes)); 1386 writes, arraysize(writes));
1393 data.set_connect_data(connect_data); 1387 data.set_connect_data(connect_data);
1394 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1388 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1395 1389
1396 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1390 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1397 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1391 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1398 1392
1399 CreateDeterministicNetworkSession(); 1393 CreateDeterministicNetworkSession();
1400 1394
1401 scoped_refptr<SpdySession> session = 1395 base::WeakPtr<SpdySession> session =
1402 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1396 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1403 1397
1404 GURL url("http://www.google.com"); 1398 GURL url("http://www.google.com");
1405 1399
1406 base::WeakPtr<SpdyStream> spdy_stream_lowest = 1400 base::WeakPtr<SpdyStream> spdy_stream_lowest =
1407 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 1401 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
1408 session, url, LOWEST, BoundNetLog()); 1402 session, url, LOWEST, BoundNetLog());
1409 ASSERT_TRUE(spdy_stream_lowest); 1403 ASSERT_TRUE(spdy_stream_lowest);
1410 EXPECT_EQ(0u, spdy_stream_lowest->stream_id()); 1404 EXPECT_EQ(0u, spdy_stream_lowest->stream_id());
1411 test::StreamDelegateDoNothing delegate_lowest(spdy_stream_lowest); 1405 test::StreamDelegateDoNothing delegate_lowest(spdy_stream_lowest);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1464 DeterministicSocketData data(reads, arraysize(reads), 1458 DeterministicSocketData data(reads, arraysize(reads),
1465 writes, arraysize(writes)); 1459 writes, arraysize(writes));
1466 data.set_connect_data(connect_data); 1460 data.set_connect_data(connect_data);
1467 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1461 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1468 1462
1469 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1463 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1470 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1464 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1471 1465
1472 CreateDeterministicNetworkSession(); 1466 CreateDeterministicNetworkSession();
1473 1467
1474 scoped_refptr<SpdySession> session = 1468 base::WeakPtr<SpdySession> session =
1475 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1469 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1476 1470
1477 GURL url1("http://www.google.com"); 1471 GURL url1("http://www.google.com");
1478 base::WeakPtr<SpdyStream> spdy_stream1 = 1472 base::WeakPtr<SpdyStream> spdy_stream1 =
1479 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 1473 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
1480 session, url1, HIGHEST, BoundNetLog()); 1474 session, url1, HIGHEST, BoundNetLog());
1481 ASSERT_TRUE(spdy_stream1.get() != NULL); 1475 ASSERT_TRUE(spdy_stream1.get() != NULL);
1482 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1476 EXPECT_EQ(0u, spdy_stream1->stream_id());
1483 test::StreamDelegateDoNothing delegate1(spdy_stream1); 1477 test::StreamDelegateDoNothing delegate1(spdy_stream1);
1484 spdy_stream1->SetDelegate(&delegate1); 1478 spdy_stream1->SetDelegate(&delegate1);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 DeterministicSocketData data(reads, arraysize(reads), 1531 DeterministicSocketData data(reads, arraysize(reads),
1538 writes, arraysize(writes)); 1532 writes, arraysize(writes));
1539 data.set_connect_data(connect_data); 1533 data.set_connect_data(connect_data);
1540 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1534 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1541 1535
1542 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1536 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1543 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1537 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1544 1538
1545 CreateDeterministicNetworkSession(); 1539 CreateDeterministicNetworkSession();
1546 1540
1547 scoped_refptr<SpdySession> session = 1541 base::WeakPtr<SpdySession> session =
1548 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1542 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1549 1543
1550 GURL url1("http://www.google.com"); 1544 GURL url1("http://www.google.com");
1551 base::WeakPtr<SpdyStream> spdy_stream1 = 1545 base::WeakPtr<SpdyStream> spdy_stream1 =
1552 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 1546 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
1553 session, url1, HIGHEST, BoundNetLog()); 1547 session, url1, HIGHEST, BoundNetLog());
1554 ASSERT_TRUE(spdy_stream1.get() != NULL); 1548 ASSERT_TRUE(spdy_stream1.get() != NULL);
1555 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1549 EXPECT_EQ(0u, spdy_stream1->stream_id());
1556 1550
1557 GURL url2("http://www.google.com"); 1551 GURL url2("http://www.google.com");
(...skipping 25 matching lines...) Expand all
1583 1577
1584 // Ensure we don't crash while closing the session. 1578 // Ensure we don't crash while closing the session.
1585 session->CloseSessionOnError(ERR_ABORTED, std::string()); 1579 session->CloseSessionOnError(ERR_ABORTED, std::string());
1586 1580
1587 EXPECT_EQ(NULL, spdy_stream1.get()); 1581 EXPECT_EQ(NULL, spdy_stream1.get());
1588 EXPECT_EQ(NULL, spdy_stream2.get()); 1582 EXPECT_EQ(NULL, spdy_stream2.get());
1589 1583
1590 EXPECT_TRUE(delegate1.StreamIsClosed()); 1584 EXPECT_TRUE(delegate1.StreamIsClosed());
1591 EXPECT_TRUE(delegate2.StreamIsClosed()); 1585 EXPECT_TRUE(delegate2.StreamIsClosed());
1592 1586
1593 session = NULL; 1587 EXPECT_TRUE(session == NULL);
1594 } 1588 }
1595 1589
1596 // Create two streams that are set to close each other on close, and 1590 // Create two streams that are set to close each other on close, and
1597 // then close the session. Nothing should blow up. 1591 // then close the session. Nothing should blow up.
1598 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedMutuallyClosingStreams) { 1592 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedMutuallyClosingStreams) {
1599 session_deps_.host_resolver->set_synchronous_mode(true); 1593 session_deps_.host_resolver->set_synchronous_mode(true);
1600 1594
1601 MockConnect connect_data(SYNCHRONOUS, OK); 1595 MockConnect connect_data(SYNCHRONOUS, OK);
1602 1596
1603 // No actual data will be sent. 1597 // No actual data will be sent.
1604 MockWrite writes[] = { 1598 MockWrite writes[] = {
1605 MockWrite(ASYNC, 0, 1) // EOF 1599 MockWrite(ASYNC, 0, 1) // EOF
1606 }; 1600 };
1607 1601
1608 MockRead reads[] = { 1602 MockRead reads[] = {
1609 MockRead(ASYNC, 0, 0) // EOF 1603 MockRead(ASYNC, 0, 0) // EOF
1610 }; 1604 };
1611 DeterministicSocketData data(reads, arraysize(reads), 1605 DeterministicSocketData data(reads, arraysize(reads),
1612 writes, arraysize(writes)); 1606 writes, arraysize(writes));
1613 data.set_connect_data(connect_data); 1607 data.set_connect_data(connect_data);
1614 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1608 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1615 1609
1616 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1610 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1617 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1611 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1618 1612
1619 CreateDeterministicNetworkSession(); 1613 CreateDeterministicNetworkSession();
1620 1614
1621 scoped_refptr<SpdySession> session = 1615 base::WeakPtr<SpdySession> session =
1622 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1616 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1623 1617
1624 GURL url1("http://www.google.com"); 1618 GURL url1("http://www.google.com");
1625 base::WeakPtr<SpdyStream> spdy_stream1 = 1619 base::WeakPtr<SpdyStream> spdy_stream1 =
1626 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 1620 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
1627 session, url1, HIGHEST, BoundNetLog()); 1621 session, url1, HIGHEST, BoundNetLog());
1628 ASSERT_TRUE(spdy_stream1.get() != NULL); 1622 ASSERT_TRUE(spdy_stream1.get() != NULL);
1629 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1623 EXPECT_EQ(0u, spdy_stream1->stream_id());
1630 1624
1631 GURL url2("http://www.google.com"); 1625 GURL url2("http://www.google.com");
(...skipping 27 matching lines...) Expand all
1659 1653
1660 // Ensure we don't crash while closing the session. 1654 // Ensure we don't crash while closing the session.
1661 session->CloseSessionOnError(ERR_ABORTED, std::string()); 1655 session->CloseSessionOnError(ERR_ABORTED, std::string());
1662 1656
1663 EXPECT_EQ(NULL, spdy_stream1.get()); 1657 EXPECT_EQ(NULL, spdy_stream1.get());
1664 EXPECT_EQ(NULL, spdy_stream2.get()); 1658 EXPECT_EQ(NULL, spdy_stream2.get());
1665 1659
1666 EXPECT_TRUE(delegate1.StreamIsClosed()); 1660 EXPECT_TRUE(delegate1.StreamIsClosed());
1667 EXPECT_TRUE(delegate2.StreamIsClosed()); 1661 EXPECT_TRUE(delegate2.StreamIsClosed());
1668 1662
1669 session = NULL; 1663 EXPECT_TRUE(session == NULL);
1670 } 1664 }
1671 1665
1672 // Create two streams that are set to re-close themselves on close, 1666 // Create two streams that are set to re-close themselves on close,
1673 // activate them, and then close the session. Nothing should blow up. 1667 // activate them, and then close the session. Nothing should blow up.
1674 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedSelfClosingStreams) { 1668 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedSelfClosingStreams) {
1675 session_deps_.host_resolver->set_synchronous_mode(true); 1669 session_deps_.host_resolver->set_synchronous_mode(true);
1676 1670
1677 MockConnect connect_data(SYNCHRONOUS, OK); 1671 MockConnect connect_data(SYNCHRONOUS, OK);
1678 1672
1679 scoped_ptr<SpdyFrame> req1( 1673 scoped_ptr<SpdyFrame> req1(
(...skipping 12 matching lines...) Expand all
1692 DeterministicSocketData data(reads, arraysize(reads), 1686 DeterministicSocketData data(reads, arraysize(reads),
1693 writes, arraysize(writes)); 1687 writes, arraysize(writes));
1694 data.set_connect_data(connect_data); 1688 data.set_connect_data(connect_data);
1695 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1689 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1696 1690
1697 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1691 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1698 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1692 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1699 1693
1700 CreateDeterministicNetworkSession(); 1694 CreateDeterministicNetworkSession();
1701 1695
1702 scoped_refptr<SpdySession> session = 1696 base::WeakPtr<SpdySession> session =
1703 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1697 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1704 1698
1705 GURL url1("http://www.google.com"); 1699 GURL url1("http://www.google.com");
1706 base::WeakPtr<SpdyStream> spdy_stream1 = 1700 base::WeakPtr<SpdyStream> spdy_stream1 =
1707 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 1701 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
1708 session, url1, MEDIUM, BoundNetLog()); 1702 session, url1, MEDIUM, BoundNetLog());
1709 ASSERT_TRUE(spdy_stream1.get() != NULL); 1703 ASSERT_TRUE(spdy_stream1.get() != NULL);
1710 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1704 EXPECT_EQ(0u, spdy_stream1->stream_id());
1711 1705
1712 GURL url2("http://www.google.com"); 1706 GURL url2("http://www.google.com");
(...skipping 30 matching lines...) Expand all
1743 1737
1744 // Ensure we don't crash while closing the session. 1738 // Ensure we don't crash while closing the session.
1745 session->CloseSessionOnError(ERR_ABORTED, std::string()); 1739 session->CloseSessionOnError(ERR_ABORTED, std::string());
1746 1740
1747 EXPECT_EQ(NULL, spdy_stream1.get()); 1741 EXPECT_EQ(NULL, spdy_stream1.get());
1748 EXPECT_EQ(NULL, spdy_stream2.get()); 1742 EXPECT_EQ(NULL, spdy_stream2.get());
1749 1743
1750 EXPECT_TRUE(delegate1.StreamIsClosed()); 1744 EXPECT_TRUE(delegate1.StreamIsClosed());
1751 EXPECT_TRUE(delegate2.StreamIsClosed()); 1745 EXPECT_TRUE(delegate2.StreamIsClosed());
1752 1746
1753 session = NULL; 1747 EXPECT_TRUE(session == NULL);
1754 } 1748 }
1755 1749
1756 // Create two streams that are set to close each other on close, 1750 // Create two streams that are set to close each other on close,
1757 // activate them, and then close the session. Nothing should blow up. 1751 // activate them, and then close the session. Nothing should blow up.
1758 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedMutuallyClosingStreams) { 1752 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedMutuallyClosingStreams) {
1759 session_deps_.host_resolver->set_synchronous_mode(true); 1753 session_deps_.host_resolver->set_synchronous_mode(true);
1760 1754
1761 MockConnect connect_data(SYNCHRONOUS, OK); 1755 MockConnect connect_data(SYNCHRONOUS, OK);
1762 1756
1763 scoped_ptr<SpdyFrame> req1( 1757 scoped_ptr<SpdyFrame> req1(
(...skipping 12 matching lines...) Expand all
1776 DeterministicSocketData data(reads, arraysize(reads), 1770 DeterministicSocketData data(reads, arraysize(reads),
1777 writes, arraysize(writes)); 1771 writes, arraysize(writes));
1778 data.set_connect_data(connect_data); 1772 data.set_connect_data(connect_data);
1779 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1773 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1780 1774
1781 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1775 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1782 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1776 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1783 1777
1784 CreateDeterministicNetworkSession(); 1778 CreateDeterministicNetworkSession();
1785 1779
1786 scoped_refptr<SpdySession> session = 1780 base::WeakPtr<SpdySession> session =
1787 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1781 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1788 1782
1789 GURL url1("http://www.google.com"); 1783 GURL url1("http://www.google.com");
1790 base::WeakPtr<SpdyStream> spdy_stream1 = 1784 base::WeakPtr<SpdyStream> spdy_stream1 =
1791 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 1785 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
1792 session, url1, MEDIUM, BoundNetLog()); 1786 session, url1, MEDIUM, BoundNetLog());
1793 ASSERT_TRUE(spdy_stream1.get() != NULL); 1787 ASSERT_TRUE(spdy_stream1.get() != NULL);
1794 EXPECT_EQ(0u, spdy_stream1->stream_id()); 1788 EXPECT_EQ(0u, spdy_stream1->stream_id());
1795 1789
1796 GURL url2("http://www.google.com"); 1790 GURL url2("http://www.google.com");
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
1829 1823
1830 // Ensure we don't crash while closing the session. 1824 // Ensure we don't crash while closing the session.
1831 session->CloseSessionOnError(ERR_ABORTED, std::string()); 1825 session->CloseSessionOnError(ERR_ABORTED, std::string());
1832 1826
1833 EXPECT_EQ(NULL, spdy_stream1.get()); 1827 EXPECT_EQ(NULL, spdy_stream1.get());
1834 EXPECT_EQ(NULL, spdy_stream2.get()); 1828 EXPECT_EQ(NULL, spdy_stream2.get());
1835 1829
1836 EXPECT_TRUE(delegate1.StreamIsClosed()); 1830 EXPECT_TRUE(delegate1.StreamIsClosed());
1837 EXPECT_TRUE(delegate2.StreamIsClosed()); 1831 EXPECT_TRUE(delegate2.StreamIsClosed());
1838 1832
1839 session = NULL; 1833 EXPECT_TRUE(session == NULL);
1840 } 1834 }
1841 1835
1842 TEST_P(SpdySessionTest, VerifyDomainAuthentication) { 1836 TEST_P(SpdySessionTest, VerifyDomainAuthentication) {
1843 session_deps_.host_resolver->set_synchronous_mode(true); 1837 session_deps_.host_resolver->set_synchronous_mode(true);
1844 1838
1845 MockConnect connect_data(SYNCHRONOUS, OK); 1839 MockConnect connect_data(SYNCHRONOUS, OK);
1846 1840
1847 // No actual data will be sent. 1841 // No actual data will be sent.
1848 MockWrite writes[] = { 1842 MockWrite writes[] = {
1849 MockWrite(ASYNC, 0, 1) // EOF 1843 MockWrite(ASYNC, 0, 1) // EOF
(...skipping 15 matching lines...) Expand all
1865 scoped_refptr<X509Certificate> test_cert( 1859 scoped_refptr<X509Certificate> test_cert(
1866 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); 1860 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
1867 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); 1861 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
1868 1862
1869 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1863 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1870 ssl.cert = test_cert; 1864 ssl.cert = test_cert;
1871 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1865 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1872 1866
1873 CreateDeterministicNetworkSession(); 1867 CreateDeterministicNetworkSession();
1874 1868
1875 scoped_refptr<SpdySession> session = 1869 base::WeakPtr<SpdySession> session =
1876 CreateSecureSpdySession(http_session_, key_, BoundNetLog()); 1870 CreateSecureSpdySession(http_session_, key_, BoundNetLog());
1877 1871
1878 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); 1872 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org"));
1879 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); 1873 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org"));
1880 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.com")); 1874 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.com"));
1881 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); 1875 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com"));
1882 } 1876 }
1883 1877
1884 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) { 1878 TEST_P(SpdySessionTest, ConnectionPooledWithTlsChannelId) {
1885 session_deps_.host_resolver->set_synchronous_mode(true); 1879 session_deps_.host_resolver->set_synchronous_mode(true);
(...skipping 22 matching lines...) Expand all
1908 ImportCertFromFile(certs_dir, "spdy_pooling.pem")); 1902 ImportCertFromFile(certs_dir, "spdy_pooling.pem"));
1909 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert); 1903 ASSERT_NE(static_cast<X509Certificate*>(NULL), test_cert);
1910 1904
1911 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1905 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1912 ssl.channel_id_sent = true; 1906 ssl.channel_id_sent = true;
1913 ssl.cert = test_cert; 1907 ssl.cert = test_cert;
1914 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1908 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1915 1909
1916 CreateDeterministicNetworkSession(); 1910 CreateDeterministicNetworkSession();
1917 1911
1918 scoped_refptr<SpdySession> session = 1912 base::WeakPtr<SpdySession> session =
1919 CreateSecureSpdySession(http_session_, key_, BoundNetLog()); 1913 CreateSecureSpdySession(http_session_, key_, BoundNetLog());
1920 1914
1921 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org")); 1915 EXPECT_TRUE(session->VerifyDomainAuthentication("www.example.org"));
1922 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org")); 1916 EXPECT_TRUE(session->VerifyDomainAuthentication("mail.example.org"));
1923 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com")); 1917 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.example.com"));
1924 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com")); 1918 EXPECT_FALSE(session->VerifyDomainAuthentication("mail.google.com"));
1925 } 1919 }
1926 1920
1927 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) { 1921 TEST_P(SpdySessionTest, CloseTwoStalledCreateStream) {
1928 // TODO(rtenneti): Define a helper class/methods and move the common code in 1922 // TODO(rtenneti): Define a helper class/methods and move the common code in
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1975 DeterministicSocketData data(reads, arraysize(reads), 1969 DeterministicSocketData data(reads, arraysize(reads),
1976 writes, arraysize(writes)); 1970 writes, arraysize(writes));
1977 data.set_connect_data(connect_data); 1971 data.set_connect_data(connect_data);
1978 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 1972 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
1979 1973
1980 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 1974 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
1981 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 1975 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
1982 1976
1983 CreateDeterministicNetworkSession(); 1977 CreateDeterministicNetworkSession();
1984 1978
1985 scoped_refptr<SpdySession> session = 1979 base::WeakPtr<SpdySession> session =
1986 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 1980 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
1987 1981
1988 // Read the settings frame. 1982 // Read the settings frame.
1989 data.RunFor(1); 1983 data.RunFor(1);
1990 1984
1991 GURL url1("http://www.google.com"); 1985 GURL url1("http://www.google.com");
1992 base::WeakPtr<SpdyStream> spdy_stream1 = 1986 base::WeakPtr<SpdyStream> spdy_stream1 =
1993 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 1987 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
1994 session, url1, LOWEST, BoundNetLog()); 1988 session, url1, LOWEST, BoundNetLog());
1995 ASSERT_TRUE(spdy_stream1.get() != NULL); 1989 ASSERT_TRUE(spdy_stream1.get() != NULL);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 2043
2050 base::WeakPtr<SpdyStream> stream3 = request3.ReleaseStream(); 2044 base::WeakPtr<SpdyStream> stream3 = request3.ReleaseStream();
2051 test::StreamDelegateDoNothing delegate3(stream3); 2045 test::StreamDelegateDoNothing delegate3(stream3);
2052 stream3->SetDelegate(&delegate3); 2046 stream3->SetDelegate(&delegate3);
2053 scoped_ptr<SpdyHeaderBlock> headers3( 2047 scoped_ptr<SpdyHeaderBlock> headers3(
2054 spdy_util_.ConstructGetHeaderBlock(url3.spec())); 2048 spdy_util_.ConstructGetHeaderBlock(url3.spec()));
2055 stream3->SendRequestHeaders(headers3.Pass(), NO_MORE_DATA_TO_SEND); 2049 stream3->SendRequestHeaders(headers3.Pass(), NO_MORE_DATA_TO_SEND);
2056 EXPECT_TRUE(stream3->HasUrlFromHeaders()); 2050 EXPECT_TRUE(stream3->HasUrlFromHeaders());
2057 2051
2058 EXPECT_EQ(0u, delegate3.stream_id()); 2052 EXPECT_EQ(0u, delegate3.stream_id());
2059 data.RunFor(4); 2053 data.RunFor(3);
2060 EXPECT_EQ(NULL, stream3.get()); 2054 EXPECT_EQ(NULL, stream3.get());
2061 EXPECT_EQ(5u, delegate3.stream_id()); 2055 EXPECT_EQ(5u, delegate3.stream_id());
2062 EXPECT_EQ(0u, session->num_active_streams() + session->num_created_streams()); 2056 EXPECT_EQ(0u, session->num_active_streams() + session->num_created_streams());
2063 EXPECT_EQ(0u, session->pending_create_stream_queue_size(LOWEST)); 2057 EXPECT_EQ(0u, session->pending_create_stream_queue_size(LOWEST));
2058
2059 data.RunFor(1);
2064 } 2060 }
2065 2061
2066 TEST_P(SpdySessionTest, CancelTwoStalledCreateStream) { 2062 TEST_P(SpdySessionTest, CancelTwoStalledCreateStream) {
2067 session_deps_.host_resolver->set_synchronous_mode(true); 2063 session_deps_.host_resolver->set_synchronous_mode(true);
2068 2064
2069 MockRead reads[] = { 2065 MockRead reads[] = {
2070 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. 2066 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
2071 }; 2067 };
2072 2068
2073 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 2069 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
2074 MockConnect connect_data(SYNCHRONOUS, OK); 2070 MockConnect connect_data(SYNCHRONOUS, OK);
2075 2071
2076 data.set_connect_data(connect_data); 2072 data.set_connect_data(connect_data);
2077 session_deps_.socket_factory->AddSocketDataProvider(&data); 2073 session_deps_.socket_factory->AddSocketDataProvider(&data);
2078 2074
2079 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2075 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2080 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 2076 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
2081 2077
2082 CreateNetworkSession(); 2078 CreateNetworkSession();
2083 2079
2084 // Initialize the SpdySetting with 1 max concurrent streams. 2080 // Initialize the SpdySetting with 1 max concurrent streams.
2085 spdy_session_pool_->http_server_properties()->SetSpdySetting( 2081 spdy_session_pool_->http_server_properties()->SetSpdySetting(
2086 test_host_port_pair_, 2082 test_host_port_pair_,
2087 SETTINGS_MAX_CONCURRENT_STREAMS, 2083 SETTINGS_MAX_CONCURRENT_STREAMS,
2088 SETTINGS_FLAG_PLEASE_PERSIST, 2084 SETTINGS_FLAG_PLEASE_PERSIST,
2089 1); 2085 1);
2090 2086
2091 scoped_refptr<SpdySession> session = 2087 base::WeakPtr<SpdySession> session =
2092 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2088 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
2093 2089
2094 GURL url1("http://www.google.com"); 2090 GURL url1("http://www.google.com");
2095 base::WeakPtr<SpdyStream> spdy_stream1 = 2091 base::WeakPtr<SpdyStream> spdy_stream1 =
2096 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 2092 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
2097 session, url1, LOWEST, BoundNetLog()); 2093 session, url1, LOWEST, BoundNetLog());
2098 ASSERT_TRUE(spdy_stream1.get() != NULL); 2094 ASSERT_TRUE(spdy_stream1.get() != NULL);
2099 EXPECT_EQ(0u, spdy_stream1->stream_id()); 2095 EXPECT_EQ(0u, spdy_stream1->stream_id());
2100 2096
2101 TestCompletionCallback callback2; 2097 TestCompletionCallback callback2;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 ssl.protocol_negotiated = GetParam(); 2151 ssl.protocol_negotiated = GetParam();
2156 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 2152 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
2157 2153
2158 CreateNetworkSession(); 2154 CreateNetworkSession();
2159 2155
2160 const GURL url("https://www.foo.com"); 2156 const GURL url("https://www.foo.com");
2161 HostPortPair test_host_port_pair(url.host(), 443); 2157 HostPortPair test_host_port_pair(url.host(), 443);
2162 SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), 2158 SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(),
2163 kPrivacyModeDisabled); 2159 kPrivacyModeDisabled);
2164 2160
2165 scoped_refptr<SpdySession> session = 2161 base::WeakPtr<SpdySession> session =
2166 CreateSecureSpdySession(http_session_, key, BoundNetLog()); 2162 CreateSecureSpdySession(http_session_, key, BoundNetLog());
2167 2163
2168 EXPECT_EQ(spdy_util_.spdy_version() >= SPDY3, session->NeedsCredentials()); 2164 EXPECT_EQ(spdy_util_.spdy_version() >= SPDY3, session->NeedsCredentials());
2169 2165
2170 // Flush the read completion task. 2166 // Flush the read completion task.
2171 base::MessageLoop::current()->RunUntilIdle(); 2167 base::MessageLoop::current()->RunUntilIdle();
2172 2168
2173 session->CloseSessionOnError(ERR_ABORTED, std::string()); 2169 session->CloseSessionOnError(ERR_ABORTED, std::string());
2174 } 2170 }
2175 2171
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2220 writes, arraysize(writes)); 2216 writes, arraysize(writes));
2221 data.set_connect_data(connect_data); 2217 data.set_connect_data(connect_data);
2222 session_deps_.host_resolver->set_synchronous_mode(true); 2218 session_deps_.host_resolver->set_synchronous_mode(true);
2223 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 2219 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
2224 2220
2225 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2221 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2226 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 2222 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
2227 2223
2228 CreateDeterministicNetworkSession(); 2224 CreateDeterministicNetworkSession();
2229 2225
2230 scoped_refptr<SpdySession> session = 2226 base::WeakPtr<SpdySession> session =
2231 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2227 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
2232 2228
2233 GURL url1("http://www.google.com"); 2229 GURL url1("http://www.google.com");
2234 base::WeakPtr<SpdyStream> spdy_stream1 = 2230 base::WeakPtr<SpdyStream> spdy_stream1 =
2235 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 2231 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
2236 session, url1, MEDIUM, BoundNetLog()); 2232 session, url1, MEDIUM, BoundNetLog());
2237 ASSERT_TRUE(spdy_stream1.get() != NULL); 2233 ASSERT_TRUE(spdy_stream1.get() != NULL);
2238 EXPECT_EQ(0u, spdy_stream1->stream_id()); 2234 EXPECT_EQ(0u, spdy_stream1->stream_id());
2239 test::StreamDelegateDoNothing delegate1(spdy_stream1); 2235 test::StreamDelegateDoNothing delegate1(spdy_stream1);
2240 spdy_stream1->SetDelegate(&delegate1); 2236 spdy_stream1->SetDelegate(&delegate1);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 writes, arraysize(writes)); 2310 writes, arraysize(writes));
2315 data.set_connect_data(connect_data); 2311 data.set_connect_data(connect_data);
2316 session_deps_.host_resolver->set_synchronous_mode(true); 2312 session_deps_.host_resolver->set_synchronous_mode(true);
2317 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 2313 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
2318 2314
2319 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2315 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2320 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 2316 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
2321 2317
2322 CreateDeterministicNetworkSession(); 2318 CreateDeterministicNetworkSession();
2323 2319
2324 scoped_refptr<SpdySession> session = 2320 base::WeakPtr<SpdySession> session =
2325 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2321 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
2326 2322
2327 GURL url1("http://www.google.com"); 2323 GURL url1("http://www.google.com");
2328 base::WeakPtr<SpdyStream> spdy_stream1 = 2324 base::WeakPtr<SpdyStream> spdy_stream1 =
2329 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 2325 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
2330 session, url1, MEDIUM, BoundNetLog()); 2326 session, url1, MEDIUM, BoundNetLog());
2331 ASSERT_TRUE(spdy_stream1.get() != NULL); 2327 ASSERT_TRUE(spdy_stream1.get() != NULL);
2332 EXPECT_EQ(0u, spdy_stream1->stream_id()); 2328 EXPECT_EQ(0u, spdy_stream1->stream_id());
2333 test::StreamDelegateDoNothing delegate1(spdy_stream1); 2329 test::StreamDelegateDoNothing delegate1(spdy_stream1);
2334 spdy_stream1->SetDelegate(&delegate1); 2330 spdy_stream1->SetDelegate(&delegate1);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
2430 writes, arraysize(writes)); 2426 writes, arraysize(writes));
2431 data.set_connect_data(connect_data); 2427 data.set_connect_data(connect_data);
2432 session_deps_.host_resolver->set_synchronous_mode(true); 2428 session_deps_.host_resolver->set_synchronous_mode(true);
2433 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 2429 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
2434 2430
2435 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2431 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2436 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 2432 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
2437 2433
2438 CreateDeterministicNetworkSession(); 2434 CreateDeterministicNetworkSession();
2439 2435
2440 scoped_refptr<SpdySession> session = 2436 base::WeakPtr<SpdySession> session =
2441 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2437 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
2442 2438
2443 GURL url1("http://www.google.com"); 2439 GURL url1("http://www.google.com");
2444 base::WeakPtr<SpdyStream> spdy_stream1 = 2440 base::WeakPtr<SpdyStream> spdy_stream1 =
2445 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 2441 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
2446 session, url1, MEDIUM, BoundNetLog()); 2442 session, url1, MEDIUM, BoundNetLog());
2447 ASSERT_TRUE(spdy_stream1.get() != NULL); 2443 ASSERT_TRUE(spdy_stream1.get() != NULL);
2448 EXPECT_EQ(0u, spdy_stream1->stream_id()); 2444 EXPECT_EQ(0u, spdy_stream1->stream_id());
2449 test::StreamDelegateDoNothing delegate1(spdy_stream1); 2445 test::StreamDelegateDoNothing delegate1(spdy_stream1);
2450 spdy_stream1->SetDelegate(&delegate1); 2446 spdy_stream1->SetDelegate(&delegate1);
(...skipping 19 matching lines...) Expand all
2470 EXPECT_EQ(NULL, spdy_stream1.get()); 2466 EXPECT_EQ(NULL, spdy_stream1.get());
2471 2467
2472 // Verify task observer's executed_count is 1, which indicates DoRead has 2468 // Verify task observer's executed_count is 1, which indicates DoRead has
2473 // posted only one task and thus yielded though there is data available for 2469 // posted only one task and thus yielded though there is data available for
2474 // it to read. 2470 // it to read.
2475 EXPECT_EQ(1u, observer.executed_count()); 2471 EXPECT_EQ(1u, observer.executed_count());
2476 EXPECT_TRUE(data.at_write_eof()); 2472 EXPECT_TRUE(data.at_write_eof());
2477 EXPECT_TRUE(data.at_read_eof()); 2473 EXPECT_TRUE(data.at_read_eof());
2478 } 2474 }
2479 2475
2480 // Send a GoAway frame when SpdySession is in DoReadLoop. If 2476 // Send a GoAway frame when SpdySession is in DoReadLoop. Make sure
2481 // scoped_refptr to <SpdySession> is deleted from 2477 // nothing blows up.
2482 // SpdySession::DoReadLoop(), we get a crash because GoAway could
2483 // delete the SpdySession from the SpdySessionPool and the last
2484 // reference to SpdySession.
2485 TEST_P(SpdySessionTest, GoAwayWhileInDoReadLoop) { 2478 TEST_P(SpdySessionTest, GoAwayWhileInDoReadLoop) {
2486 MockConnect connect_data(SYNCHRONOUS, OK); 2479 MockConnect connect_data(SYNCHRONOUS, OK);
2487 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false); 2480 BufferedSpdyFramer framer(spdy_util_.spdy_version(), false);
2488 2481
2489 scoped_ptr<SpdyFrame> req1( 2482 scoped_ptr<SpdyFrame> req1(
2490 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); 2483 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true));
2491 MockWrite writes[] = { 2484 MockWrite writes[] = {
2492 CreateMockWrite(*req1, 0), 2485 CreateMockWrite(*req1, 0),
2493 }; 2486 };
2494 2487
(...skipping 12 matching lines...) Expand all
2507 writes, arraysize(writes)); 2500 writes, arraysize(writes));
2508 data.set_connect_data(connect_data); 2501 data.set_connect_data(connect_data);
2509 session_deps_.host_resolver->set_synchronous_mode(true); 2502 session_deps_.host_resolver->set_synchronous_mode(true);
2510 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 2503 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
2511 2504
2512 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2505 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2513 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 2506 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
2514 2507
2515 CreateDeterministicNetworkSession(); 2508 CreateDeterministicNetworkSession();
2516 2509
2517 scoped_refptr<SpdySession> session = 2510 base::WeakPtr<SpdySession> session =
2518 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2511 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
2519 2512
2520 GURL url1("http://www.google.com"); 2513 GURL url1("http://www.google.com");
2521 base::WeakPtr<SpdyStream> spdy_stream1 = 2514 base::WeakPtr<SpdyStream> spdy_stream1 =
2522 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 2515 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
2523 session, url1, MEDIUM, BoundNetLog()); 2516 session, url1, MEDIUM, BoundNetLog());
2524 test::StreamDelegateDoNothing delegate1(spdy_stream1); 2517 test::StreamDelegateDoNothing delegate1(spdy_stream1);
2525 spdy_stream1->SetDelegate(&delegate1); 2518 spdy_stream1->SetDelegate(&delegate1);
2526 session = NULL;
2527 ASSERT_TRUE(spdy_stream1.get() != NULL); 2519 ASSERT_TRUE(spdy_stream1.get() != NULL);
2528 EXPECT_EQ(0u, spdy_stream1->stream_id()); 2520 EXPECT_EQ(0u, spdy_stream1->stream_id());
2529 2521
2530 scoped_ptr<SpdyHeaderBlock> headers1( 2522 scoped_ptr<SpdyHeaderBlock> headers1(
2531 spdy_util_.ConstructGetHeaderBlock(url1.spec())); 2523 spdy_util_.ConstructGetHeaderBlock(url1.spec()));
2532 spdy_stream1->SendRequestHeaders(headers1.Pass(), NO_MORE_DATA_TO_SEND); 2524 spdy_stream1->SendRequestHeaders(headers1.Pass(), NO_MORE_DATA_TO_SEND);
2533 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders()); 2525 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders());
2534 2526
2535 // Run until 1st read. 2527 // Run until 1st read.
2536 EXPECT_EQ(0u, spdy_stream1->stream_id()); 2528 EXPECT_EQ(0u, spdy_stream1->stream_id());
2537 data.RunFor(1); 2529 data.RunFor(1);
2538 EXPECT_EQ(1u, spdy_stream1->stream_id()); 2530 EXPECT_EQ(1u, spdy_stream1->stream_id());
2539 2531
2540 // Only references to SpdySession are held by DoReadLoop and
2541 // SpdySessionPool. If DoReadLoop doesn't hold the reference, we get a
2542 // crash if SpdySession is deleted from the SpdySessionPool.
2543
2544 // Run until GoAway. 2532 // Run until GoAway.
2545 data.RunFor(3); 2533 data.RunFor(3);
2546 EXPECT_EQ(NULL, spdy_stream1.get()); 2534 EXPECT_EQ(NULL, spdy_stream1.get());
2547 EXPECT_TRUE(data.at_write_eof()); 2535 EXPECT_TRUE(data.at_write_eof());
2548 EXPECT_TRUE(data.at_read_eof()); 2536 EXPECT_TRUE(data.at_read_eof());
2537 EXPECT_TRUE(session == NULL);
2549 } 2538 }
2550 2539
2551 // Within this framework, a SpdySession should be initialized with 2540 // Within this framework, a SpdySession should be initialized with
2552 // flow control disabled for protocol version 2, with flow control 2541 // flow control disabled for protocol version 2, with flow control
2553 // enabled only for streams for protocol version 3, and with flow 2542 // enabled only for streams for protocol version 3, and with flow
2554 // control enabled for streams and sessions for higher versions. 2543 // control enabled for streams and sessions for higher versions.
2555 TEST_P(SpdySessionTest, ProtocolNegotiation) { 2544 TEST_P(SpdySessionTest, ProtocolNegotiation) {
2556 session_deps_.host_resolver->set_synchronous_mode(true); 2545 session_deps_.host_resolver->set_synchronous_mode(true);
2557 2546
2558 MockConnect connect_data(SYNCHRONOUS, OK); 2547 MockConnect connect_data(SYNCHRONOUS, OK);
2559 MockRead reads[] = { 2548 MockRead reads[] = {
2560 MockRead(SYNCHRONOUS, 0, 0) // EOF 2549 MockRead(SYNCHRONOUS, 0, 0) // EOF
2561 }; 2550 };
2562 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 2551 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
2563 data.set_connect_data(connect_data); 2552 data.set_connect_data(connect_data);
2564 session_deps_.socket_factory->AddSocketDataProvider(&data); 2553 session_deps_.socket_factory->AddSocketDataProvider(&data);
2565 2554
2566 CreateNetworkSession(); 2555 CreateNetworkSession();
2567 scoped_refptr<SpdySession> session = 2556 base::WeakPtr<SpdySession> session =
2568 CreateFakeSpdySession(spdy_session_pool_, key_); 2557 CreateFakeSpdySession(spdy_session_pool_, key_);
2569 2558
2570 EXPECT_EQ(spdy_util_.spdy_version(), 2559 EXPECT_EQ(spdy_util_.spdy_version(),
2571 session->buffered_spdy_framer_->protocol_version()); 2560 session->buffered_spdy_framer_->protocol_version());
2572 if (GetParam() == kProtoSPDY2) { 2561 if (GetParam() == kProtoSPDY2) {
2573 EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state()); 2562 EXPECT_EQ(SpdySession::FLOW_CONTROL_NONE, session->flow_control_state());
2574 EXPECT_EQ(0, session->session_send_window_size_); 2563 EXPECT_EQ(0, session->session_send_window_size_);
2575 EXPECT_EQ(0, session->session_recv_window_size_); 2564 EXPECT_EQ(0, session->session_recv_window_size_);
2576 } else if (GetParam() == kProtoSPDY3) { 2565 } else if (GetParam() == kProtoSPDY3) {
2577 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM, session->flow_control_state()); 2566 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM, session->flow_control_state());
(...skipping 29 matching lines...) Expand all
2607 2596
2608 CreateNetworkSession(); 2597 CreateNetworkSession();
2609 2598
2610 TransportClientSocketPool* pool = 2599 TransportClientSocketPool* pool =
2611 http_session_->GetTransportSocketPool( 2600 http_session_->GetTransportSocketPool(
2612 HttpNetworkSession::NORMAL_SOCKET_POOL); 2601 HttpNetworkSession::NORMAL_SOCKET_POOL);
2613 2602
2614 // Create an idle SPDY session. 2603 // Create an idle SPDY session.
2615 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), 2604 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(),
2616 kPrivacyModeDisabled); 2605 kPrivacyModeDisabled);
2617 scoped_refptr<SpdySession> session1 = 2606 base::WeakPtr<SpdySession> session1 =
2618 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); 2607 CreateInsecureSpdySession(http_session_, key1, BoundNetLog());
2619 EXPECT_FALSE(pool->IsStalled()); 2608 EXPECT_FALSE(pool->IsStalled());
2620 // Release the pointer to the session so it can be closed.
2621 session1 = NULL;
2622 2609
2623 // Trying to create a new connection should cause the pool to be stalled, and 2610 // Trying to create a new connection should cause the pool to be stalled, and
2624 // post a task asynchronously to try and close the session. 2611 // post a task asynchronously to try and close the session.
2625 TestCompletionCallback callback2; 2612 TestCompletionCallback callback2;
2626 HostPortPair host_port2("2.com", 80); 2613 HostPortPair host_port2("2.com", 80);
2627 scoped_refptr<TransportSocketParams> params2( 2614 scoped_refptr<TransportSocketParams> params2(
2628 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, 2615 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false,
2629 OnHostResolutionCallback())); 2616 OnHostResolutionCallback()));
2630 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); 2617 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle);
2631 EXPECT_EQ(ERR_IO_PENDING, 2618 EXPECT_EQ(ERR_IO_PENDING,
2632 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, 2619 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY,
2633 callback2.callback(), pool, BoundNetLog())); 2620 callback2.callback(), pool, BoundNetLog()));
2634 EXPECT_TRUE(pool->IsStalled()); 2621 EXPECT_TRUE(pool->IsStalled());
2635 2622
2636 // The socket pool should close the connection asynchronously and establish a 2623 // The socket pool should close the connection asynchronously and establish a
2637 // new connection. 2624 // new connection.
2638 EXPECT_EQ(OK, callback2.WaitForResult()); 2625 EXPECT_EQ(OK, callback2.WaitForResult());
2639 EXPECT_FALSE(pool->IsStalled()); 2626 EXPECT_FALSE(pool->IsStalled());
2627 EXPECT_TRUE(session1 == NULL);
2640 } 2628 }
2641 2629
2642 // Tests the case of a non-SPDY request closing an idle SPDY session when no 2630 // Tests the case of a non-SPDY request closing an idle SPDY session when no
2643 // pointers to the idle session are currently held, in the case the SPDY session 2631 // pointers to the idle session are currently held, in the case the SPDY session
2644 // has an alias. 2632 // has an alias.
2645 TEST_P(SpdySessionTest, CloseOneIdleConnectionWithAlias) { 2633 TEST_P(SpdySessionTest, CloseOneIdleConnectionWithAlias) {
2646 ClientSocketPoolManager::set_max_sockets_per_group( 2634 ClientSocketPoolManager::set_max_sockets_per_group(
2647 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); 2635 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
2648 ClientSocketPoolManager::set_max_sockets_per_pool( 2636 ClientSocketPoolManager::set_max_sockets_per_pool(
2649 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); 2637 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
(...skipping 18 matching lines...) Expand all
2668 2656
2669 CreateNetworkSession(); 2657 CreateNetworkSession();
2670 2658
2671 TransportClientSocketPool* pool = 2659 TransportClientSocketPool* pool =
2672 http_session_->GetTransportSocketPool( 2660 http_session_->GetTransportSocketPool(
2673 HttpNetworkSession::NORMAL_SOCKET_POOL); 2661 HttpNetworkSession::NORMAL_SOCKET_POOL);
2674 2662
2675 // Create an idle SPDY session. 2663 // Create an idle SPDY session.
2676 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(), 2664 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(),
2677 kPrivacyModeDisabled); 2665 kPrivacyModeDisabled);
2678 scoped_refptr<SpdySession> session1 = 2666 base::WeakPtr<SpdySession> session1 =
2679 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); 2667 CreateInsecureSpdySession(http_session_, key1, BoundNetLog());
2680 EXPECT_FALSE(pool->IsStalled()); 2668 EXPECT_FALSE(pool->IsStalled());
2681 2669
2682 // Set up an alias for the idle SPDY session, increasing its ref count to 2. 2670 // Set up an alias for the idle SPDY session, increasing its ref count to 2.
2683 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(), 2671 SpdySessionKey key2(HostPortPair("2.com", 80), ProxyServer::Direct(),
2684 kPrivacyModeDisabled); 2672 kPrivacyModeDisabled);
2685 HostResolver::RequestInfo info(key2.host_port_pair()); 2673 HostResolver::RequestInfo info(key2.host_port_pair());
2686 AddressList addresses; 2674 AddressList addresses;
2687 // Pre-populate the DNS cache, since a synchronous resolution is required in 2675 // Pre-populate the DNS cache, since a synchronous resolution is required in
2688 // order to create the alias. 2676 // order to create the alias.
2689 session_deps_.host_resolver->Resolve( 2677 session_deps_.host_resolver->Resolve(
2690 info, &addresses, CompletionCallback(), NULL, BoundNetLog()); 2678 info, &addresses, CompletionCallback(), NULL, BoundNetLog());
2691 // Get a session for |key2|, which should return the session created earlier. 2679 // Get a session for |key2|, which should return the session created earlier.
2692 scoped_refptr<SpdySession> session2 = 2680 base::WeakPtr<SpdySession> session2 =
2693 spdy_session_pool_->FindAvailableSession(key2, BoundNetLog()); 2681 spdy_session_pool_->FindAvailableSession(key2, BoundNetLog());
2694 ASSERT_EQ(session1.get(), session2.get()); 2682 ASSERT_EQ(session1.get(), session2.get());
2695 EXPECT_FALSE(pool->IsStalled()); 2683 EXPECT_FALSE(pool->IsStalled());
2696 2684
2697 // Release both the pointers to the session so it can be closed.
2698 session1 = NULL;
2699 session2 = NULL;
2700
2701 // Trying to create a new connection should cause the pool to be stalled, and 2685 // Trying to create a new connection should cause the pool to be stalled, and
2702 // post a task asynchronously to try and close the session. 2686 // post a task asynchronously to try and close the session.
2703 TestCompletionCallback callback3; 2687 TestCompletionCallback callback3;
2704 HostPortPair host_port3("3.com", 80); 2688 HostPortPair host_port3("3.com", 80);
2705 scoped_refptr<TransportSocketParams> params3( 2689 scoped_refptr<TransportSocketParams> params3(
2706 new TransportSocketParams(host_port3, DEFAULT_PRIORITY, false, false, 2690 new TransportSocketParams(host_port3, DEFAULT_PRIORITY, false, false,
2707 OnHostResolutionCallback())); 2691 OnHostResolutionCallback()));
2708 scoped_ptr<ClientSocketHandle> connection3(new ClientSocketHandle); 2692 scoped_ptr<ClientSocketHandle> connection3(new ClientSocketHandle);
2709 EXPECT_EQ(ERR_IO_PENDING, 2693 EXPECT_EQ(ERR_IO_PENDING,
2710 connection3->Init(host_port3.ToString(), params3, DEFAULT_PRIORITY, 2694 connection3->Init(host_port3.ToString(), params3, DEFAULT_PRIORITY,
2711 callback3.callback(), pool, BoundNetLog())); 2695 callback3.callback(), pool, BoundNetLog()));
2712 EXPECT_TRUE(pool->IsStalled()); 2696 EXPECT_TRUE(pool->IsStalled());
2713 2697
2714 // The socket pool should close the connection asynchronously and establish a 2698 // The socket pool should close the connection asynchronously and establish a
2715 // new connection. 2699 // new connection.
2716 EXPECT_EQ(OK, callback3.WaitForResult()); 2700 EXPECT_EQ(OK, callback3.WaitForResult());
2717 EXPECT_FALSE(pool->IsStalled()); 2701 EXPECT_FALSE(pool->IsStalled());
2718 } 2702 EXPECT_TRUE(session1 == NULL);
2719 2703 EXPECT_TRUE(session2 == NULL);
2720 // Tests the case of a non-SPDY request closing an idle SPDY session when a
2721 // pointer to the idle session is still held.
2722 TEST_P(SpdySessionTest, CloseOneIdleConnectionSessionStillHeld) {
2723 ClientSocketPoolManager::set_max_sockets_per_group(
2724 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
2725 ClientSocketPoolManager::set_max_sockets_per_pool(
2726 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
2727
2728 MockConnect connect_data(SYNCHRONOUS, OK);
2729 MockRead reads[] = {
2730 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
2731 };
2732 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
2733 data.set_connect_data(connect_data);
2734 session_deps_.socket_factory->AddSocketDataProvider(&data);
2735 session_deps_.socket_factory->AddSocketDataProvider(&data);
2736
2737 CreateNetworkSession();
2738
2739 TransportClientSocketPool* pool =
2740 http_session_->GetTransportSocketPool(
2741 HttpNetworkSession::NORMAL_SOCKET_POOL);
2742
2743 // Create an idle SPDY session.
2744 SpdySessionKey key1(HostPortPair("1.com", 80), ProxyServer::Direct(),
2745 kPrivacyModeDisabled);
2746 scoped_refptr<SpdySession> session1 =
2747 CreateInsecureSpdySession(http_session_, key1, BoundNetLog());
2748 EXPECT_FALSE(pool->IsStalled());
2749
2750 // Trying to create a new connection should cause the pool to be stalled, and
2751 // post a task asynchronously to try and close the session.
2752 TestCompletionCallback callback2;
2753 HostPortPair host_port2("2.com", 80);
2754 scoped_refptr<TransportSocketParams> params2(
2755 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false,
2756 OnHostResolutionCallback()));
2757 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle);
2758 EXPECT_EQ(ERR_IO_PENDING,
2759 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY,
2760 callback2.callback(), pool, BoundNetLog()));
2761 EXPECT_TRUE(pool->IsStalled());
2762
2763 // Running the message loop should cause the session to prepare to be closed,
2764 // but since there's still an outstanding reference, it should not be closed
2765 // yet.
2766 base::RunLoop().RunUntilIdle();
2767 EXPECT_TRUE(pool->IsStalled());
2768 EXPECT_FALSE(callback2.have_result());
2769
2770 // Release the pointer to the session so it can be closed.
2771 session1 = NULL;
2772 EXPECT_EQ(OK, callback2.WaitForResult());
2773 EXPECT_FALSE(pool->IsStalled());
2774 } 2704 }
2775 2705
2776 // Tests that a non-SPDY request can't close a SPDY session that's currently in 2706 // Tests that a non-SPDY request can't close a SPDY session that's currently in
2777 // use. 2707 // use.
2778 TEST_P(SpdySessionTest, CloseOneIdleConnectionFailsWhenSessionInUse) { 2708 TEST_P(SpdySessionTest, CloseOneIdleConnectionFailsWhenSessionInUse) {
2779 ClientSocketPoolManager::set_max_sockets_per_group( 2709 ClientSocketPoolManager::set_max_sockets_per_group(
2780 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); 2710 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
2781 ClientSocketPoolManager::set_max_sockets_per_pool( 2711 ClientSocketPoolManager::set_max_sockets_per_pool(
2782 HttpNetworkSession::NORMAL_SOCKET_POOL, 1); 2712 HttpNetworkSession::NORMAL_SOCKET_POOL, 1);
2783 2713
(...skipping 17 matching lines...) Expand all
2801 CreateNetworkSession(); 2731 CreateNetworkSession();
2802 2732
2803 TransportClientSocketPool* pool = 2733 TransportClientSocketPool* pool =
2804 http_session_->GetTransportSocketPool( 2734 http_session_->GetTransportSocketPool(
2805 HttpNetworkSession::NORMAL_SOCKET_POOL); 2735 HttpNetworkSession::NORMAL_SOCKET_POOL);
2806 2736
2807 // Create a SPDY session. 2737 // Create a SPDY session.
2808 GURL url1("http://www.google.com"); 2738 GURL url1("http://www.google.com");
2809 SpdySessionKey key1(HostPortPair(url1.host(), 80), 2739 SpdySessionKey key1(HostPortPair(url1.host(), 80),
2810 ProxyServer::Direct(), kPrivacyModeDisabled); 2740 ProxyServer::Direct(), kPrivacyModeDisabled);
2811 scoped_refptr<SpdySession> session1 = 2741 base::WeakPtr<SpdySession> session1 =
2812 CreateInsecureSpdySession(http_session_, key1, BoundNetLog()); 2742 CreateInsecureSpdySession(http_session_, key1, BoundNetLog());
2813 EXPECT_FALSE(pool->IsStalled()); 2743 EXPECT_FALSE(pool->IsStalled());
2814 2744
2815 // Create a stream using the session, and send a request. 2745 // Create a stream using the session, and send a request.
2816 2746
2817 TestCompletionCallback callback1; 2747 TestCompletionCallback callback1;
2818 base::WeakPtr<SpdyStream> spdy_stream1 = 2748 base::WeakPtr<SpdyStream> spdy_stream1 =
2819 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 2749 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
2820 session1, url1, DEFAULT_PRIORITY, 2750 session1, url1, DEFAULT_PRIORITY,
2821 BoundNetLog()); 2751 BoundNetLog());
2822 ASSERT_TRUE(spdy_stream1.get()); 2752 ASSERT_TRUE(spdy_stream1.get());
2823 test::StreamDelegateDoNothing delegate1(spdy_stream1); 2753 test::StreamDelegateDoNothing delegate1(spdy_stream1);
2824 spdy_stream1->SetDelegate(&delegate1); 2754 spdy_stream1->SetDelegate(&delegate1);
2825 2755
2826 scoped_ptr<SpdyHeaderBlock> headers1( 2756 scoped_ptr<SpdyHeaderBlock> headers1(
2827 spdy_util_.ConstructGetHeaderBlock(url1.spec())); 2757 spdy_util_.ConstructGetHeaderBlock(url1.spec()));
2828 EXPECT_EQ(ERR_IO_PENDING, 2758 EXPECT_EQ(ERR_IO_PENDING,
2829 spdy_stream1->SendRequestHeaders( 2759 spdy_stream1->SendRequestHeaders(
2830 headers1.Pass(), NO_MORE_DATA_TO_SEND)); 2760 headers1.Pass(), NO_MORE_DATA_TO_SEND));
2831 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders()); 2761 EXPECT_TRUE(spdy_stream1->HasUrlFromHeaders());
2832 2762
2833 base::MessageLoop::current()->RunUntilIdle(); 2763 base::MessageLoop::current()->RunUntilIdle();
2834 2764
2835 // Release the session, so holding onto a pointer here does not affect
2836 // anything.
2837 session1 = NULL;
2838
2839 // Trying to create a new connection should cause the pool to be stalled, and 2765 // Trying to create a new connection should cause the pool to be stalled, and
2840 // post a task asynchronously to try and close the session. 2766 // post a task asynchronously to try and close the session.
2841 TestCompletionCallback callback2; 2767 TestCompletionCallback callback2;
2842 HostPortPair host_port2("2.com", 80); 2768 HostPortPair host_port2("2.com", 80);
2843 scoped_refptr<TransportSocketParams> params2( 2769 scoped_refptr<TransportSocketParams> params2(
2844 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false, 2770 new TransportSocketParams(host_port2, DEFAULT_PRIORITY, false, false,
2845 OnHostResolutionCallback())); 2771 OnHostResolutionCallback()));
2846 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle); 2772 scoped_ptr<ClientSocketHandle> connection2(new ClientSocketHandle);
2847 EXPECT_EQ(ERR_IO_PENDING, 2773 EXPECT_EQ(ERR_IO_PENDING,
2848 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY, 2774 connection2->Init(host_port2.ToString(), params2, DEFAULT_PRIORITY,
2849 callback2.callback(), pool, BoundNetLog())); 2775 callback2.callback(), pool, BoundNetLog()));
2850 EXPECT_TRUE(pool->IsStalled()); 2776 EXPECT_TRUE(pool->IsStalled());
2851 2777
2852 // Running the message loop should cause the socket pool to ask the SPDY 2778 // Running the message loop should cause the socket pool to ask the SPDY
2853 // session to close an idle socket, but since the socket is in use, nothing 2779 // session to close an idle socket, but since the socket is in use, nothing
2854 // happens. 2780 // happens.
2855 base::RunLoop().RunUntilIdle(); 2781 base::RunLoop().RunUntilIdle();
2856 EXPECT_TRUE(pool->IsStalled()); 2782 EXPECT_TRUE(pool->IsStalled());
2857 EXPECT_FALSE(callback2.have_result()); 2783 EXPECT_FALSE(callback2.have_result());
2858 2784
2859 // Cancelling the request should still not release the session's socket, 2785 // Cancelling the request should still not release the session's socket,
2860 // since the session is still kept alive by the SpdySessionPool. 2786 // since the session is still kept alive by the SpdySessionPool.
2861 ASSERT_TRUE(spdy_stream1.get()); 2787 ASSERT_TRUE(spdy_stream1.get());
2862 spdy_stream1->Cancel(); 2788 spdy_stream1->Cancel();
2863 base::RunLoop().RunUntilIdle(); 2789 base::RunLoop().RunUntilIdle();
2864 EXPECT_TRUE(pool->IsStalled()); 2790 EXPECT_TRUE(pool->IsStalled());
2865 EXPECT_FALSE(callback2.have_result()); 2791 EXPECT_FALSE(callback2.have_result());
2792 EXPECT_TRUE(session1 != NULL);
2866 } 2793 }
2867 2794
2868 // Verify that SpdySessionKey and therefore SpdySession is different when 2795 // Verify that SpdySessionKey and therefore SpdySession is different when
2869 // privacy mode is enabled or disabled. 2796 // privacy mode is enabled or disabled.
2870 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) { 2797 TEST_P(SpdySessionTest, SpdySessionKeyPrivacyMode) {
2871 CreateDeterministicNetworkSession(); 2798 CreateDeterministicNetworkSession();
2872 2799
2873 HostPortPair host_port_pair("www.google.com", 443); 2800 HostPortPair host_port_pair("www.google.com", 443);
2874 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(), 2801 SpdySessionKey key_privacy_enabled(host_port_pair, ProxyServer::Direct(),
2875 kPrivacyModeEnabled); 2802 kPrivacyModeEnabled);
2876 SpdySessionKey key_privacy_disabled(host_port_pair, ProxyServer::Direct(), 2803 SpdySessionKey key_privacy_disabled(host_port_pair, ProxyServer::Direct(),
2877 kPrivacyModeDisabled); 2804 kPrivacyModeDisabled);
2878 2805
2879 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_enabled)); 2806 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_enabled));
2880 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_disabled)); 2807 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_disabled));
2881 2808
2882 // Add SpdySession with PrivacyMode Enabled to the pool. 2809 // Add SpdySession with PrivacyMode Enabled to the pool.
2883 scoped_refptr<SpdySession> session_privacy_enabled = 2810 base::WeakPtr<SpdySession> session_privacy_enabled =
2884 CreateFakeSpdySession(spdy_session_pool_, key_privacy_enabled); 2811 CreateFakeSpdySession(spdy_session_pool_, key_privacy_enabled);
2885 2812
2886 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_enabled)); 2813 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_enabled));
2887 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_disabled)); 2814 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_disabled));
2888 2815
2889 // Add SpdySession with PrivacyMode Disabled to the pool. 2816 // Add SpdySession with PrivacyMode Disabled to the pool.
2890 scoped_refptr<SpdySession> session_privacy_disabled = 2817 base::WeakPtr<SpdySession> session_privacy_disabled =
2891 CreateFakeSpdySession(spdy_session_pool_, key_privacy_disabled); 2818 CreateFakeSpdySession(spdy_session_pool_, key_privacy_disabled);
2892 2819
2893 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_enabled)); 2820 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_enabled));
2894 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_disabled)); 2821 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_disabled));
2895 2822
2896 session_privacy_enabled->CloseSessionOnError(ERR_ABORTED, std::string()); 2823 session_privacy_enabled->CloseSessionOnError(ERR_ABORTED, std::string());
2897 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_enabled)); 2824 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_privacy_enabled));
2898 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_disabled)); 2825 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_privacy_disabled));
2899 2826
2900 session_privacy_disabled->CloseSessionOnError(ERR_ABORTED, std::string()); 2827 session_privacy_disabled->CloseSessionOnError(ERR_ABORTED, std::string());
(...skipping 27 matching lines...) Expand all
2928 ssl.protocol_negotiated = GetParam(); 2855 ssl.protocol_negotiated = GetParam();
2929 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 2856 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
2930 2857
2931 CreateNetworkSession(); 2858 CreateNetworkSession();
2932 2859
2933 const GURL kTestUrl("https://www.foo.com"); 2860 const GURL kTestUrl("https://www.foo.com");
2934 HostPortPair test_host_port_pair(kTestUrl.host(), 443); 2861 HostPortPair test_host_port_pair(kTestUrl.host(), 443);
2935 SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(), 2862 SpdySessionKey key(test_host_port_pair, ProxyServer::Direct(),
2936 kPrivacyModeDisabled); 2863 kPrivacyModeDisabled);
2937 2864
2938 scoped_refptr<SpdySession> session = 2865 base::WeakPtr<SpdySession> session =
2939 CreateSecureSpdySession(http_session_, key, BoundNetLog()); 2866 CreateSecureSpdySession(http_session_, key, BoundNetLog());
2940 2867
2941 EXPECT_TRUE(session->NeedsCredentials()); 2868 EXPECT_TRUE(session->NeedsCredentials());
2942 2869
2943 // Flush the read completion task. 2870 // Flush the read completion task.
2944 base::MessageLoop::current()->RunUntilIdle(); 2871 base::MessageLoop::current()->RunUntilIdle();
2945 2872
2946 session->CloseSessionOnError(ERR_ABORTED, std::string()); 2873 session->CloseSessionOnError(ERR_ABORTED, std::string());
2947 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key)); 2874 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key));
2948 } 2875 }
(...skipping 24 matching lines...) Expand all
2973 scoped_ptr<DeterministicSocketData> data( 2900 scoped_ptr<DeterministicSocketData> data(
2974 new DeterministicSocketData(reads, arraysize(reads), NULL, 0)); 2901 new DeterministicSocketData(reads, arraysize(reads), NULL, 0));
2975 data->set_connect_data(connect_data); 2902 data->set_connect_data(connect_data);
2976 session_deps_.deterministic_socket_factory->AddSocketDataProvider(data.get()); 2903 session_deps_.deterministic_socket_factory->AddSocketDataProvider(data.get());
2977 2904
2978 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2905 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
2979 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); 2906 session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl);
2980 2907
2981 CreateDeterministicNetworkSession(); 2908 CreateDeterministicNetworkSession();
2982 2909
2983 scoped_refptr<SpdySession> session = 2910 base::WeakPtr<SpdySession> session =
2984 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2911 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
2985 base::WeakPtr<SpdyStream> spdy_stream1 = 2912 base::WeakPtr<SpdyStream> spdy_stream1 =
2986 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 2913 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
2987 session, test_url_, MEDIUM, BoundNetLog()); 2914 session, test_url_, MEDIUM, BoundNetLog());
2988 ASSERT_TRUE(spdy_stream1.get() != NULL); 2915 ASSERT_TRUE(spdy_stream1.get() != NULL);
2989 TestCompletionCallback callback1; 2916 TestCompletionCallback callback1;
2990 EXPECT_NE(spdy_stream1->send_window_size(), window_size); 2917 EXPECT_NE(spdy_stream1->send_window_size(), window_size);
2991 2918
2992 data->RunFor(1); // Process the SETTINGS frame, but not the EOF 2919 data->RunFor(1); // Process the SETTINGS frame, but not the EOF
2993 base::MessageLoop::current()->RunUntilIdle(); 2920 base::MessageLoop::current()->RunUntilIdle();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
3034 }; 2961 };
3035 DeterministicSocketData data(reads, arraysize(reads), 2962 DeterministicSocketData data(reads, arraysize(reads),
3036 writes, arraysize(writes)); 2963 writes, arraysize(writes));
3037 data.set_connect_data(connect_data); 2964 data.set_connect_data(connect_data);
3038 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 2965 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3039 2966
3040 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 2967 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
3041 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 2968 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
3042 2969
3043 CreateDeterministicNetworkSession(); 2970 CreateDeterministicNetworkSession();
3044 scoped_refptr<SpdySession> session = 2971 base::WeakPtr<SpdySession> session =
3045 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 2972 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3046 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 2973 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3047 session->flow_control_state()); 2974 session->flow_control_state());
3048 2975
3049 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); 2976 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_);
3050 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); 2977 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_);
3051 2978
3052 session->IncreaseRecvWindowSize(delta_window_size); 2979 session->IncreaseRecvWindowSize(delta_window_size);
3053 EXPECT_EQ(kSpdySessionInitialWindowSize + delta_window_size, 2980 EXPECT_EQ(kSpdySessionInitialWindowSize + delta_window_size,
3054 session->session_recv_window_size_); 2981 session->session_recv_window_size_);
(...skipping 29 matching lines...) Expand all
3084 3011
3085 MockConnect connect_data(SYNCHRONOUS, OK); 3012 MockConnect connect_data(SYNCHRONOUS, OK);
3086 MockRead reads[] = { 3013 MockRead reads[] = {
3087 MockRead(SYNCHRONOUS, 0, 0) // EOF 3014 MockRead(SYNCHRONOUS, 0, 0) // EOF
3088 }; 3015 };
3089 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 3016 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
3090 data.set_connect_data(connect_data); 3017 data.set_connect_data(connect_data);
3091 session_deps_.socket_factory->AddSocketDataProvider(&data); 3018 session_deps_.socket_factory->AddSocketDataProvider(&data);
3092 3019
3093 CreateNetworkSession(); 3020 CreateNetworkSession();
3094 scoped_refptr<SpdySession> session = 3021 base::WeakPtr<SpdySession> session =
3095 CreateFakeSpdySession(spdy_session_pool_, key_); 3022 CreateFakeSpdySession(spdy_session_pool_, key_);
3096 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 3023 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3097 session->flow_control_state()); 3024 session->flow_control_state());
3098 3025
3099 const int32 delta_window_size = 100; 3026 const int32 delta_window_size = 100;
3100 3027
3101 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_); 3028 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_send_window_size_);
3102 3029
3103 session->IncreaseSendWindowSize(delta_window_size); 3030 session->IncreaseSendWindowSize(delta_window_size);
3104 EXPECT_EQ(kSpdySessionInitialWindowSize + delta_window_size, 3031 EXPECT_EQ(kSpdySessionInitialWindowSize + delta_window_size,
(...skipping 18 matching lines...) Expand all
3123 MockRead(ASYNC, 0, 1) // EOF 3050 MockRead(ASYNC, 0, 1) // EOF
3124 }; 3051 };
3125 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); 3052 DeterministicSocketData data(reads, arraysize(reads), NULL, 0);
3126 data.set_connect_data(connect_data); 3053 data.set_connect_data(connect_data);
3127 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3054 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3128 3055
3129 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 3056 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
3130 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 3057 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
3131 3058
3132 CreateDeterministicNetworkSession(); 3059 CreateDeterministicNetworkSession();
3133 scoped_refptr<SpdySession> session = 3060 base::WeakPtr<SpdySession> session =
3134 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3061 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3135 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 3062 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3136 session->flow_control_state()); 3063 session->flow_control_state());
3137 3064
3138 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); 3065 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_);
3139 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); 3066 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_);
3140 3067
3141 data.RunFor(2); 3068 data.RunFor(1);
3142 3069
3143 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_); 3070 EXPECT_EQ(kSpdySessionInitialWindowSize, session->session_recv_window_size_);
3144 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_); 3071 EXPECT_EQ(0, session->session_unacked_recv_window_bytes_);
3072
3073 data.RunFor(1);
3145 } 3074 }
3146 3075
3147 // A delegate that drops any received data. 3076 // A delegate that drops any received data.
3148 class DropReceivedDataDelegate : public test::StreamDelegateSendImmediate { 3077 class DropReceivedDataDelegate : public test::StreamDelegateSendImmediate {
3149 public: 3078 public:
3150 DropReceivedDataDelegate(const base::WeakPtr<SpdyStream>& stream, 3079 DropReceivedDataDelegate(const base::WeakPtr<SpdyStream>& stream,
3151 base::StringPiece data) 3080 base::StringPiece data)
3152 : StreamDelegateSendImmediate(stream, data) {} 3081 : StreamDelegateSendImmediate(stream, data) {}
3153 3082
3154 virtual ~DropReceivedDataDelegate() {} 3083 virtual ~DropReceivedDataDelegate() {}
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
3200 writes, arraysize(writes)); 3129 writes, arraysize(writes));
3201 data.set_connect_data(connect_data); 3130 data.set_connect_data(connect_data);
3202 session_deps_.host_resolver->set_synchronous_mode(true); 3131 session_deps_.host_resolver->set_synchronous_mode(true);
3203 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3132 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3204 3133
3205 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 3134 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
3206 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 3135 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
3207 3136
3208 CreateDeterministicNetworkSession(); 3137 CreateDeterministicNetworkSession();
3209 3138
3210 scoped_refptr<SpdySession> session = 3139 base::WeakPtr<SpdySession> session =
3211 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3140 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3212 3141
3213 GURL url(kStreamUrl); 3142 GURL url(kStreamUrl);
3214 base::WeakPtr<SpdyStream> stream = 3143 base::WeakPtr<SpdyStream> stream =
3215 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 3144 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
3216 session, url, MEDIUM, BoundNetLog()); 3145 session, url, MEDIUM, BoundNetLog());
3217 ASSERT_TRUE(stream.get() != NULL); 3146 ASSERT_TRUE(stream.get() != NULL);
3218 EXPECT_EQ(0u, stream->stream_id()); 3147 EXPECT_EQ(0u, stream->stream_id());
3219 3148
3220 DropReceivedDataDelegate delegate(stream, msg_data); 3149 DropReceivedDataDelegate delegate(stream, msg_data);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3278 writes, arraysize(writes)); 3207 writes, arraysize(writes));
3279 data.set_connect_data(connect_data); 3208 data.set_connect_data(connect_data);
3280 session_deps_.host_resolver->set_synchronous_mode(true); 3209 session_deps_.host_resolver->set_synchronous_mode(true);
3281 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3210 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3282 3211
3283 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 3212 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
3284 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 3213 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
3285 3214
3286 CreateDeterministicNetworkSession(); 3215 CreateDeterministicNetworkSession();
3287 3216
3288 scoped_refptr<SpdySession> session = 3217 base::WeakPtr<SpdySession> session =
3289 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3218 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3290 3219
3291 GURL url(kStreamUrl); 3220 GURL url(kStreamUrl);
3292 base::WeakPtr<SpdyStream> stream = 3221 base::WeakPtr<SpdyStream> stream =
3293 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 3222 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
3294 session, url, MEDIUM, BoundNetLog()); 3223 session, url, MEDIUM, BoundNetLog());
3295 ASSERT_TRUE(stream.get() != NULL); 3224 ASSERT_TRUE(stream.get() != NULL);
3296 EXPECT_EQ(0u, stream->stream_id()); 3225 EXPECT_EQ(0u, stream->stream_id());
3297 3226
3298 test::StreamDelegateSendImmediate delegate(stream, msg_data); 3227 test::StreamDelegateSendImmediate delegate(stream, msg_data);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
3370 writes, arraysize(writes)); 3299 writes, arraysize(writes));
3371 data.set_connect_data(connect_data); 3300 data.set_connect_data(connect_data);
3372 session_deps_.host_resolver->set_synchronous_mode(true); 3301 session_deps_.host_resolver->set_synchronous_mode(true);
3373 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3302 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3374 3303
3375 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 3304 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
3376 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl); 3305 session_deps_.deterministic_socket_factory->AddSSLSocketDataProvider(&ssl);
3377 3306
3378 CreateDeterministicNetworkSession(); 3307 CreateDeterministicNetworkSession();
3379 3308
3380 scoped_refptr<SpdySession> session = 3309 base::WeakPtr<SpdySession> session =
3381 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3310 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3382 3311
3383 GURL url(kStreamUrl); 3312 GURL url(kStreamUrl);
3384 base::WeakPtr<SpdyStream> stream = 3313 base::WeakPtr<SpdyStream> stream =
3385 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, 3314 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM,
3386 session, url, MEDIUM, BoundNetLog()); 3315 session, url, MEDIUM, BoundNetLog());
3387 ASSERT_TRUE(stream.get() != NULL); 3316 ASSERT_TRUE(stream.get() != NULL);
3388 EXPECT_EQ(0u, stream->stream_id()); 3317 EXPECT_EQ(0u, stream->stream_id());
3389 3318
3390 test::StreamDelegateSendImmediate delegate(stream, msg_data); 3319 test::StreamDelegateSendImmediate delegate(stream, msg_data);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
3487 }; 3416 };
3488 3417
3489 DeterministicSocketData data(reads, arraysize(reads), 3418 DeterministicSocketData data(reads, arraysize(reads),
3490 writes, arraysize(writes)); 3419 writes, arraysize(writes));
3491 MockConnect connect_data(SYNCHRONOUS, OK); 3420 MockConnect connect_data(SYNCHRONOUS, OK);
3492 data.set_connect_data(connect_data); 3421 data.set_connect_data(connect_data);
3493 3422
3494 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3423 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3495 3424
3496 CreateDeterministicNetworkSession(); 3425 CreateDeterministicNetworkSession();
3497 scoped_refptr<SpdySession> session = 3426 base::WeakPtr<SpdySession> session =
3498 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3427 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3499 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 3428 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3500 session->flow_control_state()); 3429 session->flow_control_state());
3501 3430
3502 base::WeakPtr<SpdyStream> stream = 3431 base::WeakPtr<SpdyStream> stream =
3503 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 3432 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
3504 session, url, LOWEST, BoundNetLog()); 3433 session, url, LOWEST, BoundNetLog());
3505 ASSERT_TRUE(stream.get() != NULL); 3434 ASSERT_TRUE(stream.get() != NULL);
3506 3435
3507 test::StreamDelegateWithBody delegate(stream, kBodyDataStringPiece); 3436 test::StreamDelegateWithBody delegate(stream, kBodyDataStringPiece);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
3647 }; 3576 };
3648 3577
3649 DeterministicSocketData data(reads, arraysize(reads), 3578 DeterministicSocketData data(reads, arraysize(reads),
3650 writes, arraysize(writes)); 3579 writes, arraysize(writes));
3651 MockConnect connect_data(SYNCHRONOUS, OK); 3580 MockConnect connect_data(SYNCHRONOUS, OK);
3652 data.set_connect_data(connect_data); 3581 data.set_connect_data(connect_data);
3653 3582
3654 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3583 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3655 3584
3656 CreateDeterministicNetworkSession(); 3585 CreateDeterministicNetworkSession();
3657 scoped_refptr<SpdySession> session = 3586 base::WeakPtr<SpdySession> session =
3658 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3587 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3659 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 3588 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3660 session->flow_control_state()); 3589 session->flow_control_state());
3661 3590
3662 base::WeakPtr<SpdyStream> stream1 = 3591 base::WeakPtr<SpdyStream> stream1 =
3663 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 3592 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
3664 session, url, LOWEST, BoundNetLog()); 3593 session, url, LOWEST, BoundNetLog());
3665 ASSERT_TRUE(stream1.get() != NULL); 3594 ASSERT_TRUE(stream1.get() != NULL);
3666 3595
3667 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); 3596 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece);
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
3802 }; 3731 };
3803 3732
3804 DeterministicSocketData data(reads, arraysize(reads), 3733 DeterministicSocketData data(reads, arraysize(reads),
3805 writes, arraysize(writes)); 3734 writes, arraysize(writes));
3806 MockConnect connect_data(SYNCHRONOUS, OK); 3735 MockConnect connect_data(SYNCHRONOUS, OK);
3807 data.set_connect_data(connect_data); 3736 data.set_connect_data(connect_data);
3808 3737
3809 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3738 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3810 3739
3811 CreateDeterministicNetworkSession(); 3740 CreateDeterministicNetworkSession();
3812 scoped_refptr<SpdySession> session = 3741 base::WeakPtr<SpdySession> session =
3813 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3742 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3814 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 3743 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3815 session->flow_control_state()); 3744 session->flow_control_state());
3816 3745
3817 base::WeakPtr<SpdyStream> stream1 = 3746 base::WeakPtr<SpdyStream> stream1 =
3818 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 3747 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
3819 session, url, LOWEST, BoundNetLog()); 3748 session, url, LOWEST, BoundNetLog());
3820 ASSERT_TRUE(stream1.get() != NULL); 3749 ASSERT_TRUE(stream1.get() != NULL);
3821 3750
3822 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); 3751 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
3958 }; 3887 };
3959 3888
3960 DeterministicSocketData data(reads, arraysize(reads), 3889 DeterministicSocketData data(reads, arraysize(reads),
3961 writes, arraysize(writes)); 3890 writes, arraysize(writes));
3962 MockConnect connect_data(SYNCHRONOUS, OK); 3891 MockConnect connect_data(SYNCHRONOUS, OK);
3963 data.set_connect_data(connect_data); 3892 data.set_connect_data(connect_data);
3964 3893
3965 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); 3894 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data);
3966 3895
3967 CreateDeterministicNetworkSession(); 3896 CreateDeterministicNetworkSession();
3968 scoped_refptr<SpdySession> session = 3897 base::WeakPtr<SpdySession> session =
3969 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); 3898 CreateInsecureSpdySession(http_session_, key_, BoundNetLog());
3970 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION, 3899 EXPECT_EQ(SpdySession::FLOW_CONTROL_STREAM_AND_SESSION,
3971 session->flow_control_state()); 3900 session->flow_control_state());
3972 3901
3973 base::WeakPtr<SpdyStream> stream1 = 3902 base::WeakPtr<SpdyStream> stream1 =
3974 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM, 3903 CreateStreamSynchronously(SPDY_REQUEST_RESPONSE_STREAM,
3975 session, url, LOWEST, BoundNetLog()); 3904 session, url, LOWEST, BoundNetLog());
3976 ASSERT_TRUE(stream1.get() != NULL); 3905 ASSERT_TRUE(stream1.get() != NULL);
3977 3906
3978 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece); 3907 test::StreamDelegateWithBody delegate1(stream1, kBodyDataStringPiece);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
4018 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); 3947 EXPECT_TRUE(stream2->send_stalled_by_flow_control());
4019 3948
4020 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); 3949 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_));
4021 3950
4022 // Unstall stream1. 3951 // Unstall stream1.
4023 UnstallSessionSend(session.get(), kBodyDataSize); 3952 UnstallSessionSend(session.get(), kBodyDataSize);
4024 3953
4025 // Close the session (since we can't do it from within the delegate 3954 // Close the session (since we can't do it from within the delegate
4026 // method, since it's in the stream's loop). 3955 // method, since it's in the stream's loop).
4027 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, "Closing session"); 3956 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, "Closing session");
4028 session = NULL; 3957 EXPECT_TRUE(session == NULL);
4029 3958
4030 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); 3959 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_));
4031 3960
4032 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); 3961 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose());
4033 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); 3962 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose());
4034 3963
4035 EXPECT_TRUE(delegate1.send_headers_completed()); 3964 EXPECT_TRUE(delegate1.send_headers_completed());
4036 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); 3965 EXPECT_EQ(std::string(), delegate1.TakeReceivedData());
4037 3966
4038 EXPECT_TRUE(delegate2.send_headers_completed()); 3967 EXPECT_TRUE(delegate2.send_headers_completed());
4039 EXPECT_EQ(std::string(), delegate2.TakeReceivedData()); 3968 EXPECT_EQ(std::string(), delegate2.TakeReceivedData());
4040 3969
4041 EXPECT_TRUE(data.at_write_eof()); 3970 EXPECT_TRUE(data.at_write_eof());
4042 } 3971 }
4043 3972
4044 } // namespace net 3973 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session_pool_unittest.cc ('k') | net/spdy/spdy_stream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698