OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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_test_util_common.h" | 5 #include "net/spdy/spdy_test_util_common.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <cstddef> | 9 #include <cstddef> |
10 | 10 |
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 } | 727 } |
728 | 728 |
729 void SpdySessionPoolPeer::SetSessionMaxRecvWindowSize(size_t window) { | 729 void SpdySessionPoolPeer::SetSessionMaxRecvWindowSize(size_t window) { |
730 pool_->session_max_recv_window_size_ = window; | 730 pool_->session_max_recv_window_size_ = window; |
731 } | 731 } |
732 | 732 |
733 void SpdySessionPoolPeer::SetStreamInitialRecvWindowSize(size_t window) { | 733 void SpdySessionPoolPeer::SetStreamInitialRecvWindowSize(size_t window) { |
734 pool_->stream_max_recv_window_size_ = window; | 734 pool_->stream_max_recv_window_size_ = window; |
735 } | 735 } |
736 | 736 |
737 SpdyTestUtil::SpdyTestUtil(NextProto protocol) | 737 SpdyTestUtil::SpdyTestUtil(NextProto protocol, bool dependency_priorities) |
738 : protocol_(protocol), | 738 : protocol_(protocol), |
739 spdy_version_(NextProtoToSpdyMajorVersion(protocol)), | 739 spdy_version_(NextProtoToSpdyMajorVersion(protocol)), |
740 default_url_(GURL(kDefaultURL)) { | 740 default_url_(GURL(kDefaultURL)), |
| 741 dependency_priorities_(dependency_priorities) { |
741 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 742 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
742 } | 743 } |
743 | 744 |
| 745 SpdyTestUtil::~SpdyTestUtil() {} |
| 746 |
744 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, | 747 void SpdyTestUtil::AddUrlToHeaderBlock(base::StringPiece url, |
745 SpdyHeaderBlock* headers) const { | 748 SpdyHeaderBlock* headers) const { |
746 std::string scheme, host, path; | 749 std::string scheme, host, path; |
747 ParseUrl(url, &scheme, &host, &path); | 750 ParseUrl(url, &scheme, &host, &path); |
748 (*headers)[GetHostKey()] = host; | 751 (*headers)[GetHostKey()] = host; |
749 (*headers)[GetSchemeKey()] = scheme; | 752 (*headers)[GetSchemeKey()] = scheme; |
750 (*headers)[GetPathKey()] = path; | 753 (*headers)[GetPathKey()] = path; |
751 } | 754 } |
752 | 755 |
753 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( | 756 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 957 |
955 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer | 958 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer |
956 // SpdyRstStreamIR). | 959 // SpdyRstStreamIR). |
957 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream( | 960 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream( |
958 SpdyStreamId stream_id, | 961 SpdyStreamId stream_id, |
959 SpdyRstStreamStatus status) const { | 962 SpdyRstStreamStatus status) const { |
960 SpdyRstStreamIR rst_ir(stream_id, status); | 963 SpdyRstStreamIR rst_ir(stream_id, status); |
961 return CreateFramer(false)->SerializeRstStream(rst_ir); | 964 return CreateFramer(false)->SerializeRstStream(rst_ir); |
962 } | 965 } |
963 | 966 |
964 SpdyFrame* SpdyTestUtil::ConstructSpdyGet( | 967 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const url, |
965 const char* const url, | 968 bool compressed, |
966 bool compressed, | 969 SpdyStreamId stream_id, |
967 SpdyStreamId stream_id, | 970 RequestPriority request_priority) { |
968 RequestPriority request_priority) const { | |
969 scoped_ptr<SpdyHeaderBlock> block(ConstructGetHeaderBlock(url)); | 971 scoped_ptr<SpdyHeaderBlock> block(ConstructGetHeaderBlock(url)); |
970 return ConstructSpdySyn( | 972 return ConstructSpdySyn( |
971 stream_id, *block, request_priority, compressed, true); | 973 stream_id, *block, request_priority, compressed, true); |
972 } | 974 } |
973 | 975 |
974 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], | 976 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], |
975 int extra_header_count, | 977 int extra_header_count, |
976 bool compressed, | 978 bool compressed, |
977 int stream_id, | 979 int stream_id, |
978 RequestPriority request_priority, | 980 RequestPriority request_priority, |
979 bool direct) const { | 981 bool direct) { |
980 SpdyHeaderBlock block; | 982 SpdyHeaderBlock block; |
981 MaybeAddVersionHeader(&block); | 983 MaybeAddVersionHeader(&block); |
982 block[GetMethodKey()] = "GET"; | 984 block[GetMethodKey()] = "GET"; |
983 AddUrlToHeaderBlock(default_url_.spec(), &block); | 985 AddUrlToHeaderBlock(default_url_.spec(), &block); |
984 AppendToHeaderBlock(extra_headers, extra_header_count, &block); | 986 AppendToHeaderBlock(extra_headers, extra_header_count, &block); |
985 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true); | 987 return ConstructSpdySyn(stream_id, block, request_priority, compressed, true); |
986 } | 988 } |
987 | 989 |
988 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( | 990 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( |
989 const char* const extra_headers[], | 991 const char* const extra_headers[], |
990 int extra_header_count, | 992 int extra_header_count, |
991 int stream_id, | 993 int stream_id, |
992 RequestPriority priority, | 994 RequestPriority priority, |
993 const HostPortPair& host_port_pair) const { | 995 const HostPortPair& host_port_pair) { |
994 SpdyHeaderBlock block; | 996 SpdyHeaderBlock block; |
995 MaybeAddVersionHeader(&block); | 997 MaybeAddVersionHeader(&block); |
996 block[GetMethodKey()] = "CONNECT"; | 998 block[GetMethodKey()] = "CONNECT"; |
997 if (spdy_version() < HTTP2) { | 999 if (spdy_version() < HTTP2) { |
998 block[GetHostKey()] = (host_port_pair.port() == 443) | 1000 block[GetHostKey()] = (host_port_pair.port() == 443) |
999 ? host_port_pair.host() | 1001 ? host_port_pair.host() |
1000 : host_port_pair.ToString(); | 1002 : host_port_pair.ToString(); |
1001 block[GetPathKey()] = host_port_pair.ToString(); | 1003 block[GetPathKey()] = host_port_pair.ToString(); |
1002 } else { | 1004 } else { |
1003 block[GetHostKey()] = host_port_pair.ToString(); | 1005 block[GetHostKey()] = host_port_pair.ToString(); |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1127 SpdyHeadersIR spdy_headers(stream_id); | 1129 SpdyHeadersIR spdy_headers(stream_id); |
1128 AppendToHeaderBlock(headers, header_count, | 1130 AppendToHeaderBlock(headers, header_count, |
1129 spdy_headers.mutable_header_block()); | 1131 spdy_headers.mutable_header_block()); |
1130 return CreateFramer(false)->SerializeFrame(spdy_headers); | 1132 return CreateFramer(false)->SerializeFrame(spdy_headers); |
1131 } | 1133 } |
1132 | 1134 |
1133 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, | 1135 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, |
1134 const SpdyHeaderBlock& block, | 1136 const SpdyHeaderBlock& block, |
1135 RequestPriority priority, | 1137 RequestPriority priority, |
1136 bool compressed, | 1138 bool compressed, |
1137 bool fin) const { | 1139 bool fin) { |
| 1140 // Get the stream id of the next highest priority request |
| 1141 // (most recent request of the same priority, or last request of |
| 1142 // an earlier priority). |
| 1143 int parent_stream_id = 0; |
| 1144 for (int q = priority; q >= IDLE; --q) { |
| 1145 if (!priority_to_stream_id_list_[q].empty()) { |
| 1146 parent_stream_id = priority_to_stream_id_list_[q].back(); |
| 1147 break; |
| 1148 } |
| 1149 } |
| 1150 |
| 1151 priority_to_stream_id_list_[priority].push_back(stream_id); |
| 1152 |
1138 if (protocol_ < kProtoHTTP2) { | 1153 if (protocol_ < kProtoHTTP2) { |
1139 SpdySynStreamIR syn_stream(stream_id); | 1154 SpdySynStreamIR syn_stream(stream_id); |
1140 syn_stream.set_header_block(block); | 1155 syn_stream.set_header_block(block); |
1141 syn_stream.set_priority( | 1156 syn_stream.set_priority( |
1142 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1157 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
1143 syn_stream.set_fin(fin); | 1158 syn_stream.set_fin(fin); |
1144 return CreateFramer(compressed)->SerializeFrame(syn_stream); | 1159 return CreateFramer(compressed)->SerializeFrame(syn_stream); |
1145 } else { | 1160 } else { |
1146 SpdyHeadersIR headers(stream_id); | 1161 SpdyHeadersIR headers(stream_id); |
1147 headers.set_header_block(block); | 1162 headers.set_header_block(block); |
1148 headers.set_has_priority(true); | 1163 headers.set_has_priority(true); |
1149 headers.set_priority( | 1164 headers.set_priority( |
1150 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1165 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
| 1166 if (dependency_priorities_) { |
| 1167 headers.set_parent_stream_id(parent_stream_id); |
| 1168 headers.set_exclusive(true); |
| 1169 } |
1151 headers.set_fin(fin); | 1170 headers.set_fin(fin); |
1152 return CreateFramer(compressed)->SerializeFrame(headers); | 1171 return CreateFramer(compressed)->SerializeFrame(headers); |
1153 } | 1172 } |
1154 } | 1173 } |
1155 | 1174 |
1156 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, | 1175 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, |
1157 const SpdyHeaderBlock& headers) { | 1176 const SpdyHeaderBlock& headers) { |
1158 if (protocol_ < kProtoHTTP2) { | 1177 if (protocol_ < kProtoHTTP2) { |
1159 SpdySynReplyIR syn_reply(stream_id); | 1178 SpdySynReplyIR syn_reply(stream_id); |
1160 syn_reply.set_header_block(headers); | 1179 syn_reply.set_header_block(headers); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1265 return framer.SerializeData(data_ir); | 1284 return framer.SerializeData(data_ir); |
1266 } | 1285 } |
1267 | 1286 |
1268 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( | 1287 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( |
1269 const scoped_ptr<SpdyFrame>& frame, | 1288 const scoped_ptr<SpdyFrame>& frame, |
1270 int stream_id) { | 1289 int stream_id) { |
1271 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 1290 return ConstructSpdyBodyFrame(stream_id, frame->data(), |
1272 frame->size(), false); | 1291 frame->size(), false); |
1273 } | 1292 } |
1274 | 1293 |
| 1294 void SpdyTestUtil::UpdateWithStreamDestruction(int stream_id) { |
| 1295 for (auto priority_it = priority_to_stream_id_list_.begin(); |
| 1296 priority_it != priority_to_stream_id_list_.end(); ++priority_it) { |
| 1297 for (auto stream_it = priority_it->second.begin(); |
| 1298 stream_it != priority_it->second.end(); ++stream_it) { |
| 1299 if (*stream_it == stream_id) { |
| 1300 priority_it->second.erase(stream_it); |
| 1301 return; |
| 1302 } |
| 1303 } |
| 1304 } |
| 1305 NOTREACHED(); |
| 1306 } |
| 1307 |
1275 const SpdyHeaderInfo SpdyTestUtil::MakeSpdyHeader(SpdyFrameType type) { | 1308 const SpdyHeaderInfo SpdyTestUtil::MakeSpdyHeader(SpdyFrameType type) { |
1276 const SpdyHeaderInfo kHeader = { | 1309 const SpdyHeaderInfo kHeader = { |
1277 type, | 1310 type, |
1278 1, // Stream ID | 1311 1, // Stream ID |
1279 0, // Associated stream ID | 1312 0, // Associated stream ID |
1280 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_version_), | 1313 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_version_), |
1281 kSpdyCredentialSlotUnused, | 1314 kSpdyCredentialSlotUnused, |
1282 CONTROL_FLAG_FIN, // Control Flags | 1315 CONTROL_FLAG_FIN, // Control Flags |
1283 false, // Compressed | 1316 false, // Compressed |
1284 RST_STREAM_INVALID, | 1317 RST_STREAM_INVALID, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 } | 1389 } |
1357 } | 1390 } |
1358 | 1391 |
1359 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1392 void SpdyTestUtil::SetPriority(RequestPriority priority, |
1360 SpdySynStreamIR* ir) const { | 1393 SpdySynStreamIR* ir) const { |
1361 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1394 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
1362 priority, spdy_version())); | 1395 priority, spdy_version())); |
1363 } | 1396 } |
1364 | 1397 |
1365 } // namespace net | 1398 } // namespace net |
OLD | NEW |