Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: net/quic/quic_network_transaction_unittest.cc

Issue 1672513002: Expose packet loss counts from QUIC to NetworkQualityEstimator (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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_.enable_spdy31 = true; 473 params_.enable_spdy31 = true;
446 params_.enable_http2 = true; 474 params_.enable_http2 = true;
447 params_.parse_alternative_services = true; 475 params_.parse_alternative_services = true;
448 params_.enable_alternative_service_with_different_host = true; 476 params_.enable_alternative_service_with_different_host = true;
449 } 477 }
450 478
451 session_.reset(new HttpNetworkSession(params_)); 479 session_.reset(new HttpNetworkSession(params_));
452 session_->quic_stream_factory()->set_require_confirmation(false); 480 session_->quic_stream_factory()->set_require_confirmation(false);
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 scoped_ptr<HttpNetworkSession> session_; 590 scoped_ptr<HttpNetworkSession> session_;
563 MockClientSocketFactory socket_factory_; 591 MockClientSocketFactory socket_factory_;
564 ProofVerifyDetailsChromium verify_details_; 592 ProofVerifyDetailsChromium verify_details_;
565 MockCryptoClientStreamFactory crypto_client_stream_factory_; 593 MockCryptoClientStreamFactory crypto_client_stream_factory_;
566 MockHostResolver host_resolver_; 594 MockHostResolver host_resolver_;
567 MockCertVerifier cert_verifier_; 595 MockCertVerifier cert_verifier_;
568 TransportSecurityState transport_security_state_; 596 TransportSecurityState transport_security_state_;
569 scoped_ptr<CTVerifier> cert_transparency_verifier_; 597 scoped_ptr<CTVerifier> cert_transparency_verifier_;
570 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_; 598 scoped_ptr<TestNetworkQualityEstimator> test_network_quality_estimator_;
571 TestRTTObserver rtt_observer_; 599 TestRTTObserver rtt_observer_;
600 TestPacketLossObserver packet_loss_observer_;
572 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_; 601 scoped_refptr<SSLConfigServiceDefaults> ssl_config_service_;
573 scoped_ptr<ProxyService> proxy_service_; 602 scoped_ptr<ProxyService> proxy_service_;
574 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_; 603 scoped_ptr<HttpAuthHandlerFactory> auth_handler_factory_;
575 MockRandom random_generator_; 604 MockRandom random_generator_;
576 HttpServerPropertiesImpl http_server_properties_; 605 HttpServerPropertiesImpl http_server_properties_;
577 HttpNetworkSession::Params params_; 606 HttpNetworkSession::Params params_;
578 HttpRequestInfo request_; 607 HttpRequestInfo request_;
579 BoundTestNetLog net_log_; 608 BoundTestNetLog net_log_;
580 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_; 609 std::vector<scoped_ptr<StaticSocketDataProvider>> hanging_data_;
581 SSLSocketDataProvider ssl_data_; 610 SSLSocketDataProvider ssl_data_;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 649
621 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 650 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
622 651
623 // The non-alternate protocol job needs to hang in order to guarantee that 652 // The non-alternate protocol job needs to hang in order to guarantee that
624 // the alternate-protocol job will "win". 653 // the alternate-protocol job will "win".
625 AddHangingNonAlternateProtocolSocketData(); 654 AddHangingNonAlternateProtocolSocketData();
626 655
627 CreateSession(); 656 CreateSession();
628 657
629 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); 658 EXPECT_FALSE(rtt_observer_.rtt_notification_received());
659 EXPECT_FALSE(packet_loss_observer_.notification_received());
630 SendRequestAndExpectQuicResponse("hello!"); 660 SendRequestAndExpectQuicResponse("hello!");
631 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); 661 EXPECT_TRUE(rtt_observer_.rtt_notification_received());
662 EXPECT_TRUE(packet_loss_observer_.notification_received());
632 663
633 // Check that the NetLog was filled reasonably. 664 // Check that the NetLog was filled reasonably.
634 TestNetLogEntry::List entries; 665 TestNetLogEntry::List entries;
635 net_log_.GetEntries(&entries); 666 net_log_.GetEntries(&entries);
636 EXPECT_LT(0u, entries.size()); 667 EXPECT_LT(0u, entries.size());
637 668
638 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED. 669 // Check that we logged a QUIC_SESSION_PACKET_RECEIVED.
639 int pos = ExpectLogContainsSomewhere( 670 int pos = ExpectLogContainsSomewhere(
640 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED, 671 entries, 0, NetLog::TYPE_QUIC_SESSION_PACKET_RECEIVED,
641 NetLog::PHASE_NONE); 672 NetLog::PHASE_NONE);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); 713 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK")));
683 mock_quic_data.AddRead( 714 mock_quic_data.AddRead(
684 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); 715 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!"));
685 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); 716 mock_quic_data.AddWrite(ConstructAckPacket(2, 1));
686 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read 717 mock_quic_data.AddRead(ASYNC, ERR_IO_PENDING); // No more data to read
687 mock_quic_data.AddRead(ASYNC, 0); // EOF 718 mock_quic_data.AddRead(ASYNC, 0); // EOF
688 719
689 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 720 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
690 721
691 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); 722 EXPECT_FALSE(rtt_observer_.rtt_notification_received());
723 EXPECT_FALSE(packet_loss_observer_.notification_received());
692 // There is no need to set up an alternate protocol job, because 724 // There is no need to set up an alternate protocol job, because
693 // no attempt will be made to speak to the proxy over TCP. 725 // no attempt will be made to speak to the proxy over TCP.
694 726
695 request_.url = GURL("http://mail.example.com/"); 727 request_.url = GURL("http://mail.example.com/");
696 CreateSession(); 728 CreateSession();
697 729
698 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70); 730 SendRequestAndExpectQuicResponseFromProxyOnPort("hello!", 70);
699 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); 731 EXPECT_TRUE(rtt_observer_.rtt_notification_received());
732 EXPECT_TRUE(packet_loss_observer_.notification_received());
700 } 733 }
701 734
702 // Regression test for https://crbug.com/492458. Test that for an HTTP 735 // Regression test for https://crbug.com/492458. Test that for an HTTP
703 // connection through a QUIC proxy, the certificate exhibited by the proxy is 736 // connection through a QUIC proxy, the certificate exhibited by the proxy is
704 // checked against the proxy hostname, not the origin hostname. 737 // checked against the proxy hostname, not the origin hostname.
705 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) { 738 TEST_P(QuicNetworkTransactionTest, QuicProxyWithCert) {
706 const std::string origin_host = "news.example.com"; 739 const std::string origin_host = "news.example.com";
707 const std::string proxy_host = "www.example.org"; 740 const std::string proxy_host = "www.example.org";
708 741
709 params_.enable_quic_for_proxies = true; 742 params_.enable_quic_for_proxies = true;
(...skipping 1525 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 nullptr, net_log_.bound()); 2268 nullptr, net_log_.bound());
2236 2269
2237 CreateSessionWithNextProtos(); 2270 CreateSessionWithNextProtos();
2238 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT); 2271 AddQuicAlternateProtocolMapping(MockCryptoClientStream::ZERO_RTT);
2239 SendRequestAndExpectHttpResponse("hello world"); 2272 SendRequestAndExpectHttpResponse("hello world");
2240 } 2273 }
2241 2274
2242 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) { 2275 TEST_P(QuicNetworkTransactionTest, SecureResourceOverSecureQuic) {
2243 maker_.set_hostname("www.example.org"); 2276 maker_.set_hostname("www.example.org");
2244 EXPECT_FALSE(rtt_observer_.rtt_notification_received()); 2277 EXPECT_FALSE(rtt_observer_.rtt_notification_received());
2278 EXPECT_FALSE(packet_loss_observer_.notification_received());
2245 MockQuicData mock_quic_data; 2279 MockQuicData mock_quic_data;
2246 mock_quic_data.AddWrite( 2280 mock_quic_data.AddWrite(
2247 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true, 2281 ConstructRequestHeadersPacket(1, kClientDataStreamId1, true, true,
2248 GetRequestHeaders("GET", "https", "/"))); 2282 GetRequestHeaders("GET", "https", "/")));
2249 mock_quic_data.AddRead(ConstructResponseHeadersPacket( 2283 mock_quic_data.AddRead(ConstructResponseHeadersPacket(
2250 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK"))); 2284 1, kClientDataStreamId1, false, false, GetResponseHeaders("200 OK")));
2251 mock_quic_data.AddRead( 2285 mock_quic_data.AddRead(
2252 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!")); 2286 ConstructDataPacket(2, kClientDataStreamId1, false, true, 0, "hello!"));
2253 mock_quic_data.AddWrite(ConstructAckPacket(2, 1)); 2287 mock_quic_data.AddWrite(ConstructAckPacket(2, 1));
2254 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data. 2288 mock_quic_data.AddRead(SYNCHRONOUS, ERR_IO_PENDING); // No more read data.
2255 mock_quic_data.AddSocketDataToFactory(&socket_factory_); 2289 mock_quic_data.AddSocketDataToFactory(&socket_factory_);
2256 2290
2257 request_.url = GURL("https://www.example.org:443"); 2291 request_.url = GURL("https://www.example.org:443");
2258 AddHangingNonAlternateProtocolSocketData(); 2292 AddHangingNonAlternateProtocolSocketData();
2259 CreateSessionWithNextProtos(); 2293 CreateSessionWithNextProtos();
2260 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE); 2294 AddQuicAlternateProtocolMapping(MockCryptoClientStream::CONFIRM_HANDSHAKE);
2261 SendRequestAndExpectQuicResponse("hello!"); 2295 SendRequestAndExpectQuicResponse("hello!");
2262 EXPECT_TRUE(rtt_observer_.rtt_notification_received()); 2296 EXPECT_TRUE(rtt_observer_.rtt_notification_received());
2297 EXPECT_TRUE(packet_loss_observer_.notification_received());
2263 } 2298 }
2264 2299
2265 TEST_P(QuicNetworkTransactionTest, QuicUpload) { 2300 TEST_P(QuicNetworkTransactionTest, QuicUpload) {
2266 params_.origin_to_force_quic_on = 2301 params_.origin_to_force_quic_on =
2267 HostPortPair::FromString("mail.example.com:443"); 2302 HostPortPair::FromString("mail.example.com:443");
2268 2303
2269 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)}; 2304 MockRead reads[] = {MockRead(SYNCHRONOUS, ERR_IO_PENDING, 0)};
2270 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)}; 2305 MockWrite writes[] = {MockWrite(SYNCHRONOUS, ERR_FAILED, 1)};
2271 SequencedSocketData socket_data(reads, arraysize(reads), writes, 2306 SequencedSocketData socket_data(reads, arraysize(reads), writes,
2272 arraysize(writes)); 2307 arraysize(writes));
(...skipping 13 matching lines...) Expand all
2286 scoped_ptr<HttpNetworkTransaction> trans( 2321 scoped_ptr<HttpNetworkTransaction> trans(
2287 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get())); 2322 new HttpNetworkTransaction(DEFAULT_PRIORITY, session_.get()));
2288 TestCompletionCallback callback; 2323 TestCompletionCallback callback;
2289 int rv = trans->Start(&request_, callback.callback(), net_log_.bound()); 2324 int rv = trans->Start(&request_, callback.callback(), net_log_.bound());
2290 EXPECT_EQ(ERR_IO_PENDING, rv); 2325 EXPECT_EQ(ERR_IO_PENDING, rv);
2291 EXPECT_NE(OK, callback.WaitForResult()); 2326 EXPECT_NE(OK, callback.WaitForResult());
2292 } 2327 }
2293 2328
2294 } // namespace test 2329 } // namespace test
2295 } // namespace net 2330 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698