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

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

Issue 9419032: Modify the MockConnect constructor to take an enum of ASYNC or SYNC, instead (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Fix Test Break Created 8 years, 10 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
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/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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 SpdyIOBuffer buffer = queue_.top(); 101 SpdyIOBuffer buffer = queue_.top();
102 EXPECT_EQ(priority++, buffer.priority()); 102 EXPECT_EQ(priority++, buffer.priority());
103 queue_.pop(); 103 queue_.pop();
104 } 104 }
105 } 105 }
106 106
107 TEST_F(SpdySessionTest, GoAway) { 107 TEST_F(SpdySessionTest, GoAway) {
108 SpdySessionDependencies session_deps; 108 SpdySessionDependencies session_deps;
109 session_deps.host_resolver->set_synchronous_mode(true); 109 session_deps.host_resolver->set_synchronous_mode(true);
110 110
111 MockConnect connect_data(false, OK); 111 MockConnect connect_data(SYNCHRONOUS, OK);
112 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyGoAway()); 112 scoped_ptr<spdy::SpdyFrame> goaway(ConstructSpdyGoAway());
113 MockRead reads[] = { 113 MockRead reads[] = {
114 CreateMockRead(*goaway), 114 CreateMockRead(*goaway),
115 MockRead(false, 0, 0) // EOF 115 MockRead(false, 0, 0) // EOF
116 }; 116 };
117 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 117 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
118 data.set_connect_data(connect_data); 118 data.set_connect_data(connect_data);
119 session_deps.socket_factory->AddSocketDataProvider(&data); 119 session_deps.socket_factory->AddSocketDataProvider(&data);
120 120
121 SSLSocketDataProvider ssl(false, OK); 121 SSLSocketDataProvider ssl(false, OK);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 160
161 // Delete the second session. 161 // Delete the second session.
162 spdy_session_pool->Remove(session2); 162 spdy_session_pool->Remove(session2);
163 session2 = NULL; 163 session2 = NULL;
164 } 164 }
165 165
166 TEST_F(SpdySessionTest, Ping) { 166 TEST_F(SpdySessionTest, Ping) {
167 SpdySessionDependencies session_deps; 167 SpdySessionDependencies session_deps;
168 session_deps.host_resolver->set_synchronous_mode(true); 168 session_deps.host_resolver->set_synchronous_mode(true);
169 169
170 MockConnect connect_data(false, OK); 170 MockConnect connect_data(SYNCHRONOUS, OK);
171 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing()); 171 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing());
172 MockRead reads[] = { 172 MockRead reads[] = {
173 CreateMockRead(*read_ping), 173 CreateMockRead(*read_ping),
174 CreateMockRead(*read_ping), 174 CreateMockRead(*read_ping),
175 MockRead(false, 0, 0) // EOF 175 MockRead(false, 0, 0) // EOF
176 }; 176 };
177 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing()); 177 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing());
178 MockRead writes[] = { 178 MockRead writes[] = {
179 CreateMockRead(*write_ping), 179 CreateMockRead(*write_ping),
180 CreateMockRead(*write_ping), 180 CreateMockRead(*write_ping),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 251 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
252 252
253 // Delete the first session. 253 // Delete the first session.
254 session = NULL; 254 session = NULL;
255 } 255 }
256 256
257 TEST_F(SpdySessionTest, FailedPing) { 257 TEST_F(SpdySessionTest, FailedPing) {
258 SpdySessionDependencies session_deps; 258 SpdySessionDependencies session_deps;
259 session_deps.host_resolver->set_synchronous_mode(true); 259 session_deps.host_resolver->set_synchronous_mode(true);
260 260
261 MockConnect connect_data(false, OK); 261 MockConnect connect_data(SYNCHRONOUS, OK);
262 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing()); 262 scoped_ptr<spdy::SpdyFrame> read_ping(ConstructSpdyPing());
263 MockRead reads[] = { 263 MockRead reads[] = {
264 CreateMockRead(*read_ping), 264 CreateMockRead(*read_ping),
265 MockRead(false, 0, 0) // EOF 265 MockRead(false, 0, 0) // EOF
266 }; 266 };
267 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing()); 267 scoped_ptr<spdy::SpdyFrame> write_ping(ConstructSpdyPing());
268 MockRead writes[] = { 268 MockRead writes[] = {
269 CreateMockRead(*write_ping), 269 CreateMockRead(*write_ping),
270 }; 270 };
271 StaticSocketDataProvider data( 271 StaticSocketDataProvider data(
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 session_deps.host_resolver->set_synchronous_mode(true); 494 session_deps.host_resolver->set_synchronous_mode(true);
495 495
496 spdy::SpdySettings new_settings; 496 spdy::SpdySettings new_settings;
497 spdy::SettingsFlagsAndId id(0); 497 spdy::SettingsFlagsAndId id(0);
498 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS); 498 id.set_id(spdy::SETTINGS_MAX_CONCURRENT_STREAMS);
499 const size_t max_concurrent_streams = 2; 499 const size_t max_concurrent_streams = 2;
500 new_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams)); 500 new_settings.push_back(spdy::SpdySetting(id, max_concurrent_streams));
501 501
502 // Set up the socket so we read a SETTINGS frame that raises max concurrent 502 // Set up the socket so we read a SETTINGS frame that raises max concurrent
503 // streams to 2. 503 // streams to 2.
504 MockConnect connect_data(false, OK); 504 MockConnect connect_data(SYNCHRONOUS, OK);
505 scoped_ptr<spdy::SpdyFrame> settings_frame( 505 scoped_ptr<spdy::SpdyFrame> settings_frame(
506 ConstructSpdySettings(new_settings)); 506 ConstructSpdySettings(new_settings));
507 MockRead reads[] = { 507 MockRead reads[] = {
508 CreateMockRead(*settings_frame), 508 CreateMockRead(*settings_frame),
509 MockRead(false, 0, 0) // EOF 509 MockRead(false, 0, 0) // EOF
510 }; 510 };
511 511
512 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 512 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
513 data.set_connect_data(connect_data); 513 data.set_connect_data(connect_data);
514 session_deps.socket_factory->AddSocketDataProvider(&data); 514 session_deps.socket_factory->AddSocketDataProvider(&data);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 // http://crbug.com/63532 583 // http://crbug.com/63532
584 TEST_F(SpdySessionTest, CancelPendingCreateStream) { 584 TEST_F(SpdySessionTest, CancelPendingCreateStream) {
585 SpdySessionDependencies session_deps; 585 SpdySessionDependencies session_deps;
586 session_deps.host_resolver->set_synchronous_mode(true); 586 session_deps.host_resolver->set_synchronous_mode(true);
587 587
588 MockRead reads[] = { 588 MockRead reads[] = {
589 MockRead(false, ERR_IO_PENDING) // Stall forever. 589 MockRead(false, ERR_IO_PENDING) // Stall forever.
590 }; 590 };
591 591
592 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 592 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
593 MockConnect connect_data(false, OK); 593 MockConnect connect_data(SYNCHRONOUS, OK);
594 594
595 data.set_connect_data(connect_data); 595 data.set_connect_data(connect_data);
596 session_deps.socket_factory->AddSocketDataProvider(&data); 596 session_deps.socket_factory->AddSocketDataProvider(&data);
597 597
598 SSLSocketDataProvider ssl(false, OK); 598 SSLSocketDataProvider ssl(false, OK);
599 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); 599 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
600 600
601 scoped_refptr<HttpNetworkSession> http_session( 601 scoped_refptr<HttpNetworkSession> http_session(
602 SpdySessionDependencies::SpdyCreateSession(&session_deps)); 602 SpdySessionDependencies::SpdyCreateSession(&session_deps));
603 603
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But 679 // Note that it will be marked as SETTINGS_FLAG_PERSISTED when sent out. But
680 // to set it into the SpdySettingsStorage, we need to mark as 680 // to set it into the SpdySettingsStorage, we need to mark as
681 // SETTINGS_FLAG_PLEASE_PERSIST. 681 // SETTINGS_FLAG_PLEASE_PERSIST.
682 spdy::SpdySettings settings; 682 spdy::SpdySettings settings;
683 const uint32 kBogusSettingId = 0xABAB; 683 const uint32 kBogusSettingId = 0xABAB;
684 const uint32 kBogusSettingValue = 0xCDCD; 684 const uint32 kBogusSettingValue = 0xCDCD;
685 spdy::SettingsFlagsAndId id(0); 685 spdy::SettingsFlagsAndId id(0);
686 id.set_id(kBogusSettingId); 686 id.set_id(kBogusSettingId);
687 id.set_flags(spdy::SETTINGS_FLAG_PERSISTED); 687 id.set_flags(spdy::SETTINGS_FLAG_PERSISTED);
688 settings.push_back(spdy::SpdySetting(id, kBogusSettingValue)); 688 settings.push_back(spdy::SpdySetting(id, kBogusSettingValue));
689 MockConnect connect_data(false, OK); 689 MockConnect connect_data(SYNCHRONOUS, OK);
690 scoped_ptr<spdy::SpdyFrame> settings_frame( 690 scoped_ptr<spdy::SpdyFrame> settings_frame(
691 ConstructSpdySettings(settings)); 691 ConstructSpdySettings(settings));
692 MockWrite writes[] = { 692 MockWrite writes[] = {
693 CreateMockWrite(*settings_frame), 693 CreateMockWrite(*settings_frame),
694 }; 694 };
695 695
696 StaticSocketDataProvider data( 696 StaticSocketDataProvider data(
697 reads, arraysize(reads), writes, arraysize(writes)); 697 reads, arraysize(reads), writes, arraysize(writes));
698 data.set_connect_data(connect_data); 698 data.set_connect_data(connect_data);
699 session_deps.socket_factory->AddSocketDataProvider(&data); 699 session_deps.socket_factory->AddSocketDataProvider(&data);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
763 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort)); 763 HostResolver::RequestInfo info(HostPortPair(test_hosts[i].name, kTestPort));
764 session_deps.host_resolver->Resolve( 764 session_deps.host_resolver->Resolve(
765 info, &test_hosts[i].addresses, CompletionCallback(), NULL, 765 info, &test_hosts[i].addresses, CompletionCallback(), NULL,
766 BoundNetLog()); 766 BoundNetLog());
767 767
768 // Setup a HostPortProxyPair 768 // Setup a HostPortProxyPair
769 test_hosts[i].pair = HostPortProxyPair( 769 test_hosts[i].pair = HostPortProxyPair(
770 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct()); 770 HostPortPair(test_hosts[i].name, kTestPort), ProxyServer::Direct());
771 } 771 }
772 772
773 MockConnect connect_data(false, OK); 773 MockConnect connect_data(SYNCHRONOUS, OK);
774 MockRead reads[] = { 774 MockRead reads[] = {
775 MockRead(false, ERR_IO_PENDING) // Stall forever. 775 MockRead(false, ERR_IO_PENDING) // Stall forever.
776 }; 776 };
777 777
778 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 778 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
779 data.set_connect_data(connect_data); 779 data.set_connect_data(connect_data);
780 session_deps.socket_factory->AddSocketDataProvider(&data); 780 session_deps.socket_factory->AddSocketDataProvider(&data);
781 781
782 SSLSocketDataProvider ssl(false, OK); 782 SSLSocketDataProvider ssl(false, OK);
783 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl); 783 session_deps.socket_factory->AddSSLSocketDataProvider(&ssl);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
903 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings( 903 EXPECT_NE(0u, test_http_server_properties->GetSpdySettings(
904 test_host_port_pair).size()); 904 test_host_port_pair).size());
905 spdy_session_pool->OnIPAddressChanged(); 905 spdy_session_pool->OnIPAddressChanged();
906 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings( 906 EXPECT_EQ(0u, test_http_server_properties->GetSpdySettings(
907 test_host_port_pair).size()); 907 test_host_port_pair).size());
908 } 908 }
909 909
910 TEST_F(SpdySessionTest, NeedsCredentials) { 910 TEST_F(SpdySessionTest, NeedsCredentials) {
911 SpdySessionDependencies session_deps; 911 SpdySessionDependencies session_deps;
912 912
913 MockConnect connect_data(false, OK); 913 MockConnect connect_data(SYNCHRONOUS, OK);
914 MockRead reads[] = { 914 MockRead reads[] = {
915 MockRead(false, ERR_IO_PENDING) // Stall forever. 915 MockRead(false, ERR_IO_PENDING) // Stall forever.
916 }; 916 };
917 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0); 917 StaticSocketDataProvider data(reads, arraysize(reads), NULL, 0);
918 data.set_connect_data(connect_data); 918 data.set_connect_data(connect_data);
919 session_deps.socket_factory->AddSocketDataProvider(&data); 919 session_deps.socket_factory->AddSocketDataProvider(&data);
920 920
921 SSLSocketDataProvider ssl(false, OK); 921 SSLSocketDataProvider ssl(false, OK);
922 ssl.origin_bound_cert_type = CLIENT_CERT_RSA_SIGN; 922 ssl.origin_bound_cert_type = CLIENT_CERT_RSA_SIGN;
923 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY3; 923 ssl.protocol_negotiated = SSLClientSocket::kProtoSPDY3;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 // Flush the SpdySession::OnReadComplete() task. 971 // Flush the SpdySession::OnReadComplete() task.
972 MessageLoop::current()->RunAllPending(); 972 MessageLoop::current()->RunAllPending();
973 973
974 spdy_session_pool->Remove(session); 974 spdy_session_pool->Remove(session);
975 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 975 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
976 } 976 }
977 977
978 TEST_F(SpdySessionTest, SendCredentials) { 978 TEST_F(SpdySessionTest, SendCredentials) {
979 SpdySessionDependencies session_deps; 979 SpdySessionDependencies session_deps;
980 980
981 MockConnect connect_data(false, OK); 981 MockConnect connect_data(SYNCHRONOUS, OK);
982 MockRead reads[] = { 982 MockRead reads[] = {
983 MockRead(false, ERR_IO_PENDING) // Stall forever. 983 MockRead(false, ERR_IO_PENDING) // Stall forever.
984 }; 984 };
985 spdy::SpdySettings settings; 985 spdy::SpdySettings settings;
986 scoped_ptr<spdy::SpdyFrame> settings_frame( 986 scoped_ptr<spdy::SpdyFrame> settings_frame(
987 ConstructSpdySettings(settings)); 987 ConstructSpdySettings(settings));
988 MockWrite writes[] = { 988 MockWrite writes[] = {
989 CreateMockWrite(*settings_frame), 989 CreateMockWrite(*settings_frame),
990 }; 990 };
991 StaticSocketDataProvider data(reads, arraysize(reads), 991 StaticSocketDataProvider data(reads, arraysize(reads),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 EXPECT_TRUE(session->NeedsCredentials(test_host_port_pair2)); 1044 EXPECT_TRUE(session->NeedsCredentials(test_host_port_pair2));
1045 1045
1046 // Flush the SpdySession::OnReadComplete() task. 1046 // Flush the SpdySession::OnReadComplete() task.
1047 MessageLoop::current()->RunAllPending(); 1047 MessageLoop::current()->RunAllPending();
1048 1048
1049 spdy_session_pool->Remove(session); 1049 spdy_session_pool->Remove(session);
1050 EXPECT_FALSE(spdy_session_pool->HasSession(pair)); 1050 EXPECT_FALSE(spdy_session_pool->HasSession(pair));
1051 } 1051 }
1052 1052
1053 } // namespace net 1053 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698