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

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: Added test 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 HostResolver::RequestInfo info(HostPortPair("www.google.com", 80)); 681 HostResolver::RequestInfo info(HostPortPair("www.google.com", 80));
681 AddressList address; 682 AddressList address;
682 host_resolver_.Resolve(info, &address, CompletionCallback(), NULL, 683 host_resolver_.Resolve(info, &address, CompletionCallback(), NULL,
683 net_log_.bound()); 684 net_log_.bound());
684 685
685 CreateSession(); 686 CreateSession();
686 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 687 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
687 SendRequestAndExpectQuicResponse("hello!"); 688 SendRequestAndExpectQuicResponse("hello!");
688 } 689 }
689 690
691 TEST_F(QuicNetworkTransactionTest, ZeroRTTWithConfirmationRequired) {
692 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too.
693
694 scoped_ptr<QuicEncryptedPacket> req(
695 ConstructDataPacket(1, 3, true, true, 0,
696 GetRequestString("GET", "http", "/")));
697 scoped_ptr<QuicEncryptedPacket> ack(ConstructAckPacket(1, 0));
698
699 MockWrite quic_writes[] = {
700 MockWrite(SYNCHRONOUS, req->data(), req->length()),
701 MockWrite(SYNCHRONOUS, ack->data(), ack->length()),
702 };
703
704 scoped_ptr<QuicEncryptedPacket> resp(
705 ConstructDataPacket(
706 1, 3, false, true, 0, GetResponseString("200 OK", "hello!")));
707 MockRead quic_reads[] = {
708 MockRead(SYNCHRONOUS, resp->data(), resp->length()),
709 MockRead(ASYNC, OK), // EOF
710 };
711
712 DelayedSocketData quic_data(
713 1, // wait for one write to finish before reading.
714 quic_reads, arraysize(quic_reads),
715 quic_writes, arraysize(quic_writes));
716
717 socket_factory_.AddSocketDataProvider(&quic_data);
718
719 // The non-alternate protocol job needs to hang in order to guarantee that
720 // the alternate-protocol job will "win".
721 AddHangingNonAlternateProtocolSocketData();
722
723 // In order for a new QUIC session to be established via alternate-protocol
724 // without racing an HTTP connection, we need the host resolution to happen
725 // synchronously. Of course, even though QUIC *could* perform a 0-RTT
726 // connecto the the server, in this test we require confirmation
ramant (doing other things) 2013/08/19 18:39:05 nit: connecto the -> connection to
Ryan Hamilton 2013/08/19 18:51:18 Done.
727 // before encrypting so the HTTP job will still start.
728 host_resolver_.set_synchronous_mode(true);
729 host_resolver_.rules()->AddIPLiteralRule("www.google.com", "192.168.0.1", "");
730 HostResolver::RequestInfo info(HostPortPair("www.google.com", 80));
731 AddressList address;
732 host_resolver_.Resolve(info, &address, CompletionCallback(), NULL,
733 net_log_.bound());
734
735 CreateSession();
736 session_->quic_stream_factory()->set_require_confirmation(true);
737 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
738
739 scoped_ptr<HttpNetworkTransaction> trans(
740 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
741 TestCompletionCallback callback;
742 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
743 EXPECT_EQ(ERR_IO_PENDING, rv);
744
745 crypto_client_stream_factory_.last_stream()->SendOnCryptoHandshakeEvent(
746 QuicSession::HANDSHAKE_CONFIRMED);
747 EXPECT_EQ(OK, callback.WaitForResult());
748 }
749
690 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) { 750 TEST_F(QuicNetworkTransactionTest, BrokenAlternateProtocol) {
691 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too. 751 HttpStreamFactory::EnableNpnSpdy(); // Enables QUIC too.
692 752
693 // Alternate-protocol job 753 // Alternate-protocol job
694 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1)); 754 scoped_ptr<QuicEncryptedPacket> close(ConstructConnectionClosePacket(1));
695 MockRead quic_reads[] = { 755 MockRead quic_reads[] = {
696 MockRead(ASYNC, close->data(), close->length()), 756 MockRead(ASYNC, close->data(), close->length()),
697 MockRead(ASYNC, OK), // EOF 757 MockRead(ASYNC, OK), // EOF
698 }; 758 };
699 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads), 759 StaticSocketDataProvider quic_data(quic_reads, arraysize(quic_reads),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
743 803
744 CreateSession(); 804 CreateSession();
745 805
746 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START); 806 AddQuicAlternateProtocolMapping(MockCryptoClientStream::COLD_START);
747 SendRequestAndExpectHttpResponse("hello from http"); 807 SendRequestAndExpectHttpResponse("hello from http");
748 ExpectBrokenAlternateProtocolMapping(); 808 ExpectBrokenAlternateProtocolMapping();
749 } 809 }
750 810
751 } // namespace test 811 } // namespace test
752 } // namespace net 812 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698