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