| 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/host_cache.h" | 7 #include "net/base/host_cache.h" |
| 8 #include "net/base/ip_endpoint.h" | 8 #include "net/base/ip_endpoint.h" |
| 9 #include "net/base/net_log_unittest.h" | 9 #include "net/base/net_log_unittest.h" |
| 10 #include "net/spdy/spdy_io_buffer.h" | 10 #include "net/spdy/spdy_io_buffer.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 493 |
| 494 // 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 |
| 495 // settings frame setting max concurrent streams to 2. Have the callback | 495 // settings frame setting max concurrent streams to 2. Have the callback |
| 496 // 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. |
| 497 // Make sure nothing blows up. | 497 // Make sure nothing blows up. |
| 498 // http://crbug.com/57331 | 498 // http://crbug.com/57331 |
| 499 TEST_F(SpdySessionSpdy3Test, OnSettings) { | 499 TEST_F(SpdySessionSpdy3Test, OnSettings) { |
| 500 SpdySessionDependencies session_deps; | 500 SpdySessionDependencies session_deps; |
| 501 session_deps.host_resolver->set_synchronous_mode(true); | 501 session_deps.host_resolver->set_synchronous_mode(true); |
| 502 | 502 |
| 503 SpdySettings new_settings; | 503 SettingsMap new_settings; |
| 504 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; | 504 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS; |
| 505 SettingsFlagsAndId id(SETTINGS_FLAG_NONE, kSpdySettingsIds1); | |
| 506 const size_t max_concurrent_streams = 2; | 505 const size_t max_concurrent_streams = 2; |
| 507 new_settings.push_back(SpdySetting(id, max_concurrent_streams)); | 506 new_settings[kSpdySettingsIds1] = |
| 507 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, max_concurrent_streams); |
| 508 | 508 |
| 509 // Set up the socket so we read a SETTINGS frame that raises max concurrent | 509 // Set up the socket so we read a SETTINGS frame that raises max concurrent |
| 510 // streams to 2. | 510 // streams to 2. |
| 511 MockConnect connect_data(SYNCHRONOUS, OK); | 511 MockConnect connect_data(SYNCHRONOUS, OK); |
| 512 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); | 512 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); |
| 513 MockRead reads[] = { | 513 MockRead reads[] = { |
| 514 CreateMockRead(*settings_frame), | 514 CreateMockRead(*settings_frame), |
| 515 MockRead(SYNCHRONOUS, 0, 0) // EOF | 515 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 516 }; | 516 }; |
| 517 | 517 |
| 518 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); | 518 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); |
| 519 data.set_connect_data(connect_data); | 519 data.set_connect_data(connect_data); |
| 520 session_deps.socket_factory->AddSocketDataProvider(&data); | 520 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 521 | 521 |
| 522 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 522 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 523 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 523 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 524 | 524 |
| 525 scoped_refptr<HttpNetworkSession> http_session( | 525 scoped_refptr<HttpNetworkSession> http_session( |
| 526 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 526 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 527 | 527 |
| 528 const std::string kTestHost("www.foo.com"); | 528 const std::string kTestHost("www.foo.com"); |
| 529 const int kTestPort = 80; | 529 const int kTestPort = 80; |
| 530 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 530 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 531 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 531 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 532 | 532 |
| 533 // Initialize the SpdySettingsStorage with 1 max concurrent streams. | 533 // Initialize the SpdySetting with 1 max concurrent streams. |
| 534 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 534 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 535 spdy_session_pool->http_server_properties()->SetSpdySetting( | 535 spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 536 test_host_port_pair, | 536 test_host_port_pair, |
| 537 kSpdySettingsIds1, | 537 kSpdySettingsIds1, |
| 538 SETTINGS_FLAG_PLEASE_PERSIST, | 538 SETTINGS_FLAG_PLEASE_PERSIST, |
| 539 1); | 539 1); |
| 540 | 540 |
| 541 // Create a session. | 541 // Create a session. |
| 542 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 542 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 543 scoped_refptr<SpdySession> session = | 543 scoped_refptr<SpdySession> session = |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); | 606 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 607 | 607 |
| 608 scoped_refptr<HttpNetworkSession> http_session( | 608 scoped_refptr<HttpNetworkSession> http_session( |
| 609 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 609 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 610 | 610 |
| 611 const std::string kTestHost("www.foo.com"); | 611 const std::string kTestHost("www.foo.com"); |
| 612 const int kTestPort = 80; | 612 const int kTestPort = 80; |
| 613 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 613 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 614 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); | 614 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); |
| 615 | 615 |
| 616 // Initialize the SpdySettingsStorage with 1 max concurrent streams. | 616 // Initialize the SpdySetting with 1 max concurrent streams. |
| 617 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 617 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 618 spdy_session_pool->http_server_properties()->SetSpdySetting( | 618 spdy_session_pool->http_server_properties()->SetSpdySetting( |
| 619 test_host_port_pair, | 619 test_host_port_pair, |
| 620 SETTINGS_MAX_CONCURRENT_STREAMS, | 620 SETTINGS_MAX_CONCURRENT_STREAMS, |
| 621 SETTINGS_FLAG_PLEASE_PERSIST, | 621 SETTINGS_FLAG_PLEASE_PERSIST, |
| 622 1); | 622 1); |
| 623 | 623 |
| 624 // Create a session. | 624 // Create a session. |
| 625 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); | 625 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); |
| 626 scoped_refptr<SpdySession> session = | 626 scoped_refptr<SpdySession> session = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 TEST_F(SpdySessionSpdy3Test, SendSettingsOnNewSession) { | 676 TEST_F(SpdySessionSpdy3Test, SendSettingsOnNewSession) { |
| 677 SpdySessionDependencies session_deps; | 677 SpdySessionDependencies session_deps; |
| 678 session_deps.host_resolver->set_synchronous_mode(true); | 678 session_deps.host_resolver->set_synchronous_mode(true); |
| 679 | 679 |
| 680 MockRead reads[] = { | 680 MockRead reads[] = { |
| 681 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 681 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 682 }; | 682 }; |
| 683 | 683 |
| 684 // Create the bogus setting that we want to verify is sent out. | 684 // Create the bogus setting that we want to verify is sent out. |
| 685 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But | 685 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But |
| 686 // to set it into the SpdySettingsStorage, we need to mark as | 686 // to persist it into the HttpServerProperties, we need to mark as |
| 687 // SETTINGS_FLAG_PLEASE_PERSIST. | 687 // SETTINGS_FLAG_PLEASE_PERSIST. |
| 688 SpdySettings settings; | 688 SettingsMap settings; |
| 689 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_UPLOAD_BANDWIDTH; | 689 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_UPLOAD_BANDWIDTH; |
| 690 const uint32 kBogusSettingValue = 0xCDCD; | 690 const uint32 kBogusSettingValue = 0xCDCD; |
| 691 SettingsFlagsAndId id(SETTINGS_FLAG_PERSISTED, kSpdySettingsIds1); | 691 settings[kSpdySettingsIds1] = |
| 692 settings.push_back(SpdySetting(id, kBogusSettingValue)); | 692 SettingsFlagsAndValue(SETTINGS_FLAG_PERSISTED, kBogusSettingValue); |
| 693 MockConnect connect_data(SYNCHRONOUS, OK); | 693 MockConnect connect_data(SYNCHRONOUS, OK); |
| 694 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(settings)); | 694 scoped_ptr<SpdyFrame> settings_frame(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); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 879 } // namespace | 879 } // namespace |
| 880 | 880 |
| 881 TEST_F(SpdySessionSpdy3Test, IPPooling) { | 881 TEST_F(SpdySessionSpdy3Test, IPPooling) { |
| 882 IPPoolingTest(false); | 882 IPPoolingTest(false); |
| 883 } | 883 } |
| 884 | 884 |
| 885 TEST_F(SpdySessionSpdy3Test, IPPoolingCloseCurrentSessions) { | 885 TEST_F(SpdySessionSpdy3Test, IPPoolingCloseCurrentSessions) { |
| 886 IPPoolingTest(true); | 886 IPPoolingTest(true); |
| 887 } | 887 } |
| 888 | 888 |
| 889 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorage) { | |
| 890 SpdySettingsStorage settings_storage; | |
| 891 const std::string kTestHost("www.foo.com"); | |
| 892 const int kTestPort = 80; | |
| 893 HostPortPair test_host_port_pair(kTestHost, kTestPort); | |
| 894 SpdySettings test_settings; | |
| 895 SettingsFlagsAndId id(SETTINGS_FLAG_PLEASE_PERSIST, | |
| 896 SETTINGS_MAX_CONCURRENT_STREAMS); | |
| 897 const size_t max_concurrent_streams = 2; | |
| 898 test_settings.push_back(SpdySetting(id, max_concurrent_streams)); | |
| 899 | |
| 900 settings_storage.Set(test_host_port_pair, test_settings); | |
| 901 EXPECT_NE(0u, settings_storage.Get(test_host_port_pair).size()); | |
| 902 settings_storage.Clear(); | |
| 903 EXPECT_EQ(0u, settings_storage.Get(test_host_port_pair).size()); | |
| 904 } | |
| 905 | |
| 906 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorageOnIPAddressChanged) { | 889 TEST_F(SpdySessionSpdy3Test, ClearSettingsStorageOnIPAddressChanged) { |
| 907 const std::string kTestHost("www.foo.com"); | 890 const std::string kTestHost("www.foo.com"); |
| 908 const int kTestPort = 80; | 891 const int kTestPort = 80; |
| 909 HostPortPair test_host_port_pair(kTestHost, kTestPort); | 892 HostPortPair test_host_port_pair(kTestHost, kTestPort); |
| 910 | 893 |
| 911 SpdySessionDependencies session_deps; | 894 SpdySessionDependencies session_deps; |
| 912 scoped_refptr<HttpNetworkSession> http_session( | 895 scoped_refptr<HttpNetworkSession> http_session( |
| 913 SpdySessionDependencies::SpdyCreateSession(&session_deps)); | 896 SpdySessionDependencies::SpdyCreateSession(&session_deps)); |
| 914 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); | 897 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); |
| 915 | 898 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 spdy_session_pool->Remove(session); | 975 spdy_session_pool->Remove(session); |
| 993 } | 976 } |
| 994 | 977 |
| 995 TEST_F(SpdySessionSpdy3Test, SendCredentials) { | 978 TEST_F(SpdySessionSpdy3Test, SendCredentials) { |
| 996 SpdySessionDependencies session_deps; | 979 SpdySessionDependencies session_deps; |
| 997 | 980 |
| 998 MockConnect connect_data(SYNCHRONOUS, OK); | 981 MockConnect connect_data(SYNCHRONOUS, OK); |
| 999 MockRead reads[] = { | 982 MockRead reads[] = { |
| 1000 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 983 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
| 1001 }; | 984 }; |
| 1002 SpdySettings settings; | 985 SettingsMap settings; |
| 1003 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(settings)); | 986 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(settings)); |
| 1004 MockWrite writes[] = { | 987 MockWrite writes[] = { |
| 1005 CreateMockWrite(*settings_frame), | 988 CreateMockWrite(*settings_frame), |
| 1006 }; | 989 }; |
| 1007 StaticSocketDataProvider data(reads, arraysize(reads), | 990 StaticSocketDataProvider data(reads, arraysize(reads), |
| 1008 writes, arraysize(writes)); | 991 writes, arraysize(writes)); |
| 1009 data.set_connect_data(connect_data); | 992 data.set_connect_data(connect_data); |
| 1010 session_deps.socket_factory->AddSocketDataProvider(&data); | 993 session_deps.socket_factory->AddSocketDataProvider(&data); |
| 1011 | 994 |
| 1012 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); | 995 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1128 CapturingNetLog::Entry entry = entries[pos]; | 1111 CapturingNetLog::Entry entry = entries[pos]; |
| 1129 NetLogSpdySessionCloseParameter* request_params = | 1112 NetLogSpdySessionCloseParameter* request_params = |
| 1130 static_cast<NetLogSpdySessionCloseParameter*>( | 1113 static_cast<NetLogSpdySessionCloseParameter*>( |
| 1131 entry.extra_parameters.get()); | 1114 entry.extra_parameters.get()); |
| 1132 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); | 1115 EXPECT_EQ(ERR_CONNECTION_CLOSED, request_params->status()); |
| 1133 } | 1116 } |
| 1134 | 1117 |
| 1135 TEST_F(SpdySessionSpdy3Test, UpdateStreamsSendWindowSize) { | 1118 TEST_F(SpdySessionSpdy3Test, UpdateStreamsSendWindowSize) { |
| 1136 // Set SETTINGS_INITIAL_WINDOW_SIZE to a small number so that WINDOW_UPDATE | 1119 // Set SETTINGS_INITIAL_WINDOW_SIZE to a small number so that WINDOW_UPDATE |
| 1137 // gets sent. | 1120 // gets sent. |
| 1138 SpdySettings new_settings; | 1121 SettingsMap new_settings; |
| 1139 SettingsFlagsAndId id(0, SETTINGS_INITIAL_WINDOW_SIZE); | |
| 1140 int32 window_size = 1; | 1122 int32 window_size = 1; |
| 1141 new_settings.push_back(SpdySetting(id, window_size)); | 1123 new_settings[SETTINGS_INITIAL_WINDOW_SIZE] = |
| 1124 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, window_size); |
| 1142 | 1125 |
| 1143 // Set up the socket so we read a SETTINGS frame that sets | 1126 // Set up the socket so we read a SETTINGS frame that sets |
| 1144 // INITIAL_WINDOW_SIZE. | 1127 // INITIAL_WINDOW_SIZE. |
| 1145 MockConnect connect_data(SYNCHRONOUS, OK); | 1128 MockConnect connect_data(SYNCHRONOUS, OK); |
| 1146 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); | 1129 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings)); |
| 1147 MockRead reads[] = { | 1130 MockRead reads[] = { |
| 1148 CreateMockRead(*settings_frame), | 1131 CreateMockRead(*settings_frame), |
| 1149 MockRead(SYNCHRONOUS, 0, 0) // EOF | 1132 MockRead(SYNCHRONOUS, 0, 0) // EOF |
| 1150 }; | 1133 }; |
| 1151 | 1134 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 &spdy_stream2, | 1197 &spdy_stream2, |
| 1215 BoundNetLog(), | 1198 BoundNetLog(), |
| 1216 callback1.callback())); | 1199 callback1.callback())); |
| 1217 | 1200 |
| 1218 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); | 1201 EXPECT_EQ(spdy_stream2->send_window_size(), window_size); |
| 1219 spdy_stream2->Cancel(); | 1202 spdy_stream2->Cancel(); |
| 1220 spdy_stream2 = NULL; | 1203 spdy_stream2 = NULL; |
| 1221 } | 1204 } |
| 1222 | 1205 |
| 1223 } // namespace net | 1206 } // namespace net |
| OLD | NEW |