| 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 "net/base/ip_endpoint.h" | 7 #include "net/base/ip_endpoint.h" |
| 8 #include "net/base/net_log_unittest.h" | 8 #include "net/base/net_log_unittest.h" |
| 9 #include "net/spdy/spdy_io_buffer.h" | 9 #include "net/spdy/spdy_io_buffer.h" |
| 10 #include "net/spdy/spdy_session_pool.h" | 10 #include "net/spdy/spdy_session_pool.h" |
| 11 #include "net/spdy/spdy_stream.h" | 11 #include "net/spdy/spdy_stream.h" |
| 12 #include "net/spdy/spdy_test_util_spdy3.h" | 12 #include "net/spdy/spdy_test_util_spdy3.h" |
| 13 #include "testing/platform_test.h" | 13 #include "testing/platform_test.h" |
| 14 | 14 |
| 15 using namespace net::test_spdy3; | 15 using namespace net::test_spdy3; |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 // TODO(cbentzel): Expose compression setter/getter in public SpdySession | 19 // TODO(cbentzel): Expose compression setter/getter in public SpdySession |
| 20 // interface rather than going through all these contortions. | 20 // interface rather than going through all these contortions. |
| 21 class SpdySessionSpdy3Test : public PlatformTest { | 21 class SpdySessionSpdy3Test : public PlatformTest { |
| 22 public: | 22 public: |
| 23 static void TurnOffCompression() { | 23 static void TurnOffCompression() { |
| 24 spdy::SpdyFramer::set_enable_compression_default(false); | 24 spdy::SpdyFramer::set_enable_compression_default(false); |
| 25 } | 25 } |
| 26 protected: | 26 protected: |
| 27 virtual void SetUp() { |
| 28 SpdySession::set_default_protocol(SSLClientSocket::kProtoSPDY3); |
| 29 } |
| 30 |
| 27 virtual void TearDown() { | 31 virtual void TearDown() { |
| 28 // Wanted to be 100% sure PING is disabled. | 32 // Wanted to be 100% sure PING is disabled. |
| 29 SpdySession::set_enable_ping_based_connection_checking(false); | 33 SpdySession::set_enable_ping_based_connection_checking(false); |
| 30 } | 34 } |
| 31 }; | 35 }; |
| 32 | 36 |
| 33 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { | 37 class TestSpdyStreamDelegate : public net::SpdyStream::Delegate { |
| 34 public: | 38 public: |
| 35 explicit TestSpdyStreamDelegate(const CompletionCallback& callback) | 39 explicit TestSpdyStreamDelegate(const CompletionCallback& callback) |
| 36 : callback_(callback) {} | 40 : callback_(callback) {} |
| (...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Start with max concurrent streams set to 1. Request two streams. Receive a | 494 // Start with max concurrent streams set to 1. Request two streams. Receive a |
| 491 // settings frame setting max concurrent streams to 2. Have the callback | 495 // settings frame setting max concurrent streams to 2. Have the callback |
| 492 // release the stream, which releases its reference (the last) to the session. | 496 // release the stream, which releases its reference (the last) to the session. |
| 493 // Make sure nothing blows up. | 497 // Make sure nothing blows up. |
| 494 // http://crbug.com/57331 | 498 // http://crbug.com/57331 |
| 495 TEST_F(SpdySessionSpdy3Test, OnSettings) { | 499 TEST_F(SpdySessionSpdy3Test, OnSettings) { |
| 496 SpdySessionDependencies session_deps; | 500 SpdySessionDependencies session_deps; |
| 497 session_deps.host_resolver->set_synchronous_mode(true); | 501 session_deps.host_resolver->set_synchronous_mode(true); |
| 498 | 502 |
| 499 spdy::SpdySettings new_settings; | 503 spdy::SpdySettings new_settings; |
| 500 spdy::SettingsFlagsAndId id(0); | 504 spdy::SettingsFlagsAndId id(0, spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 501 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); | |
| 502 const size_t max_concurrent_streams = 2; | 505 const size_t max_concurrent_streams = 2; |
| 503 new_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); | 506 new_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); |
| 504 | 507 |
| 505 // Set up the socket so we read a SETTINGS frame that raises max concurrent | 508 // Set up the socket so we read a SETTINGS frame that raises max concurrent |
| 506 // streams to 2. | 509 // streams to 2. |
| 507 MockConnect connect_data(SYNCHRONOUS, OK); | 510 MockConnect connect_data(SYNCHRONOUS, OK); |
| 508 scoped_ptr<spdy::SpdyFrame> settings_frame( | 511 scoped_ptr<spdy::SpdyFrame> settings_frame( |
| 509 ConstructSpdySettings(new_settings)); | 512 ConstructSpdySettings(new_settings)); |
| 510 MockRead reads[] = { | 513 MockRead reads[] = { |
| 511 CreateMockRead(*settings_frame), | 514 CreateMockRead(*settings_frame), |
| (...skipping 11 matching lines...) Expand all Loading... |
| 523 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 526 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 524 | 527 |
| 525 const std::string kTestHost("www.foo.com"); | 528 const std::string kTestHost("www.foo.com"); |
| 526 const int kTestPort = 80; | 529 const int kTestPort = 80; |
| 527 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 530 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 528 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 531 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 529 | 532 |
| 530 // Initialize the SpdySettingsStorage with 1 max concurrent streams. | 533 // Initialize the SpdySettingsStorage with 1 max concurrent streams. |
| 531 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 534 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 532 spdy::SpdySettings old_settings; | 535 spdy::SpdySettings old_settings; |
| 533 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 536 spdy::SettingsFlagsAndId id1(spdy::SETTINGS_FLAG_PLEASE_PERSIST, id.id()); |
| 534 old_settings.push_back(spdy::SpdySetting(id, 1)); | 537 old_settings.push_back(spdy::SpdySetting(id1, 1)); |
| 535 spdy_session_pool->http_server_properties()->SetSpdySettings( | 538 spdy_session_pool->http_server_properties()->SetSpdySettings( |
| 536 test_host_port_pair, old_settings); | 539 test_host_port_pair, old_settings); |
| 537 | 540 |
| 538 // Create a session. | 541 // Create a session. |
| 539 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 542 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 540 scoped_refptr<SpdySession> session = | 543 scoped_refptr<SpdySession> session = |
| 541 spdy_session_pool->Get(pair, BoundNetLog()); | 544 spdy_session_pool->Get(pair, BoundNetLog()); |
| 542 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); | 545 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 543 | 546 |
| 544 scoped_refptr<TransportSocketParams> transport_params( | 547 scoped_refptr<TransportSocketParams> transport_params( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 608 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 606 | 609 |
| 607 const std::string kTestHost("www.foo.com"); | 610 const std::string kTestHost("www.foo.com"); |
| 608 const int kTestPort = 80; | 611 const int kTestPort = 80; |
| 609 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 612 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 610 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 613 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 611 | 614 |
| 612 // Initialize the SpdySettingsStorage with 1 max concurrent streams. | 615 // Initialize the SpdySettingsStorage with 1 max concurrent streams. |
| 613 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 616 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 614 spdy::SpdySettings settings; | 617 spdy::SpdySettings settings; |
| 615 spdy::SettingsFlagsAndId id(0); | 618 spdy::SettingsFlagsAndId id(spdy::SETTINGS_FLAG_PLEASE_PERSIST, |
| 616 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); | 619 spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 617 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | |
| 618 settings.push_back(spdy::SpdySetting(id, 1)); | 620 settings.push_back(spdy::SpdySetting(id, 1)); |
| 619 spdy_session_pool->http_server_properties()->SetSpdySettings( | 621 spdy_session_pool->http_server_properties()->SetSpdySettings( |
| 620 test_host_port_pair, settings); | 622 test_host_port_pair, settings); |
| 621 | 623 |
| 622 // Create a session. | 624 // Create a session. |
| 623 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 625 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 624 scoped_refptr<SpdySession> session = | 626 scoped_refptr<SpdySession> session = |
| 625 spdy_session_pool->Get(pair, BoundNetLog()); | 627 spdy_session_pool->Get(pair, BoundNetLog()); |
| 626 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); | 628 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); |
| 627 | 629 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 680 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 679 }; | 681 }; |
| 680 | 682 |
| 681 // Create the bogus setting that we want to verify is sent out. | 683 // Create the bogus setting that we want to verify is sent out. |
| 682 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But | 684 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But |
| 683 // to set it into the SpdySettingsStorage, we need to mark as | 685 // to set it into the SpdySettingsStorage, we need to mark as |
| 684 // SETTINGS_FLAG_PLEASE_PERSIST. | 686 // SETTINGS_FLAG_PLEASE_PERSIST. |
| 685 spdy::SpdySettings settings; | 687 spdy::SpdySettings settings; |
| 686 const uint32 kBogusSettingId = 0xABAB; | 688 const uint32 kBogusSettingId = 0xABAB; |
| 687 const uint32 kBogusSettingValue = 0xCDCD; | 689 const uint32 kBogusSettingValue = 0xCDCD; |
| 688 spdy::SettingsFlagsAndId id(0); | 690 spdy::SettingsFlagsAndId id(spdy::SETTINGS_FLAG_PERSISTED, kBogusSettingId); |
| 689 id.set_id(kBogusSettingId); | |
| 690 id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); | |
| 691 settings.push_back(spdy::SpdySetting(id, kBogusSettingValue)); | 691 settings.push_back(spdy::SpdySetting(id, kBogusSettingValue)); |
| 692 MockConnect connect_data(SYNCHRONOUS, OK); | 692 MockConnect connect_data(SYNCHRONOUS, OK); |
| 693 scoped_ptr<spdy::SpdyFrame> settings_frame( | 693 scoped_ptr<spdy::SpdyFrame> settings_frame( |
| 694 ConstructSpdySettings(settings)); | 694 ConstructSpdySettings(settings)); |
| 695 MockWrite writes[] = { | 695 MockWrite writes[] = { |
| 696 CreateMockWrite(*settings_frame), | 696 CreateMockWrite(*settings_frame), |
| 697 }; | 697 }; |
| 698 | 698 |
| 699 StaticSocketDataProvider data( | 699 StaticSocketDataProvider data( |
| 700 reads, arraysize(reads), writes, arraysize(writes)); | 700 reads, arraysize(reads), writes, arraysize(writes)); |
| 701 data.set_connect_data(connect_data); | 701 data.set_connect_data(connect_data); |
| 702 session_deps.socket_factory->AddSocketDataProvider(&data); | 702 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 703 | 703 |
| 704 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 704 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 705 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 705 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 706 | 706 |
| 707 scoped_refptr<HttpNetworkSession> http_session( | 707 scoped_refptr<HttpNetworkSession> http_session( |
| 708 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 708 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 709 | 709 |
| 710 const std::string kTestHost("www.foo.com"); | 710 const std::string kTestHost("www.foo.com"); |
| 711 const int kTestPort = 80; | 711 const int kTestPort = 80; |
| 712 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 712 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 713 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 713 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 714 | 714 |
| 715 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | 715 spdy::SettingsFlagsAndId id1(spdy::SETTINGS_FLAG_PLEASE_PERSIST, id.id()); |
| 716 settings.clear(); | 716 settings.clear(); |
| 717 settings.push_back(spdy::SpdySetting(id, kBogusSettingValue)); | 717 settings.push_back(spdy::SpdySetting(id1, kBogusSettingValue)); |
| 718 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 718 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 719 spdy_session_pool->http_server_properties()->SetSpdySettings( | 719 spdy_session_pool->http_server_properties()->SetSpdySettings( |
| 720 test_host_port_pair, settings); | 720 test_host_port_pair, settings); |
| 721 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 721 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 722 scoped_refptr<SpdySession> session = | 722 scoped_refptr<SpdySession> session = |
| 723 spdy_session_pool->Get(pair, BoundNetLog()); | 723 spdy_session_pool->Get(pair, BoundNetLog()); |
| 724 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); | 724 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); |
| 725 | 725 |
| 726 scoped_refptr<TransportSocketParams> transport_params( | 726 scoped_refptr<TransportSocketParams> transport_params( |
| 727 new TransportSocketParams(test_host_port_pair, | 727 new TransportSocketParams(test_host_port_pair, |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 TEST_F(SpdySessionSpdy3Test, IPPoolingCloseCurrentSessions) { | 866 TEST_F(SpdySessionSpdy3Test, IPPoolingCloseCurrentSessions) { |
| 867 IPPoolingTest(true); | 867 IPPoolingTest(true); |
| 868 } | 868 } |
| 869 | 869 |
| 870 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorage) { | 870 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorage) { |
| 871 SpdySettingsStorage settings_storage; | 871 SpdySettingsStorage settings_storage; |
| 872 const std::string kTestHost("www.foo.com"); | 872 const std::string kTestHost("www.foo.com"); |
| 873 const int kTestPort = 80; | 873 const int kTestPort = 80; |
| 874 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 874 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 875 spdy::SpdySettings test_settings; | 875 spdy::SpdySettings test_settings; |
| 876 spdy::SettingsFlagsAndId id(0); | 876 spdy::SettingsFlagsAndId id(spdy::SETTINGS_FLAG_PLEASE_PERSIST, |
| 877 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); | 877 spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 878 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | |
| 879 const size_t max_concurrent_streams = 2; | 878 const size_t max_concurrent_streams = 2; |
| 880 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); | 879 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); |
| 881 | 880 |
| 882 settings_storage.Set(test_host_port_pair, test_settings); | 881 settings_storage.Set(test_host_port_pair, test_settings); |
| 883 EXPECT_NE(0u, settings_storage.Get(test_host_port_pair).size()); | 882 EXPECT_NE(0u, settings_storage.Get(test_host_port_pair).size()); |
| 884 settings_storage.Clear(); | 883 settings_storage.Clear(); |
| 885 EXPECT_EQ(0u, settings_storage.Get(test_host_port_pair).size()); | 884 EXPECT_EQ(0u, settings_storage.Get(test_host_port_pair).size()); |
| 886 } | 885 } |
| 887 | 886 |
| 888 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorageOnIPAddressChanged) { | 887 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorageOnIPAddressChanged) { |
| 889 const std::string kTestHost("www.foo.com"); | 888 const std::string kTestHost("www.foo.com"); |
| 890 const int kTestPort = 80; | 889 const int kTestPort = 80; |
| 891 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 890 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 892 | 891 |
| 893 SpdySessionDependencies session_deps; | 892 SpdySessionDependencies session_deps; |
| 894 scoped_refptr<HttpNetworkSession> http_session( | 893 scoped_refptr<HttpNetworkSession> http_session( |
| 895 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 894 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 896 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 895 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 897 | 896 |
| 898 HttpServerProperties* test_http_server_properties = | 897 HttpServerProperties* test_http_server_properties = |
| 899 spdy_session_pool->http_server_properties(); | 898 spdy_session_pool->http_server_properties(); |
| 900 spdy::SettingsFlagsAndId id(0); | 899 spdy::SettingsFlagsAndId id(spdy::SETTINGS_FLAG_PLEASE_PERSIST, |
| 901 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); | 900 spdy::SETTINGS_MAX_CONCURRENT_STREAMS); |
| 902 id.set_flags(spdy::SETTINGS_FLAG_PLEASE_PERSIST); | |
| 903 const size_t max_concurrent_streams = 2; | 901 const size_t max_concurrent_streams = 2; |
| 904 spdy::SpdySettings test_settings; | 902 spdy::SpdySettings test_settings; |
| 905 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); | 903 test_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); |
| 906 | 904 |
| 907 test_http_server_properties->SetSpdySettings(test_host_port_pair, | 905 test_http_server_properties->SetSpdySettings(test_host_port_pair, |
| 908 test_settings); | 906 test_settings); |
| 909 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( | 907 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( |
| 910 test_host_port_pair).size()); | 908 test_host_port_pair).size()); |
| 911 spdy_session_pool->OnIPAddressChanged(); | 909 spdy_session_pool->OnIPAddressChanged(); |
| 912 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( | 910 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1119 net::NetLog::PHASE_NONE); | 1117 net::NetLog::PHASE_NONE); |
| 1120 | 1118 |
| 1121 CapturingNetLog::Entry entry = entries[pos]; | 1119 CapturingNetLog::Entry entry = entries[pos]; |
| 1122 NetLogSpdySessionCloseParameter* request_params = | 1120 NetLogSpdySessionCloseParameter* request_params = |
| 1123 static_cast<NetLogSpdySessionCloseParameter*>( | 1121 static_cast<NetLogSpdySessionCloseParameter*>( |
| 1124 entry.extra_parameters.get()); | 1122 entry.extra_parameters.get()); |
| 1125 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); | 1123 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); |
| 1126 } | 1124 } |
| 1127 | 1125 |
| 1128 } // namespace net | 1126 } // namespace net |
| OLD | NEW |