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 <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 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 } | 95 } |
96 | 96 |
97 private: | 97 private: |
98 std::vector<QuicEncryptedPacket*> packets_; | 98 std::vector<QuicEncryptedPacket*> packets_; |
99 std::vector<MockWrite> writes_; | 99 std::vector<MockWrite> writes_; |
100 std::vector<MockRead> reads_; | 100 std::vector<MockRead> reads_; |
101 size_t sequence_number_; | 101 size_t sequence_number_; |
102 scoped_ptr<SocketDataProvider> socket_data_; | 102 scoped_ptr<SocketDataProvider> socket_data_; |
103 }; | 103 }; |
104 | 104 |
105 class ProxyHeadersHandler { | |
106 public: | |
107 ProxyHeadersHandler() : was_called_(false) {} | |
108 | |
109 bool WasCalled() { return was_called_; } | |
Ryan Hamilton
2015/02/05 18:43:12
nit: according to the style guide, this should be
tbansal1
2015/02/05 20:11:55
Done.
| |
110 | |
111 void OnBeforeProxyHeadersSent(const ProxyInfo& proxy_info, | |
112 HttpRequestHeaders* request_headers) { | |
113 was_called_ = true; | |
114 } | |
115 | |
116 private: | |
117 bool was_called_; | |
118 }; | |
119 | |
105 class QuicNetworkTransactionTest | 120 class QuicNetworkTransactionTest |
106 : public PlatformTest, | 121 : public PlatformTest, |
107 public ::testing::WithParamInterface<QuicVersion> { | 122 public ::testing::WithParamInterface<QuicVersion> { |
108 protected: | 123 protected: |
109 QuicNetworkTransactionTest() | 124 QuicNetworkTransactionTest() |
110 : clock_(new MockClock), | 125 : clock_(new MockClock), |
111 maker_(GetParam(), 0, clock_), | 126 maker_(GetParam(), 0, clock_), |
112 ssl_config_service_(new SSLConfigServiceDefaults), | 127 ssl_config_service_(new SSLConfigServiceDefaults), |
113 proxy_service_(ProxyService::CreateDirect()), | 128 proxy_service_(ProxyService::CreateDirect()), |
114 auth_handler_factory_( | 129 auth_handler_factory_( |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
261 } | 276 } |
262 | 277 |
263 void SendRequestAndExpectHttpResponse(const std::string& expected) { | 278 void SendRequestAndExpectHttpResponse(const std::string& expected) { |
264 scoped_ptr<HttpNetworkTransaction> trans( | 279 scoped_ptr<HttpNetworkTransaction> trans( |
265 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 280 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
266 RunTransaction(trans.get()); | 281 RunTransaction(trans.get()); |
267 CheckWasHttpResponse(trans); | 282 CheckWasHttpResponse(trans); |
268 CheckResponseData(trans.get(), expected); | 283 CheckResponseData(trans.get(), expected); |
269 } | 284 } |
270 | 285 |
271 void SendRequestAndExpectQuicResponse(const std::string& expected) { | 286 void SendRequestAndExpectQuicResponse(const std::string& expected, |
287 bool expect_headers_callback) { | |
Ryan Hamilton
2015/02/05 18:43:12
nit: I think this parameter should be named someth
tbansal1
2015/02/05 20:11:55
Done.
| |
272 scoped_ptr<HttpNetworkTransaction> trans( | 288 scoped_ptr<HttpNetworkTransaction> trans( |
273 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 289 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
290 ProxyHeadersHandler proxy_headers_handler; | |
291 trans->SetBeforeProxyHeadersSentCallback( | |
292 base::Bind(&ProxyHeadersHandler::OnBeforeProxyHeadersSent, | |
293 base::Unretained(&proxy_headers_handler))); | |
274 RunTransaction(trans.get()); | 294 RunTransaction(trans.get()); |
275 CheckWasQuicResponse(trans); | 295 CheckWasQuicResponse(trans); |
276 CheckResponseData(trans.get(), expected); | 296 CheckResponseData(trans.get(), expected); |
297 EXPECT_TRUE(!expect_headers_callback || proxy_headers_handler.WasCalled()); | |
277 } | 298 } |
278 | 299 |
279 void AddQuicAlternateProtocolMapping( | 300 void AddQuicAlternateProtocolMapping( |
280 MockCryptoClientStream::HandshakeMode handshake_mode) { | 301 MockCryptoClientStream::HandshakeMode handshake_mode) { |
281 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); | 302 crypto_client_stream_factory_.set_handshake_mode(handshake_mode); |
282 session_->http_server_properties()->SetAlternateProtocol( | 303 session_->http_server_properties()->SetAlternateProtocol( |
283 HostPortPair::FromURL(request_.url), 80, QUIC, 1); | 304 HostPortPair::FromURL(request_.url), 80, QUIC, 1); |
284 } | 305 } |
285 | 306 |
286 void ExpectBrokenAlternateProtocolMapping() { | 307 void ExpectBrokenAlternateProtocolMapping() { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
346 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF | 367 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
347 | 368 |
348 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); | 369 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
349 | 370 |
350 // The non-alternate protocol job needs to hang in order to guarantee that | 371 // The non-alternate protocol job needs to hang in order to guarantee that |
351 // the alternate-protocol job will "win". | 372 // the alternate-protocol job will "win". |
352 AddHangingNonAlternateProtocolSocketData(); | 373 AddHangingNonAlternateProtocolSocketData(); |
353 | 374 |
354 CreateSession(); | 375 CreateSession(); |
355 | 376 |
356 SendRequestAndExpectQuicResponse("hello!"); | 377 SendRequestAndExpectQuicResponse("hello!", false); |
357 | 378 |
358 // Check that the NetLog was filled reasonably. | 379 // Check that the NetLog was filled reasonably. |
359 net::CapturingNetLog::CapturedEntryList entries; | 380 net::CapturingNetLog::CapturedEntryList entries; |
360 net_log_.GetEntries(&entries); | 381 net_log_.GetEntries(&entries); |
361 EXPECT_LT(0u, entries.size()); | 382 EXPECT_LT(0u, entries.size()); |
362 | 383 |
363 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. | 384 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
364 int pos = net::ExpectLogContainsSomewhere( | 385 int pos = net::ExpectLogContainsSomewhere( |
365 entries, 0, | 386 entries, 0, |
366 net::NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, | 387 net::NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 428 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
408 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF | 429 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
409 | 430 |
410 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); | 431 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
411 | 432 |
412 // There is no need to set up an alternate protocol job, because | 433 // There is no need to set up an alternate protocol job, because |
413 // no attempt will be made to speak to the proxy over TCP. | 434 // no attempt will be made to speak to the proxy over TCP. |
414 | 435 |
415 CreateSession(); | 436 CreateSession(); |
416 | 437 |
417 SendRequestAndExpectQuicResponse("hello!"); | 438 SendRequestAndExpectQuicResponse("hello!", true); |
Ryan Hamilton
2015/02/05 18:43:12
It's not obvious here what true and false refer to
tbansal1
2015/02/05 20:11:55
Done.
| |
418 } | 439 } |
419 | 440 |
420 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { | 441 TEST_P(QuicNetworkTransactionTest, ForceQuicWithErrorConnecting) { |
421 params_.origin_to_force_quic_on = | 442 params_.origin_to_force_quic_on = |
422 HostPortPair::FromString("www.google.com:80"); | 443 HostPortPair::FromString("www.google.com:80"); |
423 | 444 |
424 MockQuicData mock_quic_data; | 445 MockQuicData mock_quic_data; |
425 mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); | 446 mock_quic_data.AddRead(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
426 | 447 |
427 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 0); | 448 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 0); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
485 | 506 |
486 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); | 507 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
487 | 508 |
488 // The non-alternate protocol job needs to hang in order to guarantee that | 509 // The non-alternate protocol job needs to hang in order to guarantee that |
489 // the alternate-protocol job will "win". | 510 // the alternate-protocol job will "win". |
490 AddHangingNonAlternateProtocolSocketData(); | 511 AddHangingNonAlternateProtocolSocketData(); |
491 | 512 |
492 CreateSessionWithNextProtos(); | 513 CreateSessionWithNextProtos(); |
493 | 514 |
494 SendRequestAndExpectHttpResponse("hello world"); | 515 SendRequestAndExpectHttpResponse("hello world"); |
495 SendRequestAndExpectQuicResponse("hello!"); | 516 SendRequestAndExpectQuicResponse("hello!", false); |
496 } | 517 } |
497 | 518 |
498 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { | 519 TEST_P(QuicNetworkTransactionTest, UseAlternateProtocolProbabilityForQuic) { |
499 MockRead http_reads[] = { | 520 MockRead http_reads[] = { |
500 MockRead("HTTP/1.1 200 OK\r\n"), | 521 MockRead("HTTP/1.1 200 OK\r\n"), |
501 MockRead(kQuicAlternateProtocol50pctHttpHeader), | 522 MockRead(kQuicAlternateProtocol50pctHttpHeader), |
502 MockRead("hello world"), | 523 MockRead("hello world"), |
503 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 524 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
504 MockRead(ASYNC, OK) | 525 MockRead(ASYNC, OK) |
505 }; | 526 }; |
(...skipping 17 matching lines...) Expand all Loading... | |
523 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); | 544 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
524 | 545 |
525 // The non-alternate protocol job needs to hang in order to guarantee that | 546 // The non-alternate protocol job needs to hang in order to guarantee that |
526 // the alternate-protocol job will "win". | 547 // the alternate-protocol job will "win". |
527 AddHangingNonAlternateProtocolSocketData(); | 548 AddHangingNonAlternateProtocolSocketData(); |
528 | 549 |
529 params_.alternate_protocol_probability_threshold = .25; | 550 params_.alternate_protocol_probability_threshold = .25; |
530 CreateSessionWithNextProtos(); | 551 CreateSessionWithNextProtos(); |
531 | 552 |
532 SendRequestAndExpectHttpResponse("hello world"); | 553 SendRequestAndExpectHttpResponse("hello world"); |
533 SendRequestAndExpectQuicResponse("hello!"); | 554 SendRequestAndExpectQuicResponse("hello!", false); |
534 } | 555 } |
535 | 556 |
536 TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { | 557 TEST_P(QuicNetworkTransactionTest, DontUseAlternateProtocolProbabilityForQuic) { |
537 MockRead http_reads[] = { | 558 MockRead http_reads[] = { |
538 MockRead("HTTP/1.1 200 OK\r\n"), | 559 MockRead("HTTP/1.1 200 OK\r\n"), |
539 MockRead(kQuicAlternateProtocol50pctHttpHeader), | 560 MockRead(kQuicAlternateProtocol50pctHttpHeader), |
540 MockRead("hello world"), | 561 MockRead("hello world"), |
541 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), | 562 MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
542 MockRead(ASYNC, OK) | 563 MockRead(ASYNC, OK) |
543 }; | 564 }; |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
688 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF | 709 mock_quic_data.AddRead(SYNCHRONOUS, 0); // EOF |
689 | 710 |
690 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); | 711 mock_quic_data.AddDelayedSocketDataToFactory(&socket_factory_, 1); |
691 | 712 |
692 // The non-alternate protocol job needs to hang in order to guarantee that | 713 // The non-alternate protocol job needs to hang in order to guarantee that |
693 // the alternate-protocol job will "win". | 714 // the alternate-protocol job will "win". |
694 AddHangingNonAlternateProtocolSocketData(); | 715 AddHangingNonAlternateProtocolSocketData(); |
695 | 716 |
696 CreateSessionWithNextProtos(); | 717 CreateSessionWithNextProtos(); |
697 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 718 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
698 SendRequestAndExpectQuicResponse("hello!"); | 719 SendRequestAndExpectQuicResponse("hello!", false); |
699 } | 720 } |
700 | 721 |
701 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { | 722 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithNoHttpRace) { |
702 MockQuicData mock_quic_data; | 723 MockQuicData mock_quic_data; |
703 mock_quic_data.AddWrite( | 724 mock_quic_data.AddWrite( |
704 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, | 725 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
705 GetRequestHeaders("GET", "http", "/"))); | 726 GetRequestHeaders("GET", "http", "/"))); |
706 mock_quic_data.AddRead( | 727 mock_quic_data.AddRead( |
707 ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, | 728 ConstructResponseHeadersPacket(1, kClientDataStreamId1, false, false, |
708 GetResponseHeaders("200 OK"))); | 729 GetResponseHeaders("200 OK"))); |
(...skipping 12 matching lines...) Expand all Loading... | |
721 AddressList address; | 742 AddressList address; |
722 host_resolver_.Resolve(info, | 743 host_resolver_.Resolve(info, |
723 DEFAULT_PRIORITY, | 744 DEFAULT_PRIORITY, |
724 &address, | 745 &address, |
725 CompletionCallback(), | 746 CompletionCallback(), |
726 nullptr, | 747 nullptr, |
727 net_log_.bound()); | 748 net_log_.bound()); |
728 | 749 |
729 CreateSessionWithNextProtos(); | 750 CreateSessionWithNextProtos(); |
730 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 751 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
731 SendRequestAndExpectQuicResponse("hello!"); | 752 SendRequestAndExpectQuicResponse("hello!", false); |
732 } | 753 } |
733 | 754 |
734 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { | 755 TEST_P(QuicNetworkTransactionTest, ZeroRTTWithProxy) { |
735 proxy_service_.reset( | 756 proxy_service_.reset( |
736 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); | 757 ProxyService::CreateFixedFromPacResult("PROXY myproxy:70")); |
737 | 758 |
738 // Since we are using a proxy, the QUIC job will not succeed. | 759 // Since we are using a proxy, the QUIC job will not succeed. |
739 MockWrite http_writes[] = { | 760 MockWrite http_writes[] = { |
740 MockWrite(SYNCHRONOUS, 0, "GET http://www.google.com/ HTTP/1.1\r\n"), | 761 MockWrite(SYNCHRONOUS, 0, "GET http://www.google.com/ HTTP/1.1\r\n"), |
741 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), | 762 MockWrite(SYNCHRONOUS, 1, "Host: www.google.com\r\n"), |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1035 nullptr, | 1056 nullptr, |
1036 net_log_.bound()); | 1057 net_log_.bound()); |
1037 | 1058 |
1038 CreateSessionWithNextProtos(); | 1059 CreateSessionWithNextProtos(); |
1039 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 1060 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
1040 SendRequestAndExpectHttpResponse("hello world"); | 1061 SendRequestAndExpectHttpResponse("hello world"); |
1041 } | 1062 } |
1042 | 1063 |
1043 } // namespace test | 1064 } // namespace test |
1044 } // namespace net | 1065 } // namespace net |
OLD | NEW |