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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 } | 244 } |
245 *priority = priority_getter.priority(); | 245 *priority = priority_getter.priority(); |
246 return true; | 246 return true; |
247 } | 247 } |
248 | 248 |
249 base::WeakPtr<SpdyStream> CreateStreamSynchronously( | 249 base::WeakPtr<SpdyStream> CreateStreamSynchronously( |
250 SpdyStreamType type, | 250 SpdyStreamType type, |
251 const base::WeakPtr<SpdySession>& session, | 251 const base::WeakPtr<SpdySession>& session, |
252 const GURL& url, | 252 const GURL& url, |
253 RequestPriority priority, | 253 RequestPriority priority, |
254 const BoundNetLog& net_log) { | 254 const NetLogWithSource& net_log) { |
255 SpdyStreamRequest stream_request; | 255 SpdyStreamRequest stream_request; |
256 int rv = stream_request.StartRequest(type, session, url, priority, net_log, | 256 int rv = stream_request.StartRequest(type, session, url, priority, net_log, |
257 CompletionCallback()); | 257 CompletionCallback()); |
258 return | 258 return |
259 (rv == OK) ? stream_request.ReleaseStream() : base::WeakPtr<SpdyStream>(); | 259 (rv == OK) ? stream_request.ReleaseStream() : base::WeakPtr<SpdyStream>(); |
260 } | 260 } |
261 | 261 |
262 StreamReleaserCallback::StreamReleaserCallback() {} | 262 StreamReleaserCallback::StreamReleaserCallback() {} |
263 | 263 |
264 StreamReleaserCallback::~StreamReleaserCallback() {} | 264 StreamReleaserCallback::~StreamReleaserCallback() {} |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 } | 405 } |
406 | 406 |
407 class AllowAnyCertCTPolicyEnforcer : public CTPolicyEnforcer { | 407 class AllowAnyCertCTPolicyEnforcer : public CTPolicyEnforcer { |
408 public: | 408 public: |
409 AllowAnyCertCTPolicyEnforcer(){}; | 409 AllowAnyCertCTPolicyEnforcer(){}; |
410 ~AllowAnyCertCTPolicyEnforcer() override = default; | 410 ~AllowAnyCertCTPolicyEnforcer() override = default; |
411 | 411 |
412 ct::CertPolicyCompliance DoesConformToCertPolicy( | 412 ct::CertPolicyCompliance DoesConformToCertPolicy( |
413 X509Certificate* cert, | 413 X509Certificate* cert, |
414 const SCTList& verified_scts, | 414 const SCTList& verified_scts, |
415 const BoundNetLog& net_log) override { | 415 const NetLogWithSource& net_log) override { |
416 return ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS; | 416 return ct::CertPolicyCompliance::CERT_POLICY_COMPLIES_VIA_SCTS; |
417 } | 417 } |
418 | 418 |
419 ct::EVPolicyCompliance DoesConformToCTEVPolicy( | 419 ct::EVPolicyCompliance DoesConformToCTEVPolicy( |
420 X509Certificate* cert, | 420 X509Certificate* cert, |
421 const ct::EVCertsWhitelist* ev_whitelist, | 421 const ct::EVCertsWhitelist* ev_whitelist, |
422 const SCTList& verified_scts, | 422 const SCTList& verified_scts, |
423 const BoundNetLog& net_log) override { | 423 const NetLogWithSource& net_log) override { |
424 return ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS; | 424 return ct::EVPolicyCompliance::EV_POLICY_COMPLIES_VIA_SCTS; |
425 } | 425 } |
426 }; | 426 }; |
427 | 427 |
428 class IgnoresCTVerifier : public net::CTVerifier { | 428 class IgnoresCTVerifier : public net::CTVerifier { |
429 public: | 429 public: |
430 IgnoresCTVerifier() = default; | 430 IgnoresCTVerifier() = default; |
431 ~IgnoresCTVerifier() override = default; | 431 ~IgnoresCTVerifier() override = default; |
432 | 432 |
433 int Verify(net::X509Certificate* cert, | 433 int Verify(net::X509Certificate* cert, |
434 const std::string& stapled_ocsp_response, | 434 const std::string& stapled_ocsp_response, |
435 const std::string& sct_list_from_tls_extension, | 435 const std::string& sct_list_from_tls_extension, |
436 net::ct::CTVerifyResult* result, | 436 net::ct::CTVerifyResult* result, |
437 const net::BoundNetLog& net_log) override { | 437 const net::NetLogWithSource& net_log) override { |
438 return net::OK; | 438 return net::OK; |
439 } | 439 } |
440 | 440 |
441 void SetObserver(Observer* observer) override {} | 441 void SetObserver(Observer* observer) override {} |
442 }; | 442 }; |
443 | 443 |
444 SpdyURLRequestContext::SpdyURLRequestContext() : storage_(this) { | 444 SpdyURLRequestContext::SpdyURLRequestContext() : storage_(this) { |
445 storage_.set_host_resolver( | 445 storage_.set_host_resolver( |
446 std::unique_ptr<HostResolver>(new MockHostResolver)); | 446 std::unique_ptr<HostResolver>(new MockHostResolver)); |
447 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier)); | 447 storage_.set_cert_verifier(base::WrapUnique(new MockCertVerifier)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 storage_.http_network_session(), HttpCache::DefaultBackend::InMemory(0), | 479 storage_.http_network_session(), HttpCache::DefaultBackend::InMemory(0), |
480 false)); | 480 false)); |
481 } | 481 } |
482 | 482 |
483 SpdyURLRequestContext::~SpdyURLRequestContext() { | 483 SpdyURLRequestContext::~SpdyURLRequestContext() { |
484 AssertNoURLRequests(); | 484 AssertNoURLRequests(); |
485 } | 485 } |
486 | 486 |
487 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { | 487 bool HasSpdySession(SpdySessionPool* pool, const SpdySessionKey& key) { |
488 return static_cast<bool>( | 488 return static_cast<bool>( |
489 pool->FindAvailableSession(key, GURL(), BoundNetLog())); | 489 pool->FindAvailableSession(key, GURL(), NetLogWithSource())); |
490 } | 490 } |
491 | 491 |
492 namespace { | 492 namespace { |
493 | 493 |
494 base::WeakPtr<SpdySession> CreateSpdySessionHelper( | 494 base::WeakPtr<SpdySession> CreateSpdySessionHelper( |
495 HttpNetworkSession* http_session, | 495 HttpNetworkSession* http_session, |
496 const SpdySessionKey& key, | 496 const SpdySessionKey& key, |
497 const BoundNetLog& net_log, | 497 const NetLogWithSource& net_log, |
498 Error expected_status, | 498 Error expected_status, |
499 bool is_secure) { | 499 bool is_secure) { |
500 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); | 500 EXPECT_FALSE(HasSpdySession(http_session->spdy_session_pool(), key)); |
501 | 501 |
502 scoped_refptr<TransportSocketParams> transport_params( | 502 scoped_refptr<TransportSocketParams> transport_params( |
503 new TransportSocketParams( | 503 new TransportSocketParams( |
504 key.host_port_pair(), false, OnHostResolutionCallback(), | 504 key.host_port_pair(), false, OnHostResolutionCallback(), |
505 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); | 505 TransportSocketParams::COMBINE_CONNECT_AND_WRITE_DEFAULT)); |
506 | 506 |
507 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); | 507 std::unique_ptr<ClientSocketHandle> connection(new ClientSocketHandle); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
545 EXPECT_TRUE(spdy_session); | 545 EXPECT_TRUE(spdy_session); |
546 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); | 546 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); |
547 return spdy_session; | 547 return spdy_session; |
548 } | 548 } |
549 | 549 |
550 } // namespace | 550 } // namespace |
551 | 551 |
552 base::WeakPtr<SpdySession> CreateInsecureSpdySession( | 552 base::WeakPtr<SpdySession> CreateInsecureSpdySession( |
553 HttpNetworkSession* http_session, | 553 HttpNetworkSession* http_session, |
554 const SpdySessionKey& key, | 554 const SpdySessionKey& key, |
555 const BoundNetLog& net_log) { | 555 const NetLogWithSource& net_log) { |
556 return CreateSpdySessionHelper(http_session, key, net_log, | 556 return CreateSpdySessionHelper(http_session, key, net_log, |
557 OK, false /* is_secure */); | 557 OK, false /* is_secure */); |
558 } | 558 } |
559 | 559 |
560 base::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( | 560 base::WeakPtr<SpdySession> TryCreateInsecureSpdySessionExpectingFailure( |
561 HttpNetworkSession* http_session, | 561 HttpNetworkSession* http_session, |
562 const SpdySessionKey& key, | 562 const SpdySessionKey& key, |
563 Error expected_error, | 563 Error expected_error, |
564 const BoundNetLog& net_log) { | 564 const NetLogWithSource& net_log) { |
565 DCHECK_LT(expected_error, ERR_IO_PENDING); | 565 DCHECK_LT(expected_error, ERR_IO_PENDING); |
566 return CreateSpdySessionHelper(http_session, key, net_log, | 566 return CreateSpdySessionHelper(http_session, key, net_log, |
567 expected_error, false /* is_secure */); | 567 expected_error, false /* is_secure */); |
568 } | 568 } |
569 | 569 |
570 base::WeakPtr<SpdySession> CreateSecureSpdySession( | 570 base::WeakPtr<SpdySession> CreateSecureSpdySession( |
571 HttpNetworkSession* http_session, | 571 HttpNetworkSession* http_session, |
572 const SpdySessionKey& key, | 572 const SpdySessionKey& key, |
573 const BoundNetLog& net_log) { | 573 const NetLogWithSource& net_log) { |
574 return CreateSpdySessionHelper(http_session, key, net_log, | 574 return CreateSpdySessionHelper(http_session, key, net_log, |
575 OK, true /* is_secure */); | 575 OK, true /* is_secure */); |
576 } | 576 } |
577 | 577 |
578 namespace { | 578 namespace { |
579 | 579 |
580 // A ClientSocket used for CreateFakeSpdySession() below. | 580 // A ClientSocket used for CreateFakeSpdySession() below. |
581 class FakeSpdySessionClientSocket : public MockClientSocket { | 581 class FakeSpdySessionClientSocket : public MockClientSocket { |
582 public: | 582 public: |
583 explicit FakeSpdySessionClientSocket(int read_result) | 583 explicit FakeSpdySessionClientSocket(int read_result) |
584 : MockClientSocket(BoundNetLog()), read_result_(read_result) {} | 584 : MockClientSocket(NetLogWithSource()), read_result_(read_result) {} |
585 | 585 |
586 ~FakeSpdySessionClientSocket() override {} | 586 ~FakeSpdySessionClientSocket() override {} |
587 | 587 |
588 int Read(IOBuffer* buf, | 588 int Read(IOBuffer* buf, |
589 int buf_len, | 589 int buf_len, |
590 const CompletionCallback& callback) override { | 590 const CompletionCallback& callback) override { |
591 return read_result_; | 591 return read_result_; |
592 } | 592 } |
593 | 593 |
594 int Write(IOBuffer* buf, | 594 int Write(IOBuffer* buf, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 const SpdySessionKey& key, | 636 const SpdySessionKey& key, |
637 Error expected_status) { | 637 Error expected_status) { |
638 EXPECT_NE(expected_status, ERR_IO_PENDING); | 638 EXPECT_NE(expected_status, ERR_IO_PENDING); |
639 EXPECT_FALSE(HasSpdySession(pool, key)); | 639 EXPECT_FALSE(HasSpdySession(pool, key)); |
640 std::unique_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); | 640 std::unique_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); |
641 handle->SetSocket( | 641 handle->SetSocket( |
642 std::unique_ptr<StreamSocket>(new FakeSpdySessionClientSocket( | 642 std::unique_ptr<StreamSocket>(new FakeSpdySessionClientSocket( |
643 expected_status == OK ? ERR_IO_PENDING : expected_status))); | 643 expected_status == OK ? ERR_IO_PENDING : expected_status))); |
644 base::WeakPtr<SpdySession> spdy_session = | 644 base::WeakPtr<SpdySession> spdy_session = |
645 pool->CreateAvailableSessionFromSocket( | 645 pool->CreateAvailableSessionFromSocket( |
646 key, std::move(handle), BoundNetLog(), OK, true /* is_secure */); | 646 key, std::move(handle), NetLogWithSource(), OK, true /* is_secure */); |
647 // Failure is reported asynchronously. | 647 // Failure is reported asynchronously. |
648 EXPECT_TRUE(spdy_session); | 648 EXPECT_TRUE(spdy_session); |
649 EXPECT_TRUE(HasSpdySession(pool, key)); | 649 EXPECT_TRUE(HasSpdySession(pool, key)); |
650 return spdy_session; | 650 return spdy_session; |
651 } | 651 } |
652 | 652 |
653 } // namespace | 653 } // namespace |
654 | 654 |
655 base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, | 655 base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, |
656 const SpdySessionKey& key) { | 656 const SpdySessionKey& key) { |
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1143 headers[GetSchemeKey()] = scheme.c_str(); | 1143 headers[GetSchemeKey()] = scheme.c_str(); |
1144 headers[GetPathKey()] = path.c_str(); | 1144 headers[GetPathKey()] = path.c_str(); |
1145 if (content_length) { | 1145 if (content_length) { |
1146 std::string length_str = base::Int64ToString(*content_length); | 1146 std::string length_str = base::Int64ToString(*content_length); |
1147 headers["content-length"] = length_str; | 1147 headers["content-length"] = length_str; |
1148 } | 1148 } |
1149 return headers; | 1149 return headers; |
1150 } | 1150 } |
1151 | 1151 |
1152 } // namespace net | 1152 } // namespace net |
OLD | NEW |