Chromium Code Reviews| 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"; | |
|
ramant (doing other things)
2014/06/27 22:38:13
nit: Can one send a header with p less than 0 (or
Ryan Hamilton
2014/06/30 19:02:35
No, the valid range is [0,1]. Added a test for an
ramant (doing other things)
2014/06/30 21:01:24
Great.
| |
| 54 static const char kQuicAlternateProtocolHttpsHeader[] = | 56 static const char kQuicAlternateProtocolHttpsHeader[] = |
| 55 "Alternate-Protocol: 443:quic\r\n\r\n"; | 57 "Alternate-Protocol: 443:quic\r\n\r\n"; |
| 56 | 58 |
| 57 } // namespace | 59 } // namespace |
| 58 | 60 |
| 59 namespace net { | 61 namespace net { |
| 60 namespace test { | 62 namespace test { |
| 61 | 63 |
| 62 // Helper class to encapsulate MockReads and MockWrites for QUIC. | 64 // Helper class to encapsulate MockReads and MockWrites for QUIC. |
| 63 // Simplify ownership issues and the interaction with the MockSocketFactory. | 65 // Simplify ownership issues and the interaction with the MockSocketFactory. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 268 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 270 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
| 269 RunTransaction(trans.get()); | 271 RunTransaction(trans.get()); |
| 270 CheckWasQuicResponse(trans); | 272 CheckWasQuicResponse(trans); |
| 271 CheckResponseData(trans.get(), expected); | 273 CheckResponseData(trans.get(), expected); |
| 272 } | 274 } |
| 273 | 275 |
| 274 void AddQuicAlternateProtocolMapping( | 276 void AddQuicAlternateProtocolMapping( |
| 275 MockCryptoClientStream::HandshakeMode handshake_mode) { | 277 MockCryptoClientStream::HandshakeMode handshake_mode) { |
| 276 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); | 278 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
| 277 session_->http_server_properties()->SetAlternateProtocol( | 279 session_->http_server_properties()->SetAlternateProtocol( |
| 278 HostPortPair::FromURL(request_.url), 80, QUIC); | 280 HostPortPair::FromURL(request_.url), 80, QUIC, 1); |
| 279 } | 281 } |
| 280 | 282 |
| 281 void ExpectBrokenAlternateProtocolMapping() { | 283 void ExpectBrokenAlternateProtocolMapping() { |
| 282 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( | 284 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( |
| 283 HostPortPair::FromURL(request_.url))); | 285 HostPortPair::FromURL(request_.url))); |
| 284 const PortAlternateProtocolPair alternate = | 286 const AlternateProtocolInfo alternate = |
| 285 session_->http_server_properties()->GetAlternateProtocol( | 287 session_->http_server_properties()->GetAlternateProtocol( |
| 286 HostPortPair::FromURL(request_.url)); | 288 HostPortPair::FromURL(request_.url)); |
| 287 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); | 289 EXPECT_EQ(ALTERNATE_PROTOCOL_BROKEN, alternate.protocol); |
| 288 } | 290 } |
| 289 | 291 |
| 290 void ExpectQuicAlternateProtocolMapping() { | 292 void ExpectQuicAlternateProtocolMapping() { |
| 291 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( | 293 ASSERT_TRUE(session_->http_server_properties()->HasAlternateProtocol( |
| 292 HostPortPair::FromURL(request_.url))); | 294 HostPortPair::FromURL(request_.url))); |
| 293 const PortAlternateProtocolPair alternate = | 295 const AlternateProtocolInfo alternate = |
| 294 session_->http_server_properties()->GetAlternateProtocol( | 296 session_->http_server_properties()->GetAlternateProtocol( |
| 295 HostPortPair::FromURL(request_.url)); | 297 HostPortPair::FromURL(request_.url)); |
| 296 EXPECT_EQ(QUIC, alternate.protocol); | 298 EXPECT_EQ(QUIC, alternate.protocol); |
| 297 } | 299 } |
| 298 | 300 |
| 299 void AddHangingNonAlternateProtocolSocketData() { | 301 void AddHangingNonAlternateProtocolSocketData() { |
| 300 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); | 302 MockConnect hanging_connect(SYNCHRONOUS, ERR_IO_PENDING); |
| 301 hanging_data_.set_connect_data(hanging_connect); | 303 hanging_data_.set_connect_data(hanging_connect); |
| 302 socket_factory_.AddSocketDataProvider(&hanging_data_); | 304 socket_factory_.AddSocketDataProvider(&hanging_data_); |
| 303 } | 305 } |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 // The non-alternate protocol job needs to hang in order to guarantee that | 485 // The non-alternate protocol job needs to hang in order to guarantee that |
| 484 // the alternate-protocol job will "win". | 486 // the alternate-protocol job will "win". |
| 485 AddHangingNonAlternateProtocolSocketData(); | 487 AddHangingNonAlternateProtocolSocketData(); |
| 486 | 488 |
| 487 CreateSessionWithNextProtos(); | 489 CreateSessionWithNextProtos(); |
| 488 | 490 |
| 489 SendRequestAndExpectHttpResponse("hello world"); | 491 SendRequestAndExpectHttpResponse("hello world"); |
| 490 SendRequestAndExpectQuicResponse("hello!"); | 492 SendRequestAndExpectQuicResponse("hello!"); |
| 491 } | 493 } |
| 492 | 494 |
| 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 http_server_properties.SetAlternateProtocolProbabilityThreshold(.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 | |
|
ramant (doing other things)
2014/06/27 22:38:13
nit: extra blank line.
| |
| 547 | |
| 548 http_server_properties.SetAlternateProtocolProbabilityThreshold(.75); | |
| 549 CreateSessionWithNextProtos(); | |
| 550 | |
| 551 SendRequestAndExpectHttpResponse("hello world"); | |
| 552 SendRequestAndExpectHttpResponse("hello world"); | |
| 553 } | |
| 554 | |
| 493 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { | 555 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { |
| 494 params_.origin_to_force_quic_on = | 556 params_.origin_to_force_quic_on = |
| 495 HostPortPair::FromString("www.google.com:443"); | 557 HostPortPair::FromString("www.google.com:443"); |
| 496 | 558 |
| 497 MockRead http_reads[] = { | 559 MockRead http_reads[] = { |
| 498 MockRead("HTTP/1.1 200 OK\r\n"), | 560 MockRead("HTTP/1.1 200 OK\r\n"), |
| 499 MockRead(kQuicAlternateProtocolHttpsHeader), | 561 MockRead(kQuicAlternateProtocolHttpsHeader), |
| 500 MockRead("hello world"), | 562 MockRead("hello world"), |
| 501 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 563 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 502 MockRead(ASYNC, OK) | 564 MockRead(ASYNC, OK) |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 949 NULL, | 1011 NULL, |
| 950 net_log_.bound()); | 1012 net_log_.bound()); |
| 951 | 1013 |
| 952 CreateSessionWithNextProtos(); | 1014 CreateSessionWithNextProtos(); |
| 953 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 1015 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
| 954 SendRequestAndExpectHttpResponse("hello world"); | 1016 SendRequestAndExpectHttpResponse("hello world"); |
| 955 } | 1017 } |
| 956 | 1018 |
| 957 } // namespace test | 1019 } // namespace test |
| 958 } // namespace net | 1020 } // namespace net |
| OLD | NEW |