| 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 | |
| 9 #include <cstddef> | 8 #include <cstddef> |
| 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
| 16 #include "net/cert/mock_cert_verifier.h" | 16 #include "net/cert/mock_cert_verifier.h" |
| 17 #include "net/http/http_cache.h" | 17 #include "net/http/http_cache.h" |
| 18 #include "net/http/http_network_session.h" | 18 #include "net/http/http_network_session.h" |
| 19 #include "net/http/http_network_transaction.h" | 19 #include "net/http/http_network_transaction.h" |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 // cancellable TCPConnectJobs, use synchronous lookups. | 366 // cancellable TCPConnectJobs, use synchronous lookups. |
| 367 host_resolver->set_synchronous_mode(true); | 367 host_resolver->set_synchronous_mode(true); |
| 368 } | 368 } |
| 369 | 369 |
| 370 SpdySessionDependencies::SpdySessionDependencies( | 370 SpdySessionDependencies::SpdySessionDependencies( |
| 371 NextProto protocol, | 371 NextProto protocol, |
| 372 scoped_ptr<ProxyService> proxy_service) | 372 scoped_ptr<ProxyService> proxy_service) |
| 373 : host_resolver(new MockHostResolver), | 373 : host_resolver(new MockHostResolver), |
| 374 cert_verifier(new MockCertVerifier), | 374 cert_verifier(new MockCertVerifier), |
| 375 transport_security_state(new TransportSecurityState), | 375 transport_security_state(new TransportSecurityState), |
| 376 proxy_service(proxy_service.Pass()), | 376 proxy_service(std::move(proxy_service)), |
| 377 ssl_config_service(new SSLConfigServiceDefaults), | 377 ssl_config_service(new SSLConfigServiceDefaults), |
| 378 socket_factory(new MockClientSocketFactory), | 378 socket_factory(new MockClientSocketFactory), |
| 379 http_auth_handler_factory( | 379 http_auth_handler_factory( |
| 380 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), | 380 HttpAuthHandlerFactory::CreateDefault(host_resolver.get())), |
| 381 enable_ip_pooling(true), | 381 enable_ip_pooling(true), |
| 382 enable_compression(false), | 382 enable_compression(false), |
| 383 enable_ping(false), | 383 enable_ping(false), |
| 384 enable_user_alternate_protocol_ports(false), | 384 enable_user_alternate_protocol_ports(false), |
| 385 enable_npn(true), | 385 enable_npn(true), |
| 386 protocol(protocol), | 386 protocol(protocol), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 397 SpdySessionDependencies::~SpdySessionDependencies() {} | 397 SpdySessionDependencies::~SpdySessionDependencies() {} |
| 398 | 398 |
| 399 // static | 399 // static |
| 400 scoped_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession( | 400 scoped_ptr<HttpNetworkSession> SpdySessionDependencies::SpdyCreateSession( |
| 401 SpdySessionDependencies* session_deps) { | 401 SpdySessionDependencies* session_deps) { |
| 402 HttpNetworkSession::Params params = CreateSessionParams(session_deps); | 402 HttpNetworkSession::Params params = CreateSessionParams(session_deps); |
| 403 params.client_socket_factory = session_deps->socket_factory.get(); | 403 params.client_socket_factory = session_deps->socket_factory.get(); |
| 404 scoped_ptr<HttpNetworkSession> http_session(new HttpNetworkSession(params)); | 404 scoped_ptr<HttpNetworkSession> http_session(new HttpNetworkSession(params)); |
| 405 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); | 405 SpdySessionPoolPeer pool_peer(http_session->spdy_session_pool()); |
| 406 pool_peer.SetEnableSendingInitialData(false); | 406 pool_peer.SetEnableSendingInitialData(false); |
| 407 return http_session.Pass(); | 407 return http_session; |
| 408 } | 408 } |
| 409 | 409 |
| 410 // static | 410 // static |
| 411 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( | 411 HttpNetworkSession::Params SpdySessionDependencies::CreateSessionParams( |
| 412 SpdySessionDependencies* session_deps) { | 412 SpdySessionDependencies* session_deps) { |
| 413 DCHECK(next_proto_is_spdy(session_deps->protocol)) << | 413 DCHECK(next_proto_is_spdy(session_deps->protocol)) << |
| 414 "Invalid protocol: " << session_deps->protocol; | 414 "Invalid protocol: " << session_deps->protocol; |
| 415 | 415 |
| 416 HttpNetworkSession::Params params; | 416 HttpNetworkSession::Params params; |
| 417 params.host_resolver = session_deps->host_resolver.get(); | 417 params.host_resolver = session_deps->host_resolver.get(); |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 net_log); | 535 net_log); |
| 536 } | 536 } |
| 537 | 537 |
| 538 if (rv == ERR_IO_PENDING) | 538 if (rv == ERR_IO_PENDING) |
| 539 rv = callback.WaitForResult(); | 539 rv = callback.WaitForResult(); |
| 540 | 540 |
| 541 EXPECT_EQ(OK, rv); | 541 EXPECT_EQ(OK, rv); |
| 542 | 542 |
| 543 base::WeakPtr<SpdySession> spdy_session = | 543 base::WeakPtr<SpdySession> spdy_session = |
| 544 http_session->spdy_session_pool()->CreateAvailableSessionFromSocket( | 544 http_session->spdy_session_pool()->CreateAvailableSessionFromSocket( |
| 545 key, connection.Pass(), net_log, OK, is_secure); | 545 key, std::move(connection), net_log, OK, is_secure); |
| 546 // Failure is reported asynchronously. | 546 // Failure is reported asynchronously. |
| 547 EXPECT_TRUE(spdy_session != NULL); | 547 EXPECT_TRUE(spdy_session != NULL); |
| 548 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); | 548 EXPECT_TRUE(HasSpdySession(http_session->spdy_session_pool(), key)); |
| 549 return spdy_session; | 549 return spdy_session; |
| 550 } | 550 } |
| 551 | 551 |
| 552 } // namespace | 552 } // namespace |
| 553 | 553 |
| 554 base::WeakPtr<SpdySession> CreateInsecureSpdySession( | 554 base::WeakPtr<SpdySession> CreateInsecureSpdySession( |
| 555 HttpNetworkSession* http_session, | 555 HttpNetworkSession* http_session, |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 SpdySessionPool* pool, | 642 SpdySessionPool* pool, |
| 643 const SpdySessionKey& key, | 643 const SpdySessionKey& key, |
| 644 Error expected_status) { | 644 Error expected_status) { |
| 645 EXPECT_NE(expected_status, ERR_IO_PENDING); | 645 EXPECT_NE(expected_status, ERR_IO_PENDING); |
| 646 EXPECT_FALSE(HasSpdySession(pool, key)); | 646 EXPECT_FALSE(HasSpdySession(pool, key)); |
| 647 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); | 647 scoped_ptr<ClientSocketHandle> handle(new ClientSocketHandle()); |
| 648 handle->SetSocket(scoped_ptr<StreamSocket>(new FakeSpdySessionClientSocket( | 648 handle->SetSocket(scoped_ptr<StreamSocket>(new FakeSpdySessionClientSocket( |
| 649 expected_status == OK ? ERR_IO_PENDING : expected_status))); | 649 expected_status == OK ? ERR_IO_PENDING : expected_status))); |
| 650 base::WeakPtr<SpdySession> spdy_session = | 650 base::WeakPtr<SpdySession> spdy_session = |
| 651 pool->CreateAvailableSessionFromSocket( | 651 pool->CreateAvailableSessionFromSocket( |
| 652 key, handle.Pass(), BoundNetLog(), OK, true /* is_secure */); | 652 key, std::move(handle), BoundNetLog(), OK, true /* is_secure */); |
| 653 // Failure is reported asynchronously. | 653 // Failure is reported asynchronously. |
| 654 EXPECT_TRUE(spdy_session != NULL); | 654 EXPECT_TRUE(spdy_session != NULL); |
| 655 EXPECT_TRUE(HasSpdySession(pool, key)); | 655 EXPECT_TRUE(HasSpdySession(pool, key)); |
| 656 return spdy_session; | 656 return spdy_session; |
| 657 } | 657 } |
| 658 | 658 |
| 659 } // namespace | 659 } // namespace |
| 660 | 660 |
| 661 base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, | 661 base::WeakPtr<SpdySession> CreateFakeSpdySession(SpdySessionPool* pool, |
| 662 const SpdySessionKey& key) { | 662 const SpdySessionKey& key) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 } | 714 } |
| 715 | 715 |
| 716 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( | 716 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlock( |
| 717 base::StringPiece url) const { | 717 base::StringPiece url) const { |
| 718 return ConstructHeaderBlock("GET", url, NULL); | 718 return ConstructHeaderBlock("GET", url, NULL); |
| 719 } | 719 } |
| 720 | 720 |
| 721 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( | 721 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructGetHeaderBlockForProxy( |
| 722 base::StringPiece url) const { | 722 base::StringPiece url) const { |
| 723 scoped_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); | 723 scoped_ptr<SpdyHeaderBlock> headers(ConstructGetHeaderBlock(url)); |
| 724 return headers.Pass(); | 724 return headers; |
| 725 } | 725 } |
| 726 | 726 |
| 727 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( | 727 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructHeadHeaderBlock( |
| 728 base::StringPiece url, | 728 base::StringPiece url, |
| 729 int64_t content_length) const { | 729 int64_t content_length) const { |
| 730 return ConstructHeaderBlock("HEAD", url, nullptr); | 730 return ConstructHeaderBlock("HEAD", url, nullptr); |
| 731 } | 731 } |
| 732 | 732 |
| 733 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( | 733 scoped_ptr<SpdyHeaderBlock> SpdyTestUtil::ConstructPostHeaderBlock( |
| 734 base::StringPiece url, | 734 base::StringPiece url, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 | 782 |
| 783 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, | 783 SpdyFrame* SpdyTestUtil::ConstructSpdyFrame(const SpdyHeaderInfo& header_info, |
| 784 const char* const extra_headers[], | 784 const char* const extra_headers[], |
| 785 int extra_header_count, | 785 int extra_header_count, |
| 786 const char* const tail_headers[], | 786 const char* const tail_headers[], |
| 787 int tail_header_count) const { | 787 int tail_header_count) const { |
| 788 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 788 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 789 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 789 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); |
| 790 if (tail_headers && tail_header_count) | 790 if (tail_headers && tail_header_count) |
| 791 AppendToHeaderBlock(tail_headers, tail_header_count, headers.get()); | 791 AppendToHeaderBlock(tail_headers, tail_header_count, headers.get()); |
| 792 return ConstructSpdyFrame(header_info, headers.Pass()); | 792 return ConstructSpdyFrame(header_info, std::move(headers)); |
| 793 } | 793 } |
| 794 | 794 |
| 795 SpdyFrame* SpdyTestUtil::ConstructSpdyControlFrame( | 795 SpdyFrame* SpdyTestUtil::ConstructSpdyControlFrame( |
| 796 scoped_ptr<SpdyHeaderBlock> headers, | 796 scoped_ptr<SpdyHeaderBlock> headers, |
| 797 bool compressed, | 797 bool compressed, |
| 798 SpdyStreamId stream_id, | 798 SpdyStreamId stream_id, |
| 799 RequestPriority request_priority, | 799 RequestPriority request_priority, |
| 800 SpdyFrameType type, | 800 SpdyFrameType type, |
| 801 SpdyControlFlags flags, | 801 SpdyControlFlags flags, |
| 802 SpdyStreamId associated_stream_id) const { | 802 SpdyStreamId associated_stream_id) const { |
| 803 EXPECT_GE(type, DATA); | 803 EXPECT_GE(type, DATA); |
| 804 EXPECT_LE(type, PRIORITY); | 804 EXPECT_LE(type, PRIORITY); |
| 805 const SpdyHeaderInfo header_info = { | 805 const SpdyHeaderInfo header_info = { |
| 806 type, | 806 type, |
| 807 stream_id, | 807 stream_id, |
| 808 associated_stream_id, | 808 associated_stream_id, |
| 809 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_), | 809 ConvertRequestPriorityToSpdyPriority(request_priority, spdy_version_), |
| 810 flags, | 810 flags, |
| 811 compressed, | 811 compressed, |
| 812 RST_STREAM_INVALID, // status | 812 RST_STREAM_INVALID, // status |
| 813 NULL, // data | 813 NULL, // data |
| 814 0, // length | 814 0, // length |
| 815 DATA_FLAG_NONE | 815 DATA_FLAG_NONE |
| 816 }; | 816 }; |
| 817 return ConstructSpdyFrame(header_info, headers.Pass()); | 817 return ConstructSpdyFrame(header_info, std::move(headers)); |
| 818 } | 818 } |
| 819 | 819 |
| 820 SpdyFrame* SpdyTestUtil::ConstructSpdyControlFrame( | 820 SpdyFrame* SpdyTestUtil::ConstructSpdyControlFrame( |
| 821 const char* const extra_headers[], | 821 const char* const extra_headers[], |
| 822 int extra_header_count, | 822 int extra_header_count, |
| 823 bool compressed, | 823 bool compressed, |
| 824 SpdyStreamId stream_id, | 824 SpdyStreamId stream_id, |
| 825 RequestPriority request_priority, | 825 RequestPriority request_priority, |
| 826 SpdyFrameType type, | 826 SpdyFrameType type, |
| 827 SpdyControlFlags flags, | 827 SpdyControlFlags flags, |
| 828 const char* const* tail_headers, | 828 const char* const* tail_headers, |
| 829 int tail_header_size, | 829 int tail_header_size, |
| 830 SpdyStreamId associated_stream_id) const { | 830 SpdyStreamId associated_stream_id) const { |
| 831 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); | 831 scoped_ptr<SpdyHeaderBlock> headers(new SpdyHeaderBlock()); |
| 832 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); | 832 AppendToHeaderBlock(extra_headers, extra_header_count, headers.get()); |
| 833 if (tail_headers && tail_header_size) | 833 if (tail_headers && tail_header_size) |
| 834 AppendToHeaderBlock(tail_headers, tail_header_size / 2, headers.get()); | 834 AppendToHeaderBlock(tail_headers, tail_header_size / 2, headers.get()); |
| 835 return ConstructSpdyControlFrame( | 835 return ConstructSpdyControlFrame(std::move(headers), compressed, stream_id, |
| 836 headers.Pass(), compressed, stream_id, | 836 request_priority, type, flags, |
| 837 request_priority, type, flags, associated_stream_id); | 837 associated_stream_id); |
| 838 } | 838 } |
| 839 | 839 |
| 840 std::string SpdyTestUtil::ConstructSpdyReplyString( | 840 std::string SpdyTestUtil::ConstructSpdyReplyString( |
| 841 const SpdyHeaderBlock& headers) const { | 841 const SpdyHeaderBlock& headers) const { |
| 842 std::string reply_string; | 842 std::string reply_string; |
| 843 for (SpdyHeaderBlock::const_iterator it = headers.begin(); | 843 for (SpdyHeaderBlock::const_iterator it = headers.begin(); |
| 844 it != headers.end(); ++it) { | 844 it != headers.end(); ++it) { |
| 845 std::string key = it->first.as_string(); | 845 std::string key = it->first.as_string(); |
| 846 // Remove leading colon from "special" headers (for SPDY3 and | 846 // Remove leading colon from "special" headers (for SPDY3 and |
| 847 // above). | 847 // above). |
| (...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1270 return; | 1270 return; |
| 1271 } | 1271 } |
| 1272 } | 1272 } |
| 1273 } | 1273 } |
| 1274 NOTREACHED(); | 1274 NOTREACHED(); |
| 1275 } | 1275 } |
| 1276 | 1276 |
| 1277 scoped_ptr<SpdyFramer> SpdyTestUtil::CreateFramer(bool compressed) const { | 1277 scoped_ptr<SpdyFramer> SpdyTestUtil::CreateFramer(bool compressed) const { |
| 1278 scoped_ptr<SpdyFramer> framer(new SpdyFramer(spdy_version_)); | 1278 scoped_ptr<SpdyFramer> framer(new SpdyFramer(spdy_version_)); |
| 1279 framer->set_enable_compression(compressed); | 1279 framer->set_enable_compression(compressed); |
| 1280 return framer.Pass(); | 1280 return framer; |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 const char* SpdyTestUtil::GetMethodKey() const { | 1283 const char* SpdyTestUtil::GetMethodKey() const { |
| 1284 return ":method"; | 1284 return ":method"; |
| 1285 } | 1285 } |
| 1286 | 1286 |
| 1287 const char* SpdyTestUtil::GetStatusKey() const { | 1287 const char* SpdyTestUtil::GetStatusKey() const { |
| 1288 return ":status"; | 1288 return ":status"; |
| 1289 } | 1289 } |
| 1290 | 1290 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1318 (*headers)[GetVersionKey()] = "HTTP/1.1"; | 1318 (*headers)[GetVersionKey()] = "HTTP/1.1"; |
| 1319 } | 1319 } |
| 1320 (*headers)[GetMethodKey()] = method.as_string(); | 1320 (*headers)[GetMethodKey()] = method.as_string(); |
| 1321 (*headers)[GetHostKey()] = host.c_str(); | 1321 (*headers)[GetHostKey()] = host.c_str(); |
| 1322 (*headers)[GetSchemeKey()] = scheme.c_str(); | 1322 (*headers)[GetSchemeKey()] = scheme.c_str(); |
| 1323 (*headers)[GetPathKey()] = path.c_str(); | 1323 (*headers)[GetPathKey()] = path.c_str(); |
| 1324 if (content_length) { | 1324 if (content_length) { |
| 1325 std::string length_str = base::Int64ToString(*content_length); | 1325 std::string length_str = base::Int64ToString(*content_length); |
| 1326 (*headers)["content-length"] = length_str; | 1326 (*headers)["content-length"] = length_str; |
| 1327 } | 1327 } |
| 1328 return headers.Pass(); | 1328 return headers; |
| 1329 } | 1329 } |
| 1330 | 1330 |
| 1331 void SpdyTestUtil::MaybeAddVersionHeader( | 1331 void SpdyTestUtil::MaybeAddVersionHeader( |
| 1332 SpdyFrameWithHeaderBlockIR* frame_ir) const { | 1332 SpdyFrameWithHeaderBlockIR* frame_ir) const { |
| 1333 if (include_version_header()) { | 1333 if (include_version_header()) { |
| 1334 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); | 1334 frame_ir->SetHeader(GetVersionKey(), "HTTP/1.1"); |
| 1335 } | 1335 } |
| 1336 } | 1336 } |
| 1337 | 1337 |
| 1338 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { | 1338 void SpdyTestUtil::MaybeAddVersionHeader(SpdyHeaderBlock* block) const { |
| 1339 if (include_version_header()) { | 1339 if (include_version_header()) { |
| 1340 (*block)[GetVersionKey()] = "HTTP/1.1"; | 1340 (*block)[GetVersionKey()] = "HTTP/1.1"; |
| 1341 } | 1341 } |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 void SpdyTestUtil::SetPriority(RequestPriority priority, | 1344 void SpdyTestUtil::SetPriority(RequestPriority priority, |
| 1345 SpdySynStreamIR* ir) const { | 1345 SpdySynStreamIR* ir) const { |
| 1346 ir->set_priority(ConvertRequestPriorityToSpdyPriority( | 1346 ir->set_priority(ConvertRequestPriorityToSpdyPriority( |
| 1347 priority, spdy_version())); | 1347 priority, spdy_version())); |
| 1348 } | 1348 } |
| 1349 | 1349 |
| 1350 } // namespace net | 1350 } // namespace net |
| OLD | NEW |