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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1125 base::RunLoop().RunUntilIdle(); | 1125 base::RunLoop().RunUntilIdle(); |
1126 EXPECT_EQ(OK, delegate1.WaitForClose()); | 1126 EXPECT_EQ(OK, delegate1.WaitForClose()); |
1127 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData()); | 1127 EXPECT_EQ(kUploadData, delegate1.TakeReceivedData()); |
1128 EXPECT_EQ(OK, delegate2.WaitForClose()); | 1128 EXPECT_EQ(OK, delegate2.WaitForClose()); |
1129 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData()); | 1129 EXPECT_EQ(kUploadData, delegate2.TakeReceivedData()); |
1130 | 1130 |
1131 // Session was destroyed. | 1131 // Session was destroyed. |
1132 EXPECT_FALSE(session_); | 1132 EXPECT_FALSE(session_); |
1133 } | 1133 } |
1134 | 1134 |
| 1135 // Regression test for https://crbug.com/481009. |
| 1136 TEST_P(SpdySessionTest, MaxConcurrentStreamsZero) { |
| 1137 session_deps_.host_resolver->set_synchronous_mode(true); |
| 1138 |
| 1139 int seq = 0; |
| 1140 std::vector<MockRead> reads; |
| 1141 |
| 1142 // Receive SETTINGS frame that sets max_concurrent_streams to zero. |
| 1143 SettingsMap settings_zero; |
| 1144 settings_zero[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1145 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, 0); |
| 1146 scoped_ptr<SpdyFrame> settings_frame_zero( |
| 1147 spdy_util_.ConstructSpdySettings(settings_zero)); |
| 1148 reads.push_back(CreateMockRead(*settings_frame_zero, seq++)); |
| 1149 |
| 1150 // Acknowledge it. |
| 1151 std::vector<MockWrite> writes; |
| 1152 scoped_ptr<SpdyFrame> settings_ack0; |
| 1153 if (GetProtocol() == kProtoHTTP2) { |
| 1154 settings_ack0.reset(spdy_util_.ConstructSpdySettingsAck()); |
| 1155 writes.push_back(CreateMockWrite(*settings_ack0, seq++)); |
| 1156 } |
| 1157 |
| 1158 // Pause. |
| 1159 reads.push_back(MockRead(ASYNC, ERR_IO_PENDING, seq++)); |
| 1160 |
| 1161 // Receive SETTINGS frame that sets max_concurrent_streams to one. |
| 1162 SettingsMap settings_one; |
| 1163 settings_one[SETTINGS_MAX_CONCURRENT_STREAMS] = |
| 1164 SettingsFlagsAndValue(SETTINGS_FLAG_NONE, 1); |
| 1165 scoped_ptr<SpdyFrame> settings_frame_one( |
| 1166 spdy_util_.ConstructSpdySettings(settings_one)); |
| 1167 reads.push_back(CreateMockRead(*settings_frame_one, seq++)); |
| 1168 |
| 1169 // Acknowledge it. |
| 1170 scoped_ptr<SpdyFrame> settings_ack1; |
| 1171 if (GetProtocol() == kProtoHTTP2) { |
| 1172 settings_ack1.reset(spdy_util_.ConstructSpdySettingsAck()); |
| 1173 writes.push_back(CreateMockWrite(*settings_ack1, seq++)); |
| 1174 } |
| 1175 |
| 1176 // Request and response. |
| 1177 scoped_ptr<SpdyFrame> req( |
| 1178 spdy_util_.ConstructSpdyGet(nullptr, 0, false, 1, MEDIUM, true)); |
| 1179 writes.push_back(CreateMockWrite(*req, seq++)); |
| 1180 |
| 1181 scoped_ptr<SpdyFrame> resp( |
| 1182 spdy_util_.ConstructSpdyGetSynReply(nullptr, 0, 1)); |
| 1183 reads.push_back(CreateMockRead(*resp, seq++)); |
| 1184 |
| 1185 scoped_ptr<SpdyFrame> body(spdy_util_.ConstructSpdyBodyFrame(1, true)); |
| 1186 reads.push_back(CreateMockRead(*body, seq++)); |
| 1187 |
| 1188 reads.push_back(MockRead(ASYNC, 0, seq++)); |
| 1189 |
| 1190 SequencedSocketData data(reads.data(), reads.size(), writes.data(), |
| 1191 writes.size()); |
| 1192 session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1193 |
| 1194 // Create session. |
| 1195 CreateNetworkSession(); |
| 1196 CreateInsecureSpdySession(); |
| 1197 |
| 1198 // Receive SETTINGS frame that sets max_concurrent_streams to zero. |
| 1199 base::RunLoop().RunUntilIdle(); |
| 1200 EXPECT_EQ(0u, session_->max_concurrent_streams_); |
| 1201 |
| 1202 // Start request. |
| 1203 SpdyStreamRequest request; |
| 1204 TestCompletionCallback callback; |
| 1205 int rv = |
| 1206 request.StartRequest(SPDY_REQUEST_RESPONSE_STREAM, session_, test_url_, |
| 1207 MEDIUM, BoundNetLog(), callback.callback()); |
| 1208 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1209 |
| 1210 // Stream is stalled. |
| 1211 EXPECT_EQ(1u, session_->pending_create_stream_queue_size(MEDIUM)); |
| 1212 EXPECT_EQ(0u, session_->num_created_streams()); |
| 1213 |
| 1214 // Receive SETTINGS frame that sets max_concurrent_streams to one. |
| 1215 data.Resume(); |
| 1216 base::RunLoop().RunUntilIdle(); |
| 1217 EXPECT_EQ(1u, session_->max_concurrent_streams_); |
| 1218 |
| 1219 // Stream is created. |
| 1220 EXPECT_EQ(0u, session_->pending_create_stream_queue_size(MEDIUM)); |
| 1221 EXPECT_EQ(1u, session_->num_created_streams()); |
| 1222 |
| 1223 EXPECT_EQ(OK, callback.WaitForResult()); |
| 1224 |
| 1225 // Send request. |
| 1226 base::WeakPtr<SpdyStream> stream = request.ReleaseStream(); |
| 1227 test::StreamDelegateDoNothing delegate(stream); |
| 1228 stream->SetDelegate(&delegate); |
| 1229 scoped_ptr<SpdyHeaderBlock> headers( |
| 1230 spdy_util_.ConstructGetHeaderBlock(kDefaultURL)); |
| 1231 stream->SendRequestHeaders(std::move(headers), NO_MORE_DATA_TO_SEND); |
| 1232 EXPECT_TRUE(stream->HasUrlFromHeaders()); |
| 1233 |
| 1234 EXPECT_EQ(OK, delegate.WaitForClose()); |
| 1235 EXPECT_EQ("hello!", delegate.TakeReceivedData()); |
| 1236 |
| 1237 // Session is destroyed. |
| 1238 EXPECT_FALSE(session_); |
| 1239 } |
| 1240 |
1135 // Verifies that an unstalled pending stream creation racing with a new stream | 1241 // Verifies that an unstalled pending stream creation racing with a new stream |
1136 // creation doesn't violate the maximum stream concurrency. Regression test for | 1242 // creation doesn't violate the maximum stream concurrency. Regression test for |
1137 // crbug.com/373858. | 1243 // crbug.com/373858. |
1138 TEST_P(SpdySessionTest, UnstallRacesWithStreamCreation) { | 1244 TEST_P(SpdySessionTest, UnstallRacesWithStreamCreation) { |
1139 session_deps_.host_resolver->set_synchronous_mode(true); | 1245 session_deps_.host_resolver->set_synchronous_mode(true); |
1140 | 1246 |
1141 MockRead reads[] = { | 1247 MockRead reads[] = { |
1142 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. | 1248 MockRead(SYNCHRONOUS, ERR_IO_PENDING) // Stall forever. |
1143 }; | 1249 }; |
1144 | 1250 |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1452 | 1558 |
1453 EXPECT_EQ(OK, stream_releaser.WaitForResult()); | 1559 EXPECT_EQ(OK, stream_releaser.WaitForResult()); |
1454 | 1560 |
1455 // Make sure that persisted data is cleared. | 1561 // Make sure that persisted data is cleared. |
1456 EXPECT_TRUE( | 1562 EXPECT_TRUE( |
1457 spdy_session_pool_->http_server_properties()->GetSpdySettings( | 1563 spdy_session_pool_->http_server_properties()->GetSpdySettings( |
1458 test_host_port_pair_).empty()); | 1564 test_host_port_pair_).empty()); |
1459 | 1565 |
1460 // Make sure session's max_concurrent_streams is correct. | 1566 // Make sure session's max_concurrent_streams is correct. |
1461 EXPECT_EQ(kInitialMaxConcurrentStreams + 1, | 1567 EXPECT_EQ(kInitialMaxConcurrentStreams + 1, |
1462 session_->max_concurrent_streams()); | 1568 session_->max_concurrent_streams_); |
1463 | 1569 |
1464 data.Resume(); | 1570 data.Resume(); |
1465 base::RunLoop().RunUntilIdle(); | 1571 base::RunLoop().RunUntilIdle(); |
1466 EXPECT_FALSE(session_); | 1572 EXPECT_FALSE(session_); |
1467 } | 1573 } |
1468 | 1574 |
1469 // Start with max concurrent streams set to 1. Request two streams. | 1575 // Start with max concurrent streams set to 1. Request two streams. |
1470 // When the first completes, have the callback close its stream, which | 1576 // When the first completes, have the callback close its stream, which |
1471 // should trigger the second stream creation. Then cancel that one | 1577 // should trigger the second stream creation. Then cancel that one |
1472 // immediately. Don't crash. This is a regression test for | 1578 // immediately. Don't crash. This is a regression test for |
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5334 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), | 5440 ssl_info.cert = ImportCertFromFile(GetTestCertsDirectory(), |
5335 "spdy_pooling.pem"); | 5441 "spdy_pooling.pem"); |
5336 ssl_info.is_issued_by_known_root = true; | 5442 ssl_info.is_issued_by_known_root = true; |
5337 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); | 5443 ssl_info.public_key_hashes.push_back(test::GetTestHashValue(primary_pin)); |
5338 | 5444 |
5339 EXPECT_TRUE(SpdySession::CanPool( | 5445 EXPECT_TRUE(SpdySession::CanPool( |
5340 &tss, ssl_info, "www.example.org", "mail.example.org")); | 5446 &tss, ssl_info, "www.example.org", "mail.example.org")); |
5341 } | 5447 } |
5342 | 5448 |
5343 } // namespace net | 5449 } // namespace net |
OLD | NEW |