Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(602)

Side by Side Diff: net/quic/quic_network_transaction_unittest.cc

Issue 23279011: Require handshake confirmation until a QUIC connection is created succesfully when using a new netw… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_; 225 params_.quic_crypto_client_stream_factory = &crypto_client_stream_factory_;
226 params_.host_resolver = &host_resolver_; 226 params_.host_resolver = &host_resolver_;
227 params_.cert_verifier = &cert_verifier_; 227 params_.cert_verifier = &cert_verifier_;
228 params_.transport_security_state = &transport_security_state_; 228 params_.transport_security_state = &transport_security_state_;
229 params_.proxy_service = proxy_service_.get(); 229 params_.proxy_service = proxy_service_.get();
230 params_.ssl_config_service = ssl_config_service_.get(); 230 params_.ssl_config_service = ssl_config_service_.get();
231 params_.http_auth_handler_factory = auth_handler_factory_.get(); 231 params_.http_auth_handler_factory = auth_handler_factory_.get();
232 params_.http_server_properties = http_server_properties.GetWeakPtr(); 232 params_.http_server_properties = http_server_properties.GetWeakPtr();
233 233
234 session_ = new HttpNetworkSession(params_); 234 session_ = new HttpNetworkSession(params_);
235 session_->quic_stream_factory()->set_require_confirmation(false);
235 } 236 }
236 237
237 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { 238 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) {
238 const HttpResponseInfo* response = trans->GetResponseInfo(); 239 const HttpResponseInfo* response = trans->GetResponseInfo();
239 ASSERT_TRUE(response != NULL); 240 ASSERT_TRUE(response != NULL);
240 ASSERT_TRUE(response->headers.get() != NULL); 241 ASSERT_TRUE(response->headers.get() != NULL);
241 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); 242 EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine());
242 EXPECT_TRUE(response->was_fetched_via_spdy); 243 EXPECT_TRUE(response->was_fetched_via_spdy);
243 EXPECT_TRUE(response->was_npn_negotiated); 244 EXPECT_TRUE(response->was_npn_negotiated);
244 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3, 245 EXPECT_EQ(HttpResponseInfo::CONNECTION_INFO_QUIC1_SPDY3,
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 DEFAULT_PRIORITY); 682 DEFAULT_PRIORITY);
682 AddressList address; 683 AddressList address;
683 host_resolver_.Resolve(info, &address, CompletionCallback(), NULL, 684 host_resolver_.Resolve(info, &address, CompletionCallback(), NULL,
684 net_log_.bound()); 685 net_log_.bound());
685 686
686 CreateSession(); 687 CreateSession();
687 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 688 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
688 SendRequestAndExpectQuicResponse("hello!"); 689 SendRequestAndExpectQuicResponse("hello!");
689 } 690 }
690 691
692 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) {
693 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too.
694
695 scoped_ptr<QuicEncryptedPacket> req(
696 ConstructDataPacket(1, 3, true, true, 0,
697 GetRequestString("GET", "http", "/")));
698 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0));
699
700 MockWrite quic_writes[] = {
701 MockWrite(SYNCHRONOUS, req->data(), req->length()),
702 MockWrite(SYNCHRONOUS, ack->data(), ack->length()),
703 };
704
705 scoped_ptr<QuicEncryptedPacket> resp(
706 ConstructDataPacket(
707 1, 3, false, true, 0, GetResponseString("200 OK", "hello!")));
708 MockRead quic_reads[] = {
709 MockRead(SYNCHRONOUS, resp->data(), resp->length()),
710 MockRead(ASYNC, OK), // EOF
711 };
712
713 DelayedSocketData quic_data(
714 1, // wait for one write to finish before reading.
715 quic_reads, arraysize(quic_reads),
716 quic_writes, arraysize(quic_writes));
717
718 socket_factory_.AddSocketDataProvider(&quic_data);
719
720 // The non-alternate protocol job needs to hang in order to guarantee that
721 // the alternate-protocol job will "win".
722 AddHangingNonAlternateProtocolSocketData();
723
724 // In order for a new QUIC session to be established via alternate-protocol
725 // without racing an HTTP connection, we need the host resolution to happen
726 // synchronously. Of course, even though QUIC *could* perform a 0-RTT
727 // connection to the the server, in this test we require confirmation
728 // before encrypting so the HTTP job will still start.
729 host_resolver_.set_synchronous_mode(true);
730 host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", "");
731 HostResolver::RequestInfo info(HostPortPair("www.google.com", 80),
732 DEFAULT_PRIORITY);
733 AddressList address;
734 host_resolver_.Resolve(info, &address, CompletionCallback(), NULL,
735 net_log_.bound());
736
737 CreateSession();
738 session_->quic_stream_factory()->set_require_confirmation(true);
739 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
740
741 scoped_ptr<HttpNetworkTransaction> trans(
742 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
743 TestCompletionCallback callback;
744 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
745 EXPECT_EQ(ERR_IO_PENDING, rv);
746
747 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
748 QuicSession::HANDSHAKE_CONFIRMED);
749 EXPECT_EQ(OK, callback.WaitForResult());
750 }
751
691 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { 752 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) {
692 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. 753 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too.
693 754
694 // Alternate-protocol job 755 // Alternate-protocol job
695 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); 756 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1));
696 MockRead quic_reads[] = { 757 MockRead quic_reads[] = {
697 MockRead(ASYNC, close->data(), close->length()), 758 MockRead(ASYNC, close->data(), close->length()),
698 MockRead(ASYNC, OK), // EOF 759 MockRead(ASYNC, OK), // EOF
699 }; 760 };
700 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), 761 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 TestCompletionCallback callback; 832 TestCompletionCallback callback;
772 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 833 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
773 EXPECT_EQ(ERR_IO_PENDING, rv); 834 EXPECT_EQ(ERR_IO_PENDING, rv);
774 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult()); 835 EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.WaitForResult());
775 836
776 ExpectBrokenAlternateProtocolMapping(); 837 ExpectBrokenAlternateProtocolMapping();
777 } 838 }
778 839
779 } // namespace test 840 } // namespace test
780 } // namespace net 841 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698