OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/spdy/spdy_session_pool.h" | 5 #include "net/spdy/spdy_session_pool.h" |
6 | 6 |
7 #include <cstddef> | 7 #include <cstddef> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 CreateNetworkSession(); | 530 CreateNetworkSession(); |
531 | 531 |
532 // Set up session A: Going away, but with an active stream. | 532 // Set up session A: Going away, but with an active stream. |
533 session_deps_.socket_factory->AddSocketDataProvider(&data); | 533 session_deps_.socket_factory->AddSocketDataProvider(&data); |
534 const std::string kTestHostA("http://www.a.com"); | 534 const std::string kTestHostA("http://www.a.com"); |
535 HostPortPair test_host_port_pairA(kTestHostA, 80); | 535 HostPortPair test_host_port_pairA(kTestHostA, 80); |
536 SpdySessionKey keyA( | 536 SpdySessionKey keyA( |
537 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 537 test_host_port_pairA, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
538 base::WeakPtr<SpdySession> sessionA = | 538 base::WeakPtr<SpdySession> sessionA = |
539 CreateInsecureSpdySession(http_session_, keyA, BoundNetLog()); | 539 CreateInsecureSpdySession(http_session_, keyA, BoundNetLog()); |
| 540 |
540 GURL urlA(kTestHostA); | 541 GURL urlA(kTestHostA); |
541 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( | 542 base::WeakPtr<SpdyStream> spdy_streamA = CreateStreamSynchronously( |
542 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, BoundNetLog()); | 543 SPDY_BIDIRECTIONAL_STREAM, sessionA, urlA, MEDIUM, BoundNetLog()); |
543 test::StreamDelegateDoNothing delegateA(spdy_streamA); | 544 test::StreamDelegateDoNothing delegateA(spdy_streamA); |
544 spdy_streamA->SetDelegate(&delegateA); | 545 spdy_streamA->SetDelegate(&delegateA); |
545 | 546 |
546 scoped_ptr<SpdyHeaderBlock> headers( | 547 scoped_ptr<SpdyHeaderBlock> headers( |
547 spdy_util.ConstructGetHeaderBlock(urlA.spec())); | 548 spdy_util.ConstructGetHeaderBlock(urlA.spec())); |
548 spdy_streamA->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); | 549 spdy_streamA->SendRequestHeaders(headers.Pass(), NO_MORE_DATA_TO_SEND); |
549 EXPECT_TRUE(spdy_streamA->HasUrlFromHeaders()); | 550 EXPECT_TRUE(spdy_streamA->HasUrlFromHeaders()); |
550 | 551 |
551 base::MessageLoop::current()->RunUntilIdle(); // Allow headers to write. | 552 base::MessageLoop::current()->RunUntilIdle(); // Allow headers to write. |
552 EXPECT_TRUE(delegateA.send_headers_completed()); | 553 EXPECT_TRUE(delegateA.send_headers_completed()); |
553 | 554 |
554 sessionA->MakeUnavailable(); | 555 sessionA->MakeUnavailable(); |
555 EXPECT_TRUE(sessionA->IsGoingAway()); | 556 EXPECT_TRUE(sessionA->IsGoingAway()); |
556 EXPECT_FALSE(delegateA.StreamIsClosed()); | 557 EXPECT_FALSE(delegateA.StreamIsClosed()); |
557 | 558 |
558 // Set up session B: Available, but idle. | 559 // Set up session B: Available, with a created stream. |
559 const std::string kTestHostB("http://www.b.com"); | 560 const std::string kTestHostB("http://www.b.com"); |
560 HostPortPair test_host_port_pairB(kTestHostB, 80); | 561 HostPortPair test_host_port_pairB(kTestHostB, 80); |
561 SpdySessionKey keyB( | 562 SpdySessionKey keyB( |
562 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 563 test_host_port_pairB, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
563 base::WeakPtr<SpdySession> sessionB = | 564 base::WeakPtr<SpdySession> sessionB = |
564 CreateInsecureSpdySession(http_session_, keyB, BoundNetLog()); | 565 CreateInsecureSpdySession(http_session_, keyB, BoundNetLog()); |
565 EXPECT_TRUE(sessionB->IsAvailable()); | 566 EXPECT_TRUE(sessionB->IsAvailable()); |
566 | 567 |
| 568 GURL urlB(kTestHostB); |
| 569 base::WeakPtr<SpdyStream> spdy_streamB = CreateStreamSynchronously( |
| 570 SPDY_BIDIRECTIONAL_STREAM, sessionB, urlB, MEDIUM, BoundNetLog()); |
| 571 test::StreamDelegateDoNothing delegateB(spdy_streamB); |
| 572 spdy_streamB->SetDelegate(&delegateB); |
| 573 |
567 // Set up session C: Draining. | 574 // Set up session C: Draining. |
568 session_deps_.socket_factory->AddSocketDataProvider(&data); | 575 session_deps_.socket_factory->AddSocketDataProvider(&data); |
569 const std::string kTestHostC("http://www.c.com"); | 576 const std::string kTestHostC("http://www.c.com"); |
570 HostPortPair test_host_port_pairC(kTestHostC, 80); | 577 HostPortPair test_host_port_pairC(kTestHostC, 80); |
571 SpdySessionKey keyC( | 578 SpdySessionKey keyC( |
572 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 579 test_host_port_pairC, ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
573 base::WeakPtr<SpdySession> sessionC = | 580 base::WeakPtr<SpdySession> sessionC = |
574 CreateInsecureSpdySession(http_session_, keyC, BoundNetLog()); | 581 CreateInsecureSpdySession(http_session_, keyC, BoundNetLog()); |
575 | 582 |
576 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); | 583 sessionC->CloseSessionOnError(ERR_SPDY_PROTOCOL_ERROR, "Error!"); |
577 EXPECT_TRUE(sessionC->IsDraining()); | 584 EXPECT_TRUE(sessionC->IsDraining()); |
578 | 585 |
579 spdy_session_pool_->OnIPAddressChanged(); | 586 spdy_session_pool_->OnIPAddressChanged(); |
580 | 587 |
581 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 588 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
582 EXPECT_TRUE(sessionA->IsGoingAway()); | 589 EXPECT_TRUE(sessionA->IsGoingAway()); |
583 EXPECT_TRUE(sessionB->IsDraining()); | 590 EXPECT_TRUE(sessionB->IsDraining()); |
584 EXPECT_TRUE(sessionC->IsDraining()); | 591 EXPECT_TRUE(sessionC->IsDraining()); |
585 | 592 |
586 EXPECT_EQ(1u, sessionA->num_active_streams()); // Stream is still active. | 593 EXPECT_EQ(1u, |
| 594 sessionA->num_active_streams()); // Active stream is still active. |
587 EXPECT_FALSE(delegateA.StreamIsClosed()); | 595 EXPECT_FALSE(delegateA.StreamIsClosed()); |
588 | 596 |
| 597 EXPECT_TRUE(delegateB.StreamIsClosed()); // Created stream was closed. |
| 598 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateB.WaitForClose()); |
| 599 |
589 sessionA->CloseSessionOnError(ERR_ABORTED, "Closing"); | 600 sessionA->CloseSessionOnError(ERR_ABORTED, "Closing"); |
590 sessionB->CloseSessionOnError(ERR_ABORTED, "Closing"); | 601 sessionB->CloseSessionOnError(ERR_ABORTED, "Closing"); |
591 | 602 |
592 EXPECT_TRUE(delegateA.StreamIsClosed()); | 603 EXPECT_TRUE(delegateA.StreamIsClosed()); |
593 EXPECT_EQ(ERR_ABORTED, delegateA.WaitForClose()); | 604 EXPECT_EQ(ERR_ABORTED, delegateA.WaitForClose()); |
594 #else | 605 #else |
595 EXPECT_TRUE(sessionA->IsDraining()); | 606 EXPECT_TRUE(sessionA->IsDraining()); |
596 EXPECT_TRUE(sessionB->IsDraining()); | 607 EXPECT_TRUE(sessionB->IsDraining()); |
597 EXPECT_TRUE(sessionC->IsDraining()); | 608 EXPECT_TRUE(sessionC->IsDraining()); |
598 | 609 |
| 610 // Both streams were closed with an error. |
599 EXPECT_TRUE(delegateA.StreamIsClosed()); | 611 EXPECT_TRUE(delegateA.StreamIsClosed()); |
600 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateA.WaitForClose()); | 612 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateA.WaitForClose()); |
| 613 EXPECT_TRUE(delegateB.StreamIsClosed()); |
| 614 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateB.WaitForClose()); |
601 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 615 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
602 } | 616 } |
603 | 617 |
604 } // namespace | 618 } // namespace |
605 | 619 |
606 } // namespace net | 620 } // namespace net |
OLD | NEW |