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 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 params_.http_server_properties = http_server_properties_.GetWeakPtr(); | 461 params_.http_server_properties = http_server_properties_.GetWeakPtr(); |
434 params_.quic_supported_versions = SupportedVersions(GetParam()); | 462 params_.quic_supported_versions = SupportedVersions(GetParam()); |
435 for (const char* host : | 463 for (const char* host : |
436 {kDefaultServerHostName, "www.example.org", "news.example.org", | 464 {kDefaultServerHostName, "www.example.org", "news.example.org", |
437 "bar.example.org", "foo.example.org", "invalid.example.org", | 465 "bar.example.org", "foo.example.org", "invalid.example.org", |
438 "mail.example.com"}) { | 466 "mail.example.com"}) { |
439 params_.quic_host_whitelist.insert(host); | 467 params_.quic_host_whitelist.insert(host); |
440 } | 468 } |
441 | 469 |
442 test_network_quality_estimator_->AddRTTObserver(&rtt_observer_); | 470 test_network_quality_estimator_->AddRTTObserver(&rtt_observer_); |
| 471 test_network_quality_estimator_->AddPacketLossObserver( |
| 472 &packet_loss_observer_); |
443 | 473 |
444 if (use_next_protos) { | 474 if (use_next_protos) { |
445 params_.parse_alternative_services = true; | 475 params_.parse_alternative_services = true; |
446 params_.enable_alternative_service_with_different_host = true; | 476 params_.enable_alternative_service_with_different_host = true; |
447 } | 477 } |
448 | 478 |
449 session_.reset(new HttpNetworkSession(params_)); | 479 session_.reset(new HttpNetworkSession(params_)); |
450 session_->quic_stream_factory()->set_require_confirmation(false); | 480 session_->quic_stream_factory()->set_require_confirmation(false); |
451 ASSERT_EQ(params_.quic_socket_receive_buffer_size, | 481 ASSERT_EQ(params_.quic_socket_receive_buffer_size, |
452 session_->quic_stream_factory()->socket_receive_buffer_size()); | 482 session_->quic_stream_factory()->socket_receive_buffer_size()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
572 scoped_ptr<HttpNetworkSession> session_; | 602 scoped_ptr<HttpNetworkSession> session_; |
573 MockClientSocketFactory socket_factory_; | 603 MockClientSocketFactory socket_factory_; |
574 ProofVerifyDetailsChromium verify_details_; | 604 ProofVerifyDetailsChromium verify_details_; |
575 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 605 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
576 MockHostResolver host_resolver_; | 606 MockHostResolver host_resolver_; |
577 MockCertVerifier cert_verifier_; | 607 MockCertVerifier cert_verifier_; |
578 TransportSecurityState transport_security_state_; | 608 TransportSecurityState transport_security_state_; |
579 scoped_ptr<CTVerifier> cert_transparency_verifier_; | 609 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
580 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; | 610 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; |
581 TestRTTObserver rtt_observer_; | 611 TestRTTObserver rtt_observer_; |
| 612 TestPacketLossObserver packet_loss_observer_; |
582 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 613 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
583 scoped_ptr<ProxyService> proxy_service_; | 614 scoped_ptr<ProxyService> proxy_service_; |
584 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 615 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
585 MockRandom random_generator_; | 616 MockRandom random_generator_; |
586 HttpServerPropertiesImpl http_server_properties_; | 617 HttpServerPropertiesImpl http_server_properties_; |
587 HttpNetworkSession::Params params_; | 618 HttpNetworkSession::Params params_; |
588 HttpRequestInfo request_; | 619 HttpRequestInfo request_; |
589 BoundTestNetLog net_log_; | 620 BoundTestNetLog net_log_; |
590 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; | 621 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; |
591 SSLSocketDataProvider ssl_data_; | 622 SSLSocketDataProvider ssl_data_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 | 661 |
631 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 662 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
632 | 663 |
633 // The non-alternate protocol job needs to hang in order to guarantee that | 664 // The non-alternate protocol job needs to hang in order to guarantee that |
634 // the alternate-protocol job will "win". | 665 // the alternate-protocol job will "win". |
635 AddHangingNonAlternateProtocolSocketData(); | 666 AddHangingNonAlternateProtocolSocketData(); |
636 | 667 |
637 CreateSession(); | 668 CreateSession(); |
638 | 669 |
639 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 670 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 671 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
640 SendRequestAndExpectQuicResponse("hello!"); | 672 SendRequestAndExpectQuicResponse("hello!"); |
641 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 673 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 674 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
642 | 675 |
643 // Check that the NetLog was filled reasonably. | 676 // Check that the NetLog was filled reasonably. |
644 TestNetLogEntry::List entries; | 677 TestNetLogEntry::List entries; |
645 net_log_.GetEntries(&entries); | 678 net_log_.GetEntries(&entries); |
646 EXPECT_LT(0u, entries.size()); | 679 EXPECT_LT(0u, entries.size()); |
647 | 680 |
648 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. | 681 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
649 int pos = ExpectLogContainsSomewhere( | 682 int pos = ExpectLogContainsSomewhere( |
650 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, | 683 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
651 NetLog::PHASE_NONE); | 684 NetLog::PHASE_NONE); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 725 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
693 mock_quic_data.AddRead( | 726 mock_quic_data.AddRead( |
694 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | 727 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
695 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 728 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
696 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | 729 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
697 mock_quic_data.AddRead(ASYNC, 0); // EOF | 730 mock_quic_data.AddRead(ASYNC, 0); // EOF |
698 | 731 |
699 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 732 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
700 | 733 |
701 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 734 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 735 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
702 // There is no need to set up an alternate protocol job, because | 736 // There is no need to set up an alternate protocol job, because |
703 // no attempt will be made to speak to the proxy over TCP. | 737 // no attempt will be made to speak to the proxy over TCP. |
704 | 738 |
705 request_.url = GURL("http://mail.example.org/"); | 739 request_.url = GURL("http://mail.example.org/"); |
706 CreateSession(); | 740 CreateSession(); |
707 | 741 |
708 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); | 742 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
709 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 743 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 744 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
710 } | 745 } |
711 | 746 |
712 // Regression test for https://crbug.com/492458. Test that for an HTTP | 747 // Regression test for https://crbug.com/492458. Test that for an HTTP |
713 // connection through a QUIC proxy, the certificate exhibited by the proxy is | 748 // connection through a QUIC proxy, the certificate exhibited by the proxy is |
714 // checked against the proxy hostname, not the origin hostname. | 749 // checked against the proxy hostname, not the origin hostname. |
715 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { | 750 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
716 const std::string origin_host = "mail.example.com"; | 751 const std::string origin_host = "mail.example.com"; |
717 const std::string proxy_host = "www.example.org"; | 752 const std::string proxy_host = "www.example.org"; |
718 | 753 |
719 params_.enable_quic_for_proxies = true; | 754 params_.enable_quic_for_proxies = true; |
(...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2284 nullptr, net_log_.bound()); | 2319 nullptr, net_log_.bound()); |
2285 | 2320 |
2286 CreateSessionWithNextProtos(); | 2321 CreateSessionWithNextProtos(); |
2287 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 2322 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
2288 SendRequestAndExpectHttpResponse("hello world"); | 2323 SendRequestAndExpectHttpResponse("hello world"); |
2289 } | 2324 } |
2290 | 2325 |
2291 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { | 2326 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
2292 maker_.set_hostname("www.example.org"); | 2327 maker_.set_hostname("www.example.org"); |
2293 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 2328 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 2329 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
2294 MockQuicData mock_quic_data; | 2330 MockQuicData mock_quic_data; |
2295 mock_quic_data.AddWrite( | 2331 mock_quic_data.AddWrite( |
2296 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, | 2332 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
2297 GetRequestHeaders("GET", "https", "/"))); | 2333 GetRequestHeaders("GET", "https", "/"))); |
2298 mock_quic_data.AddRead(ConstructResponseHeadersPacket( | 2334 mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
2299 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 2335 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
2300 mock_quic_data.AddRead( | 2336 mock_quic_data.AddRead( |
2301 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | 2337 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
2302 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 2338 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
2303 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. | 2339 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
2304 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 2340 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
2305 | 2341 |
2306 request_.url = GURL("https://www.example.org:443"); | 2342 request_.url = GURL("https://www.example.org:443"); |
2307 AddHangingNonAlternateProtocolSocketData(); | 2343 AddHangingNonAlternateProtocolSocketData(); |
2308 CreateSessionWithNextProtos(); | 2344 CreateSessionWithNextProtos(); |
2309 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); | 2345 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
2310 SendRequestAndExpectQuicResponse("hello!"); | 2346 SendRequestAndExpectQuicResponse("hello!"); |
2311 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 2347 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 2348 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
2312 } | 2349 } |
2313 | 2350 |
2314 TEST_P(QuicNetworkTransactionTest, QuicUpload) { | 2351 TEST_P(QuicNetworkTransactionTest, QuicUpload) { |
2315 params_.origin_to_force_quic_on = | 2352 params_.origin_to_force_quic_on = |
2316 HostPortPair::FromString("mail.example.org:443"); | 2353 HostPortPair::FromString("mail.example.org:443"); |
2317 | 2354 |
2318 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 2355 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
2319 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; | 2356 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; |
2320 SequencedSocketData socket_data(reads, arraysize(reads), writes, | 2357 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
2321 arraysize(writes)); | 2358 arraysize(writes)); |
(...skipping 13 matching lines...) Expand all Loading... |
2335 scoped_ptr<HttpNetworkTransaction> trans( | 2372 scoped_ptr<HttpNetworkTransaction> trans( |
2336 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 2373 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
2337 TestCompletionCallback callback; | 2374 TestCompletionCallback callback; |
2338 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 2375 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
2339 EXPECT_EQ(ERR_IO_PENDING, rv); | 2376 EXPECT_EQ(ERR_IO_PENDING, rv); |
2340 EXPECT_NE(OK, callback.WaitForResult()); | 2377 EXPECT_NE(OK, callback.WaitForResult()); |
2341 } | 2378 } |
2342 | 2379 |
2343 } // namespace test | 2380 } // namespace test |
2344 } // namespace net | 2381 } // namespace net |
OLD | NEW |