| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
| 6 | 6 |
| 7 #include "base/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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 BoundNetLog(), | 275 BoundNetLog(), |
| 276 callback2.callback())); | 276 callback2.callback())); |
| 277 | 277 |
| 278 callback1.SetRequestToDestroy(request2.Pass()); | 278 callback1.SetRequestToDestroy(request2.Pass()); |
| 279 | 279 |
| 280 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); | 280 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); |
| 281 | 281 |
| 282 EXPECT_EQ(ERR_ABORTED, callback1.WaitForResult()); | 282 EXPECT_EQ(ERR_ABORTED, callback1.WaitForResult()); |
| 283 } | 283 } |
| 284 | 284 |
| 285 // A session receiving a GOAWAY frame with no active streams should | 285 // A session receiving a GOAWAY frame with no active streams should close. |
| 286 // immediately close. | |
| 287 TEST_P(SpdySessionTest, GoAwayWithNoActiveStreams) { | 286 TEST_P(SpdySessionTest, GoAwayWithNoActiveStreams) { |
| 288 session_deps_.host_resolver->set_synchronous_mode(true); | 287 session_deps_.host_resolver->set_synchronous_mode(true); |
| 289 | 288 |
| 290 MockConnect connect_data(SYNCHRONOUS, OK); | 289 MockConnect connect_data(SYNCHRONOUS, OK); |
| 291 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 290 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| 292 MockRead reads[] = { | 291 MockRead reads[] = { |
| 293 CreateMockRead(*goaway, 0), | 292 CreateMockRead(*goaway, 0), |
| 294 }; | 293 }; |
| 295 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); | 294 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); |
| 296 data.set_connect_data(connect_data); | 295 data.set_connect_data(connect_data); |
| 297 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 296 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 298 | 297 |
| 299 CreateDeterministicNetworkSession(); | 298 CreateDeterministicNetworkSession(); |
| 300 | 299 |
| 301 base::WeakPtr<SpdySession> session = | 300 base::WeakPtr<SpdySession> session = |
| 302 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); | 301 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); |
| 303 | 302 |
| 304 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); | 303 EXPECT_EQ(spdy_util_.spdy_version(), session->GetProtocolVersion()); |
| 305 | 304 |
| 306 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); | 305 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 307 | 306 |
| 308 // Read and process the GOAWAY frame. | 307 // Read and process the GOAWAY frame. |
| 309 data.RunFor(1); | 308 data.RunFor(1); |
| 310 | |
| 311 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 309 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 312 | 310 base::RunLoop().RunUntilIdle(); |
| 313 EXPECT_TRUE(session == NULL); | 311 EXPECT_TRUE(session == NULL); |
| 314 } | 312 } |
| 315 | 313 |
| 316 // A session receiving a GOAWAY frame immediately with no active | 314 // A session receiving a GOAWAY frame immediately with no active |
| 317 // streams should then close. | 315 // streams should then close. |
| 318 TEST_P(SpdySessionTest, GoAwayImmediatelyWithNoActiveStreams) { | 316 TEST_P(SpdySessionTest, GoAwayImmediatelyWithNoActiveStreams) { |
| 319 session_deps_.host_resolver->set_synchronous_mode(true); | 317 session_deps_.host_resolver->set_synchronous_mode(true); |
| 320 | 318 |
| 321 MockConnect connect_data(SYNCHRONOUS, OK); | 319 MockConnect connect_data(SYNCHRONOUS, OK); |
| 322 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 320 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 | 400 |
| 403 // Read and process the GOAWAY frame. | 401 // Read and process the GOAWAY frame. |
| 404 data.RunFor(1); | 402 data.RunFor(1); |
| 405 | 403 |
| 406 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 404 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 407 | 405 |
| 408 EXPECT_FALSE(session->IsStreamActive(3)); | 406 EXPECT_FALSE(session->IsStreamActive(3)); |
| 409 EXPECT_EQ(NULL, spdy_stream2.get()); | 407 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 410 EXPECT_TRUE(session->IsStreamActive(1)); | 408 EXPECT_TRUE(session->IsStreamActive(1)); |
| 411 | 409 |
| 412 EXPECT_FALSE(session->IsClosed()); | 410 EXPECT_TRUE(session->IsGoingAway()); |
| 413 | 411 |
| 414 // Should close the session. | 412 // Should close the session. |
| 415 spdy_stream1->Close(); | 413 spdy_stream1->Close(); |
| 416 EXPECT_EQ(NULL, spdy_stream1.get()); | 414 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 417 | 415 |
| 416 base::MessageLoop::current()->RunUntilIdle(); |
| 418 EXPECT_TRUE(session == NULL); | 417 EXPECT_TRUE(session == NULL); |
| 419 } | 418 } |
| 420 | 419 |
| 421 // Have a session receive two GOAWAY frames, with the last one causing | 420 // Have a session receive two GOAWAY frames, with the last one causing |
| 422 // the last active stream to be closed. The session should then be | 421 // the last active stream to be closed. The session should then be |
| 423 // closed after the second GOAWAY frame. | 422 // closed after the second GOAWAY frame. |
| 424 TEST_P(SpdySessionTest, GoAwayTwice) { | 423 TEST_P(SpdySessionTest, GoAwayTwice) { |
| 425 session_deps_.host_resolver->set_synchronous_mode(true); | 424 session_deps_.host_resolver->set_synchronous_mode(true); |
| 426 | 425 |
| 427 MockConnect connect_data(SYNCHRONOUS, OK); | 426 MockConnect connect_data(SYNCHRONOUS, OK); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); | 481 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 483 | 482 |
| 484 // Read and process the first GOAWAY frame. | 483 // Read and process the first GOAWAY frame. |
| 485 data.RunFor(1); | 484 data.RunFor(1); |
| 486 | 485 |
| 487 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 486 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 488 | 487 |
| 489 EXPECT_FALSE(session->IsStreamActive(3)); | 488 EXPECT_FALSE(session->IsStreamActive(3)); |
| 490 EXPECT_EQ(NULL, spdy_stream2.get()); | 489 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 491 EXPECT_TRUE(session->IsStreamActive(1)); | 490 EXPECT_TRUE(session->IsStreamActive(1)); |
| 492 | 491 EXPECT_TRUE(session->IsGoingAway()); |
| 493 EXPECT_FALSE(session->IsClosed()); | |
| 494 | 492 |
| 495 // Read and process the second GOAWAY frame, which should close the | 493 // Read and process the second GOAWAY frame, which should close the |
| 496 // session. | 494 // session. |
| 497 data.RunFor(1); | 495 data.RunFor(1); |
| 498 | 496 base::MessageLoop::current()->RunUntilIdle(); |
| 499 EXPECT_TRUE(session == NULL); | 497 EXPECT_TRUE(session == NULL); |
| 500 } | 498 } |
| 501 | 499 |
| 502 // Have a session with active streams receive a GOAWAY frame and then | 500 // Have a session with active streams receive a GOAWAY frame and then |
| 503 // close it. It should handle the close properly (i.e., not try to | 501 // close it. It should handle the close properly (i.e., not try to |
| 504 // make itself unavailable in its pool twice). | 502 // make itself unavailable in its pool twice). |
| 505 TEST_P(SpdySessionTest, GoAwayWithActiveStreamsThenClose) { | 503 TEST_P(SpdySessionTest, GoAwayWithActiveStreamsThenClose) { |
| 506 session_deps_.host_resolver->set_synchronous_mode(true); | 504 session_deps_.host_resolver->set_synchronous_mode(true); |
| 507 | 505 |
| 508 MockConnect connect_data(SYNCHRONOUS, OK); | 506 MockConnect connect_data(SYNCHRONOUS, OK); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); | 559 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 562 | 560 |
| 563 // Read and process the GOAWAY frame. | 561 // Read and process the GOAWAY frame. |
| 564 data.RunFor(1); | 562 data.RunFor(1); |
| 565 | 563 |
| 566 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 564 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 567 | 565 |
| 568 EXPECT_FALSE(session->IsStreamActive(3)); | 566 EXPECT_FALSE(session->IsStreamActive(3)); |
| 569 EXPECT_EQ(NULL, spdy_stream2.get()); | 567 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 570 EXPECT_TRUE(session->IsStreamActive(1)); | 568 EXPECT_TRUE(session->IsStreamActive(1)); |
| 571 | 569 EXPECT_TRUE(session->IsGoingAway()); |
| 572 EXPECT_FALSE(session->IsClosed()); | |
| 573 | 570 |
| 574 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); | 571 session->CloseSessionOnError(ERR_ABORTED, "Aborting session"); |
| 572 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 575 | 573 |
| 576 EXPECT_EQ(NULL, spdy_stream1.get()); | 574 base::MessageLoop::current()->RunUntilIdle(); |
| 577 EXPECT_TRUE(session == NULL); | 575 EXPECT_TRUE(session == NULL); |
| 578 } | 576 } |
| 579 | 577 |
| 578 // Process a joint read buffer which causes the session to begin draining, and |
| 579 // then processes a GOAWAY. The session should gracefully drain. Regression test |
| 580 // for crbug.com/379469 |
| 581 TEST_P(SpdySessionTest, GoAwayWhileDraining) { |
| 582 session_deps_.host_resolver->set_synchronous_mode(true); |
| 583 |
| 584 scoped_ptr<SpdyFrame> req( |
| 585 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 586 MockWrite writes[] = { |
| 587 CreateMockWrite(*req, 0), |
| 588 }; |
| 589 |
| 590 scoped_ptr<SpdyFrame> resp(spdy_util_.ConstructSpdyGetSynReply(NULL, 0, 1)); |
| 591 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| 592 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 593 size_t joint_size = goaway->size() * 2 + body->size(); |
| 594 |
| 595 // Compose interleaved |goaway| and |body| frames into a single read. |
| 596 scoped_ptr<char[]> buffer(new char[joint_size]); |
| 597 { |
| 598 size_t out = 0; |
| 599 memcpy(&buffer[out], goaway->data(), goaway->size()); |
| 600 out += goaway->size(); |
| 601 memcpy(&buffer[out], body->data(), body->size()); |
| 602 out += body->size(); |
| 603 memcpy(&buffer[out], goaway->data(), goaway->size()); |
| 604 out += goaway->size(); |
| 605 ASSERT_EQ(out, joint_size); |
| 606 } |
| 607 SpdyFrame joint_frames(buffer.get(), joint_size, false); |
| 608 |
| 609 MockRead reads[] = { |
| 610 CreateMockRead(*resp, 1), CreateMockRead(joint_frames, 2), |
| 611 MockRead(ASYNC, 0, 3) // EOF |
| 612 }; |
| 613 |
| 614 MockConnect connect_data(SYNCHRONOUS, OK); |
| 615 DeterministicSocketData data( |
| 616 reads, arraysize(reads), writes, arraysize(writes)); |
| 617 data.set_connect_data(connect_data); |
| 618 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 619 |
| 620 CreateDeterministicNetworkSession(); |
| 621 base::WeakPtr<SpdySession> session = |
| 622 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); |
| 623 |
| 624 GURL url(kDefaultURL); |
| 625 base::WeakPtr<SpdyStream> spdy_stream = CreateStreamSynchronously( |
| 626 SPDY_REQUEST_RESPONSE_STREAM, session, url, MEDIUM, BoundNetLog()); |
| 627 test::StreamDelegateDoNothing delegate(spdy_stream); |
| 628 spdy_stream->SetDelegate(&delegate); |
| 629 |
| 630 scoped_ptr<SpdyHeaderBlock> headers( |
| 631 spdy_util_.ConstructGetHeaderBlock(url.spec())); |
| 632 spdy_stream->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); |
| 633 EXPECT_TRUE(spdy_stream->HasUrlFromHeaders()); |
| 634 |
| 635 data.RunFor(3); |
| 636 base::MessageLoop::current()->RunUntilIdle(); |
| 637 |
| 638 // Stream and session closed gracefully. |
| 639 EXPECT_TRUE(delegate.StreamIsClosed()); |
| 640 EXPECT_EQ(OK, delegate.WaitForClose()); |
| 641 EXPECT_EQ(kUploadData, delegate.TakeReceivedData()); |
| 642 EXPECT_TRUE(session == NULL); |
| 643 } |
| 644 |
| 580 // Try to create a stream after receiving a GOAWAY frame. It should | 645 // Try to create a stream after receiving a GOAWAY frame. It should |
| 581 // fail. | 646 // fail. |
| 582 TEST_P(SpdySessionTest, CreateStreamAfterGoAway) { | 647 TEST_P(SpdySessionTest, CreateStreamAfterGoAway) { |
| 583 session_deps_.host_resolver->set_synchronous_mode(true); | 648 session_deps_.host_resolver->set_synchronous_mode(true); |
| 584 | 649 |
| 585 MockConnect connect_data(SYNCHRONOUS, OK); | 650 MockConnect connect_data(SYNCHRONOUS, OK); |
| 586 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); | 651 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway(1)); |
| 587 MockRead reads[] = { | 652 MockRead reads[] = { |
| 588 CreateMockRead(*goaway, 1), | 653 CreateMockRead(*goaway, 1), |
| 589 MockRead(ASYNC, 0, 2) // EOF | 654 MockRead(ASYNC, 0, 2) // EOF |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 | 760 |
| 696 // Read and process the GOAWAY frame. | 761 // Read and process the GOAWAY frame. |
| 697 data.RunFor(1); | 762 data.RunFor(1); |
| 698 | 763 |
| 699 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 764 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 700 EXPECT_TRUE(session->IsStreamActive(1)); | 765 EXPECT_TRUE(session->IsStreamActive(1)); |
| 701 | 766 |
| 702 // Read and process the SYN_STREAM frame, the subsequent RST_STREAM, | 767 // Read and process the SYN_STREAM frame, the subsequent RST_STREAM, |
| 703 // and EOF. | 768 // and EOF. |
| 704 data.RunFor(3); | 769 data.RunFor(3); |
| 705 | 770 base::MessageLoop::current()->RunUntilIdle(); |
| 706 EXPECT_TRUE(session == NULL); | 771 EXPECT_TRUE(session == NULL); |
| 707 } | 772 } |
| 708 | 773 |
| 709 // A session observing a network change with active streams should close | 774 // A session observing a network change with active streams should close |
| 710 // when the last active stream is closed. | 775 // when the last active stream is closed. |
| 711 TEST_P(SpdySessionTest, NetworkChangeWithActiveStreams) { | 776 TEST_P(SpdySessionTest, NetworkChangeWithActiveStreams) { |
| 712 session_deps_.host_resolver->set_synchronous_mode(true); | 777 session_deps_.host_resolver->set_synchronous_mode(true); |
| 713 | 778 |
| 714 MockConnect connect_data(SYNCHRONOUS, OK); | 779 MockConnect connect_data(SYNCHRONOUS, OK); |
| 715 MockRead reads[] = { | 780 MockRead reads[] = { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 819 |
| 755 // The SpdySessionPool behavior differs based on how the OSs reacts to | 820 // The SpdySessionPool behavior differs based on how the OSs reacts to |
| 756 // network changes; see comment in SpdySessionPool::OnIPAddressChanged(). | 821 // network changes; see comment in SpdySessionPool::OnIPAddressChanged(). |
| 757 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 822 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
| 758 // For OSs where the TCP connections will close upon relevant network | 823 // For OSs where the TCP connections will close upon relevant network |
| 759 // changes, SpdySessionPool doesn't need to force them to close, so in these | 824 // changes, SpdySessionPool doesn't need to force them to close, so in these |
| 760 // cases verify the session has become unavailable but remains open and the | 825 // cases verify the session has become unavailable but remains open and the |
| 761 // pre-existing stream is still active. | 826 // pre-existing stream is still active. |
| 762 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 827 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 763 | 828 |
| 764 EXPECT_FALSE(session->IsClosed()); | 829 EXPECT_TRUE(session->IsGoingAway()); |
| 765 | 830 |
| 766 EXPECT_TRUE(session->IsStreamActive(1)); | 831 EXPECT_TRUE(session->IsStreamActive(1)); |
| 767 | 832 |
| 768 // Should close the session. | 833 // Should close the session. |
| 769 spdy_stream->Close(); | 834 spdy_stream->Close(); |
| 770 #endif | 835 #endif |
| 771 EXPECT_EQ(NULL, spdy_stream.get()); | 836 EXPECT_EQ(NULL, spdy_stream.get()); |
| 772 | 837 |
| 838 base::MessageLoop::current()->RunUntilIdle(); |
| 773 EXPECT_TRUE(session == NULL); | 839 EXPECT_TRUE(session == NULL); |
| 774 } | 840 } |
| 775 | 841 |
| 776 TEST_P(SpdySessionTest, ClientPing) { | 842 TEST_P(SpdySessionTest, ClientPing) { |
| 777 session_deps_.enable_ping = true; | 843 session_deps_.enable_ping = true; |
| 778 session_deps_.host_resolver->set_synchronous_mode(true); | 844 session_deps_.host_resolver->set_synchronous_mode(true); |
| 779 | 845 |
| 780 MockConnect connect_data(SYNCHRONOUS, OK); | 846 MockConnect connect_data(SYNCHRONOUS, OK); |
| 781 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1, true)); | 847 scoped_ptr<SpdyFrame> read_ping(spdy_util_.ConstructSpdyPing(1, true)); |
| 782 MockRead reads[] = { | 848 MockRead reads[] = { |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1035 EXPECT_EQ(0u, session->pending_create_stream_queue_size(MEDIUM)); | 1101 EXPECT_EQ(0u, session->pending_create_stream_queue_size(MEDIUM)); |
| 1036 | 1102 |
| 1037 // Read responses on remaining active streams. | 1103 // Read responses on remaining active streams. |
| 1038 data.RunFor(4); | 1104 data.RunFor(4); |
| 1039 EXPECT_EQ(OK, delegate1.WaitForClose()); | 1105 EXPECT_EQ(OK, delegate1.WaitForClose()); |
| 1040 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData()); | 1106 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData()); |
| 1041 EXPECT_EQ(OK, delegate2.WaitForClose()); | 1107 EXPECT_EQ(OK, delegate2.WaitForClose()); |
| 1042 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData()); | 1108 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData()); |
| 1043 | 1109 |
| 1044 // Session was destroyed. | 1110 // Session was destroyed. |
| 1111 base::MessageLoop::current()->RunUntilIdle(); |
| 1045 EXPECT_FALSE(session.get()); | 1112 EXPECT_FALSE(session.get()); |
| 1046 } | 1113 } |
| 1047 | 1114 |
| 1048 // Verifies that an unstalled pending stream creation racing with a new stream | 1115 // Verifies that an unstalled pending stream creation racing with a new stream |
| 1049 // creation doesn't violate the maximum stream concurrency. Regression test for | 1116 // creation doesn't violate the maximum stream concurrency. Regression test for |
| 1050 // crbug.com/373858. | 1117 // crbug.com/373858. |
| 1051 TEST_P(SpdySessionTest, UnstallRacesWithStreamCreation) { | 1118 TEST_P(SpdySessionTest, UnstallRacesWithStreamCreation) { |
| 1052 session_deps_.host_resolver->set_synchronous_mode(true); | 1119 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1053 | 1120 |
| 1054 MockRead reads[] = { | 1121 MockRead reads[] = { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1188 if (session->flow_control_state_ == | 1255 if (session->flow_control_state_ == |
| 1189 SpdySession::FLOW_CONTROL_STREAM_AND_SESSION) { | 1256 SpdySession::FLOW_CONTROL_STREAM_AND_SESSION) { |
| 1190 // Verify that the session window reclaimed the evicted stream body. | 1257 // Verify that the session window reclaimed the evicted stream body. |
| 1191 EXPECT_EQ(kSpdySessionInitialWindowSize, | 1258 EXPECT_EQ(kSpdySessionInitialWindowSize, |
| 1192 session->session_recv_window_size_); | 1259 session->session_recv_window_size_); |
| 1193 EXPECT_EQ(kUploadDataSize, session->session_unacked_recv_window_bytes_); | 1260 EXPECT_EQ(kUploadDataSize, session->session_unacked_recv_window_bytes_); |
| 1194 } | 1261 } |
| 1195 | 1262 |
| 1196 // Read and process EOF. | 1263 // Read and process EOF. |
| 1197 data.RunFor(1); | 1264 data.RunFor(1); |
| 1265 base::MessageLoop::current()->RunUntilIdle(); |
| 1198 EXPECT_TRUE(session == NULL); | 1266 EXPECT_TRUE(session == NULL); |
| 1199 } | 1267 } |
| 1200 | 1268 |
| 1201 TEST_P(SpdySessionTest, FailedPing) { | 1269 TEST_P(SpdySessionTest, FailedPing) { |
| 1202 session_deps_.host_resolver->set_synchronous_mode(true); | 1270 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1203 | 1271 |
| 1204 MockConnect connect_data(SYNCHRONOUS, OK); | 1272 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1205 MockRead reads[] = { | 1273 MockRead reads[] = { |
| 1206 MockRead(ASYNC, 0, 0, 0) // EOF | 1274 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 1207 }; | 1275 }; |
| 1208 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1, false)); | 1276 scoped_ptr<SpdyFrame> write_ping(spdy_util_.ConstructSpdyPing(1, false)); |
| 1209 DeterministicSocketData data(reads, arraysize(reads), NULL, 0); | 1277 MockWrite writes[] = { |
| 1278 CreateMockWrite(*write_ping), |
| 1279 }; |
| 1280 StaticSocketDataProvider data( |
| 1281 reads, arraysize(reads), writes, arraysize(writes)); |
| 1210 data.set_connect_data(connect_data); | 1282 data.set_connect_data(connect_data); |
| 1211 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 1283 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1212 | 1284 |
| 1213 CreateDeterministicNetworkSession(); | 1285 CreateNetworkSession(); |
| 1214 | 1286 |
| 1215 base::WeakPtr<SpdySession> session = | 1287 base::WeakPtr<SpdySession> session = |
| 1216 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); | 1288 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); |
| 1217 | 1289 |
| 1218 base::WeakPtr<SpdyStream> spdy_stream1 = | 1290 base::WeakPtr<SpdyStream> spdy_stream1 = |
| 1219 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, | 1291 CreateStreamSynchronously(SPDY_BIDIRECTIONAL_STREAM, |
| 1220 session, test_url_, MEDIUM, BoundNetLog()); | 1292 session, test_url_, MEDIUM, BoundNetLog()); |
| 1221 ASSERT_TRUE(spdy_stream1.get() != NULL); | 1293 ASSERT_TRUE(spdy_stream1.get() != NULL); |
| 1222 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL); | 1294 test::StreamDelegateSendImmediate delegate(spdy_stream1, NULL); |
| 1223 spdy_stream1->SetDelegate(&delegate); | 1295 spdy_stream1->SetDelegate(&delegate); |
| 1224 | 1296 |
| 1225 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); | 1297 session->set_connection_at_risk_of_loss_time(base::TimeDelta::FromSeconds(0)); |
| 1226 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); | 1298 session->set_hung_interval(base::TimeDelta::FromSeconds(0)); |
| 1227 | 1299 |
| 1228 // Send a PING frame. | 1300 // Send a PING frame. |
| 1229 session->WritePingFrame(1, false); | 1301 session->WritePingFrame(1, false); |
| 1230 EXPECT_LT(0, session->pings_in_flight()); | 1302 EXPECT_LT(0, session->pings_in_flight()); |
| 1231 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); | 1303 EXPECT_GE(session->next_ping_id(), static_cast<uint32>(1)); |
| 1232 EXPECT_TRUE(session->check_ping_status_pending()); | 1304 EXPECT_TRUE(session->check_ping_status_pending()); |
| 1233 | 1305 |
| 1234 // Assert session is not closed. | 1306 // Assert session is not closed. |
| 1235 EXPECT_FALSE(session->IsClosed()); | 1307 EXPECT_TRUE(session->IsAvailable()); |
| 1236 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); | 1308 EXPECT_LT(0u, session->num_active_streams() + session->num_created_streams()); |
| 1237 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); | 1309 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 1238 | 1310 |
| 1239 // We set last time we have received any data in 1 sec less than now. | 1311 // We set last time we have received any data in 1 sec less than now. |
| 1240 // CheckPingStatus will trigger timeout because hung interval is zero. | 1312 // CheckPingStatus will trigger timeout because hung interval is zero. |
| 1241 base::TimeTicks now = base::TimeTicks::Now(); | 1313 base::TimeTicks now = base::TimeTicks::Now(); |
| 1242 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); | 1314 session->last_activity_time_ = now - base::TimeDelta::FromSeconds(1); |
| 1243 session->CheckPingStatus(now); | 1315 session->CheckPingStatus(now); |
| 1316 base::MessageLoop::current()->RunUntilIdle(); |
| 1244 | 1317 |
| 1245 EXPECT_TRUE(session == NULL); | 1318 EXPECT_TRUE(session == NULL); |
| 1246 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 1319 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 1247 EXPECT_EQ(NULL, spdy_stream1.get()); | 1320 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 1248 } | 1321 } |
| 1249 | 1322 |
| 1250 // Request kInitialMaxConcurrentStreams + 1 streams. Receive a | 1323 // Request kInitialMaxConcurrentStreams + 1 streams. Receive a |
| 1251 // settings frame increasing the max concurrent streams by 1. Make | 1324 // settings frame increasing the max concurrent streams by 1. Make |
| 1252 // sure nothing blows up. This is a regression test for | 1325 // sure nothing blows up. This is a regression test for |
| 1253 // http://crbug.com/57331 . | 1326 // http://crbug.com/57331 . |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1297 request.StartRequest( | 1370 request.StartRequest( |
| 1298 SPDY_BIDIRECTIONAL_STREAM, session, test_url_, MEDIUM, | 1371 SPDY_BIDIRECTIONAL_STREAM, session, test_url_, MEDIUM, |
| 1299 BoundNetLog(), | 1372 BoundNetLog(), |
| 1300 stream_releaser.MakeCallback(&request))); | 1373 stream_releaser.MakeCallback(&request))); |
| 1301 | 1374 |
| 1302 data.RunFor(1); | 1375 data.RunFor(1); |
| 1303 | 1376 |
| 1304 EXPECT_EQ(OK, stream_releaser.WaitForResult()); | 1377 EXPECT_EQ(OK, stream_releaser.WaitForResult()); |
| 1305 | 1378 |
| 1306 data.RunFor(1); | 1379 data.RunFor(1); |
| 1380 if (spdy_util_.spdy_version() >= SPDY4) { |
| 1381 // Allow the SETTINGS+ACK to write, so the session finishes draining. |
| 1382 data.RunFor(1); |
| 1383 } |
| 1384 base::MessageLoop::current()->RunUntilIdle(); |
| 1307 EXPECT_TRUE(session == NULL); | 1385 EXPECT_TRUE(session == NULL); |
| 1308 } | 1386 } |
| 1309 | 1387 |
| 1310 // Start with a persisted value for max concurrent streams. Receive a | 1388 // Start with a persisted value for max concurrent streams. Receive a |
| 1311 // settings frame increasing the max concurrent streams by 1 and which | 1389 // settings frame increasing the max concurrent streams by 1 and which |
| 1312 // also clears the persisted data. Verify that persisted data is | 1390 // also clears the persisted data. Verify that persisted data is |
| 1313 // correct. | 1391 // correct. |
| 1314 TEST_P(SpdySessionTest, ClearSettings) { | 1392 TEST_P(SpdySessionTest, ClearSettings) { |
| 1315 if (spdy_util_.spdy_version() >= SPDY4) { | 1393 if (spdy_util_.spdy_version() >= SPDY4) { |
| 1316 // SPDY4 doesn't include settings persistence, or a CLEAR_SETTINGS flag. | 1394 // SPDY4 doesn't include settings persistence, or a CLEAR_SETTINGS flag. |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1576 EXPECT_LT(0, pos); | 1654 EXPECT_LT(0, pos); |
| 1577 | 1655 |
| 1578 CapturingNetLog::CapturedEntry entry = entries[pos]; | 1656 CapturingNetLog::CapturedEntry entry = entries[pos]; |
| 1579 NetLog::Source socket_source; | 1657 NetLog::Source socket_source; |
| 1580 EXPECT_TRUE(NetLog::Source::FromEventParameters(entry.params.get(), | 1658 EXPECT_TRUE(NetLog::Source::FromEventParameters(entry.params.get(), |
| 1581 &socket_source)); | 1659 &socket_source)); |
| 1582 EXPECT_TRUE(socket_source.IsValid()); | 1660 EXPECT_TRUE(socket_source.IsValid()); |
| 1583 EXPECT_NE(log.bound().source().id, socket_source.id); | 1661 EXPECT_NE(log.bound().source().id, socket_source.id); |
| 1584 } | 1662 } |
| 1585 | 1663 |
| 1586 TEST_P(SpdySessionTest, CloseSessionOnError) { | 1664 TEST_P(SpdySessionTest, NetLogOnSessionGoaway) { |
| 1587 session_deps_.host_resolver->set_synchronous_mode(true); | 1665 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1588 | 1666 |
| 1589 MockConnect connect_data(SYNCHRONOUS, OK); | 1667 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1590 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); | 1668 scoped_ptr<SpdyFrame> goaway(spdy_util_.ConstructSpdyGoAway()); |
| 1591 MockRead reads[] = { | 1669 MockRead reads[] = { |
| 1592 CreateMockRead(*goaway), | 1670 CreateMockRead(*goaway), |
| 1593 MockRead(SYNCHRONOUS, 0, 0) // EOF | 1671 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 1594 }; | 1672 }; |
| 1595 | 1673 |
| 1596 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 1674 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1618 // Check that we logged SPDY_SESSION_CLOSE correctly. | 1696 // Check that we logged SPDY_SESSION_CLOSE correctly. |
| 1619 int pos = net::ExpectLogContainsSomewhere( | 1697 int pos = net::ExpectLogContainsSomewhere( |
| 1620 entries, 0, | 1698 entries, 0, |
| 1621 net::NetLog::TYPE_SPDY_SESSION_CLOSE, | 1699 net::NetLog::TYPE_SPDY_SESSION_CLOSE, |
| 1622 net::NetLog::PHASE_NONE); | 1700 net::NetLog::PHASE_NONE); |
| 1623 | 1701 |
| 1624 if (pos < static_cast<int>(entries.size())) { | 1702 if (pos < static_cast<int>(entries.size())) { |
| 1625 CapturingNetLog::CapturedEntry entry = entries[pos]; | 1703 CapturingNetLog::CapturedEntry entry = entries[pos]; |
| 1626 int error_code = 0; | 1704 int error_code = 0; |
| 1627 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); | 1705 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); |
| 1706 EXPECT_EQ(OK, error_code); |
| 1707 } else { |
| 1708 ADD_FAILURE(); |
| 1709 } |
| 1710 } |
| 1711 |
| 1712 TEST_P(SpdySessionTest, NetLogOnSessionEOF) { |
| 1713 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1714 |
| 1715 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1716 MockRead reads[] = { |
| 1717 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 1718 }; |
| 1719 |
| 1720 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 1721 data.set_connect_data(connect_data); |
| 1722 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1723 |
| 1724 CreateNetworkSession(); |
| 1725 |
| 1726 CapturingBoundNetLog log; |
| 1727 base::WeakPtr<SpdySession> session = |
| 1728 CreateInsecureSpdySession(http_session_, key_, log.bound()); |
| 1729 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 1730 |
| 1731 // Flush the read completion task. |
| 1732 base::MessageLoop::current()->RunUntilIdle(); |
| 1733 |
| 1734 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 1735 EXPECT_TRUE(session == NULL); |
| 1736 |
| 1737 // Check that the NetLog was filled reasonably. |
| 1738 net::CapturingNetLog::CapturedEntryList entries; |
| 1739 log.GetEntries(&entries); |
| 1740 EXPECT_LT(0u, entries.size()); |
| 1741 |
| 1742 // Check that we logged SPDY_SESSION_CLOSE correctly. |
| 1743 int pos = |
| 1744 net::ExpectLogContainsSomewhere(entries, |
| 1745 0, |
| 1746 net::NetLog::TYPE_SPDY_SESSION_CLOSE, |
| 1747 net::NetLog::PHASE_NONE); |
| 1748 |
| 1749 if (pos < static_cast<int>(entries.size())) { |
| 1750 CapturingNetLog::CapturedEntry entry = entries[pos]; |
| 1751 int error_code = 0; |
| 1752 ASSERT_TRUE(entry.GetNetErrorCode(&error_code)); |
| 1628 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); | 1753 EXPECT_EQ(ERR_CONNECTION_CLOSED, error_code); |
| 1629 } else { | 1754 } else { |
| 1630 ADD_FAILURE(); | 1755 ADD_FAILURE(); |
| 1631 } | 1756 } |
| 1632 } | 1757 } |
| 1633 | 1758 |
| 1634 // Queue up a low-priority SYN_STREAM followed by a high-priority | 1759 // Queue up a low-priority SYN_STREAM followed by a high-priority |
| 1635 // one. The high priority one should still send first and receive | 1760 // one. The high priority one should still send first and receive |
| 1636 // first. | 1761 // first. |
| 1637 TEST_P(SpdySessionTest, OutOfOrderSynStreams) { | 1762 TEST_P(SpdySessionTest, OutOfOrderSynStreams) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1850 | 1975 |
| 1851 // Ensure we don't crash while closing the session. | 1976 // Ensure we don't crash while closing the session. |
| 1852 session->CloseSessionOnError(ERR_ABORTED, std::string()); | 1977 session->CloseSessionOnError(ERR_ABORTED, std::string()); |
| 1853 | 1978 |
| 1854 EXPECT_EQ(NULL, spdy_stream1.get()); | 1979 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 1855 EXPECT_EQ(NULL, spdy_stream2.get()); | 1980 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 1856 | 1981 |
| 1857 EXPECT_TRUE(delegate1.StreamIsClosed()); | 1982 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 1858 EXPECT_TRUE(delegate2.StreamIsClosed()); | 1983 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 1859 | 1984 |
| 1985 base::MessageLoop::current()->RunUntilIdle(); |
| 1860 EXPECT_TRUE(session == NULL); | 1986 EXPECT_TRUE(session == NULL); |
| 1861 } | 1987 } |
| 1862 | 1988 |
| 1863 // Create two streams that are set to close each other on close, and | 1989 // Create two streams that are set to close each other on close, and |
| 1864 // then close the session. Nothing should blow up. | 1990 // then close the session. Nothing should blow up. |
| 1865 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedMutuallyClosingStreams) { | 1991 TEST_P(SpdySessionTest, CloseSessionWithTwoCreatedMutuallyClosingStreams) { |
| 1866 session_deps_.host_resolver->set_synchronous_mode(true); | 1992 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1867 | 1993 |
| 1868 MockConnect connect_data(SYNCHRONOUS, OK); | 1994 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1869 | 1995 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1923 | 2049 |
| 1924 // Ensure we don't crash while closing the session. | 2050 // Ensure we don't crash while closing the session. |
| 1925 session->CloseSessionOnError(ERR_ABORTED, std::string()); | 2051 session->CloseSessionOnError(ERR_ABORTED, std::string()); |
| 1926 | 2052 |
| 1927 EXPECT_EQ(NULL, spdy_stream1.get()); | 2053 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 1928 EXPECT_EQ(NULL, spdy_stream2.get()); | 2054 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 1929 | 2055 |
| 1930 EXPECT_TRUE(delegate1.StreamIsClosed()); | 2056 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 1931 EXPECT_TRUE(delegate2.StreamIsClosed()); | 2057 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 1932 | 2058 |
| 2059 base::MessageLoop::current()->RunUntilIdle(); |
| 1933 EXPECT_TRUE(session == NULL); | 2060 EXPECT_TRUE(session == NULL); |
| 1934 } | 2061 } |
| 1935 | 2062 |
| 1936 // Create two streams that are set to re-close themselves on close, | 2063 // Create two streams that are set to re-close themselves on close, |
| 1937 // activate them, and then close the session. Nothing should blow up. | 2064 // activate them, and then close the session. Nothing should blow up. |
| 1938 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedSelfClosingStreams) { | 2065 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedSelfClosingStreams) { |
| 1939 session_deps_.host_resolver->set_synchronous_mode(true); | 2066 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1940 | 2067 |
| 1941 MockConnect connect_data(SYNCHRONOUS, OK); | 2068 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1942 | 2069 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2004 | 2131 |
| 2005 // Ensure we don't crash while closing the session. | 2132 // Ensure we don't crash while closing the session. |
| 2006 session->CloseSessionOnError(ERR_ABORTED, std::string()); | 2133 session->CloseSessionOnError(ERR_ABORTED, std::string()); |
| 2007 | 2134 |
| 2008 EXPECT_EQ(NULL, spdy_stream1.get()); | 2135 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 2009 EXPECT_EQ(NULL, spdy_stream2.get()); | 2136 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 2010 | 2137 |
| 2011 EXPECT_TRUE(delegate1.StreamIsClosed()); | 2138 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 2012 EXPECT_TRUE(delegate2.StreamIsClosed()); | 2139 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 2013 | 2140 |
| 2141 base::MessageLoop::current()->RunUntilIdle(); |
| 2014 EXPECT_TRUE(session == NULL); | 2142 EXPECT_TRUE(session == NULL); |
| 2015 } | 2143 } |
| 2016 | 2144 |
| 2017 // Create two streams that are set to close each other on close, | 2145 // Create two streams that are set to close each other on close, |
| 2018 // activate them, and then close the session. Nothing should blow up. | 2146 // activate them, and then close the session. Nothing should blow up. |
| 2019 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedMutuallyClosingStreams) { | 2147 TEST_P(SpdySessionTest, CloseSessionWithTwoActivatedMutuallyClosingStreams) { |
| 2020 session_deps_.host_resolver->set_synchronous_mode(true); | 2148 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2021 | 2149 |
| 2022 MockConnect connect_data(SYNCHRONOUS, OK); | 2150 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2023 | 2151 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2087 | 2215 |
| 2088 // Ensure we don't crash while closing the session. | 2216 // Ensure we don't crash while closing the session. |
| 2089 session->CloseSessionOnError(ERR_ABORTED, std::string()); | 2217 session->CloseSessionOnError(ERR_ABORTED, std::string()); |
| 2090 | 2218 |
| 2091 EXPECT_EQ(NULL, spdy_stream1.get()); | 2219 EXPECT_EQ(NULL, spdy_stream1.get()); |
| 2092 EXPECT_EQ(NULL, spdy_stream2.get()); | 2220 EXPECT_EQ(NULL, spdy_stream2.get()); |
| 2093 | 2221 |
| 2094 EXPECT_TRUE(delegate1.StreamIsClosed()); | 2222 EXPECT_TRUE(delegate1.StreamIsClosed()); |
| 2095 EXPECT_TRUE(delegate2.StreamIsClosed()); | 2223 EXPECT_TRUE(delegate2.StreamIsClosed()); |
| 2096 | 2224 |
| 2225 base::MessageLoop::current()->RunUntilIdle(); |
| 2097 EXPECT_TRUE(session == NULL); | 2226 EXPECT_TRUE(session == NULL); |
| 2098 } | 2227 } |
| 2099 | 2228 |
| 2100 // Delegate that closes a given session when the stream is closed. | 2229 // Delegate that closes a given session when the stream is closed. |
| 2101 class SessionClosingDelegate : public test::StreamDelegateDoNothing { | 2230 class SessionClosingDelegate : public test::StreamDelegateDoNothing { |
| 2102 public: | 2231 public: |
| 2103 SessionClosingDelegate(const base::WeakPtr<SpdyStream>& stream, | 2232 SessionClosingDelegate(const base::WeakPtr<SpdyStream>& stream, |
| 2104 const base::WeakPtr<SpdySession>& session_to_close) | 2233 const base::WeakPtr<SpdySession>& session_to_close) |
| 2105 : StreamDelegateDoNothing(stream), | 2234 : StreamDelegateDoNothing(stream), |
| 2106 session_to_close_(session_to_close) {} | 2235 session_to_close_(session_to_close) {} |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2117 | 2246 |
| 2118 // Close an activated stream that closes its session. Nothing should | 2247 // Close an activated stream that closes its session. Nothing should |
| 2119 // blow up. This is a regression test for http://crbug.com/263691 . | 2248 // blow up. This is a regression test for http://crbug.com/263691 . |
| 2120 TEST_P(SpdySessionTest, CloseActivatedStreamThatClosesSession) { | 2249 TEST_P(SpdySessionTest, CloseActivatedStreamThatClosesSession) { |
| 2121 session_deps_.host_resolver->set_synchronous_mode(true); | 2250 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2122 | 2251 |
| 2123 MockConnect connect_data(SYNCHRONOUS, OK); | 2252 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2124 | 2253 |
| 2125 scoped_ptr<SpdyFrame> req( | 2254 scoped_ptr<SpdyFrame> req( |
| 2126 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); | 2255 spdy_util_.ConstructSpdyGet(NULL, 0, false, 1, MEDIUM, true)); |
| 2256 scoped_ptr<SpdyFrame> rst( |
| 2257 spdy_util_.ConstructSpdyRstStream(1, RST_STREAM_CANCEL)); |
| 2127 MockWrite writes[] = { | 2258 MockWrite writes[] = { |
| 2128 CreateMockWrite(*req, 0), | 2259 CreateMockWrite(*req, 0), CreateMockWrite(*rst, 1), |
| 2129 }; | 2260 }; |
| 2130 | 2261 |
| 2131 MockRead reads[] = { | 2262 MockRead reads[] = { |
| 2132 MockRead(ASYNC, 0, 1) // EOF | 2263 MockRead(ASYNC, 0, 2) // EOF |
| 2133 }; | 2264 }; |
| 2134 DeterministicSocketData data(reads, arraysize(reads), | 2265 DeterministicSocketData data(reads, arraysize(reads), |
| 2135 writes, arraysize(writes)); | 2266 writes, arraysize(writes)); |
| 2136 data.set_connect_data(connect_data); | 2267 data.set_connect_data(connect_data); |
| 2137 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); | 2268 session_deps_.deterministic_socket_factory->AddSocketDataProvider(&data); |
| 2138 | 2269 |
| 2139 CreateDeterministicNetworkSession(); | 2270 CreateDeterministicNetworkSession(); |
| 2140 | 2271 |
| 2141 base::WeakPtr<SpdySession> session = | 2272 base::WeakPtr<SpdySession> session = |
| 2142 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); | 2273 CreateInsecureSpdySession(http_session_, key_, BoundNetLog()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 2159 EXPECT_EQ(0u, spdy_stream->stream_id()); | 2290 EXPECT_EQ(0u, spdy_stream->stream_id()); |
| 2160 | 2291 |
| 2161 data.RunFor(1); | 2292 data.RunFor(1); |
| 2162 | 2293 |
| 2163 EXPECT_EQ(1u, spdy_stream->stream_id()); | 2294 EXPECT_EQ(1u, spdy_stream->stream_id()); |
| 2164 | 2295 |
| 2165 // Ensure we don't crash while closing the stream (which closes the | 2296 // Ensure we don't crash while closing the stream (which closes the |
| 2166 // session). | 2297 // session). |
| 2167 spdy_stream->Cancel(); | 2298 spdy_stream->Cancel(); |
| 2168 | 2299 |
| 2300 data.RunFor(1); |
| 2301 base::MessageLoop::current()->RunUntilIdle(); |
| 2302 |
| 2169 EXPECT_EQ(NULL, spdy_stream.get()); | 2303 EXPECT_EQ(NULL, spdy_stream.get()); |
| 2170 EXPECT_TRUE(delegate.StreamIsClosed()); | 2304 EXPECT_TRUE(delegate.StreamIsClosed()); |
| 2305 |
| 2171 EXPECT_TRUE(session == NULL); | 2306 EXPECT_TRUE(session == NULL); |
| 2172 } | 2307 } |
| 2173 | 2308 |
| 2174 TEST_P(SpdySessionTest, VerifyDomainAuthentication) { | 2309 TEST_P(SpdySessionTest, VerifyDomainAuthentication) { |
| 2175 session_deps_.host_resolver->set_synchronous_mode(true); | 2310 session_deps_.host_resolver->set_synchronous_mode(true); |
| 2176 | 2311 |
| 2177 MockConnect connect_data(SYNCHRONOUS, OK); | 2312 MockConnect connect_data(SYNCHRONOUS, OK); |
| 2178 | 2313 |
| 2179 // No actual data will be sent. | 2314 // No actual data will be sent. |
| 2180 MockWrite writes[] = { | 2315 MockWrite writes[] = { |
| (...skipping 2120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4301 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); | 4436 EXPECT_TRUE(stream2->send_stalled_by_flow_control()); |
| 4302 | 4437 |
| 4303 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); | 4438 EXPECT_TRUE(HasSpdySession(spdy_session_pool_, key_)); |
| 4304 | 4439 |
| 4305 // Unstall stream1. | 4440 // Unstall stream1. |
| 4306 UnstallSessionSend(session.get(), kBodyDataSize); | 4441 UnstallSessionSend(session.get(), kBodyDataSize); |
| 4307 | 4442 |
| 4308 // Close the session (since we can't do it from within the delegate | 4443 // Close the session (since we can't do it from within the delegate |
| 4309 // method, since it's in the stream's loop). | 4444 // method, since it's in the stream's loop). |
| 4310 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, "Closing session"); | 4445 session->CloseSessionOnError(ERR_CONNECTION_CLOSED, "Closing session"); |
| 4446 base::RunLoop().RunUntilIdle(); |
| 4311 EXPECT_TRUE(session == NULL); | 4447 EXPECT_TRUE(session == NULL); |
| 4312 | 4448 |
| 4313 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); | 4449 EXPECT_FALSE(HasSpdySession(spdy_session_pool_, key_)); |
| 4314 | 4450 |
| 4315 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); | 4451 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate1.WaitForClose()); |
| 4316 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); | 4452 EXPECT_EQ(ERR_CONNECTION_CLOSED, delegate2.WaitForClose()); |
| 4317 | 4453 |
| 4318 EXPECT_TRUE(delegate1.send_headers_completed()); | 4454 EXPECT_TRUE(delegate1.send_headers_completed()); |
| 4319 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); | 4455 EXPECT_EQ(std::string(), delegate1.TakeReceivedData()); |
| 4320 | 4456 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4345 RST_STREAM_PROTOCOL_ERROR)); | 4481 RST_STREAM_PROTOCOL_ERROR)); |
| 4346 CHECK_EQ(STATUS_CODE_FRAME_SIZE_ERROR, | 4482 CHECK_EQ(STATUS_CODE_FRAME_SIZE_ERROR, |
| 4347 MapRstStreamStatusToProtocolError( | 4483 MapRstStreamStatusToProtocolError( |
| 4348 RST_STREAM_FRAME_SIZE_ERROR)); | 4484 RST_STREAM_FRAME_SIZE_ERROR)); |
| 4349 CHECK_EQ(STATUS_CODE_ENHANCE_YOUR_CALM, | 4485 CHECK_EQ(STATUS_CODE_ENHANCE_YOUR_CALM, |
| 4350 MapRstStreamStatusToProtocolError( | 4486 MapRstStreamStatusToProtocolError( |
| 4351 RST_STREAM_ENHANCE_YOUR_CALM)); | 4487 RST_STREAM_ENHANCE_YOUR_CALM)); |
| 4352 } | 4488 } |
| 4353 | 4489 |
| 4354 } // namespace net | 4490 } // namespace net |
| OLD | NEW |