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