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 <stdint.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" |
13 #include "net/base/chunked_upload_data_stream.h" | 15 #include "net/base/chunked_upload_data_stream.h" |
14 #include "net/base/network_quality_estimator.h" | 16 #include "net/base/network_quality_estimator.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 int32_t rtt_ms, | 177 int32_t rtt_ms, |
176 const base::TimeTicks& timestamp, | 178 const base::TimeTicks& timestamp, |
177 net::NetworkQualityEstimator::ObservationSource source) override { | 179 net::NetworkQualityEstimator::ObservationSource source) override { |
178 rtt_notification_received_ = true; | 180 rtt_notification_received_ = true; |
179 } | 181 } |
180 | 182 |
181 private: | 183 private: |
182 bool rtt_notification_received_; | 184 bool rtt_notification_received_; |
183 }; | 185 }; |
184 | 186 |
| 187 class TestPacketLossObserver |
| 188 : public NetworkQualityEstimator::PacketLossObserver { |
| 189 public: |
| 190 TestPacketLossObserver() : notification_received_(false) {} |
| 191 |
| 192 bool notification_received() const { return notification_received_; } |
| 193 |
| 194 // NetworkQualityEstimator::PacketLossObserver implementation: |
| 195 void OnPacketLossObservation( |
| 196 uint64_t num_packets_lost, |
| 197 uint64_t num_packets_received_in_order, |
| 198 uint64_t num_packets_received_not_in_order, |
| 199 const base::TimeTicks& timestamp, |
| 200 net::NetworkQualityEstimator::ObservationSource source) override { |
| 201 if (source != NetworkQualityEstimator::QUIC) { |
| 202 NOTIMPLEMENTED(); |
| 203 } |
| 204 notification_received_ = true; |
| 205 } |
| 206 |
| 207 private: |
| 208 bool notification_received_; |
| 209 }; |
| 210 |
185 class QuicNetworkTransactionTest | 211 class QuicNetworkTransactionTest |
186 : public PlatformTest, | 212 : public PlatformTest, |
187 public ::testing::WithParamInterface<QuicVersion> { | 213 public ::testing::WithParamInterface<QuicVersion> { |
188 protected: | 214 protected: |
189 QuicNetworkTransactionTest() | 215 QuicNetworkTransactionTest() |
190 : clock_(new MockClock), | 216 : clock_(new MockClock), |
191 maker_(GetParam(), 0, clock_, kDefaultServerHostName), | 217 maker_(GetParam(), 0, clock_, kDefaultServerHostName), |
192 cert_transparency_verifier_(new MultiLogCTVerifier()), | 218 cert_transparency_verifier_(new MultiLogCTVerifier()), |
193 test_network_quality_estimator_(new TestNetworkQualityEstimator()), | 219 test_network_quality_estimator_(new TestNetworkQualityEstimator()), |
194 ssl_config_service_(new SSLConfigServiceDefaults), | 220 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(); | 459 params_.http_server_properties = http_server_properties_.GetWeakPtr(); |
434 params_.quic_supported_versions = SupportedVersions(GetParam()); | 460 params_.quic_supported_versions = SupportedVersions(GetParam()); |
435 for (const char* host : | 461 for (const char* host : |
436 {kDefaultServerHostName, "www.example.com", "news.example.com", | 462 {kDefaultServerHostName, "www.example.com", "news.example.com", |
437 "bar.example.com", "foo.example.com", "www.example.org", | 463 "bar.example.com", "foo.example.com", "www.example.org", |
438 "invalid.example.org", "docs.example.org"}) { | 464 "invalid.example.org", "docs.example.org"}) { |
439 params_.quic_host_whitelist.insert(host); | 465 params_.quic_host_whitelist.insert(host); |
440 } | 466 } |
441 | 467 |
442 test_network_quality_estimator_->AddRTTObserver(&rtt_observer_); | 468 test_network_quality_estimator_->AddRTTObserver(&rtt_observer_); |
| 469 test_network_quality_estimator_->AddPacketLossObserver( |
| 470 &packet_loss_observer_); |
443 | 471 |
444 if (use_next_protos) { | 472 if (use_next_protos) { |
445 params_.parse_alternative_services = true; | 473 params_.parse_alternative_services = true; |
446 params_.enable_alternative_service_with_different_host = true; | 474 params_.enable_alternative_service_with_different_host = true; |
447 } | 475 } |
448 | 476 |
449 session_.reset(new HttpNetworkSession(params_)); | 477 session_.reset(new HttpNetworkSession(params_)); |
450 session_->quic_stream_factory()->set_require_confirmation(false); | 478 session_->quic_stream_factory()->set_require_confirmation(false); |
451 ASSERT_EQ(params_.quic_socket_receive_buffer_size, | 479 ASSERT_EQ(params_.quic_socket_receive_buffer_size, |
452 session_->quic_stream_factory()->socket_receive_buffer_size()); | 480 session_->quic_stream_factory()->socket_receive_buffer_size()); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
560 scoped_ptr<HttpNetworkSession> session_; | 588 scoped_ptr<HttpNetworkSession> session_; |
561 MockClientSocketFactory socket_factory_; | 589 MockClientSocketFactory socket_factory_; |
562 ProofVerifyDetailsChromium verify_details_; | 590 ProofVerifyDetailsChromium verify_details_; |
563 MockCryptoClientStreamFactory crypto_client_stream_factory_; | 591 MockCryptoClientStreamFactory crypto_client_stream_factory_; |
564 MockHostResolver host_resolver_; | 592 MockHostResolver host_resolver_; |
565 MockCertVerifier cert_verifier_; | 593 MockCertVerifier cert_verifier_; |
566 TransportSecurityState transport_security_state_; | 594 TransportSecurityState transport_security_state_; |
567 scoped_ptr<CTVerifier> cert_transparency_verifier_; | 595 scoped_ptr<CTVerifier> cert_transparency_verifier_; |
568 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; | 596 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; |
569 TestRTTObserver rtt_observer_; | 597 TestRTTObserver rtt_observer_; |
| 598 TestPacketLossObserver packet_loss_observer_; |
570 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; | 599 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; |
571 scoped_ptr<ProxyService> proxy_service_; | 600 scoped_ptr<ProxyService> proxy_service_; |
572 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; | 601 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; |
573 MockRandom random_generator_; | 602 MockRandom random_generator_; |
574 HttpServerPropertiesImpl http_server_properties_; | 603 HttpServerPropertiesImpl http_server_properties_; |
575 HttpNetworkSession::Params params_; | 604 HttpNetworkSession::Params params_; |
576 HttpRequestInfo request_; | 605 HttpRequestInfo request_; |
577 BoundTestNetLog net_log_; | 606 BoundTestNetLog net_log_; |
578 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; | 607 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; |
579 SSLSocketDataProvider ssl_data_; | 608 SSLSocketDataProvider ssl_data_; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
618 | 647 |
619 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 648 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
620 | 649 |
621 // The non-alternate protocol job needs to hang in order to guarantee that | 650 // The non-alternate protocol job needs to hang in order to guarantee that |
622 // the alternate-protocol job will "win". | 651 // the alternate-protocol job will "win". |
623 AddHangingNonAlternateProtocolSocketData(); | 652 AddHangingNonAlternateProtocolSocketData(); |
624 | 653 |
625 CreateSession(); | 654 CreateSession(); |
626 | 655 |
627 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 656 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 657 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
628 SendRequestAndExpectQuicResponse("hello!"); | 658 SendRequestAndExpectQuicResponse("hello!"); |
629 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 659 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 660 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
630 | 661 |
631 // Check that the NetLog was filled reasonably. | 662 // Check that the NetLog was filled reasonably. |
632 TestNetLogEntry::List entries; | 663 TestNetLogEntry::List entries; |
633 net_log_.GetEntries(&entries); | 664 net_log_.GetEntries(&entries); |
634 EXPECT_LT(0u, entries.size()); | 665 EXPECT_LT(0u, entries.size()); |
635 | 666 |
636 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. | 667 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. |
637 int pos = ExpectLogContainsSomewhere( | 668 int pos = ExpectLogContainsSomewhere( |
638 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, | 669 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, |
639 NetLog::PHASE_NONE); | 670 NetLog::PHASE_NONE); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 711 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
681 mock_quic_data.AddRead( | 712 mock_quic_data.AddRead( |
682 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | 713 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
683 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 714 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
684 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read | 715 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read |
685 mock_quic_data.AddRead(ASYNC, 0); // EOF | 716 mock_quic_data.AddRead(ASYNC, 0); // EOF |
686 | 717 |
687 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 718 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
688 | 719 |
689 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 720 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 721 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
690 // There is no need to set up an alternate protocol job, because | 722 // There is no need to set up an alternate protocol job, because |
691 // no attempt will be made to speak to the proxy over TCP. | 723 // no attempt will be made to speak to the proxy over TCP. |
692 | 724 |
693 request_.url = GURL("http://mail.example.com/"); | 725 request_.url = GURL("http://mail.example.com/"); |
694 CreateSession(); | 726 CreateSession(); |
695 | 727 |
696 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); | 728 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); |
697 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 729 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 730 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
698 } | 731 } |
699 | 732 |
700 // Regression test for https://crbug.com/492458. Test that for an HTTP | 733 // Regression test for https://crbug.com/492458. Test that for an HTTP |
701 // connection through a QUIC proxy, the certificate exhibited by the proxy is | 734 // connection through a QUIC proxy, the certificate exhibited by the proxy is |
702 // checked against the proxy hostname, not the origin hostname. | 735 // checked against the proxy hostname, not the origin hostname. |
703 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { | 736 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { |
704 const std::string origin_host = "news.example.com"; | 737 const std::string origin_host = "news.example.com"; |
705 const std::string proxy_host = "www.example.org"; | 738 const std::string proxy_host = "www.example.org"; |
706 | 739 |
707 params_.enable_quic_for_proxies = true; | 740 params_.enable_quic_for_proxies = true; |
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2233 nullptr, net_log_.bound()); | 2266 nullptr, net_log_.bound()); |
2234 | 2267 |
2235 CreateSessionWithNextProtos(); | 2268 CreateSessionWithNextProtos(); |
2236 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); | 2269 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); |
2237 SendRequestAndExpectHttpResponse("hello world"); | 2270 SendRequestAndExpectHttpResponse("hello world"); |
2238 } | 2271 } |
2239 | 2272 |
2240 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { | 2273 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { |
2241 maker_.set_hostname("www.example.org"); | 2274 maker_.set_hostname("www.example.org"); |
2242 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); | 2275 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); |
| 2276 EXPECT_FALSE(packet_loss_observer_.notification_received()); |
2243 MockQuicData mock_quic_data; | 2277 MockQuicData mock_quic_data; |
2244 mock_quic_data.AddWrite( | 2278 mock_quic_data.AddWrite( |
2245 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, | 2279 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, |
2246 GetRequestHeaders("GET", "https", "/"))); | 2280 GetRequestHeaders("GET", "https", "/"))); |
2247 mock_quic_data.AddRead(ConstructResponseHeadersPacket( | 2281 mock_quic_data.AddRead(ConstructResponseHeadersPacket( |
2248 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); | 2282 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); |
2249 mock_quic_data.AddRead( | 2283 mock_quic_data.AddRead( |
2250 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); | 2284 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); |
2251 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); | 2285 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); |
2252 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. | 2286 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. |
2253 mock_quic_data.AddSocketDataToFactory(&socket_factory_); | 2287 mock_quic_data.AddSocketDataToFactory(&socket_factory_); |
2254 | 2288 |
2255 request_.url = GURL("https://www.example.org:443"); | 2289 request_.url = GURL("https://www.example.org:443"); |
2256 AddHangingNonAlternateProtocolSocketData(); | 2290 AddHangingNonAlternateProtocolSocketData(); |
2257 CreateSessionWithNextProtos(); | 2291 CreateSessionWithNextProtos(); |
2258 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); | 2292 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); |
2259 SendRequestAndExpectQuicResponse("hello!"); | 2293 SendRequestAndExpectQuicResponse("hello!"); |
2260 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); | 2294 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); |
| 2295 EXPECT_TRUE(packet_loss_observer_.notification_received()); |
2261 } | 2296 } |
2262 | 2297 |
2263 TEST_P(QuicNetworkTransactionTest, QuicUpload) { | 2298 TEST_P(QuicNetworkTransactionTest, QuicUpload) { |
2264 params_.origin_to_force_quic_on = | 2299 params_.origin_to_force_quic_on = |
2265 HostPortPair::FromString("mail.example.com:443"); | 2300 HostPortPair::FromString("mail.example.com:443"); |
2266 | 2301 |
2267 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; | 2302 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; |
2268 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; | 2303 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; |
2269 SequencedSocketData socket_data(reads, arraysize(reads), writes, | 2304 SequencedSocketData socket_data(reads, arraysize(reads), writes, |
2270 arraysize(writes)); | 2305 arraysize(writes)); |
(...skipping 13 matching lines...) Expand all Loading... |
2284 scoped_ptr<HttpNetworkTransaction> trans( | 2319 scoped_ptr<HttpNetworkTransaction> trans( |
2285 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); | 2320 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); |
2286 TestCompletionCallback callback; | 2321 TestCompletionCallback callback; |
2287 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); | 2322 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); |
2288 EXPECT_EQ(ERR_IO_PENDING, rv); | 2323 EXPECT_EQ(ERR_IO_PENDING, rv); |
2289 EXPECT_NE(OK, callback.WaitForResult()); | 2324 EXPECT_NE(OK, callback.WaitForResult()); |
2290 } | 2325 } |
2291 | 2326 |
2292 } // namespace test | 2327 } // namespace test |
2293 } // namespace net | 2328 } // namespace net |
OLD | NEW |