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 13 matching lines...) Expand all Loading... |
24 #include "net/spdy/spdy_session.h" | 24 #include "net/spdy/spdy_session.h" |
25 #include "net/spdy/spdy_session_pool.h" | 25 #include "net/spdy/spdy_session_pool.h" |
26 #include "net/spdy/spdy_stream.h" | 26 #include "net/spdy/spdy_stream.h" |
27 | 27 |
28 namespace net { | 28 namespace net { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 bool next_proto_is_spdy(NextProto next_proto) { | 32 bool next_proto_is_spdy(NextProto next_proto) { |
33 return next_proto >= kProtoSPDYMinimumVersion && | 33 return next_proto >= kProtoSPDYMinimumVersion && |
34 next_proto <= kProtoSPDYMaximumVersion; | 34 next_proto <= kProtoSPDYMaximumVersion; |
35 } | 35 } |
36 | 36 |
37 // Parses a URL into the scheme, host, and path components required for a | 37 // Parses a URL into the scheme, host, and path components required for a |
38 // SPDY request. | 38 // SPDY request. |
39 void ParseUrl(base::StringPiece url, std::string* scheme, std::string* host, | 39 void ParseUrl(base::StringPiece url, |
| 40 std::string* scheme, |
| 41 std::string* host, |
40 std::string* path) { | 42 std::string* path) { |
41 GURL gurl(url.as_string()); | 43 GURL gurl(url.as_string()); |
42 path->assign(gurl.PathForRequest()); | 44 path->assign(gurl.PathForRequest()); |
43 scheme->assign(gurl.scheme()); | 45 scheme->assign(gurl.scheme()); |
44 host->assign(gurl.host()); | 46 host->assign(gurl.host()); |
45 if (gurl.has_port()) { | 47 if (gurl.has_port()) { |
46 host->append(":"); | 48 host->append(":"); |
47 host->append(gurl.port()); | 49 host->append(gurl.port()); |
48 } | 50 } |
49 } | 51 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 return CreateMockRead(resp, seq, ASYNC); | 178 return CreateMockRead(resp, seq, ASYNC); |
177 } | 179 } |
178 | 180 |
179 // Create a MockRead from the given SpdyFrame and sequence number. | 181 // Create a MockRead from the given SpdyFrame and sequence number. |
180 MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode) { | 182 MockRead CreateMockRead(const SpdyFrame& resp, int seq, IoMode mode) { |
181 return MockRead(mode, resp.data(), resp.size(), seq); | 183 return MockRead(mode, resp.data(), resp.size(), seq); |
182 } | 184 } |
183 | 185 |
184 // Combines the given SpdyFrames into the given char array and returns | 186 // Combines the given SpdyFrames into the given char array and returns |
185 // the total length. | 187 // the total length. |
186 int CombineFrames(const SpdyFrame** frames, int num_frames, | 188 int CombineFrames(const SpdyFrame** frames, |
187 char* buff, int buff_len) { | 189 int num_frames, |
| 190 char* buff, |
| 191 int buff_len) { |
188 int total_len = 0; | 192 int total_len = 0; |
189 for (int i = 0; i < num_frames; ++i) { | 193 for (int i = 0; i < num_frames; ++i) { |
190 total_len += frames[i]->size(); | 194 total_len += frames[i]->size(); |
191 } | 195 } |
192 DCHECK_LE(total_len, buff_len); | 196 DCHECK_LE(total_len, buff_len); |
193 char* ptr = buff; | 197 char* ptr = buff; |
194 for (int i = 0; i < num_frames; ++i) { | 198 for (int i = 0; i < num_frames; ++i) { |
195 int len = frames[i]->size(); | 199 int len = frames[i]->size(); |
196 memcpy(ptr, frames[i]->data(), len); | 200 memcpy(ptr, frames[i]->data(), len); |
197 ptr += len; | 201 ptr += len; |
198 } | 202 } |
199 return total_len; | 203 return total_len; |
200 } | 204 } |
201 | 205 |
202 namespace { | 206 namespace { |
203 | 207 |
204 class PriorityGetter : public BufferedSpdyFramerVisitorInterface { | 208 class PriorityGetter : public BufferedSpdyFramerVisitorInterface { |
205 public: | 209 public: |
206 PriorityGetter() : priority_(0) {} | 210 PriorityGetter() : priority_(0) {} |
207 virtual ~PriorityGetter() {} | 211 virtual ~PriorityGetter() {} |
208 | 212 |
209 SpdyPriority priority() const { | 213 SpdyPriority priority() const { return priority_; } |
210 return priority_; | |
211 } | |
212 | 214 |
213 virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE {} | 215 virtual void OnError(SpdyFramer::SpdyError error_code) OVERRIDE {} |
214 virtual void OnStreamError(SpdyStreamId stream_id, | 216 virtual void OnStreamError(SpdyStreamId stream_id, |
215 const std::string& description) OVERRIDE {} | 217 const std::string& description) OVERRIDE {} |
216 virtual void OnSynStream(SpdyStreamId stream_id, | 218 virtual void OnSynStream(SpdyStreamId stream_id, |
217 SpdyStreamId associated_stream_id, | 219 SpdyStreamId associated_stream_id, |
218 SpdyPriority priority, | 220 SpdyPriority priority, |
219 bool fin, | 221 bool fin, |
220 bool unidirectional, | 222 bool unidirectional, |
221 const SpdyHeaderBlock& headers) OVERRIDE { | 223 const SpdyHeaderBlock& headers) OVERRIDE { |
222 priority_ = priority; | 224 priority_ = priority; |
223 } | 225 } |
224 virtual void OnSynReply(SpdyStreamId stream_id, | 226 virtual void OnSynReply(SpdyStreamId stream_id, |
225 bool fin, | 227 bool fin, |
226 const SpdyHeaderBlock& headers) OVERRIDE {} | 228 const SpdyHeaderBlock& headers) OVERRIDE {} |
227 virtual void OnHeaders(SpdyStreamId stream_id, | 229 virtual void OnHeaders(SpdyStreamId stream_id, |
228 bool fin, | 230 bool fin, |
229 const SpdyHeaderBlock& headers) OVERRIDE {} | 231 const SpdyHeaderBlock& headers) OVERRIDE {} |
230 virtual void OnDataFrameHeader(SpdyStreamId stream_id, | 232 virtual void OnDataFrameHeader(SpdyStreamId stream_id, |
231 size_t length, | 233 size_t length, |
232 bool fin) OVERRIDE {} | 234 bool fin) OVERRIDE {} |
233 virtual void OnStreamFrameData(SpdyStreamId stream_id, | 235 virtual void OnStreamFrameData(SpdyStreamId stream_id, |
234 const char* data, | 236 const char* data, |
235 size_t len, | 237 size_t len, |
236 bool fin) OVERRIDE {} | 238 bool fin) OVERRIDE {} |
237 virtual void OnSettings(bool clear_persisted) OVERRIDE {} | 239 virtual void OnSettings(bool clear_persisted) OVERRIDE {} |
238 virtual void OnSetting( | 240 virtual void OnSetting(SpdySettingsIds id, |
239 SpdySettingsIds id, uint8 flags, uint32 value) OVERRIDE {} | 241 uint8 flags, |
| 242 uint32 value) OVERRIDE {} |
240 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE {} | 243 virtual void OnPing(SpdyPingId unique_id, bool is_ack) OVERRIDE {} |
241 virtual void OnRstStream(SpdyStreamId stream_id, | 244 virtual void OnRstStream(SpdyStreamId stream_id, |
242 SpdyRstStreamStatus status) OVERRIDE {} | 245 SpdyRstStreamStatus status) OVERRIDE {} |
243 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, | 246 virtual void OnGoAway(SpdyStreamId last_accepted_stream_id, |
244 SpdyGoAwayStatus status) OVERRIDE {} | 247 SpdyGoAwayStatus status) OVERRIDE {} |
245 virtual void OnWindowUpdate(SpdyStreamId stream_id, | 248 virtual void OnWindowUpdate(SpdyStreamId stream_id, |
246 uint32 delta_window_size) OVERRIDE {} | 249 uint32 delta_window_size) OVERRIDE {} |
247 virtual void OnPushPromise(SpdyStreamId stream_id, | 250 virtual void OnPushPromise(SpdyStreamId stream_id, |
248 SpdyStreamId promised_stream_id) OVERRIDE {} | 251 SpdyStreamId promised_stream_id) OVERRIDE {} |
249 | 252 |
(...skipping 17 matching lines...) Expand all Loading... |
267 return true; | 270 return true; |
268 } | 271 } |
269 | 272 |
270 base::WeakPtr<SpdyStream> CreateStreamSynchronously( | 273 base::WeakPtr<SpdyStream> CreateStreamSynchronously( |
271 SpdyStreamType type, | 274 SpdyStreamType type, |
272 const base::WeakPtr<SpdySession>& session, | 275 const base::WeakPtr<SpdySession>& session, |
273 const GURL& url, | 276 const GURL& url, |
274 RequestPriority priority, | 277 RequestPriority priority, |
275 const BoundNetLog& net_log) { | 278 const BoundNetLog& net_log) { |
276 SpdyStreamRequest stream_request; | 279 SpdyStreamRequest stream_request; |
277 int rv = stream_request.StartRequest(type, session, url, priority, net_log, | 280 int rv = stream_request.StartRequest( |
278 CompletionCallback()); | 281 type, session, url, priority, net_log, CompletionCallback()); |
279 return | 282 return (rv == OK) ? stream_request.ReleaseStream() |
280 (rv == OK) ? stream_request.ReleaseStream() : base::WeakPtr<SpdyStream>(); | 283 : base::WeakPtr<SpdyStream>(); |
281 } | 284 } |
282 | 285 |
283 StreamReleaserCallback::StreamReleaserCallback() {} | 286 StreamReleaserCallback::StreamReleaserCallback() { |
| 287 } |
284 | 288 |
285 StreamReleaserCallback::~StreamReleaserCallback() {} | 289 StreamReleaserCallback::~StreamReleaserCallback() { |
| 290 } |
286 | 291 |
287 CompletionCallback StreamReleaserCallback::MakeCallback( | 292 CompletionCallback StreamReleaserCallback::MakeCallback( |
288 SpdyStreamRequest* request) { | 293 SpdyStreamRequest* request) { |
289 return base::Bind(&StreamReleaserCallback::OnComplete, | 294 return base::Bind( |
290 base::Unretained(this), | 295 &StreamReleaserCallback::OnComplete, base::Unretained(this), request); |
291 request); | |
292 } | 296 } |
293 | 297 |
294 void StreamReleaserCallback::OnComplete( | 298 void StreamReleaserCallback::OnComplete(SpdyStreamRequest* request, |
295 SpdyStreamRequest* request, int result) { | 299 int result) { |
296 if (result == OK) | 300 if (result == OK) |
297 request->ReleaseStream()->Cancel(); | 301 request->ReleaseStream()->Cancel(); |
298 SetResult(result); | 302 SetResult(result); |
299 } | 303 } |
300 | 304 |
301 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key) | 305 MockECSignatureCreator::MockECSignatureCreator(crypto::ECPrivateKey* key) |
302 : key_(key) { | 306 : key_(key) { |
303 } | 307 } |
304 | 308 |
305 bool MockECSignatureCreator::Sign(const uint8* data, | 309 bool MockECSignatureCreator::Sign(const uint8* data, |
306 int data_len, | 310 int data_len, |
307 std::vector<uint8>* signature) { | 311 std::vector<uint8>* signature) { |
308 std::vector<uint8> private_key_value; | 312 std::vector<uint8> private_key_value; |
309 key_->ExportValue(&private_key_value); | 313 key_->ExportValue(&private_key_value); |
310 std::string head = "fakesignature"; | 314 std::string head = "fakesignature"; |
311 std::string tail = "/fakesignature"; | 315 std::string tail = "/fakesignature"; |
312 | 316 |
313 signature->clear(); | 317 signature->clear(); |
314 signature->insert(signature->end(), head.begin(), head.end()); | 318 signature->insert(signature->end(), head.begin(), head.end()); |
315 signature->insert(signature->end(), private_key_value.begin(), | 319 signature->insert( |
316 private_key_value.end()); | 320 signature->end(), private_key_value.begin(), private_key_value.end()); |
317 signature->insert(signature->end(), '-'); | 321 signature->insert(signature->end(), '-'); |
318 signature->insert(signature->end(), data, data + data_len); | 322 signature->insert(signature->end(), data, data + data_len); |
319 signature->insert(signature->end(), tail.begin(), tail.end()); | 323 signature->insert(signature->end(), tail.begin(), tail.end()); |
320 return true; | 324 return true; |
321 } | 325 } |
322 | 326 |
323 bool MockECSignatureCreator::DecodeSignature( | 327 bool MockECSignatureCreator::DecodeSignature( |
324 const std::vector<uint8>& signature, | 328 const std::vector<uint8>& signature, |
325 std::vector<uint8>* out_raw_sig) { | 329 std::vector<uint8>* out_raw_sig) { |
326 *out_raw_sig = signature; | 330 *out_raw_sig = signature; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 | 366 |
363 // Note: The CancelledTransaction test does cleanup by running all | 367 // Note: The CancelledTransaction test does cleanup by running all |
364 // tasks in the message loop (RunAllPending). Unfortunately, that | 368 // tasks in the message loop (RunAllPending). Unfortunately, that |
365 // doesn't clean up tasks on the host resolver thread; and | 369 // doesn't clean up tasks on the host resolver thread; and |
366 // TCPConnectJob is currently not cancellable. Using synchronous | 370 // TCPConnectJob is currently not cancellable. Using synchronous |
367 // lookups allows the test to shutdown cleanly. Until we have | 371 // lookups allows the test to shutdown cleanly. Until we have |
368 // cancellable TCPConnectJobs, use synchronous lookups. | 372 // cancellable TCPConnectJobs, use synchronous lookups. |
369 host_resolver->set_synchronous_mode(true); | 373 host_resolver->set_synchronous_mode(true); |
370 } | 374 } |
371 | 375 |
372 SpdySessionDependencies::SpdySessionDependencies( | 376 SpdySessionDependencies::SpdySessionDependencies(NextProto protocol, |
373 NextProto protocol, ProxyService* proxy_service) | 377 ProxyService* proxy_service) |
374 : host_resolver(new MockHostResolver), | 378 : host_resolver(new MockHostResolver), |
375 cert_verifier(new MockCertVerifier), | 379 cert_verifier(new MockCertVerifier), |
376 transport_security_state(new TransportSecurityState), | 380 transport_security_state(new TransportSecurityState), |
377 proxy_service(proxy_service), | 381 proxy_service(proxy_service), |
378 ssl_config_service(new SSLConfigServiceDefaults), | 382 ssl_config_service(new SSLConfigServiceDefaults), |
379 socket_factory(new MockClientSocketFactory), | 383 socket_factory(new MockClientSocketFactory), |
380 deterministic_socket_factory(new DeterministicMockClientSocketFactory), | 384 deterministic_socket_factory(new DeterministicMockClientSocketFactory), |
381 http_auth_handler_factory( | 385 http_auth_handler_factory( |
382 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 386 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
383 enable_ip_pooling(true), | 387 enable_ip_pooling(true), |
384 enable_compression(false), | 388 enable_compression(false), |
385 enable_ping(false), | 389 enable_ping(false), |
386 enable_user_alternate_protocol_ports(false), | 390 enable_user_alternate_protocol_ports(false), |
387 protocol(protocol), | 391 protocol(protocol), |
388 stream_initial_recv_window_size(kSpdyStreamInitialWindowSize), | 392 stream_initial_recv_window_size(kSpdyStreamInitialWindowSize), |
389 time_func(&base::TimeTicks::Now), | 393 time_func(&base::TimeTicks::Now), |
390 net_log(NULL) { | 394 net_log(NULL) { |
391 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 395 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
392 } | 396 } |
393 | 397 |
394 SpdySessionDependencies::~SpdySessionDependencies() {} | 398 SpdySessionDependencies::~SpdySessionDependencies() { |
| 399 } |
395 | 400 |
396 // static | 401 // static |
397 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( | 402 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( |
398 SpdySessionDependencies* session_deps) { | 403 SpdySessionDependencies* session_deps) { |
399 net::HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 404 net::HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
400 params.client_socket_factory = session_deps->socket_factory.get(); | 405 params.client_socket_factory = session_deps->socket_factory.get(); |
401 HttpNetworkSession* http_session = new HttpNetworkSession(params); | 406 HttpNetworkSession* http_session = new HttpNetworkSession(params); |
402 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); | 407 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); |
403 pool_peer.SetEnableSendingInitialData(false); | 408 pool_peer.SetEnableSendingInitialData(false); |
404 return http_session; | 409 return http_session; |
405 } | 410 } |
406 | 411 |
407 // static | 412 // static |
408 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSessionDeterministic( | 413 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSessionDeterministic( |
409 SpdySessionDependencies* session_deps) { | 414 SpdySessionDependencies* session_deps) { |
410 net::HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 415 net::HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
411 params.client_socket_factory = | 416 params.client_socket_factory = |
412 session_deps->deterministic_socket_factory.get(); | 417 session_deps->deterministic_socket_factory.get(); |
413 HttpNetworkSession* http_session = new HttpNetworkSession(params); | 418 HttpNetworkSession* http_session = new HttpNetworkSession(params); |
414 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); | 419 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); |
415 pool_peer.SetEnableSendingInitialData(false); | 420 pool_peer.SetEnableSendingInitialData(false); |
416 return http_session; | 421 return http_session; |
417 } | 422 } |
418 | 423 |
419 // static | 424 // static |
420 net::HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( | 425 net::HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( |
421 SpdySessionDependencies* session_deps) { | 426 SpdySessionDependencies* session_deps) { |
422 DCHECK(next_proto_is_spdy(session_deps->protocol)) << | 427 DCHECK(next_proto_is_spdy(session_deps->protocol)) |
423 "Invalid protocol: " << session_deps->protocol; | 428 << "Invalid protocol: " << session_deps->protocol; |
424 | 429 |
425 net::HttpNetworkSession::Params params; | 430 net::HttpNetworkSession::Params params; |
426 params.host_resolver = session_deps->host_resolver.get(); | 431 params.host_resolver = session_deps->host_resolver.get(); |
427 params.cert_verifier = session_deps->cert_verifier.get(); | 432 params.cert_verifier = session_deps->cert_verifier.get(); |
428 params.transport_security_state = | 433 params.transport_security_state = |
429 session_deps->transport_security_state.get(); | 434 session_deps->transport_security_state.get(); |
430 params.proxy_service = session_deps->proxy_service.get(); | 435 params.proxy_service = session_deps->proxy_service.get(); |
431 params.ssl_config_service = session_deps->ssl_config_service.get(); | 436 params.ssl_config_service = session_deps->ssl_config_service.get(); |
432 params.http_auth_handler_factory = | 437 params.http_auth_handler_factory = |
433 session_deps->http_auth_handler_factory.get(); | 438 session_deps->http_auth_handler_factory.get(); |
(...skipping 14 matching lines...) Expand all Loading... |
448 | 453 |
449 SpdyURLRequestContext::SpdyURLRequestContext(NextProto protocol) | 454 SpdyURLRequestContext::SpdyURLRequestContext(NextProto protocol) |
450 : storage_(this) { | 455 : storage_(this) { |
451 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 456 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
452 | 457 |
453 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); | 458 storage_.set_host_resolver(scoped_ptr<HostResolver>(new MockHostResolver)); |
454 storage_.set_cert_verifier(new MockCertVerifier); | 459 storage_.set_cert_verifier(new MockCertVerifier); |
455 storage_.set_transport_security_state(new TransportSecurityState); | 460 storage_.set_transport_security_state(new TransportSecurityState); |
456 storage_.set_proxy_service(ProxyService::CreateDirect()); | 461 storage_.set_proxy_service(ProxyService::CreateDirect()); |
457 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); | 462 storage_.set_ssl_config_service(new SSLConfigServiceDefaults); |
458 storage_.set_http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault( | 463 storage_.set_http_auth_handler_factory( |
459 host_resolver())); | 464 HttpAuthHandlerFactory::CreateDefault(host_resolver())); |
460 storage_.set_http_server_properties( | 465 storage_.set_http_server_properties( |
461 scoped_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); | 466 scoped_ptr<HttpServerProperties>(new HttpServerPropertiesImpl())); |
462 net::HttpNetworkSession::Params params; | 467 net::HttpNetworkSession::Params params; |
463 params.client_socket_factory = &socket_factory_; | 468 params.client_socket_factory = &socket_factory_; |
464 params.host_resolver = host_resolver(); | 469 params.host_resolver = host_resolver(); |
465 params.cert_verifier = cert_verifier(); | 470 params.cert_verifier = cert_verifier(); |
466 params.transport_security_state = transport_security_state(); | 471 params.transport_security_state = transport_security_state(); |
467 params.proxy_service = proxy_service(); | 472 params.proxy_service = proxy_service(); |
468 params.ssl_config_service = ssl_config_service(); | 473 params.ssl_config_service = ssl_config_service(); |
469 params.http_auth_handler_factory = http_auth_handler_factory(); | 474 params.http_auth_handler_factory = http_auth_handler_factory(); |
(...skipping 22 matching lines...) Expand all Loading... |
492 base::WeakPtr<SpdySession> CreateSpdySessionHelper( | 497 base::WeakPtr<SpdySession> CreateSpdySessionHelper( |
493 const scoped_refptr<HttpNetworkSession>& http_session, | 498 const scoped_refptr<HttpNetworkSession>& http_session, |
494 const SpdySessionKey& key, | 499 const SpdySessionKey& key, |
495 const BoundNetLog& net_log, | 500 const BoundNetLog& net_log, |
496 Error expected_status, | 501 Error expected_status, |
497 bool is_secure) { | 502 bool is_secure) { |
498 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); | 503 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); |
499 | 504 |
500 scoped_refptr<TransportSocketParams> transport_params( | 505 scoped_refptr<TransportSocketParams> transport_params( |
501 new TransportSocketParams( | 506 new TransportSocketParams( |
502 key.host_port_pair(), false, false, | 507 key.host_port_pair(), false, false, OnHostResolutionCallback())); |
503 OnHostResolutionCallback())); | |
504 | 508 |
505 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 509 scoped_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
506 TestCompletionCallback callback; | 510 TestCompletionCallback callback; |
507 | 511 |
508 int rv = ERR_UNEXPECTED; | 512 int rv = ERR_UNEXPECTED; |
509 if (is_secure) { | 513 if (is_secure) { |
510 SSLConfig ssl_config; | 514 SSLConfig ssl_config; |
511 scoped_refptr<SSLSocketParams> ssl_params( | 515 scoped_refptr<SSLSocketParams> ssl_params( |
512 new SSLSocketParams(transport_params, | 516 new SSLSocketParams(transport_params, |
513 NULL, | 517 NULL, |
514 NULL, | 518 NULL, |
515 key.host_port_pair(), | 519 key.host_port_pair(), |
516 ssl_config, | 520 ssl_config, |
517 key.privacy_mode(), | 521 key.privacy_mode(), |
518 0, | 522 0, |
519 false, | 523 false, |
520 false)); | 524 false)); |
521 rv = connection->Init(key.host_port_pair().ToString(), | 525 rv = connection->Init( |
522 ssl_params, | 526 key.host_port_pair().ToString(), |
523 MEDIUM, | 527 ssl_params, |
524 callback.callback(), | 528 MEDIUM, |
525 http_session->GetSSLSocketPool( | 529 callback.callback(), |
526 HttpNetworkSession::NORMAL_SOCKET_POOL), | 530 http_session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL), |
527 net_log); | 531 net_log); |
528 } else { | 532 } else { |
529 rv = connection->Init(key.host_port_pair().ToString(), | 533 rv = connection->Init(key.host_port_pair().ToString(), |
530 transport_params, | 534 transport_params, |
531 MEDIUM, | 535 MEDIUM, |
532 callback.callback(), | 536 callback.callback(), |
533 http_session->GetTransportSocketPool( | 537 http_session->GetTransportSocketPool( |
534 HttpNetworkSession::NORMAL_SOCKET_POOL), | 538 HttpNetworkSession::NORMAL_SOCKET_POOL), |
535 net_log); | 539 net_log); |
536 } | 540 } |
537 | 541 |
(...skipping 10 matching lines...) Expand all Loading... |
548 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); | 552 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); |
549 return spdy_session; | 553 return spdy_session; |
550 } | 554 } |
551 | 555 |
552 } // namespace | 556 } // namespace |
553 | 557 |
554 base::WeakPtr<SpdySession> CreateInsecureSpdySession( | 558 base::WeakPtr<SpdySession> CreateInsecureSpdySession( |
555 const scoped_refptr<HttpNetworkSession>& http_session, | 559 const scoped_refptr<HttpNetworkSession>& http_session, |
556 const SpdySessionKey& key, | 560 const SpdySessionKey& key, |
557 const BoundNetLog& net_log) { | 561 const BoundNetLog& net_log) { |
558 return CreateSpdySessionHelper(http_session, key, net_log, | 562 return CreateSpdySessionHelper( |
559 OK, false /* is_secure */); | 563 http_session, key, net_log, OK, false /* is_secure */); |
560 } | 564 } |
561 | 565 |
562 base::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( | 566 base::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( |
563 const scoped_refptr<HttpNetworkSession>& http_session, | 567 const scoped_refptr<HttpNetworkSession>& http_session, |
564 const SpdySessionKey& key, | 568 const SpdySessionKey& key, |
565 Error expected_error, | 569 Error expected_error, |
566 const BoundNetLog& net_log) { | 570 const BoundNetLog& net_log) { |
567 DCHECK_LT(expected_error, ERR_IO_PENDING); | 571 DCHECK_LT(expected_error, ERR_IO_PENDING); |
568 return CreateSpdySessionHelper(http_session, key, net_log, | 572 return CreateSpdySessionHelper( |
569 expected_error, false /* is_secure */); | 573 http_session, key, net_log, expected_error, false /* is_secure */); |
570 } | 574 } |
571 | 575 |
572 base::WeakPtr<SpdySession> CreateSecureSpdySession( | 576 base::WeakPtr<SpdySession> CreateSecureSpdySession( |
573 const scoped_refptr<HttpNetworkSession>& http_session, | 577 const scoped_refptr<HttpNetworkSession>& http_session, |
574 const SpdySessionKey& key, | 578 const SpdySessionKey& key, |
575 const BoundNetLog& net_log) { | 579 const BoundNetLog& net_log) { |
576 return CreateSpdySessionHelper(http_session, key, net_log, | 580 return CreateSpdySessionHelper( |
577 OK, true /* is_secure */); | 581 http_session, key, net_log, OK, true /* is_secure */); |
578 } | 582 } |
579 | 583 |
580 namespace { | 584 namespace { |
581 | 585 |
582 // A ClientSocket used for CreateFakeSpdySession() below. | 586 // A ClientSocket used for CreateFakeSpdySession() below. |
583 class FakeSpdySessionClientSocket : public MockClientSocket { | 587 class FakeSpdySessionClientSocket : public MockClientSocket { |
584 public: | 588 public: |
585 FakeSpdySessionClientSocket(int read_result) | 589 FakeSpdySessionClientSocket(int read_result) |
586 : MockClientSocket(BoundNetLog()), | 590 : MockClientSocket(BoundNetLog()), read_result_(read_result) {} |
587 read_result_(read_result) {} | |
588 | 591 |
589 virtual ~FakeSpdySessionClientSocket() {} | 592 virtual ~FakeSpdySessionClientSocket() {} |
590 | 593 |
591 virtual int Read(IOBuffer* buf, int buf_len, | 594 virtual int Read(IOBuffer* buf, |
| 595 int buf_len, |
592 const CompletionCallback& callback) OVERRIDE { | 596 const CompletionCallback& callback) OVERRIDE { |
593 return read_result_; | 597 return read_result_; |
594 } | 598 } |
595 | 599 |
596 virtual int Write(IOBuffer* buf, int buf_len, | 600 virtual int Write(IOBuffer* buf, |
| 601 int buf_len, |
597 const CompletionCallback& callback) OVERRIDE { | 602 const CompletionCallback& callback) OVERRIDE { |
598 return ERR_IO_PENDING; | 603 return ERR_IO_PENDING; |
599 } | 604 } |
600 | 605 |
601 // Return kProtoUnknown to use the pool's default protocol. | 606 // Return kProtoUnknown to use the pool's default protocol. |
602 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { | 607 virtual NextProto GetNegotiatedProtocol() const OVERRIDE { |
603 return kProtoUnknown; | 608 return kProtoUnknown; |
604 } | 609 } |
605 | 610 |
606 // The functions below are not expected to be called. | 611 // The functions below are not expected to be called. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 return ConstructHeaderBlock("PUT", url, &content_length); | 737 return ConstructHeaderBlock("PUT", url, &content_length); |
733 } | 738 } |
734 | 739 |
735 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame( | 740 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame( |
736 const SpdyHeaderInfo& header_info, | 741 const SpdyHeaderInfo& header_info, |
737 scoped_ptr<SpdyHeaderBlock> headers) const { | 742 scoped_ptr<SpdyHeaderBlock> headers) const { |
738 BufferedSpdyFramer framer(spdy_version_, header_info.compressed); | 743 BufferedSpdyFramer framer(spdy_version_, header_info.compressed); |
739 SpdyFrame* frame = NULL; | 744 SpdyFrame* frame = NULL; |
740 switch (header_info.kind) { | 745 switch (header_info.kind) { |
741 case DATA: | 746 case DATA: |
742 frame = framer.CreateDataFrame(header_info.id, header_info.data, | 747 frame = framer.CreateDataFrame(header_info.id, |
| 748 header_info.data, |
743 header_info.data_length, | 749 header_info.data_length, |
744 header_info.data_flags); | 750 header_info.data_flags); |
745 break; | 751 break; |
746 case SYN_STREAM: | 752 case SYN_STREAM: { |
747 { | 753 frame = framer.CreateSynStream(header_info.id, |
748 frame = framer.CreateSynStream(header_info.id, header_info.assoc_id, | 754 header_info.assoc_id, |
749 header_info.priority, | 755 header_info.priority, |
750 header_info.control_flags, | 756 header_info.control_flags, |
751 headers.get()); | 757 headers.get()); |
752 } | 758 } break; |
753 break; | |
754 case SYN_REPLY: | 759 case SYN_REPLY: |
755 frame = framer.CreateSynReply(header_info.id, header_info.control_flags, | 760 frame = framer.CreateSynReply( |
756 headers.get()); | 761 header_info.id, header_info.control_flags, headers.get()); |
757 break; | 762 break; |
758 case RST_STREAM: | 763 case RST_STREAM: |
759 frame = framer.CreateRstStream(header_info.id, header_info.status); | 764 frame = framer.CreateRstStream(header_info.id, header_info.status); |
760 break; | 765 break; |
761 case HEADERS: | 766 case HEADERS: |
762 frame = framer.CreateHeaders(header_info.id, header_info.control_flags, | 767 frame = framer.CreateHeaders( |
763 headers.get()); | 768 header_info.id, header_info.control_flags, headers.get()); |
764 break; | 769 break; |
765 default: | 770 default: |
766 ADD_FAILURE(); | 771 ADD_FAILURE(); |
767 break; | 772 break; |
768 } | 773 } |
769 return frame; | 774 return frame; |
770 } | 775 } |
771 | 776 |
772 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, | 777 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
773 const char* const extra_headers[], | 778 const char* const extra_headers[], |
(...skipping 11 matching lines...) Expand all Loading... |
785 scoped_ptr<SpdyHeaderBlock> headers, | 790 scoped_ptr<SpdyHeaderBlock> headers, |
786 bool compressed, | 791 bool compressed, |
787 SpdyStreamId stream_id, | 792 SpdyStreamId stream_id, |
788 RequestPriority request_priority, | 793 RequestPriority request_priority, |
789 SpdyFrameType type, | 794 SpdyFrameType type, |
790 SpdyControlFlags flags, | 795 SpdyControlFlags flags, |
791 SpdyStreamId associated_stream_id) const { | 796 SpdyStreamId associated_stream_id) const { |
792 EXPECT_GE(type, FIRST_CONTROL_TYPE); | 797 EXPECT_GE(type, FIRST_CONTROL_TYPE); |
793 EXPECT_LE(type, LAST_CONTROL_TYPE); | 798 EXPECT_LE(type, LAST_CONTROL_TYPE); |
794 const SpdyHeaderInfo header_info = { | 799 const SpdyHeaderInfo header_info = { |
795 type, | 800 type, |
796 stream_id, | 801 stream_id, |
797 associated_stream_id, | 802 associated_stream_id, |
798 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_), | 803 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_), |
799 0, // credential slot | 804 0, // credential slot |
800 flags, | 805 flags, |
801 compressed, | 806 compressed, |
802 RST_STREAM_INVALID, // status | 807 RST_STREAM_INVALID, // status |
803 NULL, // data | 808 NULL, // data |
804 0, // length | 809 0, // length |
805 DATA_FLAG_NONE | 810 DATA_FLAG_NONE}; |
806 }; | |
807 return ConstructSpdyFrame(header_info, headers.Pass()); | 811 return ConstructSpdyFrame(header_info, headers.Pass()); |
808 } | 812 } |
809 | 813 |
810 SpdyFrame* SpdyTestUtil::ConstructSpdyControlFrame( | 814 SpdyFrame* SpdyTestUtil::ConstructSpdyControlFrame( |
811 const char* const extra_headers[], | 815 const char* const extra_headers[], |
812 int extra_header_count, | 816 int extra_header_count, |
813 bool compressed, | 817 bool compressed, |
814 SpdyStreamId stream_id, | 818 SpdyStreamId stream_id, |
815 RequestPriority request_priority, | 819 RequestPriority request_priority, |
816 SpdyFrameType type, | 820 SpdyFrameType type, |
817 SpdyControlFlags flags, | 821 SpdyControlFlags flags, |
818 const char* const* tail_headers, | 822 const char* const* tail_headers, |
819 int tail_header_size, | 823 int tail_header_size, |
820 SpdyStreamId associated_stream_id) const { | 824 SpdyStreamId associated_stream_id) const { |
821 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 825 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
822 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 826 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); |
823 if (tail_headers && tail_header_size) | 827 if (tail_headers && tail_header_size) |
824 AppendToHeaderBlock(tail_headers, tail_header_size / 2, headers.get()); | 828 AppendToHeaderBlock(tail_headers, tail_header_size / 2, headers.get()); |
825 return ConstructSpdyControlFrame( | 829 return ConstructSpdyControlFrame(headers.Pass(), |
826 headers.Pass(), compressed, stream_id, | 830 compressed, |
827 request_priority, type, flags, associated_stream_id); | 831 stream_id, |
| 832 request_priority, |
| 833 type, |
| 834 flags, |
| 835 associated_stream_id); |
828 } | 836 } |
829 | 837 |
830 std::string SpdyTestUtil::ConstructSpdyReplyString( | 838 std::string SpdyTestUtil::ConstructSpdyReplyString( |
831 const SpdyHeaderBlock& headers) const { | 839 const SpdyHeaderBlock& headers) const { |
832 std::string reply_string; | 840 std::string reply_string; |
833 for (SpdyHeaderBlock::const_iterator it = headers.begin(); | 841 for (SpdyHeaderBlock::const_iterator it = headers.begin(); |
834 it != headers.end(); ++it) { | 842 it != headers.end(); |
| 843 ++it) { |
835 std::string key = it->first; | 844 std::string key = it->first; |
836 // Remove leading colon from "special" headers (for SPDY3 and | 845 // Remove leading colon from "special" headers (for SPDY3 and |
837 // above). | 846 // above). |
838 if (spdy_version() >= SPDY3 && key[0] == ':') | 847 if (spdy_version() >= SPDY3 && key[0] == ':') |
839 key = key.substr(1); | 848 key = key.substr(1); |
840 std::vector<std::string> values; | 849 std::vector<std::string> values; |
841 base::SplitString(it->second, '\0', &values); | 850 base::SplitString(it->second, '\0', &values); |
842 for (std::vector<std::string>::const_iterator it2 = values.begin(); | 851 for (std::vector<std::string>::const_iterator it2 = values.begin(); |
843 it2 != values.end(); ++it2) { | 852 it2 != values.end(); |
| 853 ++it2) { |
844 reply_string += key + ": " + *it2 + "\n"; | 854 reply_string += key + ": " + *it2 + "\n"; |
845 } | 855 } |
846 } | 856 } |
847 return reply_string; | 857 return reply_string; |
848 } | 858 } |
849 | 859 |
850 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer | 860 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer |
851 // SpdySettingsIR). | 861 // SpdySettingsIR). |
852 SpdyFrame* SpdyTestUtil::ConstructSpdySettings( | 862 SpdyFrame* SpdyTestUtil::ConstructSpdySettings( |
853 const SettingsMap& settings) const { | 863 const SettingsMap& settings) const { |
854 SpdySettingsIR settings_ir; | 864 SpdySettingsIR settings_ir; |
855 for (SettingsMap::const_iterator it = settings.begin(); | 865 for (SettingsMap::const_iterator it = settings.begin(); it != settings.end(); |
856 it != settings.end(); | |
857 ++it) { | 866 ++it) { |
858 settings_ir.AddSetting( | 867 settings_ir.AddSetting( |
859 it->first, | 868 it->first, |
860 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0, | 869 (it->second.first & SETTINGS_FLAG_PLEASE_PERSIST) != 0, |
861 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0, | 870 (it->second.first & SETTINGS_FLAG_PERSISTED) != 0, |
862 it->second.second); | 871 it->second.second); |
863 } | 872 } |
864 return CreateFramer(false)->SerializeFrame(settings_ir); | 873 return CreateFramer(false)->SerializeFrame(settings_ir); |
865 } | 874 } |
866 | 875 |
867 SpdyFrame* SpdyTestUtil::ConstructSpdyPing(uint32 ping_id, bool is_ack) const { | 876 SpdyFrame* SpdyTestUtil::ConstructSpdyPing(uint32 ping_id, bool is_ack) const { |
868 SpdyPingIR ping_ir(ping_id); | 877 SpdyPingIR ping_ir(ping_id); |
869 ping_ir.set_is_ack(is_ack); | 878 ping_ir.set_is_ack(is_ack); |
870 return CreateFramer(false)->SerializeFrame(ping_ir); | 879 return CreateFramer(false)->SerializeFrame(ping_ir); |
871 } | 880 } |
872 | 881 |
873 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway() const { | 882 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway() const { |
874 return ConstructSpdyGoAway(0); | 883 return ConstructSpdyGoAway(0); |
875 } | 884 } |
876 | 885 |
877 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway( | 886 SpdyFrame* SpdyTestUtil::ConstructSpdyGoAway( |
878 SpdyStreamId last_good_stream_id) const { | 887 SpdyStreamId last_good_stream_id) const { |
879 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); | 888 SpdyGoAwayIR go_ir(last_good_stream_id, GOAWAY_OK, "go away"); |
880 return CreateFramer(false)->SerializeFrame(go_ir); | 889 return CreateFramer(false)->SerializeFrame(go_ir); |
881 } | 890 } |
882 | 891 |
883 SpdyFrame* SpdyTestUtil::ConstructSpdyWindowUpdate( | 892 SpdyFrame* SpdyTestUtil::ConstructSpdyWindowUpdate( |
884 const SpdyStreamId stream_id, uint32 delta_window_size) const { | 893 const SpdyStreamId stream_id, |
| 894 uint32 delta_window_size) const { |
885 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); | 895 SpdyWindowUpdateIR update_ir(stream_id, delta_window_size); |
886 return CreateFramer(false)->SerializeFrame(update_ir); | 896 return CreateFramer(false)->SerializeFrame(update_ir); |
887 } | 897 } |
888 | 898 |
889 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer | 899 // TODO(jgraettinger): Eliminate uses of this method in tests (prefer |
890 // SpdyRstStreamIR). | 900 // SpdyRstStreamIR). |
891 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream( | 901 SpdyFrame* SpdyTestUtil::ConstructSpdyRstStream( |
892 SpdyStreamId stream_id, | 902 SpdyStreamId stream_id, |
893 SpdyRstStreamStatus status) const { | 903 SpdyRstStreamStatus status) const { |
894 SpdyRstStreamIR rst_ir(stream_id, status, "RST"); | 904 SpdyRstStreamIR rst_ir(stream_id, status, "RST"); |
895 return CreateFramer(false)->SerializeRstStream(rst_ir); | 905 return CreateFramer(false)->SerializeRstStream(rst_ir); |
896 } | 906 } |
897 | 907 |
898 SpdyFrame* SpdyTestUtil::ConstructSpdyGet( | 908 SpdyFrame* SpdyTestUtil::ConstructSpdyGet( |
899 const char* const url, | 909 const char* const url, |
900 bool compressed, | 910 bool compressed, |
901 SpdyStreamId stream_id, | 911 SpdyStreamId stream_id, |
902 RequestPriority request_priority) const { | 912 RequestPriority request_priority) const { |
903 const SpdyHeaderInfo header_info = { | 913 const SpdyHeaderInfo header_info = { |
904 SYN_STREAM, | 914 SYN_STREAM, |
905 stream_id, | 915 stream_id, |
906 0, // associated stream ID | 916 0, // associated stream ID |
907 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_), | 917 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_), |
908 0, // credential slot | 918 0, // credential slot |
909 CONTROL_FLAG_FIN, | 919 CONTROL_FLAG_FIN, |
910 compressed, | 920 compressed, |
911 RST_STREAM_INVALID, // status | 921 RST_STREAM_INVALID, // status |
912 NULL, // data | 922 NULL, // data |
913 0, // length | 923 0, // length |
914 DATA_FLAG_NONE | 924 DATA_FLAG_NONE}; |
915 }; | |
916 return ConstructSpdyFrame(header_info, ConstructGetHeaderBlock(url)); | 925 return ConstructSpdyFrame(header_info, ConstructGetHeaderBlock(url)); |
917 } | 926 } |
918 | 927 |
919 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], | 928 SpdyFrame* SpdyTestUtil::ConstructSpdyGet(const char* const extra_headers[], |
920 int extra_header_count, | 929 int extra_header_count, |
921 bool compressed, | 930 bool compressed, |
922 int stream_id, | 931 int stream_id, |
923 RequestPriority request_priority, | 932 RequestPriority request_priority, |
924 bool direct) const { | 933 bool direct) const { |
925 SpdySynStreamIR syn_stream(stream_id); | 934 SpdySynStreamIR syn_stream(stream_id); |
926 syn_stream.set_priority( | 935 syn_stream.set_priority( |
927 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_)); | 936 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_)); |
928 syn_stream.set_fin(true); | 937 syn_stream.set_fin(true); |
929 syn_stream.SetHeader(GetMethodKey(), "GET"); | 938 syn_stream.SetHeader(GetMethodKey(), "GET"); |
930 syn_stream.SetHeader(GetHostKey(), "www.google.com"); | 939 syn_stream.SetHeader(GetHostKey(), "www.google.com"); |
931 syn_stream.SetHeader(GetSchemeKey(), "http"); | 940 syn_stream.SetHeader(GetSchemeKey(), "http"); |
932 syn_stream.SetHeader(GetPathKey(), (is_spdy2() && !direct) ? | 941 syn_stream.SetHeader( |
933 "http://www.google.com/" : "/"); | 942 GetPathKey(), (is_spdy2() && !direct) ? "http://www.google.com/" : "/"); |
934 MaybeAddVersionHeader(&syn_stream); | 943 MaybeAddVersionHeader(&syn_stream); |
935 AppendToHeaderBlock(extra_headers, extra_header_count, | 944 AppendToHeaderBlock( |
936 syn_stream.mutable_name_value_block()); | 945 extra_headers, extra_header_count, syn_stream.mutable_name_value_block()); |
937 return CreateFramer(compressed)->SerializeFrame(syn_stream); | 946 return CreateFramer(compressed)->SerializeFrame(syn_stream); |
938 } | 947 } |
939 | 948 |
940 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect( | 949 SpdyFrame* SpdyTestUtil::ConstructSpdyConnect(const char* const extra_headers[], |
941 const char* const extra_headers[], | 950 int extra_header_count, |
942 int extra_header_count, | 951 int stream_id, |
943 int stream_id, | 952 RequestPriority priority) const { |
944 RequestPriority priority) const { | |
945 SpdySynStreamIR syn_stream(stream_id); | 953 SpdySynStreamIR syn_stream(stream_id); |
946 syn_stream.set_priority( | 954 syn_stream.set_priority( |
947 ConvertRequestPriorityToSpdyPriority(priority, spdy_version_)); | 955 ConvertRequestPriorityToSpdyPriority(priority, spdy_version_)); |
948 syn_stream.SetHeader(GetMethodKey(), "CONNECT"); | 956 syn_stream.SetHeader(GetMethodKey(), "CONNECT"); |
949 syn_stream.SetHeader(GetPathKey(), "www.google.com:443"); | 957 syn_stream.SetHeader(GetPathKey(), "www.google.com:443"); |
950 syn_stream.SetHeader(GetHostKey(), "www.google.com"); | 958 syn_stream.SetHeader(GetHostKey(), "www.google.com"); |
951 MaybeAddVersionHeader(&syn_stream); | 959 MaybeAddVersionHeader(&syn_stream); |
952 AppendToHeaderBlock(extra_headers, extra_header_count, | 960 AppendToHeaderBlock( |
953 syn_stream.mutable_name_value_block()); | 961 extra_headers, extra_header_count, syn_stream.mutable_name_value_block()); |
954 return CreateFramer(false)->SerializeFrame(syn_stream); | 962 return CreateFramer(false)->SerializeFrame(syn_stream); |
955 } | 963 } |
956 | 964 |
957 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], | 965 SpdyFrame* SpdyTestUtil::ConstructSpdyPush(const char* const extra_headers[], |
958 int extra_header_count, | 966 int extra_header_count, |
959 int stream_id, | 967 int stream_id, |
960 int associated_stream_id, | 968 int associated_stream_id, |
961 const char* url) { | 969 const char* url) { |
962 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 970 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
963 (*headers)["hello"] = "bye"; | 971 (*headers)["hello"] = "bye"; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 associated_stream_id); | 1009 associated_stream_id); |
1002 } | 1010 } |
1003 | 1011 |
1004 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( | 1012 SpdyFrame* SpdyTestUtil::ConstructSpdyPushHeaders( |
1005 int stream_id, | 1013 int stream_id, |
1006 const char* const extra_headers[], | 1014 const char* const extra_headers[], |
1007 int extra_header_count) { | 1015 int extra_header_count) { |
1008 SpdyHeadersIR headers(stream_id); | 1016 SpdyHeadersIR headers(stream_id); |
1009 headers.SetHeader(GetStatusKey(), "200 OK"); | 1017 headers.SetHeader(GetStatusKey(), "200 OK"); |
1010 MaybeAddVersionHeader(&headers); | 1018 MaybeAddVersionHeader(&headers); |
1011 AppendToHeaderBlock(extra_headers, extra_header_count, | 1019 AppendToHeaderBlock( |
1012 headers.mutable_name_value_block()); | 1020 extra_headers, extra_header_count, headers.mutable_name_value_block()); |
1013 return CreateFramer(false)->SerializeFrame(headers); | 1021 return CreateFramer(false)->SerializeFrame(headers); |
1014 } | 1022 } |
1015 | 1023 |
1016 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError( | 1024 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError( |
1017 const char* const status, | 1025 const char* const status, |
1018 const char* const* const extra_headers, | 1026 const char* const* const extra_headers, |
1019 int extra_header_count, | 1027 int extra_header_count, |
1020 int stream_id) { | 1028 int stream_id) { |
1021 SpdySynReplyIR syn_reply(stream_id); | 1029 SpdySynReplyIR syn_reply(stream_id); |
1022 syn_reply.SetHeader("hello", "bye"); | 1030 syn_reply.SetHeader("hello", "bye"); |
1023 syn_reply.SetHeader(GetStatusKey(), status); | 1031 syn_reply.SetHeader(GetStatusKey(), status); |
1024 MaybeAddVersionHeader(&syn_reply); | 1032 MaybeAddVersionHeader(&syn_reply); |
1025 AppendToHeaderBlock(extra_headers, extra_header_count, | 1033 AppendToHeaderBlock( |
1026 syn_reply.mutable_name_value_block()); | 1034 extra_headers, extra_header_count, syn_reply.mutable_name_value_block()); |
1027 return CreateFramer(false)->SerializeFrame(syn_reply); | 1035 return CreateFramer(false)->SerializeFrame(syn_reply); |
1028 } | 1036 } |
1029 | 1037 |
1030 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(int stream_id) { | 1038 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReplyRedirect(int stream_id) { |
1031 static const char* const kExtraHeaders[] = { | 1039 static const char* const kExtraHeaders[] = { |
1032 "location", "http://www.foo.com/index.php", | 1040 "location", "http://www.foo.com/index.php", |
1033 }; | 1041 }; |
1034 return ConstructSpdySynReplyError("301 Moved Permanently", kExtraHeaders, | 1042 return ConstructSpdySynReplyError("301 Moved Permanently", |
1035 arraysize(kExtraHeaders)/2, stream_id); | 1043 kExtraHeaders, |
| 1044 arraysize(kExtraHeaders) / 2, |
| 1045 stream_id); |
1036 } | 1046 } |
1037 | 1047 |
1038 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { | 1048 SpdyFrame* SpdyTestUtil::ConstructSpdySynReplyError(int stream_id) { |
1039 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); | 1049 return ConstructSpdySynReplyError("500 Internal Server Error", NULL, 0, 1); |
1040 } | 1050 } |
1041 | 1051 |
1042 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReply( | 1052 SpdyFrame* SpdyTestUtil::ConstructSpdyGetSynReply( |
1043 const char* const extra_headers[], | 1053 const char* const extra_headers[], |
1044 int extra_header_count, | 1054 int extra_header_count, |
1045 int stream_id) { | 1055 int stream_id) { |
1046 SpdySynReplyIR syn_reply(stream_id); | 1056 SpdySynReplyIR syn_reply(stream_id); |
1047 syn_reply.SetHeader("hello", "bye"); | 1057 syn_reply.SetHeader("hello", "bye"); |
1048 syn_reply.SetHeader(GetStatusKey(), "200"); | 1058 syn_reply.SetHeader(GetStatusKey(), "200"); |
1049 MaybeAddVersionHeader(&syn_reply); | 1059 MaybeAddVersionHeader(&syn_reply); |
1050 AppendToHeaderBlock(extra_headers, extra_header_count, | 1060 AppendToHeaderBlock( |
1051 syn_reply.mutable_name_value_block()); | 1061 extra_headers, extra_header_count, syn_reply.mutable_name_value_block()); |
1052 return CreateFramer(false)->SerializeFrame(syn_reply); | 1062 return CreateFramer(false)->SerializeFrame(syn_reply); |
1053 } | 1063 } |
1054 | 1064 |
1055 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, | 1065 SpdyFrame* SpdyTestUtil::ConstructSpdyPost(const char* url, |
1056 SpdyStreamId stream_id, | 1066 SpdyStreamId stream_id, |
1057 int64 content_length, | 1067 int64 content_length, |
1058 RequestPriority priority, | 1068 RequestPriority priority, |
1059 const char* const extra_headers[], | 1069 const char* const extra_headers[], |
1060 int extra_header_count) { | 1070 int extra_header_count) { |
1061 const SpdyHeaderInfo kSynStartHeader = { | 1071 const SpdyHeaderInfo kSynStartHeader = { |
1062 SYN_STREAM, | 1072 SYN_STREAM, |
1063 stream_id, | 1073 stream_id, |
1064 0, // Associated stream ID | 1074 0, // Associated stream ID |
1065 ConvertRequestPriorityToSpdyPriority(priority, spdy_version_), | 1075 ConvertRequestPriorityToSpdyPriority(priority, spdy_version_), |
1066 kSpdyCredentialSlotUnused, | 1076 kSpdyCredentialSlotUnused, |
1067 CONTROL_FLAG_NONE, | 1077 CONTROL_FLAG_NONE, |
1068 false, // Compressed | 1078 false, // Compressed |
1069 RST_STREAM_INVALID, | 1079 RST_STREAM_INVALID, |
1070 NULL, // Data | 1080 NULL, // Data |
1071 0, // Length | 1081 0, // Length |
1072 DATA_FLAG_NONE | 1082 DATA_FLAG_NONE}; |
1073 }; | 1083 return ConstructSpdyFrame(kSynStartHeader, |
1074 return ConstructSpdyFrame( | 1084 ConstructPostHeaderBlock(url, content_length)); |
1075 kSynStartHeader, ConstructPostHeaderBlock(url, content_length)); | |
1076 } | 1085 } |
1077 | 1086 |
1078 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( | 1087 SpdyFrame* SpdyTestUtil::ConstructChunkedSpdyPost( |
1079 const char* const extra_headers[], | 1088 const char* const extra_headers[], |
1080 int extra_header_count) { | 1089 int extra_header_count) { |
1081 SpdySynStreamIR syn_stream(1); | 1090 SpdySynStreamIR syn_stream(1); |
1082 syn_stream.SetHeader(GetMethodKey(), "POST"); | 1091 syn_stream.SetHeader(GetMethodKey(), "POST"); |
1083 syn_stream.SetHeader(GetPathKey(), "/"); | 1092 syn_stream.SetHeader(GetPathKey(), "/"); |
1084 syn_stream.SetHeader(GetHostKey(), "www.google.com"); | 1093 syn_stream.SetHeader(GetHostKey(), "www.google.com"); |
1085 syn_stream.SetHeader(GetSchemeKey(), "http"); | 1094 syn_stream.SetHeader(GetSchemeKey(), "http"); |
1086 MaybeAddVersionHeader(&syn_stream); | 1095 MaybeAddVersionHeader(&syn_stream); |
1087 SetPriority(LOWEST, &syn_stream); | 1096 SetPriority(LOWEST, &syn_stream); |
1088 AppendToHeaderBlock(extra_headers, extra_header_count, | 1097 AppendToHeaderBlock( |
1089 syn_stream.mutable_name_value_block()); | 1098 extra_headers, extra_header_count, syn_stream.mutable_name_value_block()); |
1090 return CreateFramer(false)->SerializeFrame(syn_stream); | 1099 return CreateFramer(false)->SerializeFrame(syn_stream); |
1091 } | 1100 } |
1092 | 1101 |
1093 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply( | 1102 SpdyFrame* SpdyTestUtil::ConstructSpdyPostSynReply( |
1094 const char* const extra_headers[], | 1103 const char* const extra_headers[], |
1095 int extra_header_count) { | 1104 int extra_header_count) { |
1096 SpdySynReplyIR syn_reply(1); | 1105 SpdySynReplyIR syn_reply(1); |
1097 syn_reply.SetHeader("hello", "bye"); | 1106 syn_reply.SetHeader("hello", "bye"); |
1098 syn_reply.SetHeader(GetStatusKey(), "200"); | 1107 syn_reply.SetHeader(GetStatusKey(), "200"); |
1099 syn_reply.SetHeader(GetPathKey(), "/index.php"); | 1108 syn_reply.SetHeader(GetPathKey(), "/index.php"); |
1100 MaybeAddVersionHeader(&syn_reply); | 1109 MaybeAddVersionHeader(&syn_reply); |
1101 AppendToHeaderBlock(extra_headers, extra_header_count, | 1110 AppendToHeaderBlock( |
1102 syn_reply.mutable_name_value_block()); | 1111 extra_headers, extra_header_count, syn_reply.mutable_name_value_block()); |
1103 return CreateFramer(false)->SerializeFrame(syn_reply); | 1112 return CreateFramer(false)->SerializeFrame(syn_reply); |
1104 } | 1113 } |
1105 | 1114 |
1106 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) { | 1115 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, bool fin) { |
1107 SpdyFramer framer(spdy_version_); | 1116 SpdyFramer framer(spdy_version_); |
1108 SpdyDataIR data_ir(stream_id, | 1117 SpdyDataIR data_ir(stream_id, |
1109 base::StringPiece(kUploadData, kUploadDataSize)); | 1118 base::StringPiece(kUploadData, kUploadDataSize)); |
1110 data_ir.set_fin(fin); | 1119 data_ir.set_fin(fin); |
1111 return framer.SerializeData(data_ir); | 1120 return framer.SerializeData(data_ir); |
1112 } | 1121 } |
1113 | 1122 |
1114 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, | 1123 SpdyFrame* SpdyTestUtil::ConstructSpdyBodyFrame(int stream_id, |
1115 const char* data, | 1124 const char* data, |
1116 uint32 len, | 1125 uint32 len, |
1117 bool fin) { | 1126 bool fin) { |
1118 SpdyFramer framer(spdy_version_); | 1127 SpdyFramer framer(spdy_version_); |
1119 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); | 1128 SpdyDataIR data_ir(stream_id, base::StringPiece(data, len)); |
1120 data_ir.set_fin(fin); | 1129 data_ir.set_fin(fin); |
1121 return framer.SerializeData(data_ir); | 1130 return framer.SerializeData(data_ir); |
1122 } | 1131 } |
1123 | 1132 |
1124 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( | 1133 SpdyFrame* SpdyTestUtil::ConstructWrappedSpdyFrame( |
1125 const scoped_ptr<SpdyFrame>& frame, | 1134 const scoped_ptr<SpdyFrame>& frame, |
1126 int stream_id) { | 1135 int stream_id) { |
1127 return ConstructSpdyBodyFrame(stream_id, frame->data(), | 1136 return ConstructSpdyBodyFrame(stream_id, frame->data(), frame->size(), false); |
1128 frame->size(), false); | |
1129 } | 1137 } |
1130 | 1138 |
1131 const SpdyHeaderInfo SpdyTestUtil::MakeSpdyHeader(SpdyFrameType type) { | 1139 const SpdyHeaderInfo SpdyTestUtil::MakeSpdyHeader(SpdyFrameType type) { |
1132 const SpdyHeaderInfo kHeader = { | 1140 const SpdyHeaderInfo kHeader = { |
1133 type, | 1141 type, |
1134 1, // Stream ID | 1142 1, // Stream ID |
1135 0, // Associated stream ID | 1143 0, // Associated stream ID |
1136 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_version_), | 1144 ConvertRequestPriorityToSpdyPriority(LOWEST, spdy_version_), |
1137 kSpdyCredentialSlotUnused, | 1145 kSpdyCredentialSlotUnused, |
1138 CONTROL_FLAG_FIN, // Control Flags | 1146 CONTROL_FLAG_FIN, // Control Flags |
1139 false, // Compressed | 1147 false, // Compressed |
1140 RST_STREAM_INVALID, | 1148 RST_STREAM_INVALID, |
1141 NULL, // Data | 1149 NULL, // Data |
1142 0, // Length | 1150 0, // Length |
1143 DATA_FLAG_NONE | 1151 DATA_FLAG_NONE}; |
1144 }; | |
1145 return kHeader; | 1152 return kHeader; |
1146 } | 1153 } |
1147 | 1154 |
1148 scoped_ptr<SpdyFramer> SpdyTestUtil::CreateFramer(bool compressed) const { | 1155 scoped_ptr<SpdyFramer> SpdyTestUtil::CreateFramer(bool compressed) const { |
1149 scoped_ptr<SpdyFramer> framer(new SpdyFramer(spdy_version_)); | 1156 scoped_ptr<SpdyFramer> framer(new SpdyFramer(spdy_version_)); |
1150 framer->set_enable_compression(compressed); | 1157 framer->set_enable_compression(compressed); |
1151 return framer.Pass(); | 1158 return framer.Pass(); |
1152 } | 1159 } |
1153 | 1160 |
1154 const char* SpdyTestUtil::GetMethodKey() const { | 1161 const char* SpdyTestUtil::GetMethodKey() const { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 | 1210 |
1204 void SpdyTestUtil::MaybeAddVersionHeader( | 1211 void SpdyTestUtil::MaybeAddVersionHeader( |
1205 SpdyFrameWithNameValueBlockIR* frame_ir) const { | 1212 SpdyFrameWithNameValueBlockIR* frame_ir) const { |
1206 if (include_version_header()) { | 1213 if (include_version_header()) { |
1207 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); | 1214 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); |
1208 } | 1215 } |
1209 } | 1216 } |
1210 | 1217 |
1211 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1218 void SpdyTestUtil::SetPriority(RequestPriority priority, |
1212 SpdySynStreamIR* ir) const { | 1219 SpdySynStreamIR* ir) const { |
1213 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1220 ir->set_priority( |
1214 priority, spdy_version())); | 1221 ConvertRequestPriorityToSpdyPriority(priority, spdy_version())); |
1215 } | 1222 } |
1216 | 1223 |
1217 } // namespace net | 1224 } // namespace net |
OLD | NEW |