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

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

Issue 339663010: Add a probability to Alternate-Protocol support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: eliminate static initializer Created 6 years, 5 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
« no previous file with comments | « net/http/http_stream_factory_impl_unittest.cc ('k') | net/quic/quic_stream_factory.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <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
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";
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
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
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 params_.alternate_protocol_probability_threshold = .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
547 params_.alternate_protocol_probability_threshold = .75;
548 CreateSessionWithNextProtos();
549
550 SendRequestAndExpectHttpResponse("hello world");
551 SendRequestAndExpectHttpResponse("hello world");
552 }
553
554 TEST_P(QuicNetworkTransactionTest,
555 DontUseAlternateProtocolWithBadProbabilityForQuic) {
556 MockRead http_reads[] = {
557 MockRead("HTTP/1.1 200 OK\r\n"),
558 MockRead("Alternate-Protocol: 443:quic,p=2\r\n\r\n"),
559 MockRead("hello world"),
560 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
561 MockRead(ASYNC, OK)
562 };
563
564 StaticSocketDataProvider http_data(http_reads, arraysize(http_reads),
565 NULL, 0);
566 socket_factory_.AddSocketDataProvider(&http_data);
567 socket_factory_.AddSocketDataProvider(&http_data);
568
569 params_.alternate_protocol_probability_threshold = .75;
570 CreateSessionWithNextProtos();
571
572 SendRequestAndExpectHttpResponse("hello world");
573 SendRequestAndExpectHttpResponse("hello world");
574 }
575
493 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) { 576 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolForQuicForHttps) {
494 params_.origin_to_force_quic_on = 577 params_.origin_to_force_quic_on =
495 HostPortPair::FromString("www.google.com:443"); 578 HostPortPair::FromString("www.google.com:443");
496 579
497 MockRead http_reads[] = { 580 MockRead http_reads[] = {
498 MockRead("HTTP/1.1 200 OK\r\n"), 581 MockRead("HTTP/1.1 200 OK\r\n"),
499 MockRead(kQuicAlternateProtocolHttpsHeader), 582 MockRead(kQuicAlternateProtocolHttpsHeader),
500 MockRead("hello world"), 583 MockRead("hello world"),
501 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), 584 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ),
502 MockRead(ASYNC, OK) 585 MockRead(ASYNC, OK)
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
949 NULL, 1032 NULL,
950 net_log_.bound()); 1033 net_log_.bound());
951 1034
952 CreateSessionWithNextProtos(); 1035 CreateSessionWithNextProtos();
953 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 1036 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
954 SendRequestAndExpectHttpResponse("hello world"); 1037 SendRequestAndExpectHttpResponse("hello world");
955 } 1038 }
956 1039
957 } // namespace test 1040 } // namespace test
958 } // namespace net 1041 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_stream_factory_impl_unittest.cc ('k') | net/quic/quic_stream_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698