| 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 #include <utility> | 10 #include <utility> |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 PriorityGetter() : priority_(0) {} | 181 PriorityGetter() : priority_(0) {} |
| 182 ~PriorityGetter() override {} | 182 ~PriorityGetter() override {} |
| 183 | 183 |
| 184 SpdyPriority priority() const { | 184 SpdyPriority priority() const { |
| 185 return priority_; | 185 return priority_; |
| 186 } | 186 } |
| 187 | 187 |
| 188 void OnError(SpdyFramer::SpdyError error_code) override {} | 188 void OnError(SpdyFramer::SpdyError error_code) override {} |
| 189 void OnStreamError(SpdyStreamId stream_id, | 189 void OnStreamError(SpdyStreamId stream_id, |
| 190 const std::string& description) override {} | 190 const std::string& description) override {} |
| 191 void OnSynStream(SpdyStreamId stream_id, | |
| 192 SpdyStreamId associated_stream_id, | |
| 193 SpdyPriority priority, | |
| 194 bool fin, | |
| 195 bool unidirectional, | |
| 196 const SpdyHeaderBlock& headers) override { | |
| 197 priority_ = priority; | |
| 198 } | |
| 199 void OnSynReply(SpdyStreamId stream_id, | |
| 200 bool fin, | |
| 201 const SpdyHeaderBlock& headers) override {} | |
| 202 void OnHeaders(SpdyStreamId stream_id, | 191 void OnHeaders(SpdyStreamId stream_id, |
| 203 bool has_priority, | 192 bool has_priority, |
| 204 int weight, | 193 int weight, |
| 205 SpdyStreamId parent_stream_id, | 194 SpdyStreamId parent_stream_id, |
| 206 bool exclusive, | 195 bool exclusive, |
| 207 bool fin, | 196 bool fin, |
| 208 const SpdyHeaderBlock& headers) override { | 197 const SpdyHeaderBlock& headers) override { |
| 209 if (has_priority) { | 198 if (has_priority) { |
| 210 priority_ = Http2WeightToSpdy3Priority(weight); | 199 priority_ = Http2WeightToSpdy3Priority(weight); |
| 211 } | 200 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 238 return false; | 227 return false; |
| 239 } | 228 } |
| 240 | 229 |
| 241 private: | 230 private: |
| 242 SpdyPriority priority_; | 231 SpdyPriority priority_; |
| 243 }; | 232 }; |
| 244 | 233 |
| 245 } // namespace | 234 } // namespace |
| 246 | 235 |
| 247 bool GetSpdyPriority(const SpdySerializedFrame& frame, SpdyPriority* priority) { | 236 bool GetSpdyPriority(const SpdySerializedFrame& frame, SpdyPriority* priority) { |
| 248 BufferedSpdyFramer framer(HTTP2); | 237 BufferedSpdyFramer framer; |
| 249 PriorityGetter priority_getter; | 238 PriorityGetter priority_getter; |
| 250 framer.set_visitor(&priority_getter); | 239 framer.set_visitor(&priority_getter); |
| 251 size_t frame_size = frame.size(); | 240 size_t frame_size = frame.size(); |
| 252 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) { | 241 if (framer.ProcessInput(frame.data(), frame_size) != frame_size) { |
| 253 return false; | 242 return false; |
| 254 } | 243 } |
| 255 *priority = priority_getter.priority(); | 244 *priority = priority_getter.priority(); |
| 256 return true; | 245 return true; |
| 257 } | 246 } |
| 258 | 247 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 ssl_config_service(new SSLConfigServiceDefaults), | 333 ssl_config_service(new SSLConfigServiceDefaults), |
| 345 socket_factory(new MockClientSocketFactory), | 334 socket_factory(new MockClientSocketFactory), |
| 346 http_auth_handler_factory( | 335 http_auth_handler_factory( |
| 347 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 336 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| 348 http_server_properties(new HttpServerPropertiesImpl), | 337 http_server_properties(new HttpServerPropertiesImpl), |
| 349 enable_ip_pooling(true), | 338 enable_ip_pooling(true), |
| 350 enable_ping(false), | 339 enable_ping(false), |
| 351 enable_user_alternate_protocol_ports(false), | 340 enable_user_alternate_protocol_ports(false), |
| 352 enable_priority_dependencies(true), | 341 enable_priority_dependencies(true), |
| 353 enable_quic(false), | 342 enable_quic(false), |
| 354 session_max_recv_window_size( | 343 session_max_recv_window_size(kDefaultInitialWindowSize), |
| 355 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2)), | 344 stream_max_recv_window_size(kDefaultInitialWindowSize), |
| 356 stream_max_recv_window_size( | |
| 357 SpdySession::GetDefaultInitialWindowSize(kProtoHTTP2)), | |
| 358 time_func(&base::TimeTicks::Now), | 345 time_func(&base::TimeTicks::Now), |
| 359 enable_http2_alternative_service_with_different_host(false), | 346 enable_http2_alternative_service_with_different_host(false), |
| 360 net_log(NULL) { | 347 net_log(NULL) { |
| 361 // Note: The CancelledTransaction test does cleanup by running all | 348 // Note: The CancelledTransaction test does cleanup by running all |
| 362 // tasks in the message loop (RunAllPending). Unfortunately, that | 349 // tasks in the message loop (RunAllPending). Unfortunately, that |
| 363 // doesn't clean up tasks on the host resolver thread; and | 350 // doesn't clean up tasks on the host resolver thread; and |
| 364 // TCPConnectJob is currently not cancellable. Using synchronous | 351 // TCPConnectJob is currently not cancellable. Using synchronous |
| 365 // lookups allows the test to shutdown cleanly. Until we have | 352 // lookups allows the test to shutdown cleanly. Until we have |
| 366 // cancellable TCPConnectJobs, use synchronous lookups. | 353 // cancellable TCPConnectJobs, use synchronous lookups. |
| 367 host_resolver->set_synchronous_mode(true); | 354 host_resolver->set_synchronous_mode(true); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 397 params.ssl_config_service = session_deps->ssl_config_service.get(); | 384 params.ssl_config_service = session_deps->ssl_config_service.get(); |
| 398 params.http_auth_handler_factory = | 385 params.http_auth_handler_factory = |
| 399 session_deps->http_auth_handler_factory.get(); | 386 session_deps->http_auth_handler_factory.get(); |
| 400 params.http_server_properties = session_deps->http_server_properties.get(); | 387 params.http_server_properties = session_deps->http_server_properties.get(); |
| 401 params.enable_spdy_ping_based_connection_checking = session_deps->enable_ping; | 388 params.enable_spdy_ping_based_connection_checking = session_deps->enable_ping; |
| 402 params.enable_user_alternate_protocol_ports = | 389 params.enable_user_alternate_protocol_ports = |
| 403 session_deps->enable_user_alternate_protocol_ports; | 390 session_deps->enable_user_alternate_protocol_ports; |
| 404 params.enable_priority_dependencies = | 391 params.enable_priority_dependencies = |
| 405 session_deps->enable_priority_dependencies; | 392 session_deps->enable_priority_dependencies; |
| 406 params.enable_quic = session_deps->enable_quic; | 393 params.enable_quic = session_deps->enable_quic; |
| 407 params.spdy_default_protocol = kProtoHTTP2; | |
| 408 params.spdy_session_max_recv_window_size = | 394 params.spdy_session_max_recv_window_size = |
| 409 session_deps->session_max_recv_window_size; | 395 session_deps->session_max_recv_window_size; |
| 410 params.spdy_stream_max_recv_window_size = | 396 params.spdy_stream_max_recv_window_size = |
| 411 session_deps->stream_max_recv_window_size; | 397 session_deps->stream_max_recv_window_size; |
| 412 params.time_func = session_deps->time_func; | 398 params.time_func = session_deps->time_func; |
| 413 params.proxy_delegate = session_deps->proxy_delegate.get(); | 399 params.proxy_delegate = session_deps->proxy_delegate.get(); |
| 414 params.enable_http2_alternative_service_with_different_host = | 400 params.enable_http2_alternative_service_with_different_host = |
| 415 session_deps->enable_http2_alternative_service_with_different_host; | 401 session_deps->enable_http2_alternative_service_with_different_host; |
| 416 params.net_log = session_deps->net_log; | 402 params.net_log = session_deps->net_log; |
| 417 return params; | 403 return params; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 432 storage_.set_job_factory(base::WrapUnique(new URLRequestJobFactoryImpl())); | 418 storage_.set_job_factory(base::WrapUnique(new URLRequestJobFactoryImpl())); |
| 433 HttpNetworkSession::Params params; | 419 HttpNetworkSession::Params params; |
| 434 params.client_socket_factory = &socket_factory_; | 420 params.client_socket_factory = &socket_factory_; |
| 435 params.host_resolver = host_resolver(); | 421 params.host_resolver = host_resolver(); |
| 436 params.cert_verifier = cert_verifier(); | 422 params.cert_verifier = cert_verifier(); |
| 437 params.transport_security_state = transport_security_state(); | 423 params.transport_security_state = transport_security_state(); |
| 438 params.proxy_service = proxy_service(); | 424 params.proxy_service = proxy_service(); |
| 439 params.ssl_config_service = ssl_config_service(); | 425 params.ssl_config_service = ssl_config_service(); |
| 440 params.http_auth_handler_factory = http_auth_handler_factory(); | 426 params.http_auth_handler_factory = http_auth_handler_factory(); |
| 441 params.enable_spdy_ping_based_connection_checking = false; | 427 params.enable_spdy_ping_based_connection_checking = false; |
| 442 params.spdy_default_protocol = kProtoHTTP2; | |
| 443 params.http_server_properties = http_server_properties(); | 428 params.http_server_properties = http_server_properties(); |
| 444 storage_.set_http_network_session( | 429 storage_.set_http_network_session( |
| 445 base::WrapUnique(new HttpNetworkSession(params))); | 430 base::WrapUnique(new HttpNetworkSession(params))); |
| 446 SpdySessionPoolPeer pool_peer( | 431 SpdySessionPoolPeer pool_peer( |
| 447 storage_.http_network_session()->spdy_session_pool()); | 432 storage_.http_network_session()->spdy_session_pool()); |
| 448 pool_peer.SetEnableSendingInitialData(false); | 433 pool_peer.SetEnableSendingInitialData(false); |
| 449 storage_.set_http_transaction_factory(base::WrapUnique( | 434 storage_.set_http_transaction_factory(base::WrapUnique( |
| 450 new HttpCache(storage_.http_network_session(), | 435 new HttpCache(storage_.http_network_session(), |
| 451 HttpCache::DefaultBackend::InMemory(0), false))); | 436 HttpCache::DefaultBackend::InMemory(0), false))); |
| 452 } | 437 } |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 701 | 686 |
| 702 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock( | 687 SpdyHeaderBlock SpdyTestUtil::ConstructPutHeaderBlock( |
| 703 base::StringPiece url, | 688 base::StringPiece url, |
| 704 int64_t content_length) const { | 689 int64_t content_length) const { |
| 705 return ConstructHeaderBlock("PUT", url, &content_length); | 690 return ConstructHeaderBlock("PUT", url, &content_length); |
| 706 } | 691 } |
| 707 | 692 |
| 708 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( | 693 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyFrame( |
| 709 const SpdyHeaderInfo& header_info, | 694 const SpdyHeaderInfo& header_info, |
| 710 SpdyHeaderBlock headers) const { | 695 SpdyHeaderBlock headers) const { |
| 711 BufferedSpdyFramer framer(HTTP2); | 696 BufferedSpdyFramer framer; |
| 712 SpdySerializedFrame* frame = NULL; | 697 SpdySerializedFrame* frame = NULL; |
| 713 switch (header_info.kind) { | 698 switch (header_info.kind) { |
| 714 case DATA: | 699 case DATA: |
| 715 frame = framer.CreateDataFrame(header_info.id, header_info.data, | 700 frame = framer.CreateDataFrame(header_info.id, header_info.data, |
| 716 header_info.data_length, | 701 header_info.data_length, |
| 717 header_info.data_flags); | 702 header_info.data_flags); |
| 718 break; | 703 break; |
| 719 case SYN_STREAM: | 704 case SYN_STREAM: |
| 720 frame = framer.CreateSynStream( | 705 frame = framer.CreateSynStream( |
| 721 header_info.id, header_info.assoc_id, header_info.priority, | 706 header_info.id, header_info.assoc_id, header_info.priority, |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 989 parent_stream_id = priority_to_stream_id_list_[q].back(); | 974 parent_stream_id = priority_to_stream_id_list_[q].back(); |
| 990 break; | 975 break; |
| 991 } | 976 } |
| 992 } | 977 } |
| 993 | 978 |
| 994 priority_to_stream_id_list_[priority].push_back(stream_id); | 979 priority_to_stream_id_list_[priority].push_back(stream_id); |
| 995 | 980 |
| 996 SpdyHeadersIR headers(stream_id, std::move(block)); | 981 SpdyHeadersIR headers(stream_id, std::move(block)); |
| 997 headers.set_has_priority(true); | 982 headers.set_has_priority(true); |
| 998 headers.set_weight(Spdy3PriorityToHttp2Weight( | 983 headers.set_weight(Spdy3PriorityToHttp2Weight( |
| 999 ConvertRequestPriorityToSpdyPriority(priority, HTTP2))); | 984 ConvertRequestPriorityToSpdyPriority(priority))); |
| 1000 if (dependency_priorities_) { | 985 if (dependency_priorities_) { |
| 1001 headers.set_parent_stream_id(parent_stream_id); | 986 headers.set_parent_stream_id(parent_stream_id); |
| 1002 headers.set_exclusive(true); | 987 headers.set_exclusive(true); |
| 1003 } | 988 } |
| 1004 headers.set_fin(fin); | 989 headers.set_fin(fin); |
| 1005 return new SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers)); | 990 return new SpdySerializedFrame(request_spdy_framer_.SerializeFrame(headers)); |
| 1006 } | 991 } |
| 1007 | 992 |
| 1008 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, | 993 SpdySerializedFrame* SpdyTestUtil::ConstructSpdyReply(int stream_id, |
| 1009 SpdyHeaderBlock headers) { | 994 SpdyHeaderBlock headers) { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 headers[GetPathKey()] = path.c_str(); | 1152 headers[GetPathKey()] = path.c_str(); |
| 1168 if (content_length) { | 1153 if (content_length) { |
| 1169 std::string length_str = base::Int64ToString(*content_length); | 1154 std::string length_str = base::Int64ToString(*content_length); |
| 1170 headers["content-length"] = length_str; | 1155 headers["content-length"] = length_str; |
| 1171 } | 1156 } |
| 1172 return headers; | 1157 return headers; |
| 1173 } | 1158 } |
| 1174 | 1159 |
| 1175 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1160 void SpdyTestUtil::SetPriority(RequestPriority priority, |
| 1176 SpdySynStreamIR* ir) const { | 1161 SpdySynStreamIR* ir) const { |
| 1177 ir->set_priority(ConvertRequestPriorityToSpdyPriority(priority, HTTP2)); | 1162 ir->set_priority(ConvertRequestPriorityToSpdyPriority(priority)); |
| 1178 } | 1163 } |
| 1179 | 1164 |
| 1180 } // namespace net | 1165 } // namespace net |
| OLD | NEW |