| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "net/base/ip_endpoint.h" | 7 #include "net/base/ip_endpoint.h" |
| 8 #include "net/spdy/spdy_io_buffer.h" | 8 #include "net/spdy/spdy_io_buffer.h" |
| 9 #include "net/spdy/spdy_session_pool.h" | 9 #include "net/spdy/spdy_session_pool.h" |
| 10 #include "net/spdy/spdy_stream.h" | 10 #include "net/spdy/spdy_stream.h" |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 scoped_refptr<SpdySession> session = | 135 scoped_refptr<SpdySession> session = |
| 136 spdy_session_pool->Get(pair, BoundNetLog()); | 136 spdy_session_pool->Get(pair, BoundNetLog()); |
| 137 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 137 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 138 | 138 |
| 139 scoped_refptr<TransportSocketParams> transport_params( | 139 scoped_refptr<TransportSocketParams> transport_params( |
| 140 new TransportSocketParams(test_host_port_pair, | 140 new TransportSocketParams(test_host_port_pair, |
| 141 MEDIUM, | 141 MEDIUM, |
| 142 false, | 142 false, |
| 143 false)); | 143 false)); |
| 144 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 144 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 145 EXPECT_EQ(OK, | 145 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 146 connection->Init(test_host_port_pair.ToString(), | 146 transport_params, MEDIUM, CompletionCallback(), |
| 147 transport_params, MEDIUM, | 147 http_session->GetTransportSocketPool(), |
| 148 NULL, http_session->GetTransportSocketPool(), | 148 BoundNetLog())); |
| 149 BoundNetLog())); | |
| 150 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 149 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 151 | 150 |
| 152 // Flush the SpdySession::OnReadComplete() task. | 151 // Flush the SpdySession::OnReadComplete() task. |
| 153 MessageLoop::current()->RunAllPending(); | 152 MessageLoop::current()->RunAllPending(); |
| 154 | 153 |
| 155 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 154 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 156 | 155 |
| 157 scoped_refptr<SpdySession> session2 = | 156 scoped_refptr<SpdySession> session2 = |
| 158 spdy_session_pool->Get(pair, BoundNetLog()); | 157 spdy_session_pool->Get(pair, BoundNetLog()); |
| 159 | 158 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 spdy_session_pool->Get(pair, BoundNetLog()); | 205 spdy_session_pool->Get(pair, BoundNetLog()); |
| 207 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 206 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 208 | 207 |
| 209 | 208 |
| 210 scoped_refptr<TransportSocketParams> transport_params( | 209 scoped_refptr<TransportSocketParams> transport_params( |
| 211 new TransportSocketParams(test_host_port_pair, | 210 new TransportSocketParams(test_host_port_pair, |
| 212 MEDIUM, | 211 MEDIUM, |
| 213 false, | 212 false, |
| 214 false)); | 213 false)); |
| 215 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 214 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 216 EXPECT_EQ(OK, | 215 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 217 connection->Init(test_host_port_pair.ToString(), | 216 transport_params, MEDIUM, CompletionCallback(), |
| 218 transport_params, | 217 http_session->GetTransportSocketPool(), |
| 219 MEDIUM, | 218 BoundNetLog())); |
| 220 NULL, | |
| 221 http_session->GetTransportSocketPool(), | |
| 222 BoundNetLog())); | |
| 223 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 219 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 224 | 220 |
| 225 scoped_refptr<SpdyStream> spdy_stream1; | 221 scoped_refptr<SpdyStream> spdy_stream1; |
| 226 TestOldCompletionCallback callback1; | 222 TestOldCompletionCallback callback1; |
| 227 EXPECT_EQ(OK, session->CreateStream(url, | 223 EXPECT_EQ(OK, session->CreateStream(url, |
| 228 MEDIUM, | 224 MEDIUM, |
| 229 &spdy_stream1, | 225 &spdy_stream1, |
| 230 BoundNetLog(), | 226 BoundNetLog(), |
| 231 &callback1)); | 227 &callback1)); |
| 232 scoped_ptr<TestSpdyStreamDelegate> delegate( | 228 scoped_ptr<TestSpdyStreamDelegate> delegate( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 scoped_refptr<SpdySession> session = | 293 scoped_refptr<SpdySession> session = |
| 298 spdy_session_pool->Get(pair, BoundNetLog()); | 294 spdy_session_pool->Get(pair, BoundNetLog()); |
| 299 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 295 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 300 | 296 |
| 301 scoped_refptr<TransportSocketParams> transport_params( | 297 scoped_refptr<TransportSocketParams> transport_params( |
| 302 new TransportSocketParams(test_host_port_pair, | 298 new TransportSocketParams(test_host_port_pair, |
| 303 MEDIUM, | 299 MEDIUM, |
| 304 false, | 300 false, |
| 305 false)); | 301 false)); |
| 306 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 302 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 307 EXPECT_EQ(OK, | 303 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 308 connection->Init(test_host_port_pair.ToString(), | 304 transport_params, MEDIUM, CompletionCallback(), |
| 309 transport_params, | 305 http_session->GetTransportSocketPool(), |
| 310 MEDIUM, | 306 BoundNetLog())); |
| 311 NULL, | |
| 312 http_session->GetTransportSocketPool(), | |
| 313 BoundNetLog())); | |
| 314 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 307 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 315 | 308 |
| 316 scoped_refptr<SpdyStream> spdy_stream1; | 309 scoped_refptr<SpdyStream> spdy_stream1; |
| 317 TestOldCompletionCallback callback1; | 310 TestOldCompletionCallback callback1; |
| 318 EXPECT_EQ(OK, session->CreateStream(url, | 311 EXPECT_EQ(OK, session->CreateStream(url, |
| 319 MEDIUM, | 312 MEDIUM, |
| 320 &spdy_stream1, | 313 &spdy_stream1, |
| 321 BoundNetLog(), | 314 BoundNetLog(), |
| 322 &callback1)); | 315 &callback1)); |
| 323 scoped_ptr<TestSpdyStreamDelegate> delegate( | 316 scoped_ptr<TestSpdyStreamDelegate> delegate( |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 scoped_refptr<SpdySession> session = | 536 scoped_refptr<SpdySession> session = |
| 544 spdy_session_pool->Get(pair, BoundNetLog()); | 537 spdy_session_pool->Get(pair, BoundNetLog()); |
| 545 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); | 538 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 546 | 539 |
| 547 scoped_refptr<TransportSocketParams> transport_params( | 540 scoped_refptr<TransportSocketParams> transport_params( |
| 548 new TransportSocketParams(test_host_port_pair, | 541 new TransportSocketParams(test_host_port_pair, |
| 549 MEDIUM, | 542 MEDIUM, |
| 550 false, | 543 false, |
| 551 false)); | 544 false)); |
| 552 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 545 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 553 EXPECT_EQ(OK, | 546 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 554 connection->Init(test_host_port_pair.ToString(), | 547 transport_params, MEDIUM, CompletionCallback(), |
| 555 transport_params, MEDIUM, | 548 http_session->GetTransportSocketPool(), |
| 556 NULL, http_session->GetTransportSocketPool(), | 549 BoundNetLog())); |
| 557 BoundNetLog())); | |
| 558 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 550 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 559 | 551 |
| 560 // Create 2 streams. First will succeed. Second will be pending. | 552 // Create 2 streams. First will succeed. Second will be pending. |
| 561 scoped_refptr<SpdyStream> spdy_stream1; | 553 scoped_refptr<SpdyStream> spdy_stream1; |
| 562 TestOldCompletionCallback callback1; | 554 TestOldCompletionCallback callback1; |
| 563 GURL url("http://www.google.com"); | 555 GURL url("http://www.google.com"); |
| 564 EXPECT_EQ(OK, | 556 EXPECT_EQ(OK, |
| 565 session->CreateStream(url, | 557 session->CreateStream(url, |
| 566 MEDIUM, /* priority, not important */ | 558 MEDIUM, /* priority, not important */ |
| 567 &spdy_stream1, | 559 &spdy_stream1, |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 628 scoped_refptr<SpdySession> session = | 620 scoped_refptr<SpdySession> session = |
| 629 spdy_session_pool->Get(pair, BoundNetLog()); | 621 spdy_session_pool->Get(pair, BoundNetLog()); |
| 630 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); | 622 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 631 | 623 |
| 632 scoped_refptr<TransportSocketParams> transport_params( | 624 scoped_refptr<TransportSocketParams> transport_params( |
| 633 new TransportSocketParams(test_host_port_pair, | 625 new TransportSocketParams(test_host_port_pair, |
| 634 MEDIUM, | 626 MEDIUM, |
| 635 false, | 627 false, |
| 636 false)); | 628 false)); |
| 637 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 629 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 638 EXPECT_EQ(OK, | 630 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 639 connection->Init(test_host_port_pair.ToString(), | 631 transport_params, MEDIUM, CompletionCallback(), |
| 640 transport_params, MEDIUM, | 632 http_session->GetTransportSocketPool(), |
| 641 NULL, http_session->GetTransportSocketPool(), | 633 BoundNetLog())); |
| 642 BoundNetLog())); | |
| 643 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 634 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 644 | 635 |
| 645 // Use scoped_ptr to let us invalidate the memory when we want to, to trigger | 636 // Use scoped_ptr to let us invalidate the memory when we want to, to trigger |
| 646 // a valgrind error if the callback is invoked when it's not supposed to be. | 637 // a valgrind error if the callback is invoked when it's not supposed to be. |
| 647 scoped_ptr<TestOldCompletionCallback> callback(new TestOldCompletionCallback); | 638 scoped_ptr<TestOldCompletionCallback> callback(new TestOldCompletionCallback); |
| 648 | 639 |
| 649 // Create 2 streams. First will succeed. Second will be pending. | 640 // Create 2 streams. First will succeed. Second will be pending. |
| 650 scoped_refptr<SpdyStream> spdy_stream1; | 641 scoped_refptr<SpdyStream> spdy_stream1; |
| 651 GURL url("http://www.google.com"); | 642 GURL url("http://www.google.com"); |
| 652 ASSERT_EQ(OK, | 643 ASSERT_EQ(OK, |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 scoped_refptr<SpdySession> session = | 718 scoped_refptr<SpdySession> session = |
| 728 spdy_session_pool->Get(pair, BoundNetLog()); | 719 spdy_session_pool->Get(pair, BoundNetLog()); |
| 729 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 720 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 730 | 721 |
| 731 scoped_refptr<TransportSocketParams> transport_params( | 722 scoped_refptr<TransportSocketParams> transport_params( |
| 732 new TransportSocketParams(test_host_port_pair, | 723 new TransportSocketParams(test_host_port_pair, |
| 733 MEDIUM, | 724 MEDIUM, |
| 734 false, | 725 false, |
| 735 false)); | 726 false)); |
| 736 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 727 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 737 EXPECT_EQ(OK, | 728 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 738 connection->Init(test_host_port_pair.ToString(), | 729 transport_params, MEDIUM, CompletionCallback(), |
| 739 transport_params, MEDIUM, | 730 http_session->GetTransportSocketPool(), |
| 740 NULL, http_session->GetTransportSocketPool(), | 731 BoundNetLog())); |
| 741 BoundNetLog())); | |
| 742 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 732 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 743 MessageLoop::current()->RunAllPending(); | 733 MessageLoop::current()->RunAllPending(); |
| 744 EXPECT_TRUE(data.at_write_eof()); | 734 EXPECT_TRUE(data.at_write_eof()); |
| 745 } | 735 } |
| 746 | 736 |
| 747 // This test has two variants, one for each style of closing the connection. | 737 // This test has two variants, one for each style of closing the connection. |
| 748 // If |clean_via_close_current_sessions| is false, the sessions are closed | 738 // If |clean_via_close_current_sessions| is false, the sessions are closed |
| 749 // manually, calling SpdySessionPool::Remove() directly. If it is true, | 739 // manually, calling SpdySessionPool::Remove() directly. If it is true, |
| 750 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). | 740 // sessions are closed with SpdySessionPool::CloseCurrentSessions(). |
| 751 void IPPoolingTest(bool clean_via_close_current_sessions) { | 741 void IPPoolingTest(bool clean_via_close_current_sessions) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 801 spdy_session_pool->Get(test_hosts[0].pair, BoundNetLog()); | 791 spdy_session_pool->Get(test_hosts[0].pair, BoundNetLog()); |
| 802 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); | 792 EXPECT_TRUE(spdy_session_pool->HasSession(test_hosts[0].pair)); |
| 803 | 793 |
| 804 HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); | 794 HostPortPair test_host_port_pair(test_hosts[0].name, kTestPort); |
| 805 scoped_refptr<TransportSocketParams> transport_params( | 795 scoped_refptr<TransportSocketParams> transport_params( |
| 806 new TransportSocketParams(test_host_port_pair, | 796 new TransportSocketParams(test_host_port_pair, |
| 807 MEDIUM, | 797 MEDIUM, |
| 808 false, | 798 false, |
| 809 false)); | 799 false)); |
| 810 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 800 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
| 811 EXPECT_EQ(OK, | 801 EXPECT_EQ(OK, connection->Init(test_host_port_pair.ToString(), |
| 812 connection->Init(test_host_port_pair.ToString(), | 802 transport_params, MEDIUM, CompletionCallback(), |
| 813 transport_params, MEDIUM, | 803 http_session->GetTransportSocketPool(), |
| 814 NULL, http_session->GetTransportSocketPool(), | 804 BoundNetLog())); |
| 815 BoundNetLog())); | |
| 816 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); | 805 EXPECT_EQ(OK, session->InitializeWithSocket(connection.release(), false, OK)); |
| 817 | 806 |
| 818 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port | 807 // TODO(rtenneti): MockClientSocket::GetPeerAddress return's 0 as the port |
| 819 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. | 808 // number. Fix it to return port 80 and then use GetPeerAddress to AddAlias. |
| 820 const addrinfo* address = test_hosts[0].addresses.head(); | 809 const addrinfo* address = test_hosts[0].addresses.head(); |
| 821 SpdySessionPoolPeer pool_peer(spdy_session_pool); | 810 SpdySessionPoolPeer pool_peer(spdy_session_pool); |
| 822 pool_peer.AddAlias(address, test_hosts[0].pair); | 811 pool_peer.AddAlias(address, test_hosts[0].pair); |
| 823 | 812 |
| 824 // Flush the SpdySession::OnReadComplete() task. | 813 // Flush the SpdySession::OnReadComplete() task. |
| 825 MessageLoop::current()->RunAllPending(); | 814 MessageLoop::current()->RunAllPending(); |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 test_http_server_properties->SetSpdySettings(test_host_port_pair, | 900 test_http_server_properties->SetSpdySettings(test_host_port_pair, |
| 912 test_settings); | 901 test_settings); |
| 913 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( | 902 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( |
| 914 test_host_port_pair).size()); | 903 test_host_port_pair).size()); |
| 915 spdy_session_pool->OnIPAddressChanged(); | 904 spdy_session_pool->OnIPAddressChanged(); |
| 916 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( | 905 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( |
| 917 test_host_port_pair).size()); | 906 test_host_port_pair).size()); |
| 918 } | 907 } |
| 919 | 908 |
| 920 } // namespace net | 909 } // namespace net |
| OLD | NEW |