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 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 SpdySession::GetDefaultInitialWindowSize(protocol)), | 408 SpdySession::GetDefaultInitialWindowSize(protocol)), |
409 time_func(&base::TimeTicks::Now), | 409 time_func(&base::TimeTicks::Now), |
410 use_alternative_services(true), | 410 use_alternative_services(true), |
411 net_log(NULL) { | 411 net_log(NULL) { |
412 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; | 412 DCHECK(next_proto_is_spdy(protocol)) << "Invalid protocol: " << protocol; |
413 } | 413 } |
414 | 414 |
415 SpdySessionDependencies::~SpdySessionDependencies() {} | 415 SpdySessionDependencies::~SpdySessionDependencies() {} |
416 | 416 |
417 // static | 417 // static |
418 scoped_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession( | 418 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSession( |
419 SpdySessionDependencies* session_deps) { | 419 SpdySessionDependencies* session_deps) { |
420 HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 420 HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
421 params.client_socket_factory = session_deps->socket_factory.get(); | 421 params.client_socket_factory = session_deps->socket_factory.get(); |
422 scoped_ptr<HttpNetworkSession> http_session(new HttpNetworkSession(params)); | 422 HttpNetworkSession* http_session = new HttpNetworkSession(params); |
423 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); | 423 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); |
424 pool_peer.SetEnableSendingInitialData(false); | 424 pool_peer.SetEnableSendingInitialData(false); |
425 return http_session.Pass(); | 425 return http_session; |
426 } | 426 } |
427 | 427 |
428 // static | 428 // static |
429 scoped_ptr<HttpNetworkSession> | 429 HttpNetworkSession* SpdySessionDependencies::SpdyCreateSessionDeterministic( |
430 SpdySessionDependencies::SpdyCreateSessionDeterministic( | |
431 SpdySessionDependencies* session_deps) { | 430 SpdySessionDependencies* session_deps) { |
432 HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 431 HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
433 params.client_socket_factory = | 432 params.client_socket_factory = |
434 session_deps->deterministic_socket_factory.get(); | 433 session_deps->deterministic_socket_factory.get(); |
435 scoped_ptr<HttpNetworkSession> http_session(new HttpNetworkSession(params)); | 434 HttpNetworkSession* http_session = new HttpNetworkSession(params); |
436 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); | 435 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); |
437 pool_peer.SetEnableSendingInitialData(false); | 436 pool_peer.SetEnableSendingInitialData(false); |
438 return http_session.Pass(); | 437 return http_session; |
439 } | 438 } |
440 | 439 |
441 // static | 440 // static |
442 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( | 441 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( |
443 SpdySessionDependencies* session_deps) { | 442 SpdySessionDependencies* session_deps) { |
444 DCHECK(next_proto_is_spdy(session_deps->protocol)) << | 443 DCHECK(next_proto_is_spdy(session_deps->protocol)) << |
445 "Invalid protocol: " << session_deps->protocol; | 444 "Invalid protocol: " << session_deps->protocol; |
446 | 445 |
447 HttpNetworkSession::Params params; | 446 HttpNetworkSession::Params params; |
448 params.host_resolver = session_deps->host_resolver.get(); | 447 params.host_resolver = session_deps->host_resolver.get(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 params.cert_verifier = cert_verifier(); | 491 params.cert_verifier = cert_verifier(); |
493 params.transport_security_state = transport_security_state(); | 492 params.transport_security_state = transport_security_state(); |
494 params.proxy_service = proxy_service(); | 493 params.proxy_service = proxy_service(); |
495 params.ssl_config_service = ssl_config_service(); | 494 params.ssl_config_service = ssl_config_service(); |
496 params.http_auth_handler_factory = http_auth_handler_factory(); | 495 params.http_auth_handler_factory = http_auth_handler_factory(); |
497 params.network_delegate = network_delegate(); | 496 params.network_delegate = network_delegate(); |
498 params.enable_spdy_compression = false; | 497 params.enable_spdy_compression = false; |
499 params.enable_spdy_ping_based_connection_checking = false; | 498 params.enable_spdy_ping_based_connection_checking = false; |
500 params.spdy_default_protocol = protocol; | 499 params.spdy_default_protocol = protocol; |
501 params.http_server_properties = http_server_properties(); | 500 params.http_server_properties = http_server_properties(); |
502 storage_.set_http_network_session( | 501 scoped_refptr<HttpNetworkSession> network_session( |
503 make_scoped_ptr(new HttpNetworkSession(params))); | 502 new HttpNetworkSession(params)); |
504 SpdySessionPoolPeer pool_peer( | 503 SpdySessionPoolPeer pool_peer(network_session->spdy_session_pool()); |
505 storage_.http_network_session()->spdy_session_pool()); | |
506 pool_peer.SetEnableSendingInitialData(false); | 504 pool_peer.SetEnableSendingInitialData(false); |
507 storage_.set_http_transaction_factory( | 505 storage_.set_http_transaction_factory(new HttpCache( |
508 new HttpCache(storage_.http_network_session(), | 506 network_session.get(), HttpCache::DefaultBackend::InMemory(0))); |
509 HttpCache::DefaultBackend::InMemory(0), false)); | |
510 } | 507 } |
511 | 508 |
512 SpdyURLRequestContext::~SpdyURLRequestContext() { | 509 SpdyURLRequestContext::~SpdyURLRequestContext() { |
513 AssertNoURLRequests(); | 510 AssertNoURLRequests(); |
514 } | 511 } |
515 | 512 |
516 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { | 513 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { |
517 return pool->FindAvailableSession(key, BoundNetLog()) != NULL; | 514 return pool->FindAvailableSession(key, BoundNetLog()) != NULL; |
518 } | 515 } |
519 | 516 |
520 namespace { | 517 namespace { |
521 | 518 |
522 base::WeakPtr<SpdySession> CreateSpdySessionHelper( | 519 base::WeakPtr<SpdySession> CreateSpdySessionHelper( |
523 HttpNetworkSession* http_session, | 520 const scoped_refptr<HttpNetworkSession>& http_session, |
524 const SpdySessionKey& key, | 521 const SpdySessionKey& key, |
525 const BoundNetLog& net_log, | 522 const BoundNetLog& net_log, |
526 Error expected_status, | 523 Error expected_status, |
527 bool is_secure) { | 524 bool is_secure) { |
528 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); | 525 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); |
529 | 526 |
530 scoped_refptr<TransportSocketParams> transport_params( | 527 scoped_refptr<TransportSocketParams> transport_params( |
531 new TransportSocketParams( | 528 new TransportSocketParams( |
532 key.host_port_pair(), false, false, OnHostResolutionCallback(), | 529 key.host_port_pair(), false, false, OnHostResolutionCallback(), |
533 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 530 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 key, connection.Pass(), net_log, OK, is_secure); | 571 key, connection.Pass(), net_log, OK, is_secure); |
575 // Failure is reported asynchronously. | 572 // Failure is reported asynchronously. |
576 EXPECT_TRUE(spdy_session != NULL); | 573 EXPECT_TRUE(spdy_session != NULL); |
577 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); | 574 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); |
578 return spdy_session; | 575 return spdy_session; |
579 } | 576 } |
580 | 577 |
581 } // namespace | 578 } // namespace |
582 | 579 |
583 base::WeakPtr<SpdySession> CreateInsecureSpdySession( | 580 base::WeakPtr<SpdySession> CreateInsecureSpdySession( |
584 HttpNetworkSession* http_session, | 581 const scoped_refptr<HttpNetworkSession>& http_session, |
585 const SpdySessionKey& key, | 582 const SpdySessionKey& key, |
586 const BoundNetLog& net_log) { | 583 const BoundNetLog& net_log) { |
587 return CreateSpdySessionHelper(http_session, key, net_log, | 584 return CreateSpdySessionHelper(http_session, key, net_log, |
588 OK, false /* is_secure */); | 585 OK, false /* is_secure */); |
589 } | 586 } |
590 | 587 |
591 base::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( | 588 base::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( |
592 HttpNetworkSession* http_session, | 589 const scoped_refptr<HttpNetworkSession>& http_session, |
593 const SpdySessionKey& key, | 590 const SpdySessionKey& key, |
594 Error expected_error, | 591 Error expected_error, |
595 const BoundNetLog& net_log) { | 592 const BoundNetLog& net_log) { |
596 DCHECK_LT(expected_error, ERR_IO_PENDING); | 593 DCHECK_LT(expected_error, ERR_IO_PENDING); |
597 return CreateSpdySessionHelper(http_session, key, net_log, | 594 return CreateSpdySessionHelper(http_session, key, net_log, |
598 expected_error, false /* is_secure */); | 595 expected_error, false /* is_secure */); |
599 } | 596 } |
600 | 597 |
601 base::WeakPtr<SpdySession> CreateSecureSpdySession( | 598 base::WeakPtr<SpdySession> CreateSecureSpdySession( |
602 HttpNetworkSession* http_session, | 599 const scoped_refptr<HttpNetworkSession>& http_session, |
603 const SpdySessionKey& key, | 600 const SpdySessionKey& key, |
604 const BoundNetLog& net_log) { | 601 const BoundNetLog& net_log) { |
605 return CreateSpdySessionHelper(http_session, key, net_log, | 602 return CreateSpdySessionHelper(http_session, key, net_log, |
606 OK, true /* is_secure */); | 603 OK, true /* is_secure */); |
607 } | 604 } |
608 | 605 |
609 namespace { | 606 namespace { |
610 | 607 |
611 // A ClientSocket used for CreateFakeSpdySession() below. | 608 // A ClientSocket used for CreateFakeSpdySession() below. |
612 class FakeSpdySessionClientSocket : public MockClientSocket { | 609 class FakeSpdySessionClientSocket : public MockClientSocket { |
(...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1341 } | 1338 } |
1342 } | 1339 } |
1343 | 1340 |
1344 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1341 void SpdyTestUtil::SetPriority(RequestPriority priority, |
1345 SpdySynStreamIR* ir) const { | 1342 SpdySynStreamIR* ir) const { |
1346 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1343 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
1347 priority, spdy_version())); | 1344 priority, spdy_version())); |
1348 } | 1345 } |
1349 | 1346 |
1350 } // namespace net | 1347 } // namespace net |
OLD | NEW |