| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/compiler_specific.h" | 6 #include "base/compiler_specific.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "net/base/capturing_net_log.h" | 9 #include "net/base/capturing_net_log.h" |
| 10 #include "net/base/net_log_unittest.h" | 10 #include "net/base/net_log_unittest.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 header_.public_header.guid = random_generator_.RandUint64(); | 204 header_.public_header.guid = random_generator_.RandUint64(); |
| 205 header_.public_header.reset_flag = false; | 205 header_.public_header.reset_flag = false; |
| 206 header_.public_header.version_flag = should_include_version; | 206 header_.public_header.version_flag = should_include_version; |
| 207 header_.packet_sequence_number = sequence_number; | 207 header_.packet_sequence_number = sequence_number; |
| 208 header_.fec_group = 0; | 208 header_.fec_group = 0; |
| 209 header_.entropy_flag = false; | 209 header_.entropy_flag = false; |
| 210 header_.fec_flag = false; | 210 header_.fec_flag = false; |
| 211 } | 211 } |
| 212 | 212 |
| 213 void CreateSession() { | 213 void CreateSession() { |
| 214 CreateSessionWithFactory(&socket_factory_); |
| 215 } |
| 216 |
| 217 void CreateSessionWithFactory(ClientSocketFactory* socket_factory) { |
| 214 params_.enable_quic = true; | 218 params_.enable_quic = true; |
| 215 params_.quic_clock = clock_; | 219 params_.quic_clock = clock_; |
| 216 params_.quic_random = &random_generator_; | 220 params_.quic_random = &random_generator_; |
| 217 params_.client_socket_factory = &socket_factory_; | 221 params_.client_socket_factory = socket_factory; |
| 218 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; | 222 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; |
| 219 params_.host_resolver = &host_resolver_; | 223 params_.host_resolver = &host_resolver_; |
| 220 params_.cert_verifier = &cert_verifier_; | 224 params_.cert_verifier = &cert_verifier_; |
| 221 params_.transport_security_state = &transport_security_state_; | 225 params_.transport_security_state = &transport_security_state_; |
| 222 params_.proxy_service = proxy_service_.get(); | 226 params_.proxy_service = proxy_service_.get(); |
| 223 params_.ssl_config_service = ssl_config_service_.get(); | 227 params_.ssl_config_service = ssl_config_service_.get(); |
| 224 params_.http_auth_handler_factory = auth_handler_factory_.get(); | 228 params_.http_auth_handler_factory = auth_handler_factory_.get(); |
| 225 params_.http_server_properties = &http_server_properties; | 229 params_.http_server_properties = &http_server_properties; |
| 226 | 230 |
| 227 session_ = new HttpNetworkSession(params_); | 231 session_ = new HttpNetworkSession(params_); |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 // The non-alternate protocol job needs to hang in order to guarantee that | 484 // The non-alternate protocol job needs to hang in order to guarantee that |
| 481 // the alternate-protocol job will "win". | 485 // the alternate-protocol job will "win". |
| 482 AddHangingNonAlternateProtocolSocketData(); | 486 AddHangingNonAlternateProtocolSocketData(); |
| 483 | 487 |
| 484 CreateSession(); | 488 CreateSession(); |
| 485 | 489 |
| 486 SendRequestAndExpectHttpResponse("hello world"); | 490 SendRequestAndExpectHttpResponse("hello world"); |
| 487 SendRequestAndExpectQuicResponse("hello!"); | 491 SendRequestAndExpectQuicResponse("hello!"); |
| 488 } | 492 } |
| 489 | 493 |
| 494 TEST_F(QuicNetworkTransactionTest, HungAlternateProtocol) { |
| 495 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
| 496 crypto_client_stream_factory_.set_handshake_mode( |
| 497 MockCryptoClientStream::COLD_START); |
| 498 |
| 499 MockWrite http_writes[] = { |
| 500 MockWrite(SYNCHRONOUS, 0, "GET / HTTP/1.1\r\n"), |
| 501 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
| 502 MockWrite(SYNCHRONOUS, 2, "Connection: keep-alive\r\n\r\n") |
| 503 }; |
| 504 |
| 505 MockRead http_reads[] = { |
| 506 MockRead(SYNCHRONOUS, 3, "HTTP/1.1 200 OK\r\n"), |
| 507 MockRead(SYNCHRONOUS, 4, kQuicAlternateProtocolHttpHeader), |
| 508 MockRead(SYNCHRONOUS, 5, "hello world"), |
| 509 MockRead(SYNCHRONOUS, OK, 6) |
| 510 }; |
| 511 |
| 512 DeterministicMockClientSocketFactory socket_factory; |
| 513 |
| 514 DeterministicSocketData http_data(http_reads, arraysize(http_reads), |
| 515 http_writes, arraysize(http_writes)); |
| 516 socket_factory.AddSocketDataProvider(&http_data); |
| 517 |
| 518 // The QUIC transaction will not be allowed to complete. |
| 519 MockWrite quic_writes[] = { |
| 520 MockWrite(ASYNC, ERR_IO_PENDING, 0) |
| 521 }; |
| 522 MockRead quic_reads[] = { |
| 523 MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 524 }; |
| 525 DeterministicSocketData quic_data(quic_reads, arraysize(quic_reads), |
| 526 quic_writes, arraysize(quic_writes)); |
| 527 socket_factory.AddSocketDataProvider(&quic_data); |
| 528 |
| 529 // The HTTP transaction will complete. |
| 530 DeterministicSocketData http_data2(http_reads, arraysize(http_reads), |
| 531 http_writes, arraysize(http_writes)); |
| 532 socket_factory.AddSocketDataProvider(&http_data2); |
| 533 |
| 534 CreateSessionWithFactory(&socket_factory); |
| 535 |
| 536 // Run the first request. |
| 537 http_data.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 538 SendRequestAndExpectHttpResponse("hello world"); |
| 539 ASSERT_TRUE(http_data.at_read_eof()); |
| 540 ASSERT_TRUE(http_data.at_write_eof()); |
| 541 |
| 542 // Now run the second request in which the QUIC socket hangs, |
| 543 // and verify the the transaction continues over HTTP. |
| 544 http_data2.StopAfter(arraysize(http_reads) + arraysize(http_writes)); |
| 545 SendRequestAndExpectHttpResponse("hello world"); |
| 546 |
| 547 ASSERT_TRUE(http_data2.at_read_eof()); |
| 548 ASSERT_TRUE(http_data2.at_write_eof()); |
| 549 ASSERT_TRUE(!quic_data.at_read_eof()); |
| 550 ASSERT_TRUE(!quic_data.at_write_eof()); |
| 551 } |
| 552 |
| 490 TEST_F(QuicNetworkTransactionTest, DontUseAlternateProtocolForQuicHttps) { | 553 TEST_F(QuicNetworkTransactionTest, DontUseAlternateProtocolForQuicHttps) { |
| 491 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. | 554 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
| 492 | 555 |
| 493 MockRead http_reads[] = { | 556 MockRead http_reads[] = { |
| 494 MockRead("HTTP/1.1 200 OK\r\n"), | 557 MockRead("HTTP/1.1 200 OK\r\n"), |
| 495 MockRead("Content-length: 11\r\n"), | 558 MockRead("Content-length: 11\r\n"), |
| 496 MockRead(kQuicAlternateProtocolHttpHeader), | 559 MockRead(kQuicAlternateProtocolHttpHeader), |
| 497 MockRead("hello world"), | 560 MockRead("hello world"), |
| 498 | 561 |
| 499 MockRead("HTTP/1.1 200 OK\r\n"), | 562 MockRead("HTTP/1.1 200 OK\r\n"), |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 | 666 |
| 604 CreateSession(); | 667 CreateSession(); |
| 605 | 668 |
| 606 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 669 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
| 607 SendRequestAndExpectHttpResponse("hello from http"); | 670 SendRequestAndExpectHttpResponse("hello from http"); |
| 608 ExpectBrokenAlternateProtocolMapping(); | 671 ExpectBrokenAlternateProtocolMapping(); |
| 609 } | 672 } |
| 610 | 673 |
| 611 } // namespace test | 674 } // namespace test |
| 612 } // namespace net | 675 } // namespace net |
| OLD | NEW |