Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: net/spdy/spdy_session_spdy2_unittest.cc

Issue 9802003: SPDY - persist SPDY settings. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(SpdySessionSpdy2Test, OnSettings) { 499 TEST_F(SpdySessionSpdy2Test, 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 SpdySettings new_settings;
504 SettingsFlagsAndId id(0, SETTINGS_MAX_CONCURRENT_STREAMS); 504 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_MAX_CONCURRENT_STREAMS;
505 SettingsFlagsAndId id(SETTINGS_FLAG_NONE, kSpdySettingsIds1);
505 const size_t max_concurrent_streams = 2; 506 const size_t max_concurrent_streams = 2;
506 new_settings.push_back(SpdySetting(id, max_concurrent_streams)); 507 new_settings.push_back(SpdySetting(id, max_concurrent_streams));
507 508
508 // 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
509 // streams to 2. 510 // streams to 2.
510 MockConnect connect_data(SYNCHRONOUS, OK); 511 MockConnect connect_data(SYNCHRONOUS, OK);
511 scoped_ptr<SpdyFrame> settings_frame( 512 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(new_settings));
512 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 SpdySettingsStorage 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 SpdySettings old_settings; 535 spdy_session_pool->http_server_properties()->SetSpdySetting(
536 SettingsFlagsAndId id1(SETTINGS_FLAG_PLEASE_PERSIST, id.id()); 536 test_host_port_pair,
537 old_settings.push_back(SpdySetting(id1, 1)); 537 kSpdySettingsIds1,
538 spdy_session_pool->http_server_properties()->SetSpdySettings( 538 SETTINGS_FLAG_PLEASE_PERSIST,
539 test_host_port_pair, old_settings); 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 =
544 spdy_session_pool->Get(pair, BoundNetLog()); 544 spdy_session_pool->Get(pair, BoundNetLog());
545 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); 545 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
546 546
547 scoped_refptr<TransportSocketParams> transport_params( 547 scoped_refptr<TransportSocketParams> transport_params(
548 new TransportSocketParams(test_host_port_pair, 548 new TransportSocketParams(test_host_port_pair,
549 MEDIUM, 549 MEDIUM,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 SpdySettingsStorage 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 SpdySettings settings; 618 spdy_session_pool->http_server_properties()->SetSpdySetting(
619 SettingsFlagsAndId id(SETTINGS_FLAG_PLEASE_PERSIST, 619 test_host_port_pair,
620 SETTINGS_MAX_CONCURRENT_STREAMS); 620 SETTINGS_MAX_CONCURRENT_STREAMS,
621 settings.push_back(SpdySetting(id, 1)); 621 SETTINGS_FLAG_PLEASE_PERSIST,
622 spdy_session_pool->http_server_properties()->SetSpdySettings( 622 1);
623 test_host_port_pair, settings);
624 623
625 // Create a session. 624 // Create a session.
626 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 625 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
627 scoped_refptr<SpdySession> session = 626 scoped_refptr<SpdySession> session =
628 spdy_session_pool->Get(pair, BoundNetLog()); 627 spdy_session_pool->Get(pair, BoundNetLog());
629 ASSERT_TRUE(spdy_session_pool->HasSession(pair)); 628 ASSERT_TRUE(spdy_session_pool->HasSession(pair));
630 629
631 scoped_refptr<TransportSocketParams> transport_params( 630 scoped_refptr<TransportSocketParams> transport_params(
632 new TransportSocketParams(test_host_port_pair, 631 new TransportSocketParams(test_host_port_pair,
633 MEDIUM, 632 MEDIUM,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 675
677 TEST_F(SpdySessionSpdy2Test, SendSettingsOnNewSession) { 676 TEST_F(SpdySessionSpdy2Test, SendSettingsOnNewSession) {
678 SpdySessionDependencies session_deps; 677 SpdySessionDependencies session_deps;
679 session_deps.host_resolver->set_synchronous_mode(true); 678 session_deps.host_resolver->set_synchronous_mode(true);
680 679
681 MockRead reads[] = { 680 MockRead reads[] = {
682 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. 681 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever.
683 }; 682 };
684 683
685 // 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.
686 // 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
687 // to set it into the SpdySettingsStorage, we need to mark as 686 // to set it into the SpdySettingsStorage, we need to mark as
688 // SETTINGS_FLAG_PLEASE_PERSIST. 687 // SETTINGS_FLAG_PLEASE_PERSIST.
689 SpdySettings settings; 688 SpdySettings settings;
690 const uint32 kBogusSettingId = 0xABAB; 689 const SpdySettingsIds kSpdySettingsIds1 = SETTINGS_UPLOAD_BANDWIDTH;
691 const uint32 kBogusSettingValue = 0xCDCD; 690 const uint32 kBogusSettingValue = 0xCDCD;
692 SettingsFlagsAndId id(SETTINGS_FLAG_PERSISTED, kBogusSettingId); 691 SettingsFlagsAndId id(SETTINGS_FLAG_PERSISTED, kSpdySettingsIds1);
693 settings.push_back(SpdySetting(id, kBogusSettingValue)); 692 settings.push_back(SpdySetting(id, kBogusSettingValue));
694 MockConnect connect_data(SYNCHRONOUS, OK); 693 MockConnect connect_data(SYNCHRONOUS, OK);
695 scoped_ptr<SpdyFrame> settings_frame( 694 scoped_ptr<SpdyFrame> settings_frame(ConstructSpdySettings(settings));
696 ConstructSpdySettings(settings));
697 MockWrite writes[] = { 695 MockWrite writes[] = {
698 CreateMockWrite(*settings_frame), 696 CreateMockWrite(*settings_frame),
699 }; 697 };
700 698
701 StaticSocketDataProvider data( 699 StaticSocketDataProvider data(
702 reads, arraysize(reads), writes, arraysize(writes)); 700 reads, arraysize(reads), writes, arraysize(writes));
703 data.set_connect_data(connect_data); 701 data.set_connect_data(connect_data);
704 session_deps.socket_factory->AddSocketDataProvider(&data); 702 session_deps.socket_factory->AddSocketDataProvider(&data);
705 703
706 SSLSocketDataProvider ssl(SYNCHRONOUS, OK); 704 SSLSocketDataProvider ssl(SYNCHRONOUS, OK);
707 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); 705 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
708 706
709 scoped_refptr<HttpNetworkSession> http_session( 707 scoped_refptr<HttpNetworkSession> http_session(
710 SpdySessionDependencies::SpdyCreateSession(&session_deps)); 708 SpdySessionDependencies::SpdyCreateSession(&session_deps));
711 709
712 const std::string kTestHost("www.foo.com"); 710 const std::string kTestHost("www.foo.com");
713 const int kTestPort = 80; 711 const int kTestPort = 80;
714 HostPortPair test_host_port_pair(kTestHost, kTestPort); 712 HostPortPair test_host_port_pair(kTestHost, kTestPort);
715 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct()); 713 HostPortProxyPair pair(test_host_port_pair, ProxyServer::Direct());
716 714
717 SettingsFlagsAndId id1(SETTINGS_FLAG_PLEASE_PERSIST, id.id());
718 settings.clear();
719 settings.push_back(SpdySetting(id1, kBogusSettingValue));
720 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); 715 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
721 spdy_session_pool->http_server_properties()->SetSpdySettings( 716 spdy_session_pool->http_server_properties()->SetSpdySetting(
722 test_host_port_pair, settings); 717 test_host_port_pair,
718 kSpdySettingsIds1,
719 SETTINGS_FLAG_PLEASE_PERSIST,
720 kBogusSettingValue);
721
723 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 722 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
724 scoped_refptr<SpdySession> session = 723 scoped_refptr<SpdySession> session =
725 spdy_session_pool->Get(pair, BoundNetLog()); 724 spdy_session_pool->Get(pair, BoundNetLog());
726 EXPECT_TRUE(spdy_session_pool->HasSession(pair)); 725 EXPECT_TRUE(spdy_session_pool->HasSession(pair));
727 726
728 scoped_refptr<TransportSocketParams> transport_params( 727 scoped_refptr<TransportSocketParams> transport_params(
729 new TransportSocketParams(test_host_port_pair, 728 new TransportSocketParams(test_host_port_pair,
730 MEDIUM, 729 MEDIUM,
731 false, 730 false,
732 false)); 731 false));
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
887 IPPoolingTest(true); 886 IPPoolingTest(true);
888 } 887 }
889 888
890 TEST_F(SpdySessionSpdy2Test, ClearSettingsStorage) { 889 TEST_F(SpdySessionSpdy2Test, ClearSettingsStorage) {
891 SpdySettingsStorage settings_storage; 890 SpdySettingsStorage settings_storage;
892 const std::string kTestHost("www.foo.com"); 891 const std::string kTestHost("www.foo.com");
893 const int kTestPort = 80; 892 const int kTestPort = 80;
894 HostPortPair test_host_port_pair(kTestHost, kTestPort); 893 HostPortPair test_host_port_pair(kTestHost, kTestPort);
895 SpdySettings test_settings; 894 SpdySettings test_settings;
896 SettingsFlagsAndId id(SETTINGS_FLAG_PLEASE_PERSIST, 895 SettingsFlagsAndId id(SETTINGS_FLAG_PLEASE_PERSIST,
897 SETTINGS_MAX_CONCURRENT_STREAMS); 896 SETTINGS_MAX_CONCURRENT_STREAMS);
898 const size_t max_concurrent_streams = 2; 897 const size_t max_concurrent_streams = 2;
899 test_settings.push_back(SpdySetting(id, max_concurrent_streams)); 898 test_settings.push_back(SpdySetting(id, max_concurrent_streams));
900 899
901 settings_storage.Set(test_host_port_pair, test_settings); 900 settings_storage.Set(test_host_port_pair, test_settings);
902 EXPECT_NE(0u, settings_storage.Get(test_host_port_pair).size()); 901 EXPECT_NE(0u, settings_storage.Get(test_host_port_pair).size());
903 settings_storage.Clear(); 902 settings_storage.Clear();
904 EXPECT_EQ(0u, settings_storage.Get(test_host_port_pair).size()); 903 EXPECT_EQ(0u, settings_storage.Get(test_host_port_pair).size());
905 } 904 }
906 905
907 TEST_F(SpdySessionSpdy2Test, ClearSettingsStorageOnIPAddressChanged) { 906 TEST_F(SpdySessionSpdy2Test, ClearSettingsStorageOnIPAddressChanged) {
908 const std::string kTestHost("www.foo.com"); 907 const std::string kTestHost("www.foo.com");
909 const int kTestPort = 80; 908 const int kTestPort = 80;
910 HostPortPair test_host_port_pair(kTestHost, kTestPort); 909 HostPortPair test_host_port_pair(kTestHost, kTestPort);
911 910
912 SpdySessionDependencies session_deps; 911 SpdySessionDependencies session_deps;
913 scoped_refptr<HttpNetworkSession> http_session( 912 scoped_refptr<HttpNetworkSession> http_session(
914 SpdySessionDependencies::SpdyCreateSession(&session_deps)); 913 SpdySessionDependencies::SpdyCreateSession(&session_deps));
915 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool()); 914 SpdySessionPool* spdy_session_pool(http_session->spdy_session_pool());
916 915
917 HttpServerProperties* test_http_server_properties = 916 HttpServerProperties* test_http_server_properties =
918 spdy_session_pool->http_server_properties(); 917 spdy_session_pool->http_server_properties();
919 SettingsFlagsAndId id(SETTINGS_FLAG_PLEASE_PERSIST, 918 SettingsFlagsAndValue flags_and_value1(SETTINGS_FLAG_PLEASE_PERSIST, 2);
920 SETTINGS_MAX_CONCURRENT_STREAMS); 919 test_http_server_properties->SetSpdySetting(
921 const size_t max_concurrent_streams = 2; 920 test_host_port_pair,
922 SpdySettings test_settings; 921 SETTINGS_MAX_CONCURRENT_STREAMS,
923 test_settings.push_back(SpdySetting(id, max_concurrent_streams)); 922 SETTINGS_FLAG_PLEASE_PERSIST,
924 923 2);
925 test_http_server_properties->SetSpdySettings(test_host_port_pair,
926 test_settings);
927 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( 924 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings(
928 test_host_port_pair).size()); 925 test_host_port_pair).size());
929 spdy_session_pool->OnIPAddressChanged(); 926 spdy_session_pool->OnIPAddressChanged();
930 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( 927 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings(
931 test_host_port_pair).size()); 928 test_host_port_pair).size());
932 } 929 }
933 930
934 TEST_F(SpdySessionSpdy2Test, NeedsCredentials) { 931 TEST_F(SpdySessionSpdy2Test, NeedsCredentials) {
935 SpdySessionDependencies session_deps; 932 SpdySessionDependencies session_deps;
936 933
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 1198
1202 // But now if we drop our reference to the session, it will be destructed 1199 // But now if we drop our reference to the session, it will be destructed
1203 // and the transport socket will return to the pool, unblocking this 1200 // and the transport socket will return to the pool, unblocking this
1204 // request. 1201 // request.
1205 session2 = NULL; 1202 session2 = NULL;
1206 EXPECT_EQ(OK, callback6.WaitForResult()); 1203 EXPECT_EQ(OK, callback6.WaitForResult());
1207 EXPECT_FALSE(pool.IsStalled()); 1204 EXPECT_FALSE(pool.IsStalled());
1208 } 1205 }
1209 1206
1210 } // namespace net 1207 } // namespace net
OLDNEW
« no previous file with comments | « net/spdy/spdy_session.cc ('k') | net/spdy/spdy_session_spdy3_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698