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 <stddef.h> |
| 6 #include <stdint.h> |
| 7 |
5 #include <vector> | 8 #include <vector> |
6 | 9 |
7 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
8 #include "base/macros.h" | 11 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
10 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
11 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
12 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/time/time.h" |
13 #include "net/base/chunked_upload_data_stream.h" | 17 #include "net/base/chunked_upload_data_stream.h" |
14 #include "net/base/network_quality_estimator.h" | 18 #include "net/base/network_quality_estimator.h" |
15 #include "net/base/socket_performance_watcher.h" | 19 #include "net/base/socket_performance_watcher.h" |
16 #include "net/base/test_completion_callback.h" | 20 #include "net/base/test_completion_callback.h" |
17 #include "net/base/test_data_directory.h" | 21 #include "net/base/test_data_directory.h" |
18 #include "net/cert/mock_cert_verifier.h" | 22 #include "net/cert/mock_cert_verifier.h" |
19 #include "net/cert/multi_log_ct_verifier.h" | 23 #include "net/cert/multi_log_ct_verifier.h" |
20 #include "net/dns/mock_host_resolver.h" | 24 #include "net/dns/mock_host_resolver.h" |
21 #include "net/http/http_auth_handler_factory.h" | 25 #include "net/http/http_auth_handler_factory.h" |
22 #include "net/http/http_network_session.h" | 26 #include "net/http/http_network_session.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 int32_t rtt_ms, | 179 int32_t rtt_ms, |
176 const base::TimeTicks& timestamp, | 180 const base::TimeTicks& timestamp, |
177 net::NetworkQualityEstimator::ObservationSource source) override { | 181 net::NetworkQualityEstimator::ObservationSource source) override { |
178 rtt_notification_received_ = true; | 182 rtt_notification_received_ = true; |
179 } | 183 } |
180 | 184 |
181 private: | 185 private: |
182 bool rtt_notification_received_; | 186 bool rtt_notification_received_; |
183 }; | 187 }; |
184 | 188 |
| 189 class TestPacketLossObserver |
| 190 : public NetworkQualityEstimator::PacketLossObserver { |
| 191 public: |
| 192 TestPacketLossObserver() : notification_received_(false) {} |
| 193 |
| 194 bool notification_received() const { return notification_received_; } |
| 195 |
| 196 // NetworkQualityEstimator::PacketLossObserver implementation: |
| 197 void OnPacketLossObservation( |
| 198 size_t packets_lost, |
| 199 size_t packets_received_in_order, |
| 200 size_t packets_received_out_of_order, |
| 201 const base::TimeTicks& timestamp, |
| 202 net::NetworkQualityEstimator::ObservationSource source) override { |
| 203 if (source != NetworkQualityEstimator::QUIC) { |
| 204 NOTIMPLEMENTED(); |
| 205 } |
| 206 notification_received_ = true; |
| 207 } |
| 208 |
| 209 private: |
| 210 bool notification_received_; |
| 211 }; |
| 212 |
185 class QuicNetworkTransactionTest | 213 class QuicNetworkTransactionTest |
186 : public PlatformTest, | 214 : public PlatformTest, |
187 public ::testing::WithParamInterface<QuicVersion> { | 215 public ::testing::WithParamInterface<QuicVersion> { |
188 protected: | 216 protected: |
189 QuicNetworkTransactionTest() | 217 QuicNetworkTransactionTest() |
190 : clock_(new MockClock), | 218 : clock_(new MockClock), |
191 maker_(GetParam(), 0, clock_, kDefaultServerHostName), | 219 maker_(GetParam(), 0, clock_, kDefaultServerHostName), |
192 cert_transparency_verifier_(new MultiLogCTVerifier()), | 220 cert_transparency_verifier_(new MultiLogCTVerifier()), |
193 test_network_quality_estimator_(new TestNetworkQualityEstimator()), | 221 test_network_quality_estimator_(new TestNetworkQualityEstimator()), |
194 ssl_config_service_(new SSLConfigServiceDefaults), | 222 ssl_config_service_(new SSLConfigServiceDefaults), |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 params_.http_server_properties = http_server_properties_.GetWeakPtr(); | 458 params_.http_server_properties = http_server_properties_.GetWeakPtr(); |
431 params_.quic_supported_versions = SupportedVersions(GetParam()); | 459 params_.quic_supported_versions = SupportedVersions(GetParam()); |
432 for (const char* host : | 460 for (const char* host : |
433 {kDefaultServerHostName, "www.example.org", "news.example.org", | 461 {kDefaultServerHostName, "www.example.org", "news.example.org", |
434 "bar.example.org", "foo.example.org", "invalid.example.org", | 462 "bar.example.org", "foo.example.org", "invalid.example.org", |
435 "mail.example.com"}) { | 463 "mail.example.com"}) { |
436 params_.quic_host_whitelist.insert(host); | 464 params_.quic_host_whitelist.insert(host); |
437 } | 465 } |
438 | 466 |
439 test_network_quality_estimator_->AddRTTObserver(&rtt_observer_); | 467 test_network_quality_estimator_->AddRTTObserver(&rtt_observer_); |
| 468 test_network_quality_estimator_->AddPacketLossObserver( |
| 469 &packet_loss_observer_); |
440 | 470 |
441 session_.reset(new HttpNetworkSession(params_)); | 471 session_.reset(new HttpNetworkSession(params_)); |
442 session_->quic_stream_factory()->set_require_confirmation(false); | 472 session_->quic_stream_factory()->set_require_confirmation(false); |
443 ASSERT_EQ(params_.quic_socket_receive_buffer_size, | 473 ASSERT_EQ(params_.quic_socket_receive_buffer_size, |
444 session_->quic_stream_factory()->socket_receive_buffer_size()); | 474 session_->quic_stream_factory()->socket_receive_buffer_size()); |
445 } | 475 } |
446 | 476 |
447 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { | 477 void CheckWasQuicResponse(const scoped_ptr<HttpNetworkTransaction>& trans) { |
448 const HttpResponseInfo* response = trans->GetResponseInfo(); | 478 const HttpResponseInfo* response = trans->GetResponseInfo(); |
449 ASSERT_TRUE(response != nullptr); | 479 ASSERT_TRUE(response != nullptr); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 scoped_ptr<HttpNetworkSession> session_; | 594 scoped_ptr<HttpNetworkSession> session_; |
565 MockClientSocketFactory socket_factory_; | 595 MockClientSocketFactory socket_factory_; |
566 ProofVerifyDetailsChromium verify_details_; | 596 ProofVerifyDetailsChromium verify_details_; |
567 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 597 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
568 MockHostResolver host_resolver_; | 598 MockHostResolver host_resolver_; |
569 MockCertVerifier cert_verifier_; | 599 MockCertVerifier cert_verifier_; |
570 TransportSecurityState transport_security_state_; | 600 TransportSecurityState transport_security_state_; |
571 scoped_ptr<CTVerifier> cert_transparency_verifier_; | 601 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
572 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; | 602 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; |
573 TestRTTObserver rtt_observer_; | 603 TestRTTObserver rtt_observer_; |
| 604 TestPacketLossObserver packet_loss_observer_; |
574 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 605 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
575 scoped_ptr<ProxyService> proxy_service_; | 606 scoped_ptr<ProxyService> proxy_service_; |
576 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 607 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
577 MockRandom random_generator_; | 608 MockRandom random_generator_; |
578 HttpServerPropertiesImpl http_server_properties_; | 609 HttpServerPropertiesImpl http_server_properties_; |
579 HttpNetworkSession::Params params_; | 610 HttpNetworkSession::Params params_; |
580 HttpRequestInfo request_; | 611 HttpRequestInfo request_; |
581 BoundTestNetLog net_log_; | 612 BoundTestNetLog net_log_; |
582 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; | 613 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; |
583 SSLSocketDataProvider ssl_data_; | 614 SSLSocketDataProvider ssl_data_; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 | 655 |
625 // The non-alternate protocol job needs to hang in order to guarantee that | 656 // The non-alternate protocol job needs to hang in order to guarantee that |
626 // the alternate-protocol job will "win". | 657 // the alternate-protocol job will "win". |
627 AddHangingNonAlternateProtocolSocketData(); | 658 AddHangingNonAlternateProtocolSocketData(); |
628 | 659 |
629 params_.parse_alternative_services = false; | 660 params_.parse_alternative_services = false; |
630 params_.enable_alternative_service_with_different_host = false; | 661 params_.enable_alternative_service_with_different_host = false; |
631 CreateSession(); | 662 CreateSession(); |
632 | 663 |
633 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 664 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 665 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
634 SendRequestAndExpectQuicResponse("hello!"); | 666 SendRequestAndExpectQuicResponse("hello!"); |
635 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 667 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 668 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
636 | 669 |
637 // Check that the NetLog was filled reasonably. | 670 // Check that the NetLog was filled reasonably. |
638 TestNetLogEntry::List entries; | 671 TestNetLogEntry::List entries; |
639 net_log_.GetEntries(&entries); | 672 net_log_.GetEntries(&entries); |
640 EXPECT_LT(0u, entries.size()); | 673 EXPECT_LT(0u, entries.size()); |
641 | 674 |
642 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. | 675 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
643 int pos = ExpectLogContainsSomewhere( | 676 int pos = ExpectLogContainsSomewhere( |
644 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, | 677 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
645 NetLog::PHASE_NONE); | 678 NetLog::PHASE_NONE); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 719 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
687 mock_quic_data.AddRead( | 720 mock_quic_data.AddRead( |
688 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | 721 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
689 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 722 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
690 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | 723 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
691 mock_quic_data.AddRead(ASYNC, 0); // EOF | 724 mock_quic_data.AddRead(ASYNC, 0); // EOF |
692 | 725 |
693 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 726 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
694 | 727 |
695 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 728 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 729 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
696 // There is no need to set up an alternate protocol job, because | 730 // There is no need to set up an alternate protocol job, because |
697 // no attempt will be made to speak to the proxy over TCP. | 731 // no attempt will be made to speak to the proxy over TCP. |
698 | 732 |
699 request_.url = GURL("http://mail.example.org/"); | 733 request_.url = GURL("http://mail.example.org/"); |
700 params_.parse_alternative_services = false; | 734 params_.parse_alternative_services = false; |
701 params_.enable_alternative_service_with_different_host = false; | 735 params_.enable_alternative_service_with_different_host = false; |
702 CreateSession(); | 736 CreateSession(); |
703 | 737 |
704 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); | 738 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
705 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 739 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 740 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
706 } | 741 } |
707 | 742 |
708 // Regression test for https://crbug.com/492458. Test that for an HTTP | 743 // Regression test for https://crbug.com/492458. Test that for an HTTP |
709 // connection through a QUIC proxy, the certificate exhibited by the proxy is | 744 // connection through a QUIC proxy, the certificate exhibited by the proxy is |
710 // checked against the proxy hostname, not the origin hostname. | 745 // checked against the proxy hostname, not the origin hostname. |
711 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { | 746 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
712 const std::string origin_host = "mail.example.com"; | 747 const std::string origin_host = "mail.example.com"; |
713 const std::string proxy_host = "www.example.org"; | 748 const std::string proxy_host = "www.example.org"; |
714 | 749 |
715 params_.enable_quic_for_proxies = true; | 750 params_.enable_quic_for_proxies = true; |
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2294 nullptr, net_log_.bound()); | 2329 nullptr, net_log_.bound()); |
2295 | 2330 |
2296 CreateSession(); | 2331 CreateSession(); |
2297 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 2332 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
2298 SendRequestAndExpectHttpResponse("hello world"); | 2333 SendRequestAndExpectHttpResponse("hello world"); |
2299 } | 2334 } |
2300 | 2335 |
2301 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { | 2336 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
2302 maker_.set_hostname("www.example.org"); | 2337 maker_.set_hostname("www.example.org"); |
2303 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 2338 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 2339 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
2304 MockQuicData mock_quic_data; | 2340 MockQuicData mock_quic_data; |
2305 mock_quic_data.AddWrite( | 2341 mock_quic_data.AddWrite( |
2306 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, | 2342 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
2307 GetRequestHeaders("GET", "https", "/"))); | 2343 GetRequestHeaders("GET", "https", "/"))); |
2308 mock_quic_data.AddRead(ConstructResponseHeadersPacket( | 2344 mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
2309 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 2345 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
2310 mock_quic_data.AddRead( | 2346 mock_quic_data.AddRead( |
2311 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | 2347 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
2312 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 2348 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
2313 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. | 2349 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
2314 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 2350 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
2315 | 2351 |
2316 request_.url = GURL("https://www.example.org:443"); | 2352 request_.url = GURL("https://www.example.org:443"); |
2317 AddHangingNonAlternateProtocolSocketData(); | 2353 AddHangingNonAlternateProtocolSocketData(); |
2318 CreateSession(); | 2354 CreateSession(); |
2319 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); | 2355 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
2320 SendRequestAndExpectQuicResponse("hello!"); | 2356 SendRequestAndExpectQuicResponse("hello!"); |
2321 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 2357 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 2358 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
2322 } | 2359 } |
2323 | 2360 |
2324 TEST_P(QuicNetworkTransactionTest, QuicUpload) { | 2361 TEST_P(QuicNetworkTransactionTest, QuicUpload) { |
2325 params_.origin_to_force_quic_on = | 2362 params_.origin_to_force_quic_on = |
2326 HostPortPair::FromString("mail.example.org:443"); | 2363 HostPortPair::FromString("mail.example.org:443"); |
2327 | 2364 |
2328 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 2365 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
2329 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; | 2366 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; |
2330 SequencedSocketData socket_data(reads, arraysize(reads), writes, | 2367 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
2331 arraysize(writes)); | 2368 arraysize(writes)); |
(...skipping 15 matching lines...) Expand all Loading... |
2347 scoped_ptr<HttpNetworkTransaction> trans( | 2384 scoped_ptr<HttpNetworkTransaction> trans( |
2348 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 2385 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
2349 TestCompletionCallback callback; | 2386 TestCompletionCallback callback; |
2350 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 2387 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
2351 EXPECT_EQ(ERR_IO_PENDING, rv); | 2388 EXPECT_EQ(ERR_IO_PENDING, rv); |
2352 EXPECT_NE(OK, callback.WaitForResult()); | 2389 EXPECT_NE(OK, callback.WaitForResult()); |
2353 } | 2390 } |
2354 | 2391 |
2355 } // namespace test | 2392 } // namespace test |
2356 } // namespace net | 2393 } // namespace net |
OLD | NEW |