| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "net/dns/host_cache.h" | 14 #include "net/dns/host_cache.h" |
| 15 #include "net/http/http_network_session.h" | 15 #include "net/http/http_network_session.h" |
| 16 #include "net/socket/client_socket_handle.h" | 16 #include "net/socket/client_socket_handle.h" |
| 17 #include "net/socket/transport_client_socket_pool.h" | 17 #include "net/socket/transport_client_socket_pool.h" |
| 18 #include "net/spdy/spdy_session.h" | 18 #include "net/spdy/spdy_session.h" |
| 19 #include "net/spdy/spdy_stream_test_util.h" | 19 #include "net/spdy/spdy_stream_test_util.h" |
| 20 #include "net/spdy/spdy_test_util_common.h" | 20 #include "net/spdy/spdy_test_util_common.h" |
| 21 #include "net/test/gtest_util.h" |
| 22 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 24 |
| 25 using net::test::IsError; |
| 26 using net::test::IsOk; |
| 27 |
| 23 namespace net { | 28 namespace net { |
| 24 | 29 |
| 25 class SpdySessionPoolTest : public ::testing::Test, | 30 class SpdySessionPoolTest : public ::testing::Test, |
| 26 public ::testing::WithParamInterface<NextProto> { | 31 public ::testing::WithParamInterface<NextProto> { |
| 27 protected: | 32 protected: |
| 28 // Used by RunIPPoolingTest(). | 33 // Used by RunIPPoolingTest(). |
| 29 enum SpdyPoolCloseSessionsType { | 34 enum SpdyPoolCloseSessionsType { |
| 30 SPDY_POOL_CLOSE_SESSIONS_MANUALLY, | 35 SPDY_POOL_CLOSE_SESSIONS_MANUALLY, |
| 31 SPDY_POOL_CLOSE_CURRENT_SESSIONS, | 36 SPDY_POOL_CLOSE_CURRENT_SESSIONS, |
| 32 SPDY_POOL_CLOSE_IDLE_SESSIONS, | 37 SPDY_POOL_CLOSE_IDLE_SESSIONS, |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 611 #if defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
| 607 EXPECT_TRUE(sessionA->IsGoingAway()); | 612 EXPECT_TRUE(sessionA->IsGoingAway()); |
| 608 EXPECT_TRUE(sessionB->IsDraining()); | 613 EXPECT_TRUE(sessionB->IsDraining()); |
| 609 EXPECT_TRUE(sessionC->IsDraining()); | 614 EXPECT_TRUE(sessionC->IsDraining()); |
| 610 | 615 |
| 611 EXPECT_EQ(1u, | 616 EXPECT_EQ(1u, |
| 612 sessionA->num_active_streams()); // Active stream is still active. | 617 sessionA->num_active_streams()); // Active stream is still active. |
| 613 EXPECT_FALSE(delegateA.StreamIsClosed()); | 618 EXPECT_FALSE(delegateA.StreamIsClosed()); |
| 614 | 619 |
| 615 EXPECT_TRUE(delegateB.StreamIsClosed()); // Created stream was closed. | 620 EXPECT_TRUE(delegateB.StreamIsClosed()); // Created stream was closed. |
| 616 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateB.WaitForClose()); | 621 EXPECT_THAT(delegateB.WaitForClose(), IsError(ERR_NETWORK_CHANGED)); |
| 617 | 622 |
| 618 sessionA->CloseSessionOnError(ERR_ABORTED, "Closing"); | 623 sessionA->CloseSessionOnError(ERR_ABORTED, "Closing"); |
| 619 sessionB->CloseSessionOnError(ERR_ABORTED, "Closing"); | 624 sessionB->CloseSessionOnError(ERR_ABORTED, "Closing"); |
| 620 | 625 |
| 621 EXPECT_TRUE(delegateA.StreamIsClosed()); | 626 EXPECT_TRUE(delegateA.StreamIsClosed()); |
| 622 EXPECT_EQ(ERR_ABORTED, delegateA.WaitForClose()); | 627 EXPECT_THAT(delegateA.WaitForClose(), IsError(ERR_ABORTED)); |
| 623 #else | 628 #else |
| 624 EXPECT_TRUE(sessionA->IsDraining()); | 629 EXPECT_TRUE(sessionA->IsDraining()); |
| 625 EXPECT_TRUE(sessionB->IsDraining()); | 630 EXPECT_TRUE(sessionB->IsDraining()); |
| 626 EXPECT_TRUE(sessionC->IsDraining()); | 631 EXPECT_TRUE(sessionC->IsDraining()); |
| 627 | 632 |
| 628 // Both streams were closed with an error. | 633 // Both streams were closed with an error. |
| 629 EXPECT_TRUE(delegateA.StreamIsClosed()); | 634 EXPECT_TRUE(delegateA.StreamIsClosed()); |
| 630 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateA.WaitForClose()); | 635 EXPECT_THAT(delegateA.WaitForClose(), IsError(ERR_NETWORK_CHANGED)); |
| 631 EXPECT_TRUE(delegateB.StreamIsClosed()); | 636 EXPECT_TRUE(delegateB.StreamIsClosed()); |
| 632 EXPECT_EQ(ERR_NETWORK_CHANGED, delegateB.WaitForClose()); | 637 EXPECT_THAT(delegateB.WaitForClose(), IsError(ERR_NETWORK_CHANGED)); |
| 633 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) | 638 #endif // defined(OS_ANDROID) || defined(OS_WIN) || defined(OS_IOS) |
| 634 } | 639 } |
| 635 | 640 |
| 636 TEST_P(SpdySessionPoolTest, FindAvailableSession) { | 641 TEST_P(SpdySessionPoolTest, FindAvailableSession) { |
| 637 SpdySessionKey key(HostPortPair("https://www.example.org", 443), | 642 SpdySessionKey key(HostPortPair("https://www.example.org", 443), |
| 638 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); | 643 ProxyServer::Direct(), PRIVACY_MODE_DISABLED); |
| 639 | 644 |
| 640 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; | 645 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING)}; |
| 641 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); | 646 StaticSocketDataProvider data(reads, arraysize(reads), nullptr, 0); |
| 642 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); | 647 data.set_connect_data(MockConnect(SYNCHRONOUS, OK)); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 664 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. | 669 // there is no pushed stream on any sessions owned by |spdy_session_pool_|. |
| 665 base::WeakPtr<SpdySession> session2 = | 670 base::WeakPtr<SpdySession> session2 = |
| 666 spdy_session_pool_->FindAvailableSession( | 671 spdy_session_pool_->FindAvailableSession( |
| 667 key, GURL("http://news.example.org/foo.html"), BoundNetLog()); | 672 key, GURL("http://news.example.org/foo.html"), BoundNetLog()); |
| 668 EXPECT_EQ(session.get(), session2.get()); | 673 EXPECT_EQ(session.get(), session2.get()); |
| 669 | 674 |
| 670 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); | 675 spdy_session_pool_->CloseCurrentSessions(ERR_ABORTED); |
| 671 } | 676 } |
| 672 | 677 |
| 673 } // namespace net | 678 } // namespace net |
| OLD | NEW |