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 <cstddef> | 7 #include <cstddef> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 } | 50 } |
51 | 51 |
52 } // namespace | 52 } // namespace |
53 | 53 |
54 NextProtoVector SpdyNextProtos() { | 54 NextProtoVector SpdyNextProtos() { |
55 NextProtoVector next_protos; | 55 NextProtoVector next_protos; |
56 next_protos.push_back(kProtoHTTP11); | 56 next_protos.push_back(kProtoHTTP11); |
57 next_protos.push_back(kProtoDeprecatedSPDY2); | 57 next_protos.push_back(kProtoDeprecatedSPDY2); |
58 next_protos.push_back(kProtoSPDY3); | 58 next_protos.push_back(kProtoSPDY3); |
59 next_protos.push_back(kProtoSPDY31); | 59 next_protos.push_back(kProtoSPDY31); |
60 next_protos.push_back(kProtoSPDY4); | 60 next_protos.push_back(kProtoSPDY4_14); |
| 61 next_protos.push_back(kProtoSPDY4_15); |
61 next_protos.push_back(kProtoQUIC1SPDY3); | 62 next_protos.push_back(kProtoQUIC1SPDY3); |
62 return next_protos; | 63 return next_protos; |
63 } | 64 } |
64 | 65 |
65 // Chop a frame into an array of MockWrites. | 66 // Chop a frame into an array of MockWrites. |
66 // |data| is the frame to chop. | 67 // |data| is the frame to chop. |
67 // |length| is the length of the frame to chop. | 68 // |length| is the length of the frame to chop. |
68 // |num_chunks| is the number of chunks to create. | 69 // |num_chunks| is the number of chunks to create. |
69 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { | 70 MockWrite* ChopWriteFrame(const char* data, int length, int num_chunks) { |
70 MockWrite* chunks = new MockWrite[num_chunks]; | 71 MockWrite* chunks = new MockWrite[num_chunks]; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
222 SpdyPriority priority, | 223 SpdyPriority priority, |
223 bool fin, | 224 bool fin, |
224 bool unidirectional, | 225 bool unidirectional, |
225 const SpdyHeaderBlock& headers) override { | 226 const SpdyHeaderBlock& headers) override { |
226 priority_ = priority; | 227 priority_ = priority; |
227 } | 228 } |
228 void OnSynReply(SpdyStreamId stream_id, | 229 void OnSynReply(SpdyStreamId stream_id, |
229 bool fin, | 230 bool fin, |
230 const SpdyHeaderBlock& headers) override {} | 231 const SpdyHeaderBlock& headers) override {} |
231 void OnHeaders(SpdyStreamId stream_id, | 232 void OnHeaders(SpdyStreamId stream_id, |
| 233 bool has_priority, |
| 234 SpdyPriority priority, |
232 bool fin, | 235 bool fin, |
233 const SpdyHeaderBlock& headers) override {} | 236 const SpdyHeaderBlock& headers) override { |
| 237 if (has_priority) { |
| 238 priority_ = priority; |
| 239 } |
| 240 } |
234 void OnDataFrameHeader(SpdyStreamId stream_id, | 241 void OnDataFrameHeader(SpdyStreamId stream_id, |
235 size_t length, | 242 size_t length, |
236 bool fin) override {} | 243 bool fin) override {} |
237 void OnStreamFrameData(SpdyStreamId stream_id, | 244 void OnStreamFrameData(SpdyStreamId stream_id, |
238 const char* data, | 245 const char* data, |
239 size_t len, | 246 size_t len, |
240 bool fin) override {} | 247 bool fin) override {} |
241 void OnSettings(bool clear_persisted) override {} | 248 void OnSettings(bool clear_persisted) override {} |
242 void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) override {} | 249 void OnSetting(SpdySettingsIds id, uint8 flags, uint32 value) override {} |
243 void OnPing(SpdyPingId unique_id, bool is_ack) override {} | 250 void OnPing(SpdyPingId unique_id, bool is_ack) override {} |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 enable_ip_pooling(true), | 367 enable_ip_pooling(true), |
361 enable_compression(false), | 368 enable_compression(false), |
362 enable_ping(false), | 369 enable_ping(false), |
363 enable_user_alternate_protocol_ports(false), | 370 enable_user_alternate_protocol_ports(false), |
364 protocol(protocol), | 371 protocol(protocol), |
365 stream_initial_recv_window_size(kSpdyStreamInitialWindowSize), | 372 stream_initial_recv_window_size(kSpdyStreamInitialWindowSize), |
366 time_func(&base::TimeTicks::Now), | 373 time_func(&base::TimeTicks::Now), |
367 force_spdy_over_ssl(false), | 374 force_spdy_over_ssl(false), |
368 force_spdy_always(false), | 375 force_spdy_always(false), |
369 use_alternate_protocols(false), | 376 use_alternate_protocols(false), |
370 enable_websocket_over_spdy(false), | |
371 net_log(NULL) { | 377 net_log(NULL) { |
372 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 378 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
373 | 379 |
374 // Note: The CancelledTransaction test does cleanup by running all | 380 // Note: The CancelledTransaction test does cleanup by running all |
375 // tasks in the message loop (RunAllPending). Unfortunately, that | 381 // tasks in the message loop (RunAllPending). Unfortunately, that |
376 // doesn't clean up tasks on the host resolver thread; and | 382 // doesn't clean up tasks on the host resolver thread; and |
377 // TCPConnectJob is currently not cancellable. Using synchronous | 383 // TCPConnectJob is currently not cancellable. Using synchronous |
378 // lookups allows the test to shutdown cleanly. Until we have | 384 // lookups allows the test to shutdown cleanly. Until we have |
379 // cancellable TCPConnectJobs, use synchronous lookups. | 385 // cancellable TCPConnectJobs, use synchronous lookups. |
380 host_resolver->set_synchronous_mode(true); | 386 host_resolver->set_synchronous_mode(true); |
(...skipping 13 matching lines...) Expand all Loading... |
394 enable_ip_pooling(true), | 400 enable_ip_pooling(true), |
395 enable_compression(false), | 401 enable_compression(false), |
396 enable_ping(false), | 402 enable_ping(false), |
397 enable_user_alternate_protocol_ports(false), | 403 enable_user_alternate_protocol_ports(false), |
398 protocol(protocol), | 404 protocol(protocol), |
399 stream_initial_recv_window_size(kSpdyStreamInitialWindowSize), | 405 stream_initial_recv_window_size(kSpdyStreamInitialWindowSize), |
400 time_func(&base::TimeTicks::Now), | 406 time_func(&base::TimeTicks::Now), |
401 force_spdy_over_ssl(false), | 407 force_spdy_over_ssl(false), |
402 force_spdy_always(false), | 408 force_spdy_always(false), |
403 use_alternate_protocols(false), | 409 use_alternate_protocols(false), |
404 enable_websocket_over_spdy(false), | |
405 net_log(NULL) { | 410 net_log(NULL) { |
406 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 411 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
407 } | 412 } |
408 | 413 |
409 SpdySessionDependencies::~SpdySessionDependencies() {} | 414 SpdySessionDependencies::~SpdySessionDependencies() {} |
410 | 415 |
411 // static | 416 // static |
412 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( | 417 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( |
413 SpdySessionDependencies* session_deps) { | 418 SpdySessionDependencies* session_deps) { |
414 net::HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 419 net::HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 session_deps->enable_user_alternate_protocol_ports; | 459 session_deps->enable_user_alternate_protocol_ports; |
455 params.spdy_default_protocol = session_deps->protocol; | 460 params.spdy_default_protocol = session_deps->protocol; |
456 params.spdy_stream_initial_recv_window_size = | 461 params.spdy_stream_initial_recv_window_size = |
457 session_deps->stream_initial_recv_window_size; | 462 session_deps->stream_initial_recv_window_size; |
458 params.time_func = session_deps->time_func; | 463 params.time_func = session_deps->time_func; |
459 params.next_protos = session_deps->next_protos; | 464 params.next_protos = session_deps->next_protos; |
460 params.trusted_spdy_proxy = session_deps->trusted_spdy_proxy; | 465 params.trusted_spdy_proxy = session_deps->trusted_spdy_proxy; |
461 params.force_spdy_over_ssl = session_deps->force_spdy_over_ssl; | 466 params.force_spdy_over_ssl = session_deps->force_spdy_over_ssl; |
462 params.force_spdy_always = session_deps->force_spdy_always; | 467 params.force_spdy_always = session_deps->force_spdy_always; |
463 params.use_alternate_protocols = session_deps->use_alternate_protocols; | 468 params.use_alternate_protocols = session_deps->use_alternate_protocols; |
464 params.enable_websocket_over_spdy = session_deps->enable_websocket_over_spdy; | |
465 params.net_log = session_deps->net_log; | 469 params.net_log = session_deps->net_log; |
466 return params; | 470 return params; |
467 } | 471 } |
468 | 472 |
469 SpdyURLRequestContext::SpdyURLRequestContext(NextProto protocol, | 473 SpdyURLRequestContext::SpdyURLRequestContext(NextProto protocol, |
470 bool force_spdy_over_ssl, | 474 bool force_spdy_over_ssl, |
471 bool force_spdy_always) | 475 bool force_spdy_always) |
472 : storage_(this) { | 476 : storage_(this) { |
473 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 477 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
474 | 478 |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 break; | 783 break; |
780 case SYN_REPLY: | 784 case SYN_REPLY: |
781 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, | 785 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, |
782 headers.get()); | 786 headers.get()); |
783 break; | 787 break; |
784 case RST_STREAM: | 788 case RST_STREAM: |
785 frame = framer.CreateRstStream(header_info.id, header_info.status); | 789 frame = framer.CreateRstStream(header_info.id, header_info.status); |
786 break; | 790 break; |
787 case HEADERS: | 791 case HEADERS: |
788 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, | 792 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, |
| 793 header_info.priority, |
789 headers.get()); | 794 headers.get()); |
790 break; | 795 break; |
791 default: | 796 default: |
792 ADD_FAILURE(); | 797 ADD_FAILURE(); |
793 break; | 798 break; |
794 } | 799 } |
795 return frame; | 800 return frame; |
796 } | 801 } |
797 | 802 |
798 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, | 803 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 AppendToHeaderBlock(extra_headers, extra_header_count, | 1101 AppendToHeaderBlock(extra_headers, extra_header_count, |
1097 headers.mutable_name_value_block()); | 1102 headers.mutable_name_value_block()); |
1098 return CreateFramer(false)->SerializeFrame(headers); | 1103 return CreateFramer(false)->SerializeFrame(headers); |
1099 } | 1104 } |
1100 | 1105 |
1101 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, | 1106 SpdyFrame* SpdyTestUtil::ConstructSpdySyn(int stream_id, |
1102 const SpdyHeaderBlock& block, | 1107 const SpdyHeaderBlock& block, |
1103 RequestPriority priority, | 1108 RequestPriority priority, |
1104 bool compressed, | 1109 bool compressed, |
1105 bool fin) const { | 1110 bool fin) const { |
1106 if (protocol_ < kProtoSPDY4) { | 1111 if (protocol_ < kProtoSPDY4MinimumVersion) { |
1107 SpdySynStreamIR syn_stream(stream_id); | 1112 SpdySynStreamIR syn_stream(stream_id); |
1108 syn_stream.set_name_value_block(block); | 1113 syn_stream.set_name_value_block(block); |
1109 syn_stream.set_priority( | 1114 syn_stream.set_priority( |
1110 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1115 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
1111 syn_stream.set_fin(fin); | 1116 syn_stream.set_fin(fin); |
1112 return CreateFramer(compressed)->SerializeFrame(syn_stream); | 1117 return CreateFramer(compressed)->SerializeFrame(syn_stream); |
1113 } else { | 1118 } else { |
1114 SpdyHeadersIR headers(stream_id); | 1119 SpdyHeadersIR headers(stream_id); |
1115 headers.set_name_value_block(block); | 1120 headers.set_name_value_block(block); |
1116 headers.set_has_priority(true); | 1121 headers.set_has_priority(true); |
1117 headers.set_priority( | 1122 headers.set_priority( |
1118 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); | 1123 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
1119 headers.set_fin(fin); | 1124 headers.set_fin(fin); |
1120 return CreateFramer(compressed)->SerializeFrame(headers); | 1125 return CreateFramer(compressed)->SerializeFrame(headers); |
1121 } | 1126 } |
1122 } | 1127 } |
1123 | 1128 |
1124 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, | 1129 SpdyFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, |
1125 const SpdyHeaderBlock& headers) { | 1130 const SpdyHeaderBlock& headers) { |
1126 if (protocol_ < kProtoSPDY4) { | 1131 if (protocol_ < kProtoSPDY4MinimumVersion) { |
1127 SpdySynReplyIR syn_reply(stream_id); | 1132 SpdySynReplyIR syn_reply(stream_id); |
1128 syn_reply.set_name_value_block(headers); | 1133 syn_reply.set_name_value_block(headers); |
1129 return CreateFramer(false)->SerializeFrame(syn_reply); | 1134 return CreateFramer(false)->SerializeFrame(syn_reply); |
1130 } else { | 1135 } else { |
1131 SpdyHeadersIR reply(stream_id); | 1136 SpdyHeadersIR reply(stream_id); |
1132 reply.set_name_value_block(headers); | 1137 reply.set_name_value_block(headers); |
1133 return CreateFramer(false)->SerializeFrame(reply); | 1138 return CreateFramer(false)->SerializeFrame(reply); |
1134 } | 1139 } |
1135 } | 1140 } |
1136 | 1141 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 return is_spdy2() ? "method" : ":method"; | 1262 return is_spdy2() ? "method" : ":method"; |
1258 } | 1263 } |
1259 | 1264 |
1260 const char* SpdyTestUtil::GetStatusKey() const { | 1265 const char* SpdyTestUtil::GetStatusKey() const { |
1261 return is_spdy2() ? "status" : ":status"; | 1266 return is_spdy2() ? "status" : ":status"; |
1262 } | 1267 } |
1263 | 1268 |
1264 const char* SpdyTestUtil::GetHostKey() const { | 1269 const char* SpdyTestUtil::GetHostKey() const { |
1265 if (protocol_ < kProtoSPDY3) | 1270 if (protocol_ < kProtoSPDY3) |
1266 return "host"; | 1271 return "host"; |
1267 if (protocol_ < kProtoSPDY4) | 1272 if (protocol_ < kProtoSPDY4MinimumVersion) |
1268 return ":host"; | 1273 return ":host"; |
1269 else | 1274 else |
1270 return ":authority"; | 1275 return ":authority"; |
1271 } | 1276 } |
1272 | 1277 |
1273 const char* SpdyTestUtil::GetSchemeKey() const { | 1278 const char* SpdyTestUtil::GetSchemeKey() const { |
1274 return is_spdy2() ? "scheme" : ":scheme"; | 1279 return is_spdy2() ? "scheme" : ":scheme"; |
1275 } | 1280 } |
1276 | 1281 |
1277 const char* SpdyTestUtil::GetVersionKey() const { | 1282 const char* SpdyTestUtil::GetVersionKey() const { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 } | 1321 } |
1317 } | 1322 } |
1318 | 1323 |
1319 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1324 void SpdyTestUtil::SetPriority(RequestPriority priority, |
1320 SpdySynStreamIR* ir) const { | 1325 SpdySynStreamIR* ir) const { |
1321 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1326 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
1322 priority, spdy_version())); | 1327 priority, spdy_version())); |
1323 } | 1328 } |
1324 | 1329 |
1325 } // namespace net | 1330 } // namespace net |
OLD | NEW |