| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 #include "testing/gtest/include/gtest/gtest.h" | 44 #include "testing/gtest/include/gtest/gtest.h" |
| 45 #include "testing/platform_test.h" | 45 #include "testing/platform_test.h" |
| 46 | 46 |
| 47 //----------------------------------------------------------------------------- | 47 //----------------------------------------------------------------------------- |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // This is the expected return from a current server advertising QUIC. | 51 // This is the expected return from a current server advertising QUIC. |
| 52 static const char kQuicAlternateProtocolHttpHeader[] = | 52 static const char kQuicAlternateProtocolHttpHeader[] = |
| 53 "Alternate-Protocol: 80:quic\r\n\r\n"; | 53 "Alternate-Protocol: 80:quic\r\n\r\n"; |
| 54 static const char kQuicAlternateProtocol50pctHttpHeader[] = | |
| 55 "Alternate-Protocol: 80:quic,p=.5\r\n\r\n"; | |
| 56 static const char kQuicAlternateProtocolHttpsHeader[] = | 54 static const char kQuicAlternateProtocolHttpsHeader[] = |
| 57 "Alternate-Protocol: 443:quic\r\n\r\n"; | 55 "Alternate-Protocol: 443:quic\r\n\r\n"; |
| 58 | 56 |
| 59 } // namespace | 57 } // namespace |
| 60 | 58 |
| 61 namespace net { | 59 namespace net { |
| 62 namespace test { | 60 namespace test { |
| 63 | 61 |
| 64 // Helper class to encapsulate MockReads and MockWrites for QUIC. | 62 // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 65 // Simplify ownership issues and the interaction with the MockSocketFactory. | 63 // Simplify ownership issues and the interaction with the MockSocketFactory. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 268 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 271 RunTransaction(trans.get()); | 269 RunTransaction(trans.get()); |
| 272 CheckWasQuicResponse(trans); | 270 CheckWasQuicResponse(trans); |
| 273 CheckResponseData(trans.get(), expected); | 271 CheckResponseData(trans.get(), expected); |
| 274 } | 272 } |
| 275 | 273 |
| 276 void AddQuicAlternateProtocolMapping( | 274 void AddQuicAlternateProtocolMapping( |
| 277 MockCryptoClientStream::HandshakeMode handshake_mode) { | 275 MockCryptoClientStream::HandshakeMode handshake_mode) { |
| 278 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); | 276 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
| 279 session_->http_server_properties()->SetAlternateProtocol( | 277 session_->http_server_properties()->SetAlternateProtocol( |
| 280 HostPortPair::FromURL(request_.url), 80, QUIC, 1); | 278 HostPortPair::FromURL(request_.url), 80, QUIC); |
| 281 } | 279 } |
| 282 | 280 |
| 283 void ExpectBrokenAlternateProtocolMapping() { | 281 void ExpectBrokenAlternateProtocolMapping() { |
| 284 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( | 282 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( |
| 285 HostPortPair::FromURL(request_.url))); | 283 HostPortPair::FromURL(request_.url))); |
| 286 const AlternateProtocolInfo alternate = | 284 const PortAlternateProtocolPair alternate = |
| 287 session_->http_server_properties()->GetAlternateProtocol( | 285 session_->http_server_properties()->GetAlternateProtocol( |
| 288 HostPortPair::FromURL(request_.url)); | 286 HostPortPair::FromURL(request_.url)); |
| 289 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 287 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
| 290 } | 288 } |
| 291 | 289 |
| 292 void ExpectQuicAlternateProtocolMapping() { | 290 void ExpectQuicAlternateProtocolMapping() { |
| 293 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( | 291 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( |
| 294 HostPortPair::FromURL(request_.url))); | 292 HostPortPair::FromURL(request_.url))); |
| 295 const AlternateProtocolInfo alternate = | 293 const PortAlternateProtocolPair alternate = |
| 296 session_->http_server_properties()->GetAlternateProtocol( | 294 session_->http_server_properties()->GetAlternateProtocol( |
| 297 HostPortPair::FromURL(request_.url)); | 295 HostPortPair::FromURL(request_.url)); |
| 298 EXPECT_EQ(QUIC, alternate.protocol); | 296 EXPECT_EQ(QUIC, alternate.protocol); |
| 299 } | 297 } |
| 300 | 298 |
| 301 void AddHangingNonAlternateProtocolSocketData() { | 299 void AddHangingNonAlternateProtocolSocketData() { |
| 302 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); | 300 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 303 hanging_data_.set_connect_data(hanging_connect); | 301 hanging_data_.set_connect_data(hanging_connect); |
| 304 socket_factory_.AddSocketDataProvider(&hanging_data_); | 302 socket_factory_.AddSocketDataProvider(&hanging_data_); |
| 305 } | 303 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 // The non-alternate protocol job needs to hang in order to guarantee that | 483 // The non-alternate protocol job needs to hang in order to guarantee that |
| 486 // the alternate-protocol job will "win". | 484 // the alternate-protocol job will "win". |
| 487 AddHangingNonAlternateProtocolSocketData(); | 485 AddHangingNonAlternateProtocolSocketData(); |
| 488 | 486 |
| 489 CreateSessionWithNextProtos(); | 487 CreateSessionWithNextProtos(); |
| 490 | 488 |
| 491 SendRequestAndExpectHttpResponse("hello world"); | 489 SendRequestAndExpectHttpResponse("hello world"); |
| 492 SendRequestAndExpectQuicResponse("hello!"); | 490 SendRequestAndExpectQuicResponse("hello!"); |
| 493 } | 491 } |
| 494 | 492 |
| 495 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { | |
| 496 MockRead http_reads[] = { | |
| 497 MockRead("HTTP/1.1 200 OK\r\n"), | |
| 498 MockRead(kQuicAlternateProtocol50pctHttpHeader), | |
| 499 MockRead("hello world"), | |
| 500 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
| 501 MockRead(ASYNC, OK) | |
| 502 }; | |
| 503 | |
| 504 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | |
| 505 NULL, 0); | |
| 506 socket_factory_.AddSocketDataProvider(&http_data); | |
| 507 | |
| 508 MockQuicData mock_quic_data; | |
| 509 mock_quic_data.AddWrite( | |
| 510 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, | |
| 511 GetRequestHeaders("GET", "http", "/"))); | |
| 512 mock_quic_data.AddRead( | |
| 513 ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, | |
| 514 GetResponseHeaders("200 OK"))); | |
| 515 mock_quic_data.AddRead( | |
| 516 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | |
| 517 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | |
| 518 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF | |
| 519 | |
| 520 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); | |
| 521 | |
| 522 // The non-alternate protocol job needs to hang in order to guarantee that | |
| 523 // the alternate-protocol job will "win". | |
| 524 AddHangingNonAlternateProtocolSocketData(); | |
| 525 | |
| 526 params_.alternate_protocol_probability_threshold = .25; | |
| 527 CreateSessionWithNextProtos(); | |
| 528 | |
| 529 SendRequestAndExpectHttpResponse("hello world"); | |
| 530 SendRequestAndExpectQuicResponse("hello!"); | |
| 531 } | |
| 532 | |
| 533 TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { | |
| 534 MockRead http_reads[] = { | |
| 535 MockRead("HTTP/1.1 200 OK\r\n"), | |
| 536 MockRead(kQuicAlternateProtocol50pctHttpHeader), | |
| 537 MockRead("hello world"), | |
| 538 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
| 539 MockRead(ASYNC, OK) | |
| 540 }; | |
| 541 | |
| 542 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | |
| 543 NULL, 0); | |
| 544 socket_factory_.AddSocketDataProvider(&http_data); | |
| 545 socket_factory_.AddSocketDataProvider(&http_data); | |
| 546 | |
| 547 params_.alternate_protocol_probability_threshold = .75; | |
| 548 CreateSessionWithNextProtos(); | |
| 549 | |
| 550 SendRequestAndExpectHttpResponse("hello world"); | |
| 551 SendRequestAndExpectHttpResponse("hello world"); | |
| 552 } | |
| 553 | |
| 554 TEST_P(QuicNetworkTransactionTest, | |
| 555 DontUseAlternateProtocolWithBadProbabilityForQuic) { | |
| 556 MockRead http_reads[] = { | |
| 557 MockRead("HTTP/1.1 200 OK\r\n"), | |
| 558 MockRead("Alternate-Protocol: 443:quic,p=2\r\n\r\n"), | |
| 559 MockRead("hello world"), | |
| 560 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | |
| 561 MockRead(ASYNC, OK) | |
| 562 }; | |
| 563 | |
| 564 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | |
| 565 NULL, 0); | |
| 566 socket_factory_.AddSocketDataProvider(&http_data); | |
| 567 socket_factory_.AddSocketDataProvider(&http_data); | |
| 568 | |
| 569 params_.alternate_protocol_probability_threshold = .75; | |
| 570 CreateSessionWithNextProtos(); | |
| 571 | |
| 572 SendRequestAndExpectHttpResponse("hello world"); | |
| 573 SendRequestAndExpectHttpResponse("hello world"); | |
| 574 } | |
| 575 | |
| 576 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { | 493 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
| 577 params_.origin_to_force_quic_on = | 494 params_.origin_to_force_quic_on = |
| 578 HostPortPair::FromString("www.google.com:443"); | 495 HostPortPair::FromString("www.google.com:443"); |
| 579 | 496 |
| 580 MockRead http_reads[] = { | 497 MockRead http_reads[] = { |
| 581 MockRead("HTTP/1.1 200 OK\r\n"), | 498 MockRead("HTTP/1.1 200 OK\r\n"), |
| 582 MockRead(kQuicAlternateProtocolHttpsHeader), | 499 MockRead(kQuicAlternateProtocolHttpsHeader), |
| 583 MockRead("hello world"), | 500 MockRead("hello world"), |
| 584 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 501 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 585 MockRead(ASYNC, OK) | 502 MockRead(ASYNC, OK) |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1032 NULL, | 949 NULL, |
| 1033 net_log_.bound()); | 950 net_log_.bound()); |
| 1034 | 951 |
| 1035 CreateSessionWithNextProtos(); | 952 CreateSessionWithNextProtos(); |
| 1036 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 953 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 1037 SendRequestAndExpectHttpResponse("hello world"); | 954 SendRequestAndExpectHttpResponse("hello world"); |
| 1038 } | 955 } |
| 1039 | 956 |
| 1040 } // namespace test | 957 } // namespace test |
| 1041 } // namespace net | 958 } // namespace net |
| OLD | NEW |