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 28 matching lines...) Expand all Loading... |
39 #include "net/ssl/ssl_config_service_defaults.h" | 39 #include "net/ssl/ssl_config_service_defaults.h" |
40 #include "testing/gtest/include/gtest/gtest.h" | 40 #include "testing/gtest/include/gtest/gtest.h" |
41 #include "testing/platform_test.h" | 41 #include "testing/platform_test.h" |
42 | 42 |
43 //----------------------------------------------------------------------------- | 43 //----------------------------------------------------------------------------- |
44 | 44 |
45 namespace { | 45 namespace { |
46 | 46 |
47 // This is the expected return from a current server advertising QUIC. | 47 // This is the expected return from a current server advertising QUIC. |
48 static const char kQuicAlternateProtocolHttpHeader[] = | 48 static const char kQuicAlternateProtocolHttpHeader[] = |
49 "Alternate-Protocol: 443:quic\r\n\r\n"; | 49 "Alternate-Protocol: 80:quic\r\n\r\n"; |
50 | |
51 // Returns a vector of NPN protocol strings for negotiating QUIC. | |
52 std::vector<std::string> QuicNextProtos() { | |
53 std::vector<std::string> protos; | |
54 protos.push_back("http/1.1"); | |
55 protos.push_back("quic"); | |
56 return protos; | |
57 } | |
58 | 50 |
59 } // namespace | 51 } // namespace |
60 | 52 |
61 namespace net { | 53 namespace net { |
62 namespace test { | 54 namespace test { |
63 | 55 |
64 class QuicNetworkTransactionTest : public PlatformTest { | 56 class QuicNetworkTransactionTest : public PlatformTest { |
65 protected: | 57 protected: |
66 QuicNetworkTransactionTest() | 58 QuicNetworkTransactionTest() |
67 : clock_(new MockClock), | 59 : clock_(new MockClock), |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 socket_factory_.AddSocketDataProvider(&data); | 432 socket_factory_.AddSocketDataProvider(&data); |
441 SSLSocketDataProvider ssl(ASYNC, OK); | 433 SSLSocketDataProvider ssl(ASYNC, OK); |
442 socket_factory_.AddSSLSocketDataProvider(&ssl); | 434 socket_factory_.AddSSLSocketDataProvider(&ssl); |
443 | 435 |
444 CreateSession(); | 436 CreateSession(); |
445 | 437 |
446 SendRequestAndExpectHttpResponse("hello world"); | 438 SendRequestAndExpectHttpResponse("hello world"); |
447 } | 439 } |
448 | 440 |
449 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { | 441 TEST_F(QuicNetworkTransactionTest, UseAlternateProtocolForQuic) { |
450 HttpStreamFactory::set_use_alternate_protocols(true); | 442 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
451 HttpStreamFactory::SetNextProtos(QuicNextProtos()); | |
452 | 443 |
453 MockRead http_reads[] = { | 444 MockRead http_reads[] = { |
454 MockRead("HTTP/1.1 200 OK\r\n"), | 445 MockRead("HTTP/1.1 200 OK\r\n"), |
455 MockRead(kQuicAlternateProtocolHttpHeader), | 446 MockRead(kQuicAlternateProtocolHttpHeader), |
456 MockRead("hello world"), | 447 MockRead("hello world"), |
457 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 448 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
458 MockRead(ASYNC, OK) | 449 MockRead(ASYNC, OK) |
459 }; | 450 }; |
460 | 451 |
461 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), | 452 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads), |
(...skipping 28 matching lines...) Expand all Loading... |
490 // the alternate-protocol job will "win". | 481 // the alternate-protocol job will "win". |
491 AddHangingNonAlternateProtocolSocketData(); | 482 AddHangingNonAlternateProtocolSocketData(); |
492 | 483 |
493 CreateSession(); | 484 CreateSession(); |
494 | 485 |
495 SendRequestAndExpectHttpResponse("hello world"); | 486 SendRequestAndExpectHttpResponse("hello world"); |
496 SendRequestAndExpectQuicResponse("hello!"); | 487 SendRequestAndExpectQuicResponse("hello!"); |
497 } | 488 } |
498 | 489 |
499 TEST_F(QuicNetworkTransactionTest, DontUseAlternateProtocolForQuicHttps) { | 490 TEST_F(QuicNetworkTransactionTest, DontUseAlternateProtocolForQuicHttps) { |
500 HttpStreamFactory::set_use_alternate_protocols(true); | 491 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
501 HttpStreamFactory::SetNextProtos(QuicNextProtos()); | |
502 | 492 |
503 MockRead http_reads[] = { | 493 MockRead http_reads[] = { |
504 MockRead("HTTP/1.1 200 OK\r\n"), | 494 MockRead("HTTP/1.1 200 OK\r\n"), |
505 MockRead("Content-length: 11\r\n"), | 495 MockRead("Content-length: 11\r\n"), |
506 MockRead(kQuicAlternateProtocolHttpHeader), | 496 MockRead(kQuicAlternateProtocolHttpHeader), |
507 MockRead("hello world"), | 497 MockRead("hello world"), |
508 | 498 |
509 MockRead("HTTP/1.1 200 OK\r\n"), | 499 MockRead("HTTP/1.1 200 OK\r\n"), |
510 MockRead("Content-length: 6\r\n"), | 500 MockRead("Content-length: 6\r\n"), |
511 MockRead(kQuicAlternateProtocolHttpHeader), | 501 MockRead(kQuicAlternateProtocolHttpHeader), |
512 MockRead("hello!"), | 502 MockRead("hello!"), |
513 }; | 503 }; |
514 | 504 |
515 StaticSocketDataProvider data(http_reads, arraysize(http_reads), NULL, 0); | 505 StaticSocketDataProvider data(http_reads, arraysize(http_reads), NULL, 0); |
516 socket_factory_.AddSocketDataProvider(&data); | 506 socket_factory_.AddSocketDataProvider(&data); |
517 SSLSocketDataProvider ssl(ASYNC, OK); | 507 SSLSocketDataProvider ssl(ASYNC, OK); |
518 socket_factory_.AddSSLSocketDataProvider(&ssl); | 508 socket_factory_.AddSSLSocketDataProvider(&ssl); |
519 | 509 |
520 request_.url = GURL("https://www.google.com/"); | 510 request_.url = GURL("https://www.google.com/"); |
521 | 511 |
522 CreateSession(); | 512 CreateSession(); |
523 | 513 |
524 SendRequestAndExpectHttpResponse("hello world"); | 514 SendRequestAndExpectHttpResponse("hello world"); |
525 SendRequestAndExpectHttpResponse("hello!"); | 515 SendRequestAndExpectHttpResponse("hello!"); |
526 } | 516 } |
527 | 517 |
528 TEST_F(QuicNetworkTransactionTest, ZeroRTT) { | 518 TEST_F(QuicNetworkTransactionTest, ZeroRTT) { |
529 HttpStreamFactory::set_use_alternate_protocols(true); | 519 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
530 HttpStreamFactory::SetNextProtos(QuicNextProtos()); | |
531 | 520 |
532 scoped_ptr<QuicEncryptedPacket> req( | 521 scoped_ptr<QuicEncryptedPacket> req( |
533 ConstructDataPacket(1, 3, true, true, 0, GetRequestString("GET", "/"))); | 522 ConstructDataPacket(1, 3, true, true, 0, GetRequestString("GET", "/"))); |
534 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); | 523 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0)); |
535 | 524 |
536 MockWrite quic_writes[] = { | 525 MockWrite quic_writes[] = { |
537 MockWrite(SYNCHRONOUS, req->data(), req->length()), | 526 MockWrite(SYNCHRONOUS, req->data(), req->length()), |
538 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), | 527 MockWrite(SYNCHRONOUS, ack->data(), ack->length()), |
539 }; | 528 }; |
540 | 529 |
(...skipping 11 matching lines...) Expand all Loading... |
552 quic_writes, arraysize(quic_writes)); | 541 quic_writes, arraysize(quic_writes)); |
553 | 542 |
554 socket_factory_.AddSocketDataProvider(&quic_data); | 543 socket_factory_.AddSocketDataProvider(&quic_data); |
555 | 544 |
556 CreateSession(); | 545 CreateSession(); |
557 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 546 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
558 SendRequestAndExpectQuicResponse("hello!"); | 547 SendRequestAndExpectQuicResponse("hello!"); |
559 } | 548 } |
560 | 549 |
561 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { | 550 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { |
562 HttpStreamFactory::set_use_alternate_protocols(true); | 551 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
563 HttpStreamFactory::SetNextProtos(QuicNextProtos()); | |
564 | 552 |
565 // Alternate-protocol job | 553 // Alternate-protocol job |
566 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); | 554 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); |
567 MockRead quic_reads[] = { | 555 MockRead quic_reads[] = { |
568 MockRead(ASYNC, close->data(), close->length()), | 556 MockRead(ASYNC, close->data(), close->length()), |
569 MockRead(ASYNC, OK), // EOF | 557 MockRead(ASYNC, OK), // EOF |
570 }; | 558 }; |
571 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 559 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
572 NULL, 0); | 560 NULL, 0); |
573 socket_factory_.AddSocketDataProvider(&quic_data); | 561 socket_factory_.AddSocketDataProvider(&quic_data); |
(...skipping 10 matching lines...) Expand all Loading... |
584 NULL, 0); | 572 NULL, 0); |
585 socket_factory_.AddSocketDataProvider(&http_data); | 573 socket_factory_.AddSocketDataProvider(&http_data); |
586 | 574 |
587 CreateSession(); | 575 CreateSession(); |
588 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 576 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
589 SendRequestAndExpectHttpResponse("hello from http"); | 577 SendRequestAndExpectHttpResponse("hello from http"); |
590 ExpectBrokenAlternateProtocolMapping(); | 578 ExpectBrokenAlternateProtocolMapping(); |
591 } | 579 } |
592 | 580 |
593 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { | 581 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocolReadError) { |
594 HttpStreamFactory::set_use_alternate_protocols(true); | 582 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. |
595 HttpStreamFactory::SetNextProtos(QuicNextProtos()); | |
596 | 583 |
597 // Alternate-protocol job | 584 // Alternate-protocol job |
598 MockRead quic_reads[] = { | 585 MockRead quic_reads[] = { |
599 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), | 586 MockRead(ASYNC, ERR_SOCKET_NOT_CONNECTED), |
600 }; | 587 }; |
601 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), | 588 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), |
602 NULL, 0); | 589 NULL, 0); |
603 socket_factory_.AddSocketDataProvider(&quic_data); | 590 socket_factory_.AddSocketDataProvider(&quic_data); |
604 | 591 |
605 // Main job which will succeed even though the alternate job fails. | 592 // Main job which will succeed even though the alternate job fails. |
(...skipping 10 matching lines...) Expand all Loading... |
616 | 603 |
617 CreateSession(); | 604 CreateSession(); |
618 | 605 |
619 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); | 606 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); |
620 SendRequestAndExpectHttpResponse("hello from http"); | 607 SendRequestAndExpectHttpResponse("hello from http"); |
621 ExpectBrokenAlternateProtocolMapping(); | 608 ExpectBrokenAlternateProtocolMapping(); |
622 } | 609 } |
623 | 610 |
624 } // namespace test | 611 } // namespace test |
625 } // namespace net | 612 } // namespace net |
OLD | NEW |